• 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.content.Context;
21 import android.provider.Settings;
22 import android.support.v14.preference.SwitchPreference;
23 import android.support.v7.preference.Preference;
24 import android.util.Log;
25 
26 import com.android.internal.logging.nano.MetricsProto;
27 import com.android.settingslib.core.lifecycle.Lifecycle;
28 
29 public class ZenModeAlarmsPreferenceController extends
30         AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
31 
32     protected static final String KEY = "zen_mode_alarms";
33 
ZenModeAlarmsPreferenceController(Context context, Lifecycle lifecycle)34     public ZenModeAlarmsPreferenceController(Context context, Lifecycle lifecycle) {
35         super(context, KEY, lifecycle);
36     }
37 
38     @Override
getPreferenceKey()39     public String getPreferenceKey() {
40         return KEY;
41     }
42 
43     @Override
isAvailable()44     public boolean isAvailable() {
45         return true;
46     }
47 
48     @Override
updateState(Preference preference)49     public void updateState(Preference preference) {
50         super.updateState(preference);
51 
52         SwitchPreference pref = (SwitchPreference) preference;
53         switch (getZenMode()) {
54             case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
55                 pref.setEnabled(false);
56                 pref.setChecked(false);
57                 break;
58             case Settings.Global.ZEN_MODE_ALARMS:
59                 pref.setEnabled(false);
60                 pref.setChecked(true);
61                 break;
62             default:
63                 pref.setEnabled(true);
64                 pref.setChecked(mBackend.isPriorityCategoryEnabled(
65                         Policy.PRIORITY_CATEGORY_ALARMS));
66         }
67     }
68 
69     @Override
onPreferenceChange(Preference preference, Object newValue)70     public boolean onPreferenceChange(Preference preference, Object newValue) {
71         final boolean allowAlarms = (Boolean) newValue;
72         if (ZenModeSettingsBase.DEBUG) {
73             Log.d(TAG, "onPrefChange allowAlarms=" + allowAlarms);
74         }
75 
76         mMetricsFeatureProvider.action(mContext, MetricsProto.MetricsEvent.ACTION_ZEN_ALLOW_ALARMS,
77                 allowAlarms);
78         mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_ALARMS, allowAlarms);
79         return true;
80     }
81 }
82