@@ -76,8 +76,11 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan {
7676 private final String mNotificationTargetClassName ;
7777 private final int mHashCode ;
7878
79- private float mUnderlineThickness ;
80- private int mUnderlineColor ;
79+ private float mEasyCorrectUnderlineThickness ;
80+ private int mEasyCorrectUnderlineColor ;
81+
82+ private float mMisspelledUnderlineThickness ;
83+ private int mMisspelledUnderlineColor ;
8184
8285 /*
8386 * TODO: If switching IME is required, needs to add parameters for ids of InputMethodInfo
@@ -132,25 +135,22 @@ public SuggestionSpan(Context context, Locale locale, String[] suggestions, int
132135 }
133136
134137 private void initStyle (Context context ) {
135- int defStyle = 0 ;
136- if ((getFlags () & FLAG_MISSPELLED ) != 0 ) {
137- defStyle = com .android .internal .R .attr .textAppearanceMisspelledSuggestion ;
138- } else if ((getFlags () & FLAG_EASY_CORRECT ) != 0 ) {
139- defStyle = com .android .internal .R .attr .textAppearanceEasyCorrectSuggestion ;
140- } else {
141- // No style is applied.
142- mUnderlineThickness = 0 ;
143- mUnderlineColor = 0 ;
144- return ;
145- }
138+ int defStyle = com .android .internal .R .attr .textAppearanceMisspelledSuggestion ;
139+ TypedArray typedArray = context .obtainStyledAttributes (
140+ null , com .android .internal .R .styleable .SuggestionSpan , defStyle , 0 );
141+ mMisspelledUnderlineThickness = typedArray .getDimension (
142+ com .android .internal .R .styleable .SuggestionSpan_textUnderlineThickness , 0 );
143+ mMisspelledUnderlineColor = typedArray .getColor (
144+ com .android .internal .R .styleable .SuggestionSpan_textUnderlineColor , Color .BLACK );
145+
146+ defStyle = com .android .internal .R .attr .textAppearanceEasyCorrectSuggestion ;
146147
147- TypedArray typedArray = context .obtainStyledAttributes (null ,
148- com .android .internal .R .styleable .SuggestionSpan ,
149- defStyle , 0 );
148+ typedArray = context .obtainStyledAttributes (
149+ null , com .android .internal .R .styleable .SuggestionSpan , defStyle , 0 );
150150
151- mUnderlineThickness = typedArray .getDimension (
151+ mEasyCorrectUnderlineThickness = typedArray .getDimension (
152152 com .android .internal .R .styleable .SuggestionSpan_textUnderlineThickness , 0 );
153- mUnderlineColor = typedArray .getColor (
153+ mEasyCorrectUnderlineColor = typedArray .getColor (
154154 com .android .internal .R .styleable .SuggestionSpan_textUnderlineColor , Color .BLACK );
155155 }
156156
@@ -160,8 +160,10 @@ public SuggestionSpan(Parcel src) {
160160 mLocaleString = src .readString ();
161161 mNotificationTargetClassName = src .readString ();
162162 mHashCode = src .readInt ();
163- mUnderlineColor = src .readInt ();
164- mUnderlineThickness = src .readFloat ();
163+ mEasyCorrectUnderlineColor = src .readInt ();
164+ mEasyCorrectUnderlineThickness = src .readFloat ();
165+ mMisspelledUnderlineColor = src .readInt ();
166+ mMisspelledUnderlineThickness = src .readFloat ();
165167 }
166168
167169 /**
@@ -211,8 +213,10 @@ public void writeToParcel(Parcel dest, int flags) {
211213 dest .writeString (mLocaleString );
212214 dest .writeString (mNotificationTargetClassName );
213215 dest .writeInt (mHashCode );
214- dest .writeInt (mUnderlineColor );
215- dest .writeFloat (mUnderlineThickness );
216+ dest .writeInt (mEasyCorrectUnderlineColor );
217+ dest .writeFloat (mEasyCorrectUnderlineThickness );
218+ dest .writeInt (mMisspelledUnderlineColor );
219+ dest .writeFloat (mMisspelledUnderlineThickness );
216220 }
217221
218222 @ Override
@@ -254,6 +258,10 @@ public SuggestionSpan[] newArray(int size) {
254258
255259 @ Override
256260 public void updateDrawState (TextPaint tp ) {
257- tp .setUnderlineText (mUnderlineColor , mUnderlineThickness );
261+ if ((mFlags & FLAG_MISSPELLED ) != 0 ) {
262+ tp .setUnderlineText (mMisspelledUnderlineColor , mMisspelledUnderlineThickness );
263+ } else if ((mFlags & FLAG_EASY_CORRECT ) != 0 ) {
264+ tp .setUnderlineText (mEasyCorrectUnderlineColor , mEasyCorrectUnderlineThickness );
265+ }
258266 }
259267}
0 commit comments