• 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;
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 ZenModeCallsPreferenceController extends
29         AbstractZenModePreferenceController implements PreferenceControllerMixin {
30 
31     private final String KEY_BEHAVIOR_SETTINGS;
32     private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
33 
ZenModeCallsPreferenceController(Context context, Lifecycle lifecycle, String key)34     public ZenModeCallsPreferenceController(Context context, Lifecycle lifecycle,
35             String key) {
36         super(context, key, lifecycle);
37         KEY_BEHAVIOR_SETTINGS = key;
38         mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
39     }
40 
41     @Override
getPreferenceKey()42     public String getPreferenceKey() {
43         return KEY_BEHAVIOR_SETTINGS;
44     }
45 
46     @Override
isAvailable()47     public boolean isAvailable() {
48         return true;
49     }
50 
51     @Override
updateState(Preference preference)52     public void updateState(Preference preference) {
53         super.updateState(preference);
54 
55         switch (getZenMode()) {
56             case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
57             case Settings.Global.ZEN_MODE_ALARMS:
58                 preference.setEnabled(false);
59                 preference.setSummary(mBackend.getAlarmsTotalSilenceCallsMessagesSummary(
60                         NotificationManager.Policy.PRIORITY_CATEGORY_CALLS));
61                 break;
62             default:
63                 preference.setEnabled(true);
64                 preference.setSummary(mSummaryBuilder.getCallsSettingSummary(getPolicy()));
65         }
66     }
67 }
68