Navaron Bracke

forward initial torch state on Android

@@ -368,11 +368,22 @@ class MobileScanner( @@ -368,11 +368,22 @@ class MobileScanner(
368 val height = resolution.height.toDouble() 368 val height = resolution.height.toDouble()
369 val portrait = (camera?.cameraInfo?.sensorRotationDegrees ?: 0) % 180 == 0 369 val portrait = (camera?.cameraInfo?.sensorRotationDegrees ?: 0) % 180 == 0
370 370
  371 + // Start with 'unavailable' torch state.
  372 + var currentTorchState: Int = -1
  373 +
  374 + camera?.cameraInfo?.let {
  375 + if (!it.hasFlashUnit()) {
  376 + return@let
  377 + }
  378 +
  379 + currentTorchState = it.torchState.value ?: -1
  380 + }
  381 +
371 mobileScannerStartedCallback( 382 mobileScannerStartedCallback(
372 MobileScannerStartParameters( 383 MobileScannerStartParameters(
373 if (portrait) width else height, 384 if (portrait) width else height,
374 if (portrait) height else width, 385 if (portrait) height else width,
375 - camera?.cameraInfo?.hasFlashUnit() ?: false, 386 + currentTorchState,
376 textureEntry!!.id(), 387 textureEntry!!.id(),
377 numberOfCameras ?: 0 388 numberOfCameras ?: 0
378 ) 389 )
@@ -183,7 +183,7 @@ class MobileScannerHandler( @@ -183,7 +183,7 @@ class MobileScannerHandler(
183 result.success(mapOf( 183 result.success(mapOf(
184 "textureId" to it.id, 184 "textureId" to it.id,
185 "size" to mapOf("width" to it.width, "height" to it.height), 185 "size" to mapOf("width" to it.width, "height" to it.height),
186 - "torchable" to it.hasFlashUnit, 186 + "currentTorchState" to it.currentTorchState,
187 "numberOfCameras" to it.numberOfCameras 187 "numberOfCameras" to it.numberOfCameras
188 )) 188 ))
189 } 189 }
@@ -3,7 +3,7 @@ package dev.steenbakker.mobile_scanner.objects @@ -3,7 +3,7 @@ package dev.steenbakker.mobile_scanner.objects
3 class MobileScannerStartParameters( 3 class MobileScannerStartParameters(
4 val width: Double = 0.0, 4 val width: Double = 0.0,
5 val height: Double, 5 val height: Double,
6 - val hasFlashUnit: Boolean, 6 + val currentTorchState: Int,
7 val id: Long, 7 val id: Long,
8 val numberOfCameras: Int 8 val numberOfCameras: Int
9 ) 9 )