Loading services/core/java/com/android/server/inputmethod/InputMethodSubtypeSwitchingController.java +9 −18 Original line number Diff line number Diff line Loading @@ -69,27 +69,16 @@ final class InputMethodSubtypeSwitchingController { mIsSystemLanguage = true; } else { // TODO: Use Locale#getLanguage or Locale#toLanguageTag final String systemLanguage = parseLanguageFromLocaleString(systemLocale); final String subtypeLanguage = parseLanguageFromLocaleString(subtypeLocale); final String systemLanguage = LocaleUtils.getLanguageFromLocaleString( systemLocale); final String subtypeLanguage = LocaleUtils.getLanguageFromLocaleString( 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); } } private static int compareNullableCharSequences(@Nullable CharSequence c1, @Nullable CharSequence c2) { // For historical reasons, an empty text needs to put at the last. Loading Loading @@ -253,6 +242,7 @@ final class InputMethodSubtypeSwitchingController { /** * Returns the index of the specified input method and subtype in the given list. * * @param imi The {@link InputMethodInfo} to be searched. * @param subtype The {@link InputMethodSubtype} to be searched. null if the input method * does not have a subtype. Loading Loading @@ -327,6 +317,7 @@ final class InputMethodSubtypeSwitchingController { * {@link #mUsageHistoryOfSubtypeListItemIndex}. * <p>We call the index of {@link #mUsageHistoryOfSubtypeListItemIndex} as "Usage Rank" * so as not to be confused with the index in {@link #mImeSubtypeList}. * * @return -1 when the specified item doesn't belong to {@link #mImeSubtypeList} actually. */ private int getUsageRank(final InputMethodInfo imi, InputMethodSubtype subtype) { Loading services/core/java/com/android/server/inputmethod/LocaleUtils.java +1 −6 Original line number Diff line number Diff line Loading @@ -215,12 +215,7 @@ final class LocaleUtils { * TODO: Use {@link Locale#toLanguageTag()} and {@link Locale#forLanguageTag(String)} */ static String getLanguageFromLocaleString(String locale) { final int idx = locale.indexOf('_'); if (idx < 0) { return locale; } else { return locale.substring(0, idx); } return Locale.forLanguageTag(locale).getLanguage(); } static Locale getSystemLocaleFromContext(Context context) { Loading services/tests/servicestests/src/com/android/server/inputmethod/LocaleUtilsTest.java +8 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server.inputmethod; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import android.os.LocaleList; Loading Loading @@ -386,4 +388,10 @@ public class LocaleUtilsTest { assertEquals(availableLocales.get(3), dest.get(0)); } } @Test public void testGetLanguageFromLocaleString() { assertThat(LocaleUtils.getLanguageFromLocaleString("en")).isEqualTo("en"); assertThat(LocaleUtils.getLanguageFromLocaleString("en-US")).isEqualTo("en"); } } Loading
services/core/java/com/android/server/inputmethod/InputMethodSubtypeSwitchingController.java +9 −18 Original line number Diff line number Diff line Loading @@ -69,27 +69,16 @@ final class InputMethodSubtypeSwitchingController { mIsSystemLanguage = true; } else { // TODO: Use Locale#getLanguage or Locale#toLanguageTag final String systemLanguage = parseLanguageFromLocaleString(systemLocale); final String subtypeLanguage = parseLanguageFromLocaleString(subtypeLocale); final String systemLanguage = LocaleUtils.getLanguageFromLocaleString( systemLocale); final String subtypeLanguage = LocaleUtils.getLanguageFromLocaleString( 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); } } private static int compareNullableCharSequences(@Nullable CharSequence c1, @Nullable CharSequence c2) { // For historical reasons, an empty text needs to put at the last. Loading Loading @@ -253,6 +242,7 @@ final class InputMethodSubtypeSwitchingController { /** * Returns the index of the specified input method and subtype in the given list. * * @param imi The {@link InputMethodInfo} to be searched. * @param subtype The {@link InputMethodSubtype} to be searched. null if the input method * does not have a subtype. Loading Loading @@ -327,6 +317,7 @@ final class InputMethodSubtypeSwitchingController { * {@link #mUsageHistoryOfSubtypeListItemIndex}. * <p>We call the index of {@link #mUsageHistoryOfSubtypeListItemIndex} as "Usage Rank" * so as not to be confused with the index in {@link #mImeSubtypeList}. * * @return -1 when the specified item doesn't belong to {@link #mImeSubtypeList} actually. */ private int getUsageRank(final InputMethodInfo imi, InputMethodSubtype subtype) { Loading
services/core/java/com/android/server/inputmethod/LocaleUtils.java +1 −6 Original line number Diff line number Diff line Loading @@ -215,12 +215,7 @@ final class LocaleUtils { * TODO: Use {@link Locale#toLanguageTag()} and {@link Locale#forLanguageTag(String)} */ static String getLanguageFromLocaleString(String locale) { final int idx = locale.indexOf('_'); if (idx < 0) { return locale; } else { return locale.substring(0, idx); } return Locale.forLanguageTag(locale).getLanguage(); } static Locale getSystemLocaleFromContext(Context context) { Loading
services/tests/servicestests/src/com/android/server/inputmethod/LocaleUtilsTest.java +8 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server.inputmethod; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import android.os.LocaleList; Loading Loading @@ -386,4 +388,10 @@ public class LocaleUtilsTest { assertEquals(availableLocales.get(3), dest.get(0)); } } @Test public void testGetLanguageFromLocaleString() { assertThat(LocaleUtils.getLanguageFromLocaleString("en")).isEqualTo("en"); assertThat(LocaleUtils.getLanguageFromLocaleString("en-US")).isEqualTo("en"); } }