Turn off the Settings key by default

bug:5094401
Change-Id: Ieb42fdfa79be2afcfa6634e7404c17737ef6927d
main
Ken Wakasa 2011-07-30 10:19:51 +09:00
parent 97c35650ad
commit 2ba975afb9
6 changed files with 50 additions and 120 deletions

View File

@ -50,26 +50,6 @@
<!-- Character for close candidates pane (BLACK UP-POINTING TRIANGLE) --> <!-- Character for close candidates pane (BLACK UP-POINTING TRIANGLE) -->
<string name="label_close_candidates_pane">\u25b2</string> <string name="label_close_candidates_pane">\u25b2</string>
<!-- Option values to show/hide the settings key in onscreen keyboard -->
<!-- Automatically decide to show or hide the settings key -->
<string name="settings_key_mode_auto">0</string>
<!-- Always show the settings key -->
<string name="settings_key_mode_always_show">1</string>
<!-- Always hide the settings key -->
<string name="settings_key_mode_always_hide">2</string>
<!-- Array of the settings key mode values -->
<string-array name="settings_key_modes_values">
<item>@string/settings_key_mode_auto</item>
<item>@string/settings_key_mode_always_show</item>
<item>@string/settings_key_mode_always_hide</item>
</string-array>
<!-- Array of the settings key modes -->
<string-array name="settings_key_modes">
<item>@string/settings_key_mode_auto_name</item>
<item>@string/settings_key_mode_always_show_name</item>
<item>@string/settings_key_mode_always_hide_name</item>
</string-array>
<!-- Always show the suggestion strip --> <!-- Always show the suggestion strip -->
<string name="prefs_suggestion_visibility_show_value">0</string> <string name="prefs_suggestion_visibility_show_value">0</string>
<!-- Show the suggestion strip only on portrait mode --> <!-- Show the suggestion strip only on portrait mode -->

View File

@ -82,12 +82,6 @@
<!-- Option to show/hide the settings key --> <!-- Option to show/hide the settings key -->
<string name="prefs_settings_key">Show settings key</string> <string name="prefs_settings_key">Show settings key</string>
<!-- Option to automatically decide to show/hide the settings key -->
<string name="settings_key_mode_auto_name">Automatic</string>
<!-- Option to always show the settings key -->
<string name="settings_key_mode_always_show_name">Always show</string>
<!-- Option to always hide the settings key -->
<string name="settings_key_mode_always_hide_name">Always hide</string>
<!-- Option to decide the auto correction threshold score --> <!-- Option to decide the auto correction threshold score -->
<!-- Option to enable auto correction [CHAR LIMIT=20]--> <!-- Option to enable auto correction [CHAR LIMIT=20]-->

View File

@ -49,13 +49,11 @@
android:summary="@string/prefs_enable_recorrection_summary" android:summary="@string/prefs_enable_recorrection_summary"
android:persistent="true" android:persistent="true"
android:defaultValue="@bool/config_default_recorrection_enabled" /> android:defaultValue="@bool/config_default_recorrection_enabled" />
<ListPreference <CheckBoxPreference
android:key="settings_key" android:key="show_settings_key"
android:title="@string/prefs_settings_key" android:title="@string/prefs_settings_key"
android:persistent="true" android:persistent="true"
android:entryValues="@array/settings_key_modes_values" android:defaultValue="false" />
android:entries="@array/settings_key_modes"
android:defaultValue="@string/settings_key_mode_auto" />
<ListPreference <ListPreference
android:key="voice_mode" android:key="voice_mode"
android:title="@string/voice_input" android:title="@string/voice_input"

View File

@ -99,14 +99,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
private static final int SWITCH_STATE_CHORDING_SYMBOL = 6; private static final int SWITCH_STATE_CHORDING_SYMBOL = 6;
private int mSwitchState = SWITCH_STATE_ALPHA; private int mSwitchState = SWITCH_STATE_ALPHA;
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 int mThemeIndex = -1; private int mThemeIndex = -1;
private Context mThemeContext; private Context mThemeContext;
@ -228,21 +220,12 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
} }
} }
public void loadKeyboard(EditorInfo attribute, Settings.Values settings) { public void loadKeyboard(EditorInfo editorInfo, Settings.Values settingsValues) {
mSwitchState = SWITCH_STATE_ALPHA; mSwitchState = SWITCH_STATE_ALPHA;
try { try {
final Locale locale = mSubtypeSwitcher.getInputLocale(); mMainKeyboardId = getKeyboardId(editorInfo, false, false, settingsValues);
final Configuration conf = mResources.getConfiguration(); mSymbolsKeyboardId = getKeyboardId(editorInfo, true, false, settingsValues);
final int width = mWindowWidthCache.getWidth(conf); mSymbolsShiftedKeyboardId = getKeyboardId(editorInfo, true, true, settingsValues);
final int orientation = conf.orientation;
final boolean voiceKeyEnabled = settings.isVoiceKeyEnabled(attribute);
final boolean voiceKeyOnMain = settings.isVoiceKeyOnMain();
mMainKeyboardId = getKeyboardId(attribute, locale, orientation, width,
false, false, voiceKeyEnabled, voiceKeyOnMain);
mSymbolsKeyboardId = getKeyboardId(attribute, locale, orientation, width,
true, false, voiceKeyEnabled, voiceKeyOnMain);
mSymbolsShiftedKeyboardId = getKeyboardId(attribute, locale, orientation, width,
true, true, voiceKeyEnabled, voiceKeyOnMain);
setKeyboard(getKeyboard(mMainKeyboardId)); setKeyboard(getKeyboard(mMainKeyboardId));
} catch (RuntimeException e) { } catch (RuntimeException e) {
Log.w(TAG, "loading keyboard failed: " + mMainKeyboardId, e); Log.w(TAG, "loading keyboard failed: " + mMainKeyboardId, e);
@ -309,10 +292,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
return keyboard; return keyboard;
} }
private KeyboardId getKeyboardId(EditorInfo attribute, Locale locale, final int orientation, private KeyboardId getKeyboardId(EditorInfo editorInfo, final boolean isSymbols,
final int width, final boolean isSymbols, final boolean isShift, final boolean isShift, Settings.Values settingsValues) {
final boolean voiceKeyEnabled, final boolean voiceKeyOnMain) { final int mode = Utils.getKeyboardMode(editorInfo);
final int mode = Utils.getKeyboardMode(attribute);
final int xmlId; final int xmlId;
switch (mode) { switch (mode) {
case KeyboardId.MODE_PHONE: case KeyboardId.MODE_PHONE:
@ -330,16 +312,20 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
break; break;
} }
final boolean settingsKeyEnabled = settingsValues.isSettingsKeyEnabled(editorInfo);
final boolean voiceKeyEnabled = settingsValues.isVoiceKeyEnabled(editorInfo);
final boolean voiceKeyOnMain = settingsValues.isVoiceKeyOnMain();
final boolean noSettingsKey = Utils.inPrivateImeOptions( final boolean noSettingsKey = Utils.inPrivateImeOptions(
mPackageName, LatinIME.IME_OPTION_NO_SETTINGS_KEY, attribute); mPackageName, LatinIME.IME_OPTION_NO_SETTINGS_KEY, editorInfo);
final boolean hasSettingsKey = getSettingsKeyMode(mPrefs, mResources) && !noSettingsKey; final boolean hasSettingsKey = settingsKeyEnabled && !noSettingsKey;
final int f2KeyMode = getF2KeyMode(mPrefs, mResources, mPackageName, attribute); final int f2KeyMode = getF2KeyMode(settingsKeyEnabled, noSettingsKey);
final boolean hasVoiceKey = voiceKeyEnabled && (isSymbols != voiceKeyOnMain); final boolean hasVoiceKey = voiceKeyEnabled && (isSymbols != voiceKeyOnMain);
final Configuration conf = mResources.getConfiguration();
return new KeyboardId( return new KeyboardId(
mResources.getResourceEntryName(xmlId), xmlId, locale, mResources.getResourceEntryName(xmlId), xmlId, mSubtypeSwitcher.getInputLocale(),
orientation, width, mode, attribute, hasSettingsKey, f2KeyMode, noSettingsKey, conf.orientation, mWindowWidthCache.getWidth(conf), mode, editorInfo,
voiceKeyEnabled, hasVoiceKey); hasSettingsKey, f2KeyMode, noSettingsKey, voiceKeyEnabled, hasVoiceKey);
} }
public int getKeyboardMode() { public int getKeyboardMode() {
@ -828,9 +814,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (PREF_KEYBOARD_LAYOUT.equals(key)) { if (PREF_KEYBOARD_LAYOUT.equals(key)) {
final int layoutId = getKeyboardThemeIndex(mInputMethodService, sharedPreferences); final int themeIndex = getKeyboardThemeIndex(mInputMethodService, sharedPreferences);
postSetInputView(createInputView(layoutId, false)); postSetInputView(createInputView(themeIndex, false));
} else if (Settings.PREF_SETTINGS_KEY.equals(key)) { } else if (Settings.PREF_SHOW_SETTINGS_KEY.equals(key)) {
postSetInputView(createInputView(mThemeIndex, true)); postSetInputView(createInputView(mThemeIndex, true));
} }
} }
@ -848,39 +834,18 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
} }
} }
private static boolean getSettingsKeyMode(SharedPreferences prefs, Resources res) { private static int getF2KeyMode(boolean settingsKeyEnabled, boolean noSettingsKey) {
final boolean showSettingsKeyOption = res.getBoolean( if (noSettingsKey) {
R.bool.config_enable_show_settings_key_option); // Never shows the Settings key
if (showSettingsKeyOption) {
final String settingsKeyMode = prefs.getString(Settings.PREF_SETTINGS_KEY,
res.getString(DEFAULT_SETTINGS_KEY_MODE));
// 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(res.getString(SETTINGS_KEY_MODE_ALWAYS_SHOW))
|| (settingsKeyMode.equals(res.getString(SETTINGS_KEY_MODE_AUTO))
&& Utils.hasMultipleEnabledIMEsOrSubtypes(
(InputMethodManagerCompatWrapper.getInstance())))) {
return true;
}
return false;
}
// If the show settings key option is disabled, we always try showing the settings key.
return true;
}
private static int getF2KeyMode(SharedPreferences prefs, Resources res, String packageName,
EditorInfo attribute) {
final boolean clobberSettingsKey = Utils.inPrivateImeOptions(
packageName, LatinIME.IME_OPTION_NO_SETTINGS_KEY, attribute);
final String settingsKeyMode = prefs.getString(Settings.PREF_SETTINGS_KEY,
res.getString(DEFAULT_SETTINGS_KEY_MODE));
if (settingsKeyMode.equals(res.getString(SETTINGS_KEY_MODE_AUTO))) {
return clobberSettingsKey ? KeyboardId.F2KEY_MODE_SHORTCUT_IME
: KeyboardId.F2KEY_MODE_SHORTCUT_IME_OR_SETTINGS;
} else if (settingsKeyMode.equals(res.getString(SETTINGS_KEY_MODE_ALWAYS_SHOW))) {
return clobberSettingsKey ? KeyboardId.F2KEY_MODE_NONE : KeyboardId.F2KEY_MODE_SETTINGS;
} else { // SETTINGS_KEY_MODE_ALWAYS_HIDE
return KeyboardId.F2KEY_MODE_SHORTCUT_IME; return KeyboardId.F2KEY_MODE_SHORTCUT_IME;
} }
if (settingsKeyEnabled) {
return KeyboardId.F2KEY_MODE_SETTINGS;
} else {
// It should be alright to fall back to the Settings key on 7-inch layouts
// even when the Settings key is not explicitly enabled.
return KeyboardId.F2KEY_MODE_SHORTCUT_IME_OR_SETTINGS;
}
} }
} }

View File

@ -61,7 +61,7 @@ public class Settings extends InputMethodSettingsActivity
public static final String PREF_KEY_PREVIEW_POPUP_ON = "popup_on"; public static final String PREF_KEY_PREVIEW_POPUP_ON = "popup_on";
public static final String PREF_RECORRECTION_ENABLED = "recorrection_enabled"; public static final String PREF_RECORRECTION_ENABLED = "recorrection_enabled";
public static final String PREF_AUTO_CAP = "auto_cap"; public static final String PREF_AUTO_CAP = "auto_cap";
public static final String PREF_SETTINGS_KEY = "settings_key"; public static final String PREF_SHOW_SETTINGS_KEY = "show_settings_key";
public static final String PREF_VOICE_SETTINGS_KEY = "voice_mode"; public static final String PREF_VOICE_SETTINGS_KEY = "voice_mode";
public static final String PREF_INPUT_LANGUAGE = "input_language"; public static final String PREF_INPUT_LANGUAGE = "input_language";
public static final String PREF_SELECTED_LANGUAGES = "selected_languages"; public static final String PREF_SELECTED_LANGUAGES = "selected_languages";
@ -118,6 +118,7 @@ public class Settings extends InputMethodSettingsActivity
public final boolean mBigramPredictionEnabled; public final boolean mBigramPredictionEnabled;
public final boolean mUseContactsDict; public final boolean mUseContactsDict;
private final boolean mShowSettingsKey;
private final boolean mVoiceKeyEnabled; private final boolean mVoiceKeyEnabled;
private final boolean mVoiceKeyOnMain; private final boolean mVoiceKeyOnMain;
@ -165,21 +166,17 @@ public class Settings extends InputMethodSettingsActivity
mVibrateOn = hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON, false); mVibrateOn = hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON, false);
mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON, mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON,
res.getBoolean(R.bool.config_default_sound_enabled)); res.getBoolean(R.bool.config_default_sound_enabled));
mKeyPreviewPopupOn = isKeyPreviewPopupEnabled(prefs, res); mKeyPreviewPopupOn = isKeyPreviewPopupEnabled(prefs, res);
mKeyPreviewPopupDismissDelay = getKeyPreviewPopupDismissDelay(prefs, res); mKeyPreviewPopupDismissDelay = getKeyPreviewPopupDismissDelay(prefs, res);
mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true); mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true);
mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res); mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res);
mBigramSuggestionEnabled = mAutoCorrectEnabled mBigramSuggestionEnabled = mAutoCorrectEnabled
&& isBigramSuggestionEnabled(prefs, res, mAutoCorrectEnabled); && isBigramSuggestionEnabled(prefs, res, mAutoCorrectEnabled);
mBigramPredictionEnabled = mBigramSuggestionEnabled mBigramPredictionEnabled = mBigramSuggestionEnabled
&& isBigramPredictionEnabled(prefs, res); && isBigramPredictionEnabled(prefs, res);
mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res); mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res);
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
mShowSettingsKey = prefs.getBoolean(Settings.PREF_SHOW_SETTINGS_KEY, false);
final String voiceModeMain = res.getString(R.string.voice_mode_main); final String voiceModeMain = res.getString(R.string.voice_mode_main);
final String voiceModeOff = res.getString(R.string.voice_mode_off); final String voiceModeOff = res.getString(R.string.voice_mode_off);
final String voiceMode = prefs.getString(PREF_VOICE_SETTINGS_KEY, voiceModeMain); final String voiceMode = prefs.getString(PREF_VOICE_SETTINGS_KEY, voiceModeMain);
@ -284,6 +281,10 @@ public class Settings extends InputMethodSettingsActivity
return builder.setIsPunctuationSuggestions().build(); return builder.setIsPunctuationSuggestions().build();
} }
public boolean isSettingsKeyEnabled(EditorInfo attribute) {
return mShowSettingsKey;
}
public boolean isVoiceKeyEnabled(EditorInfo attribute) { public boolean isVoiceKeyEnabled(EditorInfo attribute) {
final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled(); final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
final int inputType = (attribute != null) ? attribute.inputType : 0; final int inputType = (attribute != null) ? attribute.inputType : 0;
@ -298,7 +299,7 @@ public class Settings extends InputMethodSettingsActivity
private PreferenceScreen mInputLanguageSelection; private PreferenceScreen mInputLanguageSelection;
private ListPreference mVoicePreference; private ListPreference mVoicePreference;
private ListPreference mSettingsKeyPreference; private CheckBoxPreference mShowSettingsKeyPreference;
private ListPreference mShowCorrectionSuggestionsPreference; private ListPreference mShowCorrectionSuggestionsPreference;
private ListPreference mAutoCorrectionThreshold; private ListPreference mAutoCorrectionThreshold;
private ListPreference mKeyPreviewPopupDismissDelay; private ListPreference mKeyPreviewPopupDismissDelay;
@ -345,7 +346,7 @@ public class Settings extends InputMethodSettingsActivity
mInputLanguageSelection = (PreferenceScreen) findPreference(PREF_SUBTYPES); mInputLanguageSelection = (PreferenceScreen) findPreference(PREF_SUBTYPES);
mInputLanguageSelection.setOnPreferenceClickListener(this); mInputLanguageSelection.setOnPreferenceClickListener(this);
mVoicePreference = (ListPreference) findPreference(PREF_VOICE_SETTINGS_KEY); mVoicePreference = (ListPreference) findPreference(PREF_VOICE_SETTINGS_KEY);
mSettingsKeyPreference = (ListPreference) findPreference(PREF_SETTINGS_KEY); mShowSettingsKeyPreference = (CheckBoxPreference) findPreference(PREF_SHOW_SETTINGS_KEY);
mShowCorrectionSuggestionsPreference = mShowCorrectionSuggestionsPreference =
(ListPreference) findPreference(PREF_SHOW_SUGGESTIONS_SETTING); (ListPreference) findPreference(PREF_SHOW_SUGGESTIONS_SETTING);
SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
@ -376,7 +377,7 @@ public class Settings extends InputMethodSettingsActivity
final boolean showSettingsKeyOption = res.getBoolean( final boolean showSettingsKeyOption = res.getBoolean(
R.bool.config_enable_show_settings_key_option); R.bool.config_enable_show_settings_key_option);
if (!showSettingsKeyOption) { if (!showSettingsKeyOption) {
generalSettings.removePreference(mSettingsKeyPreference); generalSettings.removePreference(mShowSettingsKeyPreference);
} }
final boolean showVoiceKeyOption = res.getBoolean( final boolean showVoiceKeyOption = res.getBoolean(
@ -457,7 +458,6 @@ public class Settings extends InputMethodSettingsActivity
} else { } else {
getPreferenceScreen().removePreference(mVoicePreference); getPreferenceScreen().removePreference(mVoicePreference);
} }
updateSettingsKeySummary();
updateShowCorrectionSuggestionsSummary(); updateShowCorrectionSuggestionsSummary();
updateKeyPreviewPopupDelaySummary(); updateKeyPreviewPopupDelaySummary();
} }
@ -489,7 +489,6 @@ public class Settings extends InputMethodSettingsActivity
mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff) mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff)
.equals(mVoiceModeOff)); .equals(mVoiceModeOff));
updateVoiceModeSummary(); updateVoiceModeSummary();
updateSettingsKeySummary();
updateShowCorrectionSuggestionsSummary(); updateShowCorrectionSuggestionsSummary();
updateKeyPreviewPopupDelaySummary(); updateKeyPreviewPopupDelaySummary();
} }
@ -513,12 +512,6 @@ public class Settings extends InputMethodSettingsActivity
mShowCorrectionSuggestionsPreference.getValue())]); mShowCorrectionSuggestionsPreference.getValue())]);
} }
private void updateSettingsKeySummary() {
mSettingsKeyPreference.setSummary(
getResources().getStringArray(R.array.settings_key_modes)
[mSettingsKeyPreference.findIndexOfValue(mSettingsKeyPreference.getValue())]);
}
private void updateKeyPreviewPopupDelaySummary() { private void updateKeyPreviewPopupDelaySummary() {
final ListPreference lp = mKeyPreviewPopupDismissDelay; final ListPreference lp = mKeyPreviewPopupDismissDelay;
lp.setSummary(lp.getEntries()[lp.findIndexOfValue(lp.getValue())]); lp.setSummary(lp.getEntries()[lp.findIndexOfValue(lp.getValue())]);

View File

@ -546,11 +546,11 @@ public class Utils {
} }
} }
public static int getKeyboardMode(EditorInfo attribute) { public static int getKeyboardMode(EditorInfo editorInfo) {
if (attribute == null) if (editorInfo == null)
return KeyboardId.MODE_TEXT; return KeyboardId.MODE_TEXT;
final int inputType = attribute.inputType; final int inputType = editorInfo.inputType;
final int variation = inputType & InputType.TYPE_MASK_VARIATION; final int variation = inputType & InputType.TYPE_MASK_VARIATION;
switch (inputType & InputType.TYPE_MASK_CLASS) { switch (inputType & InputType.TYPE_MASK_CLASS) {
@ -587,11 +587,11 @@ public class Utils {
} }
public static boolean inPrivateImeOptions(String packageName, String key, public static boolean inPrivateImeOptions(String packageName, String key,
EditorInfo attribute) { EditorInfo editorInfo) {
if (attribute == null) if (editorInfo == null)
return false; return false;
return containsInCsv(packageName != null ? packageName + "." + key : key, return containsInCsv(packageName != null ? packageName + "." + key : key,
attribute.privateImeOptions); editorInfo.privateImeOptions);
} }
/** /**