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
ryuta46
2023-04-12 05:09:19 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7acd36bcbc74edea3921cc75501656147a444a58
7acd36bc
1 parent
6035379c
imp: add zoomScaleState value notifier.
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
2 deletions
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerCallbacks.kt
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt
ios/Classes/MobileScanner.swift
ios/Classes/SwiftMobileScannerPlugin.swift
lib/src/mobile_scanner_controller.dart
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
View file @
7acd36b
...
...
@@ -138,6 +138,7 @@ class MobileScanner(
torch: Boolean,
detectionSpeed: DetectionSpeed,
torchStateCallback: TorchStateCallback,
zoomScaleStateCallback: ZoomScaleStateCallback,
mobileScannerStartedCallback: MobileScannerStartedCallback,
detectionTimeout: Long
) {
...
...
@@ -201,6 +202,11 @@ class MobileScanner(
torchStateCallback(state)
}
// Register the zoom scale listener
camera!!.cameraInfo.zoomState.observe(activity) { state ->
zoomScaleStateCallback(state.linearZoom.toDouble())
}
// Enable torch if provided
camera!!.cameraControl.enableTorch(torch)
...
...
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerCallbacks.kt
View file @
7acd36b
...
...
@@ -6,4 +6,5 @@ typealias MobileScannerCallback = (barcodes: List<Map<String, Any?>>, image: Byt
typealias AnalyzerCallback = (barcodes: List<Map<String, Any?>>?) -> Unit
typealias MobileScannerErrorCallback = (error: String) -> Unit
typealias TorchStateCallback = (state: Int) -> Unit
typealias ZoomScaleStateCallback = (zoomScale: Double) -> Unit
typealias MobileScannerStartedCallback = (parameters: MobileScannerStartParameters) -> Unit
\ No newline at end of file
...
...
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt
View file @
7acd36b
...
...
@@ -70,6 +70,11 @@ class MobileScannerHandler(
barcodeHandler.publishEvent(mapOf("name" to "torchState", "data" to state))
}
private val zoomScaleStateCallback: ZoomScaleStateCallback = {zoomScale: Double ->
barcodeHandler.publishEvent(mapOf("name" to "zoomScaleState", "data" to zoomScale))
}
init {
methodChannel = MethodChannel(binaryMessenger,
"dev.steenbakker.mobile_scanner/scanner/method")
...
...
@@ -152,7 +157,7 @@ class MobileScannerHandler(
val detectionSpeed: DetectionSpeed = DetectionSpeed.values().first { it.intValue == speed}
try {
mobileScanner!!.start(barcodeScannerOptions, returnImage, position, torch, detectionSpeed, torchStateCallback, mobileScannerStartedCallback = {
mobileScanner!!.start(barcodeScannerOptions, returnImage, position, torch, detectionSpeed, torchStateCallback,
zoomScaleStateCallback,
mobileScannerStartedCallback = {
result.success(mapOf(
"textureId" to it.id,
"size" to mapOf("width" to it.width, "height" to it.height),
...
...
ios/Classes/MobileScanner.swift
View file @
7acd36b
...
...
@@ -13,6 +13,7 @@ import MLKitBarcodeScanning
typealias
MobileScannerCallback
=
((
Array
<
Barcode
>
?,
Error
?,
UIImage
)
->
())
typealias
TorchModeChangeCallback
=
((
Int
?)
->
())
typealias
ZoomScaleChangeCallback
=
((
Double
?)
->
())
public
class
MobileScanner
:
NSObject
,
AVCaptureVideoDataOutputSampleBufferDelegate
,
FlutterTexture
{
/// Capture session of the camera
...
...
@@ -36,6 +37,10 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
/// When torch mode is changes, this callback will be called
let
torchModeChangeCallback
:
TorchModeChangeCallback
/// When zoom scale is changes, this callback will be called
let
zoomScaleChangeCallback
:
ZoomScaleChangeCallback
/// If provided, the Flutter registry will be used to send the output of the CaptureOutput to a Flutter texture.
private
let
registry
:
FlutterTextureRegistry
?
...
...
@@ -47,10 +52,11 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
var
detectionSpeed
:
DetectionSpeed
=
DetectionSpeed
.
noDuplicates
init
(
registry
:
FlutterTextureRegistry
?,
mobileScannerCallback
:
@escaping
MobileScannerCallback
,
torchModeChangeCallback
:
@escaping
TorchModeChangeCallback
)
{
init
(
registry
:
FlutterTextureRegistry
?,
mobileScannerCallback
:
@escaping
MobileScannerCallback
,
torchModeChangeCallback
:
@escaping
TorchModeChangeCallback
,
zoomScaleChangeCallback
:
@escaping
ZoomScaleChangeCallback
)
{
self
.
registry
=
registry
self
.
mobileScannerCallback
=
mobileScannerCallback
self
.
torchModeChangeCallback
=
torchModeChangeCallback
self
.
zoomScaleChangeCallback
=
zoomScaleChangeCallback
super
.
init
()
}
...
...
@@ -133,6 +139,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
}
device
.
addObserver
(
self
,
forKeyPath
:
#
keyPath
(
AVCaptureDevice
.
torchMode
),
options
:
.
new
,
context
:
nil
)
device
.
addObserver
(
self
,
forKeyPath
:
#
keyPath
(
AVCaptureDevice
.
videoZoomFactor
),
options
:
.
new
,
context
:
nil
)
do
{
try
device
.
lockForConfiguration
()
if
device
.
isFocusModeSupported
(
.
continuousAutoFocus
)
{
...
...
@@ -199,6 +206,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
captureSession
.
removeOutput
(
output
)
}
device
.
removeObserver
(
self
,
forKeyPath
:
#
keyPath
(
AVCaptureDevice
.
torchMode
))
device
.
removeObserver
(
self
,
forKeyPath
:
#
keyPath
(
AVCaptureDevice
.
videoZoomFactor
))
registry
?
.
unregisterTexture
(
textureId
)
textureId
=
nil
captureSession
=
nil
...
...
@@ -228,6 +236,10 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
// off = 0; on = 1; auto = 2;
let
state
=
change
?[
.
newKey
]
as?
Int
torchModeChangeCallback
(
state
)
case
"videoZoomFactor"
:
let
zoomFactor
=
change
?[
.
newKey
]
as?
CGFloat
??
1
let
zoomScale
=
(
zoomFactor
-
1
)
/
4
zoomScaleChangeCallback
(
Double
(
zoomScale
))
default
:
break
}
...
...
ios/Classes/SwiftMobileScannerPlugin.swift
View file @
7acd36b
...
...
@@ -57,6 +57,8 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
}
},
torchModeChangeCallback
:
{
torchState
in
barcodeHandler
.
publishEvent
([
"name"
:
"torchState"
,
"data"
:
torchState
])
},
zoomScaleChangeCallback
:
{
zoomScale
in
barcodeHandler
.
publishEvent
([
"name"
:
"zoomScaleState"
,
"data"
:
zoomScale
])
})
self
.
barcodeHandler
=
barcodeHandler
super
.
init
()
...
...
lib/src/mobile_scanner_controller.dart
View file @
7acd36b
...
...
@@ -85,6 +85,10 @@ class MobileScannerController {
late
final
ValueNotifier
<
CameraFacing
>
cameraFacingState
=
ValueNotifier
(
facing
);
/// A notifier that provides zoomScale.
final
ValueNotifier
<
double
>
zoomScaleState
=
ValueNotifier
(
0.0
);
bool
isStarting
=
false
;
/// A notifier that provides availability of the Torch (Flash)
...
...
@@ -337,6 +341,9 @@ class MobileScannerController {
final
state
=
TorchState
.
values
[
data
as
int
?
??
0
];
torchState
.
value
=
state
;
break
;
case
'zoomScaleState'
:
zoomScaleState
.
value
=
data
as
double
?
??
0.0
;
break
;
case
'barcode'
:
if
(
data
==
null
)
return
;
final
parsed
=
(
data
as
List
)
...
...
Please
register
or
login
to post a comment