@@ -56,6 +56,14 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan {
5656 */
5757 public static final int FLAG_MISSPELLED = 0x0002 ;
5858
59+ /**
60+ * Sets this flag if the auto correction is about to be applied to a word/text
61+ * that the user is typing/composing. This type of suggestion is rendered differently
62+ * to indicate the auto correction is happening.
63+ * @hide
64+ */
65+ public static final int FLAG_AUTO_CORRECTION = 0x0004 ;
66+
5967 public static final String ACTION_SUGGESTION_PICKED = "android.text.style.SUGGESTION_PICKED" ;
6068 public static final String SUGGESTION_SPAN_PICKED_AFTER = "after" ;
6169 public static final String SUGGESTION_SPAN_PICKED_BEFORE = "before" ;
@@ -82,6 +90,9 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan {
8290 private float mMisspelledUnderlineThickness ;
8391 private int mMisspelledUnderlineColor ;
8492
93+ private float mAutoCorrectionUnderlineThickness ;
94+ private int mAutoCorrectionUnderlineColor ;
95+
8596 /*
8697 * TODO: If switching IME is required, needs to add parameters for ids of InputMethodInfo
8798 * and InputMethodSubtype.
@@ -145,14 +156,21 @@ private void initStyle(Context context) {
145156 com .android .internal .R .styleable .SuggestionSpan_textUnderlineColor , Color .BLACK );
146157
147158 defStyle = com .android .internal .R .attr .textAppearanceEasyCorrectSuggestion ;
148-
149159 typedArray = context .obtainStyledAttributes (
150160 null , com .android .internal .R .styleable .SuggestionSpan , defStyle , 0 );
151-
152161 mEasyCorrectUnderlineThickness = typedArray .getDimension (
153162 com .android .internal .R .styleable .SuggestionSpan_textUnderlineThickness , 0 );
154163 mEasyCorrectUnderlineColor = typedArray .getColor (
155164 com .android .internal .R .styleable .SuggestionSpan_textUnderlineColor , Color .BLACK );
165+
166+ defStyle = com .android .internal .R .attr .textAppearanceAutoCorrectionSuggestion ;
167+ typedArray = context .obtainStyledAttributes (
168+ null , com .android .internal .R .styleable .SuggestionSpan , defStyle , 0 );
169+ mAutoCorrectionUnderlineThickness = typedArray .getDimension (
170+ com .android .internal .R .styleable .SuggestionSpan_textUnderlineThickness , 0 );
171+ mAutoCorrectionUnderlineColor = typedArray .getColor (
172+ com .android .internal .R .styleable .SuggestionSpan_textUnderlineColor , Color .BLACK );
173+
156174 }
157175
158176 public SuggestionSpan (Parcel src ) {
@@ -165,6 +183,8 @@ public SuggestionSpan(Parcel src) {
165183 mEasyCorrectUnderlineThickness = src .readFloat ();
166184 mMisspelledUnderlineColor = src .readInt ();
167185 mMisspelledUnderlineThickness = src .readFloat ();
186+ mAutoCorrectionUnderlineColor = src .readInt ();
187+ mAutoCorrectionUnderlineThickness = src .readFloat ();
168188 }
169189
170190 /**
@@ -218,6 +238,8 @@ public void writeToParcel(Parcel dest, int flags) {
218238 dest .writeFloat (mEasyCorrectUnderlineThickness );
219239 dest .writeInt (mMisspelledUnderlineColor );
220240 dest .writeFloat (mMisspelledUnderlineThickness );
241+ dest .writeInt (mAutoCorrectionUnderlineColor );
242+ dest .writeFloat (mAutoCorrectionUnderlineThickness );
221243 }
222244
223245 @ Override
@@ -261,6 +283,7 @@ public SuggestionSpan[] newArray(int size) {
261283 public void updateDrawState (TextPaint tp ) {
262284 final boolean misspelled = (mFlags & FLAG_MISSPELLED ) != 0 ;
263285 final boolean easy = (mFlags & FLAG_EASY_CORRECT ) != 0 ;
286+ final boolean autoCorrection = (mFlags & FLAG_AUTO_CORRECTION ) != 0 ;
264287 if (easy ) {
265288 if (!misspelled ) {
266289 tp .setUnderlineText (mEasyCorrectUnderlineColor , mEasyCorrectUnderlineThickness );
@@ -269,6 +292,8 @@ public void updateDrawState(TextPaint tp) {
269292 // than just easy, do not apply misspelled if an easy (or a mispelled) has been set
270293 tp .setUnderlineText (mMisspelledUnderlineColor , mMisspelledUnderlineThickness );
271294 }
295+ } else if (autoCorrection ) {
296+ tp .setUnderlineText (mAutoCorrectionUnderlineColor , mAutoCorrectionUnderlineThickness );
272297 }
273298 }
274299
@@ -281,12 +306,15 @@ public int getUnderlineColor() {
281306 // The order here should match what is used in updateDrawState
282307 final boolean misspelled = (mFlags & FLAG_MISSPELLED ) != 0 ;
283308 final boolean easy = (mFlags & FLAG_EASY_CORRECT ) != 0 ;
309+ final boolean autoCorrection = (mFlags & FLAG_AUTO_CORRECTION ) != 0 ;
284310 if (easy ) {
285311 if (!misspelled ) {
286312 return mEasyCorrectUnderlineColor ;
287313 } else {
288314 return mMisspelledUnderlineColor ;
289315 }
316+ } else if (autoCorrection ) {
317+ return mAutoCorrectionUnderlineColor ;
290318 }
291319 return 0 ;
292320 }
0 commit comments