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.content.Context;
     20 import android.os.Bundle;
     21 import android.provider.SearchIndexableResource;
     22 
     23 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
     24 import com.android.settings.R;
     25 import com.android.settings.search.BaseSearchIndexProvider;
     26 import com.android.settings.search.Indexable;
     27 import com.android.settingslib.core.AbstractPreferenceController;
     28 import com.android.settingslib.core.lifecycle.Lifecycle;
     29 import com.android.settingslib.widget.FooterPreference;
     30 
     31 import java.util.ArrayList;
     32 import java.util.List;
     33 
     34 public class ZenModeRestrictNotificationsSettings extends ZenModeSettingsBase implements Indexable {
     35 
     36     @Override
     37     public void onCreate(Bundle icicle) {
     38         super.onCreate(icicle);
     39     }
     40 
     41     @Override
     42     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
     43         return buildPreferenceControllers(context, getLifecycle());
     44     }
     45 
     46     @Override
     47     public int getHelpResource() {
     48         return R.string.help_uri_interruptions;
     49     }
     50 
     51     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
     52             Lifecycle lifecycle) {
     53         List<AbstractPreferenceController> controllers = new ArrayList<>();
     54         controllers.add(new ZenModeVisEffectsNonePreferenceController(
     55                 context, lifecycle, "zen_mute_notifications"));
     56         controllers.add(new ZenModeVisEffectsAllPreferenceController(
     57                 context, lifecycle, "zen_hide_notifications"));
     58         controllers.add(new ZenModeVisEffectsCustomPreferenceController(
     59                 context, lifecycle, "zen_custom"));
     60         controllers.add(new ZenFooterPreferenceController(context, lifecycle,
     61                 FooterPreference.KEY_FOOTER));
     62         return controllers;
     63     }
     64 
     65     @Override
     66     protected int getPreferenceScreenResId() {
     67         return R.xml.zen_mode_restrict_notifications_settings;
     68     }
     69 
     70     @Override
     71     public int getMetricsCategory() {
     72         return MetricsEvent.SETTINGS_ZEN_NOTIFICATIONS;
     73     }
     74 
     75     /**
     76      * For Search.
     77      */
     78     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
     79             new BaseSearchIndexProvider() {
     80                 @Override
     81                 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
     82                         boolean enabled) {
     83                     final ArrayList<SearchIndexableResource> result = new ArrayList<>();
     84 
     85                     final SearchIndexableResource sir = new SearchIndexableResource(context);
     86                     sir.xmlResId = R.xml.zen_mode_restrict_notifications_settings;
     87                     result.add(sir);
     88                     return result;
     89                 }
     90 
     91                 @Override
     92                 public List<String> getNonIndexableKeys(Context context) {
     93                     final List<String> keys = super.getNonIndexableKeys(context);
     94                     return keys;
     95                 }
     96 
     97             @Override
     98             public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
     99                 return buildPreferenceControllers(context, null);
    100             }
    101         };
    102 }
    103