Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
✨ [android] add handleOnPause and handleOnResume methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tafelnl committed Oct 28, 2020
1 parent b7dcc9b commit c786a69
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class BarcodeScanner extends Plugin implements BarcodeCallback {
private boolean didRunCameraSetup = false;
private boolean didRunCameraPrepare = false;
private boolean isBackgroundHidden = false;
private String actionOnResume = null;

private boolean hasCamera() {
// @TODO(): check: https://stackoverflow.com/a/57974578/8634342
Expand Down Expand Up @@ -82,7 +83,7 @@ private void setupCamera() {
didRunCameraSetup = true;
}

private void dismantleCamera() {
private void dismantleCamera(Boolean freeSavedCallFlag) {
// opposite of setupCamera

getActivity()
Expand All @@ -101,15 +102,15 @@ private void dismantleCamera() {
didRunCameraPrepare = false;

// If a call is saved and a scan will not run, free the saved call
if (getSavedCall() != null && !shouldRunScan) {
if (freeSavedCallFlag && getSavedCall() != null && !shouldRunScan) {
freeSavedCall();
}
}

private void prepare() {
// undo previous setup
// because it may be prepared with a different config
dismantleCamera();
dismantleCamera(true);

// setup camera with new config
setupCamera();
Expand All @@ -125,7 +126,7 @@ private void prepare() {
private void destroy() {
showBackground();

dismantleCamera();
dismantleCamera(true);
}

private void scan() {
Expand Down Expand Up @@ -200,6 +201,25 @@ public void barcodeResult(BarcodeResult barcodeResult) {
destroy();
}

@Override
public void handleOnPause() {
if (isScanning) {
actionOnResume = "scan";
} else {
actionOnResume = null;
}
dismantleCamera(false);
}

@Override
public void handleOnResume() {
if (actionOnResume != null) {
if (actionOnResume.equals("scan")) {
scan();
}
}
}

@Override
public void possibleResultPoints(List<ResultPoint> resultPoints) {}

Expand Down

0 comments on commit c786a69

Please sign in to comment.