Pass the value we really want to pass to update functions (A67)

Change-Id: Ica9b875d119dea2f8dc237fd63e5b4eaa5e1c400
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index a2ba7bb..de2ecd3 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -219,6 +219,8 @@
 
         // isComposing is always true
         public void postUpdateSuggestions(final boolean isComposing) {
+            // TODO: remove this test
+            if (!isComposing) throw new RuntimeException("We are not composing a word");
             cancelUpdateSuggestionStrip();
             sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTIONS), mDelayUpdateSuggestions);
         }
@@ -243,6 +245,8 @@
 
         // isComposing is always false
         public void postUpdateBigramPredictions(final boolean isComposing) {
+            // TODO: remove this test
+            if (isComposing) throw new RuntimeException("We are composing a word");
             cancelUpdateSuggestionStrip();
             sendMessageDelayed(obtainMessage(MSG_SET_BIGRAM_PREDICTIONS), mDelayUpdateSuggestions);
         }
@@ -1400,10 +1404,10 @@
                 // isComposingWord() any more.
                 if (!mWordComposer.isComposingWord()) {
                     // Not composing word any more, so we can show bigrams.
-                    mHandler.postUpdateBigramPredictions(false);
+                    mHandler.postUpdateBigramPredictions(mWordComposer.isComposingWord());
                 } else {
                     // Still composing a word, so we still have letters to deduce a suggestion from.
-                    mHandler.postUpdateSuggestions(true);
+                    mHandler.postUpdateSuggestions(mWordComposer.isComposingWord());
                 }
             } else {
                 mConnection.deleteSurroundingText(1, 0);
@@ -1547,7 +1551,8 @@
                         getCurrentAutoCapsState() != Constants.TextUtils.CAP_MODE_OFF);
             }
             mConnection.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
-            mHandler.postUpdateSuggestions(true);
+            // We just added a character, so isComposingWord() is true
+            mHandler.postUpdateSuggestions(mWordComposer.isComposingWord());
         } else {
             final boolean swapWeakSpace = maybeStripSpace(primaryCode,
                     spaceState, KeyboardActionListener.SUGGESTION_STRIP_COORDINATE == x);
@@ -1561,7 +1566,10 @@
             // We may need to update predictions, if the "add to dictionary" hint was displayed
             // for example.
             if (null != mSuggestionsView) mSuggestionsView.dismissAddToDictionaryHint();
-            mHandler.postUpdateBigramPredictions(false);
+            // Here we know we are not composing a word: if we were, then we can't come here because
+            // isComposingWord is still true; if we weren't, and we now are, then isComposingWord
+            // has been turned to true, so we can't come here either.
+            mHandler.postUpdateBigramPredictions(mWordComposer.isComposingWord());
         }
         Utils.Stats.onNonSeparator((char)primaryCode, x, y);
     }
@@ -1604,7 +1612,9 @@
 
             mHandler.startDoubleSpacesTimer();
             if (!mConnection.isCursorTouchingWord(mCurrentSettings)) {
-                mHandler.postUpdateBigramPredictions(false);
+                // We know mWordComposer.isComposingWord() is false here, since if it was true,
+                // we committed the text, making it false.
+                mHandler.postUpdateBigramPredictions(mWordComposer.isComposingWord());
             }
         } else {
             if (swapWeakSpace) {
@@ -1889,7 +1899,9 @@
             mSuggestionsView.showAddToDictionaryHint(suggestion, mCurrentSettings.mHintToSaveText);
         } else {
             // If we're not showing the "Touch again to save", then show predictions.
-            mHandler.postUpdateBigramPredictions(false);
+            // We just called commitChosenWord, which ensures mWordComposer#isComposingWord()
+            // returns false.
+            mHandler.postUpdateBigramPredictions(mWordComposer.isComposingWord());
         }
     }
 
@@ -1981,7 +1993,8 @@
             ResearchLogger.latinIME_deleteSurroundingText(length);
         }
         mConnection.setComposingText(word, 1);
-        mHandler.postUpdateSuggestions(true);
+        // We just set a composing word, so isComposingWord() is true
+        mHandler.postUpdateSuggestions(mWordComposer.isComposingWord());
     }
 
     private void revertCommit() {
@@ -2026,7 +2039,9 @@
         // separator.
         mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD;
         // We have a separator between the word and the cursor: we should show predictions.
-        mHandler.postUpdateBigramPredictions(false);
+        // We know we are not composing a word here (there is even a test that throws an exception
+        // in debug mode in here)
+        mHandler.postUpdateBigramPredictions(mWordComposer.isComposingWord());
     }
 
     public boolean isWordSeparator(int code) {
@@ -2052,9 +2067,9 @@
         // we are currently composing. If we are not composing anything, we may want to display
         // predictions or punctuation signs (which is done by updateBigramPredictions anyway).
         if (mWordComposer.isComposingWord()) {
-            mHandler.postUpdateSuggestions(true);
+            mHandler.postUpdateSuggestions(mWordComposer.isComposingWord());
         } else {
-            mHandler.postUpdateBigramPredictions(false);
+            mHandler.postUpdateBigramPredictions(mWordComposer.isComposingWord());
         }
     }