11package org .neotech .app .retainabletasksdemo ;
22
3+ import android .graphics .Typeface ;
4+ import android .os .Build ;
5+ import android .os .Parcel ;
6+ import android .os .Parcelable ;
37import android .support .annotation .NonNull ;
8+ import android .support .design .internal .ParcelableSparseArray ;
49import android .text .Editable ;
510import android .text .Html ;
611import android .text .Spannable ;
1621 */
1722public final class ExtendedHtml {
1823
24+ public static final int FROM_HTML_MODE_LEGACY = Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ?Html .FROM_HTML_MODE_LEGACY :0 ;
25+ public static final int FROM_HTML_MODE_COMPACT = Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ?Html .FROM_HTML_MODE_COMPACT :0 ;
26+ public static final int FROM_HTML_OPTION_USE_CSS_COLORS = Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ?Html .FROM_HTML_OPTION_USE_CSS_COLORS :0 ;
27+ public static final int FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE = Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ?Html .FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE :0 ;
28+ public static final int FROM_HTML_SEPARATOR_LINE_BREAK_DIV = Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ?Html .FROM_HTML_SEPARATOR_LINE_BREAK_DIV :0 ;
29+ public static final int FROM_HTML_SEPARATOR_LINE_BREAK_HEADING = Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ?Html .FROM_HTML_SEPARATOR_LINE_BREAK_HEADING :0 ;
30+ public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST = Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ?Html .FROM_HTML_SEPARATOR_LINE_BREAK_LIST :0 ;
31+ public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM = Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ?Html .FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM :0 ;
32+ public static final int FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH = Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ?Html .FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH :0 ;
33+
1934 private static final ExtendedTagHandler TAG_HANDLER = new ExtendedTagHandler ();
2035
21- public static Spanned fromHtml (String source ){
22- return Html .fromHtml (source , null , TAG_HANDLER );
36+ public static Spanned fromHtml (String source , int flags ){
37+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ){
38+ return Html .fromHtml (source , flags , null , TAG_HANDLER );
39+ } else {
40+ return Html .fromHtml (source , null , TAG_HANDLER );
41+ }
2342 }
2443
2544 private static class CodeSpan extends TypefaceSpan {
@@ -31,6 +50,11 @@ public CodeSpan(int backgroundColor){
3150 this .backgroundColor = backgroundColor ;
3251 }
3352
53+ protected CodeSpan (Parcel in ) {
54+ super (in );
55+ this .backgroundColor = in .readInt ();
56+ }
57+
3458 @ Override
3559 public void updateDrawState (TextPaint tp ) {
3660 super .updateDrawState (tp );
@@ -42,14 +66,37 @@ public void updateMeasureState(TextPaint paint) {
4266 super .updateMeasureState (paint );
4367 paint .bgColor = backgroundColor ;
4468 }
69+
70+ public static final Creator <CodeSpan > CREATOR = new Creator <CodeSpan >() {
71+
72+ @ Override
73+ public CodeSpan createFromParcel (Parcel in ) {
74+ return new CodeSpan (in );
75+ }
76+
77+ @ Override
78+ public CodeSpan [] newArray (int size ) {
79+ return new CodeSpan [size ];
80+ }
81+ };
82+
83+ @ Override
84+ public void writeToParcel (Parcel dest , int flags ) {
85+ super .writeToParcel (dest , flags );
86+ dest .writeInt (backgroundColor );
87+ }
88+
89+ public int describeContents () {
90+ return 0 ;
91+ }
4592 }
4693
4794 /**
4895 * Based on: http://stackoverflow.com/questions/4044509/android-how-to-use-the-html-taghandler
4996 */
5097 private static class ExtendedTagHandler implements Html .TagHandler {
5198
52- private static final int COLOR = 0xFFCCCCCC ;
99+ private static final int COLOR = 0xFFDDDDDD ;
53100
54101 @ Override
55102 public void handleTag (boolean opening , String tag , Editable output , XMLReader xmlReader ) {
0 commit comments