capacitor-camera-module 0.0.37 → 0.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -643,71 +643,69 @@ public class CameraModulePlugin extends Plugin {
|
|
|
643
643
|
@PluginMethod
|
|
644
644
|
public void startBarcodeScan(PluginCall call) {
|
|
645
645
|
|
|
646
|
-
|
|
647
|
-
call.reject("Preview not started");
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
if (getPermissionState("camera") != PermissionState.GRANTED) {
|
|
652
|
-
call.reject("Camera permission not granted");
|
|
653
|
-
return;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
if (cameraProvider == null) {
|
|
657
|
-
call.reject("Camera not initialized");
|
|
658
|
-
return;
|
|
659
|
-
}
|
|
646
|
+
getActivity().runOnUiThread(() -> {
|
|
660
647
|
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
648
|
+
if (previewView == null) {
|
|
649
|
+
call.reject("Preview not started");
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
665
652
|
|
|
666
|
-
|
|
653
|
+
if (getPermissionState("camera") != PermissionState.GRANTED) {
|
|
654
|
+
call.reject("Camera permission not granted");
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
667
657
|
|
|
668
|
-
|
|
658
|
+
if (cameraProvider == null) {
|
|
659
|
+
call.reject("Camera not initialized");
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
669
662
|
|
|
670
|
-
|
|
671
|
-
|
|
663
|
+
if (isScanning) {
|
|
664
|
+
call.reject("Already scanning");
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
672
667
|
|
|
673
|
-
|
|
674
|
-
new ImageAnalysis.Builder()
|
|
675
|
-
.setBackpressureStrategy(
|
|
676
|
-
ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST
|
|
677
|
-
)
|
|
678
|
-
.build();
|
|
668
|
+
barcodeScanner = BarcodeScanning.getClient();
|
|
679
669
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
);
|
|
670
|
+
call.setKeepAlive(true);
|
|
671
|
+
scanCall = call;
|
|
672
|
+
isScanning = true;
|
|
684
673
|
|
|
685
|
-
|
|
674
|
+
imageAnalysis =
|
|
675
|
+
new ImageAnalysis.Builder()
|
|
676
|
+
.setBackpressureStrategy(
|
|
677
|
+
ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST
|
|
678
|
+
)
|
|
679
|
+
.build();
|
|
686
680
|
|
|
687
|
-
|
|
688
|
-
|
|
681
|
+
imageAnalysis.setAnalyzer(
|
|
682
|
+
barcodeExecutor,
|
|
683
|
+
this::processBarcode
|
|
684
|
+
);
|
|
689
685
|
|
|
690
|
-
|
|
691
|
-
new ImageCapture.Builder()
|
|
692
|
-
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
|
|
693
|
-
.build();
|
|
686
|
+
cameraProvider.unbindAll();
|
|
694
687
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
}
|
|
688
|
+
Preview preview = new Preview.Builder().build();
|
|
689
|
+
preview.setSurfaceProvider(previewView.getSurfaceProvider());
|
|
698
690
|
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
imageCapture,
|
|
704
|
-
imageAnalysis
|
|
705
|
-
);
|
|
691
|
+
imageCapture =
|
|
692
|
+
new ImageCapture.Builder()
|
|
693
|
+
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
|
|
694
|
+
.build();
|
|
706
695
|
|
|
707
|
-
|
|
696
|
+
camera = cameraProvider.bindToLifecycle(
|
|
697
|
+
getActivity(),
|
|
698
|
+
cameraSelector,
|
|
699
|
+
preview,
|
|
700
|
+
imageCapture,
|
|
701
|
+
imageAnalysis
|
|
702
|
+
);
|
|
708
703
|
|
|
704
|
+
call.resolve();
|
|
705
|
+
});
|
|
709
706
|
}
|
|
710
707
|
|
|
708
|
+
|
|
711
709
|
private void processBarcode(ImageProxy imageProxy) {
|
|
712
710
|
|
|
713
711
|
if (!isScanning) {
|