Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
mobile_scanner
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Navaron Bracke
2024-08-08 12:17:45 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
64f57c27802accc1cd66b82b25962501c3a51233
64f57c27
1 parent
e59c0261
use injectable factory function with default instead
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
2 deletions
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
View file @
64f57c2
...
...
@@ -43,6 +43,7 @@ class MobileScanner(
private val textureRegistry: TextureRegistry,
private val mobileScannerCallback: MobileScannerCallback,
private val mobileScannerErrorCallback: MobileScannerErrorCallback,
private val barcodeScannerFactory: (options: BarcodeScannerOptions?) -> BarcodeScanner = ::defaultBarcodeScannerFactory,
) {
/// Internal variables
...
...
@@ -61,6 +62,15 @@ class MobileScanner(
private var detectionTimeout: Long = 250
private var returnImage = false
companion object {
/**
* Create a barcode scanner from the given options.
*/
fun defaultBarcodeScannerFactory(options: BarcodeScannerOptions?) : BarcodeScanner {
return if (options == null) BarcodeScanning.getClient() else BarcodeScanning.getClient(options)
}
}
/**
* callback for the camera. Every frame is passed through this function.
*/
...
...
@@ -248,7 +258,7 @@ class MobileScanner(
}
lastScanned = null
scanner =
createBarcodeScanner
(barcodeScannerOptions)
scanner =
barcodeScannerFactory
(barcodeScannerOptions)
val cameraProviderFuture = ProcessCameraProvider.getInstance(activity)
val executor = ContextCompat.getMainExecutor(activity)
...
...
@@ -451,7 +461,7 @@ class MobileScanner(
val inputImage = InputImage.fromFilePath(activity, image)
// Use a short lived scanner instance, which is closed when the analysis is done.
val barcodeScanner: BarcodeScanner =
createBarcodeScanner
(scannerOptions)
val barcodeScanner: BarcodeScanner =
barcodeScannerFactory
(scannerOptions)
barcodeScanner.process(inputImage).addOnSuccessListener { barcodes ->
val barcodeMap = barcodes.map { barcode -> barcode.data }
...
...
Please
register
or
login
to post a comment