diff --git a/android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt b/android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt index fbc5d0371..c87f808fb 100644 --- a/android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt +++ b/android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt @@ -202,34 +202,6 @@ class MobileScanner( } } - // Return the best resolution for the actual device orientation. - // - // By default the resolution is 480x640, which is too low for ML Kit. - // If the given resolution is not supported by the display, - // the closest available resolution is used. - // - // The resolution should be adjusted for the display rotation, to preserve the aspect ratio. - @Suppress("deprecation") - private fun getResolution(cameraResolution: Size): Size { - val rotation = if (Build.VERSION.SDK_INT >= 30) { - activity.display!!.rotation - } else { - val windowManager = activity.applicationContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager - - windowManager.defaultDisplay.rotation - } - - val widthMaxRes = cameraResolution.width - val heightMaxRes = cameraResolution.height - - val targetResolution = if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) { - Size(widthMaxRes, heightMaxRes) // Portrait mode - } else { - Size(heightMaxRes, widthMaxRes) // Landscape mode - } - return targetResolution - } - /** * Start barcode scanning by initializing the camera and barcode scanner. */ @@ -245,8 +217,7 @@ class MobileScanner( mobileScannerStartedCallback: MobileScannerStartedCallback, mobileScannerErrorCallback: (exception: Exception) -> Unit, detectionTimeout: Long, - cameraResolution: Size?, - newCameraResolutionSelector: Boolean + cameraResolutionWanted: Size? ) { this.detectionSpeed = detectionSpeed this.detectionTimeout = detectionTimeout @@ -302,48 +273,37 @@ class MobileScanner( .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) val displayManager = activity.applicationContext.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager - if (cameraResolution != null) { - if (newCameraResolutionSelector) { - val selectorBuilder = ResolutionSelector.Builder() - selectorBuilder.setResolutionStrategy( - ResolutionStrategy( - cameraResolution, - ResolutionStrategy.FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER - ) - ) - analysisBuilder.setResolutionSelector(selectorBuilder.build()).build() - } else { - @Suppress("DEPRECATION") - analysisBuilder.setTargetResolution(getResolution(cameraResolution)) - } + val cameraResolution = cameraResolutionWanted ?: Size(1920, 1080) - if (displayListener == null) { - displayListener = object : DisplayManager.DisplayListener { - override fun onDisplayAdded(displayId: Int) {} - - override fun onDisplayRemoved(displayId: Int) {} - - override fun onDisplayChanged(displayId: Int) { - if (newCameraResolutionSelector) { - val selectorBuilder = ResolutionSelector.Builder() - selectorBuilder.setResolutionStrategy( - ResolutionStrategy( - cameraResolution, - ResolutionStrategy.FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER - ) - ) - analysisBuilder.setResolutionSelector(selectorBuilder.build()).build() - } else { - @Suppress("DEPRECATION") - analysisBuilder.setTargetResolution(getResolution(cameraResolution)) - } - } - } + val selectorBuilder = ResolutionSelector.Builder() + selectorBuilder.setResolutionStrategy( + ResolutionStrategy( + cameraResolution, + ResolutionStrategy.FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER + ) + ) + analysisBuilder.setResolutionSelector(selectorBuilder.build()).build() + + if (displayListener == null) { + displayListener = object : DisplayManager.DisplayListener { + override fun onDisplayAdded(displayId: Int) {} + + override fun onDisplayRemoved(displayId: Int) {} - displayManager.registerDisplayListener( - displayListener, null, - ) + override fun onDisplayChanged(displayId: Int) { + val selector = ResolutionSelector.Builder().setResolutionStrategy( + ResolutionStrategy( + cameraResolution, + ResolutionStrategy.FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER + ) + ) + analysisBuilder.setResolutionSelector(selector.build()).build() + } } + + displayManager.registerDisplayListener( + displayListener, null, + ) } val analysis = analysisBuilder.build().apply { setAnalyzer(executor, captureOutput) } diff --git a/android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt b/android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt index 8b67192f5..c93648ba1 100644 --- a/android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt +++ b/android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt @@ -137,7 +137,6 @@ class MobileScannerHandler( val speed: Int = call.argument("speed") ?: 1 val timeout: Int = call.argument("timeout") ?: 250 val cameraResolutionValues: List? = call.argument>("cameraResolution") - val useNewCameraSelector: Boolean = call.argument("useNewCameraSelector") ?: false val cameraResolution: Size? = if (cameraResolutionValues != null) { Size(cameraResolutionValues[0], cameraResolutionValues[1]) } else { @@ -208,8 +207,7 @@ class MobileScannerHandler( } }, timeout.toLong(), - cameraResolution, - useNewCameraSelector + cameraResolution ) } diff --git a/example/lib/barcode_scanner_controller.dart b/example/lib/barcode_scanner_controller.dart index 15bfbcfc6..c7bd1bd18 100644 --- a/example/lib/barcode_scanner_controller.dart +++ b/example/lib/barcode_scanner_controller.dart @@ -18,7 +18,6 @@ class _BarcodeScannerWithControllerState final MobileScannerController controller = MobileScannerController( autoStart: false, torchEnabled: true, - useNewCameraSelector: true, ); Barcode? _barcode; diff --git a/lib/src/mobile_scanner_controller.dart b/lib/src/mobile_scanner_controller.dart index 6b2d718dc..8ea6a7b47 100644 --- a/lib/src/mobile_scanner_controller.dart +++ b/lib/src/mobile_scanner_controller.dart @@ -25,7 +25,6 @@ class MobileScannerController extends ValueNotifier { this.formats = const [], this.returnImage = false, this.torchEnabled = false, - this.useNewCameraSelector = false, }) : detectionTimeoutMs = detectionSpeed == DetectionSpeed.normal ? detectionTimeoutMs : 0, assert( @@ -87,15 +86,6 @@ class MobileScannerController extends ValueNotifier { /// Defaults to false. final bool torchEnabled; - /// Use the new resolution selector. - /// - /// This feature is experimental and not fully tested yet. - /// Use caution when using this flag, - /// as the new resolution selector may produce unwanted or zoomed images. - /// - /// Only supported on Android. - final bool useNewCameraSelector; - /// The internal barcode controller, that listens for detected barcodes. final StreamController _barcodesController = StreamController.broadcast(); @@ -282,7 +272,6 @@ class MobileScannerController extends ValueNotifier { formats: formats, returnImage: returnImage, torchEnabled: torchEnabled, - useNewCameraSelector: useNewCameraSelector, ); try { diff --git a/lib/src/objects/start_options.dart b/lib/src/objects/start_options.dart index 3b19e7b92..71f368d69 100644 --- a/lib/src/objects/start_options.dart +++ b/lib/src/objects/start_options.dart @@ -14,7 +14,6 @@ class StartOptions { required this.formats, required this.returnImage, required this.torchEnabled, - required this.useNewCameraSelector, }); /// The direction for the camera. @@ -38,11 +37,6 @@ class StartOptions { /// Whether the torch should be turned on when the scanner starts. final bool torchEnabled; - /// Whether the new resolution selector should be used. - /// - /// This option is only supported on Android. Other platforms will ignore this option. - final bool useNewCameraSelector; - Map toMap() { return { if (cameraResolution != null) @@ -57,7 +51,6 @@ class StartOptions { 'speed': detectionSpeed.rawValue, 'timeout': detectionTimeoutMs, 'torch': torchEnabled, - 'useNewCameraSelector': useNewCameraSelector, }; } }