From 2504c6ab146a9e70561fc7256f27f8aa1cba9929 Mon Sep 17 00:00:00 2001 From: afriscic Date: Tue, 9 Jan 2024 09:14:58 +0100 Subject: [PATCH] 1.2.3 --- .../BarcodeScanning.Native.Maui.csproj | 2 +- .../Platforms/Android/CameraViewHandler.cs | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/BarcodeScanning.Native.Maui/BarcodeScanning.Native.Maui.csproj b/BarcodeScanning.Native.Maui/BarcodeScanning.Native.Maui.csproj index bcd7968..8ee2184 100644 --- a/BarcodeScanning.Native.Maui/BarcodeScanning.Native.Maui.csproj +++ b/BarcodeScanning.Native.Maui/BarcodeScanning.Native.Maui.csproj @@ -5,7 +5,7 @@ true true enable - 1.2.2 + 1.2.3 Alen Friščić MIT README.md diff --git a/BarcodeScanning.Native.Maui/Platforms/Android/CameraViewHandler.cs b/BarcodeScanning.Native.Maui/Platforms/Android/CameraViewHandler.cs index 3479d0e..1e6c867 100644 --- a/BarcodeScanning.Native.Maui/Platforms/Android/CameraViewHandler.cs +++ b/BarcodeScanning.Native.Maui/Platforms/Android/CameraViewHandler.cs @@ -16,6 +16,7 @@ public partial class CameraViewHandler private LifecycleCameraController _cameraController; private PreviewView _previewView; + private readonly int _delay = 200; private bool _cameraStarted = false; protected override BarcodeView CreatePlatformView() @@ -23,7 +24,8 @@ protected override BarcodeView CreatePlatformView() _cameraExecutor = Executors.NewSingleThreadExecutor(); _cameraController = new LifecycleCameraController(Context) { - TapToFocusEnabled = VirtualView?.TapToFocusEnabled ?? false + TapToFocusEnabled = VirtualView?.TapToFocusEnabled ?? false, + ImageAnalysisBackpressureStrategy = ImageAnalysis.StrategyKeepOnlyLatest }; _cameraController.SetEnabledUseCases(CameraController.ImageAnalysis); _previewView = new PreviewView(Context) @@ -55,6 +57,8 @@ private void Start() if (lifecycleOwner is null) return; + UpdateAnalyzer(); + _cameraController.BindToLifecycle(lifecycleOwner); _cameraStarted = true; } @@ -77,11 +81,15 @@ private void HandleCameraEnabled() if (VirtualView?.CameraEnabled ?? false) _ = Task.Run(async () => { - await Task.Delay(100); + await Task.Delay(_delay); MainThread.BeginInvokeOnMainThread(Start); }); else - Stop(); + _ = Task.Run(async () => + { + await Task.Delay(_delay); + MainThread.BeginInvokeOnMainThread(Stop); + }); } //TODO Implement camera-mlkit-vision @@ -94,7 +102,6 @@ private void UpdateAnalyzer() _barcodeAnalyzer?.Dispose(); _barcodeAnalyzer = new BarcodeAnalyzer(VirtualView, _previewView); _cameraController.SetImageAnalysisAnalyzer(_cameraExecutor, _barcodeAnalyzer); - _cameraController.ImageAnalysisBackpressureStrategy = ImageAnalysis.StrategyKeepOnlyLatest; } } @@ -140,7 +147,7 @@ private void DisposeView() { _ = Task.Run(async () => { - await Task.Delay(100); + await Task.Delay(_delay); MainThread.BeginInvokeOnMainThread(() => { this.Stop(); @@ -158,7 +165,7 @@ internal void Current_MainDisplayInfoChanged(object sender, DisplayInfoChangedEv { _ = Task.Run(async () => { - await Task.Delay(100); + await Task.Delay(_delay); MainThread.BeginInvokeOnMainThread(() => { try