1 /*
2  * Copyright (C) 2018 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.service.notification.ZenPolicy;
22 
23 import androidx.preference.Preference;
24 import androidx.preference.PreferenceScreen;
25 
26 import com.android.settings.R;
27 import com.android.settingslib.core.AbstractPreferenceController;
28 import com.android.settingslib.widget.FooterPreference;
29 
30 import java.util.ArrayList;
31 import java.util.List;
32 
33 public class ZenCustomRuleMessagesSettings extends ZenCustomRuleSettingsBase {
34     private static final String MESSAGES_KEY = "zen_mode_messages";
35     private static final String STARRED_CONTACTS_KEY = "zen_mode_starred_contacts_messages";
36     private static final String PREFERENCE_CATEGORY_KEY = "zen_mode_settings_category_messages";
37 
38     @Override
getPreferenceScreenResId()39     protected int getPreferenceScreenResId() {
40         return com.android.settings.R.xml.zen_mode_custom_rule_messages_settings;
41     }
42 
43     @Override
getMetricsCategory()44     public int getMetricsCategory() {
45         return SettingsEnums.ZEN_CUSTOM_RULE_MESSAGES;
46     }
47 
48     @Override
createPreferenceControllers(Context context)49     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
50         mControllers = new ArrayList<>();
51         mControllers.add(new ZenRuleMessagesPreferenceController(context, MESSAGES_KEY,
52                 getSettingsLifecycle()));
53         mControllers.add(new ZenRuleStarredContactsPreferenceController(context,
54                 getSettingsLifecycle(), ZenPolicy.PRIORITY_CATEGORY_MESSAGES,
55                 STARRED_CONTACTS_KEY));
56         return mControllers;
57     }
58 
59     @Override
getPreferenceCategoryKey()60     String getPreferenceCategoryKey() {
61         return PREFERENCE_CATEGORY_KEY;
62     }
63 
64     @Override
updatePreferences()65     public void updatePreferences() {
66         super.updatePreferences();
67         PreferenceScreen screen = getPreferenceScreen();
68         Preference footerPreference = screen.findPreference(FooterPreference.KEY_FOOTER);
69         footerPreference.setTitle(mContext.getResources().getString(
70                 R.string.zen_mode_custom_messages_footer, mRule.getName()));
71     }
72 }
73