Navaron Bracke

rename androidResolution to cameraResolution; format

... ... @@ -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, androidResolution: Size): Size {
private fun getResolution(windowManager: WindowManager, cameraResolution: 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,
androidResolution: Size?
cameraResolution: 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 (androidResolution != null) {
if (cameraResolution != null) {
// Override initial resolution
analysisBuilder.setTargetResolution(getResolution(windowManager, androidResolution))
analysisBuilder.setTargetResolution(getResolution(windowManager, cameraResolution))
// 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, androidResolution))
analysisBuilder.setTargetResolution(getResolution(windowManager, cameraResolution))
}
}, null)
}
... ...
... ... @@ -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,7 +164,15 @@ class MobileScannerHandler(
val detectionSpeed: DetectionSpeed = DetectionSpeed.values().first { it.intValue == speed}
try {
mobileScanner!!.start(barcodeScannerOptions, returnImage, position, torch, detectionSpeed, torchStateCallback, zoomScaleStateCallback, 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),
... ... @@ -172,8 +180,8 @@ class MobileScannerHandler(
))
},
timeout.toLong(),
androidResolution)
cameraResolution,
)
} catch (e: AlreadyStarted) {
result.error(
"MobileScanner",
... ...
... ... @@ -23,7 +23,7 @@ class MobileScannerController {
)
this.onPermissionSet,
this.autoStart = true,
this.androidResolution,
this.cameraResolution,
});
/// 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(),
];
}
}
... ...