Update DND visual interruption choices.
Change-Id: I9313052d60a9fbd88546c1478ac9b830ae6fc40c
This commit is contained in:
@@ -31,8 +31,11 @@ import com.android.settings.SettingsActivity;
|
||||
|
||||
public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
private static final String KEY_PRIORITY_SETTINGS = "priority_settings";
|
||||
private static final String KEY_VISUAL_SETTINGS = "visual_interruptions_settings";
|
||||
|
||||
private Preference mPrioritySettings;
|
||||
private Preference mVisualSettings;
|
||||
private Policy mPolicy;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -42,6 +45,8 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
final PreferenceScreen root = getPreferenceScreen();
|
||||
|
||||
mPrioritySettings = root.findPreference(KEY_PRIORITY_SETTINGS);
|
||||
mVisualSettings = root.findPreference(KEY_VISUAL_SETTINGS);
|
||||
mPolicy = NotificationManager.from(mContext).getNotificationPolicy();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,7 +55,6 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
if (isUiRestricted()) {
|
||||
return;
|
||||
}
|
||||
updateControls();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,11 +69,13 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
|
||||
@Override
|
||||
protected void onZenModeConfigChanged() {
|
||||
mPolicy = NotificationManager.from(mContext).getNotificationPolicy();
|
||||
updateControls();
|
||||
}
|
||||
|
||||
private void updateControls() {
|
||||
updatePrioritySettingsSummary();
|
||||
updateVisualSettingsSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,31 +96,47 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
}
|
||||
|
||||
private void updatePrioritySettingsSummary() {
|
||||
Policy policy = NotificationManager.from(mContext).getNotificationPolicy();
|
||||
String s = getResources().getString(R.string.zen_mode_alarms);
|
||||
s = appendLowercase(s, isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_REMINDERS),
|
||||
s = appendLowercase(s, isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_REMINDERS),
|
||||
R.string.zen_mode_reminders);
|
||||
s = appendLowercase(s, isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_EVENTS),
|
||||
s = appendLowercase(s, isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_EVENTS),
|
||||
R.string.zen_mode_events);
|
||||
if (isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_MESSAGES)) {
|
||||
if (policy.priorityMessageSenders == Policy.PRIORITY_SENDERS_ANY) {
|
||||
if (isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_MESSAGES)) {
|
||||
if (mPolicy.priorityMessageSenders == Policy.PRIORITY_SENDERS_ANY) {
|
||||
s = appendLowercase(s, true, R.string.zen_mode_all_messages);
|
||||
} else {
|
||||
s = appendLowercase(s, true, R.string.zen_mode_selected_messages);
|
||||
}
|
||||
}
|
||||
if (isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_CALLS)) {
|
||||
if (policy.priorityCallSenders == Policy.PRIORITY_SENDERS_ANY) {
|
||||
if (isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_CALLS)) {
|
||||
if (mPolicy.priorityCallSenders == Policy.PRIORITY_SENDERS_ANY) {
|
||||
s = appendLowercase(s, true, R.string.zen_mode_all_callers);
|
||||
} else {
|
||||
s = appendLowercase(s, true, R.string.zen_mode_selected_callers);
|
||||
}
|
||||
} else if (isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_REPEAT_CALLERS)) {
|
||||
} else if (isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_REPEAT_CALLERS)) {
|
||||
s = appendLowercase(s, true, R.string.zen_mode_repeat_callers);
|
||||
}
|
||||
mPrioritySettings.setSummary(s);
|
||||
}
|
||||
|
||||
private void updateVisualSettingsSummary() {
|
||||
String s = getString(R.string.zen_mode_all_visual_interruptions);
|
||||
if (isEffectSuppressed(Policy.SUPPRESSED_EFFECT_SCREEN_ON)
|
||||
&& isEffectSuppressed(Policy.SUPPRESSED_EFFECT_SCREEN_OFF)) {
|
||||
s = getString(R.string.zen_mode_no_visual_interruptions);
|
||||
} else if (isEffectSuppressed(Policy.SUPPRESSED_EFFECT_SCREEN_ON)) {
|
||||
s = getString(R.string.zen_mode_screen_on_visual_interruptions);
|
||||
} else if (isEffectSuppressed(Policy.SUPPRESSED_EFFECT_SCREEN_OFF)) {
|
||||
s = getString(R.string.zen_mode_screen_off_visual_interruptions);
|
||||
}
|
||||
mVisualSettings.setSummary(s);
|
||||
}
|
||||
|
||||
private boolean isEffectSuppressed(int effect) {
|
||||
return (mPolicy.suppressedVisualEffects & effect) != 0;
|
||||
}
|
||||
|
||||
private boolean isCategoryEnabled(Policy policy, int categoryType) {
|
||||
return (policy.priorityCategories & categoryType) != 0;
|
||||
}
|
||||
|
@@ -37,12 +37,10 @@ import java.util.List;
|
||||
|
||||
public class ZenModeVisualInterruptionSettings extends ZenModeSettingsBase {
|
||||
|
||||
private static final String KEY_PEEK = "peek";
|
||||
private static final String KEY_LIGHTS = "lights";
|
||||
private static final String KEY_SCREEN_ON = "screen_on";
|
||||
private static final String KEY_SCREEN_OFF = "screenOff";
|
||||
private static final String KEY_SCREEN_ON = "screenOn";
|
||||
|
||||
private SwitchPreference mPeek;
|
||||
private SwitchPreference mLights;
|
||||
private SwitchPreference mScreenOff;
|
||||
private SwitchPreference mScreenOn;
|
||||
|
||||
private boolean mDisableListeners;
|
||||
@@ -56,28 +54,15 @@ public class ZenModeVisualInterruptionSettings extends ZenModeSettingsBase {
|
||||
|
||||
mPolicy = NotificationManager.from(mContext).getNotificationPolicy();
|
||||
|
||||
mPeek = (SwitchPreference) root.findPreference(KEY_PEEK);
|
||||
mPeek.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
mScreenOff = (SwitchPreference) root.findPreference(KEY_SCREEN_OFF);
|
||||
mScreenOff.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (mDisableListeners) return true;
|
||||
final boolean val = (Boolean) newValue;
|
||||
MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_PEEK, val);
|
||||
if (DEBUG) Log.d(TAG, "onPrefChange suppressPeek=" + val);
|
||||
savePolicy(getNewSuppressedEffects(val, Policy.SUPPRESSED_EFFECT_PEEK));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
mLights = (SwitchPreference) root.findPreference(KEY_LIGHTS);
|
||||
mLights.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (mDisableListeners) return true;
|
||||
final boolean val = (Boolean) newValue;
|
||||
MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_LIGHTS, val);
|
||||
if (DEBUG) Log.d(TAG, "onPrefChange suppressLights=" + val);
|
||||
savePolicy(getNewSuppressedEffects(val, Policy.SUPPRESSED_EFFECT_LIGHTS));
|
||||
MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_WHEN_SCREEN_OFF, val);
|
||||
if (DEBUG) Log.d(TAG, "onPrefChange suppressWhenScreenOff=" + val);
|
||||
savePolicy(getNewSuppressedEffects(val, Policy.SUPPRESSED_EFFECT_SCREEN_OFF));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -88,8 +73,8 @@ public class ZenModeVisualInterruptionSettings extends ZenModeSettingsBase {
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (mDisableListeners) return true;
|
||||
final boolean val = (Boolean) newValue;
|
||||
MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_SCREEN_ON, val);
|
||||
if (DEBUG) Log.d(TAG, "onPrefChange suppressScreenOn=" + val);
|
||||
MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_WHEN_SCREEN_ON, val);
|
||||
if (DEBUG) Log.d(TAG, "onPrefChange suppressWhenScreenOn=" + val);
|
||||
savePolicy(getNewSuppressedEffects(val, Policy.SUPPRESSED_EFFECT_SCREEN_ON));
|
||||
return true;
|
||||
}
|
||||
@@ -114,8 +99,7 @@ public class ZenModeVisualInterruptionSettings extends ZenModeSettingsBase {
|
||||
|
||||
private void updateControls() {
|
||||
mDisableListeners = true;
|
||||
mPeek.setChecked(isEffectSuppressed(Policy.SUPPRESSED_EFFECT_PEEK));
|
||||
mLights.setChecked(isEffectSuppressed(Policy.SUPPRESSED_EFFECT_LIGHTS));
|
||||
mScreenOff.setChecked(isEffectSuppressed(Policy.SUPPRESSED_EFFECT_SCREEN_OFF));
|
||||
mScreenOn.setChecked(isEffectSuppressed(Policy.SUPPRESSED_EFFECT_SCREEN_ON));
|
||||
mDisableListeners = false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user