Updated toggles in Date and time settings page
Design doc: go/dd-android-settings-time-2024 Changes: - toggling off "automatic time zone" now sets "use location" off and makes it unmodifiable - removing "use locale default" for time format Bug: 296835792 Test: on-device and atest Flag: com.android.settings.flags.revamp_toggles Change-Id: I31744f104fed06ee9980a6a0160501325175a02d
This commit is contained in:
@@ -32,6 +32,7 @@ import androidx.preference.Preference;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settings.flags.Flags;
|
||||
|
||||
public class AutoTimeZonePreferenceController extends TogglePreferenceController {
|
||||
|
||||
@@ -46,7 +47,7 @@ public class AutoTimeZonePreferenceController extends TogglePreferenceController
|
||||
// setTimeAndDateCallback() isn't called, e.g. for slices and other cases where the
|
||||
// controller is instantiated outside of the context of the real Date & Time settings
|
||||
// screen.
|
||||
mCallback = (c) -> {};
|
||||
mCallback = (c) -> {};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,10 +104,25 @@ public class AutoTimeZonePreferenceController extends TogglePreferenceController
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder()
|
||||
.setAutoDetectionEnabled(isChecked)
|
||||
.build();
|
||||
boolean result = mTimeManager.updateTimeZoneConfiguration(configuration);
|
||||
TimeZoneConfiguration.Builder configuration = new TimeZoneConfiguration.Builder()
|
||||
.setAutoDetectionEnabled(isChecked);
|
||||
|
||||
if (Flags.revampToggles()) {
|
||||
// "Use location for time zone" is only used if "Automatic time zone" is enabled. If
|
||||
// the user toggles off automatic time zone, set the toggle off and disable the toggle.
|
||||
int geoDetectionCapability = mTimeManager
|
||||
.getTimeZoneCapabilitiesAndConfig()
|
||||
.getCapabilities()
|
||||
.getConfigureGeoDetectionEnabledCapability();
|
||||
|
||||
if (!isChecked
|
||||
&& (geoDetectionCapability == CAPABILITY_NOT_APPLICABLE
|
||||
|| geoDetectionCapability == CAPABILITY_POSSESSED)) {
|
||||
configuration.setGeoDetectionEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
boolean result = mTimeManager.updateTimeZoneConfiguration(configuration.build());
|
||||
|
||||
mCallback.updateTimeAndDateDisplay(mContext);
|
||||
return result;
|
||||
@@ -138,8 +154,10 @@ public class AutoTimeZonePreferenceController extends TogglePreferenceController
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isEnabled() {
|
||||
TimeZoneConfiguration config = getTimeZoneCapabilitiesAndConfig().getConfiguration();
|
||||
return config.isAutoDetectionEnabled();
|
||||
return mTimeManager
|
||||
.getTimeZoneCapabilitiesAndConfig()
|
||||
.getConfiguration()
|
||||
.isAutoDetectionEnabled();
|
||||
}
|
||||
|
||||
private TimeZoneCapabilitiesAndConfig getTimeZoneCapabilitiesAndConfig() {
|
||||
|
@@ -23,6 +23,7 @@ import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
@@ -49,6 +50,9 @@ public class DateTimeSettings extends DashboardFragment implements
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
if (Flags.revampToggles()) {
|
||||
return R.xml.date_time_prefs_revamped;
|
||||
}
|
||||
return R.xml.date_time_prefs;
|
||||
}
|
||||
|
||||
@@ -119,5 +123,6 @@ public class DateTimeSettings extends DashboardFragment implements
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.date_time_prefs);
|
||||
new BaseSearchIndexProvider(
|
||||
Flags.revampToggles() ? R.xml.date_time_prefs_revamped : R.xml.date_time_prefs);
|
||||
}
|
||||
|
@@ -32,6 +32,7 @@ import androidx.preference.PreferenceScreen;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
@@ -64,8 +65,10 @@ public class LocationTimeZoneDetectionPreferenceController
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
// forceRefresh set to true as the location toggle may have been turned off by switching off
|
||||
// automatic time zone
|
||||
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
|
||||
getTimeZoneCapabilitiesAndConfig(/*forceRefresh=*/false);
|
||||
getTimeZoneCapabilitiesAndConfig(/*forceRefresh=*/ Flags.revampToggles());
|
||||
TimeZoneConfiguration configuration = capabilitiesAndConfig.getConfiguration();
|
||||
return configuration.isGeoDetectionEnabled();
|
||||
}
|
||||
@@ -73,7 +76,7 @@ public class LocationTimeZoneDetectionPreferenceController
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
TimeZoneCapabilitiesAndConfig timeZoneCapabilitiesAndConfig =
|
||||
getTimeZoneCapabilitiesAndConfig(/*forceRefresh=*/false);
|
||||
getTimeZoneCapabilitiesAndConfig(/*forceRefresh=*/ false);
|
||||
boolean isLocationEnabled =
|
||||
timeZoneCapabilitiesAndConfig.getCapabilities().isUseLocationEnabled();
|
||||
if (isChecked && !isLocationEnabled) {
|
||||
@@ -130,17 +133,30 @@ public class LocationTimeZoneDetectionPreferenceController
|
||||
getTimeZoneCapabilitiesAndConfig(/* forceRefresh= */ false).getCapabilities();
|
||||
int capability = timeZoneCapabilities.getConfigureGeoDetectionEnabledCapability();
|
||||
|
||||
// The preference only has two states: present and not present. The preference is never
|
||||
// present but disabled.
|
||||
// The preference can be present and enabled, present and disabled or not present.
|
||||
if (capability == CAPABILITY_NOT_SUPPORTED || capability == CAPABILITY_NOT_ALLOWED) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
} else if (capability == CAPABILITY_NOT_APPLICABLE || capability == CAPABILITY_POSSESSED) {
|
||||
return AVAILABLE;
|
||||
if (Flags.revampToggles()) {
|
||||
return isAutoTimeZoneEnabled() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
|
||||
} else {
|
||||
return AVAILABLE;
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("Unknown capability=" + capability);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
if (Flags.revampToggles()) {
|
||||
// enable / disable the toggle based on automatic time zone being enabled or not
|
||||
preference.setEnabled(isAutoTimeZoneEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
TimeZoneCapabilitiesAndConfig timeZoneCapabilitiesAndConfig =
|
||||
@@ -212,4 +228,13 @@ public class LocationTimeZoneDetectionPreferenceController
|
||||
}
|
||||
return mTimeZoneCapabilitiesAndConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the user can select this preference or not, as it is a sub toggle of
|
||||
* automatic time zone.
|
||||
*/
|
||||
private boolean isAutoTimeZoneEnabled() {
|
||||
return mTimeManager.getTimeZoneCapabilitiesAndConfig().getConfiguration()
|
||||
.isAutoDetectionEnabled();
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settings.flags.Flags;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
@@ -72,8 +73,10 @@ public class TimeFormatPreferenceController extends TogglePreferenceController {
|
||||
if (mIsFromSUW) {
|
||||
return DISABLED_DEPENDENT_SETTING;
|
||||
}
|
||||
if (AutoTimeFormatPreferenceController.isAutoTimeFormatSelection(mContext)) {
|
||||
return DISABLED_DEPENDENT_SETTING;
|
||||
if (!Flags.revampToggles()) {
|
||||
if (AutoTimeFormatPreferenceController.isAutoTimeFormatSelection(mContext)) {
|
||||
return DISABLED_DEPENDENT_SETTING;
|
||||
}
|
||||
}
|
||||
return AVAILABLE;
|
||||
}
|
||||
@@ -130,7 +133,7 @@ public class TimeFormatPreferenceController extends TogglePreferenceController {
|
||||
timeFormatPreference = Intent.EXTRA_TIME_PREF_VALUE_USE_LOCALE_DEFAULT;
|
||||
} else {
|
||||
timeFormatPreference = is24Hour ? Intent.EXTRA_TIME_PREF_VALUE_USE_24_HOUR
|
||||
: Intent.EXTRA_TIME_PREF_VALUE_USE_12_HOUR;
|
||||
: Intent.EXTRA_TIME_PREF_VALUE_USE_12_HOUR;
|
||||
}
|
||||
timeChanged.putExtra(Intent.EXTRA_TIME_PREF_24_HOUR_FORMAT, timeFormatPreference);
|
||||
context.sendBroadcast(timeChanged);
|
||||
@@ -138,7 +141,7 @@ public class TimeFormatPreferenceController extends TogglePreferenceController {
|
||||
|
||||
static void set24Hour(Context context, Boolean is24Hour) {
|
||||
String value = is24Hour == null ? null :
|
||||
is24Hour ? HOURS_24 : HOURS_12;
|
||||
is24Hour ? HOURS_24 : HOURS_12;
|
||||
Settings.System.putString(context.getContentResolver(),
|
||||
Settings.System.TIME_12_24, value);
|
||||
}
|
||||
|
Reference in New Issue
Block a user