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

Commit

Permalink
fix(android): fixed an issue if stopped is called from the start call…
Browse files Browse the repository at this point in the history
…back
  • Loading branch information
thegnuu committed May 10, 2023
1 parent 195289c commit e20ebd7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<!-- <uses-feature android:name="android.hardware.camera" android:required="false" /> -->
<!-- <uses-permission android:name="android.permission.VIBRATE" /> -->

<uses-permission android:name="android.permission.VIBRATE" />

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public class CapacitorCommunityBarcodeScanner extends Plugin implements ImageAna
private boolean scanningPaused = false;

private static final String MLKIT_TAG = "MLKIT";

private ArrayList<String> scannedResult = new ArrayList<String>();
private Camera mCamera = null;
Vibrator mVibrator;

Expand Down Expand Up @@ -144,7 +142,10 @@ private void setupCamera(String cameraDirection) {
() -> {
try {
mCameraProvider = cameraProviderFuture.get();
bindPreview(mCameraProvider, cameraDirection.equals("front") ? CameraSelector.LENS_FACING_FRONT : CameraSelector.LENS_FACING_BACK);
bindPreview(
mCameraProvider,
cameraDirection.equals("front") ? CameraSelector.LENS_FACING_FRONT : CameraSelector.LENS_FACING_BACK
);
} catch (InterruptedException | ExecutionException e) {
// No errors need to be handled for this Future.
// This should never be reached.
Expand Down Expand Up @@ -211,7 +212,6 @@ private void _prepare(PluginCall call) {
}

private void destroy() {
scannedResult.clear();
showBackground();
dismantleCamera();
this.setTorch(false);
Expand Down Expand Up @@ -322,25 +322,21 @@ public void onSuccess(List<Barcode> barcodes) {
// Log.e(MLKIT_TAG,"corners : " + corners.toString());
Log.e(MLKIT_TAG, "bounds : " + bounds.flattenToString());

if (!scannedResult.contains(rawValue)) {
Log.e(MLKIT_TAG, "Added Into ArrayList : " + rawValue);

scannedResult.add(rawValue);
Log.e(MLKIT_TAG, "Added Into ArrayList : " + rawValue);

JSObject jsObject = new JSObject();
int[] boundArr = { bounds.top, bounds.bottom, bounds.right, bounds.left };
Log.e(MLKIT_TAG, "onSuccess: boundArr");
jsObject.put("hasContent", true);
jsObject.put("content", rawValue);
jsObject.put("format", null);
// jsObject.put("corners",corners);
jsObject.put("bounds", s);
JSObject jsObject = new JSObject();
int[] boundArr = { bounds.top, bounds.bottom, bounds.right, bounds.left };
Log.e(MLKIT_TAG, "onSuccess: boundArr");
jsObject.put("hasContent", true);
jsObject.put("content", rawValue);
jsObject.put("format", null);
// jsObject.put("corners",corners);
jsObject.put("bounds", s);

if (call != null && !call.isKeptAlive()) {
destroy();
}
call.resolve(jsObject);
if (call != null && !call.isKeptAlive()) {
destroy();
}
call.resolve(jsObject);
}
}
}
Expand Down Expand Up @@ -416,6 +412,10 @@ public void showBackground(PluginCall call) {

@PluginMethod
public void stop(PluginCall call) {
if (mScanner != null) {
mScanner.close();
mScanner = null;
}
if (call.hasOption("resolveScan") && getSavedCall() != null) {
Boolean resolveScan = call.getBoolean("resolveScan", false);
if (resolveScan != null && resolveScan) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e20ebd7

Please sign in to comment.