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