• 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.util.Log;
23 
24 import androidx.preference.Preference;
25 import androidx.preference.SwitchPreference;
26 
27 import com.android.settingslib.core.lifecycle.Lifecycle;
28 
29 public class ZenModeMediaPreferenceController extends AbstractZenModePreferenceController
30         implements Preference.OnPreferenceChangeListener {
31 
32     protected static final String KEY = "zen_mode_media";
33     private final ZenModeBackend mBackend;
34 
ZenModeMediaPreferenceController(Context context, Lifecycle lifecycle)35     public ZenModeMediaPreferenceController(Context context, Lifecycle lifecycle) {
36         super(context, KEY, lifecycle);
37         mBackend = ZenModeBackend.getInstance(context);
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_MEDIA));
68         }
69     }
70 
71     @Override
onPreferenceChange(Preference preference, Object newValue)72     public boolean onPreferenceChange(Preference preference, Object newValue) {
73         final boolean allowMedia = (Boolean) newValue;
74         if (ZenModeSettingsBase.DEBUG) {
75             Log.d(TAG, "onPrefChange allowMedia=" + allowMedia);
76         }
77         mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_MEDIA, allowMedia);
78         return true;
79     }
80 }
81