Merge "[Regional Preference] Create each page for regional preferences"
This commit is contained in:
@@ -16,11 +16,17 @@
|
||||
|
||||
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;
|
||||
|
||||
@@ -28,6 +34,7 @@ import java.util.Locale;
|
||||
* A controller for the entry of Calendar types' page
|
||||
*/
|
||||
public class CalendarTypeController extends BasePreferenceController {
|
||||
private static final String TAG = CalendarTypeController.class.getSimpleName();
|
||||
public CalendarTypeController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
@@ -60,7 +67,26 @@ public class CalendarTypeController extends BasePreferenceController {
|
||||
if (result.isEmpty()) {
|
||||
result = LocalePreferences.getCalendarType(false);
|
||||
}
|
||||
return result.isEmpty()
|
||||
? mContext.getString(R.string.default_string_of_regional_preference) : result;
|
||||
|
||||
String inputStr = result.isEmpty() ? RegionalPreferencesFragment.TYPE_DEFAULT : 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;
|
||||
}
|
||||
}
|
||||
|
@@ -16,16 +16,25 @@
|
||||
|
||||
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;
|
||||
|
||||
/** A controller for the entry of First Day of Week's page */
|
||||
public class FirstDayOfWeekController extends BasePreferenceController {
|
||||
private static final String TAG = FirstDayOfWeekController.class.getSimpleName();
|
||||
|
||||
public FirstDayOfWeekController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
@@ -59,6 +68,25 @@ public class FirstDayOfWeekController extends BasePreferenceController {
|
||||
result = LocalePreferences.getFirstDayOfWeek(false);
|
||||
}
|
||||
return result.isEmpty()
|
||||
? mContext.getString(R.string.default_string_of_regional_preference) : result;
|
||||
? 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;
|
||||
}
|
||||
}
|
||||
|
@@ -16,18 +16,26 @@
|
||||
|
||||
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 androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/** 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) {
|
||||
@@ -47,7 +55,8 @@ public class NumberingSystemController extends BasePreferenceController {
|
||||
*/
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
// Hide this , and waiting for next implementation.
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,4 +82,22 @@ public class NumberingSystemController extends BasePreferenceController {
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* 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.content.Context;
|
||||
import android.icu.util.ULocale;
|
||||
import android.os.LocaleList;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.app.LocalePicker;
|
||||
import com.android.settings.R;
|
||||
|
||||
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 String getDefaultUnicodeExtensionData(Context contxt, String type) {
|
||||
// 1. Check cache data in Settings provider.
|
||||
String record = Settings.System.getString(
|
||||
contxt.getContentResolver(), Settings.System.LOCALE_PREFERENCES);
|
||||
String result = "";
|
||||
|
||||
if (!TextUtils.isEmpty(record)) {
|
||||
result = Locale.forLanguageTag(record).getUnicodeLocaleType(type);
|
||||
}
|
||||
// 2. Check cache data in default Locale(ICU lib).
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private static void saveToSettingsProvider(Context context, String type, String value) {
|
||||
String record = Settings.System.getString(
|
||||
context.getContentResolver(), Settings.System.LOCALE_PREFERENCES);
|
||||
|
||||
record = record == null ? "" : record;
|
||||
|
||||
Settings.System.putString(
|
||||
context.getContentResolver(),
|
||||
Settings.System.LOCALE_PREFERENCES,
|
||||
addUnicodeKeywordToLocale(record, type, value).toLanguageTag());
|
||||
}
|
||||
|
||||
private static void saveToSystem(String type, String value) {
|
||||
LocaleList localeList = LocaleList.getDefault();
|
||||
Locale[] resultLocales = new Locale[localeList.size()];
|
||||
for (int i = 0; i < localeList.size(); i++) {
|
||||
resultLocales[i] = addUnicodeKeywordToLocale(localeList.get(i), type, value);
|
||||
}
|
||||
LocalePicker.updateLocales(new LocaleList(resultLocales));
|
||||
}
|
||||
|
||||
private static Locale addUnicodeKeywordToLocale(Locale locale, String type, String value) {
|
||||
return new Locale.Builder()
|
||||
.setLocale(locale)
|
||||
.setUnicodeLocaleKeyword(type, value)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static Locale addUnicodeKeywordToLocale(String languageTag, String type, String value) {
|
||||
return addUnicodeKeywordToLocale(Locale.forLanguageTag(languageTag), type, value);
|
||||
}
|
||||
|
||||
static String calendarConverter(Context context, String calendarType) {
|
||||
if (calendarType.equals(RegionalPreferencesFragment.TYPE_DEFAULT)) {
|
||||
return context.getString(R.string.default_string_of_regional_preference);
|
||||
}
|
||||
|
||||
Locale locale = new Locale.Builder()
|
||||
.setUnicodeLocaleKeyword(RegionalPreferencesFragment.TYPE_CALENDAR, calendarType)
|
||||
.build();
|
||||
return ULocale.getDisplayKeywordValue(locale.toLanguageTag(), KEYWORD_OF_CALENDAR,
|
||||
ULocale.forLocale(Locale.getDefault(Locale.Category.FORMAT)));
|
||||
}
|
||||
|
||||
static String temperatureUnitsConverter(Context context, String unit) {
|
||||
switch (unit) {
|
||||
case LocalePreferences.TemperatureUnit.CELSIUS:
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
static String dayConverter(Context context, String day) {
|
||||
switch (day) {
|
||||
case LocalePreferences.FirstDayOfWeek.MONDAY:
|
||||
return context.getString(R.string.monday_first_day_of_week);
|
||||
case LocalePreferences.FirstDayOfWeek.TUESDAY:
|
||||
return context.getString(R.string.tuesday_first_day_of_week);
|
||||
case LocalePreferences.FirstDayOfWeek.WEDNESDAY:
|
||||
return context.getString(R.string.wednesday_first_day_of_week);
|
||||
case LocalePreferences.FirstDayOfWeek.THURSDAY:
|
||||
return context.getString(R.string.thursday_first_day_of_week);
|
||||
case LocalePreferences.FirstDayOfWeek.FRIDAY:
|
||||
return context.getString(R.string.friday_first_day_of_week);
|
||||
case LocalePreferences.FirstDayOfWeek.SATURDAY:
|
||||
return context.getString(R.string.saturday_first_day_of_week);
|
||||
case LocalePreferences.FirstDayOfWeek.SUNDAY:
|
||||
return context.getString(R.string.sunday_first_day_of_week);
|
||||
default:
|
||||
return context.getString(R.string.default_string_of_regional_preference);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
/** A fragment to include each kind of regional preferences. */
|
||||
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
|
||||
String mType = "";
|
||||
|
||||
private String[] initializeUIdata(String type) {
|
||||
switch(type) {
|
||||
case TYPE_TEMPERATURE:
|
||||
mTitle = getPrefContext().getString(R.string.temperature_preferences_title);
|
||||
return getPrefContext().getResources().getStringArray(R.array.temperature_units);
|
||||
case TYPE_CALENDAR:
|
||||
mTitle = getPrefContext().getString(R.string.calendar_preferences_title);
|
||||
return getPrefContext().getResources().getStringArray(R.array.calendar_type);
|
||||
case TYPE_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];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(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);
|
||||
RegionalPreferencesDataUtils.savePreference(
|
||||
getPrefContext(),
|
||||
mType,
|
||||
preference.getKey().equals(TYPE_DEFAULT) ? null : preference.getKey());
|
||||
continue;
|
||||
}
|
||||
pref.setTickEnable(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
Bundle bundle = getArguments();
|
||||
String type = bundle.getString(TYPE_OF_REGIONAL_PREFERENCE, "");
|
||||
if (type.isEmpty()) {
|
||||
Log.w(TAG, "There is no type name.");
|
||||
finish();
|
||||
}
|
||||
mType = type;
|
||||
addPreferencesFromResource(R.xml.regional_preference_content_page);
|
||||
mPreferenceScreen = getPreferenceScreen();
|
||||
}
|
||||
|
||||
@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)) {
|
||||
pref.setTitle(RegionalPreferencesDataUtils.dayConverter(
|
||||
getPrefContext(), item));
|
||||
} else if (mType.equals(TYPE_TEMPERATURE)) {
|
||||
pref.setTitle(RegionalPreferencesDataUtils.temperatureUnitsConverter(
|
||||
getPrefContext(), item));
|
||||
} else if (mType.equals(TYPE_CALENDAR)) {
|
||||
pref.setTitle(RegionalPreferencesDataUtils.calendarConverter(
|
||||
getPrefContext(), item));
|
||||
} else {
|
||||
Log.d(TAG, "Finish this page due to no suitable type.");
|
||||
finish();
|
||||
}
|
||||
|
||||
String value = RegionalPreferencesDataUtils.getDefaultUnicodeExtensionData(
|
||||
getPrefContext(), mType);
|
||||
pref.setKey(item);
|
||||
pref.setTickEnable(!value.isEmpty() && item.equals(value));
|
||||
mPreferenceScreen.addPreference(pref);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
getActivity().setTitle(mTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
switch(mType) {
|
||||
case TYPE_CALENDAR:
|
||||
return SettingsEnums.CALENDAR_PREFERENCE;
|
||||
case TYPE_FIRST_DAY_OF_WEEK:
|
||||
return SettingsEnums.FIRST_DAY_OF_WEEK_PREFERENCE;
|
||||
default:
|
||||
return SettingsEnums.TEMPERATURE_PREFERENCE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -16,16 +16,24 @@
|
||||
|
||||
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;
|
||||
|
||||
/** A controller for the entry of Temperature units' page */
|
||||
public class TemperatureUnitController extends BasePreferenceController {
|
||||
private static final String TAG = TemperatureUnitController.class.getSimpleName();
|
||||
public TemperatureUnitController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
@@ -58,7 +66,26 @@ public class TemperatureUnitController extends BasePreferenceController {
|
||||
if (result.isEmpty()) {
|
||||
result = LocalePreferences.getTemperatureUnit(false);
|
||||
}
|
||||
|
||||
return result.isEmpty()
|
||||
? mContext.getString(R.string.default_string_of_regional_preference) : result;
|
||||
? 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;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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 android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.widget.TwoTargetPreference;
|
||||
|
||||
/** A preference with tick button */
|
||||
public class TickButtonPreference extends TwoTargetPreference {
|
||||
private static final String TAG = TickButtonPreference.class.getSimpleName();
|
||||
private boolean mIsTickEnabled;
|
||||
private View mWidgetFrame;
|
||||
private View mDivider;
|
||||
|
||||
public TickButtonPreference(Context context) {
|
||||
super(context, null);
|
||||
}
|
||||
|
||||
/** Set this preference to be selected. */
|
||||
public void setTickEnable(boolean isEnable) {
|
||||
mIsTickEnabled = isEnable;
|
||||
if (mWidgetFrame != null) {
|
||||
mWidgetFrame.setVisibility(isEnable ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
/** Check if this preference is selected. */
|
||||
public boolean isTickEnabled() {
|
||||
return mIsTickEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
mDivider = holder.findViewById(R.id.two_target_divider);
|
||||
mWidgetFrame = holder.findViewById(android.R.id.widget_frame);
|
||||
if (mDivider != null) {
|
||||
mDivider.setVisibility(View.GONE);
|
||||
}
|
||||
if (mWidgetFrame != null) {
|
||||
mWidgetFrame.setVisibility(mIsTickEnabled ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSecondTargetResId() {
|
||||
super.getSecondTargetResId();
|
||||
return R.layout.preference_widget_tick;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user