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

Commit 02255a7b authored by c_yunong's avatar c_yunong Committed by Linux Build Service Account
Browse files

LocalePicker: Support to the customize language list

Support to customize which language to list in the LocalePicker.
Support to show country/locale name in LocalePicker if it
is enabled by customized overlay.

Change-Id: I483786e15fb82e84bddf88a3f4196b865bcc3f56
CRs-Fixed: 1037633
parent 749fe29c
Loading
Loading
Loading
Loading
+32 −4
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.Bundle;
import android.os.LocaleList;
import android.os.RemoteException;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -42,6 +43,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";
@@ -97,13 +99,39 @@ public class LocalePicker extends ListFragment {
        return pseudoLocales;
    }

    /*
    * Get the customize locale codes and get the language list
    */
    private 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 = getSystemAssetLocales();
        List<String> localeList = new ArrayList<String>(locales.length);
        String[] locales = null;
        ArrayList<String> localeList = new ArrayList<String>();
        if (resources.getString(R.string.locale_codes) != null){
            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.
            localeList = getLocaleArray(locales, resources);
        } else {
            locales = getSystemAssetLocales();
            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) {
+36 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2016, The Linux Foundation. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.
    * Neither the name of The Linux Foundation nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->

<resources>

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

</resources>
+2 −0
Original line number Diff line number Diff line
@@ -2413,6 +2413,8 @@
  <java-symbol type="bool" name="config_cameraDoubleTapPowerGestureEnabled" />

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

  <java-symbol type="string" name="config_iccHotswapPromptForRestartDialogComponent" />