| Julia Reynolds | 4cf8bfd | 2018-04-23 12:24:21 -0400 | [diff] [blame^] | 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.Policy; |
| 20 | import android.content.Context; |
| 21 | import android.support.v7.preference.Preference; |
| 22 | import android.support.v7.preference.PreferenceScreen; |
| 23 | |
| 24 | import com.android.internal.logging.nano.MetricsProto; |
| 25 | import com.android.settingslib.core.lifecycle.Lifecycle; |
| 26 | |
| 27 | public class ZenModeVisEffectsAllPreferenceController |
| 28 | extends AbstractZenModePreferenceController |
| 29 | implements ZenCustomRadioButtonPreference.OnRadioButtonClickListener { |
| 30 | |
| 31 | protected static final int EFFECTS = Policy.SUPPRESSED_EFFECT_SCREEN_OFF |
| 32 | | Policy.SUPPRESSED_EFFECT_SCREEN_ON |
| 33 | | Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT |
| 34 | | Policy.SUPPRESSED_EFFECT_LIGHTS |
| 35 | | Policy.SUPPRESSED_EFFECT_PEEK |
| 36 | | Policy.SUPPRESSED_EFFECT_STATUS_BAR |
| 37 | | Policy.SUPPRESSED_EFFECT_BADGE |
| 38 | | Policy.SUPPRESSED_EFFECT_AMBIENT |
| 39 | | Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST; |
| 40 | |
| 41 | public ZenModeVisEffectsAllPreferenceController(Context context, Lifecycle lifecycle, |
| 42 | String key) { |
| 43 | super(context, key, lifecycle); |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public boolean isAvailable() { |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public void updateState(Preference preference) { |
| 53 | super.updateState(preference); |
| 54 | |
| 55 | boolean everythingBlocked = Policy.areAllVisualEffectsSuppressed( |
| 56 | mBackend.mPolicy.suppressedVisualEffects); |
| 57 | ZenCustomRadioButtonPreference pref = (ZenCustomRadioButtonPreference) preference; |
| 58 | pref.setOnRadioButtonClickListener(this); |
| 59 | pref.setChecked(everythingBlocked); |
| 60 | } |
| 61 | |
| 62 | protected void deselect(PreferenceScreen screen) { |
| 63 | ZenCustomRadioButtonPreference preference = |
| 64 | (ZenCustomRadioButtonPreference) screen.findPreference(getPreferenceKey()); |
| 65 | if (preference != null) { |
| 66 | preference.setChecked(false); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public void onRadioButtonClick(ZenCustomRadioButtonPreference p) { |
| 72 | mMetricsFeatureProvider.action(mContext, |
| 73 | MetricsProto.MetricsEvent.ACTION_ZEN_SOUND_AND_VIS_EFFECTS, true); |
| 74 | mBackend.saveVisualEffectsPolicy(EFFECTS, true); |
| 75 | } |
| 76 | } |