Skip to content

Commit

Permalink
Merge pull request #149 from ZeusWPI/fix-html
Browse files Browse the repository at this point in the history
Catch crash on older Android versions
  • Loading branch information
niknetniko authored Apr 23, 2017
2 parents fc27c44 + be2c0c0 commit d19a6a8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/src/main/java/be/ugent/zeus/hydra/ui/common/html/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.util.Log;

/**
* @author Niko Strijbol
*/
public class Utils {

private static final String TAG = "HtmlUtils";

/**
* Helper with older version support. If the html is null, an empty Spannable will be returned.
*
Expand All @@ -25,8 +28,13 @@ public static Spanned fromHtml(String html, Html.ImageGetter getter) {
}

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
//noinspection deprecation
return Html.fromHtml(html, getter, new HtmlTagHandler());
try {
return Html.fromHtml(html, getter, new HtmlTagHandler());
} catch (RuntimeException e) {
// Older versions crash sometimes, so try again without custom tags.
Log.e(TAG, "Error while reading html.", e);
return Html.fromHtml(html, getter, null);
}
} else {
return Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY, getter, new HtmlTagHandler());
}
Expand Down

0 comments on commit d19a6a8

Please sign in to comment.