Merge "Add a hidden flag for the auto correction indicator in SuggestionSpan"

This commit is contained in:
satok
2011-10-10 01:08:27 -07:00
committed by Android (Google) Code Review
4 changed files with 38 additions and 2 deletions

View File

@@ -56,6 +56,14 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan {
*/
public static final int FLAG_MISSPELLED = 0x0002;
/**
* Sets this flag if the auto correction is about to be applied to a word/text
* that the user is typing/composing. This type of suggestion is rendered differently
* to indicate the auto correction is happening.
* @hide
*/
public static final int FLAG_AUTO_CORRECTION = 0x0004;
public static final String ACTION_SUGGESTION_PICKED = "android.text.style.SUGGESTION_PICKED";
public static final String SUGGESTION_SPAN_PICKED_AFTER = "after";
public static final String SUGGESTION_SPAN_PICKED_BEFORE = "before";
@@ -82,6 +90,9 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan {
private float mMisspelledUnderlineThickness;
private int mMisspelledUnderlineColor;
private float mAutoCorrectionUnderlineThickness;
private int mAutoCorrectionUnderlineColor;
/*
* TODO: If switching IME is required, needs to add parameters for ids of InputMethodInfo
* and InputMethodSubtype.
@@ -145,14 +156,21 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan {
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);
defStyle = com.android.internal.R.attr.textAppearanceAutoCorrectionSuggestion;
typedArray = context.obtainStyledAttributes(
null, com.android.internal.R.styleable.SuggestionSpan, defStyle, 0);
mAutoCorrectionUnderlineThickness = typedArray.getDimension(
com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0);
mAutoCorrectionUnderlineColor = typedArray.getColor(
com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK);
}
public SuggestionSpan(Parcel src) {
@@ -165,6 +183,8 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan {
mEasyCorrectUnderlineThickness = src.readFloat();
mMisspelledUnderlineColor = src.readInt();
mMisspelledUnderlineThickness = src.readFloat();
mAutoCorrectionUnderlineColor = src.readInt();
mAutoCorrectionUnderlineThickness = src.readFloat();
}
/**
@@ -218,6 +238,8 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan {
dest.writeFloat(mEasyCorrectUnderlineThickness);
dest.writeInt(mMisspelledUnderlineColor);
dest.writeFloat(mMisspelledUnderlineThickness);
dest.writeInt(mAutoCorrectionUnderlineColor);
dest.writeFloat(mAutoCorrectionUnderlineThickness);
}
@Override
@@ -261,6 +283,7 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan {
public void updateDrawState(TextPaint tp) {
final boolean misspelled = (mFlags & FLAG_MISSPELLED) != 0;
final boolean easy = (mFlags & FLAG_EASY_CORRECT) != 0;
final boolean autoCorrection = (mFlags & FLAG_AUTO_CORRECTION) != 0;
if (easy) {
if (!misspelled) {
tp.setUnderlineText(mEasyCorrectUnderlineColor, mEasyCorrectUnderlineThickness);
@@ -269,6 +292,8 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan {
// than just easy, do not apply misspelled if an easy (or a mispelled) has been set
tp.setUnderlineText(mMisspelledUnderlineColor, mMisspelledUnderlineThickness);
}
} else if (autoCorrection) {
tp.setUnderlineText(mAutoCorrectionUnderlineColor, mAutoCorrectionUnderlineThickness);
}
}
@@ -281,12 +306,15 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan {
// The order here should match what is used in updateDrawState
final boolean misspelled = (mFlags & FLAG_MISSPELLED) != 0;
final boolean easy = (mFlags & FLAG_EASY_CORRECT) != 0;
final boolean autoCorrection = (mFlags & FLAG_AUTO_CORRECTION) != 0;
if (easy) {
if (!misspelled) {
return mEasyCorrectUnderlineColor;
} else {
return mMisspelledUnderlineColor;
}
} else if (autoCorrection) {
return mAutoCorrectionUnderlineColor;
}
return 0;
}

View File

@@ -158,6 +158,9 @@
<!-- The underline color and thickness for misspelled suggestion -->
<attr name="textAppearanceMisspelledSuggestion" format="reference" />
<!-- The underline color and thickness for auto correction suggestion -->
<attr name="textAppearanceAutoCorrectionSuggestion" format="reference" />
<!-- The underline color -->
<attr name="textUnderlineColor" format="reference|color" />
<!-- The underline thickness -->

View File

@@ -257,6 +257,10 @@ please see styles_device_defaults.xml.
<item name="android:textUnderlineColor">@color/holo_red_light</item>
</style>
<style name="TextAppearance.AutoCorrectionSuggestion" parent="TextAppearance.Suggestion">
<item name="android:textUnderlineColor">@color/holo_blue_light</item>
</style>
<!-- Widget Styles -->
<style name="Widget">

View File

@@ -91,6 +91,7 @@ please see themes_device_defaults.xml.
<item name="textAppearanceEasyCorrectSuggestion">@android:style/TextAppearance.EasyCorrectSuggestion</item>
<item name="textAppearanceMisspelledSuggestion">@android:style/TextAppearance.MisspelledSuggestion</item>
<item name="textAppearanceAutoCorrectionSuggestion">@android:style/TextAppearance.AutoCorrectionSuggestion</item>
<item name="textAppearanceButton">@android:style/TextAppearance.Widget.Button</item>