1 /*
2  * Copyright (C) 2020 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.zen;
18 
19 import android.app.Activity;
20 import android.app.Application;
21 import android.app.settings.SettingsEnums;
22 import android.content.Context;
23 
24 import androidx.fragment.app.Fragment;
25 import androidx.fragment.app.FragmentManager;
26 
27 import com.android.settings.R;
28 import com.android.settings.notification.NotificationBackend;
29 import com.android.settings.search.BaseSearchIndexProvider;
30 import com.android.settingslib.core.AbstractPreferenceController;
31 import com.android.settingslib.core.lifecycle.Lifecycle;
32 import com.android.settingslib.search.Indexable;
33 import com.android.settingslib.search.SearchIndexable;
34 
35 import java.util.ArrayList;
36 import java.util.List;
37 
38 @SearchIndexable
39 public class ZenModePeopleSettings extends ZenModeSettingsBase implements Indexable {
40 
41     @Override
createPreferenceControllers(Context context)42     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
43         final Activity activity = getActivity();
44         final Application app;
45         if (activity != null) {
46             app = activity.getApplication();
47         } else {
48             app = null;
49         }
50         return buildPreferenceControllers(
51                 context, getSettingsLifecycle(), app, this, getFragmentManager(),
52                 new NotificationBackend());
53     }
54 
buildPreferenceControllers(Context context, Lifecycle lifecycle, Application app, Fragment host, FragmentManager fragmentManager, NotificationBackend notificationBackend)55     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
56             Lifecycle lifecycle, Application app, Fragment host, FragmentManager fragmentManager,
57             NotificationBackend notificationBackend) {
58         List<AbstractPreferenceController> controllers = new ArrayList<>();
59         controllers.add(new ZenModeCallsPreferenceController(context, lifecycle,
60                 "zen_mode_people_calls"));
61         controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle,
62                 "zen_mode_people_messages"));
63         controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle,
64                 R.string.zen_mode_people_footer));
65         return controllers;
66     }
67 
68     @Override
getPreferenceScreenResId()69     protected int getPreferenceScreenResId() {
70         return R.xml.zen_mode_people_settings;
71     }
72 
73     @Override
getMetricsCategory()74     public int getMetricsCategory() {
75         return SettingsEnums.DND_PEOPLE;
76     }
77 
78     /**
79      * For Search.
80      */
81     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
82             new BaseSearchIndexProvider(R.xml.zen_mode_people_settings) {
83 
84                 @Override
85                 public List<AbstractPreferenceController> createPreferenceControllers(
86                         Context context) {
87                     return buildPreferenceControllers(context, null, null, null,
88                             null, null);
89                 }
90             };
91 }
92