Loading core/java/android/text/style/SuggestionSpan.java +30 −2 Original line number Diff line number Diff line Loading @@ -56,6 +56,14 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { */ public static final int FLAG_MISSPELLED = 0x0002; /** * Sets this flag if the auto correction is about to be applied to a word/text * that the user is typing/composing. This type of suggestion is rendered differently * to indicate the auto correction is happening. * @hide */ public static final int FLAG_AUTO_CORRECTION = 0x0004; public static final String ACTION_SUGGESTION_PICKED = "android.text.style.SUGGESTION_PICKED"; public static final String SUGGESTION_SPAN_PICKED_AFTER = "after"; public static final String SUGGESTION_SPAN_PICKED_BEFORE = "before"; Loading @@ -82,6 +90,9 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { private float mMisspelledUnderlineThickness; private int mMisspelledUnderlineColor; private float mAutoCorrectionUnderlineThickness; private int mAutoCorrectionUnderlineColor; /* * TODO: If switching IME is required, needs to add parameters for ids of InputMethodInfo * and InputMethodSubtype. Loading Loading @@ -145,14 +156,21 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK); defStyle = com.android.internal.R.attr.textAppearanceEasyCorrectSuggestion; typedArray = context.obtainStyledAttributes( null, com.android.internal.R.styleable.SuggestionSpan, defStyle, 0); mEasyCorrectUnderlineThickness = typedArray.getDimension( com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0); mEasyCorrectUnderlineColor = typedArray.getColor( com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK); defStyle = com.android.internal.R.attr.textAppearanceAutoCorrectionSuggestion; typedArray = context.obtainStyledAttributes( null, com.android.internal.R.styleable.SuggestionSpan, defStyle, 0); mAutoCorrectionUnderlineThickness = typedArray.getDimension( com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0); mAutoCorrectionUnderlineColor = typedArray.getColor( com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK); } public SuggestionSpan(Parcel src) { Loading @@ -165,6 +183,8 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { mEasyCorrectUnderlineThickness = src.readFloat(); mMisspelledUnderlineColor = src.readInt(); mMisspelledUnderlineThickness = src.readFloat(); mAutoCorrectionUnderlineColor = src.readInt(); mAutoCorrectionUnderlineThickness = src.readFloat(); } /** Loading Loading @@ -218,6 +238,8 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { dest.writeFloat(mEasyCorrectUnderlineThickness); dest.writeInt(mMisspelledUnderlineColor); dest.writeFloat(mMisspelledUnderlineThickness); dest.writeInt(mAutoCorrectionUnderlineColor); dest.writeFloat(mAutoCorrectionUnderlineThickness); } @Override Loading Loading @@ -261,6 +283,7 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { public void updateDrawState(TextPaint tp) { final boolean misspelled = (mFlags & FLAG_MISSPELLED) != 0; final boolean easy = (mFlags & FLAG_EASY_CORRECT) != 0; final boolean autoCorrection = (mFlags & FLAG_AUTO_CORRECTION) != 0; if (easy) { if (!misspelled) { tp.setUnderlineText(mEasyCorrectUnderlineColor, mEasyCorrectUnderlineThickness); Loading @@ -269,6 +292,8 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { // than just easy, do not apply misspelled if an easy (or a mispelled) has been set tp.setUnderlineText(mMisspelledUnderlineColor, mMisspelledUnderlineThickness); } } else if (autoCorrection) { tp.setUnderlineText(mAutoCorrectionUnderlineColor, mAutoCorrectionUnderlineThickness); } } Loading @@ -281,12 +306,15 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { // The order here should match what is used in updateDrawState final boolean misspelled = (mFlags & FLAG_MISSPELLED) != 0; final boolean easy = (mFlags & FLAG_EASY_CORRECT) != 0; final boolean autoCorrection = (mFlags & FLAG_AUTO_CORRECTION) != 0; if (easy) { if (!misspelled) { return mEasyCorrectUnderlineColor; } else { return mMisspelledUnderlineColor; } } else if (autoCorrection) { return mAutoCorrectionUnderlineColor; } return 0; } Loading core/res/res/values/attrs.xml +3 −0 Original line number Diff line number Diff line Loading @@ -158,6 +158,9 @@ <!-- The underline color and thickness for misspelled suggestion --> <attr name="textAppearanceMisspelledSuggestion" format="reference" /> <!-- The underline color and thickness for auto correction suggestion --> <attr name="textAppearanceAutoCorrectionSuggestion" format="reference" /> <!-- The underline color --> <attr name="textUnderlineColor" format="reference|color" /> <!-- The underline thickness --> Loading core/res/res/values/styles.xml +4 −0 Original line number Diff line number Diff line Loading @@ -257,6 +257,10 @@ please see styles_device_defaults.xml. <item name="android:textUnderlineColor">@color/holo_red_light</item> </style> <style name="TextAppearance.AutoCorrectionSuggestion" parent="TextAppearance.Suggestion"> <item name="android:textUnderlineColor">@color/holo_blue_light</item> </style> <!-- Widget Styles --> <style name="Widget"> Loading core/res/res/values/themes.xml +1 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ please see themes_device_defaults.xml. <item name="textAppearanceEasyCorrectSuggestion">@android:style/TextAppearance.EasyCorrectSuggestion</item> <item name="textAppearanceMisspelledSuggestion">@android:style/TextAppearance.MisspelledSuggestion</item> <item name="textAppearanceAutoCorrectionSuggestion">@android:style/TextAppearance.AutoCorrectionSuggestion</item> <item name="textAppearanceButton">@android:style/TextAppearance.Widget.Button</item> Loading Loading
core/java/android/text/style/SuggestionSpan.java +30 −2 Original line number Diff line number Diff line Loading @@ -56,6 +56,14 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { */ public static final int FLAG_MISSPELLED = 0x0002; /** * Sets this flag if the auto correction is about to be applied to a word/text * that the user is typing/composing. This type of suggestion is rendered differently * to indicate the auto correction is happening. * @hide */ public static final int FLAG_AUTO_CORRECTION = 0x0004; public static final String ACTION_SUGGESTION_PICKED = "android.text.style.SUGGESTION_PICKED"; public static final String SUGGESTION_SPAN_PICKED_AFTER = "after"; public static final String SUGGESTION_SPAN_PICKED_BEFORE = "before"; Loading @@ -82,6 +90,9 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { private float mMisspelledUnderlineThickness; private int mMisspelledUnderlineColor; private float mAutoCorrectionUnderlineThickness; private int mAutoCorrectionUnderlineColor; /* * TODO: If switching IME is required, needs to add parameters for ids of InputMethodInfo * and InputMethodSubtype. Loading Loading @@ -145,14 +156,21 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK); defStyle = com.android.internal.R.attr.textAppearanceEasyCorrectSuggestion; typedArray = context.obtainStyledAttributes( null, com.android.internal.R.styleable.SuggestionSpan, defStyle, 0); mEasyCorrectUnderlineThickness = typedArray.getDimension( com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0); mEasyCorrectUnderlineColor = typedArray.getColor( com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK); defStyle = com.android.internal.R.attr.textAppearanceAutoCorrectionSuggestion; typedArray = context.obtainStyledAttributes( null, com.android.internal.R.styleable.SuggestionSpan, defStyle, 0); mAutoCorrectionUnderlineThickness = typedArray.getDimension( com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0); mAutoCorrectionUnderlineColor = typedArray.getColor( com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK); } public SuggestionSpan(Parcel src) { Loading @@ -165,6 +183,8 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { mEasyCorrectUnderlineThickness = src.readFloat(); mMisspelledUnderlineColor = src.readInt(); mMisspelledUnderlineThickness = src.readFloat(); mAutoCorrectionUnderlineColor = src.readInt(); mAutoCorrectionUnderlineThickness = src.readFloat(); } /** Loading Loading @@ -218,6 +238,8 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { dest.writeFloat(mEasyCorrectUnderlineThickness); dest.writeInt(mMisspelledUnderlineColor); dest.writeFloat(mMisspelledUnderlineThickness); dest.writeInt(mAutoCorrectionUnderlineColor); dest.writeFloat(mAutoCorrectionUnderlineThickness); } @Override Loading Loading @@ -261,6 +283,7 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { public void updateDrawState(TextPaint tp) { final boolean misspelled = (mFlags & FLAG_MISSPELLED) != 0; final boolean easy = (mFlags & FLAG_EASY_CORRECT) != 0; final boolean autoCorrection = (mFlags & FLAG_AUTO_CORRECTION) != 0; if (easy) { if (!misspelled) { tp.setUnderlineText(mEasyCorrectUnderlineColor, mEasyCorrectUnderlineThickness); Loading @@ -269,6 +292,8 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { // than just easy, do not apply misspelled if an easy (or a mispelled) has been set tp.setUnderlineText(mMisspelledUnderlineColor, mMisspelledUnderlineThickness); } } else if (autoCorrection) { tp.setUnderlineText(mAutoCorrectionUnderlineColor, mAutoCorrectionUnderlineThickness); } } Loading @@ -281,12 +306,15 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { // The order here should match what is used in updateDrawState final boolean misspelled = (mFlags & FLAG_MISSPELLED) != 0; final boolean easy = (mFlags & FLAG_EASY_CORRECT) != 0; final boolean autoCorrection = (mFlags & FLAG_AUTO_CORRECTION) != 0; if (easy) { if (!misspelled) { return mEasyCorrectUnderlineColor; } else { return mMisspelledUnderlineColor; } } else if (autoCorrection) { return mAutoCorrectionUnderlineColor; } return 0; } Loading
core/res/res/values/attrs.xml +3 −0 Original line number Diff line number Diff line Loading @@ -158,6 +158,9 @@ <!-- The underline color and thickness for misspelled suggestion --> <attr name="textAppearanceMisspelledSuggestion" format="reference" /> <!-- The underline color and thickness for auto correction suggestion --> <attr name="textAppearanceAutoCorrectionSuggestion" format="reference" /> <!-- The underline color --> <attr name="textUnderlineColor" format="reference|color" /> <!-- The underline thickness --> Loading
core/res/res/values/styles.xml +4 −0 Original line number Diff line number Diff line Loading @@ -257,6 +257,10 @@ please see styles_device_defaults.xml. <item name="android:textUnderlineColor">@color/holo_red_light</item> </style> <style name="TextAppearance.AutoCorrectionSuggestion" parent="TextAppearance.Suggestion"> <item name="android:textUnderlineColor">@color/holo_blue_light</item> </style> <!-- Widget Styles --> <style name="Widget"> Loading
core/res/res/values/themes.xml +1 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ please see themes_device_defaults.xml. <item name="textAppearanceEasyCorrectSuggestion">@android:style/TextAppearance.EasyCorrectSuggestion</item> <item name="textAppearanceMisspelledSuggestion">@android:style/TextAppearance.MisspelledSuggestion</item> <item name="textAppearanceAutoCorrectionSuggestion">@android:style/TextAppearance.AutoCorrectionSuggestion</item> <item name="textAppearanceButton">@android:style/TextAppearance.Widget.Button</item> Loading