diff options
Diffstat (limited to 'java/src')
3 files changed, 80 insertions, 17 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java index d0e8b32c3..b256a89c1 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java @@ -36,6 +36,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 mMode; @@ -43,7 +48,10 @@ public class KeyboardId { public final int mColorScheme; public final boolean mWebInput; 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; @@ -53,8 +61,9 @@ public class KeyboardId { private final int mHashCode; public KeyboardId(String xmlName, int xmlId, int colorScheme, Locale locale, int orientation, - 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; @@ -66,6 +75,8 @@ public class KeyboardId { this.mPasswordInput = Utils.isPasswordInputType(inputType) || Utils.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 @@ -84,6 +95,8 @@ public class KeyboardId { mWebInput, mPasswordInput, hasSettingsKey, + f2KeyMode, + clobberSettingsKey, voiceKeyEnabled, hasVoiceKey, mImeAction, @@ -125,6 +138,8 @@ public class KeyboardId { && other.mWebInput == this.mWebInput && 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 @@ -138,13 +153,15 @@ public class KeyboardId { @Override public String toString() { - return String.format("[%s.xml %s %s %s %s %s%s%s%s%s%s%s]", + return String.format("[%s.xml %s %s %s %s %s %s%s%s%s%s%s%s%s]", mXmlName, mLocale, (mOrientation == 1 ? "port" : "land"), modeName(mMode), imeOptionsName(mImeAction), colorSchemeName(mColorScheme), + f2KeyModeName(mF2KeyMode), + (mClobberSettingsKey ? " clobberSettingsKey" : ""), (mWebInput ? " webInput" : ""), (mPasswordInput ? " passwordInput" : ""), (mHasSettingsKey ? " hasSettingsKey" : ""), @@ -195,5 +212,15 @@ public class KeyboardId { return action; } } + + 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"; + } + return null; + } } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java index e599dfdef..b240f6d09 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java @@ -438,6 +438,10 @@ public class KeyboardParser { R.styleable.Keyboard_Case_passwordInput, id.mPasswordInput); final boolean settingsKeyMatched = 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, @@ -455,11 +459,11 @@ public class KeyboardParser { final boolean countryCodeMatched = matchString(a, R.styleable.Keyboard_Case_countryCode, id.mLocale.getCountry()); final boolean selected = modeMatched && webInputMatched && passwordInputMatched - && settingsKeyMatched && voiceEnabledMatched && voiceKeyMatched - && colorSchemeMatched && imeActionMatched && languageCodeMatched - && countryCodeMatched; + && settingsKeyMatched && f2KeyModeMatched && clobberSettingsKeyMatched + && voiceEnabledMatched && voiceKeyMatched && colorSchemeMatched + && imeActionMatched && 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(KeyboardId.modeName( a.getInt(R.styleable.Keyboard_Case_mode, -1)), "mode"), textAttr(KeyboardId.colorSchemeName( @@ -468,6 +472,10 @@ public class KeyboardParser { booleanAttr(a, R.styleable.Keyboard_Case_webInput, "webInput"), 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(KeyboardId.imeOptionsName( diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 6f6355d53..5d3ec526a 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -36,8 +36,8 @@ import java.util.HashMap; import java.util.Locale; public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "KeyboardSwitcher"; - private static final boolean DEBUG = false; + private static final String TAG = KeyboardSwitcher.class.getSimpleName(); + private static final boolean DEBUG = LatinImeLogger.sDBG; public static final boolean DEBUG_STATE = false; private static String sConfigDefaultKeyboardThemeId; @@ -238,12 +238,17 @@ 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; final Locale locale = mSubtypeSwitcher.getInputLocale(); return new KeyboardId( res.getResourceEntryName(xmlId), xmlId, charColorId, locale, orientation, mode, - attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, enableShiftLock); + attribute, hasSettingsKey, f2KeyMode, clobberSettingsKey, mVoiceKeyEnabled, + hasVoiceKey, enableShiftLock); } private void makeSymbolsKeyboardIds(final int mode, EditorInfo attribute) { @@ -253,6 +258,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final int colorScheme = getColorScheme(); final boolean hasVoiceKey = mVoiceKeyEnabled && !mVoiceButtonOnPrimary; 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); // Note: This comment is only applied for phone number keyboard layout. // On non-xlarge device, "@integer/key_switch_alpha_symbol" key code is used to switch // between "phone keyboard" and "phone symbols keyboard". But on xlarge device, @@ -263,10 +272,12 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha int xmlId = mode == KeyboardId.MODE_PHONE ? R.xml.kbd_phone : R.xml.kbd_symbols; final String xmlName = res.getResourceEntryName(xmlId); mSymbolsId = new KeyboardId(xmlName, xmlId, colorScheme, locale, orientation, mode, - attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, true); + attribute, hasSettingsKey, f2KeyMode, clobberSettingsKey, mVoiceKeyEnabled, + hasVoiceKey, true); xmlId = mode == KeyboardId.MODE_PHONE ? R.xml.kbd_phone_symbols : R.xml.kbd_symbols_shift; mSymbolsShiftedId = new KeyboardId(xmlName, xmlId, colorScheme, locale, orientation, mode, - attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, true); + attribute, hasSettingsKey, f2KeyMode, clobberSettingsKey, mVoiceKeyEnabled, + hasVoiceKey, true); } public int getKeyboardMode() { @@ -745,16 +756,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( ((InputMethodManager) context.getSystemService( Context.INPUT_METHOD_SERVICE))))) { @@ -765,4 +776,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; + } + } } |