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.NotificationManager;
     20 import android.content.Context;
     21 import android.provider.Settings;
     22 import android.support.v14.preference.SwitchPreference;
     23 import android.support.v7.preference.Preference;
     24 import android.util.Log;
     25 
     26 import com.android.internal.logging.nano.MetricsProto;
     27 import com.android.settingslib.core.lifecycle.Lifecycle;
     28 
     29 public class ZenModeRemindersPreferenceController extends AbstractZenModePreferenceController
     30         implements Preference.OnPreferenceChangeListener {
     31 
     32     protected static final String KEY = "zen_mode_reminders";
     33 
     34     public ZenModeRemindersPreferenceController(Context context, Lifecycle lifecycle) {
     35         super(context, KEY, lifecycle);
     36     }
     37 
     38     @Override
     39     public String getPreferenceKey() {
     40         return KEY;
     41     }
     42 
     43     @Override
     44     public boolean isAvailable() {
     45         return true;
     46     }
     47 
     48     @Override
     49     public void updateState(Preference preference) {
     50         super.updateState(preference);
     51 
     52         SwitchPreference pref = (SwitchPreference) preference;
     53         switch (getZenMode()) {
     54             case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
     55             case Settings.Global.ZEN_MODE_ALARMS:
     56                 pref.setEnabled(false);
     57                 pref.setChecked(false);
     58                 break;
     59             default:
     60                 pref.setEnabled(true);
     61                 pref.setChecked(mBackend.isPriorityCategoryEnabled(
     62                         NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS));
     63         }
     64     }
     65 
     66     @Override
     67     public boolean onPreferenceChange(Preference preference, Object newValue) {
     68         final boolean allowReminders = (Boolean) newValue;
     69         if (ZenModeSettingsBase.DEBUG) {
     70             Log.d(TAG, "onPrefChange allowReminders=" + allowReminders);
     71         }
     72         mMetricsFeatureProvider.action(mContext,
     73                 MetricsProto.MetricsEvent.ACTION_ZEN_ALLOW_REMINDERS, allowReminders);
     74         mBackend.saveSoundPolicy(NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS,
     75                 allowReminders);
     76         return true;
     77     }
     78 }
     79