• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
18 
19 import android.app.NotificationManager;
20 import android.content.Context;
21 import android.provider.Settings;
22 
23 import androidx.preference.Preference;
24 
25 import com.android.settings.core.PreferenceControllerMixin;
26 import com.android.settingslib.core.lifecycle.Lifecycle;
27 
28 public class ZenModeMessagesPreferenceController extends
29         AbstractZenModePreferenceController implements PreferenceControllerMixin {
30 
31     private final String KEY;
32     private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
33 
ZenModeMessagesPreferenceController(Context context, Lifecycle lifecycle, String key)34     public ZenModeMessagesPreferenceController(Context context, Lifecycle lifecycle, String key) {
35         super(context, key, lifecycle);
36         KEY = key;
37         mSummaryBuilder = new ZenModeSettings.SummaryBuilder(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         switch (getZenMode()) {
55             case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
56             case Settings.Global.ZEN_MODE_ALARMS:
57                 preference.setEnabled(false);
58                 preference.setSummary(mBackend.getAlarmsTotalSilenceCallsMessagesSummary(
59                         NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES));
60                 break;
61             default:
62                 preference.setEnabled(true);
63                 preference.setSummary(mSummaryBuilder.getMessagesSettingSummary(getPolicy()));
64         }
65     }
66 }
67