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.NotificationManager; 20 import android.app.settings.SettingsEnums; 21 import android.content.Context; 22 import android.os.Bundle; 23 import android.service.notification.ZenPolicy; 24 25 import androidx.preference.Preference; 26 27 import com.android.settings.R; 28 import com.android.settings.core.SubSettingLauncher; 29 import com.android.settingslib.core.AbstractPreferenceController; 30 31 import java.util.ArrayList; 32 import java.util.List; 33 34 public class ZenCustomRuleConfigSettings extends ZenCustomRuleSettingsBase { 35 private static final String CALLS_KEY = "zen_rule_calls_settings"; 36 private static final String MESSAGES_KEY = "zen_rule_messages_settings"; 37 private static final String ALARMS_KEY = "zen_rule_alarms"; 38 private static final String MEDIA_KEY = "zen_rule_media"; 39 private static final String SYSTEM_KEY = "zen_rule_system"; 40 private static final String REMINDERS_KEY = "zen_rule_reminders"; 41 private static final String EVENTS_KEY = "zen_rule_events"; 42 private static final String NOTIFICATIONS_KEY = "zen_rule_notifications"; 43 private static final String PREFERENCE_CATEGORY_KEY = "zen_custom_rule_configuration_category"; 44 45 private Preference mCallsPreference; 46 private Preference mMessagesPreference; 47 private Preference mNotificationsPreference; 48 private ZenModeSettings.SummaryBuilder mSummaryBuilder; 49 50 @Override onCreate(Bundle icicle)51 public void onCreate(Bundle icicle) { 52 super.onCreate(icicle); 53 mSummaryBuilder = new ZenModeSettings.SummaryBuilder(mContext); 54 55 mCallsPreference = getPreferenceScreen().findPreference(CALLS_KEY); 56 mCallsPreference.setOnPreferenceClickListener( 57 new Preference.OnPreferenceClickListener() { 58 @Override 59 public boolean onPreferenceClick(Preference preference) { 60 new SubSettingLauncher(mContext) 61 .setDestination(ZenCustomRuleCallsSettings.class.getName()) 62 .setArguments(createZenRuleBundle()) 63 .setSourceMetricsCategory(SettingsEnums.ZEN_CUSTOM_RULE_CALLS) 64 .launch(); 65 return true; 66 } 67 }); 68 69 mMessagesPreference = getPreferenceScreen().findPreference(MESSAGES_KEY); 70 mMessagesPreference.setOnPreferenceClickListener( 71 new Preference.OnPreferenceClickListener() { 72 @Override 73 public boolean onPreferenceClick(Preference preference) { 74 new SubSettingLauncher(mContext) 75 .setDestination(ZenCustomRuleMessagesSettings.class.getName()) 76 .setArguments(createZenRuleBundle()) 77 .setSourceMetricsCategory(SettingsEnums.ZEN_CUSTOM_RULE_MESSAGES) 78 .launch(); 79 return true; 80 } 81 }); 82 83 mNotificationsPreference = getPreferenceScreen().findPreference(NOTIFICATIONS_KEY); 84 mNotificationsPreference.setOnPreferenceClickListener( 85 new Preference.OnPreferenceClickListener() { 86 @Override 87 public boolean onPreferenceClick(Preference preference) { 88 new SubSettingLauncher(mContext) 89 .setDestination(ZenCustomRuleNotificationsSettings.class.getName()) 90 .setArguments(createZenRuleBundle()) 91 .setSourceMetricsCategory 92 (SettingsEnums.ZEN_CUSTOM_RULE_NOTIFICATION_RESTRICTIONS) 93 .launch(); 94 return true; 95 } 96 }); 97 98 updateSummaries(); 99 } 100 101 @Override onZenModeConfigChanged()102 public void onZenModeConfigChanged() { 103 super.onZenModeConfigChanged(); 104 updateSummaries(); 105 } 106 107 /** 108 * Updates summaries of preferences without preference controllers 109 */ updateSummaries()110 private void updateSummaries() { 111 NotificationManager.Policy noManPolicy = mBackend.toNotificationPolicy( 112 mRule.getZenPolicy()); 113 114 mCallsPreference.setSummary(mSummaryBuilder.getCallsSettingSummary(noManPolicy)); 115 mMessagesPreference.setSummary(mSummaryBuilder.getMessagesSettingSummary(noManPolicy)); 116 mNotificationsPreference.setSummary(mSummaryBuilder.getBlockedEffectsSummary(noManPolicy)); 117 } 118 119 @Override getPreferenceScreenResId()120 protected int getPreferenceScreenResId() { 121 return R.xml.zen_mode_custom_rule_configuration; 122 } 123 124 @Override getMetricsCategory()125 public int getMetricsCategory() { 126 return SettingsEnums.ZEN_CUSTOM_RULE_SOUND_SETTINGS; 127 } 128 129 @Override createPreferenceControllers(Context context)130 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 131 mControllers = new ArrayList<>(); 132 mControllers.add(new ZenRuleCustomSwitchPreferenceController(context, 133 getSettingsLifecycle(), ALARMS_KEY, ZenPolicy.PRIORITY_CATEGORY_ALARMS, 134 SettingsEnums.ACTION_ZEN_ALLOW_ALARMS)); 135 mControllers.add(new ZenRuleCustomSwitchPreferenceController(context, 136 getSettingsLifecycle(), MEDIA_KEY, ZenPolicy.PRIORITY_CATEGORY_MEDIA, 137 SettingsEnums.ACTION_ZEN_ALLOW_MEDIA)); 138 mControllers.add(new ZenRuleCustomSwitchPreferenceController(context, 139 getSettingsLifecycle(), SYSTEM_KEY, ZenPolicy.PRIORITY_CATEGORY_SYSTEM, 140 SettingsEnums.ACTION_ZEN_ALLOW_SYSTEM)); 141 mControllers.add(new ZenRuleCustomSwitchPreferenceController(context, 142 getSettingsLifecycle(), REMINDERS_KEY, ZenPolicy.PRIORITY_CATEGORY_REMINDERS, 143 SettingsEnums.ACTION_ZEN_ALLOW_REMINDERS)); 144 mControllers.add(new ZenRuleCustomSwitchPreferenceController(context, 145 getSettingsLifecycle(), EVENTS_KEY, ZenPolicy.PRIORITY_CATEGORY_EVENTS, 146 SettingsEnums.ACTION_ZEN_ALLOW_EVENTS)); 147 return mControllers; 148 } 149 150 @Override getPreferenceCategoryKey()151 String getPreferenceCategoryKey() { 152 return PREFERENCE_CATEGORY_KEY; 153 } 154 155 @Override onResume()156 public void onResume() { 157 super.onResume(); 158 updateSummaries(); 159 } 160 } 161