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.zen; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.os.Bundle; 22 import android.service.notification.ZenPolicy; 23 24 import androidx.preference.Preference; 25 import androidx.preference.PreferenceScreen; 26 27 import com.android.settings.R; 28 import com.android.settingslib.core.AbstractPreferenceController; 29 import com.android.settingslib.widget.FooterPreference; 30 31 import java.util.ArrayList; 32 import java.util.List; 33 34 public class ZenCustomRuleCallsSettings extends ZenCustomRuleSettingsBase { 35 private static final String CALLS_KEY = "zen_mode_calls"; 36 private static final String REPEAT_CALLERS_KEY = "zen_mode_repeat_callers"; 37 private static final String STARRED_CONTACTS_KEY = "zen_mode_starred_contacts_callers"; 38 private static final String PREFERENCE_CATEGORY_KEY = "zen_mode_settings_category_calls"; 39 40 @Override onCreate(Bundle bundle)41 public void onCreate(Bundle bundle) { 42 super.onCreate(bundle); 43 } 44 45 @Override getPreferenceScreenResId()46 protected int getPreferenceScreenResId() { 47 return com.android.settings.R.xml.zen_mode_custom_rule_calls_settings; 48 } 49 50 @Override getMetricsCategory()51 public int getMetricsCategory() { 52 return SettingsEnums.ZEN_CUSTOM_RULE_CALLS; 53 } 54 55 @Override createPreferenceControllers(Context context)56 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 57 mControllers = new ArrayList<>(); 58 mControllers.add(new ZenRuleCallsPreferenceController(context, CALLS_KEY, 59 getSettingsLifecycle())); 60 mControllers.add(new ZenRuleRepeatCallersPreferenceController(context, 61 REPEAT_CALLERS_KEY, getSettingsLifecycle(), context.getResources() 62 .getInteger(com.android.internal.R.integer.config_zen_repeat_callers_threshold))); 63 mControllers.add(new ZenRuleStarredContactsPreferenceController(context, 64 getSettingsLifecycle(), ZenPolicy.PRIORITY_CATEGORY_CALLS, STARRED_CONTACTS_KEY)); 65 return mControllers; 66 } 67 68 @Override getPreferenceCategoryKey()69 String getPreferenceCategoryKey() { 70 return PREFERENCE_CATEGORY_KEY; 71 } 72 73 @Override updatePreferences()74 public void updatePreferences() { 75 super.updatePreferences(); 76 PreferenceScreen screen = getPreferenceScreen(); 77 Preference footerPreference = screen.findPreference(FooterPreference.KEY_FOOTER); 78 footerPreference.setTitle(mContext.getResources().getString( 79 R.string.zen_mode_custom_calls_footer, mRule.getName())); 80 } 81 } 82