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-04-30 12:16:27 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2e0160cb07f4fc26454d61de180baa6426acff00
2e0160cb
1 parent
f2152a31
reimplement toggle torch on Android
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
9 deletions
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
View file @
2e0160c
...
...
@@ -19,6 +19,7 @@ import androidx.camera.core.ExperimentalGetImage
import androidx.camera.core.ImageAnalysis
import androidx.camera.core.ImageProxy
import androidx.camera.core.Preview
import androidx.camera.core.TorchState
import androidx.camera.core.resolutionselector.AspectRatioStrategy
import androidx.camera.core.resolutionselector.ResolutionSelector
import androidx.camera.core.resolutionselector.ResolutionStrategy
...
...
@@ -422,13 +423,16 @@ class MobileScanner(
/**
* Toggles the flash light on or off.
*/
fun toggleTorch(enableTorch: Boolean) {
if (camera == null) {
return
fun toggleTorch() {
camera?.let {
if (!it.cameraInfo.hasFlashUnit()) {
return@let
}
if (camera?.cameraInfo?.hasFlashUnit() == true) {
camera?.cameraControl?.enableTorch(enableTorch)
when(it.cameraInfo.torchState.value) {
TorchState.OFF -> it.cameraControl.enableTorch(true)
TorchState.ON -> it.cameraControl.enableTorch(false)
}
}
}
...
...
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt
View file @
2e0160c
...
...
@@ -122,8 +122,8 @@ class MobileScannerHandler(
}
})
"start" -> start(call, result)
"torch" -> toggleTorch(call, result)
"stop" -> stop(result)
"toggleTorch" -> toggleTorch(result)
"analyzeImage" -> analyzeImage(call, result)
"setScale" -> setScale(call, result)
"resetScale" -> resetScale(result)
...
...
@@ -168,7 +168,7 @@ class MobileScannerHandler(
val position =
if (facing == 0) CameraSelector.DEFAULT_FRONT_CAMERA else CameraSelector.DEFAULT_BACK_CAMERA
val detectionSpeed: DetectionSpeed = DetectionSpeed.
values()
.first { it.intValue == speed}
val detectionSpeed: DetectionSpeed = DetectionSpeed.
entries
.first { it.intValue == speed}
mobileScanner!!.start(
barcodeScannerOptions,
...
...
@@ -244,8 +244,8 @@ class MobileScannerHandler(
mobileScanner!!.analyzeImage(uri, analyzeImageSuccessCallback, analyzeImageErrorCallback)
}
private fun toggleTorch(call: MethodCall, result: MethodChannel.Result) {
mobileScanner!!.toggleTorch(call.arguments == 1)
private fun toggleTorch(result: MethodChannel.Result) {
mobileScanner?.toggleTorch()
result.success(null)
}
...
...
Please
register
or
login
to post a comment