Fix missing prediction words on contextual strip

Bug: 17874801
Change-Id: Iaba935a6b2548376f10a0ecd80f07ea7ada6c60a
diff --git a/java/res/values/donottranslate-debug-settings.xml b/java/res/values/donottranslate-debug-settings.xml
index 35e6efa..199f977 100644
--- a/java/res/values/donottranslate-debug-settings.xml
+++ b/java/res/values/donottranslate-debug-settings.xml
@@ -23,7 +23,7 @@
     <string name="prefs_debug_mode">Debug Mode</string>
     <string name="prefs_force_non_distinct_multitouch">Force non-distinct multitouch</string>
     <string name="prefs_force_physical_keyboard_special_key">Force physical keyboard special key</string>
-    <string name="prefs_show_ui_to_accept_typed_word">Show UI to accept typed word</string>
+    <string name="prefs_should_show_lxx_suggestion_ui">Show LXX suggestion UI</string>
     <!-- Option to enable sliding key input indicator. The user can see a rubber band-like effect during sliding key input. [CHAR LIMIT=30]-->
     <string name="sliding_key_input_preview">Show slide indicator</string>
     <!-- Option summary to enable sliding key input indicator. The user can see a rubber band-like effect during sliding key input. [CHAR LIMIT=66]-->
diff --git a/java/res/xml/prefs_screen_debug.xml b/java/res/xml/prefs_screen_debug.xml
index c477402..25f7c66 100644
--- a/java/res/xml/prefs_screen_debug.xml
+++ b/java/res/xml/prefs_screen_debug.xml
@@ -36,8 +36,8 @@
         android:defaultValue="false"
         android:persistent="true" />
     <CheckBoxPreference
-        android:key="pref_show_ui_to_accept_typed_word"
-        android:title="@string/prefs_show_ui_to_accept_typed_word"
+        android:key="pref_should_show_lxx_suggestion_ui"
+        android:title="@string/prefs_should_show_lxx_suggestion_ui"
         android:defaultValue="true"
         android:persistent="true" />
     <CheckBoxPreference
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index e6fd43a..4665764 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -113,6 +113,19 @@
     }
 
     /**
+     * Get suggested word to show as suggestions to UI.
+     *
+     * @param shouldShowLxxSuggestionUi true if showing suggestion UI introduced in LXX and later.
+     * @return the count of suggested word to show as suggestions to UI.
+     */
+    public int getWordCountToShow(final boolean shouldShowLxxSuggestionUi) {
+        if (isPrediction() || !shouldShowLxxSuggestionUi) {
+            return size();
+        }
+        return size() - /* typed word */ 1;
+    }
+
+    /**
      * Get suggested word at <code>index</code>.
      * @param index The index of the suggested word.
      * @return The suggested word.
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index f67a9a6..07bfd0d 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -53,7 +53,6 @@
 import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
 import com.android.inputmethod.latin.WordComposer;
 import com.android.inputmethod.latin.define.DebugFlags;
-import com.android.inputmethod.latin.define.ProductionFlags;
 import com.android.inputmethod.latin.settings.SettingsValues;
 import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion;
 import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
@@ -169,7 +168,7 @@
             mInputLogicHandler.reset();
         }
 
-        if (settingsValues.mShouldShowUiToAcceptTypedWord) {
+        if (settingsValues.mShouldShowLxxSuggestionUi) {
             mConnection.requestCursorUpdates(true /* enableMonitor */,
                     true /* requestImmediateCallback */);
         }
@@ -2352,7 +2351,7 @@
             // We cannot help in this case because we are heavily relying on this new API.
             return false;
         }
-        if (!settingsValues.mShouldShowUiToAcceptTypedWord) {
+        if (!settingsValues.mShouldShowLxxSuggestionUi) {
             return false;
         }
         if (TextUtils.isEmpty(lastComposedWord.mTypedWord)) {
diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
index 48f4c75..091ca43 100644
--- a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
+++ b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
@@ -21,8 +21,8 @@
     public static final String PREF_FORCE_NON_DISTINCT_MULTITOUCH = "force_non_distinct_multitouch";
     public static final String PREF_FORCE_PHYSICAL_KEYBOARD_SPECIAL_KEY =
             "force_physical_keyboard_special_key";
-    public static final String PREF_SHOW_UI_TO_ACCEPT_TYPED_WORD =
-            "pref_show_ui_to_accept_typed_word";
+    public static final String PREF_SHOULD_SHOW_LXX_SUGGESTION_UI =
+            "pref_should_show_lxx_suggestion_ui";
     public static final String PREF_HAS_CUSTOM_KEY_PREVIEW_ANIMATION_PARAMS =
             "pref_has_custom_key_preview_animation_params";
     public static final String PREF_KEY_PREVIEW_SHOW_UP_START_X_SCALE =
diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java
index 5640e20..e9f8d45 100644
--- a/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java
@@ -56,8 +56,8 @@
         super.onCreate(icicle);
         addPreferencesFromResource(R.xml.prefs_screen_debug);
 
-        if (!Settings.HAS_UI_TO_ACCEPT_TYPED_WORD) {
-            removePreference(DebugSettings.PREF_SHOW_UI_TO_ACCEPT_TYPED_WORD);
+        if (!Settings.SHOULD_SHOW_LXX_SUGGESTION_UI) {
+            removePreference(DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI);
         }
 
         mReadExternalDictionaryPref = findPreference(PREF_READ_EXTERNAL_DICTIONARY);
diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java
index 83adb1c..84596b4 100644
--- a/java/src/com/android/inputmethod/latin/settings/Settings.java
+++ b/java/src/com/android/inputmethod/latin/settings/Settings.java
@@ -77,7 +77,7 @@
             BuildCompatUtils.EFFECTIVE_SDK_INT <= Build.VERSION_CODES.KITKAT;
     public static final boolean ENABLE_SHOW_LANGUAGE_SWITCH_KEY_SETTINGS =
             BuildCompatUtils.EFFECTIVE_SDK_INT <= Build.VERSION_CODES.KITKAT;
-    public static final boolean HAS_UI_TO_ACCEPT_TYPED_WORD =
+    public static final boolean SHOULD_SHOW_LXX_SUGGESTION_UI =
             BuildCompatUtils.EFFECTIVE_SDK_INT >= BuildCompatUtils.VERSION_CODES_LXX;
     public static final String PREF_SHOW_LANGUAGE_SWITCH_KEY =
             "pref_show_language_switch_key";
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index 99f761c..ce8a0ab 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -80,7 +80,7 @@
     public final boolean mPhraseGestureEnabled;
     public final int mKeyLongpressTimeout;
     public final boolean mEnableMetricsLogging;
-    public final boolean mShouldShowUiToAcceptTypedWord;
+    public final boolean mShouldShowLxxSuggestionUi;
     // Use split layout for keyboard.
     public final boolean mIsSplitKeyboardEnabled;
     public final int mScreenMetrics;
@@ -163,8 +163,8 @@
         mIsSplitKeyboardEnabled = prefs.getBoolean(Settings.PREF_ENABLE_SPLIT_KEYBOARD, false);
         mScreenMetrics = res.getInteger(R.integer.config_screen_metrics);
 
-        mShouldShowUiToAcceptTypedWord = Settings.HAS_UI_TO_ACCEPT_TYPED_WORD
-                && prefs.getBoolean(DebugSettings.PREF_SHOW_UI_TO_ACCEPT_TYPED_WORD, true);
+        mShouldShowLxxSuggestionUi = Settings.SHOULD_SHOW_LXX_SUGGESTION_UI
+                && prefs.getBoolean(DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI, true);
         // Compute other readable settings
         mKeyLongpressTimeout = Settings.readKeyLongpressTimeout(prefs, res);
         mKeypressVibrationDuration = Settings.readKeypressVibrationDuration(prefs, res);
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
index a651774..d559399 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java
@@ -240,9 +240,9 @@
         final SettingsValues settingsValues = Settings.getInstance().getCurrent();
         final boolean shouldOmitTypedWord = shouldOmitTypedWord(suggestedWords.mInputStyle,
                 settingsValues.mGestureFloatingPreviewTextEnabled,
-                settingsValues.mShouldShowUiToAcceptTypedWord);
+                settingsValues.mShouldShowLxxSuggestionUi);
         return getPositionInSuggestionStrip(indexInSuggestedWords, suggestedWords.mWillAutoCorrect,
-                settingsValues.mShouldShowUiToAcceptTypedWord && shouldOmitTypedWord,
+                settingsValues.mShouldShowLxxSuggestionUi && shouldOmitTypedWord,
                 mCenterPositionInStrip, mTypedWordPositionWhenAutocorrect);
     }
 
@@ -367,21 +367,19 @@
                     (PunctuationSuggestions)suggestedWords, stripView);
         }
 
-        final boolean shouldShowUiToAcceptTypedWord = Settings.getInstance().getCurrent()
-                .mShouldShowUiToAcceptTypedWord;
-        final int suggestionsCount = suggestedWords.size()
-                - (shouldShowUiToAcceptTypedWord ? /* typed word */ 1 : 0);
+        final int wordCountToShow = suggestedWords.getWordCountToShow(
+                Settings.getInstance().getCurrent().mShouldShowLxxSuggestionUi);
         final int startIndexOfMoreSuggestions = setupWordViewsAndReturnStartIndexOfMoreSuggestions(
                 suggestedWords, mSuggestionsCountInStrip);
         final TextView centerWordView = mWordViews.get(mCenterPositionInStrip);
         final int stripWidth = stripView.getWidth();
         final int centerWidth = getSuggestionWidth(mCenterPositionInStrip, stripWidth);
-        if (suggestionsCount == 1 || getTextScaleX(centerWordView.getText(), centerWidth,
+        if (wordCountToShow == 1 || getTextScaleX(centerWordView.getText(), centerWidth,
                 centerWordView.getPaint()) < MIN_TEXT_XSCALE) {
             // Layout only the most relevant suggested word at the center of the suggestion strip
             // by consolidating all slots in the strip.
             final int countInStrip = 1;
-            mMoreSuggestionsAvailable = (suggestionsCount > countInStrip);
+            mMoreSuggestionsAvailable = (wordCountToShow > countInStrip);
             layoutWord(mCenterPositionInStrip, stripWidth - mPadding);
             stripView.addView(centerWordView);
             setLayoutWeight(centerWordView, 1.0f, ViewGroup.LayoutParams.MATCH_PARENT);
@@ -393,7 +391,7 @@
         }
 
         final int countInStrip = mSuggestionsCountInStrip;
-        mMoreSuggestionsAvailable = (suggestionsCount > countInStrip);
+        mMoreSuggestionsAvailable = (wordCountToShow > countInStrip);
         int x = 0;
         for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) {
             if (positionInStrip != 0) {
@@ -557,7 +555,7 @@
 
     public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip) {
         final boolean shouldShowUiToAcceptTypedWord = Settings.getInstance().getCurrent()
-                .mShouldShowUiToAcceptTypedWord;
+                .mShouldShowLxxSuggestionUi;
         final int stripWidth = addToDictionaryStrip.getWidth();
         final int width = shouldShowUiToAcceptTypedWord ? stripWidth
                 : stripWidth - mDividerWidth - mPadding * 2;