Fix #1782 and part of #1781: Fix text view image loading issues #1797
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1782
Partly fixes #1781 (for online cases)
There seems to be a not well-documented or seen bug in AOSP wherein TextViews with HTML that only contains an ImageSpan and no other visible text can result in the TextView seemingly being ignored for layout & measurement. This results in our image computation for ImageSpan failing. The hack involves adding spaces around the image (technically just 1 is needed, but 2 are added to keep the image horizontally centered) which triggers Android to properly lay out the view & allow our image computation to kick-in. I filed #1796 to track finding a better long-term solution.
Note that this also includes another semi-hacky workaround: getting Android to layout the view is only part of the solution. In cases when TextView is using wrap_content, we don't have a true maximum to use when ensuring the image doesn't exceed its container's bounds. For the purpose of keeping things simple for now, we're assuming that in such cases we can limit the TextView's dimensions to that of its parent's minus established right/left margins. This should be correct in all cases (unless a maxWidth is set smaller than the parent--we don't account for this right now).
No new tests were added for the UrlImageParser work. #277 is tracking adding test cases for the parser (there's a bit too much to do there for me to do it quickly, so I deferred to that issue, instead).
Thanks to @rt4914 for the early investigation with the wrap_content part.