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