Skip to content

Instantly share code, notes, and snippets.

@kwong93
Created March 8, 2017 03:17
Show Gist options
  • Save kwong93/f89a6fd99eceb91f2ff03ac9650429b8 to your computer and use it in GitHub Desktop.
Save kwong93/f89a6fd99eceb91f2ff03ac9650429b8 to your computer and use it in GitHub Desktop.
fromHtml and toHtml deprecation utility methods
@SuppressWarnings("deprecation")
public static Spanned fromHtml(String source) {
if (source == null) {
return null;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY);
}
return Html.fromHtml(source);
}
@SuppressWarnings("deprecation")
public static String toHtml(Spannable source) {
if (source == null) {
return null;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return Html.toHtml(source, Html.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
}
return Html.toHtml(source);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment