From 6fb586a527e7ffe5da187c8b345cdf897b8481c7 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 6 Oct 2014 17:20:10 +0900 Subject: [PATCH] Fix missing prediction words on contextual strip Bug: 17874801 Change-Id: Iaba935a6b2548376f10a0ecd80f07ea7ada6c60a --- .../values/donottranslate-debug-settings.xml | 2 +- java/res/xml/prefs_screen_debug.xml | 4 ++-- .../inputmethod/latin/SuggestedWords.java | 13 +++++++++++++ .../latin/inputlogic/InputLogic.java | 5 ++--- .../latin/settings/DebugSettings.java | 4 ++-- .../latin/settings/DebugSettingsFragment.java | 4 ++-- .../inputmethod/latin/settings/Settings.java | 2 +- .../latin/settings/SettingsValues.java | 6 +++--- .../SuggestionStripLayoutHelper.java | 18 ++++++++---------- 9 files changed, 34 insertions(+), 24 deletions(-) diff --git a/java/res/values/donottranslate-debug-settings.xml b/java/res/values/donottranslate-debug-settings.xml index 35e6efa77..199f9772b 100644 --- a/java/res/values/donottranslate-debug-settings.xml +++ b/java/res/values/donottranslate-debug-settings.xml @@ -23,7 +23,7 @@ Debug Mode Force non-distinct multitouch Force physical keyboard special key - Show UI to accept typed word + Show LXX suggestion UI Show slide indicator diff --git a/java/res/xml/prefs_screen_debug.xml b/java/res/xml/prefs_screen_debug.xml index c47740268..25f7c6612 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" /> index. * @param index The index of 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 f67a9a6ef..07bfd0dee 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; 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 @@ public final class InputLogic { mInputLogicHandler.reset(); } - if (settingsValues.mShouldShowUiToAcceptTypedWord) { + if (settingsValues.mShouldShowLxxSuggestionUi) { mConnection.requestCursorUpdates(true /* enableMonitor */, true /* requestImmediateCallback */); } @@ -2352,7 +2351,7 @@ public final class InputLogic { // 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 48f4c758c..091ca43c6 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 final class DebugSettings { 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 5640e2039..e9f8d45aa 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 @@ public final class DebugSettingsFragment extends SubScreenFragment 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 83adb1c55..84596b4ad 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 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang 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 99f761ca6..ce8a0ab9c 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 class SettingsValues { 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 @@ public class SettingsValues { 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 a651774c6..d55939971 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 class SuggestionStripLayoutHelper { 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 @@ final class SuggestionStripLayoutHelper { (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 class SuggestionStripLayoutHelper { } 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 @@ final class SuggestionStripLayoutHelper { 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;