Merge "Remove Numbering System preference if no corresponding locale." into udc-dev am: db94f350cb
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/22122897 Change-Id: I143b9528f46e78192a3135e5cab2c69b7522874e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
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));
|
||||
|
@@ -19,18 +19,15 @@ package com.android.settings.regionalpreferences;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class NumberingPreferencesFragmentTest {
|
||||
private Context mApplicationContext;
|
||||
private NumberingPreferencesFragment mFragment;
|
||||
|
||||
@Before
|
||||
@@ -39,7 +36,6 @@ public class NumberingPreferencesFragmentTest {
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
mApplicationContext = ApplicationProvider.getApplicationContext();
|
||||
mFragment = new NumberingPreferencesFragment();
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.regionalpreferences;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.LocaleList;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class NumberingSystemControllerTest {
|
||||
private Context mApplicationContext;
|
||||
private NumberingSystemController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mApplicationContext = ApplicationProvider.getApplicationContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_noLocale_unavailable() {
|
||||
LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-Hant-TW"));
|
||||
mController = new NumberingSystemController(mApplicationContext, "key");
|
||||
|
||||
int result = mController.getAvailabilityStatus();
|
||||
|
||||
assertEquals(CONDITIONALLY_UNAVAILABLE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_hasLocaleWithNumberingSystems_available() {
|
||||
// ar-JO has different numbering system.
|
||||
LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-Hant-TW,ar-JO"));
|
||||
mController = new NumberingSystemController(mApplicationContext, "key");
|
||||
|
||||
int result = mController.getAvailabilityStatus();
|
||||
|
||||
assertEquals(AVAILABLE, result);
|
||||
}
|
||||
}
|
@@ -111,8 +111,8 @@ public class NumberingSystemItemControllerTest {
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void displayPreference_languageOptAndHas2Locale_show2Options() {
|
||||
LocaleList.setDefault(LocaleList.forLanguageTags("en-US, zh-TW"));
|
||||
public void displayPreference_languageOptAndHas2LocaleWithSingleNu_showNothing() {
|
||||
LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-TW"));
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
|
||||
NumberingSystemItemController.ARG_VALUE_LANGUAGE_SELECT);
|
||||
@@ -123,13 +123,31 @@ public class NumberingSystemItemControllerTest {
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
assertEquals(LocaleList.getDefault().size(), mPreferenceScreen.getPreferenceCount());
|
||||
assertEquals(0, mPreferenceScreen.getPreferenceCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void displayPreference_languageOptAndHas2LocaleWithMultiNu_showLocaleWithMultiNuOnly() {
|
||||
// ar-JO and dz-BT have multiple numbering systems.
|
||||
LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-TW,ar-JO,dz-BT"));
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
|
||||
NumberingSystemItemController.ARG_VALUE_LANGUAGE_SELECT);
|
||||
bundle.putString(
|
||||
NumberingSystemItemController.KEY_SELECTED_LANGUAGE, Locale.US.toLanguageTag());
|
||||
mController = new NumberingSystemItemController(mApplicationContext, bundle);
|
||||
mController.setParentFragment(mFragment);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
assertEquals(2, mPreferenceScreen.getPreferenceCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void displayPreference_enUsNumbersOpt_show1Option() {
|
||||
LocaleList.setDefault(LocaleList.forLanguageTags("en-US, zh-TW"));
|
||||
LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-TW"));
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
|
||||
NumberingSystemItemController.ARG_VALUE_NUMBERING_SYSTEM_SELECT);
|
||||
|
Reference in New Issue
Block a user