From 5e5c60a43a93a0b5f16680042f2fecf6e0ecd0d7 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Sat, 13 Sep 2014 01:13:38 +0900 Subject: Minimize the number of default enabled IMEs part 1 Basically this CL does following clean-ups as groundwork. - Embed isDefaultEnabledIme into its only one caller - Fix a typo in isSystemAuxilialyImeThatHashAutomaticSubtype() - Use exit-early style in getMostApplicableDefaultIME() No behavior change is intended by this CL. BUG: 17347871 Change-Id: I831502db502f4073c9c2f50ce7705a4e45e2e1e3 --- .../internal/inputmethod/InputMethodUtils.java | 47 ++++++++++------------ 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/core/java/com/android/internal/inputmethod/InputMethodUtils.java b/core/java/com/android/internal/inputmethod/InputMethodUtils.java index 6eb00995b1d8..d47d031ae4e0 100644 --- a/core/java/com/android/internal/inputmethod/InputMethodUtils.java +++ b/core/java/com/android/internal/inputmethod/InputMethodUtils.java @@ -108,7 +108,7 @@ public class InputMethodUtils { return containsSubtypeOf(imi, ENGLISH_LOCALE.getLanguage(), SUBTYPE_MODE_KEYBOARD); } - private static boolean isSystemAuxilialyImeThatHashAutomaticSubtype(InputMethodInfo imi) { + private static boolean isSystemAuxilialyImeThatHasAutomaticSubtype(InputMethodInfo imi) { if (!isSystemIme(imi)) { return false; } @@ -131,7 +131,8 @@ public class InputMethodUtils { boolean auxilialyImeAdded = false; for (int i = 0; i < imis.size(); ++i) { final InputMethodInfo imi = imis.get(i); - if (isDefaultEnabledIme(isSystemReady, imi, context)) { + if (isValidSystemDefaultIme(isSystemReady, imi, context) + || isSystemImeThatHasEnglishKeyboardSubtype(imi)) { retval.add(imi); if (imi.isAuxiliaryIme()) { auxilialyImeAdded = true; @@ -143,7 +144,7 @@ public class InputMethodUtils { } for (int i = 0; i < imis.size(); ++i) { final InputMethodInfo imi = imis.get(i); - if (isSystemAuxilialyImeThatHashAutomaticSubtype(imi)) { + if (isSystemAuxilialyImeThatHasAutomaticSubtype(imi)) { retval.add(imi); } } @@ -175,12 +176,6 @@ public class InputMethodUtils { return false; } - public static boolean isDefaultEnabledIme( - boolean isSystemReady, InputMethodInfo imi, Context context) { - return isValidSystemDefaultIme(isSystemReady, imi, context) - || isSystemImeThatHasEnglishKeyboardSubtype(imi); - } - public static boolean containsSubtypeOf(InputMethodInfo imi, String language, String mode) { final int N = imi.getSubtypeCount(); for (int i = 0; i < N; ++i) { @@ -219,25 +214,25 @@ public class InputMethodUtils { public static InputMethodInfo getMostApplicableDefaultIME( List enabledImes) { - if (enabledImes != null && enabledImes.size() > 0) { - // We'd prefer to fall back on a system IME, since that is safer. - int i = enabledImes.size(); - int firstFoundSystemIme = -1; - while (i > 0) { - i--; - final InputMethodInfo imi = enabledImes.get(i); - if (InputMethodUtils.isSystemImeThatHasEnglishKeyboardSubtype(imi) - && !imi.isAuxiliaryIme()) { - return imi; - } - if (firstFoundSystemIme < 0 && InputMethodUtils.isSystemIme(imi) - && !imi.isAuxiliaryIme()) { - firstFoundSystemIme = i; - } + if (enabledImes == null || enabledImes.isEmpty()) { + return null; + } + // We'd prefer to fall back on a system IME, since that is safer. + int i = enabledImes.size(); + int firstFoundSystemIme = -1; + while (i > 0) { + i--; + final InputMethodInfo imi = enabledImes.get(i); + if (InputMethodUtils.isSystemImeThatHasEnglishKeyboardSubtype(imi) + && !imi.isAuxiliaryIme()) { + return imi; + } + if (firstFoundSystemIme < 0 && InputMethodUtils.isSystemIme(imi) + && !imi.isAuxiliaryIme()) { + firstFoundSystemIme = i; } - return enabledImes.get(Math.max(firstFoundSystemIme, 0)); } - return null; + return enabledImes.get(Math.max(firstFoundSystemIme, 0)); } public static boolean isValidSubtypeId(InputMethodInfo imi, int subtypeHashCode) { -- cgit v1.2.3-59-g8ed1b