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

Commit f1930d24 authored by Presubmit Automerger Backend's avatar Presubmit Automerger Backend
Browse files

[automerge] Add current system language into suggestion list 2p: 729a22a2

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17700590

Bug: 228905883
Change-Id: I67a9ea739116526bf7a732a7c412b1af283a0c27
parents 201f94fe 729a22a2
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -129,6 +129,12 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
        boolean isForCountryMode = parent != null;

        if (!TextUtils.isEmpty(appPackageName) && !isForCountryMode) {
            // Filter current system locale to add them into suggestion
            LocaleList systemLangList = LocaleList.getDefault();
            for(int i = 0; i < systemLangList.size(); i++) {
                langTagsToIgnore.add(systemLangList.get(i).toLanguageTag());
            }

            if (appCurrentLocale != null) {
                Log.d(TAG, "appCurrentLocale: " + appCurrentLocale.getLocale().toLanguageTag());
                langTagsToIgnore.add(appCurrentLocale.getLocale().toLanguageTag());
@@ -168,9 +174,20 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
                    result.mLocaleStatus == LocaleStatus.GET_SUPPORTED_LANGUAGE_FROM_LOCAL_CONFIG
                    || result.mLocaleStatus == LocaleStatus.GET_SUPPORTED_LANGUAGE_FROM_ASSET;

            // Add current system language into suggestion list
            for(LocaleStore.LocaleInfo localeInfo: LocaleStore.getSystemCurrentLocaleInfo()) {
                if (appCurrentLocale == null ||
                        !localeInfo.getLocale().equals(appCurrentLocale.getLocale())) {
                    mLocaleList.add(localeInfo);
                }
            }

            // Filter the language not support in app
            mLocaleList = filterTheLanguagesNotSupportedInApp(
                    shouldShowList, result.mAppSupportedLocales);

            Log.d(TAG, "mLocaleList after app-supported filter:  " + mLocaleList.size());

            // Add "system language"
            if (!isForCountryMode && shouldShowList) {
                mLocaleList.add(LocaleStore.getSystemDefaultLocaleInfo(appCurrentLocale == null));
@@ -190,7 +207,6 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
                    }
                }
            }
            Log.d(TAG, "mLocaleList after app-supported filter:  " + filteredList.size());
        }

        return filteredList;
+18 −0
Original line number Diff line number Diff line
@@ -25,9 +25,11 @@ import android.telephony.TelephonyManager;
import android.util.Log;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IllformedLocaleException;
import java.util.List;
import java.util.Locale;
import java.util.Set;

@@ -277,6 +279,22 @@ public class LocaleStore {
        return null;
    }

    /**
     * Returns a list of system languages with LocaleInfo
     */
    public static List<LocaleInfo> getSystemCurrentLocaleInfo() {
        List<LocaleInfo> localeList = new ArrayList<>();

        LocaleList systemLangList = LocaleList.getDefault();
        for(int i = 0; i < systemLangList.size(); i++) {
            LocaleInfo systemLocaleInfo = new LocaleInfo(systemLangList.get(i));
            systemLocaleInfo.mSuggestionFlags |= LocaleInfo.SUGGESTION_TYPE_SIM;
            systemLocaleInfo.mIsTranslated = true;
            localeList.add(systemLocaleInfo);
        }
        return localeList;
    }

    /**
     * The "system default" is special case for per-app picker. Intentionally keep the locale
     * empty to let activity know "system default" been selected.