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.content.DialogInterface.OnClickListener; 22 import android.os.Bundle; 23 import android.support.v4.app.DialogFragment; 24 25 import androidx.car.app.CarAlertDialog; 26 27 import com.android.car.settings.R; 28 29 /** 30 * Dialog to confirm user removal. 31 */ 32 public class ConfirmRemoveUserDialog extends DialogFragment { 33 private final DialogInterface.OnClickListener mDeleteUserListener = new OnClickListener() { 34 @Override 35 public void onClick(DialogInterface dialog, int which) { 36 if (mListener != null && which == DialogInterface.BUTTON_POSITIVE) { 37 mListener.onRemoveUserConfirmed(); 38 } 39 dialog.dismiss(); 40 } 41 }; 42 43 private ConfirmRemoveUserListener mListener; 44 45 /** 46 * Sets a listener for OnRemoveUserConfirmed that will get called if user confirms 47 * the dialog. 48 * 49 * @param listener Instance of {@link ConfirmRemoveUserListener} to call when confirmed. 50 */ 51 public void setConfirmRemoveUserListener(ConfirmRemoveUserListener listener) { 52 mListener = listener; 53 } 54 55 @Override 56 public Dialog onCreateDialog(Bundle savedInstanceState) { 57 return new CarAlertDialog.Builder(getContext()) 58 .setTitle(R.string.really_remove_user_title) 59 .setBody(R.string.really_remove_user_message) 60 .setPositiveButton(R.string.delete_button, mDeleteUserListener) 61 .setNegativeButton(android.R.string.cancel, null) 62 .create(); 63 } 64 65 /** 66 * Interface for listeners that want to receive a callback when user confirms user removal in a 67 * dialog. 68 */ 69 public interface ConfirmRemoveUserListener { 70 71 /** 72 * Method called only when user presses delete button. 73 */ 74 void onRemoveUserConfirmed(); 75 } 76 } 77