Home | History | Annotate | Download | only in notification
      1 /*
      2  * Copyright (C) 2017 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.AutomaticZenRule;
     20 import android.app.Fragment;
     21 import android.content.Context;
     22 import android.support.annotation.VisibleForTesting;
     23 import android.support.v7.preference.Preference;
     24 import android.support.v7.preference.PreferenceCategory;
     25 import android.support.v7.preference.PreferenceScreen;
     26 
     27 import com.android.settingslib.core.lifecycle.Lifecycle;
     28 
     29 import java.util.Map;
     30 
     31 public class ZenModeAutomaticRulesPreferenceController extends
     32         AbstractZenModeAutomaticRulePreferenceController {
     33 
     34     protected static final String KEY = "zen_mode_automatic_rules";
     35 
     36     @VisibleForTesting
     37     protected PreferenceCategory mPreferenceCategory;
     38 
     39     public ZenModeAutomaticRulesPreferenceController(Context context, Fragment parent, Lifecycle
     40             lifecycle) {
     41         super(context, KEY, parent, lifecycle);
     42     }
     43 
     44     @Override
     45     public String getPreferenceKey() {
     46         return KEY;
     47     }
     48 
     49     @Override
     50     public boolean isAvailable() {
     51         return true;
     52     }
     53 
     54     @Override
     55     public void displayPreference(PreferenceScreen screen) {
     56         super.displayPreference(screen);
     57         mPreferenceCategory = (PreferenceCategory) screen.findPreference(getPreferenceKey());
     58         mPreferenceCategory.setPersistent(false);
     59     }
     60 
     61     @Override
     62     public void updateState(Preference preference) {
     63         super.updateState(preference);
     64 
     65         mPreferenceCategory.removeAll();
     66         Map.Entry<String, AutomaticZenRule>[] sortedRules = sortedRules();
     67         for (Map.Entry<String, AutomaticZenRule> sortedRule : sortedRules) {
     68             ZenRulePreference pref = new ZenRulePreference(mPreferenceCategory.getContext(),
     69                     sortedRule, mParent, mMetricsFeatureProvider);
     70             mPreferenceCategory.addPreference(pref);
     71         }
     72     }
     73 }
     74 
     75 
     76 
     77