android:value="true" />
</activity>
+ <activity android:name="Settings$ZenModePrioritySettingsActivity"
+ android:label="@string/zen_mode_priority_settings_title"
+ android:exported="true"
+ android:taskAffinity="">
+ <intent-filter android:priority="1">
+ <action android:name="android.settings.ZEN_MODE_PRIORITY_SETTINGS" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="com.android.settings.SHORTCUT" />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.notification.ZenModePrioritySettings" />
+ <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
+ android:resource="@id/notification_settings" />
+ <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+ android:value="true" />
+ </activity>
+
<activity android:name="Settings$HomeSettingsActivity"
android:label="@string/home_settings"
android:taskAffinity="">
<string name="notification_volume_option_title">Notification volume</string>
<!-- Sound & notification > Sound section: Title for the Interruptions option and associated settings page. [CHAR LIMIT=30] -->
- <string name="zen_mode_settings_title">Interruptions</string>
+ <string name="zen_mode_settings_title">Block interruptions</string>
+
+ <!-- Sound & notification > Sound section: Title for the Priority interruptions option and associated settings page. [CHAR LIMIT=30] -->
+ <string name="zen_mode_priority_settings_title">Priority only allows</string>
<!-- Sound & notification > Sound section: Title for the zen mode option. [CHAR LIMIT=60] -->
<string name="zen_mode_option_title">When calls and notifications arrive</string>
<!-- [CHAR LIMIT=30] Zen mode settings: Exit condition selection dialog, default option -->
<string name="zen_mode_default_option">Until you turn this off</string>
- <!-- [CHAR LIMIT=40] Zen mode settings: Important category text -->
- <string name="zen_mode_important_category">Priority interruptions</string>
-
<!-- [CHAR LIMIT=60] Zen mode settings: Downtime category text -->
<string name="zen_mode_downtime_category">Downtime</string>
<!-- [CHAR LIMIT=30] Zen mode settings: From option value: Starred contacts -->
<string name="zen_mode_from_starred">Starred contacts only</string>
- <!-- [CHAR LIMIT=50] Zen mode settings: Events option -->
- <string name="zen_mode_events">Events and reminders</string>
+ <!-- [CHAR LIMIT=50] Zen mode settings: Alarms option -->
+ <string name="zen_mode_alarms">Alarms</string>
- <!-- [CHAR LIMIT=80] Zen mode settings: Reminder text about alarms -->
- <string name="zen_mode_alarm_info">Alarms are always priority interruptions</string>
+ <!-- [CHAR LIMIT=50] Zen mode settings: Reminders option -->
+ <string name="zen_mode_reminders">Reminders</string>
+
+ <!-- [CHAR LIMIT=50] Zen mode settings: Events option -->
+ <string name="zen_mode_events">Events</string>
<!-- [CHAR LIMIT=20] Zen mode settings: When option -->
<string name="zen_mode_when">Automatically turn on</string>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2015 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ android:key="zen_mode_settings"
+ android:title="@string/zen_mode_priority_settings_title" >
+
+ <!-- Alarms -->
+ <SwitchPreference
+ android:key="alarms"
+ android:title="@string/zen_mode_alarms"
+ android:enabled="false"
+ android:defaultValue="true"
+ android:persistent="false"
+ android:switchTextOff=""
+ android:switchTextOn="" />
+
+ <!-- Reminders -->
+ <SwitchPreference
+ android:key="reminders"
+ android:title="@string/zen_mode_reminders"
+ android:persistent="false"
+ android:switchTextOff=""
+ android:switchTextOn="" />
+
+ <!-- Events -->
+ <SwitchPreference
+ android:key="events"
+ android:title="@string/zen_mode_events"
+ android:persistent="false"
+ android:switchTextOff=""
+ android:switchTextOn="" />
+
+ <!-- Messages -->
+ <SwitchPreference
+ android:key="messages"
+ android:title="@string/zen_mode_messages"
+ android:persistent="false"
+ android:switchTextOff=""
+ android:switchTextOn="" />
+
+ <!-- Calls -->
+ <SwitchPreference
+ android:key="calls"
+ android:title="@string/zen_mode_calls"
+ android:persistent="false"
+ android:switchTextOff=""
+ android:switchTextOn="" />
+
+ <!-- Messages/calls from -->
+ <com.android.settings.DropDownPreference
+ android:key="starred"
+ android:title="@string/zen_mode_from"
+ android:persistent="false" />
+
+</PreferenceScreen>
android:title="@string/zen_mode_option_title"
android:persistent="false" />
- <PreferenceCategory
- android:key="important"
- android:title="@string/zen_mode_important_category" >
-
- <SwitchPreference
- android:key="events"
- android:title="@string/zen_mode_events"
- android:persistent="false"
- android:switchTextOff=""
- android:switchTextOn="" />
-
- <SwitchPreference
- android:key="calls"
- android:title="@string/zen_mode_calls"
- android:persistent="false"
- android:switchTextOff=""
- android:switchTextOn="" />
-
- <SwitchPreference
- android:key="messages"
- android:title="@string/zen_mode_messages"
- android:persistent="false"
- android:switchTextOff=""
- android:switchTextOn="" />
-
- <com.android.settings.DropDownPreference
- android:key="starred"
- android:title="@string/zen_mode_from"
- android:persistent="false" />
-
- <Preference
- android:key="alarm_info"
- android:title=""
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="?android:attr/colorForegroundInverse"
- android:selectable="false"
- android:summary="@string/zen_mode_alarm_info" />
-
- </PreferenceCategory>
+ <!-- Priority only allows -->
+ <PreferenceScreen
+ android:key="priority_settings"
+ android:title="@string/zen_mode_priority_settings_title"
+ android:fragment="com.android.settings.notification.ZenModePrioritySettings" />
<!-- Downtime -->
<PreferenceCategory
public static class PrintSettingsActivity extends SettingsActivity { /* empty */ }
public static class PrintJobSettingsActivity extends SettingsActivity { /* empty */ }
public static class ZenModeSettingsActivity extends SettingsActivity { /* empty */ }
+ public static class ZenModePrioritySettingsActivity extends SettingsActivity { /* empty */ }
public static class NotificationSettingsActivity extends SettingsActivity { /* empty */ }
public static class NotificationAppListActivity extends SettingsActivity { /* empty */ }
public static class AppNotificationSettingsActivity extends SettingsActivity { /* empty */ }
--- /dev/null
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.notification;
+
+import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.preference.PreferenceScreen;
+import android.preference.SwitchPreference;
+import android.service.notification.ZenModeConfig;
+import android.util.Log;
+
+import com.android.internal.logging.MetricsLogger;
+import com.android.settings.DropDownPreference;
+import com.android.settings.R;
+import com.android.settings.search.Indexable;
+
+public class ZenModePrioritySettings extends ZenModeSettingsBase implements Indexable {
+ private static final String KEY_REMINDERS = "reminders";
+ private static final String KEY_EVENTS = "events";
+ private static final String KEY_MESSAGES = "messages";
+ private static final String KEY_CALLS = "calls";
+ private static final String KEY_STARRED = "starred";
+
+ private boolean mDisableListeners;
+ private SwitchPreference mReminders;
+ private SwitchPreference mEvents;
+ private SwitchPreference mMessages;
+ private SwitchPreference mCalls;
+ private DropDownPreference mStarred;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.zen_mode_priority_settings);
+ final PreferenceScreen root = getPreferenceScreen();
+
+ mReminders = (SwitchPreference) root.findPreference(KEY_REMINDERS);
+ mReminders.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mDisableListeners) return true;
+ final boolean val = (Boolean) newValue;
+ if (val == mConfig.allowReminders) return true;
+ if (DEBUG) Log.d(TAG, "onPrefChange allowReminders=" + val);
+ final ZenModeConfig newConfig = mConfig.copy();
+ newConfig.allowReminders = val;
+ return setZenModeConfig(newConfig);
+ }
+ });
+
+ mEvents = (SwitchPreference) root.findPreference(KEY_EVENTS);
+ mEvents.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mDisableListeners) return true;
+ final boolean val = (Boolean) newValue;
+ if (val == mConfig.allowEvents) return true;
+ if (DEBUG) Log.d(TAG, "onPrefChange allowEvents=" + val);
+ final ZenModeConfig newConfig = mConfig.copy();
+ newConfig.allowEvents = val;
+ return setZenModeConfig(newConfig);
+ }
+ });
+
+ mMessages = (SwitchPreference) root.findPreference(KEY_MESSAGES);
+ mMessages.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mDisableListeners) return true;
+ final boolean val = (Boolean) newValue;
+ if (val == mConfig.allowMessages) return true;
+ if (DEBUG) Log.d(TAG, "onPrefChange allowMessages=" + val);
+ final ZenModeConfig newConfig = mConfig.copy();
+ newConfig.allowMessages = val;
+ return setZenModeConfig(newConfig);
+ }
+ });
+
+ mCalls = (SwitchPreference) root.findPreference(KEY_CALLS);
+ mCalls.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mDisableListeners) return true;
+ final boolean val = (Boolean) newValue;
+ if (val == mConfig.allowCalls) return true;
+ if (DEBUG) Log.d(TAG, "onPrefChange allowCalls=" + val);
+ final ZenModeConfig newConfig = mConfig.copy();
+ newConfig.allowCalls = val;
+ return setZenModeConfig(newConfig);
+ }
+ });
+
+ mStarred = (DropDownPreference) root.findPreference(KEY_STARRED);
+ mStarred.addItem(R.string.zen_mode_from_anyone, ZenModeConfig.SOURCE_ANYONE);
+ mStarred.addItem(R.string.zen_mode_from_contacts, ZenModeConfig.SOURCE_CONTACT);
+ mStarred.addItem(R.string.zen_mode_from_starred, ZenModeConfig.SOURCE_STAR);
+ mStarred.setCallback(new DropDownPreference.Callback() {
+ @Override
+ public boolean onItemSelected(int pos, Object newValue) {
+ if (mDisableListeners) return true;
+ final int val = (Integer) newValue;
+ if (val == mConfig.allowFrom) return true;
+ if (DEBUG) Log.d(TAG, "onPrefChange allowFrom=" +
+ ZenModeConfig.sourceToString(val));
+ final ZenModeConfig newConfig = mConfig.copy();
+ newConfig.allowFrom = val;
+ return setZenModeConfig(newConfig);
+ }
+ });
+
+ updateControls();
+ }
+
+ @Override
+ protected void onZenModeChanged() {
+ // don't care
+ }
+
+ @Override
+ protected void updateControls() {
+ mDisableListeners = true;
+ if (mCalls != null) {
+ mCalls.setChecked(mConfig.allowCalls);
+ }
+ mMessages.setChecked(mConfig.allowMessages);
+ mStarred.setSelectedValue(mConfig.allowFrom);
+ mReminders.setChecked(mConfig.allowReminders);
+ mEvents.setChecked(mConfig.allowEvents);
+ updateStarredEnabled();
+ mDisableListeners = false;
+ }
+
+ @Override
+ protected int getMetricsCategory() {
+ return MetricsLogger.NOTIFICATION_ZEN_MODE_PRIORITY;
+ }
+
+ private void updateStarredEnabled() {
+ mStarred.setEnabled(mConfig.allowCalls || mConfig.allowMessages);
+ }
+
+}
import android.content.DialogInterface.OnDismissListener;
import android.content.pm.PackageManager;
import android.content.res.Resources;
-import android.database.ContentObserver;
-import android.net.Uri;
import android.os.Bundle;
-import android.os.Handler;
import android.os.ServiceManager;
import android.preference.Preference;
-import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
-import android.preference.SwitchPreference;
import android.provider.Settings.Global;
import android.service.notification.Condition;
import android.service.notification.ZenModeConfig;
import java.util.List;
import java.util.Objects;
-public class ZenModeSettings extends SettingsPreferenceFragment implements Indexable {
- private static final String TAG = "ZenModeSettings";
- private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
-
+public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
private static final String KEY_ZEN_MODE = "zen_mode";
- private static final String KEY_IMPORTANT = "important";
- private static final String KEY_CALLS = "calls";
- private static final String KEY_MESSAGES = "messages";
- private static final String KEY_STARRED = "starred";
- private static final String KEY_EVENTS = "events";
- private static final String KEY_ALARM_INFO = "alarm_info";
-
+ private static final String KEY_PRIORITY_SETTINGS = "priority_settings";
private static final String KEY_DOWNTIME = "downtime";
private static final String KEY_DAYS = "days";
private static final String KEY_START_TIME = "start_time";
private static SparseArray<String> allKeyTitles(Context context) {
final SparseArray<String> rt = new SparseArray<String>();
- rt.put(R.string.zen_mode_important_category, KEY_IMPORTANT);
- rt.put(R.string.zen_mode_calls, KEY_CALLS);
rt.put(R.string.zen_mode_option_title, KEY_ZEN_MODE);
- rt.put(R.string.zen_mode_messages, KEY_MESSAGES);
- rt.put(R.string.zen_mode_from_starred, KEY_STARRED);
- rt.put(R.string.zen_mode_events, KEY_EVENTS);
- rt.put(R.string.zen_mode_alarm_info, KEY_ALARM_INFO);
+ rt.put(R.string.zen_mode_priority_settings_title, KEY_PRIORITY_SETTINGS);
rt.put(R.string.zen_mode_downtime_category, KEY_DOWNTIME);
rt.put(R.string.zen_mode_downtime_days, KEY_DAYS);
rt.put(R.string.zen_mode_start_time, KEY_START_TIME);
return rt;
}
- private final Handler mHandler = new Handler();
- private final SettingsObserver mSettingsObserver = new SettingsObserver();
-
- private Context mContext;
private PackageManager mPM;
- private ZenModeConfig mConfig;
private boolean mDisableListeners;
- private SwitchPreference mCalls;
- private SwitchPreference mMessages;
- private DropDownPreference mStarred;
- private SwitchPreference mEvents;
private boolean mDowntimeSupported;
+ private Preference mPrioritySettings;
private Preference mDays;
private TimePickerPreference mStart;
private TimePickerPreference mEnd;
}
@Override
+ protected void onZenModeChanged() {
+ PREF_ZEN_MODE.update(mContext);
+ }
+
+ @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mContext = getActivity();
mPM = mContext.getPackageManager();
addPreferencesFromResource(R.xml.zen_mode_settings);
final PreferenceScreen root = getPreferenceScreen();
- mConfig = getZenModeConfig();
- if (DEBUG) Log.d(TAG, "Loaded mConfig=" + mConfig);
-
PREF_ZEN_MODE.init(this);
PREF_ZEN_MODE.setCallback(new SettingPrefWithCallback.Callback() {
@Override
}
});
- final PreferenceCategory important =
- (PreferenceCategory) root.findPreference(KEY_IMPORTANT);
-
- mCalls = (SwitchPreference) important.findPreference(KEY_CALLS);
- mCalls.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- if (mDisableListeners) return true;
- final boolean val = (Boolean) newValue;
- if (val == mConfig.allowCalls) return true;
- if (DEBUG) Log.d(TAG, "onPrefChange allowCalls=" + val);
- final ZenModeConfig newConfig = mConfig.copy();
- newConfig.allowCalls = val;
- return setZenModeConfig(newConfig);
- }
- });
-
- mMessages = (SwitchPreference) important.findPreference(KEY_MESSAGES);
- mMessages.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- if (mDisableListeners) return true;
- final boolean val = (Boolean) newValue;
- if (val == mConfig.allowMessages) return true;
- if (DEBUG) Log.d(TAG, "onPrefChange allowMessages=" + val);
- final ZenModeConfig newConfig = mConfig.copy();
- newConfig.allowMessages = val;
- return setZenModeConfig(newConfig);
- }
- });
-
- mStarred = (DropDownPreference) important.findPreference(KEY_STARRED);
- mStarred.addItem(R.string.zen_mode_from_anyone, ZenModeConfig.SOURCE_ANYONE);
- mStarred.addItem(R.string.zen_mode_from_contacts, ZenModeConfig.SOURCE_CONTACT);
- mStarred.addItem(R.string.zen_mode_from_starred, ZenModeConfig.SOURCE_STAR);
- mStarred.setCallback(new DropDownPreference.Callback() {
- @Override
- public boolean onItemSelected(int pos, Object newValue) {
- if (mDisableListeners) return true;
- final int val = (Integer) newValue;
- if (val == mConfig.allowFrom) return true;
- if (DEBUG) Log.d(TAG, "onPrefChange allowFrom=" +
- ZenModeConfig.sourceToString(val));
- final ZenModeConfig newConfig = mConfig.copy();
- newConfig.allowFrom = val;
- return setZenModeConfig(newConfig);
- }
- });
- important.addPreference(mStarred);
-
- mEvents = (SwitchPreference) important.findPreference(KEY_EVENTS);
- mEvents.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- if (mDisableListeners) return true;
- final boolean val = (Boolean) newValue;
- if (val == mConfig.allowEvents) return true;
- if (DEBUG) Log.d(TAG, "onPrefChange allowEvents=" + val);
- final ZenModeConfig newConfig = mConfig.copy();
- newConfig.allowEvents = val;
- return setZenModeConfig(newConfig);
- }
- });
+ mPrioritySettings = root.findPreference(KEY_PRIORITY_SETTINGS);
final PreferenceCategory downtime = (PreferenceCategory) root.findPreference(KEY_DOWNTIME);
mDowntimeSupported = isDowntimeSupported(mContext);
mEnd.setSummaryFormat(summaryFormat);
}
- private void updateControls() {
+ @Override
+ protected void updateControls() {
mDisableListeners = true;
- if (mCalls != null) {
- mCalls.setChecked(mConfig.allowCalls);
- }
- mMessages.setChecked(mConfig.allowMessages);
- mStarred.setSelectedValue(mConfig.allowFrom);
- mEvents.setChecked(mConfig.allowEvents);
- updateStarredEnabled();
if (mDowntimeSupported) {
updateDays();
mStart.setTime(mConfig.sleepStartHour, mConfig.sleepStartMinute);
mDisableListeners = false;
refreshAutomationSection();
updateEndSummary();
+ updatePrioritySettingsSummary();
}
- private void updateStarredEnabled() {
- mStarred.setEnabled(mConfig.allowCalls || mConfig.allowMessages);
+ private void updatePrioritySettingsSummary() {
+ String s = getResources().getString(R.string.zen_mode_alarms);
+ s = appendLowercase(s, mConfig.allowReminders, R.string.zen_mode_reminders);
+ s = appendLowercase(s, mConfig.allowEvents, R.string.zen_mode_events);
+ s = appendLowercase(s, mConfig.allowCalls, R.string.zen_mode_calls);
+ s = appendLowercase(s, mConfig.allowMessages, R.string.zen_mode_messages);
+ mPrioritySettings.setSummary(s);
+ }
+
+ private String appendLowercase(String s, boolean condition, int resId) {
+ if (condition) {
+ return getResources().getString(R.string.join_many_items_middle, s,
+ getResources().getString(resId).toLowerCase());
+ }
+ return s;
}
private void refreshAutomationSection() {
}
}
- @Override
- public void onResume() {
- super.onResume();
- updateControls();
- mSettingsObserver.register();
- }
-
- @Override
- public void onPause() {
- super.onPause();
- mSettingsObserver.unregister();
- }
-
- private void updateZenModeConfig() {
- final ZenModeConfig config = getZenModeConfig();
- if (Objects.equals(config, mConfig)) return;
- mConfig = config;
- if (DEBUG) Log.d(TAG, "updateZenModeConfig mConfig=" + mConfig);
- updateControls();
- }
-
- private ZenModeConfig getZenModeConfig() {
- final INotificationManager nm = INotificationManager.Stub.asInterface(
- ServiceManager.getService(Context.NOTIFICATION_SERVICE));
- try {
- return nm.getZenModeConfig();
- } catch (Exception e) {
- Log.w(TAG, "Error calling NoMan", e);
- return new ZenModeConfig();
- }
- }
-
- private boolean setZenModeConfig(ZenModeConfig config) {
- final INotificationManager nm = INotificationManager.Stub.asInterface(
- ServiceManager.getService(Context.NOTIFICATION_SERVICE));
- try {
- final boolean success = nm.setZenModeConfig(config);
- if (success) {
- mConfig = config;
- if (DEBUG) Log.d(TAG, "Saved mConfig=" + mConfig);
- updateEndSummary();
- updateStarredEnabled();
- }
- return success;
- } catch (Exception e) {
- Log.w(TAG, "Error calling NoMan", e);
- return false;
- }
- }
-
protected void putZenModeSetting(int value) {
Global.putInt(getContentResolver(), Global.ZEN_MODE, value);
}
}
}
- private final class SettingsObserver extends ContentObserver {
- private final Uri ZEN_MODE_URI = Global.getUriFor(Global.ZEN_MODE);
- private final Uri ZEN_MODE_CONFIG_ETAG_URI = Global.getUriFor(Global.ZEN_MODE_CONFIG_ETAG);
-
- public SettingsObserver() {
- super(mHandler);
- }
-
- public void register() {
- getContentResolver().registerContentObserver(ZEN_MODE_URI, false, this);
- getContentResolver().registerContentObserver(ZEN_MODE_CONFIG_ETAG_URI, false, this);
- }
-
- public void unregister() {
- getContentResolver().unregisterContentObserver(this);
- }
-
- @Override
- public void onChange(boolean selfChange, Uri uri) {
- super.onChange(selfChange, uri);
- if (ZEN_MODE_URI.equals(uri)) {
- PREF_ZEN_MODE.update(mContext);
- }
- if (ZEN_MODE_CONFIG_ETAG_URI.equals(uri)) {
- updateZenModeConfig();
- }
- }
- }
-
private static class TimePickerPreference extends Preference {
private final Context mContext;
--- /dev/null
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.notification;
+
+import android.app.INotificationManager;
+import android.content.Context;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.ServiceManager;
+import android.provider.Settings.Global;
+import android.service.notification.ZenModeConfig;
+import android.util.Log;
+
+import com.android.settings.SettingsPreferenceFragment;
+
+import java.util.Objects;
+
+abstract public class ZenModeSettingsBase extends SettingsPreferenceFragment {
+ protected static final String TAG = "ZenModeSettings";
+ protected static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+
+ private final Handler mHandler = new Handler();
+ private final SettingsObserver mSettingsObserver = new SettingsObserver();
+
+ protected Context mContext;
+ protected ZenModeConfig mConfig;
+
+ abstract protected void onZenModeChanged();
+ abstract protected void updateControls();
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ mContext = getActivity();
+ mConfig = getZenModeConfig();
+ if (DEBUG) Log.d(TAG, "Loaded mConfig=" + mConfig);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ mConfig = getZenModeConfig();
+ updateControls();
+ mSettingsObserver.register();
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ mSettingsObserver.unregister();
+ }
+
+ protected boolean setZenModeConfig(ZenModeConfig config) {
+ final INotificationManager nm = INotificationManager.Stub.asInterface(
+ ServiceManager.getService(Context.NOTIFICATION_SERVICE));
+ try {
+ final boolean success = nm.setZenModeConfig(config);
+ if (success) {
+ mConfig = config;
+ if (DEBUG) Log.d(TAG, "Saved mConfig=" + mConfig);
+ updateControls();
+ }
+ return success;
+ } catch (Exception e) {
+ Log.w(TAG, "Error calling NoMan", e);
+ return false;
+ }
+ }
+
+ private void updateZenModeConfig() {
+ final ZenModeConfig config = getZenModeConfig();
+ if (Objects.equals(config, mConfig)) return;
+ mConfig = config;
+ if (DEBUG) Log.d(TAG, "updateZenModeConfig mConfig=" + mConfig);
+ updateControls();
+ }
+
+ private ZenModeConfig getZenModeConfig() {
+ final INotificationManager nm = INotificationManager.Stub.asInterface(
+ ServiceManager.getService(Context.NOTIFICATION_SERVICE));
+ try {
+ return nm.getZenModeConfig();
+ } catch (Exception e) {
+ Log.w(TAG, "Error calling NoMan", e);
+ return new ZenModeConfig();
+ }
+ }
+
+ private final class SettingsObserver extends ContentObserver {
+ private final Uri ZEN_MODE_URI = Global.getUriFor(Global.ZEN_MODE);
+ private final Uri ZEN_MODE_CONFIG_ETAG_URI = Global.getUriFor(Global.ZEN_MODE_CONFIG_ETAG);
+
+ private SettingsObserver() {
+ super(mHandler);
+ }
+
+ public void register() {
+ getContentResolver().registerContentObserver(ZEN_MODE_URI, false, this);
+ getContentResolver().registerContentObserver(ZEN_MODE_CONFIG_ETAG_URI, false, this);
+ }
+
+ public void unregister() {
+ getContentResolver().unregisterContentObserver(this);
+ }
+
+ @Override
+ public void onChange(boolean selfChange, Uri uri) {
+ super.onChange(selfChange, uri);
+ if (ZEN_MODE_URI.equals(uri)) {
+ onZenModeChanged();
+ }
+ if (ZEN_MODE_CONFIG_ETAG_URI.equals(uri)) {
+ updateZenModeConfig();
+ }
+ }
+ }
+}
import com.android.settings.net.DataUsageMeteredSettings;
import com.android.settings.notification.NotificationSettings;
import com.android.settings.notification.OtherSoundSettings;
+import com.android.settings.notification.ZenModePrioritySettings;
import com.android.settings.notification.ZenModeSettings;
import com.android.settings.print.PrintSettingsFragment;
import com.android.settings.sim.SimSettings;
sRankMap.put(NotificationSettings.class.getName(), RANK_NOTIFICATIONS);
sRankMap.put(OtherSoundSettings.class.getName(), RANK_NOTIFICATIONS);
sRankMap.put(ZenModeSettings.class.getName(), RANK_NOTIFICATIONS);
+ sRankMap.put(ZenModePrioritySettings.class.getName(), RANK_NOTIFICATIONS);
// Storage
sRankMap.put(Memory.class.getName(), RANK_STORAGE);
import com.android.settings.net.DataUsageMeteredSettings;
import com.android.settings.notification.NotificationSettings;
import com.android.settings.notification.OtherSoundSettings;
+import com.android.settings.notification.ZenModePrioritySettings;
import com.android.settings.notification.ZenModeSettings;
import com.android.settings.print.PrintSettingsFragment;
import com.android.settings.sim.SimSettings;
ZenModeSettings.class.getName(),
R.drawable.ic_settings_notifications));
+ sResMap.put(ZenModePrioritySettings.class.getName(),
+ new SearchIndexableResource(
+ Ranking.getRankForClassName(ZenModePrioritySettings.class.getName()),
+ R.xml.zen_mode_priority_settings,
+ ZenModePrioritySettings.class.getName(),
+ R.drawable.ic_settings_notifications));
+
sResMap.put(Memory.class.getName(),
new SearchIndexableResource(
Ranking.getRankForClassName(Memory.class.getName()),