--- /dev/null
+<!--
+ 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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="2dip"
+ android:layout_marginBottom="4dip"
+ android:alpha="?android:attr/disabledAlpha"
+ android:background="#000" />
+
+ <TextView
+ android:id="@android:id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAllCaps="true"
+ android:textStyle="bold" />
+
+</LinearLayout>
\ No newline at end of file
<!-- [CHAR LIMIT=20] Notification settings: App notifications dialog dismiss button caption -->
<string name="app_notifications_dialog_done">Done</string>
+ <!-- [CHAR LIMIT=20] Zen mode settings: Master switch option title, off -->
+ <string name="zen_mode_option_off">Off</string>
+
+ <!-- [CHAR LIMIT=20] Zen mode settings: Master switch option title, on -->
+ <string name="zen_mode_option_on">On</string>
+
<!-- [CHAR LIMIT=40] Zen mode settings: General category text -->
- <string name="zen_mode_general_category">When on, limit interruptions to</string>
+ <string name="zen_mode_general_category">Block all interruptions except</string>
<!-- [CHAR LIMIT=40] Zen mode settings: Automatic category text -->
- <string name="zen_mode_automatic_category">Automatically turn on for sleep</string>
+ <string name="zen_mode_automatic_category">At night</string>
<!-- [CHAR LIMIT=20] Zen mode settings: Phone calls option -->
<string name="zen_mode_phone_calls">Phone calls</string>
<string name="zen_mode_from_starred">Starred contacts only</string>
<!-- [CHAR LIMIT=60] Zen mode settings: Reminder text about alarms -->
- <string name="zen_mode_alarm_info">You’ll always hear alarms and timers in Do not disturb</string>
+ <string name="zen_mode_alarm_info">Alarms and timers are never blocked</string>
<!-- [CHAR LIMIT=20] Zen mode settings: When option -->
- <string name="zen_mode_when">When</string>
+ <string name="zen_mode_when">Automatically turn on</string>
<!-- [CHAR LIMIT=20] Zen mode settings: When option value: Never -->
<string name="zen_mode_when_never">Never</string>
package com.android.settings.notification;
-import android.app.ActionBar;
-import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.service.notification.ZenModeConfig;
import android.text.format.DateFormat;
import android.util.Log;
-import android.view.Gravity;
-import android.view.Menu;
-import android.view.MenuInflater;
-import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.CompoundButton;
-import android.widget.CompoundButton.OnCheckedChangeListener;
-import android.widget.Switch;
import android.widget.TextView;
import android.widget.TimePicker;
private static final String TAG = "ZenModeSettings";
private static final boolean DEBUG = true;
+ private static final String KEY_ZEN_MODE = "zen_mode";
private static final String KEY_GENERAL = "general";
private static final String KEY_CALLS = "phone_calls";
private static final String KEY_MESSAGES = "messages";
private final Handler mHandler = new Handler();
private final SettingsObserver mSettingsObserver = new SettingsObserver();
- private Switch mSwitch;
- private Activity mActivity;
+ private SwitchPreference mSwitch;
private Context mContext;
- private MenuItem mSearch;
private ZenModeConfig mConfig;
private boolean mDisableListeners;
private SwitchPreference mCalls;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
- mContext = mActivity = getActivity();
- mSwitch = new Switch(mActivity.getActionBar().getThemedContext());
+ mContext = getActivity();
final Resources res = mContext.getResources();
final int p = res.getDimensionPixelSize(R.dimen.content_margin_left);
- mSwitch.setPadding(0, 0, p, 0);
- setHasOptionsMenu(true);
addPreferencesFromResource(R.xml.zen_mode_settings);
final PreferenceScreen root = getPreferenceScreen();
mConfig = getZenModeConfig();
if (DEBUG) Log.d(TAG, "Loaded mConfig=" + mConfig);
+ mSwitch = (SwitchPreference) root.findPreference(KEY_ZEN_MODE);
+
final PreferenceCategory general = (PreferenceCategory) root.findPreference(KEY_GENERAL);
mCalls = (SwitchPreference) root.findPreference(KEY_CALLS);
mWhen.setKey(KEY_WHEN);
mWhen.setTitle(R.string.zen_mode_when);
mWhen.setDropDownWidth(R.dimen.zen_mode_dropdown_width);
- mWhen.addItem(R.string.zen_mode_when_never);
mWhen.addItem(R.string.zen_mode_when_every_night);
mWhen.addItem(R.string.zen_mode_when_weeknights);
+ mWhen.addItem(R.string.zen_mode_when_never);
mWhen.setCallback(new DropDownPreference.Callback() {
@Override
public boolean onItemSelected(int pos) {
mStart.setDependency(mWhen.getKey());
mEnd.setDependency(mWhen.getKey());
+ updateZenMode();
updateControls();
}
}
@Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- super.onCreateOptionsMenu(menu, inflater);
- mSearch = menu.findItem(R.id.search);
- if (mSearch != null) mSearch.setVisible(false);
- }
-
- @Override
public void onResume() {
super.onResume();
updateZenMode();
mSettingsObserver.register();
- mActivity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
- ActionBar.DISPLAY_SHOW_CUSTOM);
- mActivity.getActionBar().setCustomView(mSwitch, new ActionBar.LayoutParams(
- ActionBar.LayoutParams.WRAP_CONTENT,
- ActionBar.LayoutParams.WRAP_CONTENT,
- Gravity.CENTER_VERTICAL | Gravity.END));
- if (mSearch != null) mSearch.setVisible(false);
}
@Override
public void onPause() {
super.onPause();
mSettingsObserver.unregister();
- mActivity.getActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
- if (mSearch != null) mSearch.setVisible(true);
}
private void updateZenMode() {
- mSwitch.setOnCheckedChangeListener(null);
+ mSwitch.setOnPreferenceChangeListener(null);
final boolean zenMode = Global.getInt(getContentResolver(),
Global.ZEN_MODE, Global.ZEN_MODE_OFF) != Global.ZEN_MODE_OFF;
mSwitch.setChecked(zenMode);
- mSwitch.setOnCheckedChangeListener(mSwitchListener);
+ mSwitch.setTitle(zenMode ? R.string.zen_mode_option_on : R.string.zen_mode_option_off);
+ mSwitch.setOnPreferenceChangeListener(mSwitchListener);
}
private void updateZenModeConfig() {
}
}
- private final OnCheckedChangeListener mSwitchListener = new OnCheckedChangeListener() {
+ private final OnPreferenceChangeListener mSwitchListener = new OnPreferenceChangeListener() {
@Override
- public void onCheckedChanged(CompoundButton buttonView, final boolean isChecked) {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final boolean isChecked = (Boolean) newValue;
AsyncTask.execute(new Runnable() {
@Override
public void run() {
Global.putInt(getContentResolver(), Global.ZEN_MODE, v);
}
});
+ return true;
}
};