Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Add setRemoveFromHtmlSpace function/ cleanup example #37

Conversation

derekcsm
Copy link
Contributor

@derekcsm derekcsm commented Apr 5, 2016

This commit adds the option of having HtmlTextView automatically trim the extra "space" that Html.fromHtml sometimes adds to the bottom of text, via a simple setRemoveFromHtmlSpace(boolean) method.

setRemoveFromHtmlSpace must be called before setting text for the trailing space to be trimmed off it there are any, it will not work after text is already set since it just simply sets a value that will cause removeHtmlBottomPadding to be used in setHtmlFromString in the HtmlTextView class.

I like this approach more than a constructor because it's explicitly optional, straight forward, and not a breaking change, of-course a constructor could be added, w/ potentialy XML attributes so that it can be used from resources, but for now I don't think it's necessary.

I've also cleaned up MainActivity in the example app, moved the example html to a string resource, and added setRemoveFromHtmlSpace as an example. The activity_main layout now also has a slightly darker background from the HtmlTextView so that you can clearly see the bounds w/o using developer options "show layout bounds"

This commit adds the option of having HtmlTextView automatically trim the extra "space" that `Html.fromHtml` sometimes adds to the bottom of text, via a simple `setRemoveFromHtmlSpace(boolean)` method.

`setRemoveFromHtmlSpace` must be called before setting text for the trailing space to be trimmed off it there are any, it will not work after text is already set since it just simply sets a value that will cause `removeHtmlBottomPadding` to be used in `setHtmlFromString` in the `HtmlTextView` class.

I like this approach more than a constructor because it's explicitly optional, straight forward, and not a breaking change, of-course a constructor could be added, w/ potentialy XML attributes so that it can be used from resources, but for now I don't think it's necessary.

I've also cleaned up `MainActivity` in the example app, moved the example html to a string resource, and added `setRemoveFromHtmlSpace` as an example. The `activity_main` layout now also has a slightly darker background from the `HtmlTextView` so that you can clearly see the bounds w/o using developer options "show layout bounds"
@derekcsm
Copy link
Contributor Author

derekcsm commented Apr 5, 2016

Hey 👋 😄 let me know what you think

This would fix #19

Note: I haven't updated any version numbers

@@ -118,7 +126,10 @@ public void setHtmlFromString(String html, ImageGetter imageGetter) {
final HtmlTagHandler htmlTagHandler = new HtmlTagHandler();
htmlTagHandler.setClickableTableSpan(mClickableTableSpan);
htmlTagHandler.setDrawTableLinkSpan(mDrawTableLinkSpan);
setText(Html.fromHtml(html, htmlImageGetter, htmlTagHandler));
if (removeFromHtmlSpace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please always use brackets for if-else-statements

@dschuermann
Copy link
Member

looks good besides code style requirements

@derekcsm
Copy link
Contributor Author

derekcsm commented Apr 7, 2016

Hey @dschuermann I made a few updates yesterday, please let me know how this is.

@dschuermann dschuermann merged commit fbccba0 into SufficientlySecure:master Apr 8, 2016
@dschuermann
Copy link
Member

Great work thanks!

@dschuermann
Copy link
Member

released 1.5

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants