Merge "Fix enrolled face id can't be deleted when changing device rotation then pressing back key" into main
This commit is contained in:
@@ -29,7 +29,9 @@ import android.util.Log;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
import android.window.OnBackInvokedCallback;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
@@ -57,9 +59,14 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
|||||||
private static final String TAG = "FaceSettings/Remove";
|
private static final String TAG = "FaceSettings/Remove";
|
||||||
static final String KEY = "security_settings_face_delete_faces_container";
|
static final String KEY = "security_settings_face_delete_faces_container";
|
||||||
|
|
||||||
public static class ConfirmRemoveDialog extends InstrumentedDialogFragment {
|
public static class ConfirmRemoveDialog extends InstrumentedDialogFragment
|
||||||
|
implements OnBackInvokedCallback {
|
||||||
private static final String KEY_IS_CONVENIENCE = "is_convenience";
|
private static final String KEY_IS_CONVENIENCE = "is_convenience";
|
||||||
private DialogInterface.OnClickListener mOnClickListener;
|
private DialogInterface.OnClickListener mOnClickListener;
|
||||||
|
@Nullable
|
||||||
|
private AlertDialog mDialog = null;
|
||||||
|
@Nullable
|
||||||
|
private Preference mFaceUnlockPreference = null;
|
||||||
|
|
||||||
/** Returns the new instance of the class */
|
/** Returns the new instance of the class */
|
||||||
public static ConfirmRemoveDialog newInstance(boolean isConvenience) {
|
public static ConfirmRemoveDialog newInstance(boolean isConvenience) {
|
||||||
@@ -99,14 +106,41 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
|||||||
.setMessage(dialogMessageRes)
|
.setMessage(dialogMessageRes)
|
||||||
.setPositiveButton(R.string.delete, mOnClickListener)
|
.setPositiveButton(R.string.delete, mOnClickListener)
|
||||||
.setNegativeButton(R.string.cancel, mOnClickListener);
|
.setNegativeButton(R.string.cancel, mOnClickListener);
|
||||||
AlertDialog dialog = builder.create();
|
mDialog = builder.create();
|
||||||
dialog.setCanceledOnTouchOutside(false);
|
mDialog.setCanceledOnTouchOutside(false);
|
||||||
return dialog;
|
mDialog.getOnBackInvokedDispatcher().registerOnBackInvokedCallback(0, this);
|
||||||
|
return mDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnClickListener(DialogInterface.OnClickListener listener) {
|
public void setOnClickListener(DialogInterface.OnClickListener listener) {
|
||||||
mOnClickListener = listener;
|
mOnClickListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPreference(@Nullable Preference preference) {
|
||||||
|
mFaceUnlockPreference = preference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregisterOnBackInvokedCallback() {
|
||||||
|
if (mDialog != null) {
|
||||||
|
mDialog.getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackInvoked() {
|
||||||
|
if (mDialog != null) {
|
||||||
|
mDialog.cancel();
|
||||||
|
}
|
||||||
|
unregisterOnBackInvokedCallback();
|
||||||
|
|
||||||
|
if (mFaceUnlockPreference != null) {
|
||||||
|
final Button removeButton = ((LayoutPreference) mFaceUnlockPreference)
|
||||||
|
.findViewById(R.id.security_settings_face_settings_remove_button);
|
||||||
|
if (removeButton != null) {
|
||||||
|
removeButton.setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Listener {
|
interface Listener {
|
||||||
@@ -171,6 +205,13 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
|||||||
mButton.setEnabled(true);
|
mButton.setEnabled(true);
|
||||||
mRemoving = false;
|
mRemoving = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final ConfirmRemoveDialog removeDialog =
|
||||||
|
(ConfirmRemoveDialog) mActivity.getSupportFragmentManager()
|
||||||
|
.findFragmentByTag(ConfirmRemoveDialog.class.getName());
|
||||||
|
if (removeDialog != null) {
|
||||||
|
removeDialog.unregisterOnBackInvokedCallback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -210,6 +251,7 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
|||||||
(ConfirmRemoveDialog) mActivity.getSupportFragmentManager()
|
(ConfirmRemoveDialog) mActivity.getSupportFragmentManager()
|
||||||
.findFragmentByTag(ConfirmRemoveDialog.class.getName());
|
.findFragmentByTag(ConfirmRemoveDialog.class.getName());
|
||||||
if (removeDialog != null) {
|
if (removeDialog != null) {
|
||||||
|
removeDialog.setPreference(mPreference);
|
||||||
mRemoving = true;
|
mRemoving = true;
|
||||||
removeDialog.setOnClickListener(mOnConfirmDialogClickListener);
|
removeDialog.setOnClickListener(mOnConfirmDialogClickListener);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user