am a22e2ab6: Merge "Minimize the number of default enabled IMEs part 2" into lmp-dev
* commit 'a22e2ab64c1629e8d8a60ce5e2ccc034714f1365': Minimize the number of default enabled IMEs part 2
This commit is contained in:
@@ -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";
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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) {
|
||||
@@ -179,13 +194,14 @@ 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)) {
|
||||
final InputMethodSubtype subtype = imi.getSubtypeAt(i);
|
||||
if (!subtype.getLocale().startsWith(language)) {
|
||||
continue;
|
||||
}
|
||||
if(!TextUtils.isEmpty(mode) && !imi.getSubtypeAt(i).getMode().equalsIgnoreCase(mode)) {
|
||||
continue;
|
||||
if (mode == SUBTYPE_MODE_ANY || TextUtils.isEmpty(mode) ||
|
||||
mode.equalsIgnoreCase(subtype.getMode())) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
@@ -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");
|
||||
@@ -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",
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user