Skip to content
Snippets Groups Projects
Commit 995ce455 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Use "languageTag" in RichInputMethodSubtype.

With this CL, RichInputMethodSubtype#getLocale() starts returning
a Locale object that is initialized with "languageTag" when it is
specified.  No behavior change is intended when "languageTag" attribute
is not available or specified.

Bug: 22858221
Change-Id: I23f2e479b8e284ce589c6950b071ba84c5dd8ce1
parent f6997344
No related branches found
No related tags found
No related merge requests found
......@@ -17,14 +17,17 @@
package com.android.inputmethod.compat;
import android.os.Build;
import android.text.TextUtils;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.RichInputMethodSubtype;
import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.common.LocaleUtils;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Locale;
import javax.annotation.Nonnull;
......@@ -78,6 +81,21 @@ public final class InputMethodSubtypeCompatUtils {
|| subtype.containsExtraValueKey(Constants.Subtype.ExtraValue.ASCII_CAPABLE);
}
// Note that InputMethodSubtype.getLanguageTag() is expected to be available in Android N+.
private static final Method GET_LANGUAGE_TAG =
CompatUtils.getMethod(InputMethodSubtype.class, "getLanguageTag");
public static Locale getLocaleObject(final InputMethodSubtype subtype) {
// Locale.forLanguageTag() is available only in Android L and later.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
final String languageTag = (String) CompatUtils.invoke(subtype, null, GET_LANGUAGE_TAG);
if (!TextUtils.isEmpty(languageTag)) {
return Locale.forLanguageTag(languageTag);
}
}
return LocaleUtils.constructLocaleFromString(subtype.getLocale());
}
@UsedForTesting
public static boolean isAsciiCapableWithAPI(final InputMethodSubtype subtype) {
return (Boolean)CompatUtils.invoke(subtype, false, METHOD_isAsciiCapable);
......
......@@ -47,7 +47,7 @@ public class RichInputMethodSubtype {
public RichInputMethodSubtype(@Nonnull final InputMethodSubtype subtype) {
mSubtype = subtype;
mLocale = LocaleUtils.constructLocaleFromString(mSubtype.getLocale());
mLocale = InputMethodSubtypeCompatUtils.getLocaleObject(mSubtype);
}
// Extra values are determined by the primary subtype. This is probably right, but
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment