1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.notification.modes;
18 
19 import android.app.Application;
20 import android.app.AutomaticZenRule;
21 import android.app.settings.SettingsEnums;
22 import android.content.Context;
23 
24 import com.android.settings.R;
25 import com.android.settingslib.applications.ApplicationsState;
26 import com.android.settingslib.core.AbstractPreferenceController;
27 
28 import java.util.ArrayList;
29 import java.util.List;
30 
31 public class ZenModeFragment extends ZenModeFragmentBase {
32 
33     @Override
getPreferenceScreenResId()34     protected int getPreferenceScreenResId() {
35         return R.xml.modes_rule_settings;
36     }
37 
38     @Override
createPreferenceControllers(Context context)39     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
40         List<AbstractPreferenceController> prefControllers = new ArrayList<>();
41         prefControllers.add(new ZenModeHeaderController(context, "header", this, mBackend));
42         prefControllers.add(new ZenModeButtonPreferenceController(context, "activate", mBackend));
43         prefControllers.add(new ZenModeActionsPreferenceController(context, "actions", mBackend));
44         prefControllers.add(new ZenModePeopleLinkPreferenceController(
45                 context, "zen_mode_people", mBackend));
46         prefControllers.add(new ZenModeAppsLinkPreferenceController(
47                 context, "zen_mode_apps", this,
48                 ApplicationsState.getInstance((Application) context.getApplicationContext()),
49                 mBackend));
50         prefControllers.add(new ZenModeOtherLinkPreferenceController(
51                 context, "zen_other_settings", mBackend));
52         prefControllers.add(new ZenModeDisplayLinkPreferenceController(
53                 context, "mode_display_settings", mBackend));
54         prefControllers.add(new ZenModeSetTriggerLinkPreferenceController(context,
55                 "zen_automatic_trigger_category", mBackend));
56         return prefControllers;
57     }
58 
59     @Override
onStart()60     public void onStart() {
61         super.onStart();
62 
63         // Set title for the entire screen
64         ZenMode mode = getMode();
65         AutomaticZenRule azr = getAZR();
66         if (mode == null || azr == null) {
67             return;
68         }
69         getActivity().setTitle(azr.getName());
70     }
71 
72     @Override
getMetricsCategory()73     public int getMetricsCategory() {
74         // TODO: b/332937635 - make this the correct metrics category
75         return SettingsEnums.NOTIFICATION_ZEN_MODE_AUTOMATION;
76     }
77 }
78