• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.car.settings.security;
18 
19 import android.app.Dialog;
20 import android.content.DialogInterface;
21 import android.os.Bundle;
22 import android.support.v4.app.DialogFragment;
23 
24 import androidx.car.app.CarAlertDialog;
25 
26 import com.android.car.settings.R;
27 
28 /**
29  * Dialog to confirm screen lock removal.
30  */
31 public class ConfirmRemoveScreenLockDialog extends DialogFragment implements
32         DialogInterface.OnClickListener {
33 
34     private ConfirmRemoveLockListener mListener;
35 
36     /**
37      * Sets a listener for OnRemoveLockConfirmed that will get called if user confirms the dialog.
38      *
39      * @param listener Instance of {@link ConfirmRemoveLockListener} to call when confirmed.
40      */
setConfirmRemoveLockListener(ConfirmRemoveLockListener listener)41     public void setConfirmRemoveLockListener(ConfirmRemoveLockListener listener) {
42         mListener = listener;
43     }
44 
45     @Override
onCreateDialog(Bundle savedInstanceState)46     public Dialog onCreateDialog(Bundle savedInstanceState) {
47         return new CarAlertDialog.Builder(getContext())
48                 .setTitle(R.string.remove_screen_lock_title)
49                 .setBody(R.string.remove_screen_lock_message)
50                 .setPositiveButton(R.string.remove_button, this)
51                 .setNegativeButton(android.R.string.cancel, null)
52                 .create();
53     }
54 
55     @Override
onClick(DialogInterface dialog, int which)56     public void onClick(DialogInterface dialog, int which) {
57         if (mListener != null) {
58             mListener.onRemoveLockConfirmed();
59         }
60     }
61 
62     /**
63      * Interface for listeners that want to receive a callback when user confirms lock removal in
64      * the dialog.
65      */
66     public interface ConfirmRemoveLockListener {
67         /**
68          * Callback when user confirms locks removal.
69          */
onRemoveLockConfirmed()70         void onRemoveLockConfirmed();
71     }
72 }
73