Skip to content

Commit

Permalink
style: format
Browse files Browse the repository at this point in the history
  • Loading branch information
robingenz committed Feb 27, 2025
1 parent af833f0 commit 6faf333
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 261 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ public void startScan(ScanSettings scanSettings, StartScanResultCallback callbac
preview.setSurfaceProvider(previewView.getSurfaceProvider());

// Start the camera
camera =
processCameraProvider.bindToLifecycle((LifecycleOwner) plugin.getContext(), cameraSelector, preview, imageAnalysis);
camera = processCameraProvider.bindToLifecycle(
(LifecycleOwner) plugin.getContext(),
cameraSelector,
preview,
imageAnalysis
);

callback.success();
} catch (Exception exception) {
Expand Down Expand Up @@ -181,16 +185,12 @@ public void readBarcodesFromImage(String path, ScanSettings scanSettings, ReadBa
com.google.mlkit.vision.barcode.BarcodeScanner barcodeScannerInstance = BarcodeScanning.getClient(options);
barcodeScannerInstance
.process(inputImage)
.addOnSuccessListener(
barcodes -> {
callback.success(barcodes);
}
)
.addOnFailureListener(
exception -> {
callback.error(exception);
}
);
.addOnSuccessListener(barcodes -> {
callback.success(barcodes);
})
.addOnFailureListener(exception -> {
callback.error(exception);
});
}

public void scan(ScanSettings scanSettings, ScanResultCallback callback) {
Expand All @@ -199,39 +199,29 @@ public void scan(ScanSettings scanSettings, ScanResultCallback callback) {

scanner
.startScan()
.addOnSuccessListener(
barcode -> {
callback.success(barcode);
}
)
.addOnCanceledListener(
() -> {
callback.cancel();
}
)
.addOnFailureListener(
exception -> {
callback.error(exception);
}
);
.addOnSuccessListener(barcode -> {
callback.success(barcode);
})
.addOnCanceledListener(() -> {
callback.cancel();
})
.addOnFailureListener(exception -> {
callback.error(exception);
});
}

public void isGoogleBarcodeScannerModuleAvailable(IsGoogleBarodeScannerModuleAvailableResultCallback callback) {
GmsBarcodeScanner scanner = GmsBarcodeScanning.getClient(plugin.getContext());
ModuleInstallClient moduleInstallClient = ModuleInstall.getClient(plugin.getContext());
moduleInstallClient
.areModulesAvailable(scanner)
.addOnSuccessListener(
response -> {
boolean isAvailable = response.areModulesAvailable();
callback.success(isAvailable);
}
)
.addOnFailureListener(
exception -> {
callback.error(exception);
}
);
.addOnSuccessListener(response -> {
boolean isAvailable = response.areModulesAvailable();
callback.success(isAvailable);
})
.addOnFailureListener(exception -> {
callback.error(exception);
});
}

public void installGoogleBarcodeScannerModule(InstallGoogleBarcodeScannerModuleResultCallback callback) {
Expand All @@ -241,20 +231,16 @@ public void installGoogleBarcodeScannerModule(InstallGoogleBarcodeScannerModuleR
ModuleInstallClient moduleInstallClient = ModuleInstall.getClient(plugin.getContext());
moduleInstallClient
.installModules(moduleInstallRequest)
.addOnSuccessListener(
moduleInstallResponse -> {
if (moduleInstallResponse.areModulesAlreadyInstalled()) {
callback.error(new Exception(BarcodeScannerPlugin.ERROR_GOOGLE_BARCODE_SCANNER_MODULE_ALREADY_INSTALLED));
} else {
callback.success();
}
}
)
.addOnFailureListener(
exception -> {
callback.error(exception);
.addOnSuccessListener(moduleInstallResponse -> {
if (moduleInstallResponse.areModulesAlreadyInstalled()) {
callback.error(new Exception(BarcodeScannerPlugin.ERROR_GOOGLE_BARCODE_SCANNER_MODULE_ALREADY_INSTALLED));
} else {
callback.success();
}
);
})
.addOnFailureListener(exception -> {
callback.error(exception);
});
}

public boolean isSupported() {
Expand Down Expand Up @@ -339,32 +325,26 @@ public void analyze(@NonNull ImageProxy imageProxy) {
Point imageSize = new Point(inputImage.getWidth(), inputImage.getHeight());
barcodeScannerInstance
.process(inputImage)
.addOnSuccessListener(
barcodes -> {
if (scanSettings == null) {
// Scanning stopped while processing the image
return;
}
List<Barcode> barcodesWithEnoughVotes = voteForBarcodes(barcodes);
for (Barcode barcode : barcodesWithEnoughVotes) {
handleScannedBarcode(barcode, imageSize);
}
if (barcodesWithEnoughVotes.size() > 0) {
handleScannedBarcodes(barcodesWithEnoughVotes.toArray(new Barcode[0]), imageSize);
}
.addOnSuccessListener(barcodes -> {
if (scanSettings == null) {
// Scanning stopped while processing the image
return;
}
)
.addOnFailureListener(
exception -> {
handleScanError(exception);
List<Barcode> barcodesWithEnoughVotes = voteForBarcodes(barcodes);
for (Barcode barcode : barcodesWithEnoughVotes) {
handleScannedBarcode(barcode, imageSize);
}
)
.addOnCompleteListener(
task -> {
imageProxy.close();
image.close();
if (barcodesWithEnoughVotes.size() > 0) {
handleScannedBarcodes(barcodesWithEnoughVotes.toArray(new Barcode[0]), imageSize);
}
);
})
.addOnFailureListener(exception -> {
handleScanError(exception);
})
.addOnCompleteListener(task -> {
imageProxy.close();
image.close();
});
}

public void handleGoogleBarcodeScannerModuleInstallProgress(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,23 @@ public void startScan(PluginCall call) {
}

getActivity()
.runOnUiThread(
() -> {
implementation.startScan(
scanSettings,
new StartScanResultCallback() {
@Override
public void success() {
call.resolve();
}

@Override
public void error(Exception exception) {
Logger.error(TAG, exception.getMessage(), exception);
call.reject(exception.getMessage());
}
.runOnUiThread(() -> {
implementation.startScan(
scanSettings,
new StartScanResultCallback() {
@Override
public void success() {
call.resolve();
}
);
}
);

@Override
public void error(Exception exception) {
Logger.error(TAG, exception.getMessage(), exception);
call.reject(exception.getMessage());
}
}
);
});
} catch (Exception exception) {
Logger.error(TAG, exception.getMessage(), exception);
call.reject(exception.getMessage());
Expand All @@ -114,12 +112,10 @@ public void error(Exception exception) {
public void stopScan(PluginCall call) {
try {
getActivity()
.runOnUiThread(
() -> {
implementation.stopScan();
call.resolve();
}
);
.runOnUiThread(() -> {
implementation.stopScan();
call.resolve();
});
} catch (Exception exception) {
Logger.error(TAG, exception.getMessage(), exception);
call.reject(exception.getMessage());
Expand Down Expand Up @@ -186,8 +182,7 @@ public void success(boolean isAvailable) {
if (isAvailable) {
implementation.scan(
scanSettings,
(
new ScanResultCallback() {
(new ScanResultCallback() {
@Override
public void success(Barcode barcode) {
JSObject barcodeResult = BarcodeScannerHelper.createBarcodeResultForBarcode(
Expand All @@ -214,8 +209,7 @@ public void error(Exception exception) {
Logger.error(TAG, exception.getMessage(), exception);
call.reject(exception.getMessage());
}
}
)
})
);
} else {
call.reject(ERROR_GOOGLE_BARCODE_SCANNER_MODULE_NOT_AVAILABLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,22 @@ public void processImage(ProcessImageOptions options, ProcessImageResultCallback
final FaceDetector faceDetector = com.google.mlkit.vision.face.FaceDetection.getClient(faceDetectorOptions);
plugin
.getActivity()
.runOnUiThread(
() -> {
faceDetector
.process(inputImage)
.addOnSuccessListener(
faces -> {
faceDetector.close();
ProcessImageResult result = new ProcessImageResult(faces);
callback.success(result);
}
)
.addOnCanceledListener(
() -> {
faceDetector.close();
callback.cancel();
}
)
.addOnFailureListener(
exception -> {
faceDetector.close();
callback.error(exception);
}
);
}
);
.runOnUiThread(() -> {
faceDetector
.process(inputImage)
.addOnSuccessListener(faces -> {
faceDetector.close();
ProcessImageResult result = new ProcessImageResult(faces);
callback.success(result);
})
.addOnCanceledListener(() -> {
faceDetector.close();
callback.cancel();
})
.addOnFailureListener(exception -> {
faceDetector.close();
callback.error(exception);
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,22 @@ public void processImage(ProcessImageOptions options, ProcessImageResultCallback
final FaceMeshDetector faceMeshDetector = com.google.mlkit.vision.facemesh.FaceMeshDetection.getClient(faceMeshDetectorOptions);
plugin
.getActivity()
.runOnUiThread(
() -> {
faceMeshDetector
.process(inputImage)
.addOnSuccessListener(
faceMeshs -> {
faceMeshDetector.close();
ProcessImageResult result = new ProcessImageResult(faceMeshs);
callback.success(result);
}
)
.addOnCanceledListener(
() -> {
faceMeshDetector.close();
callback.cancel();
}
)
.addOnFailureListener(
exception -> {
faceMeshDetector.close();
callback.error(exception);
}
);
}
);
.runOnUiThread(() -> {
faceMeshDetector
.process(inputImage)
.addOnSuccessListener(faceMeshs -> {
faceMeshDetector.close();
ProcessImageResult result = new ProcessImageResult(faceMeshs);
callback.success(result);
})
.addOnCanceledListener(() -> {
faceMeshDetector.close();
callback.cancel();
})
.addOnFailureListener(exception -> {
faceMeshDetector.close();
callback.error(exception);
});
});
}
}
Loading

0 comments on commit 6faf333

Please sign in to comment.