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.permissioncontroller.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 
36     @Override
onCreateDialog(Bundle bundle)37     public Dialog onCreateDialog(Bundle bundle) {
38         return new AlertDialog.Builder(getContext())
39                 .setMessage(getArguments().getString(ARG_MESSAGE))
40                 .setNegativeButton(R.string.cancel, null)
41                 .setPositiveButton(R.string.grant_dialog_button_deny_anyway,
42                         (dialog, which) -> {
43                             Activity activity = getActivity();
44                             if (activity instanceof OnActionConfirmedListener) {
45                                 String groupName = getArguments().getString(ARG_ACTION);
46                                 ((OnActionConfirmedListener) activity)
47                                         .onActionConfirmed(groupName);
48                             }
49                         })
50         .create();
51     }
52 }
53