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.Fragment; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.support.v7.preference.Preference; 23 import android.support.v7.preference.PreferenceScreen; 24 import com.android.settingslib.core.lifecycle.Lifecycle; 25 26 import com.android.settings.utils.ZenServiceListing; 27 28 public class ZenModeAddAutomaticRulePreferenceController extends 29 AbstractZenModeAutomaticRulePreferenceController implements 30 Preference.OnPreferenceClickListener { 31 32 protected static final String KEY = "zen_mode_add_automatic_rule"; 33 private final ZenServiceListing mZenServiceListing; 34 35 public ZenModeAddAutomaticRulePreferenceController(Context context, Fragment parent, 36 ZenServiceListing serviceListing, Lifecycle lifecycle) { 37 super(context, KEY, parent, lifecycle); 38 mZenServiceListing = serviceListing; 39 } 40 41 @Override 42 public String getPreferenceKey() { 43 return 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 Preference pref = screen.findPreference(KEY); 55 pref.setPersistent(false); 56 pref.setOnPreferenceClickListener(this); 57 } 58 59 @Override 60 public boolean onPreferenceClick(Preference preference) { 61 ZenRuleSelectionDialog.show(mContext, mParent, new RuleSelectionListener(), 62 mZenServiceListing); 63 return true; 64 } 65 66 public class RuleSelectionListener implements ZenRuleSelectionDialog.PositiveClickListener { 67 public RuleSelectionListener() {} 68 69 @Override 70 public void onSystemRuleSelected(ZenRuleInfo ri, Fragment parent) { 71 showNameRuleDialog(ri, parent); 72 } 73 74 @Override 75 public void onExternalRuleSelected(ZenRuleInfo ri, Fragment parent) { 76 Intent intent = new Intent().setComponent(ri.configurationActivity); 77 parent.startActivity(intent); 78 } 79 } 80 } 81