Showing
1 changed file
with
12 additions
and
2 deletions
| @@ -43,6 +43,7 @@ class MobileScanner( | @@ -43,6 +43,7 @@ class MobileScanner( | ||
| 43 | private val textureRegistry: TextureRegistry, | 43 | private val textureRegistry: TextureRegistry, |
| 44 | private val mobileScannerCallback: MobileScannerCallback, | 44 | private val mobileScannerCallback: MobileScannerCallback, |
| 45 | private val mobileScannerErrorCallback: MobileScannerErrorCallback, | 45 | private val mobileScannerErrorCallback: MobileScannerErrorCallback, |
| 46 | + private val barcodeScannerFactory: (options: BarcodeScannerOptions?) -> BarcodeScanner = ::defaultBarcodeScannerFactory, | ||
| 46 | ) { | 47 | ) { |
| 47 | 48 | ||
| 48 | /// Internal variables | 49 | /// Internal variables |
| @@ -61,6 +62,15 @@ class MobileScanner( | @@ -61,6 +62,15 @@ class MobileScanner( | ||
| 61 | private var detectionTimeout: Long = 250 | 62 | private var detectionTimeout: Long = 250 |
| 62 | private var returnImage = false | 63 | private var returnImage = false |
| 63 | 64 | ||
| 65 | + companion object { | ||
| 66 | + /** | ||
| 67 | + * Create a barcode scanner from the given options. | ||
| 68 | + */ | ||
| 69 | + fun defaultBarcodeScannerFactory(options: BarcodeScannerOptions?) : BarcodeScanner { | ||
| 70 | + return if (options == null) BarcodeScanning.getClient() else BarcodeScanning.getClient(options) | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + | ||
| 64 | /** | 74 | /** |
| 65 | * callback for the camera. Every frame is passed through this function. | 75 | * callback for the camera. Every frame is passed through this function. |
| 66 | */ | 76 | */ |
| @@ -248,7 +258,7 @@ class MobileScanner( | @@ -248,7 +258,7 @@ class MobileScanner( | ||
| 248 | } | 258 | } |
| 249 | 259 | ||
| 250 | lastScanned = null | 260 | lastScanned = null |
| 251 | - scanner = createBarcodeScanner(barcodeScannerOptions) | 261 | + scanner = barcodeScannerFactory(barcodeScannerOptions) |
| 252 | 262 | ||
| 253 | val cameraProviderFuture = ProcessCameraProvider.getInstance(activity) | 263 | val cameraProviderFuture = ProcessCameraProvider.getInstance(activity) |
| 254 | val executor = ContextCompat.getMainExecutor(activity) | 264 | val executor = ContextCompat.getMainExecutor(activity) |
| @@ -451,7 +461,7 @@ class MobileScanner( | @@ -451,7 +461,7 @@ class MobileScanner( | ||
| 451 | val inputImage = InputImage.fromFilePath(activity, image) | 461 | val inputImage = InputImage.fromFilePath(activity, image) |
| 452 | 462 | ||
| 453 | // Use a short lived scanner instance, which is closed when the analysis is done. | 463 | // Use a short lived scanner instance, which is closed when the analysis is done. |
| 454 | - val barcodeScanner: BarcodeScanner = createBarcodeScanner(scannerOptions) | 464 | + val barcodeScanner: BarcodeScanner = barcodeScannerFactory(scannerOptions) |
| 455 | 465 | ||
| 456 | barcodeScanner.process(inputImage).addOnSuccessListener { barcodes -> | 466 | barcodeScanner.process(inputImage).addOnSuccessListener { barcodes -> |
| 457 | val barcodeMap = barcodes.map { barcode -> barcode.data } | 467 | val barcodeMap = barcodes.map { barcode -> barcode.data } |
-
Please register or login to post a comment