Skip to content

Commit f790a0c

Browse files
Fixing the error callback when user clicks on the cancel button of the dialog.
1 parent 45977cb commit f790a0c

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

fingerprint-dialog-compat/src/main/java/com/kevalpatel2106/fingerprintdialog/FingerprintDialogCompatV23.java

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
/*
2-
* Copyright 2018 Keval Patel
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance wit
5-
* the License. You may obtain a copy of the License at
6-
*
7-
* http://www.apache.org/licenses/LICENSE-2.0
8-
*
9-
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
10-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for
11-
* the specific language governing permissions and limitations under the License.
2+
* Copyright (c) 2018. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
3+
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
4+
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
5+
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
6+
* Vestibulum commodo. Ut rhoncus gravida arcu.
127
*/
138

149
package com.kevalpatel2106.fingerprintdialog;
1510

1611
import android.annotation.TargetApi;
1712
import android.content.Context;
18-
import android.content.DialogInterface;
1913
import android.content.pm.PackageManager;
2014
import android.graphics.Color;
2115
import android.graphics.drawable.ColorDrawable;
@@ -196,13 +190,13 @@ public void onResume() {
196190
startAuth();
197191
} else {
198192
mCallback.fingerprintAuthenticationNotSupported();
199-
dismiss();
193+
closeDialog();
200194
}
201195
}
202196

203197
@Override
204-
public void onDetach() {
205-
super.onDetach();
198+
public void onPause() {
199+
super.onPause();
206200
stopAuthIfRunning();
207201
}
208202

@@ -213,8 +207,8 @@ public void onDestroyView() {
213207
}
214208

215209
@Override
216-
public void onDismiss(DialogInterface dialog) {
217-
super.onDismiss(dialog);
210+
public void onDetach() {
211+
super.onDetach();
218212
stopAuthIfRunning();
219213
}
220214

@@ -257,10 +251,8 @@ public void onViewCreated(@NonNull final View view, @Nullable final Bundle saved
257251
negativeButton.setOnClickListener(new View.OnClickListener() {
258252
@Override
259253
public void onClick(final View view) {
260-
261-
//Authentication canceled by the user.
262-
mCallback.authenticationCanceledByUser();
263-
dismiss();
254+
//Close the dialog
255+
closeDialog();
264256
}
265257
});
266258
} else {
@@ -388,6 +380,7 @@ public void onAuthenticationError(int errMsgId, CharSequence errString) {
388380
displayStatusText(errString.toString(), true);
389381

390382
switch (errMsgId) {
383+
case FingerprintManager.FINGERPRINT_ERROR_CANCELED:
391384
case FingerprintManager.FINGERPRINT_ERROR_USER_CANCELED:
392385
mCallback.authenticationCanceledByUser();
393386
break;
@@ -415,7 +408,7 @@ public void onAuthenticationFailed() {
415408
@Override
416409
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
417410
mCallback.onAuthenticationSucceeded();
418-
dismiss();
411+
closeDialog();
419412
}
420413
};
421414

@@ -429,7 +422,7 @@ public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult re
429422
} else {
430423
//Cannot access the secure keystore.
431424
mCallback.fingerprintAuthenticationNotSupported();
432-
dismiss();
425+
closeDialog();
433426
}
434427
}
435428

@@ -450,6 +443,11 @@ private void stopAuthIfRunning() {
450443
}
451444
}
452445

446+
private void closeDialog() {
447+
stopAuthIfRunning();
448+
dismiss();
449+
}
450+
453451
/**
454452
* Display the text in the {@link #mStatusText} for 1 second.
455453
*
@@ -466,7 +464,7 @@ public void run() {
466464

467465
if (getDialog() != null && getDialog().isShowing()) {
468466
mStatusText.setText("");
469-
if (isDismiss) dismiss();
467+
if (isDismiss) closeDialog();
470468
}
471469
}
472470
};

0 commit comments

Comments
 (0)