• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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;
18 
19 import android.app.NotificationManager.Policy;
20 import android.app.settings.SettingsEnums;
21 import android.content.Context;
22 import android.provider.Settings;
23 import android.util.Log;
24 
25 import androidx.preference.Preference;
26 import androidx.preference.SwitchPreference;
27 
28 import com.android.settingslib.core.lifecycle.Lifecycle;
29 
30 public class ZenModeAlarmsPreferenceController extends
31         AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
32 
33     private final String KEY;
34 
ZenModeAlarmsPreferenceController(Context context, Lifecycle lifecycle, String key)35     public ZenModeAlarmsPreferenceController(Context context, Lifecycle lifecycle, String key) {
36         super(context, key, lifecycle);
37         KEY = key;
38     }
39 
40     @Override
getPreferenceKey()41     public String getPreferenceKey() {
42         return KEY;
43     }
44 
45     @Override
isAvailable()46     public boolean isAvailable() {
47         return true;
48     }
49 
50     @Override
updateState(Preference preference)51     public void updateState(Preference preference) {
52         super.updateState(preference);
53 
54         SwitchPreference pref = (SwitchPreference) preference;
55         switch (getZenMode()) {
56             case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
57                 pref.setEnabled(false);
58                 pref.setChecked(false);
59                 break;
60             case Settings.Global.ZEN_MODE_ALARMS:
61                 pref.setEnabled(false);
62                 pref.setChecked(true);
63                 break;
64             default:
65                 pref.setEnabled(true);
66                 pref.setChecked(mBackend.isPriorityCategoryEnabled(
67                         Policy.PRIORITY_CATEGORY_ALARMS));
68         }
69     }
70 
71     @Override
onPreferenceChange(Preference preference, Object newValue)72     public boolean onPreferenceChange(Preference preference, Object newValue) {
73         final boolean allowAlarms = (Boolean) newValue;
74         if (ZenModeSettingsBase.DEBUG) {
75             Log.d(TAG, "onPrefChange allowAlarms=" + allowAlarms);
76         }
77 
78         mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_ZEN_ALLOW_ALARMS,
79                 allowAlarms);
80         mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_ALARMS, allowAlarms);
81 
82         return true;
83     }
84 }
85