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.settings.SettingsEnums; 20 import android.content.Context; 21 import android.util.Pair; 22 23 import androidx.preference.Preference; 24 import androidx.preference.PreferenceScreen; 25 26 import com.android.internal.logging.nano.MetricsProto; 27 import com.android.settings.core.PreferenceControllerMixin; 28 import com.android.settings.core.SubSettingLauncher; 29 import com.android.settingslib.core.lifecycle.Lifecycle; 30 import com.android.settingslib.widget.SelectorWithWidgetPreference; 31 32 public class ZenRuleVisEffectsCustomPreferenceController extends 33 AbstractZenCustomRulePreferenceController implements PreferenceControllerMixin { 34 35 private SelectorWithWidgetPreference mPreference; 36 ZenRuleVisEffectsCustomPreferenceController(Context context, Lifecycle lifecycle, String key)37 public ZenRuleVisEffectsCustomPreferenceController(Context context, Lifecycle lifecycle, 38 String key) { 39 super(context, key, lifecycle); 40 } 41 42 @Override displayPreference(PreferenceScreen screen)43 public void displayPreference(PreferenceScreen screen) { 44 super.displayPreference(screen); 45 mPreference = screen.findPreference(getPreferenceKey()); 46 47 mPreference.setOnClickListener(p -> { 48 launchCustomSettings(); 49 50 }); 51 52 mPreference.setExtraWidgetOnClickListener(p -> { 53 launchCustomSettings(); 54 }); 55 } 56 57 @Override updateState(Preference preference)58 public void updateState(Preference preference) { 59 super.updateState(preference); 60 if (mId == null || mRule == null || mRule.getZenPolicy() == null) { 61 return; 62 } 63 64 mPreference.setChecked(!mRule.getZenPolicy().shouldHideAllVisualEffects() 65 && !mRule.getZenPolicy().shouldShowAllVisualEffects()); 66 } 67 launchCustomSettings()68 private void launchCustomSettings() { 69 mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_ZEN_SHOW_CUSTOM, 70 Pair.create(MetricsProto.MetricsEvent.FIELD_ZEN_RULE_ID, mId)); 71 new SubSettingLauncher(mContext) 72 .setDestination(ZenCustomRuleBlockedEffectsSettings.class.getName()) 73 .setArguments(createBundle()) 74 .setSourceMetricsCategory(SettingsEnums.ZEN_CUSTOM_RULE_VIS_EFFECTS) 75 .launch(); 76 } 77 }