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

Commit 73797e49 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "LocalePicker: Support customize the language list"

parents 31d1bcfd 5ab77412
Loading
Loading
Loading
Loading
+40 −3
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.content.res.Resources;
import android.os.Bundle;
import android.os.RemoteException;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -41,6 +42,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.ArrayList;
import java.util.Arrays;

public class LocalePicker extends ListFragment {
    private static final String TAG = "LocalePicker";
@@ -83,12 +85,28 @@ public class LocalePicker extends ListFragment {
        }
    }

    public static ArrayList<String> getLocaleArray(String[] locales, Resources resources) {
        String localeCodes = resources.getString(R.string.locale_codes);
        String[] localeCodesArray = null;
        if (localeCodes != null && !TextUtils.isEmpty(localeCodes.trim())) {
            localeCodes = localeCodes.replace('_', '-');
            // ICU use "fil" instead of "tl"
            localeCodes = localeCodes.replaceAll("tl-", "fil-");
            localeCodesArray = localeCodes.split(",");
        }
        ArrayList<String> localeList = new ArrayList<String>(
            Arrays.asList((localeCodesArray == null || localeCodesArray.length == 0) ? locales
                : localeCodesArray));
        return localeList;
    }

    public static List<LocaleInfo> getAllAssetLocales(Context context, boolean isInDeveloperMode) {
        final Resources resources = context.getResources();

        final String[] locales = Resources.getSystem().getAssets().getLocales();
        List<String> localeList = new ArrayList<String>(locales.length);
        Collections.addAll(localeList, locales);
        String[] locales = Resources.getSystem().getAssets().getLocales();
        // Check the locale_codes if the locales list is customized in data package overlay.
        // If locale_codes is customized, use the customized list instead of built-in locales.
        ArrayList<String> localeList = getLocaleArray(locales, resources);

        // Don't show the pseudolocales unless we're in developer mode. http://b/17190407.
        if (!isInDeveloperMode) {
@@ -142,6 +160,25 @@ public class LocalePicker extends ListFragment {
                }
            }
        }
        // If customized to true, always show the country name
        boolean shallShowCountry
                = resources.getBoolean(R.bool.config_display_country_for_locale_codes);
        if (shallShowCountry) {
            for (LocaleInfo locale : localeInfos) {
                Locale l = locale.locale;
                String languageName = toTitleCase(l.getDisplayLanguage(l));
                String displayName
                        = toTitleCase(getDisplayName(l, specialLocaleCodes, specialLocaleNames));
                if (locale.label.equals(languageName)) {
                    if (displayName.equals(languageName)) {
                        // Fix some cases where getDisplayName() not works(e.g. ar-EG).
                        displayName = toTitleCase(String.format("%s (%s)", languageName,
                                l.getDisplayCountry(l)));
                    }
                    locale.label = displayName;
                }
            }
        }

        Collections.sort(localeInfos);
        return localeInfos;
+6 −0
Original line number Diff line number Diff line
@@ -30,6 +30,12 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

<resources>

    <!-- Used in LocalePicker, default language must be contained -->
    <string name="locale_codes" translatable="false"></string>

    <!-- If configure to true, always show the country(locale) name in the language lable -->
    <bool name="config_display_country_for_locale_codes">false</bool>

    <!--Fully qualified class name of the plugin which would be
         dynamically loaded by TelephonyPluginDelegate-->
    <java-symbol type="string" name="telephony_plugin_class_name" />
+4 −0
Original line number Diff line number Diff line
@@ -2331,6 +2331,10 @@

  <java-symbol type="drawable" name="platlogo_m" />

  <!-- language/locale picker extention feature -->
  <java-symbol type="string" name="locale_codes" />
  <java-symbol type="bool"   name="config_display_country_for_locale_codes" />

  <!-- config softap extention feature -->
  <java-symbol type="bool" name="config_softap_extention" />