Updates to automatic rule pages in Settings

- Re-added metrics for zen behavior preference controllers
- Dialogs in zen mode settings are rotate-friendly
- Automatic rules are refreshed on update state
- User-created (and default) automatic rules are always priority only and user cannot change this
- Automatic rules redesigned to have headers

Test: make ROBOTEST_FILTER=ZenModeAutomaticRulesPreferenceControllerTest RunSettingsRoboTests -j40
Bug: 63077372
Fixes: 68324465
Fixes: 69057696
Change-Id: I163acef2715dd4e60bfc08207f0e22352c4c0e28
This commit is contained in:
Beverly
2017-11-20 17:33:01 -05:00
parent 91fff3093d
commit 323522171d
25 changed files with 829 additions and 405 deletions

View File

@@ -19,28 +19,31 @@ package com.android.settings.notification;
import android.app.AutomaticZenRule;
import android.app.Fragment;
import android.content.Context;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceScreen;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.Map;
public class ZenModeAutomaticRulesPreferenceController extends
AbstractZenModeAutomaticRulePreferenceController {
private final String KEY_AUTOMATIC_RULES;
private PreferenceCategory mPreferenceCategory;
Map.Entry<String, AutomaticZenRule>[] mSortedRules;
protected static final String KEY = "zen_mode_automatic_rules";
public ZenModeAutomaticRulesPreferenceController(Context context, String key,
Fragment parent) {
super(context, parent);
KEY_AUTOMATIC_RULES = key;
mSortedRules = sortedRules();
@VisibleForTesting
protected PreferenceCategory mPreferenceCategory;
public ZenModeAutomaticRulesPreferenceController(Context context, Fragment parent, Lifecycle
lifecycle) {
super(context, KEY, parent, lifecycle);
}
@Override
public String getPreferenceKey() {
return KEY_AUTOMATIC_RULES;
return KEY;
}
@Override
@@ -59,40 +62,14 @@ public class ZenModeAutomaticRulesPreferenceController extends
public void updateState(Preference preference) {
super.updateState(preference);
// no need to update AutomaticRule if a rule was deleted
// (on rule deletion, the preference removes itself from its parent)
int oldRuleLength = mSortedRules.length;
mSortedRules = sortedRules();
if (!wasRuleDeleted(oldRuleLength)) {
updateAutomaticRules();
mPreferenceCategory.removeAll();
Map.Entry<String, AutomaticZenRule>[] sortedRules = sortedRules();
for (Map.Entry<String, AutomaticZenRule> sortedRule : sortedRules) {
ZenRulePreference pref = new ZenRulePreference(mPreferenceCategory.getContext(),
sortedRule, mParent, mMetricsFeatureProvider);
mPreferenceCategory.addPreference(pref);
}
}
private boolean wasRuleDeleted(int oldRuleLength) {
int newRuleLength = mSortedRules.length;
int prefCount = mPreferenceCategory.getPreferenceCount();
return (prefCount == oldRuleLength -1) && (prefCount == newRuleLength);
}
private void updateAutomaticRules() {
for (Map.Entry<String, AutomaticZenRule> sortedRule : mSortedRules) {
ZenRulePreference currPref = (ZenRulePreference)
mPreferenceCategory.findPreference(sortedRule.getKey());
if (currPref != null && currPref.appExists) {
// rule already exists in preferences, update it
currPref.setAttributes(sortedRule.getValue());
} else {
// rule doesn't exist in preferences, add it
ZenRulePreference pref = new ZenRulePreference(mPreferenceCategory.getContext(),
sortedRule, mPreferenceCategory);
if (pref.appExists) {
mPreferenceCategory.addPreference(pref);
}
}
}
}
}