[Regional preferences] Add numbering system page.

- Add language selection page
 - Add number format page
 - Refactor some part for readability.

Bug: b/247073388
Bug: b/246929960
Test: atest pass

Change-Id: I617698a3146b6e461467a97de8c08f4c4dc6e7f2
This commit is contained in:
tom hsu
2023-01-04 07:46:08 +08:00
parent 2aab7ae039
commit 6461d16c59
22 changed files with 813 additions and 215 deletions

View File

@@ -1361,15 +1361,14 @@
<string-array name="allowlist_hide_summary_in_battery_usage" translatable="false">
</string-array>
<!-- A list for all temperature units. [CHAR LIMIT=NONE] -->
<!-- A list for all temperature units. [DO NOT TRANSLATE] -->
<string-array name="temperature_units">
<item>default</item>
<item>celsius</item>
<item>fahrenheit</item>
<item>kelvin</item>
<item>fahrenhe</item>
</string-array>
<!-- A list for all days of a week. [CHAR LIMIT=NONE] -->
<!-- A list for all days of a week. [DO NOT TRANSLATE] -->
<string-array name="first_day_of_week">
<item>default</item>
<item>sun</item>
@@ -1381,7 +1380,7 @@
<item>sat</item>
</string-array>
<!-- A list for all supported calendar types. [CHAR LIMIT=NONE] -->
<!-- A list for all supported calendar types. [DO NOT TRANSLATE] -->
<string-array name="calendar_type">
<item>default</item>
<item>chinese</item>

View File

@@ -360,9 +360,11 @@
<!-- The summary of the menu entry of regional preferences. [CHAR LIMIT=NONE] -->
<string name="regional_preferences_summary">Set units and number preferences</string>
<!-- The subtitle of main page of regional preferences. [CHAR LIMIT=NONE] -->
<string name="regional_preferences_main_page_sub_title">Apps can use your regional preferences to personalize your experience</string>
<string name="regional_preferences_main_page_sub_title">Let apps know your regional preferences so they can personalize your experience.</string>
<!-- The subtitle of option's page of regional preferences for Temperature units, Calendar and First day of week. [CHAR LIMIT=NONE] -->
<string name="regional_preferences_option_page_sub_title">Apps will use your regional preferences where possible.</string>
<!-- The title of menu entry of Temperature unit preference. [CHAR LIMIT=50] -->
<string name="temperature_preferences_title">Temperature</string>
<string name="temperature_preferences_title">Temperature units</string>
<!-- The title of the menu entry of Calendar type preference. [CHAR LIMIT=50] -->
<string name="calendar_preferences_title">Calendar</string>
<!-- The title of the menu entry of First day of week preference. [CHAR LIMIT=50] -->
@@ -370,13 +372,11 @@
<!-- The title of the menu entry of Numbers system preference. [CHAR LIMIT=50] -->
<string name="numbers_preferences_title">Numbers</string>
<!-- The summary of default string for each regional preference. [CHAR LIMIT=50] -->
<string name="default_string_of_regional_preference">[No preference]</string>
<string name="default_string_of_regional_preference">Use app default</string>
<!-- The title of Celsius for preference of temperature unit. [CHAR LIMIT=50] -->
<string name="celsius_temperature_unit">Celsius</string>
<string name="celsius_temperature_unit">Celsius(\u00B0C)</string>
<!-- The title of Fahrenheit for preference of temperature unit. [CHAR LIMIT=50] -->
<string name="fahrenheit_temperature_unit">Fahrenheit</string>
<!-- The title of Kevin for preference of temperature unit. [CHAR LIMIT=50] -->
<string name="kevin_temperature_unit">Kevin</string>
<string name="fahrenheit_temperature_unit">Fahrenheit(\u00B0F)</string>
<!-- The title of sunday for preference of first day of week. [CHAR LIMIT=50] -->
<string name="sunday_first_day_of_week">Sunday</string>
<!-- The title of monday for preference of first day of week. [CHAR LIMIT=50] -->

View File

@@ -15,4 +15,8 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.android.settingslib.widget.TopIntroPreference
android:key="key_option_page_sub_title"
android:title="@string/regional_preferences_option_page_sub_title"
android:persistent="false" />
</PreferenceScreen>

View File

@@ -26,24 +26,44 @@
android:key="key_temperature_unit"
android:title="@string/temperature_preferences_title"
android:summary="@string/default_string_of_regional_preference"
settings:controller="com.android.settings.regionalpreferences.TemperatureUnitController"/>
settings:controller="com.android.settings.regionalpreferences.TemperatureUnitController"
settings:fragment="com.android.settings.regionalpreferences.RegionalPreferencesFragment">
<extra
android:name="arg_key_regional_preference"
android:value="mu" />
</Preference>
<Preference
android:key="key_calendar_type"
android:title="@string/calendar_preferences_title"
android:summary="@string/default_string_of_regional_preference"
settings:controller="com.android.settings.regionalpreferences.CalendarTypeController"/>
settings:controller="com.android.settings.regionalpreferences.CalendarTypeController"
settings:fragment="com.android.settings.regionalpreferences.RegionalPreferencesFragment">
<extra
android:name="arg_key_regional_preference"
android:value="ca" />
</Preference>
<Preference
android:key="key_first_day_of_week"
android:title="@string/first_day_of_week_preferences_title"
android:summary="@string/default_string_of_regional_preference"
settings:controller="com.android.settings.regionalpreferences.FirstDayOfWeekController"/>
settings:controller="com.android.settings.regionalpreferences.FirstDayOfWeekController"
settings:fragment="com.android.settings.regionalpreferences.RegionalPreferencesFragment">
<extra
android:name="arg_key_regional_preference"
android:value="fw" />
</Preference>
<Preference
android:key="key_numbering_system"
android:title="@string/numbers_preferences_title"
android:summary="@string/default_string_of_regional_preference"
settings:controller="com.android.settings.regionalpreferences.NumberingSystemController"/>
settings:controller="com.android.settings.regionalpreferences.NumberingSystemController"
settings:fragment="com.android.settings.regionalpreferences.NumberingPreferencesFragment">
<extra
android:name="arg_key_regional_preference"
android:value="arg_value_language_select" />
</Preference>
</PreferenceScreen>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" />

View File

@@ -16,17 +16,10 @@
package com.android.settings.regionalpreferences;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import androidx.preference.Preference;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.SubSettingLauncher;
import java.util.Locale;
@@ -68,25 +61,7 @@ public class CalendarTypeController extends BasePreferenceController {
result = LocalePreferences.getCalendarType(false);
}
String inputStr = result.isEmpty() ? RegionalPreferencesFragment.TYPE_DEFAULT : result;
String inputStr = result.isEmpty() ? RegionalPreferencesDataUtils.DEFAULT_VALUE : result;
return RegionalPreferencesDataUtils.calendarConverter(mContext, inputStr);
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (!TextUtils.equals(preference.getKey(), mPreferenceKey)) {
Log.e(TAG, "not the key " + preference.getKey() + " / " + mPreferenceKey);
return false;
}
final Bundle extra = new Bundle();
extra.putString(RegionalPreferencesFragment.TYPE_OF_REGIONAL_PREFERENCE,
RegionalPreferencesFragment.TYPE_CALENDAR);
new SubSettingLauncher(preference.getContext())
.setDestination(RegionalPreferencesFragment.class.getName())
.setSourceMetricsCategory(SettingsEnums.REGIONAL_PREFERENCE)
.setArguments(extra)
.launch();
return true;
}
}

View File

@@ -0,0 +1,36 @@
/*
* 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 android.annotation.StringDef;
/** Provides necessary value of language tag to Regional Preferences. */
public class ExtensionTypes {
public static final String CALENDAR = "ca";
public static final String FIRST_DAY_OF_WEEK = "fw";
public static final String NUMBERING_SYSTEM = "nu";
public static final String TEMPERATURE_UNIT = "mu";
@StringDef({
FIRST_DAY_OF_WEEK,
CALENDAR,
TEMPERATURE_UNIT,
NUMBERING_SYSTEM
})
public @interface Values {}
}

View File

@@ -16,18 +16,11 @@
package com.android.settings.regionalpreferences;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.SubSettingLauncher;
import java.util.Locale;
@@ -71,22 +64,4 @@ public class FirstDayOfWeekController extends BasePreferenceController {
? mContext.getString(R.string.default_string_of_regional_preference)
: RegionalPreferencesDataUtils.dayConverter(mContext, result);
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (!TextUtils.equals(preference.getKey(), mPreferenceKey)) {
Log.e(TAG, "not the key " + preference.getKey() + " / " + mPreferenceKey);
return false;
}
final Bundle extra = new Bundle();
extra.putString(RegionalPreferencesFragment.TYPE_OF_REGIONAL_PREFERENCE,
RegionalPreferencesFragment.TYPE_FIRST_DAY_OF_WEEK);
new SubSettingLauncher(preference.getContext())
.setDestination(RegionalPreferencesFragment.class.getName())
.setSourceMetricsCategory(SettingsEnums.REGIONAL_PREFERENCE)
.setArguments(extra)
.launch();
return true;
}
}

View File

@@ -276,7 +276,7 @@ public final class LocalePreferences {
/** Celsius */
public static final String CELSIUS = "celsius";
/** Fahrenheit */
public static final String FAHRENHEIT = "fahrenheit";
public static final String FAHRENHEIT = "fahrenhe";
/** Kelvin */
public static final String KELVIN = "kelvin";
/** Default Temperature for the locale */
@@ -301,7 +301,7 @@ public final class LocalePreferences {
/**
* Return the user's preference of the temperature unit which is from {@link
* Locale#getDefault(Locale.Category)}. The returned result is resolved and bases on the
* {@code Locale#getDefault(Locale.Category)} settings. E.g. "fahrenheit"
* {@code Locale#getDefault(Locale.Category)} settings. E.g. "fahrenhe"
*/
@NonNull
@OptIn(markerClass = BuildCompat.PrereleaseSdkCheck.class)
@@ -312,7 +312,7 @@ public final class LocalePreferences {
/**
* Return the temperature unit of the inputted {@link Locale}. The returned result is resolved
* and bases on the inputted {@code Locale} settings. E.g. "fahrenheit"
* and bases on the inputted {@code Locale} settings. E.g. "fahrenhe"
*/
@NonNull
@OptIn(markerClass = BuildCompat.PrereleaseSdkCheck.class)
@@ -324,7 +324,7 @@ public final class LocalePreferences {
/**
* Return the user's preference of the temperature unit which is from {@link
* Locale#getDefault(Locale.Category)}. E.g. "fahrenheit"
* Locale#getDefault(Locale.Category)}. E.g. "fahrenhe"
*
* @param resolved If the {@code Locale#getDefault(Locale.Category)} contains temperature unit
* subtag, this argument is ignored. If the
@@ -522,9 +522,6 @@ public final class LocalePreferences {
String mu =
locale.getUnicodeLocaleType(TemperatureUnit.U_EXTENSION_OF_TEMPERATURE_UNIT);
if (mu != null) {
if (mu.contains("fahrenhe")) {
mu = TemperatureUnit.FAHRENHEIT;
}
return mu;
}
if (!resolved) {
@@ -592,7 +589,11 @@ public final class LocalePreferences {
.usage("temperature")
.unit(MeasureUnit.CELSIUS)
.locale(locale);
return nf.format(1).getOutputUnit().getIdentifier();
String unit = nf.format(1).getOutputUnit().getIdentifier();
if (unit.contains(TemperatureUnit.FAHRENHEIT)) {
return TemperatureUnit.FAHRENHEIT;
}
return unit;
}
private Api33Impl() {

View File

@@ -0,0 +1,111 @@
/*
* 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 android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/** Provides options of numbering system to each language. */
public class NumberingPreferencesFragment extends DashboardFragment {
/** Initializes variables. */
@VisibleForTesting
String initTitle() {
String option = getArguments().getString(
RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE, "");
if (option.isEmpty()) {
Log.d(getLogTag(), "Option is empty.");
return "";
}
Log.i(getLogTag(), "[NumberingPreferencesFragment] option is " + option);
if (option.equals(NumberingSystemItemController.ARG_VALUE_LANGUAGE_SELECT)) {
return getContext().getString(R.string.numbers_preferences_title);
} else if (option.equals(NumberingSystemItemController.ARG_VALUE_NUMBERING_SYSTEM_SELECT)) {
String selectedLanguage = getArguments().getString(
NumberingSystemItemController.KEY_SELECTED_LANGUAGE, "");
if (selectedLanguage.isEmpty()) {
Log.w(getLogTag(), "No selected language.");
return "";
}
return Locale.forLanguageTag(selectedLanguage)
.stripExtensions()
.getDisplayName(Locale.forLanguageTag(selectedLanguage));
}
Log.w(getLogTag(), "Incorrect option : " + option);
return "";
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
String title = initTitle();
if (initTitle().isEmpty()) {
finish();
} else {
getActivity().setTitle(title);
}
}
/**
* Get a list of {@link AbstractPreferenceController} for this fragment.
*/
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
NumberingSystemItemController controller =
new NumberingSystemItemController(context, getArguments());
controller.setParentFragment(this);
List<AbstractPreferenceController> listControllers = new ArrayList<>();
listControllers.add(controller);
return listControllers;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.regional_preference_numbering_system_page;
}
/**
* Get the tag string for logging.
*/
@Override
protected String getLogTag() {
return NumberingPreferencesFragment.class.getSimpleName();
}
@Override
public int getMetricsCategory() {
String option = getArguments().getString(
RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE, "");
if (option.equals(NumberingSystemItemController.ARG_VALUE_LANGUAGE_SELECT)) {
return SettingsEnums.NUMBERING_SYSTEM_LANGUAGE_SELECTION_PREFERENCE;
} else {
return SettingsEnums.NUMBERING_SYSTEM_NUMBER_FORMAT_SELECTION_PREFERENCE;
}
}
}

View File

@@ -16,28 +16,18 @@
package com.android.settings.regionalpreferences;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.icu.text.NumberingSystem;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.os.LocaleList;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.SubSettingLauncher;
import java.util.Locale;
import java.util.StringJoiner;
/** A controller for the entry of Numbering System's page */
public class NumberingSystemController extends BasePreferenceController {
private static final String TAG = NumberingSystemController.class.getSimpleName();
private static final String UNICODE_EXTENSION_NUMBERING_SYSTEM = "nu";
public NumberingSystemController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@@ -55,49 +45,17 @@ public class NumberingSystemController extends BasePreferenceController {
*/
@Override
public int getAvailabilityStatus() {
// Hide this , and waiting for next implementation.
return CONDITIONALLY_UNAVAILABLE;
return AVAILABLE;
}
@Override
public CharSequence getSummary() {
String record = Settings.System.getString(
mContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES);
String result = "";
if (!TextUtils.isEmpty(record)) {
result = Locale.forLanguageTag(record)
.getUnicodeLocaleType(UNICODE_EXTENSION_NUMBERING_SYSTEM);
LocaleList localeList = LocaleList.getDefault();
StringJoiner stringJoiner = new StringJoiner(", ");
for (int i = 0; i < localeList.size(); i++) {
Locale locale = localeList.get(i);
stringJoiner.add(locale.stripExtensions().getDisplayName(locale));
}
if (TextUtils.isEmpty(result)) {
result = Locale.getDefault(Locale.Category.FORMAT)
.getUnicodeLocaleType(UNICODE_EXTENSION_NUMBERING_SYSTEM);
if (TextUtils.isEmpty(result)) {
return mContext.getString(R.string.default_string_of_regional_preference);
}
}
Locale locale = new Locale.Builder()
.setUnicodeLocaleKeyword(UNICODE_EXTENSION_NUMBERING_SYSTEM, result)
.build();
return NumberingSystem.getInstance(locale).getName();
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (!TextUtils.equals(preference.getKey(), mPreferenceKey)) {
Log.e(TAG, "not the key " + preference.getKey() + " / " + mPreferenceKey);
return false;
}
final Bundle extra = new Bundle();
extra.putString(RegionalPreferencesFragment.TYPE_OF_REGIONAL_PREFERENCE,
RegionalPreferencesFragment.TYPE_NUMBERING_SYSTEM);
new SubSettingLauncher(preference.getContext())
.setDestination(RegionalPreferencesFragment.class.getName())
.setSourceMetricsCategory(SettingsEnums.REGIONAL_PREFERENCE)
.setArguments(extra)
.launch();
return true;
return stringJoiner.toString();
}
}

View File

@@ -0,0 +1,216 @@
/*
* 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 android.app.settings.SettingsEnums;
import android.content.Context;
import android.icu.text.NumberingSystem;
import android.icu.util.ULocale;
import android.os.Bundle;
import android.os.LocaleList;
import android.text.TextUtils;
import android.util.Log;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.internal.app.LocaleHelper;
import com.android.internal.app.LocalePicker;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.dashboard.DashboardFragment;
import java.util.Locale;
/** Uses to control the preference UI of numbering system page. */
public class NumberingSystemItemController extends BasePreferenceController {
private static final String TAG = NumberingSystemItemController.class.getSimpleName();
static final String ARG_VALUE_NUMBERING_SYSTEM_SELECT = "arg_value_numbering_system_select";
static final String ARG_VALUE_LANGUAGE_SELECT = "arg_value_language_select";
static final String KEY_SELECTED_LANGUAGE = "key_selected_language";
private static final String DISPLAY_KEYWORD_NUMBERING_SYSTEM = "numbers";
private String mOption = "";
private String mSelectedLanguage = "";
private DashboardFragment mParentFragment;
private PreferenceScreen mPreferenceScreen;
public NumberingSystemItemController(Context context, Bundle argument) {
super(context, "no_key");
mOption = argument.getString(
RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE, "");
mSelectedLanguage = argument.getString(
NumberingSystemItemController.KEY_SELECTED_LANGUAGE, "");
}
/**
* Displays preference in this controller.
*/
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreferenceScreen = screen;
if (mOption.equals(ARG_VALUE_LANGUAGE_SELECT)) {
initLanguageOptionsUi(screen);
} else if (mOption.equals(ARG_VALUE_NUMBERING_SYSTEM_SELECT)) {
initNumberingSystemOptionsUi(screen, Locale.forLanguageTag(mSelectedLanguage));
}
}
/**
* Sets the parent fragment and attaches this controller to the settings lifecycle.
*
* @param fragment the fragment to use as the parent
*/
public void setParentFragment(DashboardFragment fragment) {
mParentFragment = fragment;
}
/**
* @return {@link AvailabilityStatus} for the Setting. This status is used to determine if the
* Setting should be shown or disabled in Settings. Further, it can be used to produce
* appropriate error / warning Slice in the case of unavailability.
* </p>
* The status is used for the convenience methods: {@link #isAvailable()}, {@link
* #isSupported()}
* </p>
* The inherited class doesn't need to check work profile if android:forWork="true" is set in
* preference xml.
*/
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (mOption.equals(ARG_VALUE_LANGUAGE_SELECT)) {
handleLanguageSelect(preference);
} else if (mOption.equals(ARG_VALUE_NUMBERING_SYSTEM_SELECT)) {
handleNumberSystemSelect(preference);
}
return true;
}
private void initLanguageOptionsUi(PreferenceScreen screen) {
// 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);
pref.setTitle(LocaleHelper.getDisplayName(locale.stripExtensions(), locale, true));
pref.setKey(locale.toLanguageTag());
pref.setSummary(getNumberingSystem(locale));
screen.addPreference(pref);
}
}
private void initNumberingSystemOptionsUi(PreferenceScreen screen, Locale targetLocale) {
String[] locales = LocalePicker.getSupportedLocales(mContext);
for (String localeTag : locales) {
Locale supportedLocale = Locale.forLanguageTag(localeTag);
if (isSameBaseLocale(targetLocale, supportedLocale)) {
TickButtonPreference pref = new TickButtonPreference(mContext);
String numberingName = getNumberingSystem(supportedLocale);
pref.setTitle(numberingName);
String key = supportedLocale.getUnicodeLocaleType(
ExtensionTypes.NUMBERING_SYSTEM);
pref.setKey(key == null ? RegionalPreferencesDataUtils.DEFAULT_VALUE : key);
pref.setTickEnable(isSameNumberingSystem(targetLocale, supportedLocale));
screen.addPreference(pref);
}
}
}
private void handleLanguageSelect(Preference preference) {
final Bundle extra = new Bundle();
extra.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
ARG_VALUE_NUMBERING_SYSTEM_SELECT);
extra.putString(KEY_SELECTED_LANGUAGE, preference.getKey());
new SubSettingLauncher(preference.getContext())
.setDestination(NumberingPreferencesFragment.class.getName())
.setSourceMetricsCategory(
SettingsEnums.NUMBERING_SYSTEM_LANGUAGE_SELECTION_PREFERENCE)
.setArguments(extra)
.launch();
}
private void handleNumberSystemSelect(Preference preference) {
for (int i = 0; i < mPreferenceScreen.getPreferenceCount(); i++) {
TickButtonPreference pref = (TickButtonPreference) mPreferenceScreen.getPreference(i);
Log.i(TAG, "[onPreferenceClick] key is " + pref.getKey());
if (pref.getKey().equals(preference.getKey())) {
pref.setTickEnable(true);
Locale updatedLocale =
saveNumberingSystemToLocale(
Locale.forLanguageTag(mSelectedLanguage), pref.getKey());
// After updated locale to framework, this fragment will recreate,
// so it need to update the argement of selected language.
Bundle bundle = new Bundle();
bundle.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
ARG_VALUE_NUMBERING_SYSTEM_SELECT);
bundle.putString(KEY_SELECTED_LANGUAGE, updatedLocale.toLanguageTag());
mParentFragment.setArguments(bundle);
continue;
}
pref.setTickEnable(false);
}
}
private Locale saveNumberingSystemToLocale(Locale targetLocale, String value) {
LocaleList localeList = LocalePicker.getLocales();
Locale[] locales = new Locale[localeList.size()];
for (int i = 0; i < localeList.size(); i++) {
Locale locale = localeList.get(i);
if (targetLocale.equals(locale)) {
if (value.equals(RegionalPreferencesDataUtils.DEFAULT_VALUE)) {
value = null;
}
Locale updatedLocale = new Locale.Builder()
.setLocale(locale)
.setUnicodeLocaleKeyword(ExtensionTypes.NUMBERING_SYSTEM, value)
.build();
locales[i] = updatedLocale;
continue;
}
locales[i] = localeList.get(i);
}
LocalePicker.updateLocales(new LocaleList(locales));
return targetLocale;
}
private static String getNumberingSystem(Locale locale) {
ULocale uLocale = new ULocale.Builder()
.setUnicodeLocaleKeyword(ExtensionTypes.NUMBERING_SYSTEM,
NumberingSystem.getInstance(locale).getName())
.build();
return uLocale.getDisplayKeywordValue(DISPLAY_KEYWORD_NUMBERING_SYSTEM,
ULocale.forLocale(locale));
}
private static boolean isSameNumberingSystem(Locale locale1, Locale locale2) {
String name1 = NumberingSystem.getInstance(locale1).getName();
String name2 = NumberingSystem.getInstance(locale2).getName();
return TextUtils.equals(name1, name2);
}
private static boolean isSameBaseLocale(Locale locale1, Locale locale2) {
return locale1.stripExtensions().equals(locale2.stripExtensions());
}
}

View File

@@ -29,10 +29,8 @@ import java.util.Locale;
/** Provides utils for regional preferences. */
public class RegionalPreferencesDataUtils {
private static final String TAG = RegionalPreferencesDataUtils.class.getSimpleName();
private static final String U_EXTENSION_FAHRENHEIT = "fahrenhe";
private static final String KEYWORD_OF_CALENDAR = "calendar";
static final String DISPLAY_KEYWORD_OF_CALENDAR = "calendar";
static final String DEFAULT_VALUE = "default";
static String getDefaultUnicodeExtensionData(Context contxt, String type) {
// 1. Check cache data in Settings provider.
@@ -47,27 +45,11 @@ public class RegionalPreferencesDataUtils {
if (TextUtils.isEmpty(result)) {
result = Locale.getDefault(Locale.Category.FORMAT).getUnicodeLocaleType(type);
}
if (result == null) {
return RegionalPreferencesFragment.TYPE_DEFAULT;
}
// In BCP47 expression, the tag of fahrenheit is "fahrenhe" i.e. und-u-mu-fahrenhe,
// so if it may need to convert from the langngiage tag, "fahrenhe", to "fahrenheit".
if (result.equals(U_EXTENSION_FAHRENHEIT)) {
return LocalePreferences.TemperatureUnit.FAHRENHEIT;
}
return result;
return result == null ? DEFAULT_VALUE : result;
}
static void savePreference(Context context, String type, String value) {
if (type.equals(RegionalPreferencesFragment.TYPE_TEMPERATURE)
&& value != null && value.equals(LocalePreferences.TemperatureUnit.FAHRENHEIT)) {
// In BCP47 expression, the temperature unit is expressed to "fahrenhe"
// i.e. zh-TW-u-mu-fahrenhe. Hence, if we want to save fahrenheit unit to u extension,
// It need to change from "fahrenheit" to "fahrenhe".
value = U_EXTENSION_FAHRENHEIT;
}
saveToSettingsProvider(context, type, value);
saveToSystem(type, value);
}
@@ -105,14 +87,14 @@ public class RegionalPreferencesDataUtils {
}
static String calendarConverter(Context context, String calendarType) {
if (calendarType.equals(RegionalPreferencesFragment.TYPE_DEFAULT)) {
if (calendarType.equals(DEFAULT_VALUE)) {
return context.getString(R.string.default_string_of_regional_preference);
}
Locale locale = new Locale.Builder()
.setUnicodeLocaleKeyword(RegionalPreferencesFragment.TYPE_CALENDAR, calendarType)
.setUnicodeLocaleKeyword(ExtensionTypes.CALENDAR, calendarType)
.build();
return ULocale.getDisplayKeywordValue(locale.toLanguageTag(), KEYWORD_OF_CALENDAR,
return ULocale.getDisplayKeywordValue(locale.toLanguageTag(), DISPLAY_KEYWORD_OF_CALENDAR,
ULocale.forLocale(Locale.getDefault(Locale.Category.FORMAT)));
}
@@ -122,8 +104,6 @@ public class RegionalPreferencesDataUtils {
return context.getString(R.string.celsius_temperature_unit);
case LocalePreferences.TemperatureUnit.FAHRENHEIT:
return context.getString(R.string.fahrenheit_temperature_unit);
case LocalePreferences.TemperatureUnit.KELVIN:
return context.getString(R.string.kevin_temperature_unit);
default:
return context.getString(R.string.default_string_of_regional_preference);
}

View File

@@ -28,6 +28,8 @@ import com.android.settingslib.search.SearchIndexable;
public class RegionalPreferencesEntriesFragment extends DashboardFragment {
private static final String TAG = RegionalPreferencesEntriesFragment.class.getSimpleName();
static final String ARG_KEY_REGIONAL_PREFERENCE = "arg_key_regional_preference";
@Override
public void onStart() {
super.onStart();

View File

@@ -34,13 +34,6 @@ import com.android.settings.SettingsPreferenceFragment;
public class RegionalPreferencesFragment extends SettingsPreferenceFragment {
private static final String TAG = RegionalPreferencesFragment.class.getSimpleName();
static final String TYPE_DEFAULT = "default";
static final String TYPE_TEMPERATURE = "mu";
static final String TYPE_CALENDAR = "ca";
static final String TYPE_FIRST_DAY_OF_WEEK = "fw";
static final String TYPE_NUMBERING_SYSTEM = "nu";
static final String TYPE_OF_REGIONAL_PREFERENCE = "type_of_regional_preference";
private PreferenceScreen mPreferenceScreen;
private String mTitle = "";
@VisibleForTesting
@@ -48,18 +41,15 @@ public class RegionalPreferencesFragment extends SettingsPreferenceFragment {
private String[] initializeUIdata(String type) {
switch(type) {
case TYPE_TEMPERATURE:
case ExtensionTypes.TEMPERATURE_UNIT:
mTitle = getPrefContext().getString(R.string.temperature_preferences_title);
return getPrefContext().getResources().getStringArray(R.array.temperature_units);
case TYPE_CALENDAR:
case ExtensionTypes.CALENDAR:
mTitle = getPrefContext().getString(R.string.calendar_preferences_title);
return getPrefContext().getResources().getStringArray(R.array.calendar_type);
case TYPE_FIRST_DAY_OF_WEEK:
case ExtensionTypes.FIRST_DAY_OF_WEEK:
mTitle = getPrefContext().getString(R.string.first_day_of_week_preferences_title);
return getPrefContext().getResources().getStringArray(R.array.first_day_of_week);
case TYPE_NUMBERING_SYSTEM:
mTitle = getPrefContext().getString(R.string.numbers_preferences_title);
return new String[0];
default:
mTitle = getPrefContext().getString(R.string.regional_preferences_title);
return new String[0];
@@ -68,7 +58,8 @@ public class RegionalPreferencesFragment extends SettingsPreferenceFragment {
@Override
public boolean onPreferenceTreeClick(Preference preference) {
for (int i = 0; i < mPreferenceScreen.getPreferenceCount(); i++) {
// The first preference is TopIntroPreference
for (int i = 1; i < mPreferenceScreen.getPreferenceCount(); i++) {
TickButtonPreference pref = (TickButtonPreference) mPreferenceScreen.getPreference(i);
Log.i(TAG, "[onPreferenceClick] key is " + pref.getKey());
if (pref.getKey().equals(preference.getKey())) {
@@ -76,7 +67,9 @@ public class RegionalPreferencesFragment extends SettingsPreferenceFragment {
RegionalPreferencesDataUtils.savePreference(
getPrefContext(),
mType,
preference.getKey().equals(TYPE_DEFAULT) ? null : preference.getKey());
preference.getKey().equals(
RegionalPreferencesDataUtils.DEFAULT_VALUE)
? null : preference.getKey());
continue;
}
pref.setTickEnable(false);
@@ -88,7 +81,8 @@ public class RegionalPreferencesFragment extends SettingsPreferenceFragment {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Bundle bundle = getArguments();
String type = bundle.getString(TYPE_OF_REGIONAL_PREFERENCE, "");
String type = bundle.getString(
RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE, "");
if (type.isEmpty()) {
Log.w(TAG, "There is no type name.");
finish();
@@ -101,18 +95,16 @@ public class RegionalPreferencesFragment extends SettingsPreferenceFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
String[] uiData = initializeUIdata(mType);
for (String item : uiData) {
TickButtonPreference pref = new TickButtonPreference(getPrefContext());
if (mType.equals(TYPE_FIRST_DAY_OF_WEEK)) {
if (mType.equals(ExtensionTypes.FIRST_DAY_OF_WEEK)) {
pref.setTitle(RegionalPreferencesDataUtils.dayConverter(
getPrefContext(), item));
} else if (mType.equals(TYPE_TEMPERATURE)) {
} else if (mType.equals(ExtensionTypes.TEMPERATURE_UNIT)) {
pref.setTitle(RegionalPreferencesDataUtils.temperatureUnitsConverter(
getPrefContext(), item));
} else if (mType.equals(TYPE_CALENDAR)) {
} else if (mType.equals(ExtensionTypes.CALENDAR)) {
pref.setTitle(RegionalPreferencesDataUtils.calendarConverter(
getPrefContext(), item));
} else {
@@ -126,7 +118,7 @@ public class RegionalPreferencesFragment extends SettingsPreferenceFragment {
pref.setTickEnable(!value.isEmpty() && item.equals(value));
mPreferenceScreen.addPreference(pref);
}
return view;
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
@@ -138,9 +130,9 @@ public class RegionalPreferencesFragment extends SettingsPreferenceFragment {
@Override
public int getMetricsCategory() {
switch(mType) {
case TYPE_CALENDAR:
case ExtensionTypes.CALENDAR:
return SettingsEnums.CALENDAR_PREFERENCE;
case TYPE_FIRST_DAY_OF_WEEK:
case ExtensionTypes.FIRST_DAY_OF_WEEK:
return SettingsEnums.FIRST_DAY_OF_WEEK_PREFERENCE;
default:
return SettingsEnums.TEMPERATURE_PREFERENCE;

View File

@@ -16,18 +16,11 @@
package com.android.settings.regionalpreferences;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.SubSettingLauncher;
import java.util.Locale;
@@ -71,21 +64,4 @@ public class TemperatureUnitController extends BasePreferenceController {
? mContext.getString(R.string.default_string_of_regional_preference)
: RegionalPreferencesDataUtils.temperatureUnitsConverter(mContext, result);
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (!TextUtils.equals(preference.getKey(), mPreferenceKey)) {
Log.e(TAG, "not the key " + preference.getKey() + " / " + mPreferenceKey);
return false;
}
final Bundle extra = new Bundle();
extra.putString(RegionalPreferencesFragment.TYPE_OF_REGIONAL_PREFERENCE,
RegionalPreferencesFragment.TYPE_TEMPERATURE);
new SubSettingLauncher(preference.getContext())
.setDestination(RegionalPreferencesFragment.class.getName())
.setSourceMetricsCategory(SettingsEnums.REGIONAL_PREFERENCE)
.setArguments(extra)
.launch();
return true;
}
}

View File

@@ -98,8 +98,10 @@ public class CalendarTypeControllerTest {
private static String getDisplayKeywordValue(String value) {
String languageTag = new Locale.Builder()
.setUnicodeLocaleKeyword(
RegionalPreferencesFragment.TYPE_CALENDAR, value).build().toLanguageTag();
return ULocale.getDisplayKeywordValue(languageTag, "calendar",
ExtensionTypes.CALENDAR, value).build().toLanguageTag();
return ULocale.getDisplayKeywordValue(
languageTag,
RegionalPreferencesDataUtils.DISPLAY_KEYWORD_OF_CALENDAR,
ULocale.forLocale(Locale.getDefault(Locale.Category.FORMAT)));
}
}

View File

@@ -0,0 +1,106 @@
/*
* 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 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 com.android.settings.testutils.ResourcesUtils;
import org.junit.Before;
import org.junit.Test;
import java.util.Locale;
public class NumberingPreferencesFragmentTest {
private Context mApplicationContext;
private NumberingPreferencesFragment mFragment;
@Before
@UiThreadTest
public void setUp() throws Exception {
if (Looper.myLooper() == null) {
Looper.prepare();
}
mApplicationContext = ApplicationProvider.getApplicationContext();
mFragment = new NumberingPreferencesFragment();
}
@Test
@UiThreadTest
public void initTitle_optionIsLanguageSelection_titleIsNumbers() {
Bundle bundle = new Bundle();
bundle.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
NumberingSystemItemController.ARG_VALUE_LANGUAGE_SELECT);
mFragment.setArguments(bundle);
String result = mFragment.initTitle();
assertEquals(ResourcesUtils.getResourcesString(
mApplicationContext, "numbers_preferences_title"), result);
}
@Test
@UiThreadTest
public void initTitle_optionIsNumberingSystemSelection_titleIsLocaleDisplayName() {
Locale expectedLocale = Locale.forLanguageTag("en-US");
Bundle bundle = new Bundle();
bundle.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
NumberingSystemItemController.ARG_VALUE_NUMBERING_SYSTEM_SELECT);
bundle.putString(
NumberingSystemItemController.KEY_SELECTED_LANGUAGE,
expectedLocale.toLanguageTag());
mFragment.setArguments(bundle);
String result = mFragment.initTitle();
assertEquals(expectedLocale.getDisplayName(expectedLocale), result);
}
@Test
@UiThreadTest
public void getMetricsCategory_optionIsLanguageSelection_resultIsLanguageSelection() {
Bundle extras = new Bundle();
extras.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
NumberingSystemItemController.ARG_VALUE_LANGUAGE_SELECT);
mFragment.setArguments(extras);
int result = mFragment.getMetricsCategory();
assertEquals(SettingsEnums.NUMBERING_SYSTEM_LANGUAGE_SELECTION_PREFERENCE, result);
}
@Test
@UiThreadTest
public void getMetricsCategory_optionIsNumberSelection_resultIsNumberSelection() {
Bundle extras = new Bundle();
extras.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
NumberingSystemItemController.ARG_VALUE_NUMBERING_SYSTEM_SELECT);
mFragment.setArguments(extras);
int result = mFragment.getMetricsCategory();
assertEquals(SettingsEnums.NUMBERING_SYSTEM_NUMBER_FORMAT_SELECTION_PREFERENCE, result);
}
}

View File

@@ -0,0 +1,83 @@
/*
* 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 org.junit.Assert.assertEquals;
import android.content.Context;
import android.os.LocaleList;
import androidx.test.core.app.ApplicationProvider;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.Locale;
public class NumberingSystemControllerTest {
private Context mApplicationContext;
private NumberingSystemController mController;
private LocaleList mCacheLocales;
@Before
public void setUp() throws Exception {
mApplicationContext = ApplicationProvider.getApplicationContext();
mController = new NumberingSystemController(mApplicationContext, "key");
mCacheLocales = LocaleList.getDefault();
}
@After
public void tearDown() throws Exception {
LocaleList.setDefault(mCacheLocales);
}
@Test
public void getSummary_has1Locale_showEnUs() {
LocaleList.setDefault(LocaleList.forLanguageTags("en-US"));
String summary = mController.getSummary().toString();
String expectedResult =
Locale.forLanguageTag("en-us").getDisplayName();
assertEquals(expectedResult, summary);
}
@Test
public void getSummary_has2Locales_showEnUsAndZhTw() {
LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-TW"));
String summary = mController.getSummary().toString();
Locale locale1 = Locale.forLanguageTag("en-US");
Locale locale2 = Locale.forLanguageTag("zh-TW");
String expectedResult =
locale1.getDisplayName(locale1) + ", " + locale2.getDisplayName(locale2);
assertEquals(expectedResult, summary);
}
@Test
public void getSummary_localeHasExtensionTag_showEnUsWithoutTag() {
LocaleList.setDefault(LocaleList.forLanguageTags("en-US-u-ca-chinese"));
String summary = mController.getSummary().toString();
String expectedResult = Locale.forLanguageTag("en-US").getDisplayName();
assertEquals(expectedResult, summary);
}
}

View File

@@ -0,0 +1,146 @@
/*
* 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 org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.os.Bundle;
import android.os.LocaleList;
import android.os.Looper;
import android.util.AndroidRuntimeException;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.test.annotation.UiThreadTest;
import androidx.test.core.app.ApplicationProvider;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.Locale;
public class NumberingSystemItemControllerTest {
private Context mApplicationContext;
private NumberingSystemItemController mController;
private NumberingPreferencesFragment mFragment;
private PreferenceScreen mPreferenceScreen;
private LocaleList mCacheLocale;
@Before
@UiThreadTest
public void setUp() throws Exception {
if (Looper.myLooper() == null) {
Looper.prepare();
}
mApplicationContext = ApplicationProvider.getApplicationContext();
mFragment = spy(new NumberingPreferencesFragment());
PreferenceManager preferenceManager = new PreferenceManager(mApplicationContext);
mPreferenceScreen = preferenceManager.createPreferenceScreen(mApplicationContext);
mCacheLocale = LocaleList.getDefault();
}
@After
public void tearDown() {
LocaleList.setDefault(mCacheLocale);
}
@Test
@UiThreadTest
public void handlePreferenceTreeClick_languageSelect_launchFragment() {
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());
TickButtonPreference preference = new TickButtonPreference(mApplicationContext);
preference.setKey("I_am_the_key");
mPreferenceScreen.addPreference(preference);
mController = new NumberingSystemItemController(mApplicationContext, bundle);
mController.setParentFragment(mFragment);
mController.displayPreference(mPreferenceScreen);
boolean isCallingStartActivity = false;
try {
mController.handlePreferenceTreeClick(preference);
} catch (AndroidRuntimeException exception) {
isCallingStartActivity = true;
}
assertTrue(isCallingStartActivity);
}
@Test
@UiThreadTest
public void handlePreferenceTreeClick_numbersSelect_preferenceHasTick() {
Bundle bundle = new Bundle();
bundle.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
NumberingSystemItemController.ARG_VALUE_NUMBERING_SYSTEM_SELECT);
bundle.putString(
NumberingSystemItemController.KEY_SELECTED_LANGUAGE, Locale.US.toLanguageTag());
TickButtonPreference preference = new TickButtonPreference(mApplicationContext);
preference.setKey("test_key");
mPreferenceScreen.addPreference(preference);
mController = new NumberingSystemItemController(mApplicationContext, bundle);
mController.setParentFragment(mFragment);
mController.displayPreference(mPreferenceScreen);
mController.handlePreferenceTreeClick(preference);
verify(mFragment).setArguments(any());
}
@Test
@UiThreadTest
public void displayPreference_languageOptAndHas2Locale_show2Options() {
LocaleList.setDefault(LocaleList.forLanguageTags("en-US, zh-TW"));
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(LocaleList.getDefault().size(), mPreferenceScreen.getPreferenceCount());
}
@Test
@UiThreadTest
public void displayPreference_enUsNumbersOpt_show1Option() {
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);
bundle.putString(
NumberingSystemItemController.KEY_SELECTED_LANGUAGE, Locale.US.toLanguageTag());
mController = new NumberingSystemItemController(mApplicationContext, bundle);
mController.setParentFragment(mFragment);
mController.displayPreference(mPreferenceScreen);
// en-US only has 1 numbering system.
assertEquals(1, mPreferenceScreen.getPreferenceCount());
}
}

View File

@@ -62,7 +62,7 @@ public class RegionalPreferencesDataUtilsTest {
mApplicationContext, "und-u-mu-celsius");
String unit = RegionalPreferencesDataUtils.getDefaultUnicodeExtensionData(
mApplicationContext, RegionalPreferencesFragment.TYPE_TEMPERATURE);
mApplicationContext, ExtensionTypes.TEMPERATURE_UNIT);
assertEquals(LocalePreferences.TemperatureUnit.CELSIUS, unit);
}
@@ -74,7 +74,7 @@ public class RegionalPreferencesDataUtilsTest {
Locale.setDefault(Locale.forLanguageTag("en-US-u-mu-celsius"));
String unit = RegionalPreferencesDataUtils.getDefaultUnicodeExtensionData(
mApplicationContext, RegionalPreferencesFragment.TYPE_TEMPERATURE);
mApplicationContext, ExtensionTypes.TEMPERATURE_UNIT);
assertEquals(LocalePreferences.TemperatureUnit.CELSIUS, unit);
}
@@ -86,16 +86,16 @@ public class RegionalPreferencesDataUtilsTest {
Locale.setDefault(Locale.forLanguageTag("en-US"));
String unit = RegionalPreferencesDataUtils.getDefaultUnicodeExtensionData(
mApplicationContext, RegionalPreferencesFragment.TYPE_TEMPERATURE);
mApplicationContext, ExtensionTypes.TEMPERATURE_UNIT);
assertEquals(RegionalPreferencesFragment.TYPE_DEFAULT, unit);
assertEquals(RegionalPreferencesDataUtils.DEFAULT_VALUE, unit);
}
@Test
public void savePreference_saveCalendarIsDangi_success() {
RegionalPreferencesDataUtils.savePreference(
mApplicationContext,
RegionalPreferencesFragment.TYPE_CALENDAR,
ExtensionTypes.CALENDAR,
LocalePreferences.CalendarType.DANGI
);
String providerContent = Settings.System.getString(
@@ -103,12 +103,12 @@ public class RegionalPreferencesDataUtilsTest {
Locale locale = Locale.forLanguageTag(providerContent);
String result1 = locale.getUnicodeLocaleType(RegionalPreferencesFragment.TYPE_CALENDAR);
String result1 = locale.getUnicodeLocaleType(ExtensionTypes.CALENDAR);
assertEquals(LocalePreferences.CalendarType.DANGI, result1);
String result2 = Locale.getDefault(Locale.Category.FORMAT)
.getUnicodeLocaleType(RegionalPreferencesFragment.TYPE_CALENDAR);
.getUnicodeLocaleType(ExtensionTypes.CALENDAR);
assertEquals(LocalePreferences.CalendarType.DANGI, result2);
@@ -126,7 +126,7 @@ public class RegionalPreferencesDataUtilsTest {
@Test
public void temperatureUnitsConverter_inputDefault_resultIsDefaultString() {
String result = RegionalPreferencesDataUtils.temperatureUnitsConverter(mApplicationContext,
RegionalPreferencesFragment.TYPE_DEFAULT);
RegionalPreferencesDataUtils.DEFAULT_VALUE);
assertEquals(ResourcesUtils.getResourcesString(
mApplicationContext, "default_string_of_regional_preference"), result);
@@ -144,7 +144,7 @@ public class RegionalPreferencesDataUtilsTest {
@Test
public void dayConverter_inputDefault_resultIsDefaultString() {
String result = RegionalPreferencesDataUtils.dayConverter(mApplicationContext,
RegionalPreferencesFragment.TYPE_DEFAULT);
RegionalPreferencesDataUtils.DEFAULT_VALUE);
assertEquals(ResourcesUtils.getResourcesString(
mApplicationContext, "default_string_of_regional_preference"), result);
@@ -153,7 +153,7 @@ public class RegionalPreferencesDataUtilsTest {
@Test
public void calendarConverter_inputDefault_resultIsDefaultString() {
String result = RegionalPreferencesDataUtils.dayConverter(mApplicationContext,
RegionalPreferencesFragment.TYPE_DEFAULT);
RegionalPreferencesDataUtils.DEFAULT_VALUE);
assertEquals(ResourcesUtils.getResourcesString(
mApplicationContext, "default_string_of_regional_preference"), result);

View File

@@ -41,7 +41,7 @@ public class RegionalPreferencesFragmentTest {
@Test
@UiThreadTest
public void getMetricsCategory_typeIsCa_resultIsCalendarPreference() {
mFragment.mType = RegionalPreferencesFragment.TYPE_CALENDAR;
mFragment.mType = ExtensionTypes.CALENDAR;
int result = mFragment.getMetricsCategory();
@@ -51,7 +51,7 @@ public class RegionalPreferencesFragmentTest {
@Test
@UiThreadTest
public void getMetricsCategory_typeIsFw_resultIsFirstDayOfWeekPreference() {
mFragment.mType = RegionalPreferencesFragment.TYPE_FIRST_DAY_OF_WEEK;
mFragment.mType = ExtensionTypes.FIRST_DAY_OF_WEEK;
int result = mFragment.getMetricsCategory();
@@ -61,7 +61,7 @@ public class RegionalPreferencesFragmentTest {
@Test
@UiThreadTest
public void getMetricsCategory_typeIsMu_resultIsTemperaturePreference() {
mFragment.mType = RegionalPreferencesFragment.TYPE_TEMPERATURE;
mFragment.mType = ExtensionTypes.TEMPERATURE_UNIT;
int result = mFragment.getMetricsCategory();