summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Spurlock <jspurlock@google.com>2014-02-27 15:37:13 -0500
committerJohn Spurlock <jspurlock@google.com>2014-02-27 15:43:40 -0500
commitadda1b0022f12dd15a802ec36e6efee0f9c6bff2 (patch)
tree64894e05cdc49157a58c9bde30e916cb90097c21
parent76dcc66f4a39dfe95c2ef886bc1b5fba02135e27 (diff)
downloadpackages_apps_Settings-adda1b0022f12dd15a802ec36e6efee0f9c6bff2.zip
packages_apps_Settings-adda1b0022f12dd15a802ec36e6efee0f9c6bff2.tar.gz
packages_apps_Settings-adda1b0022f12dd15a802ec36e6efee0f9c6bff2.tar.bz2
Zen mode settings.
Step 1: Surface zen mode value under sound settings. This is in keeping with the principle that quick settings are accelerators (not replacements) for settings in the Settings app. Adding configuration to "Limited interruptions" will be done as a followup, and will serve as the target for the configuration icon in SystemUI. Change-Id: Ia2c7351454b17df3e27926ff593eebff284ebef8
-rw-r--r--res/values/arrays.xml13
-rw-r--r--res/values/strings.xml7
-rw-r--r--res/xml/sound_settings.xml9
-rw-r--r--src/com/android/settings/SoundSettings.java5
-rw-r--r--src/com/android/settings/ZenModeListPreference.java92
5 files changed, 126 insertions, 0 deletions
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 2e22d46..6d0cd76 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -1229,4 +1229,17 @@
<item>6</item>
</string-array>
+ <!-- Setting display values for zen mode -->
+ <string-array name="entries_zen_mode">
+ <item>Off</item>
+ <item>Limited interruptions</item>
+ <item>Zero interruptions</item>
+ </string-array>
+
+ <!-- Setting values for zen mode, must match the Settings.Global.ZEN_MODE_ constants -->
+ <string-array name="entryvalues_zen_mode" translatable="false">
+ <item>0</item>
+ <item>1</item>
+ <item>2</item>
+ </string-array>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b42c88c..612677b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5005,4 +5005,11 @@
shown in notifications shown on a secure lock screen
[CHAR LIMIT=50] -->
<string name="lock_screen_notifications_summary_on">All notification contents will be shown when locked</string>
+
+ <!-- [CHAR LIMIT=30] Sound settings screen, setting option name to change zen mode -->
+ <string name="title_zen_mode">Zen mode</string>
+ <!-- [CHAR LIMIT=30] Sound settings screen, setting option summary displaying the currently selected zen mode -->
+ <string name="summary_zen_mode" translatable="false">%1$s</string>
+ <!-- [CHAR LIMIT=40] Sound settings screen, title of dialog for picking zen mode -->
+ <string name="dialog_title_zen_mode">Zen mode</string>
</resources>
diff --git a/res/xml/sound_settings.xml b/res/xml/sound_settings.xml
index 26e2e20..580b6d5 100644
--- a/res/xml/sound_settings.xml
+++ b/res/xml/sound_settings.xml
@@ -109,4 +109,13 @@
android:title="@string/dock_sounds_enable_title"
android:defaultValue="false" />
+ <com.android.settings.ZenModeListPreference
+ android:key="zen_mode"
+ android:persistent="false"
+ android:title="@string/title_zen_mode"
+ android:summary="@string/summary_zen_mode"
+ android:entries="@array/entries_zen_mode"
+ android:entryValues="@array/entryvalues_zen_mode"
+ android:dialogTitle="@string/dialog_title_zen_mode" />
+
</PreferenceScreen>
diff --git a/src/com/android/settings/SoundSettings.java b/src/com/android/settings/SoundSettings.java
index 28d93f1..d506864 100644
--- a/src/com/android/settings/SoundSettings.java
+++ b/src/com/android/settings/SoundSettings.java
@@ -75,6 +75,7 @@ public class SoundSettings extends SettingsPreferenceFragment implements
private static final String KEY_DOCK_AUDIO_SETTINGS = "dock_audio";
private static final String KEY_DOCK_SOUNDS = "dock_sounds";
private static final String KEY_DOCK_AUDIO_MEDIA_ENABLED = "dock_audio_media_enabled";
+ private static final String KEY_ZEN_MODE = "zen_mode";
private static final String[] NEED_VOICE_CAPABILITY = {
KEY_RINGTONE, KEY_DTMF_TONE, KEY_CATEGORY_CALLS,
@@ -101,6 +102,7 @@ public class SoundSettings extends SettingsPreferenceFragment implements
private CheckBoxPreference mDockSounds;
private Intent mDockIntent;
private CheckBoxPreference mDockAudioMediaEnabled;
+ private ZenModeListPreference mZenModeListPreference;
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
@@ -227,6 +229,9 @@ public class SoundSettings extends SettingsPreferenceFragment implements
};
initDockSettings();
+
+ mZenModeListPreference = (ZenModeListPreference) findPreference(KEY_ZEN_MODE);
+ mZenModeListPreference.init();
}
@Override
diff --git a/src/com/android/settings/ZenModeListPreference.java b/src/com/android/settings/ZenModeListPreference.java
new file mode 100644
index 0000000..0315a13
--- /dev/null
+++ b/src/com/android/settings/ZenModeListPreference.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2014 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;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.database.ContentObserver;
+import android.os.Handler;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.provider.Settings;
+import android.util.AttributeSet;
+import android.util.Log;
+
+public class ZenModeListPreference extends ListPreference {
+ private static final String TAG = "ZenModeListPreference";
+ private static final boolean DEBUG = false;
+
+ private final Handler mHandler = new Handler();
+ private final ContentResolver mResolver;
+
+ public ZenModeListPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ if (DEBUG) Log.d(TAG, "new ZenModeListPreference()");
+ mResolver = context.getContentResolver();
+ }
+
+ public void init() {
+ if (DEBUG) Log.d(TAG, "init");
+ loadZenModeSetting("init");
+ setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (DEBUG) Log.d(TAG, "onPreferenceChange " + newValue);
+ final boolean updateWithNewValue = saveZenModeSetting((String)newValue);
+ return updateWithNewValue;
+ }
+ });
+ mResolver.registerContentObserver(
+ Settings.Global.getUriFor(Settings.Global.ZEN_MODE),
+ false, new SettingsObserver());
+ }
+
+ private void loadZenModeSetting(String reason) {
+ if (DEBUG) Log.d(TAG, "loadZenModeSetting " + reason);
+ setValue(Integer.toString(Settings.Global.getInt(mResolver,
+ Settings.Global.ZEN_MODE, Settings.Global.ZEN_MODE_OFF)));
+ }
+
+ private boolean saveZenModeSetting(String value) {
+ if (DEBUG) Log.d(TAG, "saveZenModeSetting " + value);
+ try {
+ final int v = Integer.valueOf(value);
+ checkZenMode(v);
+ return Settings.Global.putInt(mResolver, Settings.Global.ZEN_MODE, v);
+ } catch (Throwable t) {
+ Log.w(TAG, "Failed to update zen mode with value: " + value, t);
+ return false;
+ }
+ }
+
+ private static void checkZenMode(int mode) {
+ if (mode < Settings.Global.ZEN_MODE_OFF || mode > Settings.Global.ZEN_MODE_FULL) {
+ throw new IllegalArgumentException("Invalid zen mode: " + mode);
+ }
+ }
+
+ private final class SettingsObserver extends ContentObserver {
+ public SettingsObserver() {
+ super(mHandler);
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ loadZenModeSetting("change");
+ }
+ }
+}