• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.app.DialogFragment;
23 import android.content.DialogInterface;
24 import android.os.Bundle;
25 import com.android.packageinstaller.R;
26 
27 public final class ConfirmActionDialogFragment extends DialogFragment {
28     public static final String ARG_MESSAGE = "MESSAGE";
29     public static final String ARG_ACTION = "ACTION";
30 
31     public static interface OnActionConfirmedListener {
onActionConfirmed(String action)32         public void onActionConfirmed(String action);
33     }
34 
newInstance(CharSequence message, String action)35     public static ConfirmActionDialogFragment newInstance(CharSequence message, String action) {
36         Bundle arguments = new Bundle();
37         arguments.putCharSequence(ARG_MESSAGE, message);
38         arguments.putString(ARG_ACTION, action);
39         ConfirmActionDialogFragment fragment = new ConfirmActionDialogFragment();
40         fragment.setArguments(arguments);
41         return fragment;
42     }
43 
44     @Override
onCreateDialog(Bundle bundle)45     public Dialog onCreateDialog(Bundle bundle) {
46         return new AlertDialog.Builder(getContext())
47                 .setMessage(getArguments().getString(ARG_MESSAGE))
48                 .setNegativeButton(R.string.cancel, null)
49                 .setPositiveButton(R.string.grant_dialog_button_deny_anyway,
50                         new DialogInterface.OnClickListener() {
51                     @Override
52                     public void onClick(DialogInterface dialog, int which) {
53                         Activity activity = getActivity();
54                         if (activity instanceof OnActionConfirmedListener) {
55                             String groupName = getArguments().getString(ARG_ACTION);
56                             ((OnActionConfirmedListener) activity)
57                                     .onActionConfirmed(groupName);
58                         }
59                     }
60                 })
61         .create();
62     }
63 }
64