Merge "Breakdown QWERTY keyboard into rows and share"
diff --git a/java/src/com/android/inputmethod/latin/AutoCorrection.java b/java/src/com/android/inputmethod/latin/AutoCorrection.java
index 9754d15..9c35f8f 100644
--- a/java/src/com/android/inputmethod/latin/AutoCorrection.java
+++ b/java/src/com/android/inputmethod/latin/AutoCorrection.java
@@ -32,15 +32,15 @@
 
     public static CharSequence computeAutoCorrectionWord(Map<String, Dictionary> dictionaries,
             WordComposer wordComposer, ArrayList<CharSequence> suggestions, int[] sortedScores,
-            CharSequence typedWord, double autoCorrectionThreshold, int correctionMode,
+            CharSequence consideredWord, double autoCorrectionThreshold,
             CharSequence whitelistedWord) {
         if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) {
             return whitelistedWord;
-        } else if (hasAutoCorrectionForTypedWord(
-                dictionaries, wordComposer, suggestions, typedWord, correctionMode)) {
-            return typedWord;
-        } else if (hasAutoCorrectionForBinaryDictionary(wordComposer, suggestions, correctionMode,
-                sortedScores, typedWord, autoCorrectionThreshold)) {
+        } else if (hasAutoCorrectionForConsideredWord(
+                dictionaries, wordComposer, suggestions, consideredWord)) {
+            return consideredWord;
+        } else if (hasAutoCorrectionForBinaryDictionary(wordComposer, suggestions,
+                sortedScores, consideredWord, autoCorrectionThreshold)) {
             return suggestions.get(0);
         }
         return null;
@@ -87,31 +87,27 @@
         return whiteListedWord != null;
     }
 
-    private static boolean hasAutoCorrectionForTypedWord(Map<String, Dictionary> dictionaries,
-            WordComposer wordComposer, ArrayList<CharSequence> suggestions, CharSequence typedWord,
-            int correctionMode) {
-        if (TextUtils.isEmpty(typedWord)) return false;
+    private static boolean hasAutoCorrectionForConsideredWord(Map<String, Dictionary> dictionaries,
+            WordComposer wordComposer, ArrayList<CharSequence> suggestions,
+            CharSequence consideredWord) {
+        if (TextUtils.isEmpty(consideredWord)) return false;
         return wordComposer.size() > 1 && suggestions.size() > 0
-                && !allowsToBeAutoCorrected(dictionaries, typedWord, false)
-                && (correctionMode == Suggest.CORRECTION_FULL
-                || correctionMode == Suggest.CORRECTION_FULL_BIGRAM);
+                && !allowsToBeAutoCorrected(dictionaries, consideredWord, false);
     }
 
     private static boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer,
-            ArrayList<CharSequence> suggestions, int correctionMode, int[] sortedScores,
-            CharSequence typedWord, double autoCorrectionThreshold) {
-        if (wordComposer.size() > 1 && (correctionMode == Suggest.CORRECTION_FULL
-                || correctionMode == Suggest.CORRECTION_FULL_BIGRAM)
-                && typedWord != null && suggestions.size() > 0 && sortedScores.length > 0) {
+            ArrayList<CharSequence> suggestions, int[] sortedScores,
+            CharSequence consideredWord, double autoCorrectionThreshold) {
+        if (wordComposer.size() > 1 && suggestions.size() > 0 && sortedScores.length > 0) {
             final CharSequence autoCorrectionSuggestion = suggestions.get(0);
             final int autoCorrectionSuggestionScore = sortedScores[0];
             // 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 = BinaryDictionary.calcNormalizedScore(
-                    typedWord.toString(), autoCorrectionSuggestion.toString(),
+                    consideredWord.toString(), autoCorrectionSuggestion.toString(),
                     autoCorrectionSuggestionScore);
             if (DBG) {
-                Log.d(TAG, "Normalized " + typedWord + "," + autoCorrectionSuggestion + ","
+                Log.d(TAG, "Normalized " + consideredWord + "," + autoCorrectionSuggestion + ","
                         + autoCorrectionSuggestionScore + ", " + normalizedScore
                         + "(" + autoCorrectionThreshold + ")");
             }
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index e1ca854..13ba44b 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1816,20 +1816,20 @@
         } else {
             prevWord = EditingUtils.getPreviousWord(ic, mSettingsValues.mWordSeparators);
         }
+
+        final CharSequence typedWord = mWordComposer.getTypedWord();
+        final int quotesCount = mWordComposer.trailingSingleQuotesCount();
         // getSuggestedWordBuilder handles gracefully a null value of prevWord
         final SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(mWordComposer,
                 prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCorrectionMode);
 
-        boolean autoCorrectionAvailable = !mInputAttributes.mInputTypeNoAutoCorrect
-                && mSuggest.hasAutoCorrection();
-        final CharSequence typedWord = mWordComposer.getTypedWord();
+        boolean autoCorrectionAvailable = mSuggest.hasAutoCorrection();
         // Here, we want to promote a whitelisted word if exists.
         // TODO: Change this scheme - a boolean is not enough. A whitelisted word may be "valid"
         // but still autocorrected from - in the case the whitelist only capitalizes the word.
         // The whitelist should be case-insensitive, so it's not possible to be consistent with
         // a boolean flag. Right now this is handled with a slight hack in
         // WhitelistDictionary#shouldForciblyAutoCorrectFrom.
-        final int quotesCount = mWordComposer.trailingSingleQuotesCount();
         final boolean allowsToBeAutoCorrected = AutoCorrection.allowsToBeAutoCorrected(
                 mSuggest.getUnigramDictionaries(),
                 // If the typed string ends with a single quote, for dictionary lookup purposes
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index a213160..b6a7ce7 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -277,11 +277,9 @@
         final String consideredWord = mTrailingSingleQuotesCount > 0
                 ? typedWord.substring(0, typedWord.length() - mTrailingSingleQuotesCount)
                 : typedWord;
-        if (typedWord != null) {
-            // Treating USER_TYPED as UNIGRAM suggestion for logging now.
-            LatinImeLogger.onAddSuggestedWord(typedWord, Suggest.DIC_USER_TYPED,
-                    Dictionary.UNIGRAM);
-        }
+        // Treating USER_TYPED as UNIGRAM suggestion for logging now.
+        LatinImeLogger.onAddSuggestedWord(typedWord, Suggest.DIC_USER_TYPED,
+                Dictionary.UNIGRAM);
         mConsideredWord = consideredWord;
 
         if (wordComposer.size() <= 1 && (correctionMode == CORRECTION_FULL_BIGRAM)) {
@@ -340,17 +338,21 @@
                 }
             }
         }
-        final String consideredWordString =
-                consideredWord == null ? null : consideredWord.toString();
+        final String consideredWordString = consideredWord.toString();
 
         CharSequence whitelistedWord = capitalizeWord(mIsAllUpperCase, mIsFirstCharCapitalized,
                 mWhiteListDictionary.getWhitelistedWord(consideredWordString));
 
-        final CharSequence autoCorrection =
-                AutoCorrection.computeAutoCorrectionWord(mUnigramDictionaries, wordComposer,
-                mSuggestions, mScores, consideredWord, mAutoCorrectionThreshold, correctionMode,
-                whitelistedWord);
-        mHasAutoCorrection = (null != autoCorrection);
+        if (CORRECTION_FULL == correctionMode
+                || CORRECTION_FULL_BIGRAM == correctionMode) {
+            final CharSequence autoCorrection =
+                    AutoCorrection.computeAutoCorrectionWord(mUnigramDictionaries, wordComposer,
+                            mSuggestions, mScores, consideredWord, mAutoCorrectionThreshold,
+                            whitelistedWord);
+            mHasAutoCorrection = (null != autoCorrection);
+        } else {
+            mHasAutoCorrection = false;
+        }
 
         if (whitelistedWord != null) {
             if (mTrailingSingleQuotesCount > 0) {
@@ -364,9 +366,7 @@
             }
         }
 
-        if (typedWord != null) {
-            mSuggestions.add(0, typedWord.toString());
-        }
+        mSuggestions.add(0, typedWord.toString());
         StringUtils.removeDupes(mSuggestions);
 
         if (DBG) {