Make "Show correction suggestions" as a binary option

Formerly "Show correction suggestions" had three options, "always
show", "show in portrait mode", and "always hide". The reason behind
"show in portrait mode" was that there may not be enough screen estate
in landscape mode to show suggestions. Because recent phone devices
have relatively large screen, we decide to remove "show in portrait
mode" option.

Bug: 15780939
Change-Id: I896d737452c3893d43ce20bd88127f10c1eb3d83
main
Tadashi G. Takaoka 2014-07-22 10:18:38 -07:00
parent 825243bfdd
commit ab661e3ef8
9 changed files with 52 additions and 94 deletions

View File

@ -18,26 +18,6 @@
*/
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Always show the suggestion strip -->
<string name="prefs_suggestion_visibility_show_value">0</string>
<!-- Show the suggestion strip only on portrait mode -->
<string name="prefs_suggestion_visibility_show_only_portrait_value">1</string>
<!-- Always hide the suggestion strip -->
<string name="prefs_suggestion_visibility_hide_value">2</string>
<!-- Default value of the visibility of the suggestion strip -->
<string name="prefs_suggestion_visibility_default_value">0</string>
<!-- Option to show/hide the suggestion strip -->
<string-array name="prefs_suggestion_visibility_values">
<item>@string/prefs_suggestion_visibility_show_value</item>
<item>@string/prefs_suggestion_visibility_show_only_portrait_value</item>
<item>@string/prefs_suggestion_visibility_hide_value</item>
</string-array>
<string-array name="prefs_suggestion_visibilities">
<item>@string/prefs_suggestion_visibility_show_name</item>
<item>@string/prefs_suggestion_visibility_show_only_portrait_name</item>
<item>@string/prefs_suggestion_visibility_hide_name</item>
</string-array>
<!-- For backward compatibility.
See {@link SettingsValues#needsToShowVoiceInputKey(SharedPreferences,Resources)} -->
<string name="voice_mode_main">0</string>

View File

@ -108,9 +108,6 @@
<string name="prefs_show_suggestions">Show correction suggestions</string>
<!-- Description for show suggestions -->
<string name="prefs_show_suggestions_summary">Display suggested words while typing</string>
<string name="prefs_suggestion_visibility_show_name">Always show</string>
<string name="prefs_suggestion_visibility_show_only_portrait_name">Show in portrait mode</string>
<string name="prefs_suggestion_visibility_hide_name">Always hide</string>
<!-- Option to block potentially offensive words to be shown [CHAR_LIMIT=30] -->
<string name="prefs_block_potentially_offensive_title">Block offensive words</string>

View File

@ -144,13 +144,11 @@
android:entries="@array/auto_correction_threshold_modes"
android:defaultValue="@string/auto_correction_threshold_mode_index_modest"
android:persistent="true" />
<ListPreference
android:key="show_suggestions_setting"
<CheckBoxPreference
android:key="show_suggestions"
android:summary="@string/prefs_show_suggestions_summary"
android:title="@string/prefs_show_suggestions"
android:entryValues="@array/prefs_suggestion_visibility_values"
android:entries="@array/prefs_suggestion_visibilities"
android:defaultValue="@string/prefs_suggestion_visibility_default_value"
android:defaultValue="true"
android:persistent="true" />
<CheckBoxPreference
android:key="pref_key_use_personalized_dicts"

View File

@ -280,7 +280,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return;
}
if (!latinIme.mSettings.getCurrent()
.isCurrentOrientationAllowingSuggestionsPerUserSettings()) {
.isSuggestionsEnabledPerUserSettings()) {
return;
}
removeMessages(MSG_RESUME_SUGGESTIONS);
@ -650,7 +650,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mDictionaryFacilitator.resetDictionaries(this /* context */, locale,
settingsValues.mUseContactsDict, settingsValues.mUsePersonalizedDicts,
false /* forceReloadMainDictionary */, this);
if (settingsValues.mAutoCorrectionEnabled) {
if (settingsValues.mAutoCorrectionEnabledPerUserSettings) {
mInputLogic.mSuggest.setAutoCorrectionThreshold(
settingsValues.mAutoCorrectionThreshold);
}
@ -862,7 +862,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mainKeyboardView.closing();
currentSettingsValues = mSettings.getCurrent();
if (currentSettingsValues.mAutoCorrectionEnabled) {
if (currentSettingsValues.mAutoCorrectionEnabledPerUserSettings) {
suggest.setAutoCorrectionThreshold(
currentSettingsValues.mAutoCorrectionThreshold);
}
@ -977,7 +977,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
*/
@Override
public void onExtractedTextClicked() {
if (mSettings.getCurrent().isSuggestionsRequested()) {
if (mSettings.getCurrent().needsToLookupSuggestions()) {
return;
}
@ -995,7 +995,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
*/
@Override
public void onExtractedCursorMovement(final int dx, final int dy) {
if (mSettings.getCurrent().isSuggestionsRequested()) {
if (mSettings.getCurrent().needsToLookupSuggestions()) {
return;
}
@ -1379,7 +1379,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
ImportantNoticeUtils.shouldShowImportantNotice(this);
final boolean shouldShowSuggestionCandidates =
currentSettingsValues.mInputAttributes.mShouldShowSuggestions
&& currentSettingsValues.isCurrentOrientationAllowingSuggestionsPerUserSettings();
&& currentSettingsValues.isSuggestionsEnabledPerUserSettings();
final boolean shouldShowSuggestionsStripUnlessPassword = shouldShowImportantNotice
|| currentSettingsValues.mShowsVoiceInputKey
|| shouldShowSuggestionCandidates
@ -1403,7 +1403,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
if (currentSettingsValues.isCurrentOrientationAllowingSuggestionsPerUserSettings()
if (currentSettingsValues.isSuggestionsEnabledPerUserSettings()
// We should clear suggestions if there is no suggestion to show.
|| noSuggestionsToShow
|| currentSettingsValues.isApplicationSpecifiedCompletionsOn()) {

View File

@ -745,7 +745,7 @@ public final class InputLogic {
// a letter or a word connector.
&& settingsValues.isWordCodePoint(codePoint)
// We never go into composing state if suggestions are not requested.
&& settingsValues.isSuggestionsRequested() &&
&& settingsValues.needsToLookupSuggestions() &&
// In languages with spaces, we only start composing a word when we are not already
// touching a word. In languages without spaces, the above conditions are sufficient.
(!mConnection.isCursorTouchingWord(settingsValues.mSpacingAndPunctuations)
@ -810,7 +810,7 @@ public final class InputLogic {
}
// isComposingWord() may have changed since we stored wasComposing
if (mWordComposer.isComposingWord()) {
if (settingsValues.mAutoCorrectionEnabled) {
if (settingsValues.mAutoCorrectionEnabledPerUserSettings) {
final String separator = shouldAvoidSendingCode ? LastComposedWord.NOT_A_SEPARATOR
: StringUtils.newSingleCodePointString(codePoint);
commitCurrentAutoCorrection(settingsValues, separator, handler);
@ -1029,7 +1029,7 @@ public final class InputLogic {
}
}
if (inputTransaction.mSettingsValues
.isCurrentOrientationAllowingSuggestionsPerUserSettings()
.isSuggestionsEnabledPerUserSettings()
&& inputTransaction.mSettingsValues.mSpacingAndPunctuations
.mCurrentLanguageHasSpaces
&& !mConnection.isCursorFollowedByWordCharacter(
@ -1224,7 +1224,7 @@ public final class InputLogic {
// If correction is not enabled, we don't add words to the user history dictionary.
// That's to avoid unintended additions in some sensitive fields, or fields that
// expect to receive non-words.
if (!settingsValues.mAutoCorrectionEnabled) return;
if (!settingsValues.mAutoCorrectionEnabledPerUserSettings) return;
if (TextUtils.isEmpty(suggestion)) return;
final boolean wasAutoCapitalized =
@ -1237,7 +1237,7 @@ public final class InputLogic {
public void performUpdateSuggestionStripSync(final SettingsValues settingsValues) {
// Check if we have a suggestion engine attached.
if (!settingsValues.isSuggestionsRequested()) {
if (!settingsValues.needsToLookupSuggestions()) {
if (mWordComposer.isComposingWord()) {
Log.w(TAG, "Called updateSuggestionsOrPredictions but suggestions were not "
+ "requested!");
@ -1299,7 +1299,7 @@ public final class InputLogic {
// how to segment them yet.
|| !settingsValues.mSpacingAndPunctuations.mCurrentLanguageHasSpaces
// If no suggestions are requested, don't try restarting suggestions.
|| !settingsValues.isSuggestionsRequested()
|| !settingsValues.needsToLookupSuggestions()
// If we are currently in a batch input, we must not resume suggestions, or the result
// of the batch input will replace the new composition. This may happen in the corner case
// that the app moves the cursor on its own accord during a batch input.
@ -2003,7 +2003,7 @@ public final class InputLogic {
new SettingsValuesForSuggestion(settingsValues.mBlockPotentiallyOffensive,
settingsValues.mPhraseGestureEnabled,
settingsValues.mAdditionalFeaturesSettingValues),
settingsValues.mAutoCorrectionEnabled,
settingsValues.mAutoCorrectionEnabledPerUserSettings,
sessionId, sequenceNumber, callback);
}
}

View File

@ -57,7 +57,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_EDIT_PERSONAL_DICTIONARY = "edit_personal_dictionary";
public static final String PREF_CONFIGURE_DICTIONARIES_KEY = "configure_dictionaries_key";
public static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold";
public static final String PREF_SHOW_SUGGESTIONS_SETTING = "show_suggestions_setting";
// PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE is obsolete. Use PREF_SHOW_SUGGESTIONS instead.
public static final String PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE = "show_suggestions_setting";
public static final String PREF_SHOW_SUGGESTIONS = "show_suggestions";
public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict";
public static final String PREF_KEY_USE_PERSONALIZED_DICTS = "pref_key_use_personalized_dicts";
public static final String PREF_KEY_USE_DOUBLE_SPACE_PERIOD =

View File

@ -247,7 +247,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
if (showSetupWizardIcon != null) {
showSetupWizardIcon.setChecked(Settings.readShowSetupWizardIcon(prefs, getActivity()));
}
updateListPreferenceSummaryToCurrentValue(Settings.PREF_SHOW_SUGGESTIONS_SETTING);
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
final ListPreference keyboardThemePref = (ListPreference)findPreference(
Settings.PREF_KEYBOARD_THEME);
@ -298,7 +297,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
LauncherIconVisibilityManager.updateSetupWizardIconVisibility(getActivity());
}
ensureConsistencyOfAutoCorrectionSettings();
updateListPreferenceSummaryToCurrentValue(Settings.PREF_SHOW_SUGGESTIONS_SETTING);
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEYBOARD_THEME);
refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources());

View File

@ -85,9 +85,8 @@ public final class SettingsValues {
public final int mKeyPreviewPopupDismissDelay;
private final boolean mAutoCorrectEnabled;
public final float mAutoCorrectionThreshold;
// TODO: Rename this to mAutoCorrectionEnabledPerUserSettings.
public final boolean mAutoCorrectionEnabled;
public final int mSuggestionVisibility;
public final boolean mAutoCorrectionEnabledPerUserSettings;
private final boolean mSuggestionsEnabledPerUserSettings;
public final int mDisplayOrientation;
private final AsyncResultHolder<AppWorkaroundsUtils> mAppWorkarounds;
@ -155,11 +154,9 @@ public final class SettingsValues {
mGestureFloatingPreviewTextEnabled = prefs.getBoolean(
Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true);
mPhraseGestureEnabled = Settings.readPhraseGestureEnabled(prefs, res);
mAutoCorrectionEnabled = mAutoCorrectEnabled && !mInputAttributes.mInputTypeNoAutoCorrect;
final String showSuggestionsSetting = prefs.getString(
Settings.PREF_SHOW_SUGGESTIONS_SETTING,
res.getString(R.string.prefs_suggestion_visibility_default_value));
mSuggestionVisibility = createSuggestionVisibility(res, showSuggestionsSetting);
mAutoCorrectionEnabledPerUserSettings = mAutoCorrectEnabled
&& !mInputAttributes.mInputTypeNoAutoCorrect;
mSuggestionsEnabledPerUserSettings = readSuggestionsEnabled(prefs);
AdditionalFeaturesSettingUtils.readAdditionalFeaturesPreferencesIntoArray(
prefs, mAdditionalFeaturesSettingValues);
mIsInternal = Settings.isInternal(prefs);
@ -193,17 +190,13 @@ public final class SettingsValues {
return mInputAttributes.mApplicationSpecifiedCompletionOn;
}
// TODO: Rename this to needsToLookupSuggestions().
public boolean isSuggestionsRequested() {
public boolean needsToLookupSuggestions() {
return mInputAttributes.mShouldShowSuggestions
&& (mAutoCorrectionEnabled
|| isCurrentOrientationAllowingSuggestionsPerUserSettings());
&& (mAutoCorrectionEnabledPerUserSettings || isSuggestionsEnabledPerUserSettings());
}
public boolean isCurrentOrientationAllowingSuggestionsPerUserSettings() {
return (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_VALUE)
|| (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE
&& mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT);
public boolean isSuggestionsEnabledPerUserSettings() {
return mSuggestionsEnabledPerUserSettings;
}
public boolean isWordSeparator(final int code) {
@ -263,26 +256,18 @@ public final class SettingsValues {
return null == appWorkaroundUtils ? false : appWorkaroundUtils.isBrokenByRecorrection();
}
private static final int SUGGESTION_VISIBILITY_SHOW_VALUE =
R.string.prefs_suggestion_visibility_show_value;
private static final int SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE =
R.string.prefs_suggestion_visibility_show_only_portrait_value;
private static final int SUGGESTION_VISIBILITY_HIDE_VALUE =
R.string.prefs_suggestion_visibility_hide_value;
private static final int[] SUGGESTION_VISIBILITY_VALUE_ARRAY = new int[] {
SUGGESTION_VISIBILITY_SHOW_VALUE,
SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE,
SUGGESTION_VISIBILITY_HIDE_VALUE
};
private static final String SUGGESTIONS_VISIBILITY_HIDE_VALUE_OBSOLETE = "2";
private static int createSuggestionVisibility(final Resources res,
final String suggestionVisiblityStr) {
for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) {
if (suggestionVisiblityStr.equals(res.getString(visibility))) {
return visibility;
}
private static boolean readSuggestionsEnabled(final SharedPreferences prefs) {
if (prefs.contains(Settings.PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE)) {
final boolean alwaysHide = SUGGESTIONS_VISIBILITY_HIDE_VALUE_OBSOLETE.equals(
prefs.getString(Settings.PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE, null));
prefs.edit()
.remove(Settings.PREF_SHOW_SUGGESTIONS_SETTING_OBSOLETE)
.putBoolean(Settings.PREF_SHOW_SUGGESTIONS, !alwaysHide)
.apply();
}
throw new RuntimeException("Bug: visibility string is not configured correctly");
return prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true);
}
private static boolean readBigramPredictionEnabled(final SharedPreferences prefs,
@ -396,10 +381,10 @@ public final class SettingsValues {
sb.append("" + mAutoCorrectEnabled);
sb.append("\n mAutoCorrectionThreshold = ");
sb.append("" + mAutoCorrectionThreshold);
sb.append("\n mAutoCorrectionEnabled = ");
sb.append("" + mAutoCorrectionEnabled);
sb.append("\n mSuggestionVisibility = ");
sb.append("" + mSuggestionVisibility);
sb.append("\n mAutoCorrectionEnabledPerUserSettings = ");
sb.append("" + mAutoCorrectionEnabledPerUserSettings);
sb.append("\n mSuggestionsEnabledPerUserSettings = ");
sb.append("" + mSuggestionsEnabledPerUserSettings);
sb.append("\n mDisplayOrientation = ");
sb.append("" + mDisplayOrientation);
sb.append("\n mAppWorkarounds = ");

View File

@ -16,12 +16,12 @@
package com.android.inputmethod.latin;
import com.android.inputmethod.latin.settings.Settings;
import android.test.suitebuilder.annotation.LargeTest;
import android.text.TextUtils;
import android.view.inputmethod.BaseInputConnection;
import com.android.inputmethod.latin.settings.Settings;
@LargeTest
public class InputLogicTests extends InputTestsBase {
@ -242,16 +242,14 @@ public class InputLogicTests extends InputTestsBase {
public void testDoubleSpacePeriod() {
// Reset settings to default, else these tests will go flaky.
setStringPreference(Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0", "0");
setBooleanPreference(Settings.PREF_SHOW_SUGGESTIONS, true, true);
setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, "1", "1");
setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true);
testDoubleSpacePeriodWithSettings(true /* expectsPeriod */);
// "Suggestion visibility" to "always hide"
testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "2");
// "Suggestion visibility" to "portrait only"
testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "1");
// "Suggestion visibility" to "always show"
testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0");
// "Suggestion visibility" to off
testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS, false);
// "Suggestion visibility" to on
testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS, true);
// "Double-space period" to "off"
testDoubleSpacePeriodWithSettings(false, Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, false);
@ -264,10 +262,10 @@ public class InputLogicTests extends InputTestsBase {
testDoubleSpacePeriodWithSettings(true, Settings.PREF_AUTO_CORRECTION_THRESHOLD, "3");
// "Suggestion visibility" to "always hide" and "Auto-correction" to "off"
testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0",
testDoubleSpacePeriodWithSettings(true, Settings.PREF_SHOW_SUGGESTIONS, false,
Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0");
// "Suggestion visibility" to "always hide" and "Auto-correction" to "off"
testDoubleSpacePeriodWithSettings(false, Settings.PREF_SHOW_SUGGESTIONS_SETTING, "0",
testDoubleSpacePeriodWithSettings(false, Settings.PREF_SHOW_SUGGESTIONS, false,
Settings.PREF_AUTO_CORRECTION_THRESHOLD, "0",
Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, false);
}