Merge "Remove Numbering System preference if no corresponding locale." into udc-dev
This commit is contained in:
@@ -27,9 +27,19 @@ public class LocaleFeatureProviderImpl implements LocaleFeatureProvider {
|
||||
@Override
|
||||
public String getLocaleNames() {
|
||||
final LocaleList locales = LocalePicker.getLocales();
|
||||
Locale[] arrLocalesWithoutExtension = new Locale[locales.size()];
|
||||
for (int i = 0; i < locales.size(); i++) {
|
||||
arrLocalesWithoutExtension[i] = locales.get(i).stripExtensions();
|
||||
return getLocaleNames(locales);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns displayable string of inputted locales.
|
||||
*/
|
||||
public String getLocaleNames(LocaleList inputLocales) {
|
||||
if (inputLocales.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
Locale[] arrLocalesWithoutExtension = new Locale[inputLocales.size()];
|
||||
for (int i = 0; i < inputLocales.size(); i++) {
|
||||
arrLocalesWithoutExtension[i] = inputLocales.get(i).stripExtensions();
|
||||
}
|
||||
final Locale displayLocale = Locale.getDefault();
|
||||
return LocaleHelper.toSentenceCase(
|
||||
|
@@ -17,16 +17,26 @@
|
||||
package com.android.settings.regionalpreferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.LocaleList;
|
||||
|
||||
import com.android.internal.app.LocaleStore;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.localepicker.LocaleFeatureProviderImpl;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
/** A controller for the entry of Numbering System's page */
|
||||
public class NumberingSystemController extends BasePreferenceController {
|
||||
private static final String TAG = NumberingSystemController.class.getSimpleName();
|
||||
|
||||
private LocaleList mLocaleList;
|
||||
public NumberingSystemController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
// Initialize the supported languages to LocaleInfos
|
||||
LocaleStore.fillCache(context);
|
||||
mLocaleList = getNumberingSystemLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,11 +52,31 @@ public class NumberingSystemController extends BasePreferenceController {
|
||||
*/
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
return mLocaleList.isEmpty() ? CONDITIONALLY_UNAVAILABLE : AVAILABLE;
|
||||
}
|
||||
|
||||
private static LocaleList getNumberingSystemLocale() {
|
||||
LocaleList localeList = LocaleList.getDefault();
|
||||
Set<Locale> localesHasNumberingSystems = new HashSet<>();
|
||||
for (int i = 0; i < localeList.size(); i++) {
|
||||
Locale locale = localeList.get(i);
|
||||
LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(locale);
|
||||
if (localeInfo.hasNumberingSystems()) {
|
||||
localesHasNumberingSystems.add(locale);
|
||||
}
|
||||
}
|
||||
return convertToLocaleList(localesHasNumberingSystems);
|
||||
}
|
||||
|
||||
private static LocaleList convertToLocaleList(Set<Locale> locales) {
|
||||
if (locales.isEmpty()) {
|
||||
return LocaleList.getEmptyLocaleList();
|
||||
}
|
||||
return new LocaleList(locales.stream().toArray(Locale[]::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return new LocaleFeatureProviderImpl().getLocaleNames();
|
||||
return new LocaleFeatureProviderImpl().getLocaleNames(getNumberingSystemLocale());
|
||||
}
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.app.LocaleHelper;
|
||||
import com.android.internal.app.LocalePicker;
|
||||
import com.android.internal.app.LocaleStore;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
@@ -52,6 +53,8 @@ public class NumberingSystemItemController extends BasePreferenceController {
|
||||
|
||||
public NumberingSystemItemController(Context context, Bundle argument) {
|
||||
super(context, "no_key");
|
||||
// Initialize the supported languages to LocaleInfos
|
||||
LocaleStore.fillCache(context);
|
||||
mOption = argument.getString(
|
||||
RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE, "");
|
||||
mSelectedLanguage = argument.getString(
|
||||
@@ -111,8 +114,12 @@ public class NumberingSystemItemController extends BasePreferenceController {
|
||||
// Get current system language list to show on screen.
|
||||
LocaleList localeList = LocaleList.getDefault();
|
||||
for (int i = 0; i < localeList.size(); i++) {
|
||||
Preference pref = new Preference(mContext);
|
||||
Locale locale = localeList.get(i);
|
||||
LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(locale);
|
||||
if (!localeInfo.hasNumberingSystems()) {
|
||||
continue;
|
||||
}
|
||||
Preference pref = new Preference(mContext);
|
||||
pref.setTitle(LocaleHelper.getDisplayName(locale.stripExtensions(), locale, true));
|
||||
pref.setKey(locale.toLanguageTag());
|
||||
pref.setSummary(getNumberingSystem(locale));
|
||||
|
Reference in New Issue
Block a user