Created
March 8, 2017 03:17
-
-
Save kwong93/f89a6fd99eceb91f2ff03ac9650429b8 to your computer and use it in GitHub Desktop.
fromHtml and toHtml deprecation utility methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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