Merge "Warn users about rule deletion when revoking DND access."
This commit is contained in:
committed by
Android (Google) Code Review
commit
0fab3131fb
@@ -6864,6 +6864,12 @@
|
|||||||
<!-- Zen mode access settings - summary for warning dialog when enabling access [CHAR LIMIT=NONE] -->
|
<!-- 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>
|
<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] -->
|
<!-- Ignore battery optimizations on label [CHAR LIMIT=30] -->
|
||||||
<string name="ignore_optimizations_on">Don\u2019t optimize</string>
|
<string name="ignore_optimizations_on">Don\u2019t optimize</string>
|
||||||
|
|
||||||
|
@@ -119,15 +119,15 @@ public class ZenAccessSettings extends EmptyTextSettings {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
final boolean access = (Boolean) newValue;
|
final boolean access = (Boolean) newValue;
|
||||||
if (!access) {
|
if (access) {
|
||||||
// disabling access
|
new ScaryWarningDialogFragment()
|
||||||
setAccess(mContext, pkg, access);
|
.setPkgInfo(pkg, label)
|
||||||
return true;
|
.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;
|
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 {
|
private final class SettingObserver extends ContentObserver {
|
||||||
public SettingObserver() {
|
public SettingObserver() {
|
||||||
super(new Handler(Looper.getMainLooper()));
|
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 {
|
public static class ScaryWarningDialogFragment extends DialogFragment {
|
||||||
static final String KEY_PKG = "p";
|
static final String KEY_PKG = "p";
|
||||||
static final String KEY_LABEL = "l";
|
static final String KEY_LABEL = "l";
|
||||||
@@ -202,4 +215,51 @@ public class ZenAccessSettings extends EmptyTextSettings {
|
|||||||
.create();
|
.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user