2 * Copyright (C) 2014 The Android Open Source Project
3 * Copyright (C) 2016 The CyanogenMod Project
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package com.android.settings.notification;
20 import android.content.Context;
21 import android.content.res.Resources;
22 import android.os.Bundle;
23 import android.preference.Preference;
24 import android.preference.PreferenceScreen;
25 import android.util.SparseArray;
27 import com.android.internal.logging.MetricsLogger;
28 import com.android.settings.R;
29 import com.android.settings.Utils;
30 import com.android.settings.search.BaseSearchIndexProvider;
31 import com.android.settings.search.Indexable;
32 import com.android.settings.search.SearchIndexableRaw;
34 import java.util.ArrayList;
35 import java.util.List;
37 public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
38 private static final String KEY_PRIORITY_SETTINGS = "priority_settings";
39 private static final String KEY_AUTOMATION_SETTINGS = "automation_settings";
40 private static final String KEY_ZEN_ACCESS = "manage_zen_access";
42 private Preference mPrioritySettings;
43 private Preference mZenAccess;
46 public void onCreate(Bundle savedInstanceState) {
47 super.onCreate(savedInstanceState);
49 addPreferencesFromResource(R.xml.zen_mode_settings);
50 final PreferenceScreen root = getPreferenceScreen();
52 mPrioritySettings = root.findPreference(KEY_PRIORITY_SETTINGS);
53 if (!isScheduleSupported(mContext)) {
54 removePreference(KEY_AUTOMATION_SETTINGS);
57 mZenAccess = findPreference(KEY_ZEN_ACCESS);
62 public void onResume() {
69 protected int getMetricsCategory() {
70 return MetricsLogger.NOTIFICATION_ZEN_MODE;
74 protected void onZenModeChanged() {
79 protected void onZenModeConfigChanged() {
83 private void updateControls() {
84 updatePrioritySettingsSummary();
87 private void updatePrioritySettingsSummary() {
88 final ArrayList<String> items = new ArrayList<>();
89 items.add(getString(R.string.zen_mode_alarms));
90 if (mConfig.allowReminders) {
91 items.add(getString(R.string.zen_mode_summary_reminders));
93 if (mConfig.allowEvents) {
94 items.add(getString(R.string.zen_mode_summary_events));
96 if (mConfig.allowCalls || mConfig.allowRepeatCallers) {
97 items.add(getString(R.string.zen_mode_summary_selected_callers));
99 if (mConfig.allowMessages) {
100 items.add(getString(R.string.zen_mode_summary_selected_messages));
102 mPrioritySettings.setSummary(Utils.join(getResources(), items));
105 private static SparseArray<String> allKeyTitles(Context context) {
106 final SparseArray<String> rt = new SparseArray<String>();
107 rt.put(R.string.zen_mode_priority_settings_title, KEY_PRIORITY_SETTINGS);
108 rt.put(R.string.zen_mode_automation_settings_title, KEY_AUTOMATION_SETTINGS);
113 protected int getHelpResource() {
114 return R.string.help_uri_interruptions;
117 // Enable indexing of searchable data
118 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
119 new BaseSearchIndexProvider() {
122 public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
123 final SparseArray<String> keyTitles = allKeyTitles(context);
124 final int N = keyTitles.size();
125 final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>(N);
126 final Resources res = context.getResources();
127 for (int i = 0; i < N; i++) {
128 final SearchIndexableRaw data = new SearchIndexableRaw(context);
129 data.key = keyTitles.valueAt(i);
130 data.title = res.getString(keyTitles.keyAt(i));
131 data.screenTitle = res.getString(R.string.zen_mode_settings_title);
138 public List<String> getNonIndexableKeys(Context context) {
139 final ArrayList<String> rt = new ArrayList<String>();
140 if (!isScheduleSupported(context)) {
141 rt.add(KEY_AUTOMATION_SETTINGS);
147 // === Zen access ===
149 private void refreshZenAccess() {