Loading core/java/com/android/internal/inputmethod/InputMethodUtils.java +23 −8 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import java.util.Locale; public class InputMethodUtils { public static final boolean DEBUG = false; public static final int NOT_A_SUBTYPE_ID = -1; public static final String SUBTYPE_MODE_ANY = null; public static final String SUBTYPE_MODE_KEYBOARD = "keyboard"; public static final String SUBTYPE_MODE_VOICE = "voice"; private static final String TAG = "InputMethodUtils"; Loading Loading @@ -127,10 +128,23 @@ public class InputMethodUtils { public static ArrayList<InputMethodInfo> getDefaultEnabledImes( Context context, boolean isSystemReady, ArrayList<InputMethodInfo> imis) { final ArrayList<InputMethodInfo> retval = new ArrayList<InputMethodInfo>(); if (!isSystemReady) { final ArrayList<InputMethodInfo> retval = new ArrayList<>(); for (int i = 0; i < imis.size(); ++i) { final InputMethodInfo imi = imis.get(i); if (isSystemImeThatHasEnglishKeyboardSubtype(imi)) { retval.add(imi); } } return retval; } final ArrayList<InputMethodInfo> retval = new ArrayList<>(); boolean auxilialyImeAdded = false; for (int i = 0; i < imis.size(); ++i) { final InputMethodInfo imi = imis.get(i); // TODO: We should check isAsciiCapable instead of relying on // isSystemImeThatHasEnglishKeyboardSubtype(). if (isValidSystemDefaultIme(isSystemReady, imi, context) || isSystemImeThatHasEnglishKeyboardSubtype(imi)) { retval.add(imi); Loading @@ -139,6 +153,7 @@ public class InputMethodUtils { } } } // If one or more auxiliary input methods are available, OK to stop populating the list. if (auxilialyImeAdded) { return retval; } Loading @@ -164,7 +179,7 @@ public class InputMethodUtils { try { if (imi.isDefault(context) && containsSubtypeOf( imi, context.getResources().getConfiguration().locale.getLanguage(), null /* mode */)) { SUBTYPE_MODE_ANY)) { return true; } } catch (Resources.NotFoundException ex) { Loading @@ -179,14 +194,15 @@ public class InputMethodUtils { public static boolean containsSubtypeOf(InputMethodInfo imi, String language, String mode) { final int N = imi.getSubtypeCount(); for (int i = 0; i < N; ++i) { if (!imi.getSubtypeAt(i).getLocale().startsWith(language)) { continue; } if(!TextUtils.isEmpty(mode) && !imi.getSubtypeAt(i).getMode().equalsIgnoreCase(mode)) { final InputMethodSubtype subtype = imi.getSubtypeAt(i); if (!subtype.getLocale().startsWith(language)) { continue; } if (mode == SUBTYPE_MODE_ANY || TextUtils.isEmpty(mode) || mode.equalsIgnoreCase(subtype.getMode())) { return true; } } return false; } Loading @@ -212,8 +228,7 @@ public class InputMethodUtils { return subtypes; } public static InputMethodInfo getMostApplicableDefaultIME( List<InputMethodInfo> enabledImes) { public static InputMethodInfo getMostApplicableDefaultIME(List<InputMethodInfo> enabledImes) { if (enabledImes == null || enabledImes.isEmpty()) { return null; } Loading core/tests/inputmethodtests/src/android/os/InputMethodTest.java +8 −19 Original line number Diff line number Diff line Loading @@ -53,10 +53,8 @@ public class InputMethodTest extends InstrumentationTestCase { public void testVoiceImes() throws Exception { // locale: en_US assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US, !IS_SYSTEM_READY, "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme"); "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_US, !IS_SYSTEM_READY, "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US, IS_SYSTEM_READY, "DummyDefaultAutoVoiceIme", "DummyDefaultEnKeyboardIme"); Loading @@ -66,10 +64,8 @@ public class InputMethodTest extends InstrumentationTestCase { // locale: en_GB assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB, !IS_SYSTEM_READY, "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme"); "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_GB, !IS_SYSTEM_READY, "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB, IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme"); Loading @@ -79,10 +75,8 @@ public class InputMethodTest extends InstrumentationTestCase { // locale: ja_JP assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP, !IS_SYSTEM_READY, "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme"); "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_JA_JP, !IS_SYSTEM_READY, "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP, IS_SYSTEM_READY, "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", Loading @@ -96,40 +90,35 @@ public class InputMethodTest extends InstrumentationTestCase { public void testKeyboardImes() throws Exception { // locale: en_US assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_US, !IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_US, IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); // locale: en_GB assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_GB, !IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_GB, IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); // locale: en_IN assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_IN, !IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_IN, IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); // locale: hi assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_HI, !IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_HI, IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); // locale: ja_JP assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_JA_JP, !IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_JA_JP, IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi", "com.android.apps.inputmethod.japanese"); Loading Loading
core/java/com/android/internal/inputmethod/InputMethodUtils.java +23 −8 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import java.util.Locale; public class InputMethodUtils { public static final boolean DEBUG = false; public static final int NOT_A_SUBTYPE_ID = -1; public static final String SUBTYPE_MODE_ANY = null; public static final String SUBTYPE_MODE_KEYBOARD = "keyboard"; public static final String SUBTYPE_MODE_VOICE = "voice"; private static final String TAG = "InputMethodUtils"; Loading Loading @@ -127,10 +128,23 @@ public class InputMethodUtils { public static ArrayList<InputMethodInfo> getDefaultEnabledImes( Context context, boolean isSystemReady, ArrayList<InputMethodInfo> imis) { final ArrayList<InputMethodInfo> retval = new ArrayList<InputMethodInfo>(); if (!isSystemReady) { final ArrayList<InputMethodInfo> retval = new ArrayList<>(); for (int i = 0; i < imis.size(); ++i) { final InputMethodInfo imi = imis.get(i); if (isSystemImeThatHasEnglishKeyboardSubtype(imi)) { retval.add(imi); } } return retval; } final ArrayList<InputMethodInfo> retval = new ArrayList<>(); boolean auxilialyImeAdded = false; for (int i = 0; i < imis.size(); ++i) { final InputMethodInfo imi = imis.get(i); // TODO: We should check isAsciiCapable instead of relying on // isSystemImeThatHasEnglishKeyboardSubtype(). if (isValidSystemDefaultIme(isSystemReady, imi, context) || isSystemImeThatHasEnglishKeyboardSubtype(imi)) { retval.add(imi); Loading @@ -139,6 +153,7 @@ public class InputMethodUtils { } } } // If one or more auxiliary input methods are available, OK to stop populating the list. if (auxilialyImeAdded) { return retval; } Loading @@ -164,7 +179,7 @@ public class InputMethodUtils { try { if (imi.isDefault(context) && containsSubtypeOf( imi, context.getResources().getConfiguration().locale.getLanguage(), null /* mode */)) { SUBTYPE_MODE_ANY)) { return true; } } catch (Resources.NotFoundException ex) { Loading @@ -179,14 +194,15 @@ public class InputMethodUtils { public static boolean containsSubtypeOf(InputMethodInfo imi, String language, String mode) { final int N = imi.getSubtypeCount(); for (int i = 0; i < N; ++i) { if (!imi.getSubtypeAt(i).getLocale().startsWith(language)) { continue; } if(!TextUtils.isEmpty(mode) && !imi.getSubtypeAt(i).getMode().equalsIgnoreCase(mode)) { final InputMethodSubtype subtype = imi.getSubtypeAt(i); if (!subtype.getLocale().startsWith(language)) { continue; } if (mode == SUBTYPE_MODE_ANY || TextUtils.isEmpty(mode) || mode.equalsIgnoreCase(subtype.getMode())) { return true; } } return false; } Loading @@ -212,8 +228,7 @@ public class InputMethodUtils { return subtypes; } public static InputMethodInfo getMostApplicableDefaultIME( List<InputMethodInfo> enabledImes) { public static InputMethodInfo getMostApplicableDefaultIME(List<InputMethodInfo> enabledImes) { if (enabledImes == null || enabledImes.isEmpty()) { return null; } Loading
core/tests/inputmethodtests/src/android/os/InputMethodTest.java +8 −19 Original line number Diff line number Diff line Loading @@ -53,10 +53,8 @@ public class InputMethodTest extends InstrumentationTestCase { public void testVoiceImes() throws Exception { // locale: en_US assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US, !IS_SYSTEM_READY, "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme"); "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_US, !IS_SYSTEM_READY, "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_US, IS_SYSTEM_READY, "DummyDefaultAutoVoiceIme", "DummyDefaultEnKeyboardIme"); Loading @@ -66,10 +64,8 @@ public class InputMethodTest extends InstrumentationTestCase { // locale: en_GB assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB, !IS_SYSTEM_READY, "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme"); "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_EN_GB, !IS_SYSTEM_READY, "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_EN_GB, IS_SYSTEM_READY, "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme"); Loading @@ -79,10 +75,8 @@ public class InputMethodTest extends InstrumentationTestCase { // locale: ja_JP assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP, !IS_SYSTEM_READY, "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", "DummyDefaultEnKeyboardIme", "DummyDefaultAutoVoiceIme"); "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithoutDefaultVoiceIme(), LOCALE_JA_JP, !IS_SYSTEM_READY, "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", "DummyDefaultEnKeyboardIme"); assertDefaultEnabledImes(getImesWithDefaultVoiceIme(), LOCALE_JA_JP, IS_SYSTEM_READY, "DummyNonDefaultAutoVoiceIme0", "DummyNonDefaultAutoVoiceIme1", Loading @@ -96,40 +90,35 @@ public class InputMethodTest extends InstrumentationTestCase { public void testKeyboardImes() throws Exception { // locale: en_US assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_US, !IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_US, IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); // locale: en_GB assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_GB, !IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_GB, IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); // locale: en_IN assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_IN, !IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_EN_IN, IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); // locale: hi assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_HI, !IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_HI, IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); // locale: ja_JP assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_JA_JP, !IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi"); assertDefaultEnabledImes(getSamplePreinstalledImes(), LOCALE_JA_JP, IS_SYSTEM_READY, "com.android.apps.inputmethod.voice", "com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.hindi", "com.android.apps.inputmethod.japanese"); Loading