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 static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
     20 import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
     21 import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
     22 import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS;
     23 import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;
     24 import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
     25 import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR;
     26 
     27 import android.content.Context;
     28 import android.os.Bundle;
     29 import android.provider.SearchIndexableResource;
     30 import android.support.v7.preference.CheckBoxPreference;
     31 
     32 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
     33 import com.android.settings.R;
     34 import com.android.settings.search.BaseSearchIndexProvider;
     35 import com.android.settings.search.Indexable;
     36 import com.android.settingslib.core.AbstractPreferenceController;
     37 import com.android.settingslib.core.lifecycle.Lifecycle;
     38 
     39 import java.util.ArrayList;
     40 import java.util.List;
     41 
     42 public class ZenModeBlockedEffectsSettings extends ZenModeSettingsBase implements Indexable {
     43 
     44     @Override
     45     public void onCreate(Bundle icicle) {
     46         super.onCreate(icicle);
     47         mFooterPreferenceMixin.createFooterPreference().setTitle(
     48                 R.string.zen_mode_blocked_effects_footer);
     49     }
     50 
     51     @Override
     52     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
     53         return buildPreferenceControllers(context, getLifecycle());
     54     }
     55 
     56     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
     57             Lifecycle lifecycle) {
     58         List<AbstractPreferenceController> controllers = new ArrayList<>();
     59         controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
     60                 "zen_effect_intent", SUPPRESSED_EFFECT_FULL_SCREEN_INTENT,
     61                 MetricsEvent.ACTION_ZEN_BLOCK_FULL_SCREEN_INTENTS, null));
     62         controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
     63                 "zen_effect_light", SUPPRESSED_EFFECT_LIGHTS,
     64                 MetricsEvent.ACTION_ZEN_BLOCK_LIGHT, null));
     65         controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
     66                 "zen_effect_peek", SUPPRESSED_EFFECT_PEEK,
     67                 MetricsEvent.ACTION_ZEN_BLOCK_PEEK, null));
     68         controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
     69                 "zen_effect_status", SUPPRESSED_EFFECT_STATUS_BAR,
     70                 MetricsEvent.ACTION_ZEN_BLOCK_STATUS,
     71                 new int[] {SUPPRESSED_EFFECT_NOTIFICATION_LIST}));
     72         controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
     73                 "zen_effect_badge", SUPPRESSED_EFFECT_BADGE,
     74                 MetricsEvent.ACTION_ZEN_BLOCK_BADGE, null));
     75         controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
     76                 "zen_effect_ambient", SUPPRESSED_EFFECT_AMBIENT,
     77                 MetricsEvent.ACTION_ZEN_BLOCK_AMBIENT, null));
     78         controllers.add(new ZenModeVisEffectPreferenceController(context, lifecycle,
     79                 "zen_effect_list", SUPPRESSED_EFFECT_NOTIFICATION_LIST,
     80                 MetricsEvent.ACTION_ZEN_BLOCK_NOTIFICATION_LIST, null));
     81         return controllers;
     82     }
     83 
     84     @Override
     85     protected int getPreferenceScreenResId() {
     86         return R.xml.zen_mode_block_settings;
     87     }
     88 
     89     @Override
     90     public int getMetricsCategory() {
     91         return MetricsEvent.ZEN_WHAT_TO_BLOCK;
     92     }
     93 
     94     /**
     95      * For Search.
     96      */
     97     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
     98             new BaseSearchIndexProvider() {
     99                 @Override
    100                 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
    101                         boolean enabled) {
    102                     final ArrayList<SearchIndexableResource> result = new ArrayList<>();
    103 
    104                     final SearchIndexableResource sir = new SearchIndexableResource(context);
    105                     sir.xmlResId = R.xml.zen_mode_block_settings;
    106                     result.add(sir);
    107                     return result;
    108                 }
    109 
    110                 @Override
    111                 public List<String> getNonIndexableKeys(Context context) {
    112                     final List<String> keys = super.getNonIndexableKeys(context);
    113                     return keys;
    114                 }
    115 
    116             @Override
    117             public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
    118                 return buildPreferenceControllers(context, null);
    119             }
    120         };
    121 }
    122