Merge "Warn users about rule deletion when revoking DND access."

This commit is contained in:
Julia Reynolds
2015-12-02 20:27:48 +00:00
committed by Android (Google) Code Review
2 changed files with 74 additions and 8 deletions

View File

@@ -6864,6 +6864,12 @@
<!-- Zen mode access settings - summary for warning dialog when enabling access [CHAR LIMIT=NONE] -->
<string name="zen_access_warning_dialog_summary">The app will be able to turn on/off Do Not Disturb and make changes to related settings.</string>
<!-- Zen mode access settings - title for warning dialog when revoking access [CHAR LIMIT=NONE] -->
<string name="zen_access_revoke_warning_dialog_title">Revoke access to Do Not Disturb for <xliff:g id="app" example="Tasker">%1$s</xliff:g>?</string>
<!-- Zen mode access settings - summary for warning dialog when revoking access [CHAR LIMIT=NONE] -->
<string name="zen_access_revoke_warning_dialog_summary">All Do Not Disturb rules created by this app will be removed.</string>
<!-- Ignore battery optimizations on label [CHAR LIMIT=30] -->
<string name="ignore_optimizations_on">Don\u2019t optimize</string>

View File

@@ -119,15 +119,15 @@ public class ZenAccessSettings extends EmptyTextSettings {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean access = (Boolean) newValue;
if (!access) {
// disabling access
setAccess(mContext, pkg, access);
return true;
if (access) {
new ScaryWarningDialogFragment()
.setPkgInfo(pkg, label)
.show(getFragmentManager(), "dialog");
} else {
new FriendlyWarningDialogFragment()
.setPkgInfo(pkg, label)
.show(getFragmentManager(), "dialog");
}
// enabling access: show a scary dialog first
new ScaryWarningDialogFragment()
.setPkgInfo(pkg, label)
.show(getFragmentManager(), "dialog");
return false;
}
});
@@ -149,6 +149,16 @@ public class ZenAccessSettings extends EmptyTextSettings {
});
}
private static void deleteRules(final Context context, final String pkg) {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
final NotificationManager mgr = context.getSystemService(NotificationManager.class);
mgr.removeAutomaticZenRules(pkg);
}
});
}
private final class SettingObserver extends ContentObserver {
public SettingObserver() {
super(new Handler(Looper.getMainLooper()));
@@ -160,6 +170,9 @@ public class ZenAccessSettings extends EmptyTextSettings {
}
}
/**
* Warning dialog when allowing zen access warning about the privileges being granted.
*/
public static class ScaryWarningDialogFragment extends DialogFragment {
static final String KEY_PKG = "p";
static final String KEY_LABEL = "l";
@@ -202,4 +215,51 @@ public class ZenAccessSettings extends EmptyTextSettings {
.create();
}
}
/**
* Warning dialog when revoking zen access warning that zen rule instances will be deleted.
*/
public static class FriendlyWarningDialogFragment extends DialogFragment {
static final String KEY_PKG = "p";
static final String KEY_LABEL = "l";
public FriendlyWarningDialogFragment setPkgInfo(String pkg, CharSequence label) {
Bundle args = new Bundle();
args.putString(KEY_PKG, pkg);
args.putString(KEY_LABEL, TextUtils.isEmpty(label) ? pkg : label.toString());
setArguments(args);
return this;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Bundle args = getArguments();
final String pkg = args.getString(KEY_PKG);
final String label = args.getString(KEY_LABEL);
final String title = getResources().getString(
R.string.zen_access_revoke_warning_dialog_title, label);
final String summary = getResources()
.getString(R.string.zen_access_revoke_warning_dialog_summary);
return new AlertDialog.Builder(getContext())
.setMessage(summary)
.setTitle(title)
.setCancelable(true)
.setPositiveButton(R.string.okay,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
deleteRules(getContext(), pkg);
setAccess(getContext(), pkg, false);
}
})
.setNegativeButton(R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// pass
}
})
.create();
}
}
}