Zen: Move zen mode preference to switch bar.
- Add summary line support to SwitchBar. - Remove obsolete strings. - Wire up switchbar to zen mode w/ dialog prompt. - Remove obsolete callback pref helper. Bug: 20064962 Change-Id: Ifede00b5d43d441ccd94db96bd2796bc57d1a990
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end"
|
||||
android:textAppearance="@style/TextAppearance.Switch"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textAlignment="viewStart" />
|
||||
|
@@ -5692,20 +5692,17 @@
|
||||
<!-- Sound & notification > Sound section: Title for the zen mode automation option and associated settings page. [CHAR LIMIT=30] -->
|
||||
<string name="zen_mode_automation_settings_title">Automatic rules</string>
|
||||
|
||||
<!-- Sound & notification > Sound section: Title for the zen mode option. [CHAR LIMIT=60] -->
|
||||
<string name="zen_mode_option_title">When calls and notifications arrive</string>
|
||||
|
||||
<!-- Sound & notification > Sound section: Zen mode option: Off [CHAR LIMIT=60] -->
|
||||
<string name="zen_mode_option_off">Always interrupt</string>
|
||||
|
||||
<!-- Sound & notification > Sound section: Zen mode option: Important interruptions [CHAR LIMIT=60] -->
|
||||
<string name="zen_mode_option_important_interruptions">Allow only priority interruptions</string>
|
||||
<string name="zen_mode_option_important_interruptions">Priority only</string>
|
||||
|
||||
<!-- Sound & notification > Sound section: Zen mode option: Alarms only [CHAR LIMIT=60] -->
|
||||
<string name="zen_mode_option_alarms">Allow only alarms</string>
|
||||
<string name="zen_mode_option_alarms">Alarms only</string>
|
||||
|
||||
<!-- Sound & notification > Sound section: Zen mode option: No interruptions [CHAR LIMIT=60] -->
|
||||
<string name="zen_mode_option_no_interruptions">Don\'t interrupt</string>
|
||||
<string name="zen_mode_option_no_interruptions">No interruptions</string>
|
||||
|
||||
<!-- Sound & notification > Sound section: Zen mode combined summary + condition line [CHAR LIMIT=60] -->
|
||||
<string name="zen_mode_summary_combination"><xliff:g id="mode" example="Priority only">%1$s</xliff:g> <xliff:g id="exit condition" example="until you turn this off">%2$s</xliff:g></string>
|
||||
|
||||
<!-- Sound & notification > Sound section: Title for the option defining the phone ringtone. [CHAR LIMIT=30] -->
|
||||
<string name="ringtone_title">Phone ringtone</string>
|
||||
@@ -5875,9 +5872,6 @@
|
||||
<!-- [CHAR LIMIT=20] Notification settings: App notifications dialog dismiss button caption -->
|
||||
<string name="app_notifications_dialog_done">Done</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>
|
||||
|
||||
<!-- [CHAR LIMIT=60] Zen mode settings: Downtime category text -->
|
||||
<string name="zen_mode_downtime_category">Downtime</string>
|
||||
|
||||
|
@@ -350,4 +350,8 @@
|
||||
<item name="android:textColor">@color/fingerprint_message_color</item>
|
||||
</style>
|
||||
|
||||
<style name="TextAppearance.Small.SwitchBar">
|
||||
<item name="android:textColor">?android:attr/textColorPrimary</item>
|
||||
<item name="android:textStyle">normal</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
@@ -19,12 +19,6 @@
|
||||
android:key="zen_mode_settings"
|
||||
android:title="@string/zen_mode_settings_title" >
|
||||
|
||||
<!-- When calls and notifications arrive -->
|
||||
<com.android.settings.DropDownPreference
|
||||
android:key="zen_mode"
|
||||
android:title="@string/zen_mode_option_title"
|
||||
android:persistent="false" />
|
||||
|
||||
<!-- Priority only allows -->
|
||||
<PreferenceScreen
|
||||
android:key="priority_settings"
|
||||
|
@@ -118,7 +118,8 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase implements In
|
||||
removePreference(KEY_DOWNTIME);
|
||||
return;
|
||||
}
|
||||
mDays = root.findPreference(KEY_DAYS);
|
||||
final PreferenceCategory downtime = (PreferenceCategory) findPreference(KEY_DOWNTIME);
|
||||
mDays = downtime.findPreference(KEY_DAYS);
|
||||
mDays.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
@@ -168,7 +169,7 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase implements In
|
||||
return setZenModeConfig(newConfig);
|
||||
}
|
||||
});
|
||||
root.addPreference(mStart);
|
||||
downtime.addPreference(mStart);
|
||||
mStart.setDependency(mDays.getKey());
|
||||
|
||||
mEnd = new TimePickerPreference(mContext, mgr);
|
||||
@@ -190,10 +191,10 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase implements In
|
||||
return setZenModeConfig(newConfig);
|
||||
}
|
||||
});
|
||||
root.addPreference(mEnd);
|
||||
downtime.addPreference(mEnd);
|
||||
mEnd.setDependency(mDays.getKey());
|
||||
|
||||
mDowntimeMode = (DropDownPreference) root.findPreference(KEY_DOWNTIME_MODE);
|
||||
mDowntimeMode = (DropDownPreference) downtime.findPreference(KEY_DOWNTIME_MODE);
|
||||
mDowntimeMode.addItem(R.string.zen_mode_downtime_mode_priority, false);
|
||||
mDowntimeMode.addItem(R.string.zen_mode_downtime_mode_none, true);
|
||||
mDowntimeMode.setCallback(new DropDownPreference.Callback() {
|
||||
@@ -265,7 +266,17 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase implements In
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateControls() {
|
||||
protected void onZenModeConfigChanged() {
|
||||
updateControls();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
updateControls();
|
||||
}
|
||||
|
||||
private void updateControls() {
|
||||
mDisableListeners = true;
|
||||
if (mDowntimeSupported) {
|
||||
updateDays();
|
||||
|
@@ -27,7 +27,6 @@ import android.os.UserHandle;
|
||||
import android.service.notification.Condition;
|
||||
import android.service.notification.IConditionListener;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.RadioButton;
|
||||
@@ -117,7 +116,7 @@ public class ZenModeConditionSelection extends RadioGroup {
|
||||
}
|
||||
}
|
||||
if (v != null) {
|
||||
v.setText(!TextUtils.isEmpty(c.line1) ? c.line1 : c.summary);
|
||||
v.setText(ZenModeSettings.computeConditionText(c));
|
||||
v.setEnabled(c.state == Condition.STATE_TRUE);
|
||||
}
|
||||
mConditions.add(c);
|
||||
|
@@ -132,7 +132,11 @@ public class ZenModePrioritySettings extends ZenModeSettingsBase implements Inde
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateControls() {
|
||||
protected void onZenModeConfigChanged() {
|
||||
updateControls();
|
||||
}
|
||||
|
||||
private void updateControls() {
|
||||
mDisableListeners = true;
|
||||
if (mCalls != null) {
|
||||
mCalls.setChecked(mConfig.allowCalls);
|
||||
|
@@ -24,51 +24,87 @@ import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.provider.Settings.Global;
|
||||
import android.service.notification.Condition;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.Switch;
|
||||
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.SettingsActivity;
|
||||
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.List;
|
||||
|
||||
public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
|
||||
private static final String KEY_ZEN_MODE = "zen_mode";
|
||||
public class ZenModeSettings extends ZenModeSettingsBase
|
||||
implements Indexable, SwitchBar.OnSwitchChangeListener {
|
||||
private static final String KEY_PRIORITY_SETTINGS = "priority_settings";
|
||||
private static final String KEY_AUTOMATION_SETTINGS = "automation_settings";
|
||||
|
||||
private static final SettingPrefWithCallback PREF_ZEN_MODE = new SettingPrefWithCallback(
|
||||
SettingPref.TYPE_GLOBAL, KEY_ZEN_MODE, Global.ZEN_MODE, Global.ZEN_MODE_OFF,
|
||||
Global.ZEN_MODE_OFF, Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS, Global.ZEN_MODE_ALARMS,
|
||||
Global.ZEN_MODE_NO_INTERRUPTIONS) {
|
||||
protected String getCaption(Resources res, int value) {
|
||||
switch (value) {
|
||||
case Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||
return res.getString(R.string.zen_mode_option_no_interruptions);
|
||||
case Global.ZEN_MODE_ALARMS:
|
||||
return res.getString(R.string.zen_mode_option_alarms);
|
||||
case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
|
||||
return res.getString(R.string.zen_mode_option_important_interruptions);
|
||||
default:
|
||||
return res.getString(R.string.zen_mode_option_off);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private Preference mPrioritySettings;
|
||||
private AlertDialog mDialog;
|
||||
private SwitchBar mSwitchBar;
|
||||
private boolean mShowing;
|
||||
|
||||
private static SparseArray<String> allKeyTitles(Context context) {
|
||||
final SparseArray<String> rt = new SparseArray<String>();
|
||||
rt.put(R.string.zen_mode_option_title, KEY_ZEN_MODE);
|
||||
rt.put(R.string.zen_mode_priority_settings_title, KEY_PRIORITY_SETTINGS);
|
||||
rt.put(R.string.zen_mode_automation_settings_title, KEY_AUTOMATION_SETTINGS);
|
||||
return rt;
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.zen_mode_settings);
|
||||
final PreferenceScreen root = getPreferenceScreen();
|
||||
|
||||
mPrioritySettings = root.findPreference(KEY_PRIORITY_SETTINGS);
|
||||
if (!isDowntimeSupported(mContext)) {
|
||||
removePreference(KEY_AUTOMATION_SETTINGS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
final SettingsActivity activity = (SettingsActivity) getActivity();
|
||||
mSwitchBar = activity.getSwitchBar();
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mSwitchBar.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mSwitchBar.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
updateControls();
|
||||
mShowing = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
mShowing = false;
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||
if (DEBUG) Log.d(TAG, "onSwitchChanged " + isChecked + " mShowing=" + mShowing);
|
||||
if (!mShowing) return; // not from the user
|
||||
if (isChecked) {
|
||||
setZenMode(Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
||||
showConditionSelection(Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
||||
} else {
|
||||
setZenMode(Global.ZEN_MODE_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,36 +114,52 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
|
||||
|
||||
@Override
|
||||
protected void onZenModeChanged() {
|
||||
PREF_ZEN_MODE.update(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.zen_mode_settings);
|
||||
final PreferenceScreen root = getPreferenceScreen();
|
||||
|
||||
PREF_ZEN_MODE.init(this);
|
||||
PREF_ZEN_MODE.setCallback(new SettingPrefWithCallback.Callback() {
|
||||
@Override
|
||||
public void onSettingSelected(int value) {
|
||||
if (value != Global.ZEN_MODE_OFF) {
|
||||
showConditionSelection(value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mPrioritySettings = root.findPreference(KEY_PRIORITY_SETTINGS);
|
||||
if (!isDowntimeSupported(mContext)) {
|
||||
removePreference(KEY_AUTOMATION_SETTINGS);
|
||||
}
|
||||
|
||||
updateControls();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateControls() {
|
||||
protected void onZenModeConfigChanged() {
|
||||
updateControls();
|
||||
}
|
||||
|
||||
private String computeZenModeCaption(int zenMode) {
|
||||
switch (zenMode) {
|
||||
case Global.ZEN_MODE_ALARMS:
|
||||
return getString(R.string.zen_mode_option_alarms);
|
||||
case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
|
||||
return getString(R.string.zen_mode_option_important_interruptions);
|
||||
case Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||
return getString(R.string.zen_mode_option_no_interruptions);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String computeExitConditionText() {
|
||||
return mConfig == null || mConfig.exitCondition == null
|
||||
? getString(com.android.internal.R.string.zen_mode_forever)
|
||||
: computeConditionText(mConfig.exitCondition);
|
||||
}
|
||||
|
||||
public static String computeConditionText(Condition c) {
|
||||
return !TextUtils.isEmpty(c.line1) ? c.line1
|
||||
: !TextUtils.isEmpty(c.summary) ? c.summary
|
||||
: "";
|
||||
}
|
||||
|
||||
private String computeZenModeSummaryLine() {
|
||||
final String caption = computeZenModeCaption(mZenMode);
|
||||
if (caption == null) return null;
|
||||
final String conditionText = computeExitConditionText().toLowerCase();
|
||||
return getString(R.string.zen_mode_summary_combination, caption, conditionText);
|
||||
}
|
||||
|
||||
private void updateControls() {
|
||||
if (mSwitchBar != null) {
|
||||
final String summaryLine = computeZenModeSummaryLine();
|
||||
mSwitchBar.setChecked(summaryLine != null);
|
||||
mSwitchBar.setSummary(summaryLine);
|
||||
}
|
||||
updatePrioritySettingsSummary();
|
||||
}
|
||||
|
||||
@@ -128,7 +180,7 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
|
||||
return s;
|
||||
}
|
||||
|
||||
protected void showConditionSelection(final int newSettingsValue) {
|
||||
protected void showConditionSelection(final int zenMode) {
|
||||
if (mDialog != null) return;
|
||||
|
||||
final ZenModeConditionSelection zenModeConditionSelection =
|
||||
@@ -140,34 +192,41 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
|
||||
mDialog = null;
|
||||
}
|
||||
};
|
||||
final int oldSettingsValue = PREF_ZEN_MODE.getValue(mContext);
|
||||
ScrollView scrollView = new ScrollView(mContext);
|
||||
scrollView.addView(zenModeConditionSelection);
|
||||
mDialog = new AlertDialog.Builder(getActivity())
|
||||
.setTitle(PREF_ZEN_MODE.getCaption(getResources(), newSettingsValue))
|
||||
.setTitle(computeZenModeCaption(zenMode))
|
||||
.setView(scrollView)
|
||||
.setPositiveButton(R.string.okay, positiveListener)
|
||||
.setNegativeButton(R.string.cancel_all_caps, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
cancelDialog(oldSettingsValue);
|
||||
cancelDialog();
|
||||
}
|
||||
})
|
||||
.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
cancelDialog(oldSettingsValue);
|
||||
cancelDialog();
|
||||
}
|
||||
}).create();
|
||||
mDialog.show();
|
||||
}
|
||||
|
||||
protected void cancelDialog(int oldSettingsValue) {
|
||||
// If not making a decision, reset drop down to current setting.
|
||||
PREF_ZEN_MODE.setValueWithoutCallback(mContext, oldSettingsValue);
|
||||
private void cancelDialog() {
|
||||
if (DEBUG) Log.d(TAG, "cancelDialog");
|
||||
// If not making a decision, reset zen to off.
|
||||
setZenMode(Global.ZEN_MODE_OFF);
|
||||
mDialog = null;
|
||||
}
|
||||
|
||||
private static SparseArray<String> allKeyTitles(Context context) {
|
||||
final SparseArray<String> rt = new SparseArray<String>();
|
||||
rt.put(R.string.zen_mode_priority_settings_title, KEY_PRIORITY_SETTINGS);
|
||||
rt.put(R.string.zen_mode_automation_settings_title, KEY_AUTOMATION_SETTINGS);
|
||||
return rt;
|
||||
}
|
||||
|
||||
// Enable indexing of searchable data
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@@ -197,58 +256,4 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
|
||||
return rt;
|
||||
}
|
||||
};
|
||||
|
||||
private static class SettingPrefWithCallback extends SettingPref {
|
||||
|
||||
private Callback mCallback;
|
||||
private int mValue;
|
||||
|
||||
public SettingPrefWithCallback(int type, String key, String setting, int def,
|
||||
int... values) {
|
||||
super(type, key, setting, def, values);
|
||||
}
|
||||
|
||||
public void setCallback(Callback callback) {
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Context context) {
|
||||
// Avoid callbacks from non-user changes.
|
||||
mValue = getValue(context);
|
||||
super.update(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setSetting(Context context, int value) {
|
||||
if (value == mValue) return true;
|
||||
mValue = value;
|
||||
if (mCallback != null) {
|
||||
mCallback.onSettingSelected(value);
|
||||
}
|
||||
return super.setSetting(context, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Preference init(SettingsPreferenceFragment settings) {
|
||||
Preference ret = super.init(settings);
|
||||
mValue = getValue(settings.getActivity());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean setValueWithoutCallback(Context context, int value) {
|
||||
// Set the current value ahead of time, this way we won't trigger a callback.
|
||||
mValue = value;
|
||||
return putInt(mType, context.getContentResolver(), mSetting, value);
|
||||
}
|
||||
|
||||
public int getValue(Context context) {
|
||||
return getInt(mType, context.getContentResolver(), mSetting, mDefault);
|
||||
}
|
||||
|
||||
public interface Callback {
|
||||
void onSettingSelected(int value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.ServiceManager;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.Global;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
import android.util.Log;
|
||||
@@ -41,23 +42,25 @@ abstract public class ZenModeSettingsBase extends SettingsPreferenceFragment {
|
||||
|
||||
protected Context mContext;
|
||||
protected ZenModeConfig mConfig;
|
||||
protected int mZenMode;
|
||||
|
||||
abstract protected void onZenModeChanged();
|
||||
abstract protected void updateControls();
|
||||
abstract protected void onZenModeConfigChanged();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
mContext = getActivity();
|
||||
mConfig = getZenModeConfig();
|
||||
updateZenMode(false /*fireChanged*/);
|
||||
updateZenModeConfig(false /*fireChanged*/);
|
||||
if (DEBUG) Log.d(TAG, "Loaded mConfig=" + mConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mConfig = getZenModeConfig();
|
||||
updateControls();
|
||||
updateZenMode(true /*fireChanged*/);
|
||||
updateZenModeConfig(true /*fireChanged*/);
|
||||
mSettingsObserver.register();
|
||||
}
|
||||
|
||||
@@ -67,6 +70,26 @@ abstract public class ZenModeSettingsBase extends SettingsPreferenceFragment {
|
||||
mSettingsObserver.unregister();
|
||||
}
|
||||
|
||||
private void updateZenMode(boolean fireChanged) {
|
||||
final int zenMode = Settings.Global.getInt(getContentResolver(), Global.ZEN_MODE, mZenMode);
|
||||
if (zenMode == mZenMode) return;
|
||||
mZenMode = zenMode;
|
||||
if (DEBUG) Log.d(TAG, "updateZenMode mZenMode=" + mZenMode);
|
||||
if (fireChanged) {
|
||||
onZenModeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateZenModeConfig(boolean fireChanged) {
|
||||
final ZenModeConfig config = getZenModeConfig();
|
||||
if (Objects.equals(config, mConfig)) return;
|
||||
mConfig = config;
|
||||
if (DEBUG) Log.d(TAG, "updateZenModeConfig mConfig=" + mConfig);
|
||||
if (fireChanged) {
|
||||
onZenModeConfigChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean setZenModeConfig(ZenModeConfig config) {
|
||||
final INotificationManager nm = INotificationManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
||||
@@ -75,7 +98,7 @@ abstract public class ZenModeSettingsBase extends SettingsPreferenceFragment {
|
||||
if (success) {
|
||||
mConfig = config;
|
||||
if (DEBUG) Log.d(TAG, "Saved mConfig=" + mConfig);
|
||||
updateControls();
|
||||
onZenModeConfigChanged();
|
||||
}
|
||||
return success;
|
||||
} catch (Exception e) {
|
||||
@@ -84,19 +107,15 @@ abstract public class ZenModeSettingsBase extends SettingsPreferenceFragment {
|
||||
}
|
||||
}
|
||||
|
||||
protected void setZenMode(int zenMode) {
|
||||
Global.putInt(getContentResolver(), Global.ZEN_MODE, zenMode);
|
||||
}
|
||||
|
||||
protected static boolean isDowntimeSupported(Context context) {
|
||||
return NotificationManager.from(context)
|
||||
.isSystemConditionProviderEnabled(ZenModeConfig.DOWNTIME_PATH);
|
||||
}
|
||||
|
||||
private void updateZenModeConfig() {
|
||||
final ZenModeConfig config = getZenModeConfig();
|
||||
if (Objects.equals(config, mConfig)) return;
|
||||
mConfig = config;
|
||||
if (DEBUG) Log.d(TAG, "updateZenModeConfig mConfig=" + mConfig);
|
||||
updateControls();
|
||||
}
|
||||
|
||||
private ZenModeConfig getZenModeConfig() {
|
||||
final INotificationManager nm = INotificationManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
||||
@@ -129,10 +148,10 @@ abstract public class ZenModeSettingsBase extends SettingsPreferenceFragment {
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
super.onChange(selfChange, uri);
|
||||
if (ZEN_MODE_URI.equals(uri)) {
|
||||
onZenModeChanged();
|
||||
updateZenMode(true /*fireChanged*/);
|
||||
}
|
||||
if (ZEN_MODE_CONFIG_ETAG_URI.equals(uri)) {
|
||||
updateZenModeConfig();
|
||||
updateZenModeConfig(true /*fireChanged*/);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -20,15 +20,18 @@ import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.TextAppearanceSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -46,8 +49,12 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
||||
void onSwitchChanged(Switch switchView, boolean isChecked);
|
||||
}
|
||||
|
||||
private final TextAppearanceSpan mSummarySpan;
|
||||
|
||||
private ToggleSwitch mSwitch;
|
||||
private TextView mTextView;
|
||||
private String mLabel;
|
||||
private String mSummary;
|
||||
|
||||
private ArrayList<OnSwitchChangeListener> mSwitchChangeListeners =
|
||||
new ArrayList<OnSwitchChangeListener>();
|
||||
@@ -78,7 +85,9 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
||||
a.recycle();
|
||||
|
||||
mTextView = (TextView) findViewById(R.id.switch_text);
|
||||
mTextView.setText(R.string.switch_off_text);
|
||||
mLabel = getResources().getString(R.string.switch_off_text);
|
||||
mSummarySpan = new TextAppearanceSpan(mContext, R.style.TextAppearance_Small_SwitchBar);
|
||||
updateText();
|
||||
ViewGroup.MarginLayoutParams lp = (MarginLayoutParams) mTextView.getLayoutParams();
|
||||
lp.setMarginStart(switchBarMarginStart);
|
||||
|
||||
@@ -103,7 +112,26 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
||||
}
|
||||
|
||||
public void setTextViewLabel(boolean isChecked) {
|
||||
mTextView.setText(isChecked ? R.string.switch_on_text : R.string.switch_off_text);
|
||||
mLabel = getResources()
|
||||
.getString(isChecked ? R.string.switch_on_text : R.string.switch_off_text);
|
||||
updateText();
|
||||
}
|
||||
|
||||
public void setSummary(String summary) {
|
||||
mSummary = summary;
|
||||
updateText();
|
||||
}
|
||||
|
||||
private void updateText() {
|
||||
if (TextUtils.isEmpty(mSummary)) {
|
||||
mTextView.setText(mLabel);
|
||||
return;
|
||||
}
|
||||
final SpannableStringBuilder ssb = new SpannableStringBuilder(mLabel).append('\n');
|
||||
final int start = ssb.length();
|
||||
ssb.append(mSummary);
|
||||
ssb.setSpan(mSummarySpan, start, ssb.length(), 0);
|
||||
mTextView.setText(ssb);
|
||||
}
|
||||
|
||||
public void setChecked(boolean checked) {
|
||||
|
Reference in New Issue
Block a user