am 572527f2: Merge "Remove the suggestion underline when the TextView loses focus."

* commit '572527f2c337ec9266ebcd931a66e17d2ae63e01':
  Remove the suggestion underline when the TextView loses focus.
This commit is contained in:
Gilles Debunne
2011-09-02 13:58:00 -07:00
committed by Android Git Automerger
2 changed files with 54 additions and 25 deletions

View File

@@ -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;
}
TypedArray typedArray = context.obtainStyledAttributes(null,
com.android.internal.R.styleable.SuggestionSpan,
defStyle, 0);
mUnderlineThickness = typedArray.getDimension(
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);
mUnderlineColor = typedArray.getColor(
mMisspelledUnderlineColor = typedArray.getColor(
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);
}
@@ -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);
}
}
}

View File

@@ -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
@@ -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) {