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,16 +16,20 @@
package com.android.settings.notification;
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Fragment;
import android.app.NotificationManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.service.notification.ZenModeConfig;
import android.util.Log;
import android.view.LayoutInflater;
@@ -35,6 +39,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.utils.ZenServiceListing;
import java.lang.ref.WeakReference;
@@ -43,24 +48,48 @@ import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;
public abstract class ZenRuleSelectionDialog {
public class ZenRuleSelectionDialog extends InstrumentedDialogFragment {
private static final String TAG = "ZenRuleSelectionDialog";
private static final boolean DEBUG = ZenModeSettings.DEBUG;
private final Context mContext;
private final PackageManager mPm;
private NotificationManager mNm;
private final AlertDialog mDialog;
private final LinearLayout mRuleContainer;
private final ZenServiceListing mServiceListing;
private static ZenServiceListing mServiceListing;
protected static PositiveClickListener mPositiveClickListener;
public ZenRuleSelectionDialog(Context context, ZenServiceListing serviceListing) {
private static Context mContext;
private static PackageManager mPm;
private static NotificationManager mNm;
private LinearLayout mRuleContainer;
/**
* The interface we expect a listener to implement.
*/
public interface PositiveClickListener {
void onSystemRuleSelected(ZenRuleInfo ruleInfo, Fragment parent);
void onExternalRuleSelected(ZenRuleInfo ruleInfo, Fragment parent);
}
@Override
public int getMetricsCategory() {
return MetricsEvent.NOTIFICATION_ZEN_MODE_RULE_SELECTION_DIALOG;
}
public static void show(Context context, Fragment parent, PositiveClickListener
listener, ZenServiceListing serviceListing) {
mPositiveClickListener = listener;
mContext = context;
mPm = context.getPackageManager();
mNm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mPm = mContext.getPackageManager();
mNm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
mServiceListing = serviceListing;
final View v =
LayoutInflater.from(context).inflate(R.layout.zen_rule_type_selection, null, false);
ZenRuleSelectionDialog dialog = new ZenRuleSelectionDialog();
dialog.setTargetFragment(parent, 0);
dialog.show(parent.getFragmentManager(), TAG);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final View v = LayoutInflater.from(getContext()).inflate(R.layout.zen_rule_type_selection,
null, false);
mRuleContainer = (LinearLayout) v.findViewById(R.id.rule_container);
if (mServiceListing != null) {
@@ -69,28 +98,21 @@ public abstract class ZenRuleSelectionDialog {
mServiceListing.addZenCallback(mServiceListingCallback);
mServiceListing.reloadApprovedServices();
}
mDialog = new AlertDialog.Builder(context)
return new AlertDialog.Builder(getContext())
.setTitle(R.string.zen_mode_choose_rule_type)
.setView(v)
.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (mServiceListing != null) {
mServiceListing.removeZenCallback(mServiceListingCallback);
}
}
})
.setNegativeButton(R.string.cancel, null)
.create();
}
public void show() {
mDialog.show();
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
if (mServiceListing != null) {
mServiceListing.removeZenCallback(mServiceListingCallback);
}
}
abstract public void onSystemRuleSelected(ZenRuleInfo ruleInfo);
abstract public void onExternalRuleSelected(ZenRuleInfo ruleInfo);
private void bindType(final ZenRuleInfo ri) {
try {
ApplicationInfo info = mPm.getApplicationInfo(ri.packageName, 0);
@@ -108,11 +130,11 @@ public abstract class ZenRuleSelectionDialog {
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDialog.dismiss();
dismiss();
if (ri.isSystem) {
onSystemRuleSelected(ri);
mPositiveClickListener.onSystemRuleSelected(ri, getTargetFragment());
} else {
onExternalRuleSelected(ri);
mPositiveClickListener.onExternalRuleSelected(ri, getTargetFragment());
}
}
});