diff options
author | satok <satok@google.com> | 2012-05-02 20:51:49 +0900 |
---|---|---|
committer | satok <satok@google.com> | 2012-05-02 21:08:46 +0900 |
commit | 472c3c93fc61b797b3ee22352a876ccae3eeb153 (patch) | |
tree | 54671fbc8e57facbd67918c2ff307ad16c3944c7 /src/com | |
parent | 9593b743cb625e88b97b2674c5f528bb07f96011 (diff) | |
download | packages_apps_settings-472c3c93fc61b797b3ee22352a876ccae3eeb153.zip packages_apps_settings-472c3c93fc61b797b3ee22352a876ccae3eeb153.tar.gz packages_apps_settings-472c3c93fc61b797b3ee22352a876ccae3eeb153.tar.bz2 |
Always on the valid system default ime
Bug: 6422390
Change-Id: I9af4065e4b9f9332f3b0db168dea5546727d5951
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/settings/inputmethod/InputMethodAndSubtypeUtil.java | 54 | ||||
-rw-r--r-- | src/com/android/settings/inputmethod/InputMethodPreference.java | 10 |
2 files changed, 55 insertions, 9 deletions
diff --git a/src/com/android/settings/inputmethod/InputMethodAndSubtypeUtil.java b/src/com/android/settings/inputmethod/InputMethodAndSubtypeUtil.java index cb4058f..c7d8c89 100644 --- a/src/com/android/settings/inputmethod/InputMethodAndSubtypeUtil.java +++ b/src/com/android/settings/inputmethod/InputMethodAndSubtypeUtil.java @@ -22,6 +22,7 @@ import android.content.ContentResolver; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.content.res.Resources; import android.preference.CheckBoxPreference; import android.preference.Preference; import android.preference.PreferenceScreen; @@ -36,6 +37,7 @@ import android.view.inputmethod.InputMethodSubtype; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; public class InputMethodAndSubtypeUtil { @@ -46,6 +48,7 @@ public class InputMethodAndSubtypeUtil { private static final char INPUT_METHOD_SEPARATER = ':'; private static final char INPUT_METHOD_SUBTYPE_SEPARATER = ';'; private static final int NOT_A_SUBTYPE_ID = -1; + private static final Locale ENGLISH_LOCALE = new Locale("en"); private static final TextUtils.SimpleStringSplitter sStringInputMethodSplitter = new TextUtils.SimpleStringSplitter(INPUT_METHOD_SEPARATER); @@ -183,7 +186,7 @@ public class InputMethodAndSubtypeUtil { getEnabledInputMethodsAndSubtypeList(resolver); HashSet<String> disabledSystemIMEs = getDisabledSystemIMEs(resolver); - final boolean onlyOneIME = inputMethodInfos.size() == 1; + final int imiCount = inputMethodInfos.size(); boolean needsToResetSelectedSubtype = false; for (InputMethodInfo imi : inputMethodInfos) { final String imiId = imi.getId(); @@ -193,11 +196,11 @@ public class InputMethodAndSubtypeUtil { // pref is instance of CheckBoxPreference in the Configure input method screen. final boolean isImeChecked = (pref instanceof CheckBoxPreference) ? ((CheckBoxPreference) pref).isChecked() - : enabledIMEAndSubtypesMap.containsKey(imiId); + : enabledIMEAndSubtypesMap.containsKey(imiId); final boolean isCurrentInputMethod = imiId.equals(currentInputMethodId); - final boolean auxIme = isAuxiliaryIme(imi); final boolean systemIme = isSystemIme(imi); - if (((onlyOneIME || (systemIme && !auxIme)) && !hasHardKeyboard) || isImeChecked) { + if ((!hasHardKeyboard && isAlwaysCheckedIme(imi, context.getActivity(), imiCount)) + || isImeChecked) { if (!enabledIMEAndSubtypesMap.containsKey(imiId)) { // imiId has just been enabled enabledIMEAndSubtypesMap.put(imiId, new HashSet<String>()); @@ -373,4 +376,47 @@ public class InputMethodAndSubtypeUtil { public static boolean isAuxiliaryIme(InputMethodInfo imi) { return imi.isAuxiliaryIme(); } + + public static boolean isAlwaysCheckedIme(InputMethodInfo imi, Context context, int imiCount) { + if (imiCount <= 1) { + return true; + } + if (!isSystemIme(imi)) { + return false; + } + if (isAuxiliaryIme(imi)) { + return false; + } + if (isValidDefaultIme(imi, context)) { + return true; + } + return containsSubtypeOf(imi, ENGLISH_LOCALE.getLanguage()); + } + + private static boolean isValidDefaultIme(InputMethodInfo imi, Context context) { + if (imi.getIsDefaultResourceId() != 0) { + try { + Resources res = context.createPackageContext( + imi.getPackageName(), 0).getResources(); + if (res.getBoolean(imi.getIsDefaultResourceId()) + && containsSubtypeOf(imi, context.getResources().getConfiguration(). + locale.getLanguage())) { + return true; + } + } catch (PackageManager.NameNotFoundException ex) { + } catch (Resources.NotFoundException ex) { + } + } + return false; + } + + private static boolean containsSubtypeOf(InputMethodInfo imi, String language) { + final int N = imi.getSubtypeCount(); + for (int i = 0; i < N; ++i) { + if (imi.getSubtypeAt(i).getLocale().startsWith(language)) { + return true; + } + } + return false; + } } diff --git a/src/com/android/settings/inputmethod/InputMethodPreference.java b/src/com/android/settings/inputmethod/InputMethodPreference.java index 4ecdb8e..90eef85 100644 --- a/src/com/android/settings/inputmethod/InputMethodPreference.java +++ b/src/com/android/settings/inputmethod/InputMethodPreference.java @@ -51,7 +51,7 @@ public class InputMethodPreference extends CheckBoxPreference private final InputMethodInfo mImi; private final InputMethodManager mImm; private final Intent mSettingsIntent; - private final boolean mIsSystemIme; + private final boolean mAlwaysChecked; private AlertDialog mDialog = null; private ImageView mInputMethodSettingsButton; @@ -68,7 +68,7 @@ public class InputMethodPreference extends CheckBoxPreference if (isChecked()) { setChecked(false); } else { - if (mIsSystemIme) { + if (mAlwaysChecked) { setChecked(true); } else { showSecurityWarnDialog(mImi, InputMethodPreference.this); @@ -87,9 +87,9 @@ public class InputMethodPreference extends CheckBoxPreference mImm = imm; mImi = imi; updateSummary(); - mIsSystemIme = InputMethodAndSubtypeUtil.isSystemIme(imi); - final boolean isAuxIme = InputMethodAndSubtypeUtil.isAuxiliaryIme(imi); - if (imiCount <= 1 || (mIsSystemIme && !isAuxIme)) { + mAlwaysChecked = InputMethodAndSubtypeUtil.isAlwaysCheckedIme( + imi, fragment.getActivity(), imiCount); + if (mAlwaysChecked) { setEnabled(false); } } |