• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.settings.SettingsEnums;
20 import android.content.Context;
21 import android.provider.SearchIndexableResource;
22 
23 import com.android.settings.R;
24 import com.android.settings.search.BaseSearchIndexProvider;
25 import com.android.settingslib.core.AbstractPreferenceController;
26 import com.android.settingslib.core.lifecycle.Lifecycle;
27 import com.android.settingslib.search.SearchIndexable;
28 
29 import java.util.ArrayList;
30 import java.util.List;
31 
32 /**
33  * DND Messages Settings page to determine which priority senders can bypass DND.
34  * "Messages" include SMS, MMS, and messaging apps.
35  */
36 @SearchIndexable
37 public class ZenModeMessagesSettings extends ZenModeSettingsBase {
38 
39     @Override
createPreferenceControllers(Context context)40     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
41         return buildPreferenceControllers(context, getSettingsLifecycle());
42     }
43 
buildPreferenceControllers(Context context, Lifecycle lifecycle)44     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
45             Lifecycle lifecycle) {
46         List<AbstractPreferenceController> controllers = new ArrayList<>();
47         controllers.add(new ZenModeSendersImagePreferenceController(context,
48                 "zen_mode_messages_image", lifecycle, true));
49         controllers.add(new ZenModePrioritySendersPreferenceController(context,
50                 "zen_mode_settings_category_messages", lifecycle, true));
51         controllers.add(new ZenModeBehaviorFooterPreferenceController(
52                 context, lifecycle, R.string.zen_mode_messages_footer));
53         return controllers;
54     }
55 
56     @Override
getPreferenceScreenResId()57     protected int getPreferenceScreenResId() {
58         return R.xml.zen_mode_messages_settings;
59     }
60 
61     @Override
getMetricsCategory()62     public int getMetricsCategory() {
63         return SettingsEnums.DND_MESSAGES;
64     }
65 
66     /**
67      * For Search.
68      */
69     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
70             new BaseSearchIndexProvider() {
71         @Override
72         public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
73                 boolean enabled) {
74             final ArrayList<SearchIndexableResource> result = new ArrayList<>();
75 
76             final SearchIndexableResource sir = new SearchIndexableResource(context);
77             sir.xmlResId = R.xml.zen_mode_messages_settings;
78             result.add(sir);
79             return result;
80         }
81 
82         @Override
83         public List<AbstractPreferenceController> createPreferenceControllers(
84                 Context context) {
85             return buildPreferenceControllers(context, null);
86         }
87     };
88 }
89