• 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.zen;
18 
19 import android.app.NotificationManager.Policy;
20 import android.app.settings.SettingsEnums;
21 import android.content.Context;
22 
23 import androidx.preference.Preference;
24 import androidx.preference.PreferenceScreen;
25 
26 import com.android.settingslib.core.lifecycle.Lifecycle;
27 import com.android.settingslib.widget.RadioButtonPreference;
28 
29 public class ZenModeVisEffectsAllPreferenceController
30         extends AbstractZenModePreferenceController
31         implements RadioButtonPreference.OnClickListener {
32 
33     private RadioButtonPreference mPreference;
34 
35     protected static final int EFFECTS = Policy.SUPPRESSED_EFFECT_SCREEN_OFF
36             | Policy.SUPPRESSED_EFFECT_SCREEN_ON
37             | Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
38             | Policy.SUPPRESSED_EFFECT_LIGHTS
39             | Policy.SUPPRESSED_EFFECT_PEEK
40             | Policy.SUPPRESSED_EFFECT_STATUS_BAR
41             | Policy.SUPPRESSED_EFFECT_BADGE
42             | Policy.SUPPRESSED_EFFECT_AMBIENT
43             | Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;
44 
ZenModeVisEffectsAllPreferenceController(Context context, Lifecycle lifecycle, String key)45     public ZenModeVisEffectsAllPreferenceController(Context context, Lifecycle lifecycle,
46             String key) {
47         super(context, key, lifecycle);
48     }
49 
50     @Override
displayPreference(PreferenceScreen screen)51     public void displayPreference(PreferenceScreen screen) {
52         super.displayPreference(screen);
53         mPreference = screen.findPreference(getPreferenceKey());
54         mPreference.setOnClickListener(this);
55     }
56 
57     @Override
isAvailable()58     public boolean isAvailable() {
59         return true;
60     }
61 
62     @Override
updateState(Preference preference)63     public void updateState(Preference preference) {
64         super.updateState(preference);
65 
66         boolean everythingBlocked = Policy.areAllVisualEffectsSuppressed(
67                 mBackend.mPolicy.suppressedVisualEffects);
68         mPreference.setChecked(everythingBlocked);
69     }
70 
71     @Override
onRadioButtonClicked(RadioButtonPreference p)72     public void onRadioButtonClicked(RadioButtonPreference p) {
73         mMetricsFeatureProvider.action(mContext,
74                 SettingsEnums.ACTION_ZEN_SOUND_AND_VIS_EFFECTS, true);
75         mBackend.saveVisualEffectsPolicy(EFFECTS, true);
76     }
77 }
78