From d47a955610987c8abdab4d275c044aefc8a7f1db Mon Sep 17 00:00:00 2001
From: "Tadashi G. Takaoka" <takaoka@google.com>
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 172ca2f253..4cabe93a89 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -107,10 +107,11 @@
     </declare-styleable>
 
     <declare-styleable name="CandidateView">
-        <attr name="autoCorrectHighlight" format="integer">
+        <attr name="suggestionStripOption" format="integer">
             <flag name="autoCorrectBold" value="0x01" />
             <flag name="autoCorrectUnderline" value="0x02" />
             <flag name="autoCorrectInvert" value="0x04" />
+            <flag name="validTypedWordBold" value="0x08" />
         </attr>
         <attr name="colorTypedWord" format="color" />
         <attr name="colorAutoCorrect" format="color" />
diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml
index 8145d0510e..cb9edb0b88 100644
--- a/java/res/values/styles.xml
+++ b/java/res/values/styles.xml
@@ -85,7 +85,7 @@
         <item name="android:background">@drawable/candidate_feedback_background</item>
     </style>
     <style name="CandidateViewStyle" parent="SuggestionsStripBackgroundStyle">
-        <item name="autoCorrectHighlight">autoCorrectBold</item>
+        <item name="suggestionStripOption">autoCorrectBold</item>
         <item name="colorTypedWord">#FFFFFFFF</item>
         <item name="colorAutoCorrect">#FFFCAE00</item>
         <item name="colorSuggested">#FFFCAE00</item>
@@ -188,10 +188,10 @@
         <item name="android:background">@drawable/keyboard_popup_panel_background_holo</item>
     </style>
     <style name="CandidateViewStyle.IceCreamSandwich" parent="SuggestionsStripBackgroundStyle.IceCreamSandwich">
-        <item name="autoCorrectHighlight">autoCorrectBold</item>
-        <item name="colorTypedWord">#FFFFFFFF</item>
-        <item name="colorAutoCorrect">#FF3DC8FF</item>
-        <item name="colorSuggested">#FFFFFFFF</item>
+        <item name="suggestionStripOption">autoCorrectBold|validTypedWordBold</item>
+        <item name="colorTypedWord">#FFBCBEC0</item>
+        <item name="colorAutoCorrect">#FF0099CC</item>
+        <item name="colorSuggested">#FFA7A9AC</item>
         <item name="candidateCountInStrip">@integer/candidate_count_in_strip</item>
         <item name="centerCandidatePercentile">@integer/center_candidate_percentile</item>
     </style>
diff --git a/java/src/com/android/inputmethod/latin/CandidateView.java b/java/src/com/android/inputmethod/latin/CandidateView.java
index f499bc0bbb..d46b4b5b58 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<CharSequence> mTexts = new ArrayList<CharSequence>();
 
@@ -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++) {
-- 
GitLab