Loading core/java/android/text/style/SuggestionSpan.java +31 −23 Original line number Diff line number Diff line Loading @@ -76,8 +76,11 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { private final String mNotificationTargetClassName; private final int mHashCode; private float mUnderlineThickness; private int mUnderlineColor; private float mEasyCorrectUnderlineThickness; private int mEasyCorrectUnderlineColor; private float mMisspelledUnderlineThickness; private int mMisspelledUnderlineColor; /* * TODO: If switching IME is required, needs to add parameters for ids of InputMethodInfo Loading Loading @@ -132,25 +135,22 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { } private void initStyle(Context context) { int defStyle = 0; if ((getFlags() & FLAG_MISSPELLED) != 0) { defStyle = com.android.internal.R.attr.textAppearanceMisspelledSuggestion; } else if ((getFlags() & FLAG_EASY_CORRECT) != 0) { int defStyle = com.android.internal.R.attr.textAppearanceMisspelledSuggestion; TypedArray typedArray = context.obtainStyledAttributes( null, com.android.internal.R.styleable.SuggestionSpan, defStyle, 0); mMisspelledUnderlineThickness = typedArray.getDimension( com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0); mMisspelledUnderlineColor = typedArray.getColor( com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK); defStyle = com.android.internal.R.attr.textAppearanceEasyCorrectSuggestion; } else { // No style is applied. mUnderlineThickness = 0; mUnderlineColor = 0; return; } TypedArray typedArray = context.obtainStyledAttributes(null, com.android.internal.R.styleable.SuggestionSpan, defStyle, 0); typedArray = context.obtainStyledAttributes( null, com.android.internal.R.styleable.SuggestionSpan, defStyle, 0); mUnderlineThickness = typedArray.getDimension( mEasyCorrectUnderlineThickness = typedArray.getDimension( com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0); mUnderlineColor = typedArray.getColor( mEasyCorrectUnderlineColor = typedArray.getColor( com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK); } Loading @@ -160,8 +160,10 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { mLocaleString = src.readString(); mNotificationTargetClassName = src.readString(); mHashCode = src.readInt(); mUnderlineColor = src.readInt(); mUnderlineThickness = src.readFloat(); mEasyCorrectUnderlineColor = src.readInt(); mEasyCorrectUnderlineThickness = src.readFloat(); mMisspelledUnderlineColor = src.readInt(); mMisspelledUnderlineThickness = src.readFloat(); } /** Loading Loading @@ -211,8 +213,10 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { dest.writeString(mLocaleString); dest.writeString(mNotificationTargetClassName); dest.writeInt(mHashCode); dest.writeInt(mUnderlineColor); dest.writeFloat(mUnderlineThickness); dest.writeInt(mEasyCorrectUnderlineColor); dest.writeFloat(mEasyCorrectUnderlineThickness); dest.writeInt(mMisspelledUnderlineColor); dest.writeFloat(mMisspelledUnderlineThickness); } @Override Loading Loading @@ -254,6 +258,10 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { @Override public void updateDrawState(TextPaint tp) { tp.setUnderlineText(mUnderlineColor, mUnderlineThickness); if ((mFlags & FLAG_MISSPELLED) != 0) { tp.setUnderlineText(mMisspelledUnderlineColor, mMisspelledUnderlineThickness); } else if ((mFlags & FLAG_EASY_CORRECT) != 0) { tp.setUnderlineText(mEasyCorrectUnderlineColor, mEasyCorrectUnderlineThickness); } } } core/java/android/widget/TextView.java +21 −0 Original line number Diff line number Diff line Loading @@ -8121,6 +8121,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener Selection.setSelection((Spannable) mText, selStart, selEnd); } else { hideControllers(); downgradeEasyCorrectionSpans(); } // No need to create the controller Loading Loading @@ -8327,6 +8328,26 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return false; } /** * Downgrades to simple suggestions all the easy correction spans that are not a spell check * span. */ private void downgradeEasyCorrectionSpans() { if (mText instanceof Spannable) { Spannable spannable = (Spannable) mText; SuggestionSpan[] suggestionSpans = spannable.getSpans(0, spannable.length(), SuggestionSpan.class); for (int i = 0; i < suggestionSpans.length; i++) { int flags = suggestionSpans[i].getFlags(); if ((flags & SuggestionSpan.FLAG_EASY_CORRECT) != 0 && (flags & SuggestionSpan.FLAG_MISSPELLED) == 0) { flags = flags & ~SuggestionSpan.FLAG_EASY_CORRECT; suggestionSpans[i].setFlags(flags); } } } } @Override public boolean onGenericMotionEvent(MotionEvent event) { if (mMovement != null && mText instanceof Spannable && mLayout != null) { Loading Loading
core/java/android/text/style/SuggestionSpan.java +31 −23 Original line number Diff line number Diff line Loading @@ -76,8 +76,11 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { private final String mNotificationTargetClassName; private final int mHashCode; private float mUnderlineThickness; private int mUnderlineColor; private float mEasyCorrectUnderlineThickness; private int mEasyCorrectUnderlineColor; private float mMisspelledUnderlineThickness; private int mMisspelledUnderlineColor; /* * TODO: If switching IME is required, needs to add parameters for ids of InputMethodInfo Loading Loading @@ -132,25 +135,22 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { } private void initStyle(Context context) { int defStyle = 0; if ((getFlags() & FLAG_MISSPELLED) != 0) { defStyle = com.android.internal.R.attr.textAppearanceMisspelledSuggestion; } else if ((getFlags() & FLAG_EASY_CORRECT) != 0) { int defStyle = com.android.internal.R.attr.textAppearanceMisspelledSuggestion; TypedArray typedArray = context.obtainStyledAttributes( null, com.android.internal.R.styleable.SuggestionSpan, defStyle, 0); mMisspelledUnderlineThickness = typedArray.getDimension( com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0); mMisspelledUnderlineColor = typedArray.getColor( com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK); defStyle = com.android.internal.R.attr.textAppearanceEasyCorrectSuggestion; } else { // No style is applied. mUnderlineThickness = 0; mUnderlineColor = 0; return; } TypedArray typedArray = context.obtainStyledAttributes(null, com.android.internal.R.styleable.SuggestionSpan, defStyle, 0); typedArray = context.obtainStyledAttributes( null, com.android.internal.R.styleable.SuggestionSpan, defStyle, 0); mUnderlineThickness = typedArray.getDimension( mEasyCorrectUnderlineThickness = typedArray.getDimension( com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0); mUnderlineColor = typedArray.getColor( mEasyCorrectUnderlineColor = typedArray.getColor( com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK); } Loading @@ -160,8 +160,10 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { mLocaleString = src.readString(); mNotificationTargetClassName = src.readString(); mHashCode = src.readInt(); mUnderlineColor = src.readInt(); mUnderlineThickness = src.readFloat(); mEasyCorrectUnderlineColor = src.readInt(); mEasyCorrectUnderlineThickness = src.readFloat(); mMisspelledUnderlineColor = src.readInt(); mMisspelledUnderlineThickness = src.readFloat(); } /** Loading Loading @@ -211,8 +213,10 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { dest.writeString(mLocaleString); dest.writeString(mNotificationTargetClassName); dest.writeInt(mHashCode); dest.writeInt(mUnderlineColor); dest.writeFloat(mUnderlineThickness); dest.writeInt(mEasyCorrectUnderlineColor); dest.writeFloat(mEasyCorrectUnderlineThickness); dest.writeInt(mMisspelledUnderlineColor); dest.writeFloat(mMisspelledUnderlineThickness); } @Override Loading Loading @@ -254,6 +258,10 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { @Override public void updateDrawState(TextPaint tp) { tp.setUnderlineText(mUnderlineColor, mUnderlineThickness); if ((mFlags & FLAG_MISSPELLED) != 0) { tp.setUnderlineText(mMisspelledUnderlineColor, mMisspelledUnderlineThickness); } else if ((mFlags & FLAG_EASY_CORRECT) != 0) { tp.setUnderlineText(mEasyCorrectUnderlineColor, mEasyCorrectUnderlineThickness); } } }
core/java/android/widget/TextView.java +21 −0 Original line number Diff line number Diff line Loading @@ -8121,6 +8121,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener Selection.setSelection((Spannable) mText, selStart, selEnd); } else { hideControllers(); downgradeEasyCorrectionSpans(); } // No need to create the controller Loading Loading @@ -8327,6 +8328,26 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return false; } /** * Downgrades to simple suggestions all the easy correction spans that are not a spell check * span. */ private void downgradeEasyCorrectionSpans() { if (mText instanceof Spannable) { Spannable spannable = (Spannable) mText; SuggestionSpan[] suggestionSpans = spannable.getSpans(0, spannable.length(), SuggestionSpan.class); for (int i = 0; i < suggestionSpans.length; i++) { int flags = suggestionSpans[i].getFlags(); if ((flags & SuggestionSpan.FLAG_EASY_CORRECT) != 0 && (flags & SuggestionSpan.FLAG_MISSPELLED) == 0) { flags = flags & ~SuggestionSpan.FLAG_EASY_CORRECT; suggestionSpans[i].setFlags(flags); } } } } @Override public boolean onGenericMotionEvent(MotionEvent event) { if (mMovement != null && mText instanceof Spannable && mLayout != null) { Loading