Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rawatnaresh committed Jan 25, 2025
1 parent e8fd5a7 commit cf8c148
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
14 changes: 6 additions & 8 deletions android/src/main/java/com/rncamerakit/CKCamera.kt
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class CKCamera(context: ThemedReactContext) : FrameLayout(context), LifecycleObs
}

val barcodeFrame = barcodeFrame;
if(barcodeFrame == null){
if(barcodeFrame == null) {
onBarcodeRead(barcodes)
return@QRCodeAnalyzer
}
Expand All @@ -326,17 +326,15 @@ class CKCamera(context: ThemedReactContext) : FrameLayout(context), LifecycleObs
val filteredBarcodes = barcodes.filter { barcode ->
val barcodeBoundingBox = barcode.boundingBox ?: return@filter false;
val scaledBarcodeBoundingBox = Rect(
(barcodeBoundingBox.left * scaleX).toInt(),
(barcodeBoundingBox.top * scaleY).toInt(),
(barcodeBoundingBox.right * scaleX).toInt(),
(barcodeBoundingBox.bottom * scaleY).toInt()
(barcodeBoundingBox.left * scaleX).toInt(),
(barcodeBoundingBox.top * scaleY).toInt(),
(barcodeBoundingBox.right * scaleX).toInt(),
(barcodeBoundingBox.bottom * scaleY).toInt()
)

// Check if the scaled bounding box is within the frame rectangle
barcodeFrame.frameRect.contains(scaledBarcodeBoundingBox)
}

if(filteredBarcodes.isNotEmpty()){
if(filteredBarcodes.isNotEmpty()) {
onBarcodeRead(filteredBarcodes)
}
}
Expand Down
22 changes: 11 additions & 11 deletions android/src/main/java/com/rncamerakit/QRCodeAnalyzer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import com.google.mlkit.vision.barcode.BarcodeScanning
import com.google.mlkit.vision.barcode.common.Barcode
import com.google.mlkit.vision.common.InputImage

class QRCodeAnalyzer(
private val onQRCodesDetected: (qrCodes: List<Barcode>, imageSize: Size) -> Unit
class QRCodeAnalyzer (
private val onQRCodesDetected: (qrCodes: List<Barcode>, imageSize: Size) -> Unit
) : ImageAnalysis.Analyzer {
@SuppressLint("UnsafeExperimentalUsageError")
@ExperimentalGetImage
Expand All @@ -21,15 +21,15 @@ class QRCodeAnalyzer(

val scanner = BarcodeScanning.getClient()
scanner.process(inputImage)
.addOnSuccessListener { barcodes ->
val strBarcodes = mutableListOf<Barcode>()
barcodes.forEach { barcode ->
strBarcodes.add(barcode ?: return@forEach)
}
onQRCodesDetected(strBarcodes, Size(image.width, image.height))
}
.addOnCompleteListener {
image.close()
.addOnSuccessListener { barcodes ->
val strBarcodes = mutableListOf<Barcode>()
barcodes.forEach { barcode ->
strBarcodes.add(barcode ?: return@forEach)
}
onQRCodesDetected(strBarcodes, Size(image.width, image.height))
}
.addOnCompleteListener {
image.close()
}
}
}

0 comments on commit cf8c148

Please sign in to comment.