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 19 import android.app.AlertDialog; 20 import android.app.Dialog; 21 import android.app.Fragment; 22 import android.content.DialogInterface; 23 import android.os.Bundle; 24 import android.view.View; 25 26 import com.android.internal.logging.nano.MetricsProto; 27 import com.android.settings.R; 28 import com.android.settings.core.instrumentation.InstrumentedDialogFragment; 29 30 public class ZenDeleteRuleDialog extends InstrumentedDialogFragment { 31 protected static final String TAG = "ZenDeleteRuleDialog"; 32 private static final String EXTRA_ZEN_RULE_NAME = "zen_rule_name"; 33 private static final String EXTRA_ZEN_RULE_ID = "zen_rule_id"; 34 protected static PositiveClickListener mPositiveClickListener; 35 36 /** 37 * The interface we expect a listener to implement. 38 */ 39 public interface PositiveClickListener { onOk(String id)40 void onOk(String id); 41 } 42 show(Fragment parent, String ruleName, String id, PositiveClickListener listener)43 public static void show(Fragment parent, String ruleName, String id, PositiveClickListener 44 listener) { 45 final Bundle args = new Bundle(); 46 args.putString(EXTRA_ZEN_RULE_NAME, ruleName); 47 args.putString(EXTRA_ZEN_RULE_ID, id); 48 mPositiveClickListener = listener; 49 50 ZenDeleteRuleDialog dialog = new ZenDeleteRuleDialog(); 51 dialog.setArguments(args); 52 dialog.setTargetFragment(parent, 0); 53 dialog.show(parent.getFragmentManager(), TAG); 54 } 55 56 @Override getMetricsCategory()57 public int getMetricsCategory() { 58 return MetricsProto.MetricsEvent.NOTIFICATION_ZEN_MODE_DELETE_RULE_DIALOG; 59 } 60 61 @Override onCreateDialog(Bundle savedInstanceState)62 public Dialog onCreateDialog(Bundle savedInstanceState) { 63 Bundle arguments = getArguments(); 64 String ruleName = arguments.getString(EXTRA_ZEN_RULE_NAME); 65 String id = arguments.getString(EXTRA_ZEN_RULE_ID); 66 67 final AlertDialog dialog = new AlertDialog.Builder(getContext()) 68 .setMessage(getString(R.string.zen_mode_delete_rule_confirmation, ruleName)) 69 .setNegativeButton(R.string.cancel, null) 70 .setPositiveButton(R.string.zen_mode_delete_rule_button, 71 new DialogInterface.OnClickListener() { 72 @Override 73 public void onClick(DialogInterface dialog, int which) { 74 if (arguments != null) { 75 mPositiveClickListener.onOk(id); 76 } 77 } 78 }).create(); 79 final View messageView = dialog.findViewById(android.R.id.message); 80 if (messageView != null) { 81 messageView.setTextDirection(View.TEXT_DIRECTION_LOCALE); 82 } 83 return dialog; 84 } 85 86 } 87