Fix suggestions strip text colors

This change also shows the valid typed word in bold face.

Bug: 5161713
Change-Id: I15355a11888fc8ef90ecc8b64a52eb08c1a2b367
main
Tadashi G. Takaoka 2011-08-16 18:18:58 -07:00
parent b39f612d97
commit d47a955610
3 changed files with 24 additions and 16 deletions

View File

@ -107,10 +107,11 @@
</declare-styleable> </declare-styleable>
<declare-styleable name="CandidateView"> <declare-styleable name="CandidateView">
<attr name="autoCorrectHighlight" format="integer"> <attr name="suggestionStripOption" format="integer">
<flag name="autoCorrectBold" value="0x01" /> <flag name="autoCorrectBold" value="0x01" />
<flag name="autoCorrectUnderline" value="0x02" /> <flag name="autoCorrectUnderline" value="0x02" />
<flag name="autoCorrectInvert" value="0x04" /> <flag name="autoCorrectInvert" value="0x04" />
<flag name="validTypedWordBold" value="0x08" />
</attr> </attr>
<attr name="colorTypedWord" format="color" /> <attr name="colorTypedWord" format="color" />
<attr name="colorAutoCorrect" format="color" /> <attr name="colorAutoCorrect" format="color" />

View File

@ -85,7 +85,7 @@
<item name="android:background">@drawable/candidate_feedback_background</item> <item name="android:background">@drawable/candidate_feedback_background</item>
</style> </style>
<style name="CandidateViewStyle" parent="SuggestionsStripBackgroundStyle"> <style name="CandidateViewStyle" parent="SuggestionsStripBackgroundStyle">
<item name="autoCorrectHighlight">autoCorrectBold</item> <item name="suggestionStripOption">autoCorrectBold</item>
<item name="colorTypedWord">#FFFFFFFF</item> <item name="colorTypedWord">#FFFFFFFF</item>
<item name="colorAutoCorrect">#FFFCAE00</item> <item name="colorAutoCorrect">#FFFCAE00</item>
<item name="colorSuggested">#FFFCAE00</item> <item name="colorSuggested">#FFFCAE00</item>
@ -188,10 +188,10 @@
<item name="android:background">@drawable/keyboard_popup_panel_background_holo</item> <item name="android:background">@drawable/keyboard_popup_panel_background_holo</item>
</style> </style>
<style name="CandidateViewStyle.IceCreamSandwich" parent="SuggestionsStripBackgroundStyle.IceCreamSandwich"> <style name="CandidateViewStyle.IceCreamSandwich" parent="SuggestionsStripBackgroundStyle.IceCreamSandwich">
<item name="autoCorrectHighlight">autoCorrectBold</item> <item name="suggestionStripOption">autoCorrectBold|validTypedWordBold</item>
<item name="colorTypedWord">#FFFFFFFF</item> <item name="colorTypedWord">#FFBCBEC0</item>
<item name="colorAutoCorrect">#FF3DC8FF</item> <item name="colorAutoCorrect">#FF0099CC</item>
<item name="colorSuggested">#FFFFFFFF</item> <item name="colorSuggested">#FFA7A9AC</item>
<item name="candidateCountInStrip">@integer/candidate_count_in_strip</item> <item name="candidateCountInStrip">@integer/candidate_count_in_strip</item>
<item name="centerCandidatePercentile">@integer/center_candidate_percentile</item> <item name="centerCandidatePercentile">@integer/center_candidate_percentile</item>
</style> </style>

View File

@ -272,9 +272,10 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
private static final int AUTO_CORRECT_BOLD = 0x01; private static final int AUTO_CORRECT_BOLD = 0x01;
private static final int AUTO_CORRECT_UNDERLINE = 0x02; private static final int AUTO_CORRECT_UNDERLINE = 0x02;
private static final int AUTO_CORRECT_INVERT = 0x04; private static final int AUTO_CORRECT_INVERT = 0x04;
private static final int VALID_TYPED_WORD_BOLD = 0x08;
private final TextPaint mPaint; private final TextPaint mPaint;
private final int mAutoCorrectHighlight; private final int mSuggestionStripOption;
private final ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(); private final ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>();
@ -285,7 +286,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
super(words, dividers, infos); super(words, dividers, infos);
final TypedArray a = context.obtainStyledAttributes( final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.CandidateView, defStyle, R.style.CandidateViewStyle); attrs, R.styleable.CandidateView, defStyle, R.style.CandidateViewStyle);
mAutoCorrectHighlight = a.getInt(R.styleable.CandidateView_autoCorrectHighlight, 0); mSuggestionStripOption = a.getInt(R.styleable.CandidateView_suggestionStripOption, 0);
mColorTypedWord = a.getColor(R.styleable.CandidateView_colorTypedWord, 0); mColorTypedWord = a.getColor(R.styleable.CandidateView_colorTypedWord, 0);
mColorAutoCorrect = a.getColor(R.styleable.CandidateView_colorAutoCorrect, 0); mColorAutoCorrect = a.getColor(R.styleable.CandidateView_colorAutoCorrect, 0);
mColorSuggestedCandidate = a.getColor(R.styleable.CandidateView_colorSuggested, 0); mColorSuggestedCandidate = a.getColor(R.styleable.CandidateView_colorSuggested, 0);
@ -313,15 +314,23 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
return mColorTypedWord; return mColorTypedWord;
} }
private CharSequence getStyledCandidateWord(CharSequence word, boolean isAutoCorrect) { private CharSequence getStyledCandidateWord(SuggestedWords suggestions, int pos) {
if (!isAutoCorrect) final CharSequence word = suggestions.getWord(pos);
final boolean isAutoCorrect = pos == 1 && willAutoCorrect(suggestions);
final boolean isTypedWordValid = pos == 0 && suggestions.mTypedWordValid;
if (!isAutoCorrect && !isTypedWordValid)
return word; return word;
final int len = word.length(); final int len = word.length();
final Spannable spannedWord = new SpannableString(word); final Spannable spannedWord = new SpannableString(word);
if ((mAutoCorrectHighlight & AUTO_CORRECT_BOLD) != 0) final int option = mSuggestionStripOption;
if ((isAutoCorrect && (option & AUTO_CORRECT_BOLD) != 0)
|| (isTypedWordValid && (option & VALID_TYPED_WORD_BOLD) != 0)) {
spannedWord.setSpan(BOLD_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannedWord.setSpan(BOLD_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
if ((mAutoCorrectHighlight & AUTO_CORRECT_UNDERLINE) != 0) }
if (isAutoCorrect && (option & AUTO_CORRECT_UNDERLINE) != 0) {
spannedWord.setSpan(UNDERLINE_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannedWord.setSpan(UNDERLINE_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
return spannedWord; return spannedWord;
} }
@ -370,7 +379,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
} }
public CharSequence getInvertedText(CharSequence text) { public CharSequence getInvertedText(CharSequence text) {
if ((mAutoCorrectHighlight & AUTO_CORRECT_INVERT) == 0) if ((mSuggestionStripOption & AUTO_CORRECT_INVERT) == 0)
return null; return null;
final int len = text.length(); final int len = text.length();
final Spannable word = new SpannableString(text); final Spannable word = new SpannableString(text);
@ -457,9 +466,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
mTexts.clear(); mTexts.clear();
final int count = Math.min(suggestions.size(), countInStrip); final int count = Math.min(suggestions.size(), countInStrip);
for (int pos = 0; pos < count; pos++) { for (int pos = 0; pos < count; pos++) {
final CharSequence word = suggestions.getWord(pos); final CharSequence styled = getStyledCandidateWord(suggestions, pos);
final boolean isAutoCorrect = pos == 1 && willAutoCorrect(suggestions);
final CharSequence styled = getStyledCandidateWord(word, isAutoCorrect);
mTexts.add(styled); mTexts.add(styled);
} }
for (int pos = count; pos < countInStrip; pos++) { for (int pos = count; pos < countInStrip; pos++) {