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.settings.SettingsEnums; 20 import android.content.Context; 21 import android.service.notification.ZenPolicy; 22 import android.util.Pair; 23 24 import androidx.preference.Preference; 25 import androidx.preference.PreferenceScreen; 26 27 import com.android.internal.logging.nano.MetricsProto; 28 import com.android.settings.core.PreferenceControllerMixin; 29 import com.android.settingslib.core.lifecycle.Lifecycle; 30 31 public class ZenRuleVisEffectsNonePreferenceController extends 32 AbstractZenCustomRulePreferenceController implements PreferenceControllerMixin { 33 34 private ZenCustomRadioButtonPreference mPreference; 35 ZenRuleVisEffectsNonePreferenceController(Context context, Lifecycle lifecycle, String key)36 public ZenRuleVisEffectsNonePreferenceController(Context context, Lifecycle lifecycle, 37 String key) { 38 super(context, key, lifecycle); 39 } 40 41 @Override displayPreference(PreferenceScreen screen)42 public void displayPreference(PreferenceScreen screen) { 43 super.displayPreference(screen); 44 mPreference = screen.findPreference(getPreferenceKey()); 45 46 mPreference.setOnRadioButtonClickListener(p -> { 47 mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_ZEN_SOUND_AND_VIS_EFFECTS, 48 Pair.create(MetricsProto.MetricsEvent.FIELD_ZEN_RULE_ID, mId)); 49 mRule.setZenPolicy(new ZenPolicy.Builder(mRule.getZenPolicy()) 50 .hideAllVisualEffects() 51 .build()); 52 mBackend.updateZenRule(mId, mRule); 53 }); 54 } 55 56 @Override updateState(Preference preference)57 public void updateState(Preference preference) { 58 super.updateState(preference); 59 if (mId == null || mRule == null || mRule.getZenPolicy() == null) { 60 return; 61 } 62 63 mPreference.setChecked(mRule.getZenPolicy().shouldHideAllVisualEffects()); 64 } 65 }