Merge "Convert subtypes whose locale is "tl" to "fil"." into mnc-dev

This commit is contained in:
Yohei Yukawa
2015-06-03 17:40:05 +00:00
committed by Android (Google) Code Review
3 changed files with 28 additions and 2 deletions

View File

@@ -16,6 +16,7 @@
package android.view.inputmethod;
import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Parcel;
@@ -322,6 +323,19 @@ public final class InputMethodSubtype implements Parcelable {
return mSubtypeLocale;
}
/**
* @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() {
// TODO: Move the following method from InputMethodUtils to InputMethodSubtype.
return InputMethodUtils.constructLocaleFromString(mSubtypeLocale);
}
/**
* @return The mode of the subtype.
*/
@@ -381,7 +395,7 @@ public final class InputMethodSubtype implements Parcelable {
*/
public CharSequence getDisplayName(
Context context, String packageName, ApplicationInfo appInfo) {
final Locale locale = InputMethodUtils.constructLocaleFromString(mSubtypeLocale);
final Locale locale = getLocaleObject();
final String localeStr = locale != null ? locale.getDisplayName() : mSubtypeLocale;
if (mSubtypeNameResId == 0) {
return localeStr;

View File

@@ -379,6 +379,14 @@ public class InputMethodUtils {
// The length of localeStr is guaranteed to always return a 1 <= value <= 3
// because localeStr is not empty.
if (localeParams.length == 1) {
if (localeParams.length >= 1 && "tl".equals(localeParams[0])) {
// Convert a locale whose language is "tl" to one whose language is "fil".
// For example, "tl_PH" will get converted to "fil_PH".
// Versions of Android earlier than Lollipop did not support three letter language
// codes, and used "tl" (Tagalog) as the language string for "fil" (Filipino).
// On Lollipop and above, the current three letter version must be used.
localeParams[0] = "fil";
}
return new Locale(localeParams[0]);
} else if (localeParams.length == 2) {
return new Locale(localeParams[0], localeParams[1]);
@@ -397,7 +405,7 @@ public class InputMethodUtils {
for (int i = 0; i < N; ++i) {
final InputMethodSubtype subtype = imi.getSubtypeAt(i);
if (checkCountry) {
final Locale subtypeLocale = constructLocaleFromString(subtype.getLocale());
final Locale subtypeLocale = subtype.getLocaleObject();
if (subtypeLocale == null ||
!TextUtils.equals(subtypeLocale.getLanguage(), locale.getLanguage()) ||
!TextUtils.equals(subtypeLocale.getCountry(), locale.getCountry())) {

View File

@@ -56,6 +56,10 @@ public class InputMethodSubtypeTest extends InstrumentationTestCase {
verifyLocale("zz");
verifyLocale("iw");
verifyLocale("he");
verifyLocale("tl");
verifyLocale("tl_PH");
verifyLocale("fil");
verifyLocale("fil_PH");
}
@SmallTest