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:
28
res/layout/zen_mode_section_first.xml
Normal file
28
res/layout/zen_mode_section_first.xml
Normal 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>
|
@@ -5175,12 +5175,6 @@
|
|||||||
<!-- [CHAR LIMIT=20] Notification settings: App notifications dialog dismiss button caption -->
|
<!-- [CHAR LIMIT=20] Notification settings: App notifications dialog dismiss button caption -->
|
||||||
<string name="app_notifications_dialog_done">Done</string>
|
<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 -->
|
<!-- [CHAR LIMIT=30] Zen mode settings: Exit condition selection dialog, default option -->
|
||||||
<string name="zen_mode_default_option">Until you turn this off</string>
|
<string name="zen_mode_default_option">Until you turn this off</string>
|
||||||
|
|
||||||
|
@@ -19,15 +19,9 @@
|
|||||||
android:key="zen_mode_settings"
|
android:key="zen_mode_settings"
|
||||||
android:title="@string/zen_mode_settings_title" >
|
android:title="@string/zen_mode_settings_title" >
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:key="zen_mode"
|
|
||||||
android:persistent="false"
|
|
||||||
android:switchTextOff=""
|
|
||||||
android:switchTextOn="" />
|
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="general"
|
android:key="general"
|
||||||
android:layout="@layout/zen_mode_section"
|
android:layout="@layout/zen_mode_section_first"
|
||||||
android:title="@string/zen_mode_general_category" >
|
android:title="@string/zen_mode_general_category" >
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="phone_calls"
|
android:key="phone_calls"
|
||||||
|
@@ -47,25 +47,28 @@ import android.text.format.DateFormat;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Switch;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.TimePicker;
|
import android.widget.TimePicker;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
import com.android.settings.search.SearchIndexableRaw;
|
import com.android.settings.search.SearchIndexableRaw;
|
||||||
|
import com.android.settings.widget.SwitchBar;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
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 String TAG = "ZenModeSettings";
|
||||||
private static final boolean DEBUG = true;
|
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_GENERAL = "general";
|
||||||
private static final String KEY_CALLS = "phone_calls";
|
private static final String KEY_CALLS = "phone_calls";
|
||||||
private static final String KEY_MESSAGES = "messages";
|
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 Handler mHandler = new Handler();
|
||||||
private final SettingsObserver mSettingsObserver = new SettingsObserver();
|
private final SettingsObserver mSettingsObserver = new SettingsObserver();
|
||||||
|
|
||||||
private SwitchPreference mSwitch;
|
private SwitchBar mSwitchBar;
|
||||||
|
private Switch mSwitch;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private PackageManager mPM;
|
private PackageManager mPM;
|
||||||
private ZenModeConfig mConfig;
|
private ZenModeConfig mConfig;
|
||||||
@@ -97,6 +101,26 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
|||||||
private AlertDialog mDialog;
|
private AlertDialog mDialog;
|
||||||
private boolean mIgnoreNext;
|
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
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
@@ -111,8 +135,8 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
|||||||
mConfig = getZenModeConfig();
|
mConfig = getZenModeConfig();
|
||||||
if (DEBUG) Log.d(TAG, "Loaded mConfig=" + mConfig);
|
if (DEBUG) Log.d(TAG, "Loaded mConfig=" + mConfig);
|
||||||
|
|
||||||
mSwitch = (SwitchPreference) root.findPreference(KEY_ZEN_MODE);
|
mSwitchBar = ((SettingsActivity) mContext).getSwitchBar();
|
||||||
mSwitch.setOnPreferenceChangeListener(mSwitchListener);
|
mSwitch = mSwitchBar.getSwitch();
|
||||||
|
|
||||||
final PreferenceCategory general = (PreferenceCategory) root.findPreference(KEY_GENERAL);
|
final PreferenceCategory general = (PreferenceCategory) root.findPreference(KEY_GENERAL);
|
||||||
|
|
||||||
@@ -324,12 +348,16 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
|||||||
updateControls();
|
updateControls();
|
||||||
updateZenMode();
|
updateZenMode();
|
||||||
mSettingsObserver.register();
|
mSettingsObserver.register();
|
||||||
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
|
mSwitchBar.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
mSettingsObserver.unregister();
|
mSettingsObserver.unregister();
|
||||||
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
|
mSwitchBar.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateZenMode() {
|
private void updateZenMode() {
|
||||||
@@ -339,7 +367,6 @@ public class ZenModeSettings extends SettingsPreferenceFragment implements Index
|
|||||||
mSwitch.setChecked(zenMode);
|
mSwitch.setChecked(zenMode);
|
||||||
mIgnoreNext = true;
|
mIgnoreNext = true;
|
||||||
}
|
}
|
||||||
mSwitch.setTitle(zenMode ? R.string.zen_mode_option_on : R.string.zen_mode_option_off);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateZenModeConfig() {
|
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
|
// Enable indexing of searchable data
|
||||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
new BaseSearchIndexProvider() {
|
new BaseSearchIndexProvider() {
|
||||||
|
Reference in New Issue
Block a user