blob: 694fcbac0a21d408279103c214bc446072623f7a [file] [log] [blame]
Beverly32352212017-11-20 17:33:01 -05001/*
2 * Copyright (c) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings.notification;
18
Beverly32352212017-11-20 17:33:01 -050019import android.app.Dialog;
Fan Zhang31b21002019-01-16 13:49:47 -080020import android.app.settings.SettingsEnums;
Beverly32352212017-11-20 17:33:01 -050021import android.content.DialogInterface;
22import android.os.Bundle;
Beverly5fbdeaa2018-10-01 14:29:37 -040023import android.text.BidiFormatter;
Beverly32352212017-11-20 17:33:01 -050024import android.view.View;
25
Beverly5fbdeaa2018-10-01 14:29:37 -040026import androidx.appcompat.app.AlertDialog;
27import androidx.fragment.app.Fragment;
28
Fan Zhang31b21002019-01-16 13:49:47 -080029import com.android.settings.R;
30import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
31
Beverly32352212017-11-20 17:33:01 -050032public class ZenDeleteRuleDialog extends InstrumentedDialogFragment {
33 protected static final String TAG = "ZenDeleteRuleDialog";
34 private static final String EXTRA_ZEN_RULE_NAME = "zen_rule_name";
35 private static final String EXTRA_ZEN_RULE_ID = "zen_rule_id";
36 protected static PositiveClickListener mPositiveClickListener;
37
38 /**
39 * The interface we expect a listener to implement.
40 */
41 public interface PositiveClickListener {
42 void onOk(String id);
43 }
44
45 public static void show(Fragment parent, String ruleName, String id, PositiveClickListener
46 listener) {
Beverly5fbdeaa2018-10-01 14:29:37 -040047 final BidiFormatter bidi = BidiFormatter.getInstance();
Beverly32352212017-11-20 17:33:01 -050048 final Bundle args = new Bundle();
Beverly5fbdeaa2018-10-01 14:29:37 -040049 args.putString(EXTRA_ZEN_RULE_NAME, bidi.unicodeWrap(ruleName));
Beverly32352212017-11-20 17:33:01 -050050 args.putString(EXTRA_ZEN_RULE_ID, id);
51 mPositiveClickListener = listener;
52
53 ZenDeleteRuleDialog dialog = new ZenDeleteRuleDialog();
54 dialog.setArguments(args);
55 dialog.setTargetFragment(parent, 0);
56 dialog.show(parent.getFragmentManager(), TAG);
57 }
58
59 @Override
60 public int getMetricsCategory() {
Fan Zhang31b21002019-01-16 13:49:47 -080061 return SettingsEnums.NOTIFICATION_ZEN_MODE_DELETE_RULE_DIALOG;
Beverly32352212017-11-20 17:33:01 -050062 }
63
64 @Override
65 public Dialog onCreateDialog(Bundle savedInstanceState) {
66 Bundle arguments = getArguments();
67 String ruleName = arguments.getString(EXTRA_ZEN_RULE_NAME);
68 String id = arguments.getString(EXTRA_ZEN_RULE_ID);
69
70 final AlertDialog dialog = new AlertDialog.Builder(getContext())
71 .setMessage(getString(R.string.zen_mode_delete_rule_confirmation, ruleName))
72 .setNegativeButton(R.string.cancel, null)
73 .setPositiveButton(R.string.zen_mode_delete_rule_button,
74 new DialogInterface.OnClickListener() {
75 @Override
76 public void onClick(DialogInterface dialog, int which) {
77 if (arguments != null) {
78 mPositiveClickListener.onOk(id);
79 }
80 }
81 }).create();
82 final View messageView = dialog.findViewById(android.R.id.message);
83 if (messageView != null) {
84 messageView.setTextDirection(View.TEXT_DIRECTION_LOCALE);
85 }
86 return dialog;
87 }
88
89}