summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2014-07-24 09:54:59 +0900
committerYohei Yukawa <yukawa@google.com>2014-07-26 03:21:03 +0900
commit71cf0a32d0d9a45653704a671154f26a8bc3132b (patch)
tree02a72b957add60dc7e196901d957634eb27a7473 /core
parent1a6896910898ae0bccaecc96aad4887cdc5fac1a (diff)
downloadframeworks_base-71cf0a32d0d9a45653704a671154f26a8bc3132b.zip
frameworks_base-71cf0a32d0d9a45653704a671154f26a8bc3132b.tar.gz
frameworks_base-71cf0a32d0d9a45653704a671154f26a8bc3132b.tar.bz2
Stop assuming language part in locale string is up to 2-letter
With this CL, InputMethodSubtypeSwitchingController stop assuming that language part in locale string is up to 2-letter. this CL is not so risky because InputMethodSubtypeSwitchingController have used language part for nothing but sorting subtypes to determine the initial rotation order of IME switching. BUG: 16502987 Change-Id: Ib159ece0b7aa04f8fd7abc96c9a6e0832a4b7cd2
Diffstat (limited to 'core')
-rw-r--r--core/java/com/android/internal/inputmethod/InputMethodSubtypeSwitchingController.java28
-rw-r--r--core/tests/inputmethodtests/src/android/os/InputMethodSubtypeSwitchingControllerTest.java29
2 files changed, 53 insertions, 4 deletions
diff --git a/core/java/com/android/internal/inputmethod/InputMethodSubtypeSwitchingController.java b/core/java/com/android/internal/inputmethod/InputMethodSubtypeSwitchingController.java
index fdd24a6..52485dd 100644
--- a/core/java/com/android/internal/inputmethod/InputMethodSubtypeSwitchingController.java
+++ b/core/java/com/android/internal/inputmethod/InputMethodSubtypeSwitchingController.java
@@ -54,8 +54,8 @@ public class InputMethodSubtypeSwitchingController {
public final CharSequence mSubtypeName;
public final InputMethodInfo mImi;
public final int mSubtypeId;
- private final boolean mIsSystemLocale;
- private final boolean mIsSystemLanguage;
+ public final boolean mIsSystemLocale;
+ public final boolean mIsSystemLanguage;
public ImeSubtypeListItem(CharSequence imeName, CharSequence subtypeName,
InputMethodInfo imi, int subtypeId, String subtypeLocale, String systemLocale) {
@@ -68,8 +68,28 @@ public class InputMethodSubtypeSwitchingController {
mIsSystemLanguage = false;
} else {
mIsSystemLocale = subtypeLocale.equals(systemLocale);
- mIsSystemLanguage = mIsSystemLocale
- || subtypeLocale.startsWith(systemLocale.substring(0, 2));
+ if (mIsSystemLocale) {
+ mIsSystemLanguage = true;
+ } else {
+ // TODO: Use Locale#getLanguage or Locale#toLanguageTag
+ final String systemLanguage = parseLanguageFromLocaleString(systemLocale);
+ final String subtypeLanguage = parseLanguageFromLocaleString(subtypeLocale);
+ mIsSystemLanguage = systemLanguage.length() >= 2 &&
+ systemLanguage.equals(subtypeLanguage);
+ }
+ }
+ }
+
+ /**
+ * Returns the language component of a given locale string.
+ * TODO: Use {@link Locale#getLanguage()} instead.
+ */
+ private static String parseLanguageFromLocaleString(final String locale) {
+ final int idx = locale.indexOf('_');
+ if (idx < 0) {
+ return locale;
+ } else {
+ return locale.substring(0, idx);
}
}
diff --git a/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeSwitchingControllerTest.java b/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeSwitchingControllerTest.java
index ca68e93..3a598f2 100644
--- a/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeSwitchingControllerTest.java
+++ b/core/tests/inputmethodtests/src/android/os/InputMethodSubtypeSwitchingControllerTest.java
@@ -295,4 +295,33 @@ public class InputMethodSubtypeSwitchingControllerTest extends InstrumentationTe
assertRotationOrder(anotherController, false /* onlyCurrentIme */,
switchingUnawarelatinIme_en_UK, switchUnawareJapaneseIme_ja_JP);
}
+
+ @SmallTest
+ public void testImeSubtypeListItem() throws Exception {
+ final List<ImeSubtypeListItem> items = new ArrayList<ImeSubtypeListItem>();
+ addDummyImeSubtypeListItems(items, "LatinIme", "LatinIme",
+ Arrays.asList("en_US", "fr", "en", "en_uk", "enn", "e", "EN_US"),
+ true /* supportsSwitchingToNextInputMethod*/);
+ final ImeSubtypeListItem item_en_US = items.get(0);
+ final ImeSubtypeListItem item_fr = items.get(1);
+ final ImeSubtypeListItem item_en = items.get(2);
+ final ImeSubtypeListItem item_enn = items.get(3);
+ final ImeSubtypeListItem item_e = items.get(4);
+ final ImeSubtypeListItem item_EN_US = items.get(5);
+
+ assertTrue(item_en_US.mIsSystemLocale);
+ assertFalse(item_fr.mIsSystemLocale);
+ assertFalse(item_en.mIsSystemLocale);
+ assertFalse(item_en.mIsSystemLocale);
+ assertFalse(item_enn.mIsSystemLocale);
+ assertFalse(item_e.mIsSystemLocale);
+ assertFalse(item_EN_US.mIsSystemLocale);
+
+ assertTrue(item_en_US.mIsSystemLanguage);
+ assertFalse(item_fr.mIsSystemLanguage);
+ assertTrue(item_en.mIsSystemLanguage);
+ assertFalse(item_enn.mIsSystemLocale);
+ assertFalse(item_e.mIsSystemLocale);
+ assertFalse(item_EN_US.mIsSystemLocale);
+ }
}