[automerge] Add current system language into suggestion list 2p: 729a22a2cc
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17700590 Bug: 228905883 Change-Id: I67a9ea739116526bf7a732a7c412b1af283a0c27
This commit is contained in:
@@ -129,6 +129,12 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
|
|||||||
boolean isForCountryMode = parent != null;
|
boolean isForCountryMode = parent != null;
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(appPackageName) && !isForCountryMode) {
|
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) {
|
if (appCurrentLocale != null) {
|
||||||
Log.d(TAG, "appCurrentLocale: " + appCurrentLocale.getLocale().toLanguageTag());
|
Log.d(TAG, "appCurrentLocale: " + appCurrentLocale.getLocale().toLanguageTag());
|
||||||
langTagsToIgnore.add(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_LOCAL_CONFIG
|
||||||
|| result.mLocaleStatus == LocaleStatus.GET_SUPPORTED_LANGUAGE_FROM_ASSET;
|
|| 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(
|
mLocaleList = filterTheLanguagesNotSupportedInApp(
|
||||||
shouldShowList, result.mAppSupportedLocales);
|
shouldShowList, result.mAppSupportedLocales);
|
||||||
|
|
||||||
|
Log.d(TAG, "mLocaleList after app-supported filter: " + mLocaleList.size());
|
||||||
|
|
||||||
// Add "system language"
|
// Add "system language"
|
||||||
if (!isForCountryMode && shouldShowList) {
|
if (!isForCountryMode && shouldShowList) {
|
||||||
mLocaleList.add(LocaleStore.getSystemDefaultLocaleInfo(appCurrentLocale == null));
|
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;
|
return filteredList;
|
||||||
|
|||||||
@@ -25,9 +25,11 @@ import android.telephony.TelephonyManager;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.IllformedLocaleException;
|
import java.util.IllformedLocaleException;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -277,6 +279,22 @@ public class LocaleStore {
|
|||||||
return null;
|
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
|
* The "system default" is special case for per-app picker. Intentionally keep the locale
|
||||||
* empty to let activity know "system default" been selected.
|
* empty to let activity know "system default" been selected.
|
||||||
|
|||||||
Reference in New Issue
Block a user