blob: 2af7866450b263061d2df6213aeac40ead00aa44 [file] [log] [blame]
Julia Reynolds4cf8bfd2018-04-23 12:24:21 -04001/*
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
17package com.android.settings.notification;
18
19import android.app.NotificationManager.Policy;
20import android.content.Context;
Aurimas Liutikas03fcde32018-04-17 11:22:43 -070021import androidx.preference.Preference;
22import androidx.preference.PreferenceScreen;
Julia Reynolds4cf8bfd2018-04-23 12:24:21 -040023
24import com.android.internal.logging.nano.MetricsProto;
25import com.android.settingslib.core.lifecycle.Lifecycle;
26
27public class ZenModeVisEffectsAllPreferenceController
28 extends AbstractZenModePreferenceController
29 implements ZenCustomRadioButtonPreference.OnRadioButtonClickListener {
30
Beverly2f2a4d92018-05-18 14:33:36 -040031 private final String KEY;
32 private ZenCustomRadioButtonPreference mPreference;
33
Julia Reynolds4cf8bfd2018-04-23 12:24:21 -040034 protected static final int EFFECTS = Policy.SUPPRESSED_EFFECT_SCREEN_OFF
35 | Policy.SUPPRESSED_EFFECT_SCREEN_ON
36 | Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
37 | Policy.SUPPRESSED_EFFECT_LIGHTS
38 | Policy.SUPPRESSED_EFFECT_PEEK
39 | Policy.SUPPRESSED_EFFECT_STATUS_BAR
40 | Policy.SUPPRESSED_EFFECT_BADGE
41 | Policy.SUPPRESSED_EFFECT_AMBIENT
42 | Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;
43
44 public ZenModeVisEffectsAllPreferenceController(Context context, Lifecycle lifecycle,
45 String key) {
46 super(context, key, lifecycle);
Beverly2f2a4d92018-05-18 14:33:36 -040047 KEY = key;
48 }
49
50 @Override
51 public void displayPreference(PreferenceScreen screen) {
52 super.displayPreference(screen);
53 mPreference = (ZenCustomRadioButtonPreference) screen.findPreference(KEY);
54 mPreference.setOnRadioButtonClickListener(this);
Julia Reynolds4cf8bfd2018-04-23 12:24:21 -040055 }
56
57 @Override
58 public boolean isAvailable() {
59 return true;
60 }
61
62 @Override
63 public void updateState(Preference preference) {
64 super.updateState(preference);
65
66 boolean everythingBlocked = Policy.areAllVisualEffectsSuppressed(
67 mBackend.mPolicy.suppressedVisualEffects);
Beverly2f2a4d92018-05-18 14:33:36 -040068 mPreference.setChecked(everythingBlocked);
Julia Reynolds4cf8bfd2018-04-23 12:24:21 -040069 }
70
71 @Override
72 public void onRadioButtonClick(ZenCustomRadioButtonPreference p) {
73 mMetricsFeatureProvider.action(mContext,
74 MetricsProto.MetricsEvent.ACTION_ZEN_SOUND_AND_VIS_EFFECTS, true);
75 mBackend.saveVisualEffectsPolicy(EFFECTS, true);
76 }
77}