Fix auto correction threshold values array reference

This change also removes unused argument from Suggest.getSuggestions().

Change-Id: I512f8695d22898bb906e136a66e0ee6b521cd1d1
diff --git a/java/res/values/config.xml b/java/res/values/config.xml
index 456d9ad..0bb0e33 100644
--- a/java/res/values/config.xml
+++ b/java/res/values/config.xml
@@ -32,14 +32,14 @@
     <integer name="config_long_press_key_timeout">400</integer>
     <integer name="config_long_press_shift_key_timeout">1200</integer>
     <integer name="config_multi_tap_key_timeout">800</integer>
-    <string-array name="auto_complete_threshold_values">
-        <!-- Off, When auto completing setting is Off, this value is not used. -->
+    <string-array name="auto_correction_threshold_values">
+        <!-- Off, When auto correction setting is Off, this value is not used. -->
         <item></item>
         <!-- Modest : Suggestion whose normalized score is greater than this value
-             will be subject to auto-completion. -->
+             will be subject to auto-correction. -->
         <item>0.22</item>
         <!-- Aggressive : Suggestion whose normalized score is greater than this value
-             will be subject to auto-completion. -->
+             will be subject to auto-correction. -->
         <item>0</item>
     </string-array>
 </resources>
diff --git a/java/res/values/donottranslate.xml b/java/res/values/donottranslate.xml
index cfca4d6..5703729 100644
--- a/java/res/values/donottranslate.xml
+++ b/java/res/values/donottranslate.xml
@@ -65,13 +65,13 @@
        <item>@string/prefs_suggestion_visibility_hide_name</item>
     </string-array>
 
-    <string name="auto_correction_threshold_mode_value_off">0</string>
-    <string name="auto_correction_threshold_mode_value_modest">1</string>
-    <string name="auto_correction_threshold_mode_value_aggeressive">2</string>
-    <string-array name="auto_correction_threshold_mode_values">
-      <item>@string/auto_correction_threshold_mode_value_off</item>
-      <item>@string/auto_correction_threshold_mode_value_modest</item>
-      <item>@string/auto_correction_threshold_mode_value_aggeressive</item>
+    <string name="auto_correction_threshold_mode_index_off">0</string>
+    <string name="auto_correction_threshold_mode_index_modest">1</string>
+    <string name="auto_correction_threshold_mode_index_aggeressive">2</string>
+    <string-array name="auto_correction_threshold_mode_indexes">
+      <item>@string/auto_correction_threshold_mode_index_off</item>
+      <item>@string/auto_correction_threshold_mode_index_modest</item>
+      <item>@string/auto_correction_threshold_mode_index_aggeressive</item>
     </string-array>
     <string-array name="auto_correction_threshold_modes">
       <item>@string/auto_correction_threshold_mode_off</item>
diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml
index 1bc3395..0eee060 100644
--- a/java/res/xml/prefs.xml
+++ b/java/res/xml/prefs.xml
@@ -106,9 +106,9 @@
             android:title="@string/auto_correction"
             android:summary="@string/auto_correction_summary"
             android:persistent="true"
-            android:entryValues="@array/auto_correction_threshold_mode_values"
+            android:entryValues="@array/auto_correction_threshold_mode_indexes"
             android:entries="@array/auto_correction_threshold_modes"
-            android:defaultValue="@string/auto_correction_threshold_mode_value_modest"
+            android:defaultValue="@string/auto_correction_threshold_mode_index_modest"
             />
 
         <CheckBoxPreference
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 010473f..5a12320 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1438,8 +1438,10 @@
 
         if (mCandidateView != null) {
             mCandidateView.setSuggestions(words);
-            if (mCandidateView.isConfigCandidateHighlightFontColorEnabled())
-                mKeyboardSwitcher.onAutoCorrectionStateChanged(words.hasAutoCorrectionWord());
+            if (mCandidateView.isConfigCandidateHighlightFontColorEnabled()) {
+                mKeyboardSwitcher.onAutoCorrectionStateChanged(
+                        words.hasWordAboveAutoCorrectionScoreThreshold());
+            }
         }
     }
 
@@ -1460,8 +1462,7 @@
     }
 
     private SuggestedWords.Builder getTypedSuggestions(WordComposer word) {
-        return mSuggest.getSuggestedWordBuilder(
-                mKeyboardSwitcher.getInputView(), word, false, null);
+        return mSuggest.getSuggestedWordBuilder(mKeyboardSwitcher.getInputView(), word, null);
     }
 
     private void showCorrections(WordAlternatives alternatives) {
@@ -1477,9 +1478,7 @@
         CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(),
                 mWordSeparators);
         SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(
-                mKeyboardSwitcher.getInputView(), word, false, prevWord);
-        // long stopTime = System.currentTimeMillis(); // TIME MEASUREMENT!
-        // Log.d("LatinIME","Suggest Total Time - " + (stopTime - startTime));
+                mKeyboardSwitcher.getInputView(), word, prevWord);
 
         int[] nextLettersFrequencies = mSuggest.getNextLettersFrequencies();
         mKeyboardSwitcher.setPreferredLetters(nextLettersFrequencies);
@@ -1506,8 +1505,7 @@
     private void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) {
         setSuggestions(suggestedWords);
         if (suggestedWords.size() > 0) {
-            if (suggestedWords.mHasMinimalSuggestion
-                    && !suggestedWords.mTypedWordValid && suggestedWords.size() > 1) {
+            if (suggestedWords.hasAutoCorrectionWord()) {
                 mBestWord = suggestedWords.getWord(1);
             } else {
                 mBestWord = typedWord;
@@ -2067,9 +2065,9 @@
 
         final String currentAutoCorrectionSetting = sp.getString(
                 Settings.PREF_AUTO_CORRECTION_THRESHOLD,
-                mResources.getString(R.string.auto_correction_threshold_mode_value_modest));
+                mResources.getString(R.string.auto_correction_threshold_mode_index_modest));
         final String[] autoCorrectionThresholdValues = mResources.getStringArray(
-                R.array.auto_correction_threshold_mode_values);
+                R.array.auto_correction_threshold_values);
         // When autoCrrectionThreshold is greater than 1.0, auto correction is virtually turned off.
         double autoCorrectionThreshold = Double.MAX_VALUE;
         try {
@@ -2094,9 +2092,9 @@
     private boolean isAutoCorrectEnabled(SharedPreferences sp) {
         final String currentAutoCorrectionSetting = sp.getString(
                 Settings.PREF_AUTO_CORRECTION_THRESHOLD,
-                mResources.getString(R.string.auto_correction_threshold_mode_value_modest));
+                mResources.getString(R.string.auto_correction_threshold_mode_index_modest));
         final String autoCorrectionOff = mResources.getString(
-                R.string.auto_correction_threshold_mode_value_off);
+                R.string.auto_correction_threshold_mode_index_off);
         return !currentAutoCorrectionSetting.equals(autoCorrectionOff);
     }
 
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index d2ec917..b8590a7 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -79,7 +79,7 @@
 
     private void ensureConsistencyOfAutoCorrectionSettings() {
         final String autoCorrectionOff = getResources().getString(
-                R.string.auto_correction_threshold_mode_value_off);
+                R.string.auto_correction_threshold_mode_index_off);
         final String currentSetting = mAutoCorrectionThreshold.getValue();
         mBigramSuggestion.setEnabled(!currentSetting.equals(autoCorrectionOff));
     }
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 77e0a3d..a30ec15 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -95,7 +95,6 @@
     ArrayList<CharSequence> mBigramSuggestions  = new ArrayList<CharSequence>();
     private ArrayList<CharSequence> mStringPool = new ArrayList<CharSequence>();
     private boolean mHaveCorrection;
-    private CharSequence mOriginalWord;
     private String mLowerOriginalWord;
 
     // TODO: Remove these member variables by passing more context to addWord() callback method
@@ -197,14 +196,13 @@
      * @return suggested words object.
      */
     public SuggestedWords getSuggestions(View view, WordComposer wordComposer,
-            boolean includeTypedWordIfValid, CharSequence prevWordForBigram) {
-        return getSuggestedWordBuilder(view, wordComposer, includeTypedWordIfValid,
-                prevWordForBigram).build();
+            CharSequence prevWordForBigram) {
+        return getSuggestedWordBuilder(view, wordComposer, prevWordForBigram).build();
     }
 
     // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder
     public SuggestedWords.Builder getSuggestedWordBuilder(View view, WordComposer wordComposer,
-            boolean includeTypedWordIfValid, CharSequence prevWordForBigram) {
+            CharSequence prevWordForBigram) {
         LatinImeLogger.onStartSuggestion(prevWordForBigram);
         mHaveCorrection = false;
         mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized();
@@ -214,13 +212,13 @@
         Arrays.fill(mNextLettersFrequencies, 0);
 
         // Save a lowercase version of the original word
-        mOriginalWord = wordComposer.getTypedWord();
-        if (mOriginalWord != null) {
-            final String mOriginalWordString = mOriginalWord.toString();
-            mOriginalWord = mOriginalWordString;
-            mLowerOriginalWord = mOriginalWordString.toLowerCase();
+        CharSequence typedWord = wordComposer.getTypedWord();
+        if (typedWord != null) {
+            final String typedWordString = typedWord.toString();
+            typedWord = typedWordString;
+            mLowerOriginalWord = typedWordString.toLowerCase();
             // Treating USER_TYPED as UNIGRAM suggestion for logging now.
-            LatinImeLogger.onAddSuggestedWord(mOriginalWordString, Suggest.DIC_USER_TYPED,
+            LatinImeLogger.onAddSuggestedWord(typedWordString, Suggest.DIC_USER_TYPED,
                     Dictionary.DataType.UNIGRAM);
         } else {
             mLowerOriginalWord = "";
@@ -278,7 +276,7 @@
                     mContactsDictionary.getWords(wordComposer, this, mNextLettersFrequencies);
                 }
 
-                if (mSuggestions.size() > 0 && isValidWord(mOriginalWord)
+                if (mSuggestions.size() > 0 && isValidWord(typedWord)
                         && (mCorrectionMode == CORRECTION_FULL
                         || mCorrectionMode == CORRECTION_FULL_BIGRAM)) {
                     mHaveCorrection = true;
@@ -290,9 +288,9 @@
                 // TODO: when the normalized score of the first suggestion is nearly equals to
                 //       the normalized score of the second suggestion, behave less aggressive.
                 final double normalizedScore = Utils.calcNormalizedScore(
-                        mOriginalWord, mSuggestions.get(0), mPriorities[0]);
+                        typedWord, mSuggestions.get(0), mPriorities[0]);
                 if (LatinImeLogger.sDBG) {
-                    Log.d(TAG, "Normalized " + mOriginalWord + "," + mSuggestions.get(0) + ","
+                    Log.d(TAG, "Normalized " + typedWord + "," + mSuggestions.get(0) + ","
                             + mPriorities[0] + normalizedScore
                             + "(" + mAutoCorrectionThreshold + ")");
                 }
@@ -301,8 +299,8 @@
                 }
             }
         }
-        if (mOriginalWord != null) {
-            mSuggestions.add(0, mOriginalWord.toString());
+        if (typedWord != null) {
+            mSuggestions.add(0, typedWord.toString());
         }
         if (mAutoTextEnabled) {
             int i = 0;
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index 3a3176e..0bb7c66 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -53,7 +53,11 @@
     }
 
     public boolean hasAutoCorrectionWord() {
-        return mHasMinimalSuggestion && ((size() >= 1 && !mTypedWordValid) || mTypedWordValid);
+        return mHasMinimalSuggestion && size() > 1 && !mTypedWordValid;
+    }
+
+    public boolean hasWordAboveAutoCorrectionScoreThreshold() {
+        return mHasMinimalSuggestion && ((size() > 1 && !mTypedWordValid) || mTypedWordValid);
     }
 
     public static class Builder {
diff --git a/tests/src/com/android/inputmethod/latin/SuggestHelper.java b/tests/src/com/android/inputmethod/latin/SuggestHelper.java
index 25ceef6..7254520 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestHelper.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestHelper.java
@@ -125,19 +125,19 @@
 
     boolean isDefaultSuggestion(CharSequence typed, CharSequence expected) {
         WordComposer word = createWordComposer(typed);
-        SuggestedWords suggestions = mSuggest.getSuggestions(null, word, false, null);
+        SuggestedWords suggestions = mSuggest.getSuggestions(null, word, null);
         return isDefaultSuggestion(suggestions, expected);
     }
 
     boolean isDefaultCorrection(CharSequence typed, CharSequence expected) {
         WordComposer word = createWordComposer(typed);
-        SuggestedWords suggestions = mSuggest.getSuggestions(null, word, false, null);
+        SuggestedWords suggestions = mSuggest.getSuggestions(null, word, null);
         return isDefaultSuggestion(suggestions, expected) && mSuggest.hasMinimalCorrection();
     }
 
     boolean isASuggestion(CharSequence typed, CharSequence expected) {
         WordComposer word = createWordComposer(typed);
-        SuggestedWords suggestions = mSuggest.getSuggestions(null, word, false, null);
+        SuggestedWords suggestions = mSuggest.getSuggestions(null, word, null);
         for (int i = 1; i < suggestions.size(); i++) {
             if (TextUtils.equals(suggestions.getWord(i), expected)) return true;
         }
@@ -147,7 +147,7 @@
     private void getBigramSuggestions(CharSequence previous, CharSequence typed) {
         if (!TextUtils.isEmpty(previous) && (typed.length() > 1)) {
             WordComposer firstChar = createWordComposer(Character.toString(typed.charAt(0)));
-            mSuggest.getSuggestions(null, firstChar, false, previous);
+            mSuggest.getSuggestions(null, firstChar, previous);
         }
     }
 
@@ -155,7 +155,7 @@
             CharSequence expected) {
         WordComposer word = createWordComposer(typed);
         getBigramSuggestions(previous, typed);
-        SuggestedWords suggestions = mSuggest.getSuggestions(null, word, false, previous);
+        SuggestedWords suggestions = mSuggest.getSuggestions(null, word, previous);
         return isDefaultSuggestion(suggestions, expected);
     }
 
@@ -163,7 +163,7 @@
             CharSequence expected) {
         WordComposer word = createWordComposer(typed);
         getBigramSuggestions(previous, typed);
-        SuggestedWords suggestions = mSuggest.getSuggestions(null, word, false, previous);
+        SuggestedWords suggestions = mSuggest.getSuggestions(null, word, previous);
         return isDefaultSuggestion(suggestions, expected) && mSuggest.hasMinimalCorrection();
     }
 
@@ -171,7 +171,7 @@
             CharSequence expected) {
         WordComposer word = createWordComposer(typed);
         getBigramSuggestions(previous, typed);
-        SuggestedWords suggestions = mSuggest.getSuggestions(null, word, false, previous);
+        SuggestedWords suggestions = mSuggest.getSuggestions(null, word, previous);
         for (int i = 1; i < suggestions.size(); i++) {
             if (TextUtils.equals(suggestions.getWord(i), expected)) return true;
         }
@@ -189,7 +189,7 @@
         flushUserBigrams();
         if (!TextUtils.isEmpty(previous) && !TextUtils.isEmpty(Character.toString(typed))) {
             WordComposer firstChar = createWordComposer(Character.toString(typed));
-            mSuggest.getSuggestions(null, firstChar, false, previous);
+            mSuggest.getSuggestions(null, firstChar, previous);
             boolean reloading = mUserBigram.reloadDictionaryIfRequired();
             if (reloading) mUserBigram.waitForDictionaryLoading();
             mUserBigram.getBigrams(firstChar, previous, mSuggest, null);