From d47a955610987c8abdab4d275c044aefc8a7f1db Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 16 Aug 2011 18:18:58 -0700 Subject: [PATCH] Fix suggestions strip text colors This change also shows the valid typed word in bold face. Bug: 5161713 Change-Id: I15355a11888fc8ef90ecc8b64a52eb08c1a2b367 --- java/res/values/attrs.xml | 3 ++- java/res/values/styles.xml | 10 +++---- .../inputmethod/latin/CandidateView.java | 27 ++++++++++++------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 172ca2f25..4cabe93a8 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -107,10 +107,11 @@ - + + diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index 8145d0510..cb9edb0b8 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -85,7 +85,7 @@ @drawable/candidate_feedback_background diff --git a/java/src/com/android/inputmethod/latin/CandidateView.java b/java/src/com/android/inputmethod/latin/CandidateView.java index f499bc0bb..d46b4b5b5 100644 --- a/java/src/com/android/inputmethod/latin/CandidateView.java +++ b/java/src/com/android/inputmethod/latin/CandidateView.java @@ -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_UNDERLINE = 0x02; private static final int AUTO_CORRECT_INVERT = 0x04; + private static final int VALID_TYPED_WORD_BOLD = 0x08; private final TextPaint mPaint; - private final int mAutoCorrectHighlight; + private final int mSuggestionStripOption; private final ArrayList mTexts = new ArrayList(); @@ -285,7 +286,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo super(words, dividers, infos); final TypedArray a = context.obtainStyledAttributes( 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); mColorAutoCorrect = a.getColor(R.styleable.CandidateView_colorAutoCorrect, 0); mColorSuggestedCandidate = a.getColor(R.styleable.CandidateView_colorSuggested, 0); @@ -313,15 +314,23 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo return mColorTypedWord; } - private CharSequence getStyledCandidateWord(CharSequence word, boolean isAutoCorrect) { - if (!isAutoCorrect) + private CharSequence getStyledCandidateWord(SuggestedWords suggestions, int pos) { + 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; + final int len = word.length(); 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); - if ((mAutoCorrectHighlight & AUTO_CORRECT_UNDERLINE) != 0) + } + if (isAutoCorrect && (option & AUTO_CORRECT_UNDERLINE) != 0) { spannedWord.setSpan(UNDERLINE_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); + } return spannedWord; } @@ -370,7 +379,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo } public CharSequence getInvertedText(CharSequence text) { - if ((mAutoCorrectHighlight & AUTO_CORRECT_INVERT) == 0) + if ((mSuggestionStripOption & AUTO_CORRECT_INVERT) == 0) return null; final int len = text.length(); final Spannable word = new SpannableString(text); @@ -457,9 +466,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo mTexts.clear(); final int count = Math.min(suggestions.size(), countInStrip); for (int pos = 0; pos < count; pos++) { - final CharSequence word = suggestions.getWord(pos); - final boolean isAutoCorrect = pos == 1 && willAutoCorrect(suggestions); - final CharSequence styled = getStyledCandidateWord(word, isAutoCorrect); + final CharSequence styled = getStyledCandidateWord(suggestions, pos); mTexts.add(styled); } for (int pos = count; pos < countInStrip; pos++) {