Merge changes from topic "regional_preference_metrics" into udc-dev
* changes: [Regional Pref] Remove Calendar controller and related Fragement [Regional Pref] 1. Add metrics for user changes the First day of week 2. Refactor to Settings design [Regional Pref] 1. Add metrics for user changes the Temperature unit 2. Refactor to Settings design
This commit is contained in:
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.icu.util.ULocale;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.testutils.ResourcesUtils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class CalendarTypeControllerTest {
|
||||
private Context mApplicationContext;
|
||||
private CalendarTypeController mController;
|
||||
private String mCacheProviderContent = "";
|
||||
private Locale mCacheLocale;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mApplicationContext = ApplicationProvider.getApplicationContext();
|
||||
mController = new CalendarTypeController(mApplicationContext, "key");
|
||||
mCacheProviderContent = Settings.System.getString(
|
||||
mApplicationContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES);
|
||||
mCacheLocale = Locale.getDefault(Locale.Category.FORMAT);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
RegionalPreferenceTestUtils.setSettingsProviderContent(
|
||||
mApplicationContext, mCacheProviderContent);
|
||||
Locale.setDefault(mCacheLocale);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_hasProviderValue_resultIsChineseCalendar() {
|
||||
RegionalPreferenceTestUtils.setSettingsProviderContent(
|
||||
mApplicationContext, "und-u-ca-chinese");
|
||||
|
||||
String summary = mController.getSummary().toString();
|
||||
|
||||
assertEquals(getDisplayKeywordValue(LocalePreferences.CalendarType.CHINESE), summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_hasProviderValue_resultIsDangiCalendar() {
|
||||
RegionalPreferenceTestUtils.setSettingsProviderContent(
|
||||
mApplicationContext, "und-u-ca-dangi");
|
||||
|
||||
String summary = mController.getSummary().toString();
|
||||
|
||||
assertEquals(getDisplayKeywordValue(LocalePreferences.CalendarType.DANGI), summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_noProviderValueButHasDefaultLocaleWithSubtag_resultIsChineseCalendar() {
|
||||
RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, "");
|
||||
Locale.setDefault(Locale.forLanguageTag("en-US-u-ca-chinese"));
|
||||
|
||||
String summary = mController.getSummary().toString();
|
||||
|
||||
assertEquals(getDisplayKeywordValue(LocalePreferences.CalendarType.CHINESE), summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_noProviderValueAndDefaultLocaleWithoutSubtag_resultIsEmpty() {
|
||||
RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, "");
|
||||
Locale.setDefault(Locale.forLanguageTag("en-US"));
|
||||
|
||||
String summary = mController.getSummary().toString();
|
||||
|
||||
assertEquals(ResourcesUtils.getResourcesString(
|
||||
mApplicationContext, "default_string_of_regional_preference"), summary);
|
||||
}
|
||||
|
||||
private static String getDisplayKeywordValue(String value) {
|
||||
String languageTag = new Locale.Builder()
|
||||
.setUnicodeLocaleKeyword(
|
||||
ExtensionTypes.CALENDAR, value).build().toLanguageTag();
|
||||
return ULocale.getDisplayKeywordValue(
|
||||
languageTag,
|
||||
RegionalPreferencesDataUtils.DISPLAY_KEYWORD_OF_CALENDAR,
|
||||
ULocale.forLocale(Locale.getDefault(Locale.Category.FORMAT)));
|
||||
}
|
||||
}
|
@@ -0,0 +1,124 @@
|
||||
/**
|
||||
* 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.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.LocaleList;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.internal.app.LocalePicker;
|
||||
import com.android.settings.widget.TickButtonPreference;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class FirstDayOfWeekItemListControllerTest {
|
||||
|
||||
private static final String KEY_PREFERENCE_CATEGORY_FIRST_DAY_OF_WEEK_ITEM =
|
||||
"first_day_of_week_item_category";
|
||||
private static final String KEY_PREFERENCE_FIRST_DAY_OF_WEEK_ITEM =
|
||||
"first_day_of_week_item_list";
|
||||
|
||||
private Context mContext;
|
||||
private PreferenceManager mPreferenceManager;
|
||||
private PreferenceCategory mPreferenceCategory;
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
private FirstDayOfWeekItemListController mController;
|
||||
private LocaleList mCacheLocaleList;
|
||||
private Locale mCacheLocale;
|
||||
private String mCacheProviderContent = "";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
mPreferenceManager = new PreferenceManager(mContext);
|
||||
mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
|
||||
mPreferenceCategory = new PreferenceCategory(mContext);
|
||||
mPreferenceCategory.setKey(KEY_PREFERENCE_CATEGORY_FIRST_DAY_OF_WEEK_ITEM);
|
||||
mPreferenceScreen.addPreference(mPreferenceCategory);
|
||||
mController = new FirstDayOfWeekItemListController(mContext,
|
||||
KEY_PREFERENCE_FIRST_DAY_OF_WEEK_ITEM);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mCacheProviderContent = Settings.System.getString(
|
||||
mContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES);
|
||||
mCacheLocale = Locale.getDefault(Locale.Category.FORMAT);
|
||||
mCacheLocaleList = LocaleList.getDefault();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
RegionalPreferenceTestUtils.setSettingsProviderContent(
|
||||
mContext, mCacheProviderContent);
|
||||
Locale.setDefault(mCacheLocale);
|
||||
LocalePicker.updateLocales(mCacheLocaleList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_setSelectPreferredFirstDayOfWeekIsDefault() {
|
||||
TickButtonPreference pref = (TickButtonPreference) mPreferenceCategory.getPreference(0);
|
||||
pref.performClick();
|
||||
String record = Settings.System.getString(
|
||||
mContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES);
|
||||
|
||||
assertThat(pref.getKey()).isEqualTo("default");
|
||||
assertThat(record).contains("default");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_setSelectPreferredFirstDayOfWeekIsSunday() {
|
||||
TickButtonPreference pref = (TickButtonPreference) mPreferenceCategory.getPreference(1);
|
||||
pref.performClick();
|
||||
String record = Settings.System.getString(
|
||||
mContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES);
|
||||
|
||||
assertThat(pref.getKey()).isEqualTo("sun");
|
||||
assertThat(record).contains("sun");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_setSelectPreferredFirstDayOfWeekIsMonday() {
|
||||
TickButtonPreference pref = (TickButtonPreference) mPreferenceCategory.getPreference(2);
|
||||
pref.performClick();
|
||||
String record = Settings.System.getString(
|
||||
mContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES);
|
||||
|
||||
assertThat(pref.getKey()).isEqualTo("mon");
|
||||
assertThat(record).contains("mon");
|
||||
}
|
||||
}
|
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* 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.os.Looper;
|
||||
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RegionalPreferencesFragmentTest {
|
||||
private RegionalPreferencesFragment mFragment;
|
||||
|
||||
@Before
|
||||
@UiThreadTest
|
||||
public void setUp() throws Exception {
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
mFragment = new RegionalPreferencesFragment();
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getMetricsCategory_typeIsCa_resultIsCalendarPreference() {
|
||||
mFragment.mType = ExtensionTypes.CALENDAR;
|
||||
|
||||
int result = mFragment.getMetricsCategory();
|
||||
|
||||
assertEquals(SettingsEnums.CALENDAR_PREFERENCE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getMetricsCategory_typeIsFw_resultIsFirstDayOfWeekPreference() {
|
||||
mFragment.mType = ExtensionTypes.FIRST_DAY_OF_WEEK;
|
||||
|
||||
int result = mFragment.getMetricsCategory();
|
||||
|
||||
assertEquals(SettingsEnums.FIRST_DAY_OF_WEEK_PREFERENCE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void getMetricsCategory_typeIsMu_resultIsTemperaturePreference() {
|
||||
mFragment.mType = ExtensionTypes.TEMPERATURE_UNIT;
|
||||
|
||||
int result = mFragment.getMetricsCategory();
|
||||
|
||||
assertEquals(SettingsEnums.TEMPERATURE_PREFERENCE, result);
|
||||
}
|
||||
}
|
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* 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.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.LocaleList;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.internal.app.LocalePicker;
|
||||
import com.android.settings.widget.TickButtonPreference;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class TemperatureUnitListControllerTest {
|
||||
|
||||
private static final String KEY_PREFERENCE_CATEGORY_TEMPERATURE_UNIT =
|
||||
"temperature_unit_category";
|
||||
private static final String KEY_PREFERENCE_TEMPERATURE_UNIT = "temperature_unit_list";
|
||||
|
||||
private Context mContext;
|
||||
private PreferenceManager mPreferenceManager;
|
||||
private PreferenceCategory mPreferenceCategory;
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
private TemperatureUnitListController mController;
|
||||
private LocaleList mCacheLocaleList;
|
||||
private Locale mCacheLocale;
|
||||
private String mCacheProviderContent = "";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
mPreferenceManager = new PreferenceManager(mContext);
|
||||
mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
|
||||
mPreferenceCategory = new PreferenceCategory(mContext);
|
||||
mPreferenceCategory.setKey(KEY_PREFERENCE_CATEGORY_TEMPERATURE_UNIT);
|
||||
mPreferenceScreen.addPreference(mPreferenceCategory);
|
||||
mController = new TemperatureUnitListController(mContext, KEY_PREFERENCE_TEMPERATURE_UNIT);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
mCacheProviderContent = Settings.System.getString(
|
||||
mContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES);
|
||||
mCacheLocale = Locale.getDefault(Locale.Category.FORMAT);
|
||||
mCacheLocaleList = LocaleList.getDefault();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
RegionalPreferenceTestUtils.setSettingsProviderContent(
|
||||
mContext, mCacheProviderContent);
|
||||
Locale.setDefault(mCacheLocale);
|
||||
LocalePicker.updateLocales(mCacheLocaleList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_setSelectPreferredTemperatureUnitIsDefault() {
|
||||
TickButtonPreference pref = (TickButtonPreference) mPreferenceCategory.getPreference(0);
|
||||
pref.performClick();
|
||||
String record = Settings.System.getString(
|
||||
mContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES);
|
||||
|
||||
assertThat(pref.getKey()).isEqualTo("default");
|
||||
assertThat(record).contains("default");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_setSelectPreferredTemperatureUnitIsCelsius() {
|
||||
TickButtonPreference pref = (TickButtonPreference) mPreferenceCategory.getPreference(1);
|
||||
pref.performClick();
|
||||
String record = Settings.System.getString(
|
||||
mContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES);
|
||||
|
||||
assertThat(pref.getKey()).isEqualTo("celsius");
|
||||
assertThat(record).contains("celsius");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_setSelectPreferredTemperatureUnitIsFahrenhe() {
|
||||
TickButtonPreference pref = (TickButtonPreference) mPreferenceCategory.getPreference(2);
|
||||
pref.performClick();
|
||||
String record = Settings.System.getString(
|
||||
mContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES);
|
||||
|
||||
assertThat(pref.getKey()).isEqualTo("fahrenhe");
|
||||
assertThat(record).contains("fahrenhe");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user