diff options
author | Luca Zanolin <zano@google.com> | 2011-09-02 19:41:42 +0100 |
---|---|---|
committer | Luca Zanolin <zano@google.com> | 2011-09-02 19:41:42 +0100 |
commit | fe5e9834a3086ab6bd99a4cb0d9273fdeb52ecd8 (patch) | |
tree | c0ebda1547417cdac9ef64a4e0800d003f2689a7 | |
parent | bffb83e96c2f3d01bf42490737201ab4de79c91b (diff) | |
download | frameworks_base-fe5e9834a3086ab6bd99a4cb0d9273fdeb52ecd8.zip frameworks_base-fe5e9834a3086ab6bd99a4cb0d9273fdeb52ecd8.tar.gz frameworks_base-fe5e9834a3086ab6bd99a4cb0d9273fdeb52ecd8.tar.bz2 |
Remove the suggestion underline when the TextView loses focus.
Only the easy correction (i.e., voice ime corrections) will lose the underline, while the misspelled span will not.
Change-Id: If96c17473dd70c99b808739ddde800cc93551e2a
-rw-r--r-- | core/java/android/text/style/SuggestionSpan.java | 54 | ||||
-rw-r--r-- | core/java/android/widget/TextView.java | 21 |
2 files changed, 52 insertions, 23 deletions
diff --git a/core/java/android/text/style/SuggestionSpan.java b/core/java/android/text/style/SuggestionSpan.java index 8625257..693a7a9 100644 --- a/core/java/android/text/style/SuggestionSpan.java +++ b/core/java/android/text/style/SuggestionSpan.java @@ -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 @@ -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) { - defStyle = com.android.internal.R.attr.textAppearanceEasyCorrectSuggestion; - } else { - // No style is applied. - mUnderlineThickness = 0; - mUnderlineColor = 0; - return; - } + 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; - 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); } @@ -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(); } /** @@ -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 @@ -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); + } } } diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 1aa009b..719740f 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -8119,6 +8119,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener Selection.setSelection((Spannable) mText, selStart, selEnd); } else { hideControllers(); + downgradeEasyCorrectionSpans(); } // No need to create the controller @@ -8328,6 +8329,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) { |