blob: af5910760e372df654ec9a0aec8a1b8afb08c420 [file] [log] [blame]
Beverlya58e52a2017-10-27 14:44:23 -04001/*
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
17package com.android.settings.notification;
18
19import android.app.NotificationManager.Policy;
20import android.content.Context;
21import android.provider.Settings;
22import android.support.v14.preference.SwitchPreference;
23import android.support.v7.preference.Preference;
24import android.util.Log;
25
Beverly32352212017-11-20 17:33:01 -050026import com.android.internal.logging.nano.MetricsProto;
Beverlya58e52a2017-10-27 14:44:23 -040027import com.android.settingslib.core.lifecycle.Lifecycle;
28
29public class ZenModeAlarmsPreferenceController extends
Beverly495c6462017-11-17 10:00:20 -050030 AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
Beverlya58e52a2017-10-27 14:44:23 -040031
32 protected static final String KEY = "zen_mode_alarms";
Beverlya58e52a2017-10-27 14:44:23 -040033
34 public ZenModeAlarmsPreferenceController(Context context, Lifecycle lifecycle) {
35 super(context, KEY, lifecycle);
Beverlya58e52a2017-10-27 14:44:23 -040036 }
37
38 @Override
39 public String getPreferenceKey() {
40 return KEY;
41 }
42
43 @Override
44 public boolean isAvailable() {
45 return true;
46 }
47
48 @Override
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
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 }
Beverly32352212017-11-20 17:33:01 -050075
76 mMetricsFeatureProvider.action(mContext, MetricsProto.MetricsEvent.ACTION_ZEN_ALLOW_ALARMS,
77 allowAlarms);
Beverlya58e52a2017-10-27 14:44:23 -040078 mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_ALARMS, allowAlarms);
79 return true;
80 }
81}