• 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.users;
18 
19 import android.app.AlertDialog;
20 import android.app.Dialog;
21 import android.content.DialogInterface;
22 import android.os.Bundle;
23 
24 import androidx.annotation.VisibleForTesting;
25 import androidx.fragment.app.DialogFragment;
26 import androidx.fragment.app.Fragment;
27 
28 import com.android.car.settings.R;
29 
30 /**
31  * A dialog that asks the user to confirm that they want to exit retail mode, which will result in
32  * a factory reset.
33  */
34 public class ConfirmExitRetailModeDialog extends DialogFragment implements
35         DialogInterface.OnClickListener {
36     @VisibleForTesting
37     static final String DIALOG_TAG = "ConfirmExitRetailModeDialog";
38     private ConfirmExitRetailModeListener mListener;
39 
40     /**
41      * Shows the dialog.
42      *
43      * @param parent Fragment associated with the dialog.
44      */
show(Fragment parent)45     public void show(Fragment parent) {
46         setTargetFragment(parent, 0);
47         show(parent.getFragmentManager(), DIALOG_TAG);
48     }
49 
50     /**
51      * Sets a listener for onExitRetailModeConfirmed that will get called if user confirms
52      * the dialog.
53      *
54      * @param listener Instance of {@link ConfirmExitRetailModeListener} to call when confirmed.
55      */
setConfirmExitRetailModeListener(ConfirmExitRetailModeListener listener)56     public void setConfirmExitRetailModeListener(ConfirmExitRetailModeListener listener) {
57         mListener = listener;
58     }
59 
60     @Override
onCreateDialog(Bundle savedInstanceState)61     public Dialog onCreateDialog(Bundle savedInstanceState) {
62         return new AlertDialog.Builder(getContext())
63                 .setTitle(R.string.exit_retail_mode_dialog_title)
64                 .setMessage(R.string.exit_retail_mode_dialog_body)
65                 .setPositiveButton(R.string.exit_retail_mode_dialog_confirmation_button_text, this)
66                 .setNegativeButton(android.R.string.cancel, null)
67                 .create();
68     }
69 
70     @Override
onClick(DialogInterface dialog, int which)71     public void onClick(DialogInterface dialog, int which) {
72         if (mListener != null) {
73             mListener.onExitRetailModeConfirmed();
74         }
75         dialog.dismiss();
76     }
77 
78     /**
79      * Interface for listeners that want to receive a callback when user confirms exit of retail
80      * mode in a dialog.
81      */
82     public interface ConfirmExitRetailModeListener {
83         /**
84          * Called when the user confirms that they want to exit retail mode.
85          */
onExitRetailModeConfirmed()86         void onExitRetailModeConfirmed();
87     }
88 }
89