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
2023-10-29 14:45:14 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
29dd4825700ecdc8a2dd4760acc7446d555beae7
29dd4825
1 parent
78b52497
check flash unit before toggling it in start(); safe access camera instead of forced casts
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
19 deletions
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
View file @
29dd482
...
...
@@ -235,10 +235,12 @@ class MobileScanner(
cameraProviderFuture.addListener({
cameraProvider = cameraProviderFuture.get()
if (cameraProvider == null) {
throw CameraError()
}
cameraProvider!!.unbindAll()
cameraProvider?.unbindAll()
textureEntry = textureRegistry.createSurfaceTexture()
// Preview
...
...
@@ -297,31 +299,34 @@ class MobileScanner(
analysis
)
// Register the torch listener
camera!!.cameraInfo.torchState.observe(activity) { state ->
// TorchState.OFF = 0; TorchState.ON = 1
torchStateCallback(state)
}
// Register the zoom scale listener
camera!!.cameraInfo.zoomState.observe(activity) { state ->
zoomScaleStateCallback(state.linearZoom.toDouble())
}
camera?.let {
// Register the torch listener
it.cameraInfo.torchState.observe(activity as LifecycleOwner) { state ->
// TorchState.OFF = 0; TorchState.ON = 1
torchStateCallback(state)
}
// Register the zoom scale listener
it.cameraInfo.zoomState.observe(activity) { state ->
zoomScaleStateCallback(state.linearZoom.toDouble())
}
// Enable torch if provided
camera!!.cameraControl.enableTorch(torch)
// Enable torch if provided
if (it.cameraInfo.hasFlashUnit()) {
it.cameraControl.enableTorch(torch)
}
}
val resolution = analysis.resolutionInfo!!.resolution
val portrait = camera!!.cameraInfo.sensorRotationDegrees % 180 == 0
val width = resolution.width.toDouble()
val height = resolution.height.toDouble()
val portrait = (camera?.cameraInfo?.sensorRotationDegrees ?: 0) % 180 == 0
mobileScannerStartedCallback(
MobileScannerStartParameters(
if (portrait) width else height,
if (portrait) height else width,
camera
!!.cameraInfo.hasFlashUnit()
,
camera
?.cameraInfo?.hasFlashUnit() ?: false
,
textureEntry!!.id()
)
)
...
...
@@ -363,7 +368,10 @@ class MobileScanner(
if (camera == null) {
throw TorchWhenStopped()
}
camera!!.cameraControl.enableTorch(enableTorch)
if (camera?.cameraInfo?.hasFlashUnit() == true) {
camera?.cameraControl?.enableTorch(enableTorch)
}
}
/**
...
...
@@ -393,9 +401,9 @@ class MobileScanner(
* Set the zoom rate of the camera.
*/
fun setScale(scale: Double) {
if (camera == null) throw ZoomWhenStopped()
if (scale > 1.0 || scale < 0) throw ZoomNotInRange()
camera!!.cameraControl.setLinearZoom(scale.toFloat())
if (camera == null) throw ZoomWhenStopped()
camera?.cameraControl?.setLinearZoom(scale.toFloat())
}
/**
...
...
@@ -403,7 +411,7 @@ class MobileScanner(
*/
fun resetScale() {
if (camera == null) throw ZoomWhenStopped()
camera
!!.cameraControl
.setZoomRatio(1f)
camera
?.cameraControl?
.setZoomRatio(1f)
}
}
...
...
Please
register
or
login
to post a comment