1 /* 2 * Copyright (C) 2015 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.packageinstaller.permission.ui; 18 19 import android.app.Activity; 20 import android.app.AlertDialog; 21 import android.app.Dialog; 22 import android.os.Bundle; 23 24 import androidx.fragment.app.DialogFragment; 25 26 import com.android.permissioncontroller.R; 27 28 public final class ConfirmActionDialogFragment extends DialogFragment { 29 public static final String ARG_MESSAGE = "MESSAGE"; 30 public static final String ARG_ACTION = "ACTION"; 31 32 public interface OnActionConfirmedListener { onActionConfirmed(String action)33 void onActionConfirmed(String action); 34 } 35 newInstance(CharSequence message, String action)36 public static ConfirmActionDialogFragment newInstance(CharSequence message, String action) { 37 Bundle arguments = new Bundle(); 38 arguments.putCharSequence(ARG_MESSAGE, message); 39 arguments.putString(ARG_ACTION, action); 40 ConfirmActionDialogFragment fragment = new ConfirmActionDialogFragment(); 41 fragment.setArguments(arguments); 42 return fragment; 43 } 44 45 @Override onCreateDialog(Bundle bundle)46 public Dialog onCreateDialog(Bundle bundle) { 47 return new AlertDialog.Builder(getContext()) 48 .setMessage(getArguments().getString(ARG_MESSAGE)) 49 .setNegativeButton(R.string.cancel, null) 50 .setPositiveButton(R.string.grant_dialog_button_deny_anyway, 51 (dialog, which) -> { 52 Activity activity = getActivity(); 53 if (activity instanceof OnActionConfirmedListener) { 54 String groupName = getArguments().getString(ARG_ACTION); 55 ((OnActionConfirmedListener) activity) 56 .onActionConfirmed(groupName); 57 } 58 }) 59 .create(); 60 } 61 } 62