From cb389ef0d6e6eec737c249e1729c2a2cdc30f341 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 4 Apr 2012 18:18:56 +0900 Subject: [PATCH] Refactor to utilize InputMethodSubtype Change-Id: I76fbc8a395eb8dab996c02c86d7328f07865f8cf --- .../inputmethod/keyboard/KeyboardSet.java | 6 ++++- .../keyboard/KeyboardSwitcher.java | 7 ++---- .../android/inputmethod/latin/LatinIME.java | 4 +--- .../inputmethod/latin/SubtypeLocale.java | 11 +++++++++ .../inputmethod/latin/SubtypeSwitcher.java | 23 +++++++------------ 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java index efa4021b0..f9b6b72c7 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java @@ -25,6 +25,7 @@ import android.text.InputType; import android.util.Log; import android.util.Xml; import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.compat.EditorInfoCompatUtils; import com.android.inputmethod.keyboard.KeyboardSet.Params.ElementParams; @@ -242,7 +243,10 @@ public class KeyboardSet { return this; } - public Builder setSubtype(Locale inputLocale, boolean asciiCapable) { + public Builder setSubtype(InputMethodSubtype subtype) { + final Locale inputLocale = SubtypeLocale.getSubtypeLocale(subtype); + final boolean asciiCapable = subtype.containsExtraValueKey( + LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE); final boolean deprecatedForceAscii = StringUtils.inPrivateImeOptions( mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo); final boolean forceAscii = EditorInfoCompatUtils.hasFlagForceAscii( diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 93d8704de..3bc63f3dd 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -137,10 +137,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions { final KeyboardSet.Builder builder = new KeyboardSet.Builder(mThemeContext, editorInfo); builder.setScreenGeometry(mThemeContext.getResources().getConfiguration().orientation, mThemeContext.getResources().getDisplayMetrics().widthPixels); - builder.setSubtype( - mSubtypeSwitcher.getInputLocale(), - mSubtypeSwitcher.currentSubtypeContainsExtraValueKey( - LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE)); + builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype()); builder.setOptions( settingsValues.isVoiceKeyEnabled(editorInfo), settingsValues.isVoiceKeyOnMain(), @@ -384,7 +381,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions { public void onNetworkStateChanged() { if (mKeyboardView != null) { - mKeyboardView.updateShortcutKey(SubtypeSwitcher.getInstance().isShortcutImeReady()); + mKeyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady()); } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index db57044e9..8a26d2b9e 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -713,9 +713,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold); } - if (mSubtypeSwitcher.isKeyboardMode()) { - switcher.loadKeyboard(editorInfo, mSettingsValues); - } + switcher.loadKeyboard(editorInfo, mSettingsValues); if (mSuggestionsView != null) mSuggestionsView.clear(); diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java index ba67f3358..fac74f0b5 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java +++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java @@ -18,6 +18,7 @@ package com.android.inputmethod.latin; import android.content.Context; import android.content.res.Resources; +import android.view.inputmethod.InputMethodSubtype; import java.util.Locale; @@ -120,4 +121,14 @@ public class SubtypeLocale { // - It also does not work with unicode surrogate code points. return s.toUpperCase(locale).charAt(0) + s.substring(1); } + + public static String getSubtypeLocaleString(InputMethodSubtype subtype) { + final String keyboardLocale = subtype.getExtraValueOf( + LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE); + return keyboardLocale != null ? keyboardLocale : subtype.getLocale(); + } + + public static Locale getSubtypeLocale(InputMethodSubtype subtype) { + return LocaleUtils.constructLocaleFromString(getSubtypeLocaleString(subtype)); + } } diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 7541bd31b..3ed7f8700 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -419,30 +419,23 @@ public class SubtypeSwitcher { } } - public boolean isKeyboardMode() { + // TODO: Remove this method + private boolean isKeyboardMode() { return KEYBOARD_MODE.equals(getCurrentSubtypeMode()); } - ///////////////////////////// - // Other utility functions // - ///////////////////////////// - - public String getCurrentSubtypeExtraValue() { - // If null, return what an empty ExtraValue would return : the empty string. - return mCurrentSubtype.getExtraValue(); + // TODO: Remove this method + private String getCurrentSubtypeMode() { + return mCurrentSubtype.getMode(); } + // TODO: Remove this method public boolean currentSubtypeContainsExtraValueKey(String key) { // If null, return what an empty ExtraValue would return : false. return mCurrentSubtype.containsExtraValueKey(key); } - public String getCurrentSubtypeExtraValueOf(String key) { - // If null, return what an empty ExtraValue would return : null. - return mCurrentSubtype.getExtraValueOf(key); - } - - public String getCurrentSubtypeMode() { - return mCurrentSubtype.getMode(); + public InputMethodSubtype getCurrentSubtype() { + return mCurrentSubtype; } }