Show confirmation dialog for removing enrollment
Fixes: 123605413 Test: builds Change-Id: I9e918977909bcf461a29eb36f157c3a261c6dcc4
This commit is contained in:
@@ -16,9 +16,14 @@
|
||||
|
||||
package com.android.settings.biometrics.face;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.hardware.face.Face;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@@ -28,7 +33,9 @@ import android.widget.Toast;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
import java.util.List;
|
||||
@@ -43,6 +50,33 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
||||
private static final String TAG = "FaceSettings/Remove";
|
||||
private static final String KEY = "security_settings_face_delete_faces_container";
|
||||
|
||||
public static class ConfirmRemoveDialog extends InstrumentedDialogFragment {
|
||||
|
||||
private DialogInterface.OnClickListener mOnClickListener;
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.DIALOG_FACE_REMOVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
|
||||
builder.setTitle(R.string.security_settings_face_settings_remove_dialog_title)
|
||||
.setMessage(R.string.security_settings_face_settings_remove_dialog_details)
|
||||
.setPositiveButton(R.string.okay, mOnClickListener)
|
||||
.setNegativeButton(R.string.cancel, mOnClickListener);
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public void setOnClickListener(DialogInterface.OnClickListener listener) {
|
||||
mOnClickListener = listener;
|
||||
}
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
void onRemoved();
|
||||
}
|
||||
@@ -50,6 +84,7 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
||||
private Button mButton;
|
||||
private List<Face> mFaces;
|
||||
private Listener mListener;
|
||||
private SettingsActivity mActivity;
|
||||
|
||||
private final Context mContext;
|
||||
private final int mUserId;
|
||||
@@ -77,6 +112,27 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
||||
}
|
||||
};
|
||||
|
||||
private final DialogInterface.OnClickListener mOnClickListener
|
||||
= new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
if (mFaces.isEmpty()) {
|
||||
Log.e(TAG, "No faces");
|
||||
return;
|
||||
}
|
||||
if (mFaces.size() > 1) {
|
||||
Log.e(TAG, "Multiple enrollments: " + mFaces.size());
|
||||
}
|
||||
|
||||
// Remove the first/only face
|
||||
mFaceManager.remove(mFaces.get(0), mUserId, mRemovalCallback);
|
||||
} else {
|
||||
mButton.setEnabled(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public FaceSettingsRemoveButtonPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mContext = context;
|
||||
@@ -115,20 +171,17 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
||||
public void onClick(View v) {
|
||||
if (v == mButton) {
|
||||
mButton.setEnabled(false);
|
||||
if (mFaces.isEmpty()) {
|
||||
Log.e(TAG, "No faces");
|
||||
return;
|
||||
}
|
||||
if (mFaces.size() > 1) {
|
||||
Log.e(TAG, "Multiple enrollments: " + mFaces.size());
|
||||
}
|
||||
|
||||
// Remove the first/only face
|
||||
mFaceManager.remove(mFaces.get(0), mUserId, mRemovalCallback);
|
||||
ConfirmRemoveDialog dialog = new ConfirmRemoveDialog();
|
||||
dialog.setOnClickListener(mOnClickListener);
|
||||
dialog.show(mActivity.getSupportFragmentManager(), ConfirmRemoveDialog.class.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void setListener(Listener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public void setActivity(SettingsActivity activity) {
|
||||
mActivity = activity;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user