Remove Numbering System preference if no corresponding locale.
- If locale has no multiple numbering systems, it shall not show the locale on list. - If there is no locale with numberung system, remove the entry of numbering system preference on UI. Bug: b/274053189 Test: atest passed Test: Manual test passed Change-Id: If61c7e233630644e2d6245c5efd75d15d52cf94b
This commit is contained in:
@@ -27,9 +27,19 @@ public class LocaleFeatureProviderImpl implements LocaleFeatureProvider {
|
|||||||
@Override
|
@Override
|
||||||
public String getLocaleNames() {
|
public String getLocaleNames() {
|
||||||
final LocaleList locales = LocalePicker.getLocales();
|
final LocaleList locales = LocalePicker.getLocales();
|
||||||
Locale[] arrLocalesWithoutExtension = new Locale[locales.size()];
|
return getLocaleNames(locales);
|
||||||
for (int i = 0; i < locales.size(); i++) {
|
}
|
||||||
arrLocalesWithoutExtension[i] = locales.get(i).stripExtensions();
|
|
||||||
|
/**
|
||||||
|
* 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();
|
final Locale displayLocale = Locale.getDefault();
|
||||||
return LocaleHelper.toSentenceCase(
|
return LocaleHelper.toSentenceCase(
|
||||||
|
@@ -17,16 +17,26 @@
|
|||||||
package com.android.settings.regionalpreferences;
|
package com.android.settings.regionalpreferences;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.LocaleList;
|
||||||
|
|
||||||
|
import com.android.internal.app.LocaleStore;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.localepicker.LocaleFeatureProviderImpl;
|
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 */
|
/** A controller for the entry of Numbering System's page */
|
||||||
public class NumberingSystemController extends BasePreferenceController {
|
public class NumberingSystemController extends BasePreferenceController {
|
||||||
private static final String TAG = NumberingSystemController.class.getSimpleName();
|
private static final String TAG = NumberingSystemController.class.getSimpleName();
|
||||||
|
|
||||||
|
private LocaleList mLocaleList;
|
||||||
public NumberingSystemController(Context context, String preferenceKey) {
|
public NumberingSystemController(Context context, String preferenceKey) {
|
||||||
super(context, 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
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
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
|
@Override
|
||||||
public CharSequence getSummary() {
|
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.LocaleHelper;
|
||||||
import com.android.internal.app.LocalePicker;
|
import com.android.internal.app.LocalePicker;
|
||||||
|
import com.android.internal.app.LocaleStore;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
@@ -52,6 +53,8 @@ public class NumberingSystemItemController extends BasePreferenceController {
|
|||||||
|
|
||||||
public NumberingSystemItemController(Context context, Bundle argument) {
|
public NumberingSystemItemController(Context context, Bundle argument) {
|
||||||
super(context, "no_key");
|
super(context, "no_key");
|
||||||
|
// Initialize the supported languages to LocaleInfos
|
||||||
|
LocaleStore.fillCache(context);
|
||||||
mOption = argument.getString(
|
mOption = argument.getString(
|
||||||
RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE, "");
|
RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE, "");
|
||||||
mSelectedLanguage = argument.getString(
|
mSelectedLanguage = argument.getString(
|
||||||
@@ -111,8 +114,12 @@ public class NumberingSystemItemController extends BasePreferenceController {
|
|||||||
// Get current system language list to show on screen.
|
// Get current system language list to show on screen.
|
||||||
LocaleList localeList = LocaleList.getDefault();
|
LocaleList localeList = LocaleList.getDefault();
|
||||||
for (int i = 0; i < localeList.size(); i++) {
|
for (int i = 0; i < localeList.size(); i++) {
|
||||||
Preference pref = new Preference(mContext);
|
|
||||||
Locale locale = localeList.get(i);
|
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.setTitle(LocaleHelper.getDisplayName(locale.stripExtensions(), locale, true));
|
||||||
pref.setKey(locale.toLanguageTag());
|
pref.setKey(locale.toLanguageTag());
|
||||||
pref.setSummary(getNumberingSystem(locale));
|
pref.setSummary(getNumberingSystem(locale));
|
||||||
|
@@ -19,18 +19,15 @@ package com.android.settings.regionalpreferences;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
|
||||||
import androidx.test.annotation.UiThreadTest;
|
import androidx.test.annotation.UiThreadTest;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class NumberingPreferencesFragmentTest {
|
public class NumberingPreferencesFragmentTest {
|
||||||
private Context mApplicationContext;
|
|
||||||
private NumberingPreferencesFragment mFragment;
|
private NumberingPreferencesFragment mFragment;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -39,7 +36,6 @@ public class NumberingPreferencesFragmentTest {
|
|||||||
if (Looper.myLooper() == null) {
|
if (Looper.myLooper() == null) {
|
||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
}
|
}
|
||||||
mApplicationContext = ApplicationProvider.getApplicationContext();
|
|
||||||
mFragment = new NumberingPreferencesFragment();
|
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,7 +111,7 @@ public class NumberingSystemItemControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@UiThreadTest
|
@UiThreadTest
|
||||||
public void displayPreference_languageOptAndHas2Locale_show2Options() {
|
public void displayPreference_languageOptAndHas2LocaleWithSingleNu_showNothing() {
|
||||||
LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-TW"));
|
LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-TW"));
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
|
bundle.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
|
||||||
@@ -123,7 +123,25 @@ public class NumberingSystemItemControllerTest {
|
|||||||
|
|
||||||
mController.displayPreference(mPreferenceScreen);
|
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
|
@Test
|
||||||
|
Reference in New Issue
Block a user