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.AlertDialog; 20 import android.app.Dialog; 21 import android.os.Bundle; 22 23 import androidx.fragment.app.DialogFragment; 24 25 import com.android.car.settings.R; 26 27 /** 28 * Dialog to confirm screen lock removal. 29 */ 30 public class ConfirmRemoveScreenLockDialog extends DialogFragment { 31 32 /** Identifier for the dialog which confirms the removal of a screen lock. */ 33 public static final String TAG = "confirm_remove_lock_dialog"; 34 private ConfirmRemoveScreenLockListener mConfirmRemoveScreenLockListener; 35 36 /** Sets a listener to act when a user confirms delete. */ setConfirmRemoveScreenLockListener(ConfirmRemoveScreenLockListener listener)37 public void setConfirmRemoveScreenLockListener(ConfirmRemoveScreenLockListener listener) { 38 mConfirmRemoveScreenLockListener = listener; 39 } 40 41 @Override onCreateDialog(Bundle savedInstanceState)42 public Dialog onCreateDialog(Bundle savedInstanceState) { 43 return new AlertDialog.Builder(getContext()) 44 .setTitle(R.string.remove_screen_lock_title) 45 .setMessage(R.string.remove_screen_lock_message) 46 .setPositiveButton(R.string.remove_button, (dialog, which) -> { 47 if (mConfirmRemoveScreenLockListener != null) { 48 mConfirmRemoveScreenLockListener.onConfirmRemoveScreenLock(); 49 } 50 dialog.dismiss(); 51 }) 52 .setNegativeButton(android.R.string.cancel, null) 53 .create(); 54 } 55 56 /** A listener for when user confirms lock removal for the current user. */ 57 public interface ConfirmRemoveScreenLockListener { 58 /** Defines the actions to take when a user confirms the removal of a lock. */ 59 void onConfirmRemoveScreenLock(); 60 } 61 } 62