Use SwitchBar for DoNoDisturb Settings

- follow up CL to 4193776698

Related to bug #14898161 On/Off switches must move down from Action Bar

Change-Id: If1ce0eb147ade8485107ee948b0d03cf688bcf06
This commit is contained in:
Fabrice Di Meglio
2014-05-15 20:15:27 -07:00
parent 7ba17ab12c
commit 8fb5d4a0ea
4 changed files with 62 additions and 44 deletions

View File

@@ -0,0 +1,28 @@
<!--
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" >
<TextView
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:textStyle="bold" />
</LinearLayout>

View File

@@ -5175,12 +5175,6 @@
<!-- [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=30] Zen mode settings: Exit condition selection dialog, default option -->
<string name="zen_mode_default_option">Until you turn this off</string>

View File

@@ -19,15 +19,9 @@
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/zen_mode_section"
android:layout="@layout/zen_mode_section_first"
android:title="@string/zen_mode_general_category" >
<SwitchPreference
android:key="phone_calls"

View File

@@ -47,25 +47,28 @@ import android.text.format.DateFormat;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.TimePicker;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.search.SearchIndexableRaw;
import com.android.settings.widget.SwitchBar;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Objects;
public class ZenModeSettings extends SettingsPreferenceFragment implements Indexable {
public class ZenModeSettings extends SettingsPreferenceFragment implements Indexable,
SwitchBar.OnSwitchChangeListener {
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";
@@ -80,7 +83,8 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
private final Handler mHandler = new Handler();
private final SettingsObserver mSettingsObserver = new SettingsObserver();
private SwitchPreference mSwitch;
private SwitchBar mSwitchBar;
private Switch mSwitch;
private Context mContext;
private PackageManager mPM;
private ZenModeConfig mConfig;
@@ -97,6 +101,26 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
private AlertDialog mDialog;
private boolean mIgnoreNext;
@Override
public void onSwitchChanged(Switch switchView, final boolean isChecked) {
if (DEBUG) Log.d(TAG, "onPreferenceChange isChecked=" + isChecked
+ " mIgnoreNext=" + mIgnoreNext);
if (mIgnoreNext) {
mIgnoreNext = false;
}
AsyncTask.execute(new Runnable() {
@Override
public void run() {
final int v = isChecked ? Global.ZEN_MODE_ON : Global.ZEN_MODE_OFF;
putZenModeSetting(v);
final int n = ConditionProviderSettings.getEnabledProviderCount(mContext);
if (n > 0) {
mHandler.post(isChecked ? mShowDialog : mHideDialog);
}
}
});
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -111,8 +135,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);
mSwitch.setOnPreferenceChangeListener(mSwitchListener);
mSwitchBar = ((SettingsActivity) mContext).getSwitchBar();
mSwitch = mSwitchBar.getSwitch();
final PreferenceCategory general = (PreferenceCategory) root.findPreference(KEY_GENERAL);
@@ -324,12 +348,16 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
updateControls();
updateZenMode();
mSettingsObserver.register();
mSwitchBar.addOnSwitchChangeListener(this);
mSwitchBar.show();
}
@Override
public void onPause() {
super.onPause();
mSettingsObserver.unregister();
mSwitchBar.removeOnSwitchChangeListener(this);
mSwitchBar.hide();
}
private void updateZenMode() {
@@ -339,7 +367,6 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
mSwitch.setChecked(zenMode);
mIgnoreNext = true;
}
mSwitch.setTitle(zenMode ? R.string.zen_mode_option_on : R.string.zen_mode_option_off);
}
private void updateZenModeConfig() {
@@ -417,31 +444,6 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
}
};
private final OnPreferenceChangeListener mSwitchListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean isChecked = (Boolean) newValue;
if (DEBUG) Log.d(TAG, "onPreferenceChange isChecked=" + isChecked
+ " mIgnoreNext=" + mIgnoreNext);
if (mIgnoreNext) {
mIgnoreNext = false;
return true;
}
AsyncTask.execute(new Runnable() {
@Override
public void run() {
final int v = isChecked ? Global.ZEN_MODE_ON : Global.ZEN_MODE_OFF;
putZenModeSetting(v);
final int n = ConditionProviderSettings.getEnabledProviderCount(mContext);
if (n > 0) {
mHandler.post(isChecked ? mShowDialog : mHideDialog);
}
}
});
return true;
}
};
// Enable indexing of searchable data
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {