Navaron Bracke

rename androidResolution to cameraResolution; format

@@ -174,10 +174,10 @@ class MobileScanner( @@ -174,10 +174,10 @@ class MobileScanner(
174 // By default camera set its resolution to width 480 and height 640 which is too low for ML KIT. 174 // By default camera set its resolution to width 480 and height 640 which is too low for ML KIT.
175 // If we return an higher resolution than device can handle, camera package take the most relevant one available. 175 // If we return an higher resolution than device can handle, camera package take the most relevant one available.
176 // Resolution set must take care of device orientation to preserve aspect ratio. 176 // Resolution set must take care of device orientation to preserve aspect ratio.
177 - private fun getResolution(windowManager: WindowManager, androidResolution: Size): Size { 177 + private fun getResolution(windowManager: WindowManager, cameraResolution: Size): Size {
178 val rotation = windowManager.defaultDisplay.rotation 178 val rotation = windowManager.defaultDisplay.rotation
179 - val widthMaxRes = androidResolution.width  
180 - val heightMaxRes = androidResolution.height 179 + val widthMaxRes = cameraResolution.width
  180 + val heightMaxRes = cameraResolution.height
181 181
182 val targetResolution = if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) { 182 val targetResolution = if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) {
183 Size(widthMaxRes, heightMaxRes) // Portrait mode 183 Size(widthMaxRes, heightMaxRes) // Portrait mode
@@ -202,7 +202,7 @@ class MobileScanner( @@ -202,7 +202,7 @@ class MobileScanner(
202 zoomScaleStateCallback: ZoomScaleStateCallback, 202 zoomScaleStateCallback: ZoomScaleStateCallback,
203 mobileScannerStartedCallback: MobileScannerStartedCallback, 203 mobileScannerStartedCallback: MobileScannerStartedCallback,
204 detectionTimeout: Long, 204 detectionTimeout: Long,
205 - androidResolution: Size? 205 + cameraResolution: Size?
206 ) { 206 ) {
207 this.detectionSpeed = detectionSpeed 207 this.detectionSpeed = detectionSpeed
208 this.detectionTimeout = detectionTimeout 208 this.detectionTimeout = detectionTimeout
@@ -255,15 +255,15 @@ class MobileScanner( @@ -255,15 +255,15 @@ class MobileScanner(
255 val displayManager = activity.applicationContext.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager 255 val displayManager = activity.applicationContext.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
256 val windowManager = activity.applicationContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager 256 val windowManager = activity.applicationContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
257 257
258 - if (androidResolution != null) { 258 + if (cameraResolution != null) {
259 // Override initial resolution 259 // Override initial resolution
260 - analysisBuilder.setTargetResolution(getResolution(windowManager, androidResolution)) 260 + analysisBuilder.setTargetResolution(getResolution(windowManager, cameraResolution))
261 // Listen future orientation change to apply the custom resolution 261 // Listen future orientation change to apply the custom resolution
262 displayManager.registerDisplayListener(object : DisplayManager.DisplayListener { 262 displayManager.registerDisplayListener(object : DisplayManager.DisplayListener {
263 override fun onDisplayAdded(displayId: Int) {} 263 override fun onDisplayAdded(displayId: Int) {}
264 override fun onDisplayRemoved(displayId: Int) {} 264 override fun onDisplayRemoved(displayId: Int) {}
265 override fun onDisplayChanged(displayId: Int) { 265 override fun onDisplayChanged(displayId: Int) {
266 - analysisBuilder.setTargetResolution(getResolution(windowManager, androidResolution)) 266 + analysisBuilder.setTargetResolution(getResolution(windowManager, cameraResolution))
267 } 267 }
268 }, null) 268 }, null)
269 } 269 }
@@ -134,9 +134,9 @@ class MobileScannerHandler( @@ -134,9 +134,9 @@ class MobileScannerHandler(
134 val returnImage: Boolean = call.argument<Boolean>("returnImage") ?: false 134 val returnImage: Boolean = call.argument<Boolean>("returnImage") ?: false
135 val speed: Int = call.argument<Int>("speed") ?: 1 135 val speed: Int = call.argument<Int>("speed") ?: 1
136 val timeout: Int = call.argument<Int>("timeout") ?: 250 136 val timeout: Int = call.argument<Int>("timeout") ?: 250
137 - val androidResolutionValueList: List<Int>? = call.argument<List<Int>>("androidResolution")  
138 - val androidResolution: Size? = if (androidResolutionValueList != null) {  
139 - Size(androidResolutionValueList[0], androidResolutionValueList[1]) 137 + val cameraResolutionValues: List<Int>? = call.argument<List<Int>>("cameraResolution")
  138 + val cameraResolution: Size? = if (cameraResolutionValues != null) {
  139 + Size(cameraResolutionValues[0], cameraResolutionValues[1])
140 } else { 140 } else {
141 null 141 null
142 } 142 }
@@ -164,16 +164,24 @@ class MobileScannerHandler( @@ -164,16 +164,24 @@ class MobileScannerHandler(
164 val detectionSpeed: DetectionSpeed = DetectionSpeed.values().first { it.intValue == speed} 164 val detectionSpeed: DetectionSpeed = DetectionSpeed.values().first { it.intValue == speed}
165 165
166 try { 166 try {
167 - mobileScanner!!.start(barcodeScannerOptions, returnImage, position, torch, detectionSpeed, torchStateCallback, zoomScaleStateCallback, mobileScannerStartedCallback = {  
168 - result.success(mapOf(  
169 - "textureId" to it.id,  
170 - "size" to mapOf("width" to it.width, "height" to it.height),  
171 - "torchable" to it.hasFlashUnit  
172 - ))  
173 - }, 167 + mobileScanner!!.start(
  168 + barcodeScannerOptions,
  169 + returnImage,
  170 + position,
  171 + torch,
  172 + detectionSpeed,
  173 + torchStateCallback,
  174 + zoomScaleStateCallback,
  175 + mobileScannerStartedCallback = {
  176 + result.success(mapOf(
  177 + "textureId" to it.id,
  178 + "size" to mapOf("width" to it.width, "height" to it.height),
  179 + "torchable" to it.hasFlashUnit
  180 + ))
  181 + },
174 timeout.toLong(), 182 timeout.toLong(),
175 - androidResolution)  
176 - 183 + cameraResolution,
  184 + )
177 } catch (e: AlreadyStarted) { 185 } catch (e: AlreadyStarted) {
178 result.error( 186 result.error(
179 "MobileScanner", 187 "MobileScanner",
@@ -23,7 +23,7 @@ class MobileScannerController { @@ -23,7 +23,7 @@ class MobileScannerController {
23 ) 23 )
24 this.onPermissionSet, 24 this.onPermissionSet,
25 this.autoStart = true, 25 this.autoStart = true,
26 - this.androidResolution, 26 + this.cameraResolution,
27 }); 27 });
28 28
29 /// Select which camera should be used. 29 /// Select which camera should be used.
@@ -59,20 +59,19 @@ class MobileScannerController { @@ -59,20 +59,19 @@ class MobileScannerController {
59 /// Automatically start the mobileScanner on initialization. 59 /// Automatically start the mobileScanner on initialization.
60 final bool autoStart; 60 final bool autoStart;
61 61
62 - /// Can be used to override default Android camera resolution.  
63 - /// The default camera resolution is 640x480.  
64 - /// Overriding the resolution can change the camera aspect ratio. 62 + /// The desired resolution for the camera.
65 /// 63 ///
66 - /// Example: androidResolution: Size(1920, 2560); 64 + /// When this value is provided, the camera will try to match this resolution,
  65 + /// or fallback to the closest available resolution.
  66 + /// When this is null, Android defaults to a resolution of 640x480.
67 /// 67 ///
68 - /// NOTE:  
69 - /// Values inside this Size will be converted to integer type. 68 + /// Bear in mind that changing the resolution has an effect on the aspect ratio.
70 /// 69 ///
71 - /// The package Android implementation will manage itself the orientation.  
72 - /// You don't need to update this parameter if orientation change. 70 + /// When the camera orientation changes,
  71 + /// the resolution will be flipped to match the new dimensions of the display.
73 /// 72 ///
74 - /// Android will take the closest resolution available if the overrided one can't be set  
75 - final Size? androidResolution; 73 + /// Currently only supported on Android.
  74 + final Size? cameraResolution;
76 75
77 /// Sets the barcode stream 76 /// Sets the barcode stream
78 final StreamController<BarcodeCapture> _barcodesController = 77 final StreamController<BarcodeCapture> _barcodesController =
@@ -150,10 +149,10 @@ class MobileScannerController { @@ -150,10 +149,10 @@ class MobileScannerController {
150 arguments['formats'] = formats!.map((e) => e.rawValue).toList(); 149 arguments['formats'] = formats!.map((e) => e.rawValue).toList();
151 } else if (Platform.isAndroid) { 150 } else if (Platform.isAndroid) {
152 arguments['formats'] = formats!.map((e) => e.index).toList(); 151 arguments['formats'] = formats!.map((e) => e.index).toList();
153 - if (androidResolution != null) {  
154 - arguments['androidResolution'] = <int>[  
155 - androidResolution!.width.toInt(),  
156 - androidResolution!.height.toInt(), 152 + if (cameraResolution != null) {
  153 + arguments['cameraResolution'] = <int>[
  154 + cameraResolution!.width.toInt(),
  155 + cameraResolution!.height.toInt(),
157 ]; 156 ];
158 } 157 }
159 } 158 }