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
This commit is contained in:
@@ -1229,4 +1229,17 @@
|
|||||||
<item>6</item>
|
<item>6</item>
|
||||||
</string-array>
|
</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>
|
</resources>
|
||||||
|
@@ -5005,4 +5005,11 @@
|
|||||||
shown in notifications shown on a secure lock screen
|
shown in notifications shown on a secure lock screen
|
||||||
[CHAR LIMIT=50] -->
|
[CHAR LIMIT=50] -->
|
||||||
<string name="lock_screen_notifications_summary_on">All notification contents will be shown when locked</string>
|
<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>
|
</resources>
|
||||||
|
@@ -109,4 +109,13 @@
|
|||||||
android:title="@string/dock_sounds_enable_title"
|
android:title="@string/dock_sounds_enable_title"
|
||||||
android:defaultValue="false" />
|
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>
|
</PreferenceScreen>
|
||||||
|
@@ -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_AUDIO_SETTINGS = "dock_audio";
|
||||||
private static final String KEY_DOCK_SOUNDS = "dock_sounds";
|
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_DOCK_AUDIO_MEDIA_ENABLED = "dock_audio_media_enabled";
|
||||||
|
private static final String KEY_ZEN_MODE = "zen_mode";
|
||||||
|
|
||||||
private static final String[] NEED_VOICE_CAPABILITY = {
|
private static final String[] NEED_VOICE_CAPABILITY = {
|
||||||
KEY_RINGTONE, KEY_DTMF_TONE, KEY_CATEGORY_CALLS,
|
KEY_RINGTONE, KEY_DTMF_TONE, KEY_CATEGORY_CALLS,
|
||||||
@@ -101,6 +102,7 @@ public class SoundSettings extends SettingsPreferenceFragment implements
|
|||||||
private CheckBoxPreference mDockSounds;
|
private CheckBoxPreference mDockSounds;
|
||||||
private Intent mDockIntent;
|
private Intent mDockIntent;
|
||||||
private CheckBoxPreference mDockAudioMediaEnabled;
|
private CheckBoxPreference mDockAudioMediaEnabled;
|
||||||
|
private ZenModeListPreference mZenModeListPreference;
|
||||||
|
|
||||||
private Handler mHandler = new Handler() {
|
private Handler mHandler = new Handler() {
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
@@ -227,6 +229,9 @@ public class SoundSettings extends SettingsPreferenceFragment implements
|
|||||||
};
|
};
|
||||||
|
|
||||||
initDockSettings();
|
initDockSettings();
|
||||||
|
|
||||||
|
mZenModeListPreference = (ZenModeListPreference) findPreference(KEY_ZEN_MODE);
|
||||||
|
mZenModeListPreference.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
92
src/com/android/settings/ZenModeListPreference.java
Normal file
92
src/com/android/settings/ZenModeListPreference.java
Normal file
@@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user