Add tests for scanning QR codes

This commit is contained in:
Alexander Bakker 2022-08-04 21:31:53 +02:00
parent 3b715d58cf
commit 5f12eae678
5 changed files with 173 additions and 18 deletions

View file

@ -2,8 +2,6 @@ package com.beemdevelopment.aegis.helpers;
import static android.graphics.ImageFormat.YUV_420_888;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.util.Size;
@ -70,7 +68,7 @@ public class QrCodeAnalyzer implements ImageAnalysis.Analyzer {
Result result = reader.decode(bitmap, hints);
if (_listener != null) {
new Handler(Looper.getMainLooper()).post(() -> _listener.onQrCodeDetected(result));
_listener.onQrCodeDetected(result);
}
} catch (NotFoundException ignored) {

View file

@ -3,6 +3,7 @@ package com.beemdevelopment.aegis.ui;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
@ -170,23 +171,25 @@ public class ScannerActivity extends AegisActivity implements QrCodeAnalyzer.Lis
@Override
public void onQrCodeDetected(Result result) {
if (_analysis != null) {
try {
Uri uri = Uri.parse(result.getText().trim());
if (uri.getScheme() != null && uri.getScheme().equals(GoogleAuthInfo.SCHEME_EXPORT)) {
handleExportUri(uri);
} else {
handleUri(uri);
}
} catch (GoogleAuthInfoException e) {
e.printStackTrace();
new Handler(getMainLooper()).post(() -> {
if (_analysis != null) {
try {
Uri uri = Uri.parse(result.getText().trim());
if (uri.getScheme() != null && uri.getScheme().equals(GoogleAuthInfo.SCHEME_EXPORT)) {
handleExportUri(uri);
} else {
handleUri(uri);
}
} catch (GoogleAuthInfoException e) {
e.printStackTrace();
unbindPreview(_cameraProvider);
Dialogs.showErrorDialog(this,
e.isPhoneFactor() ? R.string.read_qr_error_phonefactor : R.string.read_qr_error,
e, ((dialog, which) -> bindPreview(_cameraProvider)));
unbindPreview(_cameraProvider);
Dialogs.showErrorDialog(this,
e.isPhoneFactor() ? R.string.read_qr_error_phonefactor : R.string.read_qr_error,
e, ((dialog, which) -> bindPreview(_cameraProvider)));
}
}
}
});
}
private void handleUri(Uri uri) throws GoogleAuthInfoException {