Make "show settings key option" dependent to device configuration

Bug: 3095814
Change-Id: I73b8a5023b398621a910c953eade252dc6412923
diff --git a/java/res/values-xlarge/bools.xml b/java/res/values-xlarge/bools.xml
index fe8fc58..66cfd9d 100644
--- a/java/res/values-xlarge/bools.xml
+++ b/java/res/values-xlarge/bools.xml
@@ -20,4 +20,5 @@
 <resources>
     <!-- Whether or not Popup on key press is enabled by default -->
     <bool name="default_popup_preview">false</bool>
+    <bool name="config_enable_show_settings_key_option">false</bool>
 </resources>
diff --git a/java/res/values/bools.xml b/java/res/values/bools.xml
index 5a24e4c..64d05bd 100644
--- a/java/res/values/bools.xml
+++ b/java/res/values/bools.xml
@@ -30,4 +30,5 @@
     <bool name="default_popup_preview">true</bool>
     <bool name="default_recorrection_enabled">true</bool>
     <bool name="config_long_press_comma_for_settings_enabled">true</bool>
+    <bool name="config_enable_show_settings_key_option">true</bool>
 </resources>
diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
index ec42217..3a54904 100644
--- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
@@ -160,11 +160,10 @@
     // Indicates whether or not we have the settings key
     private boolean mHasSettingsKey;
     private static final int SETTINGS_KEY_MODE_AUTO = R.string.settings_key_mode_auto;
-    private static final int SETTINGS_KEY_MODE_ALWAYS_SHOW = R.string.settings_key_mode_always_show;
-    // NOTE: No need to have SETTINGS_KEY_MODE_ALWAYS_HIDE here because it's not being referred to
-    // in the source code now.
-    // Default is SETTINGS_KEY_MODE_AUTO.
-    private static final int DEFAULT_SETTINGS_KEY_MODE = SETTINGS_KEY_MODE_AUTO;
+    private static final int SETTINGS_KEY_MODE_ALWAYS_SHOW =
+            R.string.settings_key_mode_always_show;
+    private static final int SETTINGS_KEY_MODE_ALWAYS_HIDE =
+            R.string.settings_key_mode_always_hide;
 
     private int mLastDisplayWidth;
     private LanguageSwitcher mLanguageSwitcher;
@@ -543,8 +542,12 @@
 
     private void updateSettingsKeyState(SharedPreferences prefs) {
         Resources resources = mInputMethodService.getResources();
+        final boolean showSettingsKeyOption = resources.getBoolean(
+                R.bool.config_enable_show_settings_key_option);
+        final int defaultSettingsKeyMode = showSettingsKeyOption
+                ? SETTINGS_KEY_MODE_AUTO : SETTINGS_KEY_MODE_ALWAYS_HIDE;
         final String settingsKeyMode = prefs.getString(LatinIMESettings.PREF_SETTINGS_KEY,
-                resources.getString(DEFAULT_SETTINGS_KEY_MODE));
+                resources.getString(defaultSettingsKeyMode));
         // We show the settings key when 1) SETTINGS_KEY_MODE_ALWAYS_SHOW or
         // 2) SETTINGS_KEY_MODE_AUTO and there are two or more enabled IMEs on the system
         if (settingsKeyMode.equals(resources.getString(SETTINGS_KEY_MODE_ALWAYS_SHOW))
diff --git a/java/src/com/android/inputmethod/latin/LatinIMESettings.java b/java/src/com/android/inputmethod/latin/LatinIMESettings.java
index 99d8a62..4f20e9b 100644
--- a/java/src/com/android/inputmethod/latin/LatinIMESettings.java
+++ b/java/src/com/android/inputmethod/latin/LatinIMESettings.java
@@ -96,6 +96,11 @@
         mAutoCompletionThreshold = (ListPreference) findPreference(PREF_AUTO_COMPLETION_THRESHOLD);
         mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS);
         ensureConsistencyOfAutoCompletionSettings();
+
+        final boolean showSettingsKeyOption = getResources().getBoolean(
+                R.bool.config_enable_show_settings_key_option);
+        if (!showSettingsKeyOption)
+            getPreferenceScreen().removePreference(mSettingsKeyPreference);
     }
 
     @Override