diff options
author | 2011-06-23 08:35:21 -0700 | |
---|---|---|
committer | 2011-06-23 08:35:21 -0700 | |
commit | 80b79bf9a2bc2ad1e1e9c53782657f47fb1de2c2 (patch) | |
tree | 17fd9338fa5e8493184f286401dca7ca39f2d0e3 /java/src/com/android/inputmethod | |
parent | da9b1325133ed5096c06782537e66f75d8f5cf3e (diff) | |
parent | cd96a691b14b384face577d907f6c1aa33b47233 (diff) | |
download | latinime-80b79bf9a2bc2ad1e1e9c53782657f47fb1de2c2.tar.gz latinime-80b79bf9a2bc2ad1e1e9c53782657f47fb1de2c2.tar.xz latinime-80b79bf9a2bc2ad1e1e9c53782657f47fb1de2c2.zip |
Merge "Fix "Show settings key" option on 7" device"
Diffstat (limited to 'java/src/com/android/inputmethod')
3 files changed, 76 insertions, 17 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java index b91134dd6..9c63c198c 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java @@ -37,6 +37,11 @@ public class KeyboardId { public static final int MODE_PHONE = 4; public static final int MODE_NUMBER = 5; + public static final int F2KEY_MODE_NONE = 0; + public static final int F2KEY_MODE_SETTINGS = 1; + public static final int F2KEY_MODE_SHORTCUT_IME = 2; + public static final int F2KEY_MODE_SHORTCUT_IME_OR_SETTINGS = 3; + public final Locale mLocale; public final int mOrientation; public final int mWidth; @@ -44,7 +49,10 @@ public class KeyboardId { public final int mXmlId; public final boolean mNavigateAction; public final boolean mPasswordInput; + // TODO: Clean up these booleans and modes. public final boolean mHasSettingsKey; + public final int mF2KeyMode; + public final boolean mClobberSettingsKey; public final boolean mVoiceKeyEnabled; public final boolean mHasVoiceKey; public final int mImeAction; @@ -56,8 +64,9 @@ public class KeyboardId { private final int mHashCode; public KeyboardId(String xmlName, int xmlId, Locale locale, int orientation, int width, - int mode, EditorInfo attribute, boolean hasSettingsKey, boolean voiceKeyEnabled, - boolean hasVoiceKey, boolean enableShiftLock) { + int mode, EditorInfo attribute, boolean hasSettingsKey, int f2KeyMode, + boolean clobberSettingsKey, boolean voiceKeyEnabled, boolean hasVoiceKey, + boolean enableShiftLock) { final int inputType = (attribute != null) ? attribute.inputType : 0; final int imeOptions = (attribute != null) ? attribute.imeOptions : 0; this.mLocale = locale; @@ -72,6 +81,8 @@ public class KeyboardId { this.mPasswordInput = InputTypeCompatUtils.isPasswordInputType(inputType) || InputTypeCompatUtils.isVisiblePasswordInputType(inputType); this.mHasSettingsKey = hasSettingsKey; + this.mF2KeyMode = f2KeyMode; + this.mClobberSettingsKey = clobberSettingsKey; this.mVoiceKeyEnabled = voiceKeyEnabled; this.mHasVoiceKey = hasVoiceKey; // We are interested only in {@link EditorInfo#IME_MASK_ACTION} enum value and @@ -92,6 +103,8 @@ public class KeyboardId { mNavigateAction, mPasswordInput, hasSettingsKey, + f2KeyMode, + clobberSettingsKey, voiceKeyEnabled, hasVoiceKey, mImeAction, @@ -101,14 +114,16 @@ public class KeyboardId { public KeyboardId cloneWithNewLayout(String xmlName, int xmlId) { return new KeyboardId(xmlName, xmlId, mLocale, mOrientation, mWidth, mMode, mAttribute, - mHasSettingsKey, mVoiceKeyEnabled, mHasVoiceKey, mEnableShiftLock); + mHasSettingsKey, mF2KeyMode, mClobberSettingsKey, mVoiceKeyEnabled, mHasVoiceKey, + mEnableShiftLock); } public KeyboardId cloneWithNewGeometry(int width) { if (mWidth == width) return this; return new KeyboardId(mXmlName, mXmlId, mLocale, mOrientation, width, mMode, mAttribute, - mHasSettingsKey, mVoiceKeyEnabled, mHasVoiceKey, mEnableShiftLock); + mHasSettingsKey, mF2KeyMode, mClobberSettingsKey, mVoiceKeyEnabled, mHasVoiceKey, + mEnableShiftLock); } public int getXmlId() { @@ -149,6 +164,8 @@ public class KeyboardId { && other.mNavigateAction == this.mNavigateAction && other.mPasswordInput == this.mPasswordInput && other.mHasSettingsKey == this.mHasSettingsKey + && other.mF2KeyMode == this.mF2KeyMode + && other.mClobberSettingsKey == this.mClobberSettingsKey && other.mVoiceKeyEnabled == this.mVoiceKeyEnabled && other.mHasVoiceKey == this.mHasVoiceKey && other.mImeAction == this.mImeAction @@ -162,12 +179,14 @@ public class KeyboardId { @Override public String toString() { - return String.format("[%s.xml %s %s%d %s %s %s%s%s%s%s%s]", + return String.format("[%s.xml %s %s%d %s %s %s%s%s%s%s%s%s%s]", mXmlName, mLocale, (mOrientation == 1 ? "port" : "land"), mWidth, modeName(mMode), EditorInfoCompatUtils.imeOptionsName(mImeAction), + f2KeyModeName(mF2KeyMode), + (mClobberSettingsKey ? " clobberSettingsKey" : ""), (mNavigateAction ? " navigateAction" : ""), (mPasswordInput ? " passwordInput" : ""), (mHasSettingsKey ? " hasSettingsKey" : ""), @@ -185,7 +204,17 @@ public class KeyboardId { case MODE_IM: return "im"; case MODE_PHONE: return "phone"; case MODE_NUMBER: return "number"; + default: return null; + } + } + + public static String f2KeyModeName(int f2KeyMode) { + switch (f2KeyMode) { + case F2KEY_MODE_NONE: return "none"; + case F2KEY_MODE_SETTINGS: return "settings"; + case F2KEY_MODE_SHORTCUT_IME: return "shortcutIme"; + case F2KEY_MODE_SHORTCUT_IME_OR_SETTINGS: return "shortcutImeOrSettings"; + default: return null; } - return null; } } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index eef01a67c..275e9d1fe 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -284,6 +284,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } } final boolean hasSettingsKey = hasSettingsKey(attribute); + final int f2KeyMode = getF2KeyMode(mPrefs, mInputMethodService, attribute); + final boolean clobberSettingsKey = Utils.inPrivateImeOptions( + mInputMethodService.getPackageName(), LatinIME.IME_OPTION_NO_SETTINGS_KEY, + attribute); final Resources res = mInputMethodService.getResources(); final int orientation = res.getConfiguration().orientation; if (mKeyboardWidth == 0) @@ -291,7 +295,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final Locale locale = mSubtypeSwitcher.getInputLocale(); return new KeyboardId( res.getResourceEntryName(xmlId), xmlId, locale, orientation, mKeyboardWidth, - mode, attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, enableShiftLock); + mode, attribute, hasSettingsKey, f2KeyMode, clobberSettingsKey, mVoiceKeyEnabled, + hasVoiceKey, enableShiftLock); } private KeyboardId makeSiblingKeyboardId(KeyboardId base, int alphabet, int phone) { @@ -805,16 +810,16 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } private static boolean getSettingsKeyMode(SharedPreferences prefs, Context context) { - Resources resources = context.getResources(); - final boolean showSettingsKeyOption = resources.getBoolean( + final Resources res = context.getResources(); + final boolean showSettingsKeyOption = res.getBoolean( R.bool.config_enable_show_settings_key_option); if (showSettingsKeyOption) { final String settingsKeyMode = prefs.getString(Settings.PREF_SETTINGS_KEY, - resources.getString(DEFAULT_SETTINGS_KEY_MODE)); + 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(resources.getString(SETTINGS_KEY_MODE_ALWAYS_SHOW)) - || (settingsKeyMode.equals(resources.getString(SETTINGS_KEY_MODE_AUTO)) + if (settingsKeyMode.equals(res.getString(SETTINGS_KEY_MODE_ALWAYS_SHOW)) + || (settingsKeyMode.equals(res.getString(SETTINGS_KEY_MODE_AUTO)) && Utils.hasMultipleEnabledIMEsOrSubtypes( (InputMethodManagerCompatWrapper.getInstance(context))))) { return true; @@ -824,4 +829,21 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // If the show settings key option is disabled, we always try showing the settings key. return true; } + + private static int getF2KeyMode(SharedPreferences prefs, Context context, + EditorInfo attribute) { + final boolean clobberSettingsKey = Utils.inPrivateImeOptions( + context.getPackageName(), LatinIME.IME_OPTION_NO_SETTINGS_KEY, attribute); + final Resources res = context.getResources(); + 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; + } + } } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java index 8954eec59..a6708171f 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java @@ -488,8 +488,12 @@ public class KeyboardParser { R.styleable.Keyboard_Case_navigateAction, id.mNavigateAction); final boolean passwordInputMatched = matchBoolean(a, R.styleable.Keyboard_Case_passwordInput, id.mPasswordInput); - final boolean settingsKeyMatched = matchBoolean(a, + final boolean hasSettingsKeyMatched = matchBoolean(a, R.styleable.Keyboard_Case_hasSettingsKey, id.mHasSettingsKey); + final boolean f2KeyModeMatched = matchInteger(a, + R.styleable.Keyboard_Case_f2KeyMode, id.mF2KeyMode); + final boolean clobberSettingsKeyMatched = matchBoolean(a, + R.styleable.Keyboard_Case_clobberSettingsKey, id.mClobberSettingsKey); final boolean voiceEnabledMatched = matchBoolean(a, R.styleable.Keyboard_Case_voiceKeyEnabled, id.mVoiceKeyEnabled); final boolean voiceKeyMatched = matchBoolean(a, @@ -507,15 +511,19 @@ public class KeyboardParser { final boolean countryCodeMatched = matchString(a, R.styleable.Keyboard_Case_countryCode, id.mLocale.getCountry()); final boolean selected = modeMatched && navigateActionMatched && passwordInputMatched - && settingsKeyMatched && voiceEnabledMatched && voiceKeyMatched - && imeActionMatched && localeCodeMatched && languageCodeMatched - && countryCodeMatched; + && hasSettingsKeyMatched && f2KeyModeMatched && clobberSettingsKeyMatched + && voiceEnabledMatched && voiceKeyMatched && imeActionMatched && + localeCodeMatched && languageCodeMatched && countryCodeMatched; - if (DEBUG) Log.d(TAG, String.format("<%s%s%s%s%s%s%s%s%s%s%s> %s", TAG_CASE, + if (DEBUG) Log.d(TAG, String.format("<%s%s%s%s%s%s%s%s%s%s%s%s%s> %s", TAG_CASE, textAttr(a.getString(R.styleable.Keyboard_Case_mode), "mode"), booleanAttr(a, R.styleable.Keyboard_Case_navigateAction, "navigateAction"), booleanAttr(a, R.styleable.Keyboard_Case_passwordInput, "passwordInput"), booleanAttr(a, R.styleable.Keyboard_Case_hasSettingsKey, "hasSettingsKey"), + textAttr(KeyboardId.f2KeyModeName( + a.getInt(R.styleable.Keyboard_Case_f2KeyMode, -1)), "f2KeyMode"), + booleanAttr(a, R.styleable.Keyboard_Case_clobberSettingsKey, + "clobberSettingsKey"), booleanAttr(a, R.styleable.Keyboard_Case_voiceKeyEnabled, "voiceKeyEnabled"), booleanAttr(a, R.styleable.Keyboard_Case_hasVoiceKey, "hasVoiceKey"), textAttr(EditorInfoCompatUtils.imeOptionsName( |