Loading core/java/android/view/textservice/SpellCheckerSubtype.java +15 −11 Original line number Diff line number Diff line Loading @@ -16,9 +16,6 @@ package android.view.textservice; import com.android.internal.inputmethod.InputMethodUtils; import android.annotation.Nullable; import android.content.Context; import android.content.pm.ApplicationInfo; import android.os.Parcel; Loading Loading @@ -150,15 +147,22 @@ public final class SpellCheckerSubtype implements Parcelable { } /** * @return The normalized {@link Locale} object of the subtype. The returned locale may or may * not equal to "locale" string parameter passed to the constructor. * * <p>TODO: Consider to make this a public API.</p> * @hide */ @Nullable public Locale getLocaleObject() { return InputMethodUtils.constructLocaleFromString(mSubtypeLocale); public static Locale constructLocaleFromString(String localeStr) { if (TextUtils.isEmpty(localeStr)) return null; String[] localeParams = localeStr.split("_", 3); // The length of localeStr is guaranteed to always return a 1 <= value <= 3 // because localeStr is not empty. if (localeParams.length == 1) { return new Locale(localeParams[0]); } else if (localeParams.length == 2) { return new Locale(localeParams[0], localeParams[1]); } else if (localeParams.length == 3) { return new Locale(localeParams[0], localeParams[1], localeParams[2]); } return null; } /** Loading @@ -173,7 +177,7 @@ public final class SpellCheckerSubtype implements Parcelable { */ public CharSequence getDisplayName( Context context, String packageName, ApplicationInfo appInfo) { final Locale locale = getLocaleObject(); final Locale locale = constructLocaleFromString(mSubtypeLocale); final String localeStr = locale != null ? locale.getDisplayName() : mSubtypeLocale; if (mSubtypeNameResId == 0) { return localeStr; Loading core/java/android/widget/TextView.java +1 −1 Original line number Diff line number Diff line Loading @@ -8785,7 +8785,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener final SpellCheckerSubtype subtype = textServicesManager.getCurrentSpellCheckerSubtype(true); final Locale locale; if (subtype != null) { locale = subtype.getLocaleObject(); locale = SpellCheckerSubtype.constructLocaleFromString(subtype.getLocale()); } else { locale = null; } Loading core/tests/coretests/src/android/view/textservice/SpellCheckerSubtypeTest.java +0 −29 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.test.InstrumentationTestCase; import android.test.suitebuilder.annotation.SmallTest; import java.util.Arrays; import java.util.Locale; import static android.test.MoreAsserts.assertNotEqual; Loading Loading @@ -80,34 +79,6 @@ public class SpellCheckerSubtypeTest extends InstrumentationTestCase { clonedSubtype.hashCode()); } @SmallTest public void testGetLocaleObject() throws Exception { assertEquals(new Locale("en"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "en", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); assertEquals(new Locale("en", "US"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "en_US", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); assertEquals(new Locale("en", "US", "POSIX"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "en_US_POSIX", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); // Special rewrite rule for "tl" for versions of Android earlier than Lollipop that did not // support three letter language codes, and used "tl" (Tagalog) as the language string for // "fil" (Filipino). assertEquals(new Locale("fil"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "tl", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); assertEquals(new Locale("fil", "PH"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "tl_PH", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); assertEquals(new Locale("fil", "PH", "POSIX"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "tl_PH_POSIX", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); // So far rejecting invalid/unexpected locale strings is out of the scope. assertEquals(new Locale("a"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "a", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); assertEquals(new Locale("a b c"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "a b c", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); assertEquals(new Locale("en-US"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "en-US", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); } @SmallTest public void testEquality() throws Exception { assertEquals( Loading Loading
core/java/android/view/textservice/SpellCheckerSubtype.java +15 −11 Original line number Diff line number Diff line Loading @@ -16,9 +16,6 @@ package android.view.textservice; import com.android.internal.inputmethod.InputMethodUtils; import android.annotation.Nullable; import android.content.Context; import android.content.pm.ApplicationInfo; import android.os.Parcel; Loading Loading @@ -150,15 +147,22 @@ public final class SpellCheckerSubtype implements Parcelable { } /** * @return The normalized {@link Locale} object of the subtype. The returned locale may or may * not equal to "locale" string parameter passed to the constructor. * * <p>TODO: Consider to make this a public API.</p> * @hide */ @Nullable public Locale getLocaleObject() { return InputMethodUtils.constructLocaleFromString(mSubtypeLocale); public static Locale constructLocaleFromString(String localeStr) { if (TextUtils.isEmpty(localeStr)) return null; String[] localeParams = localeStr.split("_", 3); // The length of localeStr is guaranteed to always return a 1 <= value <= 3 // because localeStr is not empty. if (localeParams.length == 1) { return new Locale(localeParams[0]); } else if (localeParams.length == 2) { return new Locale(localeParams[0], localeParams[1]); } else if (localeParams.length == 3) { return new Locale(localeParams[0], localeParams[1], localeParams[2]); } return null; } /** Loading @@ -173,7 +177,7 @@ public final class SpellCheckerSubtype implements Parcelable { */ public CharSequence getDisplayName( Context context, String packageName, ApplicationInfo appInfo) { final Locale locale = getLocaleObject(); final Locale locale = constructLocaleFromString(mSubtypeLocale); final String localeStr = locale != null ? locale.getDisplayName() : mSubtypeLocale; if (mSubtypeNameResId == 0) { return localeStr; Loading
core/java/android/widget/TextView.java +1 −1 Original line number Diff line number Diff line Loading @@ -8785,7 +8785,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener final SpellCheckerSubtype subtype = textServicesManager.getCurrentSpellCheckerSubtype(true); final Locale locale; if (subtype != null) { locale = subtype.getLocaleObject(); locale = SpellCheckerSubtype.constructLocaleFromString(subtype.getLocale()); } else { locale = null; } Loading
core/tests/coretests/src/android/view/textservice/SpellCheckerSubtypeTest.java +0 −29 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.test.InstrumentationTestCase; import android.test.suitebuilder.annotation.SmallTest; import java.util.Arrays; import java.util.Locale; import static android.test.MoreAsserts.assertNotEqual; Loading Loading @@ -80,34 +79,6 @@ public class SpellCheckerSubtypeTest extends InstrumentationTestCase { clonedSubtype.hashCode()); } @SmallTest public void testGetLocaleObject() throws Exception { assertEquals(new Locale("en"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "en", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); assertEquals(new Locale("en", "US"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "en_US", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); assertEquals(new Locale("en", "US", "POSIX"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "en_US_POSIX", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); // Special rewrite rule for "tl" for versions of Android earlier than Lollipop that did not // support three letter language codes, and used "tl" (Tagalog) as the language string for // "fil" (Filipino). assertEquals(new Locale("fil"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "tl", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); assertEquals(new Locale("fil", "PH"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "tl_PH", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); assertEquals(new Locale("fil", "PH", "POSIX"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "tl_PH_POSIX", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); // So far rejecting invalid/unexpected locale strings is out of the scope. assertEquals(new Locale("a"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "a", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); assertEquals(new Locale("a b c"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "a b c", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); assertEquals(new Locale("en-US"), new SpellCheckerSubtype( SUBTYPE_NAME_RES_ID_A, "en-US", SUBTYPE_EXTRA_VALUE_A).getLocaleObject()); } @SmallTest public void testEquality() throws Exception { assertEquals( Loading