Loading src/com/android/settings/dashboard/SuggestionsChecks.java +5 −5 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ import com.android.settings.Settings.WifiCallingSuggestionActivity; import com.android.settings.Settings.ZenModeAutomationSuggestionActivity; import com.android.settingslib.drawer.Tile; import java.util.List; import java.util.Collection; /** * The Home of all stupidly dynamic Settings Suggestions checks. Loading Loading @@ -86,10 +86,10 @@ public class SuggestionsChecks { } private boolean hasEnabledZenAutoRules() { List<AutomaticZenRule> zenRules = NotificationManager.from(mContext).getAutomaticZenRules(); final int N = zenRules.size(); for (int i = 0; i < N; i++) { if (zenRules.get(i).isEnabled()) { Collection<AutomaticZenRule> zenRules = NotificationManager.from(mContext).getAutomaticZenRules().values(); for (AutomaticZenRule rule : zenRules) { if (rule.isEnabled()) { return true; } } Loading src/com/android/settings/notification/ZenModeAutomationSettings.java +24 −17 Original line number Diff line number Diff line Loading @@ -46,7 +46,9 @@ import com.android.settings.notification.ManagedServiceSettings.Config; import java.lang.ref.WeakReference; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Map; public class ZenModeAutomationSettings extends ZenModeSettingsBase { Loading Loading @@ -111,15 +113,15 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { AutomaticZenRule rule = new AutomaticZenRule(ruleName, ri.serviceComponent, ri.defaultConditionId, NotificationManager.INTERRUPTION_FILTER_PRIORITY, true); AutomaticZenRule savedRule = addZenRule(rule); if (savedRule != null) { startActivity(getRuleIntent(ri.settingsAction, null, savedRule.getId())); String savedRuleId = addZenRule(rule); if (savedRuleId != null) { startActivity(getRuleIntent(ri.settingsAction, null, savedRuleId)); } } }.show(); } private void showDeleteRuleDialog(final String ruleId, final String ruleName) { private void showDeleteRuleDialog(final String ruleId, final CharSequence ruleName) { new AlertDialog.Builder(mContext) .setMessage(getString(R.string.zen_mode_delete_rule_confirmation, ruleName)) .setNegativeButton(R.string.cancel, null) Loading Loading @@ -147,8 +149,9 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { return intent; } private AutomaticZenRule[] sortedRules() { final AutomaticZenRule[] rt = mRules.toArray(new AutomaticZenRule[mRules.size()]); private Map.Entry<String,AutomaticZenRule>[] sortedRules() { final Map.Entry<String,AutomaticZenRule>[] rt = mRules.toArray(new Map.Entry[mRules.size()]); Arrays.sort(rt, RULE_COMPARATOR); return rt; } Loading @@ -156,8 +159,8 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { private void updateControls() { final PreferenceScreen root = getPreferenceScreen(); root.removeAll(); final AutomaticZenRule[] sortedRules = sortedRules(); for (AutomaticZenRule sortedRule : sortedRules) { final Map.Entry<String,AutomaticZenRule>[] sortedRules = sortedRules(); for (Map.Entry<String,AutomaticZenRule> sortedRule : sortedRules) { ZenRulePreference pref = new ZenRulePreference(getPrefContext(), sortedRule); if (pref.appExists) { root.addPreference(pref); Loading Loading @@ -247,15 +250,17 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { return null; } private static final Comparator<AutomaticZenRule> RULE_COMPARATOR = new Comparator<AutomaticZenRule>() { private static final Comparator<Map.Entry<String,AutomaticZenRule>> RULE_COMPARATOR = new Comparator<Map.Entry<String,AutomaticZenRule>>() { @Override public int compare(AutomaticZenRule lhs, AutomaticZenRule rhs) { int byDate = Long.compare(lhs.getCreationTime(), rhs.getCreationTime()); public int compare(Map.Entry<String,AutomaticZenRule> lhs, Map.Entry<String,AutomaticZenRule> rhs) { int byDate = Long.compare(lhs.getValue().getCreationTime(), rhs.getValue().getCreationTime()); if (byDate != 0) { return byDate; } else { return key(lhs).compareTo(key(rhs)); return key(lhs.getValue()).compareTo(key(rhs.getValue())); } } Loading @@ -263,20 +268,22 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { final int type = ZenModeConfig.isValidScheduleConditionId(rule.getConditionId()) ? 1 : ZenModeConfig.isValidEventConditionId(rule.getConditionId()) ? 2 : 3; return type + rule.getName(); return type + rule.getName().toString(); } }; private class ZenRulePreference extends Preference { final String mName; final CharSequence mName; final String mId; final boolean appExists; public ZenRulePreference(Context context, final AutomaticZenRule rule) { public ZenRulePreference(Context context, final Map.Entry<String, AutomaticZenRule> ruleEntry) { super(context); final AutomaticZenRule rule = ruleEntry.getValue(); mName = rule.getName(); mId = rule.getId(); mId = ruleEntry.getKey(); final boolean isSchedule = ZenModeConfig.isValidScheduleConditionId( rule.getConditionId()); Loading src/com/android/settings/notification/ZenModeRuleSettingsBase.java +5 −5 Original line number Diff line number Diff line Loading @@ -123,7 +123,7 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase if (zenMode == mRule.getInterruptionFilter()) return false; if (DEBUG) Log.d(TAG, "onPrefChange zenMode=" + zenMode); mRule.setInterruptionFilter(zenMode); setZenRule(mRule); setZenRule(mId, mRule); return true; } }); Loading Loading @@ -166,7 +166,7 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ENABLE_RULE, enabled); if (DEBUG) Log.d(TAG, "onSwitchChanged enabled=" + enabled); mRule.setEnabled(enabled); setZenRule(mRule); setZenRule(mId, mRule); if (enabled) { final int toastText = getEnabledToastText(); if (toastText != 0) { Loading @@ -182,7 +182,7 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase protected void updateRule(Uri newConditionId) { mRule.setConditionId(newConditionId); setZenRule(mRule); setZenRule(mId, mRule); } @Override Loading Loading @@ -219,7 +219,7 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase @Override public void onOk(String ruleName) { mRule.setName(ruleName); setZenRule(mRule); setZenRule(mId, mRule); } }.show(); } Loading @@ -243,7 +243,7 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase public void onClick(DialogInterface dialog, int which) { MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_DELETE_RULE_OK); mDeleting = true; removeZenRule(mRule.getId()); removeZenRule(mId); } }) .show(); Loading src/com/android/settings/notification/ZenModeSettingsBase.java +14 −8 Original line number Diff line number Diff line Loading @@ -31,7 +31,10 @@ import android.util.Log; import com.android.settings.RestrictedSettingsFragment; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; abstract public class ZenModeSettingsBase extends RestrictedSettingsFragment { protected static final String TAG = "ZenModeSettings"; Loading @@ -41,7 +44,7 @@ abstract public class ZenModeSettingsBase extends RestrictedSettingsFragment { private final SettingsObserver mSettingsObserver = new SettingsObserver(); protected Context mContext; protected List<AutomaticZenRule> mRules; protected Set<Map.Entry<String, AutomaticZenRule>> mRules; protected int mZenMode; abstract protected void onZenModeChanged(); Loading Loading @@ -92,16 +95,17 @@ abstract public class ZenModeSettingsBase extends RestrictedSettingsFragment { } } protected AutomaticZenRule addZenRule(AutomaticZenRule rule) { protected String addZenRule(AutomaticZenRule rule) { String id = NotificationManager.from(mContext).addAutomaticZenRule(rule); final AutomaticZenRule savedRule = NotificationManager.from(mContext).addAutomaticZenRule(rule); NotificationManager.from(mContext).getAutomaticZenRule(id); maybeRefreshRules(savedRule != null, true); return savedRule; return id; } protected boolean setZenRule(AutomaticZenRule rule) { protected boolean setZenRule(String id, AutomaticZenRule rule) { final boolean success = NotificationManager.from(mContext).updateAutomaticZenRule(rule); NotificationManager.from(mContext).updateAutomaticZenRule(id, rule); maybeRefreshRules(success, true); return success; } Loading @@ -127,8 +131,10 @@ abstract public class ZenModeSettingsBase extends RestrictedSettingsFragment { NotificationManager.from(mContext).setZenMode(zenMode, conditionId, TAG); } private List<AutomaticZenRule> getZenModeRules() { return NotificationManager.from(mContext).getAutomaticZenRules(); private Set<Map.Entry<String, AutomaticZenRule>> getZenModeRules() { Map<String, AutomaticZenRule> ruleMap = NotificationManager.from(mContext).getAutomaticZenRules(); return ruleMap.entrySet(); } private final class SettingsObserver extends ContentObserver { Loading src/com/android/settings/notification/ZenRuleNameDialog.java +3 −3 Original line number Diff line number Diff line Loading @@ -31,10 +31,10 @@ public abstract class ZenRuleNameDialog { private final AlertDialog mDialog; private final EditText mEditText; private final String mOriginalRuleName; private final CharSequence mOriginalRuleName; private final boolean mIsNew; public ZenRuleNameDialog(Context context, String ruleName) { public ZenRuleNameDialog(Context context, CharSequence ruleName) { mIsNew = ruleName == null; mOriginalRuleName = ruleName; final View v = LayoutInflater.from(context).inflate(R.layout.zen_rule_name, null, false); Loading @@ -52,7 +52,7 @@ public abstract class ZenRuleNameDialog { public void onClick(DialogInterface dialog, int which) { final String newName = trimmedText(); if (!mIsNew && mOriginalRuleName != null && mOriginalRuleName.equalsIgnoreCase(newName)) { && mOriginalRuleName.equals(newName)) { return; // no change to an existing rule, just dismiss } onOk(newName); Loading Loading
src/com/android/settings/dashboard/SuggestionsChecks.java +5 −5 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ import com.android.settings.Settings.WifiCallingSuggestionActivity; import com.android.settings.Settings.ZenModeAutomationSuggestionActivity; import com.android.settingslib.drawer.Tile; import java.util.List; import java.util.Collection; /** * The Home of all stupidly dynamic Settings Suggestions checks. Loading Loading @@ -86,10 +86,10 @@ public class SuggestionsChecks { } private boolean hasEnabledZenAutoRules() { List<AutomaticZenRule> zenRules = NotificationManager.from(mContext).getAutomaticZenRules(); final int N = zenRules.size(); for (int i = 0; i < N; i++) { if (zenRules.get(i).isEnabled()) { Collection<AutomaticZenRule> zenRules = NotificationManager.from(mContext).getAutomaticZenRules().values(); for (AutomaticZenRule rule : zenRules) { if (rule.isEnabled()) { return true; } } Loading
src/com/android/settings/notification/ZenModeAutomationSettings.java +24 −17 Original line number Diff line number Diff line Loading @@ -46,7 +46,9 @@ import com.android.settings.notification.ManagedServiceSettings.Config; import java.lang.ref.WeakReference; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Map; public class ZenModeAutomationSettings extends ZenModeSettingsBase { Loading Loading @@ -111,15 +113,15 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { AutomaticZenRule rule = new AutomaticZenRule(ruleName, ri.serviceComponent, ri.defaultConditionId, NotificationManager.INTERRUPTION_FILTER_PRIORITY, true); AutomaticZenRule savedRule = addZenRule(rule); if (savedRule != null) { startActivity(getRuleIntent(ri.settingsAction, null, savedRule.getId())); String savedRuleId = addZenRule(rule); if (savedRuleId != null) { startActivity(getRuleIntent(ri.settingsAction, null, savedRuleId)); } } }.show(); } private void showDeleteRuleDialog(final String ruleId, final String ruleName) { private void showDeleteRuleDialog(final String ruleId, final CharSequence ruleName) { new AlertDialog.Builder(mContext) .setMessage(getString(R.string.zen_mode_delete_rule_confirmation, ruleName)) .setNegativeButton(R.string.cancel, null) Loading Loading @@ -147,8 +149,9 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { return intent; } private AutomaticZenRule[] sortedRules() { final AutomaticZenRule[] rt = mRules.toArray(new AutomaticZenRule[mRules.size()]); private Map.Entry<String,AutomaticZenRule>[] sortedRules() { final Map.Entry<String,AutomaticZenRule>[] rt = mRules.toArray(new Map.Entry[mRules.size()]); Arrays.sort(rt, RULE_COMPARATOR); return rt; } Loading @@ -156,8 +159,8 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { private void updateControls() { final PreferenceScreen root = getPreferenceScreen(); root.removeAll(); final AutomaticZenRule[] sortedRules = sortedRules(); for (AutomaticZenRule sortedRule : sortedRules) { final Map.Entry<String,AutomaticZenRule>[] sortedRules = sortedRules(); for (Map.Entry<String,AutomaticZenRule> sortedRule : sortedRules) { ZenRulePreference pref = new ZenRulePreference(getPrefContext(), sortedRule); if (pref.appExists) { root.addPreference(pref); Loading Loading @@ -247,15 +250,17 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { return null; } private static final Comparator<AutomaticZenRule> RULE_COMPARATOR = new Comparator<AutomaticZenRule>() { private static final Comparator<Map.Entry<String,AutomaticZenRule>> RULE_COMPARATOR = new Comparator<Map.Entry<String,AutomaticZenRule>>() { @Override public int compare(AutomaticZenRule lhs, AutomaticZenRule rhs) { int byDate = Long.compare(lhs.getCreationTime(), rhs.getCreationTime()); public int compare(Map.Entry<String,AutomaticZenRule> lhs, Map.Entry<String,AutomaticZenRule> rhs) { int byDate = Long.compare(lhs.getValue().getCreationTime(), rhs.getValue().getCreationTime()); if (byDate != 0) { return byDate; } else { return key(lhs).compareTo(key(rhs)); return key(lhs.getValue()).compareTo(key(rhs.getValue())); } } Loading @@ -263,20 +268,22 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase { final int type = ZenModeConfig.isValidScheduleConditionId(rule.getConditionId()) ? 1 : ZenModeConfig.isValidEventConditionId(rule.getConditionId()) ? 2 : 3; return type + rule.getName(); return type + rule.getName().toString(); } }; private class ZenRulePreference extends Preference { final String mName; final CharSequence mName; final String mId; final boolean appExists; public ZenRulePreference(Context context, final AutomaticZenRule rule) { public ZenRulePreference(Context context, final Map.Entry<String, AutomaticZenRule> ruleEntry) { super(context); final AutomaticZenRule rule = ruleEntry.getValue(); mName = rule.getName(); mId = rule.getId(); mId = ruleEntry.getKey(); final boolean isSchedule = ZenModeConfig.isValidScheduleConditionId( rule.getConditionId()); Loading
src/com/android/settings/notification/ZenModeRuleSettingsBase.java +5 −5 Original line number Diff line number Diff line Loading @@ -123,7 +123,7 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase if (zenMode == mRule.getInterruptionFilter()) return false; if (DEBUG) Log.d(TAG, "onPrefChange zenMode=" + zenMode); mRule.setInterruptionFilter(zenMode); setZenRule(mRule); setZenRule(mId, mRule); return true; } }); Loading Loading @@ -166,7 +166,7 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_ENABLE_RULE, enabled); if (DEBUG) Log.d(TAG, "onSwitchChanged enabled=" + enabled); mRule.setEnabled(enabled); setZenRule(mRule); setZenRule(mId, mRule); if (enabled) { final int toastText = getEnabledToastText(); if (toastText != 0) { Loading @@ -182,7 +182,7 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase protected void updateRule(Uri newConditionId) { mRule.setConditionId(newConditionId); setZenRule(mRule); setZenRule(mId, mRule); } @Override Loading Loading @@ -219,7 +219,7 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase @Override public void onOk(String ruleName) { mRule.setName(ruleName); setZenRule(mRule); setZenRule(mId, mRule); } }.show(); } Loading @@ -243,7 +243,7 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase public void onClick(DialogInterface dialog, int which) { MetricsLogger.action(mContext, MetricsEvent.ACTION_ZEN_DELETE_RULE_OK); mDeleting = true; removeZenRule(mRule.getId()); removeZenRule(mId); } }) .show(); Loading
src/com/android/settings/notification/ZenModeSettingsBase.java +14 −8 Original line number Diff line number Diff line Loading @@ -31,7 +31,10 @@ import android.util.Log; import com.android.settings.RestrictedSettingsFragment; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; abstract public class ZenModeSettingsBase extends RestrictedSettingsFragment { protected static final String TAG = "ZenModeSettings"; Loading @@ -41,7 +44,7 @@ abstract public class ZenModeSettingsBase extends RestrictedSettingsFragment { private final SettingsObserver mSettingsObserver = new SettingsObserver(); protected Context mContext; protected List<AutomaticZenRule> mRules; protected Set<Map.Entry<String, AutomaticZenRule>> mRules; protected int mZenMode; abstract protected void onZenModeChanged(); Loading Loading @@ -92,16 +95,17 @@ abstract public class ZenModeSettingsBase extends RestrictedSettingsFragment { } } protected AutomaticZenRule addZenRule(AutomaticZenRule rule) { protected String addZenRule(AutomaticZenRule rule) { String id = NotificationManager.from(mContext).addAutomaticZenRule(rule); final AutomaticZenRule savedRule = NotificationManager.from(mContext).addAutomaticZenRule(rule); NotificationManager.from(mContext).getAutomaticZenRule(id); maybeRefreshRules(savedRule != null, true); return savedRule; return id; } protected boolean setZenRule(AutomaticZenRule rule) { protected boolean setZenRule(String id, AutomaticZenRule rule) { final boolean success = NotificationManager.from(mContext).updateAutomaticZenRule(rule); NotificationManager.from(mContext).updateAutomaticZenRule(id, rule); maybeRefreshRules(success, true); return success; } Loading @@ -127,8 +131,10 @@ abstract public class ZenModeSettingsBase extends RestrictedSettingsFragment { NotificationManager.from(mContext).setZenMode(zenMode, conditionId, TAG); } private List<AutomaticZenRule> getZenModeRules() { return NotificationManager.from(mContext).getAutomaticZenRules(); private Set<Map.Entry<String, AutomaticZenRule>> getZenModeRules() { Map<String, AutomaticZenRule> ruleMap = NotificationManager.from(mContext).getAutomaticZenRules(); return ruleMap.entrySet(); } private final class SettingsObserver extends ContentObserver { Loading
src/com/android/settings/notification/ZenRuleNameDialog.java +3 −3 Original line number Diff line number Diff line Loading @@ -31,10 +31,10 @@ public abstract class ZenRuleNameDialog { private final AlertDialog mDialog; private final EditText mEditText; private final String mOriginalRuleName; private final CharSequence mOriginalRuleName; private final boolean mIsNew; public ZenRuleNameDialog(Context context, String ruleName) { public ZenRuleNameDialog(Context context, CharSequence ruleName) { mIsNew = ruleName == null; mOriginalRuleName = ruleName; final View v = LayoutInflater.from(context).inflate(R.layout.zen_rule_name, null, false); Loading @@ -52,7 +52,7 @@ public abstract class ZenRuleNameDialog { public void onClick(DialogInterface dialog, int which) { final String newName = trimmedText(); if (!mIsNew && mOriginalRuleName != null && mOriginalRuleName.equalsIgnoreCase(newName)) { && mOriginalRuleName.equals(newName)) { return; // no change to an existing rule, just dismiss } onOk(newName); Loading