diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index bd60844a3d4a1d59c09b6dc8e658391483d9b776..392a0705a51170aac16b894b9094b7308c7c2922 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -61,8 +61,10 @@ <string name="include_other_imes_in_language_switch_list">Switch to other input methods</string> <!-- Option summary for including other IMEs in the language switch list [CHAR LIMIT=65] --> <string name="include_other_imes_in_language_switch_list_summary">Language switch key covers other input methods too</string> - <!-- Option to suppress language switch key [CHAR LIMIT=30] --> - <string name="suppress_language_switch_key">Suppress language switch key</string> + <!-- Option to show language switch key [CHAR LIMIT=30] --> + <string name="show_language_switch_key">Language switch key</string> + <!-- Option summary for showing language switch key [CHAR LIMIT=65] --> + <string name="show_language_switch_key_summary">Show when multiple input languages are enabled</string> <!-- Option for the dismiss delay of the key popup [CHAR LIMIT=25] --> <string name="key_preview_popup_dismiss_delay">Key popup dismiss delay</string> diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml index f7c993d9d7404745718af1966ecd603ccb257025..3e83fc0fc76f5ed10711bcbd79032946a5049f2d 100644 --- a/java/res/xml/prefs.xml +++ b/java/res/xml/prefs.xml @@ -108,10 +108,11 @@ android:persistent="true" android:defaultValue="true" /> <CheckBoxPreference - android:key="pref_suppress_language_switch_key" - android:title="@string/suppress_language_switch_key" + android:key="pref_show_language_switch_key" + android:title="@string/show_language_switch_key" + android:summary="@string/show_language_switch_key_summary" android:persistent="true" - android:defaultValue="false" /> + android:defaultValue="true" /> <CheckBoxPreference android:key="pref_include_other_imes_in_language_switch_list" android:title="@string/include_other_imes_in_language_switch_list" diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index c2dec25933887c9971084e16fc9637a86c031170..9479a88a71cbb4e26b8b9fbf11eaaf870b4e1e76 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -42,7 +42,7 @@ import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.research.ResearchLogger; import com.android.inputmethodcommon.InputMethodSettingsFragment; -public class Settings extends InputMethodSettingsFragment +public final class Settings extends InputMethodSettingsFragment implements SharedPreferences.OnSharedPreferenceChangeListener { public static final boolean ENABLE_INTERNAL_SETTINGS = ProductionFlag.IS_INTERNAL; @@ -63,8 +63,8 @@ public class Settings extends InputMethodSettingsFragment "last_user_dictionary_write_time"; public static final String PREF_ADVANCED_SETTINGS = "pref_advanced_settings"; public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict"; - public static final String PREF_SUPPRESS_LANGUAGE_SWITCH_KEY = - "pref_suppress_language_switch_key"; + public static final String PREF_SHOW_LANGUAGE_SWITCH_KEY = + "pref_show_language_switch_key"; public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST = "pref_include_other_imes_in_language_switch_list"; public static final String PREF_CUSTOM_INPUT_STYLES = "custom_input_styles"; @@ -97,7 +97,7 @@ public class Settings extends InputMethodSettingsFragment private TextView mKeypressVibrationDurationSettingsTextView; private TextView mKeypressSoundVolumeSettingsTextView; - private static void setPreferenceEnabled(Preference preference, boolean enabled) { + private static void setPreferenceEnabled(final Preference preference, final boolean enabled) { if (preference != null) { preference.setEnabled(enabled); } @@ -111,7 +111,7 @@ public class Settings extends InputMethodSettingsFragment } @Override - public void onCreate(Bundle icicle) { + public void onCreate(final Bundle icicle) { super.onCreate(icicle); setInputMethodSettingsCategoryTitle(R.string.language_selection_title); setSubtypeEnablerTitle(R.string.select_language); @@ -192,7 +192,7 @@ public class Settings extends InputMethodSettingsFragment } setPreferenceEnabled(findPreference(PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST), - !SettingsValues.isLanguageSwitchKeySupressed(prefs)); + SettingsValues.showsLanguageSwitchKey(prefs)); final PreferenceScreen dictionaryLink = (PreferenceScreen) findPreference(PREF_CONFIGURE_DICTIONARIES_KEY); @@ -288,14 +288,14 @@ public class Settings extends InputMethodSettingsFragment } @Override - public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) { (new BackupManager(getActivity())).dataChanged(); if (key.equals(PREF_POPUP_ON)) { setPreferenceEnabled(findPreference(PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY), prefs.getBoolean(PREF_POPUP_ON, true)); - } else if (key.equals(PREF_SUPPRESS_LANGUAGE_SWITCH_KEY)) { + } else if (key.equals(PREF_SHOW_LANGUAGE_SWITCH_KEY)) { setPreferenceEnabled(findPreference(PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST), - !SettingsValues.isLanguageSwitchKeySupressed(prefs)); + SettingsValues.showsLanguageSwitchKey(prefs)); } else if (key.equals(PREF_GESTURE_INPUT)) { final boolean gestureInputEnabledByConfig = getResources().getBoolean( R.bool.config_gesture_input_enabled_by_build_config); @@ -352,7 +352,7 @@ public class Settings extends InputMethodSettingsFragment } private void refreshEnablingsOfKeypressSoundAndVibrationSettings( - SharedPreferences sp, Resources res) { + final SharedPreferences sp, final Resources res) { if (mKeypressVibrationDurationSettingsPref != null) { final boolean hasVibratorHardware = VibratorUtils.getInstance(getActivity()) .hasVibrator(); @@ -370,7 +370,7 @@ public class Settings extends InputMethodSettingsFragment } private void updateKeypressVibrationDurationSettingsSummary( - SharedPreferences sp, Resources res) { + final SharedPreferences sp, final Resources res) { if (mKeypressVibrationDurationSettingsPref != null) { mKeypressVibrationDurationSettingsPref.setSummary( SettingsValues.getCurrentVibrationDuration(sp, res) @@ -428,7 +428,7 @@ public class Settings extends InputMethodSettingsFragment builder.create().show(); } - private void updateKeypressSoundVolumeSummary(SharedPreferences sp, Resources res) { + private void updateKeypressSoundVolumeSummary(final SharedPreferences sp, final Resources res) { if (mKeypressSoundVolumeSettingsPref != null) { mKeypressSoundVolumeSettingsPref.setSummary(String.valueOf( (int)(SettingsValues.getCurrentKeypressSoundVolume(sp, res) * 100))); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index d9cf2700b66c3f2cceb39775870a48265fdd7736..9d8379a7acf82cc5c124952e4be9f829400671c4 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -72,7 +72,7 @@ public final class SettingsValues { @SuppressWarnings("unused") // TODO: Use this private final boolean mUsabilityStudyMode; public final boolean mIncludesOtherImesInLanguageSwitchList; - public final boolean mIsLanguageSwitchKeySuppressed; + public final boolean mShowsLanguageSwitchKey; @SuppressWarnings("unused") // TODO: Use this private final String mKeyPreviewPopupDismissDelayRawValue; public final boolean mUseContactsDict; @@ -151,7 +151,7 @@ public final class SettingsValues { mUsabilityStudyMode = getUsabilityStudyMode(prefs); mIncludesOtherImesInLanguageSwitchList = prefs.getBoolean( Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST, false); - mIsLanguageSwitchKeySuppressed = isLanguageSwitchKeySupressed(prefs); + mShowsLanguageSwitchKey = showsLanguageSwitchKey(prefs); mKeyPreviewPopupDismissDelayRawValue = prefs.getString( Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, Integer.toString(res.getInteger(R.integer.config_key_preview_linger_timeout))); @@ -336,12 +336,25 @@ public final class SettingsValues { return mVoiceKeyOnMain; } - public static boolean isLanguageSwitchKeySupressed(final SharedPreferences prefs) { - return prefs.getBoolean(Settings.PREF_SUPPRESS_LANGUAGE_SWITCH_KEY, false); + // This preference key is deprecated. Use {@link #PREF_SHOW_LANGUAGE_SWITCH_KEY} instead. + // This is being used only for the backward compatibility. + private static final String PREF_SUPPRESS_LANGUAGE_SWITCH_KEY = + "pref_suppress_language_switch_key"; + + public static boolean showsLanguageSwitchKey(final SharedPreferences prefs) { + if (prefs.contains(PREF_SUPPRESS_LANGUAGE_SWITCH_KEY)) { + final boolean suppressLanguageSwitchKey = prefs.getBoolean( + PREF_SUPPRESS_LANGUAGE_SWITCH_KEY, false); + final SharedPreferences.Editor editor = prefs.edit(); + editor.remove(PREF_SUPPRESS_LANGUAGE_SWITCH_KEY); + editor.putBoolean(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, !suppressLanguageSwitchKey); + editor.apply(); + } + return prefs.getBoolean(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, true); } public boolean isLanguageSwitchKeyEnabled(final Context context) { - if (mIsLanguageSwitchKeySuppressed) { + if (!mShowsLanguageSwitchKey) { return false; } if (mIncludesOtherImesInLanguageSwitchList) { @@ -353,7 +366,7 @@ public final class SettingsValues { } } - public boolean isFullscreenModeAllowed(final Resources res) { + public static boolean isFullscreenModeAllowed(final Resources res) { return res.getBoolean(R.bool.config_use_fullscreen_mode); }