OSDN Git Service

Update zen mode settings strings.
authorJohn Spurlock <jspurlock@google.com>
Mon, 28 Apr 2014 15:41:20 +0000 (11:41 -0400)
committerJohn Spurlock <jspurlock@google.com>
Mon, 28 Apr 2014 15:41:20 +0000 (11:41 -0400)
Change-Id: I0caeed5825cedb6be16384df4988aab0ea5cdbc6

res/layout/zen_mode_section.xml [new file with mode: 0644]
res/values/strings.xml
res/xml/zen_mode_settings.xml
src/com/android/settings/notification/ZenModeSettings.java

diff --git a/res/layout/zen_mode_section.xml b/res/layout/zen_mode_section.xml
new file mode 100644 (file)
index 0000000..3e87b0c
--- /dev/null
@@ -0,0 +1,35 @@
+<!--
+     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
index 6a632ce..99f6664 100644 (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&#8217;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>
index 0a7a519..19316af 100644 (file)
     android:key="zen_mode_settings"
     android:title="@string/zen_mode_settings_title" >
 
+    <SwitchPreference
+        android:key="zen_mode"
+        android:persistent="false"
+        android:switchTextOff=""
+        android:switchTextOn="" />
+
     <PreferenceCategory
         android:key="general"
-        android:layout="@layout/notification_app_section"
+        android:layout="@layout/zen_mode_section"
         android:title="@string/zen_mode_general_category" >
         <SwitchPreference
             android:key="phone_calls"
@@ -38,7 +44,7 @@
     </PreferenceCategory>
     <PreferenceCategory
         android:key="automatic"
-        android:layout="@layout/notification_app_section"
+        android:layout="@layout/zen_mode_section"
         android:title="@string/zen_mode_automatic_category" />
 
 </PreferenceScreen>
\ No newline at end of file
index 050d2e9..26fa539 100644 (file)
@@ -16,8 +16,6 @@
 
 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;
@@ -41,15 +39,8 @@ import android.provider.Settings.Global;
 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;
 
@@ -68,6 +59,7 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
     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";
@@ -78,10 +70,8 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
     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;
@@ -94,12 +84,9 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
     @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();
@@ -107,6 +94,8 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
         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);
@@ -166,9 +155,9 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
         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) {
@@ -230,6 +219,7 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
         mStart.setDependency(mWhen.getKey());
         mEnd.setDependency(mWhen.getKey());
 
+        updateZenMode();
         updateControls();
     }
 
@@ -247,40 +237,25 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
     }
 
     @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() {
@@ -317,9 +292,10 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
         }
     }
 
-    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() {
@@ -327,6 +303,7 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
                     Global.putInt(getContentResolver(), Global.ZEN_MODE, v);
                 }
             });
+            return true;
         }
     };