Home | History | Annotate | Download | only in notification
      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.settings.R;
     26 import com.android.settings.core.SubSettingLauncher;
     27 import com.android.settingslib.core.lifecycle.Lifecycle;
     28 
     29 public class ZenModeVisEffectsCustomPreferenceController
     30         extends AbstractZenModePreferenceController {
     31 
     32     private final String KEY;
     33     private ZenCustomRadioButtonPreference mPreference;
     34 
     35     protected static final int INTERRUPTIVE_EFFECTS = Policy.SUPPRESSED_EFFECT_AMBIENT
     36             | Policy.SUPPRESSED_EFFECT_PEEK
     37             | Policy.SUPPRESSED_EFFECT_LIGHTS
     38             | Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
     39 
     40     public ZenModeVisEffectsCustomPreferenceController(Context context, Lifecycle lifecycle,
     41             String key) {
     42         super(context, key, lifecycle);
     43         KEY = key;
     44     }
     45 
     46     @Override
     47     public boolean isAvailable() {
     48         return true;
     49     }
     50 
     51     @Override
     52     public void displayPreference(PreferenceScreen screen) {
     53         super.displayPreference(screen);
     54         mPreference = (ZenCustomRadioButtonPreference) screen.findPreference(KEY);
     55 
     56         mPreference.setOnGearClickListener(p -> {
     57             launchCustomSettings();
     58         });
     59 
     60         mPreference.setOnRadioButtonClickListener(p -> {
     61             launchCustomSettings();
     62         });
     63     }
     64 
     65     @Override
     66     public void updateState(Preference preference) {
     67         super.updateState(preference);
     68 
     69         mPreference.setChecked(areCustomOptionsSelected());
     70     }
     71 
     72     protected boolean areCustomOptionsSelected() {
     73         boolean allEffectsSuppressed =
     74                 Policy.areAllVisualEffectsSuppressed(mBackend.mPolicy.suppressedVisualEffects);
     75         boolean noEffectsSuppressed = mBackend.mPolicy.suppressedVisualEffects == 0;
     76 
     77         return !(allEffectsSuppressed || noEffectsSuppressed);
     78     }
     79 
     80     protected void select() {
     81         mMetricsFeatureProvider.action(mContext,
     82                 MetricsProto.MetricsEvent.ACTION_ZEN_CUSTOM, true);
     83     }
     84 
     85     private void launchCustomSettings() {
     86         select();
     87         new SubSettingLauncher(mContext)
     88                 .setDestination(ZenModeBlockedEffectsSettings.class.getName())
     89                 .setTitle(R.string.zen_mode_what_to_block_title)
     90                 .setSourceMetricsCategory(MetricsProto.MetricsEvent.SETTINGS_ZEN_NOTIFICATIONS)
     91                 .launch();
     92     }
     93 }