From 025402c5e96ef346c39bb6d97ddeab7ca955e01d Mon Sep 17 00:00:00 2001 From: Igor Viarheichyk Date: Fri, 6 Oct 2017 12:46:49 -0700 Subject: Simple numbering system selector for LocalePicker. This change introduces minimal changes needed to support selection of locales with BCP 47 numbering system specification. Two level selection (Language/Region) schema remains, locales with numbering systems appear in the region selection list and are displayed as "region (numbering system)". Bug: 18340949 Bug: 63754513 Test: manual, experimental UI for review. Change-Id: I42691f3714c5e5c51fd8d96c034cc3a9f6be93dc --- core/java/android/os/LocaleList.java | 6 +++- .../com/android/internal/app/LocaleHelper.java | 11 +++++++- .../com/android/internal/app/LocalePicker.java | 15 +++------- .../java/com/android/internal/app/LocaleStore.java | 32 ++++++++++++---------- core/res/res/values/locale_config.xml | 3 ++ 5 files changed, 40 insertions(+), 27 deletions(-) diff --git a/core/java/android/os/LocaleList.java b/core/java/android/os/LocaleList.java index 2dc3bebb2d10..ca9cbec99cde 100644 --- a/core/java/android/os/LocaleList.java +++ b/core/java/android/os/LocaleList.java @@ -295,7 +295,11 @@ public final class LocaleList implements Parcelable { return STRING_EN_XA.equals(locale) || STRING_AR_XB.equals(locale); } - private static boolean isPseudoLocale(Locale locale) { + /** + * Returns true if locale is a pseudo-locale, false otherwise. + * {@hide} + */ + public static boolean isPseudoLocale(Locale locale) { return LOCALE_EN_XA.equals(locale) || LOCALE_AR_XB.equals(locale); } diff --git a/core/java/com/android/internal/app/LocaleHelper.java b/core/java/com/android/internal/app/LocaleHelper.java index 386aa84bfdbe..0a230a90a735 100644 --- a/core/java/com/android/internal/app/LocaleHelper.java +++ b/core/java/com/android/internal/app/LocaleHelper.java @@ -136,7 +136,16 @@ public class LocaleHelper { * @return the localized country name. */ public static String getDisplayCountry(Locale locale, Locale displayLocale) { - return ULocale.getDisplayCountry(locale.toLanguageTag(), ULocale.forLocale(displayLocale)); + final String languageTag = locale.toLanguageTag(); + final ULocale uDisplayLocale = ULocale.forLocale(displayLocale); + final String country = ULocale.getDisplayCountry(languageTag, uDisplayLocale); + final String numberingSystem = locale.getUnicodeLocaleType("nu"); + if (numberingSystem != null) { + return String.format("%s (%s)", country, + ULocale.getDisplayKeywordValue(languageTag, "numbers", uDisplayLocale)); + } else { + return country; + } } /** diff --git a/core/java/com/android/internal/app/LocalePicker.java b/core/java/com/android/internal/app/LocalePicker.java index 9936ed5c6491..c8c2fcf60d1f 100644 --- a/core/java/com/android/internal/app/LocalePicker.java +++ b/core/java/com/android/internal/app/LocalePicker.java @@ -93,10 +93,6 @@ public class LocalePicker extends ListFragment { return context.getResources().getStringArray(R.array.supported_locales); } - public static String[] getPseudoLocales() { - return pseudoLocales; - } - public static List getAllAssetLocales(Context context, boolean isInDeveloperMode) { final Resources resources = context.getResources(); @@ -104,13 +100,6 @@ public class LocalePicker extends ListFragment { List localeList = new ArrayList(locales.length); Collections.addAll(localeList, locales); - // Don't show the pseudolocales unless we're in developer mode. http://b/17190407. - if (!isInDeveloperMode) { - for (String locale : pseudoLocales) { - localeList.remove(locale); - } - } - Collections.sort(localeList); final String[] specialLocaleCodes = resources.getStringArray(R.array.special_locale_codes); final String[] specialLocaleNames = resources.getStringArray(R.array.special_locale_names); @@ -122,6 +111,10 @@ public class LocalePicker extends ListFragment { || l.getLanguage().isEmpty() || l.getCountry().isEmpty()) { continue; } + // Don't show the pseudolocales unless we're in developer mode. http://b/17190407. + if (!isInDeveloperMode && LocaleList.isPseudoLocale(l)) { + continue; + } if (localeInfos.isEmpty()) { if (DEBUG) { diff --git a/core/java/com/android/internal/app/LocaleStore.java b/core/java/com/android/internal/app/LocaleStore.java index e3fce5197dca..2b0b5eec6c56 100644 --- a/core/java/com/android/internal/app/LocaleStore.java +++ b/core/java/com/android/internal/app/LocaleStore.java @@ -17,6 +17,7 @@ package com.android.internal.app; import android.content.Context; +import android.os.LocaleList; import android.provider.Settings; import android.telephony.TelephonyManager; @@ -68,7 +69,9 @@ public class LocaleStore { return null; } return new Locale.Builder() - .setLocale(locale).setRegion("") + .setLocale(locale) + .setRegion("") + .setExtension(Locale.UNICODE_LOCALE_EXTENSION, "") .build(); } @@ -253,11 +256,25 @@ public class LocaleStore { Set simCountries = getSimCountries(context); + final boolean isInDeveloperMode = Settings.Global.getInt(context.getContentResolver(), + Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0; for (String localeId : LocalePicker.getSupportedLocales(context)) { if (localeId.isEmpty()) { throw new IllformedLocaleException("Bad locale entry in locale_config.xml"); } LocaleInfo li = new LocaleInfo(localeId); + + if (LocaleList.isPseudoLocale(li.getLocale())) { + if (isInDeveloperMode) { + li.setTranslated(true); + li.mIsPseudo = true; + li.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_SIM; + } else { + // Do not display pseudolocales unless in development mode. + continue; + } + } + if (simCountries.contains(li.getLocale().getCountry())) { li.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_SIM; } @@ -271,19 +288,6 @@ public class LocaleStore { } } - boolean isInDeveloperMode = Settings.Global.getInt(context.getContentResolver(), - Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0; - for (String localeId : LocalePicker.getPseudoLocales()) { - LocaleInfo li = getLocaleInfo(Locale.forLanguageTag(localeId)); - if (isInDeveloperMode) { - li.setTranslated(true); - li.mIsPseudo = true; - li.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_SIM; - } else { - sLocaleCache.remove(li.getId()); - } - } - // TODO: See if we can reuse what LocaleList.matchScore does final HashSet localizedLocales = new HashSet<>(); for (String localeId : LocalePicker.getSystemAssetLocales()) { diff --git a/core/res/res/values/locale_config.xml b/core/res/res/values/locale_config.xml index 04ea0771f8e9..2c4058acc972 100644 --- a/core/res/res/values/locale_config.xml +++ b/core/res/res/values/locale_config.xml @@ -27,6 +27,7 @@ ar-DJ ar-DZ ar-EG + ar-EG-u-nu-latn ar-EH ar-ER ar-IL @@ -48,6 +49,7 @@ ar-SY ar-TD ar-TN + ar-TN-u-nu-arab ar-XB ar-YE as-IN @@ -366,6 +368,7 @@ ms-SG mt-MT my-MM + my-MM-u-nu-latn mzn-IR naq-NA nb-NO -- cgit v1.2.3-59-g8ed1b