Migrate "duration for quick settings" to new modes page.

This mostly continues to use the existing dialogs in settingslib (ZenDurationDialog, SettingsEnableZenModeDialog) and creates a controller to read from the settings value.

Also updates the "turn on / turn off" button to respect the preferred duration.

Flag: android.app.modes_ui
Bug: 343444249
Test: ZenModeButtonPreferenceControllerTest, ManualDurationPreferenceControllerTest
Change-Id: I2fd49a79d9a5807fefdd7ec310a6cc60d70f9bb1
This commit is contained in:
Yuri Lin
2024-06-20 17:26:23 -04:00
parent 5653acd533
commit c1a4abbc51
8 changed files with 473 additions and 6 deletions

View File

@@ -35,7 +35,6 @@ import java.util.ArrayList;
import java.util.List;
public class ZenModeFragment extends ZenModeFragmentBase {
// for mode deletion menu
private static final int DELETE_MODE = 1;
@@ -48,7 +47,8 @@ public class ZenModeFragment extends ZenModeFragmentBase {
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
List<AbstractPreferenceController> prefControllers = new ArrayList<>();
prefControllers.add(new ZenModeHeaderController(context, "header", this, mBackend));
prefControllers.add(new ZenModeButtonPreferenceController(context, "activate", mBackend));
prefControllers.add(
new ZenModeButtonPreferenceController(context, "activate", this, mBackend));
prefControllers.add(new ZenModeActionsPreferenceController(context, "actions", mBackend));
prefControllers.add(new ZenModePeopleLinkPreferenceController(
context, "zen_mode_people", mBackend, mHelperBackend));
@@ -64,9 +64,19 @@ public class ZenModeFragment extends ZenModeFragmentBase {
"zen_automatic_trigger_category", this, mBackend));
prefControllers.add(new InterruptionFilterPreferenceController(
context, "allow_filtering", mBackend));
prefControllers.add(new ManualDurationPreferenceController(
context, "mode_manual_duration", this, mBackend));
return prefControllers;
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
// allow duration preference controller to listen for settings changes
use(ManualDurationPreferenceController.class).registerSettingsObserver();
}
@Override
public void onStart() {
super.onStart();
@@ -78,6 +88,12 @@ public class ZenModeFragment extends ZenModeFragmentBase {
}
}
@Override
public void onDetach() {
use(ManualDurationPreferenceController.class).unregisterSettingsObserver();
super.onDetach();
}
@Override
public int getMetricsCategory() {
// TODO: b/332937635 - make this the correct metrics category