Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 025402c5 authored by Igor Viarheichyk's avatar Igor Viarheichyk
Browse files

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
parent 884a7e48
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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);
    }

+10 −1
Original line number Diff line number Diff line
@@ -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;
        }
    }

    /**
+4 −11
Original line number Diff line number Diff line
@@ -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<LocaleInfo> getAllAssetLocales(Context context, boolean isInDeveloperMode) {
        final Resources resources = context.getResources();

@@ -104,13 +100,6 @@ public class LocalePicker extends ListFragment {
        List<String> localeList = new ArrayList<String>(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) {
+18 −14
Original line number Diff line number Diff line
@@ -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<String> 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<String> localizedLocales = new HashSet<>();
        for (String localeId : LocalePicker.getSystemAssetLocales()) {
+3 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
        <item>ar-DJ</item> <!-- Arabic (Djibouti) -->
        <item>ar-DZ</item> <!-- Arabic (Algeria) -->
        <item>ar-EG</item> <!-- Arabic (Egypt) -->
        <item>ar-EG-u-nu-latn</item> <!-- Arabic (Egypt,Western Digits) -->
        <item>ar-EH</item> <!-- Arabic (Western Sahara) -->
        <item>ar-ER</item> <!-- Arabic (Eritrea) -->
        <item>ar-IL</item> <!-- Arabic (Israel) -->
@@ -48,6 +49,7 @@
        <item>ar-SY</item> <!-- Arabic (Syria) -->
        <item>ar-TD</item> <!-- Arabic (Chad) -->
        <item>ar-TN</item> <!-- Arabic (Tunisia) -->
        <item>ar-TN-u-nu-arab</item> <!-- Arabic (Tunisia,Arabic-Indic Digits) -->
        <item>ar-XB</item> <!-- Right-to-left pseudolocale -->
        <item>ar-YE</item> <!-- Arabic (Yemen) -->
        <item>as-IN</item> <!-- Assamese (India) -->
@@ -366,6 +368,7 @@
        <item>ms-SG</item> <!-- Malay (Singapore) -->
        <item>mt-MT</item> <!-- Maltese (Malta) -->
        <item>my-MM</item> <!-- Burmese (Myanmar (Burma)) -->
        <item>my-MM-u-nu-latn</item> <!-- Burmese (Myanmar (Burma), Western Digits) -->
        <item>mzn-IR</item> <!-- Mazanderani (Iran) -->
        <item>naq-NA</item> <!-- Nama (Namibia) -->
        <item>nb-NO</item> <!-- Norwegian Bokmål (Norway) -->