2 * Copyright (C) 2018 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.notification;
19 import android.app.NotificationManager;
20 import android.content.Context;
21 import androidx.preference.Preference;
22 import androidx.preference.PreferenceScreen;
24 import com.android.internal.logging.nano.MetricsProto;
25 import com.android.settings.R;
26 import com.android.settings.core.SubSettingLauncher;
27 import com.android.settingslib.core.lifecycle.Lifecycle;
29 public class ZenModeVisEffectsCustomPreferenceController
30 extends AbstractZenModePreferenceController {
32 private ZenCustomRadioButtonPreference mPreference;
34 protected static final int INTERRUPTIVE_EFFECTS =
35 NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT
36 | NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK
37 | NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS
38 | NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
40 public ZenModeVisEffectsCustomPreferenceController(Context context, Lifecycle lifecycle,
42 super(context, key, lifecycle);
46 public boolean isAvailable() {
51 public void displayPreference(PreferenceScreen screen) {
52 super.displayPreference(screen);
53 mPreference = (ZenCustomRadioButtonPreference) screen.findPreference(getPreferenceKey());
55 mPreference.setOnGearClickListener(p -> {
56 launchCustomSettings();
60 mPreference.setOnRadioButtonClickListener(p -> {
61 launchCustomSettings();
66 public void updateState(Preference preference) {
67 super.updateState(preference);
69 mPreference.setChecked(areCustomOptionsSelected());
72 protected boolean areCustomOptionsSelected() {
73 boolean allEffectsSuppressed =
74 NotificationManager.Policy.areAllVisualEffectsSuppressed(
75 mBackend.mPolicy.suppressedVisualEffects);
76 boolean noEffectsSuppressed = mBackend.mPolicy.suppressedVisualEffects == 0;
78 return !(allEffectsSuppressed || noEffectsSuppressed);
81 protected void select() {
82 mMetricsFeatureProvider.action(mContext,
83 MetricsProto.MetricsEvent.ACTION_ZEN_CUSTOM, true);
86 private void launchCustomSettings() {
88 new SubSettingLauncher(mContext)
89 .setDestination(ZenModeBlockedEffectsSettings.class.getName())
90 .setTitleRes(R.string.zen_mode_what_to_block_title)
91 .setSourceMetricsCategory(MetricsProto.MetricsEvent.SETTINGS_ZEN_NOTIFICATIONS)