Merge "Symbols shift key shoud have small greek pi"
diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index 0550606..475e92f 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -175,7 +175,7 @@
     </declare-styleable>
 
     <declare-styleable name="SuggestionStripView">
-        <attr name="suggestionStripOption" format="integer">
+        <attr name="suggestionStripOptions" format="integer">
             <!-- This should be aligned with SuggestionStripLayoutHelper.AUTO_CORRECT_* and etc. -->
             <flag name="autoCorrectBold" value="0x01" />
             <flag name="autoCorrectUnderline" value="0x02" />
diff --git a/java/res/values/themes-gb.xml b/java/res/values/themes-gb.xml
index a460d4f..c189da3 100644
--- a/java/res/values/themes-gb.xml
+++ b/java/res/values/themes-gb.xml
@@ -133,7 +133,7 @@
         parent="SuggestionStripView"
     >
         <item name="android:background">@drawable/keyboard_suggest_strip_gb</item>
-        <item name="suggestionStripOption">autoCorrectBold|validTypedWordBold</item>
+        <item name="suggestionStripOptions">autoCorrectBold|validTypedWordBold</item>
         <item name="colorValidTypedWord">@color/highlight_color_gb</item>
         <item name="colorTypedWord">@color/typed_word_color_gb</item>
         <item name="colorAutoCorrect">@color/highlight_color_gb</item>
diff --git a/java/res/values/themes-ics.xml b/java/res/values/themes-ics.xml
index caea921..720eda9 100644
--- a/java/res/values/themes-ics.xml
+++ b/java/res/values/themes-ics.xml
@@ -112,7 +112,7 @@
         parent="SuggestionStripView"
     >
         <item name="android:background">@drawable/keyboard_suggest_strip_holo</item>
-        <item name="suggestionStripOption">autoCorrectBold|validTypedWordBold</item>
+        <item name="suggestionStripOptions">autoCorrectBold|validTypedWordBold</item>
         <item name="colorValidTypedWord">@color/typed_word_color_ics</item>
         <item name="colorTypedWord">@color/typed_word_color_ics</item>
         <item name="colorAutoCorrect">@color/highlight_color_ics</item>
diff --git a/java/res/values/themes-klp.xml b/java/res/values/themes-klp.xml
index 0599fb6..8305271 100644
--- a/java/res/values/themes-klp.xml
+++ b/java/res/values/themes-klp.xml
@@ -112,7 +112,7 @@
         parent="SuggestionStripView"
     >
         <item name="android:background">@drawable/keyboard_suggest_strip_holo</item>
-        <item name="suggestionStripOption">autoCorrectBold|validTypedWordBold</item>
+        <item name="suggestionStripOptions">autoCorrectBold|validTypedWordBold</item>
         <item name="colorValidTypedWord">@color/typed_word_color_klp</item>
         <item name="colorTypedWord">@color/typed_word_color_klp</item>
         <item name="colorAutoCorrect">@color/highlight_color_klp</item>
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index abf831a..5e14410 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -147,6 +147,8 @@
             }
         }
 
+        final boolean isPrediction = !wordComposer.isComposingWord();
+
         // We allow auto-correction if we have a whitelisted word, or if the word is not a valid
         // word of more than 1 char, except if the first suggestion is the same as the typed string
         // because in this case if it's strong enough to auto-correct that will mistakenly designate
@@ -165,7 +167,7 @@
         // same time, it feels wrong that the SuggestedWord object includes information about
         // the current settings. It may also be useful to know, when the setting is off, whether
         // the word *would* have been auto-corrected.
-        if (!isCorrectionEnabled || !allowsToBeAutoCorrected || !wordComposer.isComposingWord()
+        if (!isCorrectionEnabled || !allowsToBeAutoCorrected || isPrediction
                 || suggestionsSet.isEmpty() || wordComposer.hasDigits()
                 || wordComposer.isMostlyCaps() || wordComposer.isResumed()
                 || !mDictionaryFacilitator.hasMainDictionary()
@@ -225,10 +227,9 @@
                 // TODO: this first argument is lying. If this is a whitelisted word which is an
                 // actual word, it says typedWordValid = false, which looks wrong. We should either
                 // rename the attribute or change the value.
-                !allowsToBeAutoCorrected /* typedWordValid */,
+                !isPrediction && !allowsToBeAutoCorrected /* typedWordValid */,
                 hasAutoCorrection, /* willAutoCorrect */
-                false /* isObsoleteSuggestions */,
-                !wordComposer.isComposingWord() /* isPrediction */, sequenceNumber));
+                false /* isObsoleteSuggestions */, isPrediction, sequenceNumber));
     }
 
     // Retrieves suggestions for the batch input
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index 46df3e8..06bc90c 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -69,7 +69,7 @@
             final boolean isPrediction,
             final int sequenceNumber) {
         this(suggestedWordInfoList, rawSuggestions,
-                suggestedWordInfoList.isEmpty() ? null
+                (suggestedWordInfoList.isEmpty() || isPrediction) ? null
                         : suggestedWordInfoList.get(INDEX_OF_TYPED_WORD).mWord,
                 typedWordValid, willAutoCorrect, isObsoleteSuggestions, isPrediction,
                 sequenceNumber);
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 045d06f..f2f9f1e 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -1360,10 +1360,12 @@
                         }});
         } else {
             // We found suggestion spans in the word. We'll create the SuggestedWords out of
-            // them, and make willAutoCorrect false.
+            // them, and make willAutoCorrect false. We make typedWordValid false, because the
+            // color of the word in the suggestion strip changes according to this parameter,
+            // and false gives the correct color.
             final SuggestedWords suggestedWords = new SuggestedWords(suggestions,
                     null /* rawSuggestions */, typedWord,
-                    true /* typedWordValid */, false /* willAutoCorrect */,
+                    false /* typedWordValid */, false /* willAutoCorrect */,
                     false /* isObsoleteSuggestions */, false /* isPrediction */,
                     SuggestedWords.NOT_A_SEQUENCE_NUMBER);
             mIsAutoCorrectionIndicatorOn = false;
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
index 8ea7128..afa8fe3 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
@@ -95,9 +95,9 @@
     private static final CharacterStyle BOLD_SPAN = new StyleSpan(Typeface.BOLD);
     private static final CharacterStyle UNDERLINE_SPAN = new UnderlineSpan();
 
-    private final int mSuggestionStripOption;
+    private final int mSuggestionStripOptions;
     // These constants are the flag values of
-    // {@link R.styleable#SuggestionStripView_suggestionStripOption} attribute.
+    // {@link R.styleable#SuggestionStripView_suggestionStripOptions} attribute.
     private static final int AUTO_CORRECT_BOLD = 0x01;
     private static final int AUTO_CORRECT_UNDERLINE = 0x02;
     private static final int VALID_TYPED_WORD_BOLD = 0x04;
@@ -122,8 +122,8 @@
 
         final TypedArray a = context.obtainStyledAttributes(attrs,
                 R.styleable.SuggestionStripView, defStyle, R.style.SuggestionStripView);
-        mSuggestionStripOption = a.getInt(
-                R.styleable.SuggestionStripView_suggestionStripOption, 0);
+        mSuggestionStripOptions = a.getInt(
+                R.styleable.SuggestionStripView_suggestionStripOptions, 0);
         mAlphaObsoleted = ResourceUtils.getFraction(a,
                 R.styleable.SuggestionStripView_alphaObsoleted, 1.0f);
         mColorValidTypedWord = a.getColor(R.styleable.SuggestionStripView_colorValidTypedWord, 0);
@@ -200,22 +200,24 @@
             return null;
         }
         final String word = suggestedWords.getLabel(indexInSuggestedWords);
-        final boolean isAutoCorrect = indexInSuggestedWords == 1
-                && suggestedWords.mWillAutoCorrect;
-        final boolean isTypedWordValid = indexInSuggestedWords == 0
-                && suggestedWords.mTypedWordValid;
-        if (!isAutoCorrect && !isTypedWordValid) {
+        // TODO: don't use the index to decide whether this is the auto-correction/typed word, as
+        // this is brittle
+        final boolean isAutoCorrection = suggestedWords.mWillAutoCorrect
+                && indexInSuggestedWords == SuggestedWords.INDEX_OF_AUTO_CORRECTION;
+        final boolean isTypedWordValid = suggestedWords.mTypedWordValid
+                && indexInSuggestedWords == SuggestedWords.INDEX_OF_TYPED_WORD;
+        if (!isAutoCorrection && !isTypedWordValid) {
             return word;
         }
 
         final int len = word.length();
         final Spannable spannedWord = new SpannableString(word);
-        final int option = mSuggestionStripOption;
-        if ((isAutoCorrect && (option & AUTO_CORRECT_BOLD) != 0)
-                || (isTypedWordValid && (option & VALID_TYPED_WORD_BOLD) != 0)) {
+        final int options = mSuggestionStripOptions;
+        if ((isAutoCorrection && (options & AUTO_CORRECT_BOLD) != 0)
+                || (isTypedWordValid && (options & VALID_TYPED_WORD_BOLD) != 0)) {
             spannedWord.setSpan(BOLD_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
         }
-        if (isAutoCorrect && (option & AUTO_CORRECT_UNDERLINE) != 0) {
+        if (isAutoCorrection && (options & AUTO_CORRECT_UNDERLINE) != 0) {
             spannedWord.setSpan(UNDERLINE_SPAN, 0, len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
         }
         return spannedWord;
@@ -242,22 +244,23 @@
         return indexInSuggestedWords;
     }
 
-    private int getSuggestionTextColor(final int indexInSuggestedWords,
-            final SuggestedWords suggestedWords) {
+    private int getSuggestionTextColor(final SuggestedWords suggestedWords,
+            final int indexInSuggestedWords) {
         final int positionInStrip =
                 getPositionInSuggestionStrip(indexInSuggestedWords, suggestedWords);
-        // TODO: Need to revisit this logic with bigram suggestions
-        final boolean isSuggested = (indexInSuggestedWords != SuggestedWords.INDEX_OF_TYPED_WORD);
+        // Use identity for strings, not #equals : it's the typed word if it's the same object
+        final boolean isTypedWord =
+                suggestedWords.getWord(indexInSuggestedWords) == suggestedWords.mTypedWord;
 
         final int color;
         if (positionInStrip == mCenterPositionInStrip && suggestedWords.mWillAutoCorrect) {
             color = mColorAutoCorrect;
-        } else if (positionInStrip == mCenterPositionInStrip && suggestedWords.mTypedWordValid) {
+        } else if (isTypedWord && suggestedWords.mTypedWordValid) {
             color = mColorValidTypedWord;
-        } else if (isSuggested) {
-            color = mColorSuggested;
-        } else {
+        } else if (isTypedWord) {
             color = mColorTypedWord;
+        } else {
+            color = mColorSuggested;
         }
         if (LatinImeLogger.sDBG && suggestedWords.size() > 1) {
             // If we auto-correct, then the autocorrection is in slot 0 and the typed word
@@ -270,7 +273,7 @@
             }
         }
 
-        if (suggestedWords.mIsObsoleteSuggestions && isSuggested) {
+        if (suggestedWords.mIsObsoleteSuggestions && !isTypedWord) {
             return applyAlpha(color, mAlphaObsoleted);
         }
         return color;
@@ -438,7 +441,7 @@
             // {@link SuggestionStripView#onClick(View)}.
             wordView.setTag(indexInSuggestedWords);
             wordView.setText(getStyledSuggestedWord(suggestedWords, indexInSuggestedWords));
-            wordView.setTextColor(getSuggestionTextColor(positionInStrip, suggestedWords));
+            wordView.setTextColor(getSuggestionTextColor(suggestedWords, indexInSuggestedWords));
             if (SuggestionStripView.DBG) {
                 mDebugInfoViews.get(positionInStrip).setText(
                         suggestedWords.getDebugString(indexInSuggestedWords));