Beverly | 3235221 | 2017-11-20 17:33:01 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.settings.notification; |
| 18 | |
Beverly | 3235221 | 2017-11-20 17:33:01 -0500 | [diff] [blame] | 19 | import android.app.Dialog; |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 20 | import android.app.settings.SettingsEnums; |
Beverly | 3235221 | 2017-11-20 17:33:01 -0500 | [diff] [blame] | 21 | import android.content.DialogInterface; |
| 22 | import android.os.Bundle; |
Beverly | 5fbdeaa | 2018-10-01 14:29:37 -0400 | [diff] [blame] | 23 | import android.text.BidiFormatter; |
Beverly | 3235221 | 2017-11-20 17:33:01 -0500 | [diff] [blame] | 24 | import android.view.View; |
| 25 | |
Beverly | 5fbdeaa | 2018-10-01 14:29:37 -0400 | [diff] [blame] | 26 | import androidx.appcompat.app.AlertDialog; |
| 27 | import androidx.fragment.app.Fragment; |
| 28 | |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 29 | import com.android.settings.R; |
| 30 | import com.android.settings.core.instrumentation.InstrumentedDialogFragment; |
| 31 | |
Beverly | 3235221 | 2017-11-20 17:33:01 -0500 | [diff] [blame] | 32 | public 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) { |
Beverly | 5fbdeaa | 2018-10-01 14:29:37 -0400 | [diff] [blame] | 47 | final BidiFormatter bidi = BidiFormatter.getInstance(); |
Beverly | 3235221 | 2017-11-20 17:33:01 -0500 | [diff] [blame] | 48 | final Bundle args = new Bundle(); |
Beverly | 5fbdeaa | 2018-10-01 14:29:37 -0400 | [diff] [blame] | 49 | args.putString(EXTRA_ZEN_RULE_NAME, bidi.unicodeWrap(ruleName)); |
Beverly | 3235221 | 2017-11-20 17:33:01 -0500 | [diff] [blame] | 50 | 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 Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 61 | return SettingsEnums.NOTIFICATION_ZEN_MODE_DELETE_RULE_DIALOG; |
Beverly | 3235221 | 2017-11-20 17:33:01 -0500 | [diff] [blame] | 62 | } |
| 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 | } |