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:
Geoffrey Boullanger
2024-10-11 16:02:59 +00:00
parent f7d9c87ac7
commit b2dd2e3203
10 changed files with 282 additions and 21 deletions

View File

@@ -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();
}
}