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-13 13:28:46 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
18477145f4922b72a0eb2f8caa7061dc4e8e1b92
18477145
1 parent
3dbb5f18
rename androidResolution to cameraResolution; format
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
34 deletions
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt
lib/src/mobile_scanner_controller.dart
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
View file @
1847714
...
...
@@ -174,10 +174,10 @@ class MobileScanner(
// By default camera set its resolution to width 480 and height 640 which is too low for ML KIT.
// If we return an higher resolution than device can handle, camera package take the most relevant one available.
// Resolution set must take care of device orientation to preserve aspect ratio.
private fun getResolution(windowManager: WindowManager,
android
Resolution: Size): Size {
private fun getResolution(windowManager: WindowManager,
camera
Resolution: Size): Size {
val rotation = windowManager.defaultDisplay.rotation
val widthMaxRes = androidResolution.width
val heightMaxRes = androidResolution.height
val widthMaxRes = cameraResolution.width
val heightMaxRes = cameraResolution.height
val targetResolution = if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) {
Size(widthMaxRes, heightMaxRes) // Portrait mode
...
...
@@ -202,7 +202,7 @@ class MobileScanner(
zoomScaleStateCallback: ZoomScaleStateCallback,
mobileScannerStartedCallback: MobileScannerStartedCallback,
detectionTimeout: Long,
android
Resolution: Size?
camera
Resolution: Size?
) {
this.detectionSpeed = detectionSpeed
this.detectionTimeout = detectionTimeout
...
...
@@ -255,15 +255,15 @@ class MobileScanner(
val displayManager = activity.applicationContext.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
val windowManager = activity.applicationContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
if (
android
Resolution != null) {
if (
camera
Resolution != null) {
// Override initial resolution
analysisBuilder.setTargetResolution(getResolution(windowManager,
android
Resolution))
analysisBuilder.setTargetResolution(getResolution(windowManager,
camera
Resolution))
// Listen future orientation change to apply the custom resolution
displayManager.registerDisplayListener(object : DisplayManager.DisplayListener {
override fun onDisplayAdded(displayId: Int) {}
override fun onDisplayRemoved(displayId: Int) {}
override fun onDisplayChanged(displayId: Int) {
analysisBuilder.setTargetResolution(getResolution(windowManager,
android
Resolution))
analysisBuilder.setTargetResolution(getResolution(windowManager,
camera
Resolution))
}
}, null)
}
...
...
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt
View file @
1847714
...
...
@@ -134,9 +134,9 @@ class MobileScannerHandler(
val returnImage: Boolean = call.argument<Boolean>("returnImage") ?: false
val speed: Int = call.argument<Int>("speed") ?: 1
val timeout: Int = call.argument<Int>("timeout") ?: 250
val androidResolutionValueList: List<Int>? = call.argument<List<Int>>("androidResolution")
val androidResolution: Size? = if (androidResolutionValueList != null) {
Size(androidResolutionValueList[0], androidResolutionValueList[1])
val cameraResolutionValues: List<Int>? = call.argument<List<Int>>("cameraResolution")
val cameraResolution: Size? = if (cameraResolutionValues != null) {
Size(cameraResolutionValues[0], cameraResolutionValues[1])
} else {
null
}
...
...
@@ -164,16 +164,24 @@ class MobileScannerHandler(
val detectionSpeed: DetectionSpeed = DetectionSpeed.values().first { it.intValue == speed}
try {
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),
"torchable" to it.hasFlashUnit
))
},
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),
"torchable" to it.hasFlashUnit
))
},
timeout.toLong(),
androidResolution)
cameraResolution,
)
} catch (e: AlreadyStarted) {
result.error(
"MobileScanner",
...
...
lib/src/mobile_scanner_controller.dart
View file @
1847714
...
...
@@ -23,7 +23,7 @@ class MobileScannerController {
)
this
.
onPermissionSet
,
this
.
autoStart
=
true
,
this
.
android
Resolution
,
this
.
camera
Resolution
,
});
/// Select which camera should be used.
...
...
@@ -59,20 +59,19 @@ class MobileScannerController {
/// Automatically start the mobileScanner on initialization.
final
bool
autoStart
;
/// Can be used to override default Android camera resolution.
/// The default camera resolution is 640x480.
/// Overriding the resolution can change the camera aspect ratio.
/// The desired resolution for the camera.
///
/// Example: androidResolution: Size(1920, 2560);
/// When this value is provided, the camera will try to match this resolution,
/// or fallback to the closest available resolution.
/// When this is null, Android defaults to a resolution of 640x480.
///
/// NOTE:
/// Values inside this Size will be converted to integer type.
/// Bear in mind that changing the resolution has an effect on the aspect ratio.
///
/// The package Android implementation will manage itself the orientation.
/// You don't need to update this parameter if orientation change.
/// When the camera orientation changes,
/// the resolution will be flipped to match the new dimensions of the display.
///
/// Android will take the closest resolution available if the overrided one can't be set
final
Size
?
androidResolution
;
/// Currently only supported on Android.
final
Size
?
cameraResolution
;
/// Sets the barcode stream
final
StreamController
<
BarcodeCapture
>
_barcodesController
=
...
...
@@ -150,10 +149,10 @@ class MobileScannerController {
arguments
[
'formats'
]
=
formats
!.
map
((
e
)
=>
e
.
rawValue
).
toList
();
}
else
if
(
Platform
.
isAndroid
)
{
arguments
[
'formats'
]
=
formats
!.
map
((
e
)
=>
e
.
index
).
toList
();
if
(
androidResolution
!=
null
)
{
arguments
[
'androidResolution'
]
=
<
int
>[
androidResolution
!.
width
.
toInt
(),
androidResolution
!.
height
.
toInt
(),
if
(
cameraResolution
!=
null
)
{
arguments
[
'cameraResolution'
]
=
<
int
>[
cameraResolution
!.
width
.
toInt
(),
cameraResolution
!.
height
.
toInt
(),
];
}
}
...
...
Please
register
or
login
to post a comment