Add current system language into suggestion list

Bug: 228905883
Test: Add system language and change app language

Change-Id: I7b1f78bb13902dc50f3e8ce8e1c62590ac623b9c
This commit is contained in:
Calvin Pan
2022-04-12 05:47:24 +00:00
parent 11c6bd077e
commit 729a22a2cc
2 changed files with 35 additions and 1 deletions

View File

@@ -128,6 +128,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());
@@ -167,9 +173,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));
@@ -189,7 +206,6 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
}
}
}
Log.d(TAG, "mLocaleList after app-supported filter: " + filteredList.size());
}
return filteredList;

View File

@@ -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.