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

@@ -16,23 +16,21 @@
package com.android.settings.notification;
import android.app.AlertDialog;
import android.app.AutomaticZenRule;
import android.app.NotificationManager;
import android.app.Fragment;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.service.notification.ZenModeConfig;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceViewHolder;
import android.view.View;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.utils.ManagedServiceSettings;
import com.android.settings.utils.ZenServiceListing;
import com.android.settingslib.TwoTargetPreference;
@@ -45,16 +43,17 @@ public class ZenRulePreference extends TwoTargetPreference {
final CharSequence mName;
final String mId;
boolean appExists;
final PreferenceCategory mParent;
final Fragment mParent;
final Preference mPref;
final Context mContext;
final ZenModeBackend mBackend;
final ZenServiceListing mServiceListing;
final PackageManager mPm;
final MetricsFeatureProvider mMetricsFeatureProvider;
public ZenRulePreference(Context context,
final Map.Entry<String, AutomaticZenRule> ruleEntry,
PreferenceCategory prefCategory) {
Fragment parent, MetricsFeatureProvider metricsProvider) {
super(context);
mBackend = ZenModeBackend.getInstance(context);
@@ -62,11 +61,12 @@ public class ZenRulePreference extends TwoTargetPreference {
final AutomaticZenRule rule = ruleEntry.getValue();
mName = rule.getName();
mId = ruleEntry.getKey();
mParent = prefCategory;
mParent = parent;
mPm = mContext.getPackageManager();
mServiceListing = new ZenServiceListing(mContext, CONFIG);
mServiceListing.reloadApprovedServices();
mPref = this;
mMetricsFeatureProvider = metricsProvider;
setAttributes(rule);
}
@@ -89,25 +89,21 @@ public class ZenRulePreference extends TwoTargetPreference {
private final View.OnClickListener mDeleteListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
showDeleteRuleDialog(mId, mName, mParent, mPref);
showDeleteRuleDialog(mParent, mId, mName.toString());
}
};
private void showDeleteRuleDialog(final String ruleId, final CharSequence ruleName,
PreferenceCategory parent, Preference pref) {
new AlertDialog.Builder(mContext)
.setMessage(mContext.getResources().getString(
R.string.zen_mode_delete_rule_confirmation, ruleName))
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.zen_mode_delete_rule_button,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mBackend.removeZenRule(ruleId);
parent.removePreference(pref);
}
})
.show();
private void showDeleteRuleDialog(final Fragment parent, final String ruleId,
final String ruleName) {
ZenDeleteRuleDialog.show(parent, ruleName, ruleId,
new ZenDeleteRuleDialog.PositiveClickListener() {
@Override
public void onOk(String id) {
mMetricsFeatureProvider.action(mContext,
MetricsProto.MetricsEvent.ACTION_ZEN_DELETE_RULE_OK);
mBackend.removeZenRule(id);
}
});
}
protected void setAttributes(AutomaticZenRule rule) {
@@ -141,26 +137,8 @@ public class ZenRulePreference extends TwoTargetPreference {
private String computeRuleSummary(AutomaticZenRule rule, boolean isSystemRule,
CharSequence providerLabel) {
final String mode = computeZenModeCaption(mContext.getResources(),
rule.getInterruptionFilter());
final String ruleState = (rule == null || !rule.isEnabled())
return (rule == null || !rule.isEnabled())
? mContext.getResources().getString(R.string.switch_off_text)
: mContext.getResources().getString(
R.string.zen_mode_rule_summary_enabled_combination, mode);
return ruleState;
}
private static String computeZenModeCaption(Resources res, int zenMode) {
switch (zenMode) {
case NotificationManager.INTERRUPTION_FILTER_ALARMS:
return res.getString(R.string.zen_mode_option_alarms);
case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
return res.getString(R.string.zen_mode_option_important_interruptions);
case NotificationManager.INTERRUPTION_FILTER_NONE:
return res.getString(R.string.zen_mode_option_no_interruptions);
default:
return null;
}
: mContext.getResources().getString(R.string.switch_on_text);
}
}