From 78ecba805f932c7adf735870e68bd5057c855a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alen=20Fri=C5=A1=C4=8Di=C4=87?= Date: Wed, 20 Dec 2023 10:18:01 +0100 Subject: [PATCH] 1.2.1 --- .../BarcodeScanning.Native.Maui.csproj | 9 +++++++-- BarcodeScanning.Native.Maui/CameraView.cs | 1 - .../CameraViewHandler.cs | 13 +++---------- BarcodeScanning.Native.Maui/NET/BarcodeView.cs | 5 +++++ .../NET/CameraViewHandler.cs | 16 ++++++++++++++++ BarcodeScanning.Native.Maui/NET/Methods.cs | 6 ++++++ .../Platforms/Android/BarcodeAnalyzer.cs | 3 +-- .../Platforms/Android/BarcodeView.cs | 5 ++--- ...Handler.android.cs => CameraViewHandler.cs} | 6 ++---- .../Platforms/Android/Methods.cs | 7 +++---- .../Platforms/iOS/BarcodeAnalyzer.cs | 2 +- .../Platforms/iOS/BarcodeView.cs | 4 ++-- ...ViewHandler.ios.cs => CameraViewHandler.cs} | 18 ++++++++++++------ .../Platforms/iOS/Methods.cs | 6 +++--- BarcodeScanning.Native.Maui/Shared/Methods.cs | 12 +----------- .../Shared/OnDetectedEventArg.cs | 7 +------ 16 files changed, 65 insertions(+), 55 deletions(-) create mode 100644 BarcodeScanning.Native.Maui/NET/BarcodeView.cs create mode 100644 BarcodeScanning.Native.Maui/NET/CameraViewHandler.cs create mode 100644 BarcodeScanning.Native.Maui/NET/Methods.cs rename BarcodeScanning.Native.Maui/Platforms/Android/{CameraViewHandler.android.cs => CameraViewHandler.cs} (95%) rename BarcodeScanning.Native.Maui/Platforms/iOS/{CameraViewHandler.ios.cs => CameraViewHandler.cs} (88%) diff --git a/BarcodeScanning.Native.Maui/BarcodeScanning.Native.Maui.csproj b/BarcodeScanning.Native.Maui/BarcodeScanning.Native.Maui.csproj index 1f75af2..b1e7d0a 100644 --- a/BarcodeScanning.Native.Maui/BarcodeScanning.Native.Maui.csproj +++ b/BarcodeScanning.Native.Maui/BarcodeScanning.Native.Maui.csproj @@ -1,11 +1,11 @@  - net8.0-android;net8.0-ios + net8.0;net8.0-android;net8.0-ios true true enable - 1.2.0 + 1.2.1 Alen Friščić MIT README.md @@ -17,6 +17,11 @@ 15.1 + + + + + diff --git a/BarcodeScanning.Native.Maui/CameraView.cs b/BarcodeScanning.Native.Maui/CameraView.cs index 0ffc93d..4797bc5 100644 --- a/BarcodeScanning.Native.Maui/CameraView.cs +++ b/BarcodeScanning.Native.Maui/CameraView.cs @@ -1,5 +1,4 @@ using System.Windows.Input; - using Timer = System.Timers.Timer; namespace BarcodeScanning; diff --git a/BarcodeScanning.Native.Maui/CameraViewHandler.cs b/BarcodeScanning.Native.Maui/CameraViewHandler.cs index 488735c..43902a4 100644 --- a/BarcodeScanning.Native.Maui/CameraViewHandler.cs +++ b/BarcodeScanning.Native.Maui/CameraViewHandler.cs @@ -1,15 +1,8 @@ using Microsoft.Maui.Handlers; -#if IOS -using NativeCameraView = UIKit.UIView; -#elif ANDROID -using NativeCameraView = AndroidX.CoordinatorLayout.Widget.CoordinatorLayout; - -#endif - namespace BarcodeScanning; -public partial class CameraViewHandler : ViewHandler +public partial class CameraViewHandler : ViewHandler { public static readonly PropertyMapper CameraViewMapper = new() { @@ -29,10 +22,10 @@ public CameraViewHandler() : base(CameraViewMapper, CameraCommandMapper) { } - protected override void DisconnectHandler(NativeCameraView nativeView) + protected override void DisconnectHandler(BarcodeView barcodeView) { this.Stop(); - base.DisconnectHandler(nativeView); + base.DisconnectHandler(barcodeView); this.DisposeView(); } } \ No newline at end of file diff --git a/BarcodeScanning.Native.Maui/NET/BarcodeView.cs b/BarcodeScanning.Native.Maui/NET/BarcodeView.cs new file mode 100644 index 0000000..1899c78 --- /dev/null +++ b/BarcodeScanning.Native.Maui/NET/BarcodeView.cs @@ -0,0 +1,5 @@ +namespace BarcodeScanning; + +public class BarcodeView +{ +} diff --git a/BarcodeScanning.Native.Maui/NET/CameraViewHandler.cs b/BarcodeScanning.Native.Maui/NET/CameraViewHandler.cs new file mode 100644 index 0000000..d584ea2 --- /dev/null +++ b/BarcodeScanning.Native.Maui/NET/CameraViewHandler.cs @@ -0,0 +1,16 @@ +namespace BarcodeScanning; + +public partial class CameraViewHandler +{ + protected override BarcodeView CreatePlatformView() => throw new NotImplementedException(); + private void Start() => throw new NotImplementedException(); + private void Stop() => throw new NotImplementedException(); + private void UpdateCamera() => throw new NotImplementedException(); + private void UpdateResolution() => throw new NotImplementedException(); + private void UpdateAnalyzer() => throw new NotImplementedException(); + private void UpdateTorch() => throw new NotImplementedException(); + private void HandleCameraEnabled() => throw new NotImplementedException(); + private void HandleAimModeEnabled() => throw new NotImplementedException(); + private void DisposeView() => throw new NotImplementedException(); + +} diff --git a/BarcodeScanning.Native.Maui/NET/Methods.cs b/BarcodeScanning.Native.Maui/NET/Methods.cs new file mode 100644 index 0000000..709ad7a --- /dev/null +++ b/BarcodeScanning.Native.Maui/NET/Methods.cs @@ -0,0 +1,6 @@ +namespace BarcodeScanning; + +public static partial class Methods +{ + public static Task> ScanFromImage(byte[] imageArray) => throw new NotImplementedException(); +} diff --git a/BarcodeScanning.Native.Maui/Platforms/Android/BarcodeAnalyzer.cs b/BarcodeScanning.Native.Maui/Platforms/Android/BarcodeAnalyzer.cs index 67e19da..41fcece 100644 --- a/BarcodeScanning.Native.Maui/Platforms/Android/BarcodeAnalyzer.cs +++ b/BarcodeScanning.Native.Maui/Platforms/Android/BarcodeAnalyzer.cs @@ -4,10 +4,9 @@ using AndroidX.Camera.View.Transform; using Xamarin.Google.MLKit.Vision.BarCode; using Xamarin.Google.MLKit.Vision.Common; - using Size = Android.Util.Size; -namespace BarcodeScanning.Platforms.Android; +namespace BarcodeScanning; internal class BarcodeAnalyzer : Java.Lang.Object, ImageAnalysis.IAnalyzer { diff --git a/BarcodeScanning.Native.Maui/Platforms/Android/BarcodeView.cs b/BarcodeScanning.Native.Maui/Platforms/Android/BarcodeView.cs index fa42e6d..64d4f8d 100644 --- a/BarcodeScanning.Native.Maui/Platforms/Android/BarcodeView.cs +++ b/BarcodeScanning.Native.Maui/Platforms/Android/BarcodeView.cs @@ -3,13 +3,12 @@ using Android.Widget; using AndroidX.Camera.View; using AndroidX.CoordinatorLayout.Widget; - using Color = Android.Graphics.Color; using Paint = Android.Graphics.Paint; -namespace BarcodeScanning.Platforms.Android; +namespace BarcodeScanning; -internal class BarcodeView : CoordinatorLayout +public class BarcodeView : CoordinatorLayout { private readonly ImageView _imageView; private readonly RelativeLayout _relativeLayout; diff --git a/BarcodeScanning.Native.Maui/Platforms/Android/CameraViewHandler.android.cs b/BarcodeScanning.Native.Maui/Platforms/Android/CameraViewHandler.cs similarity index 95% rename from BarcodeScanning.Native.Maui/Platforms/Android/CameraViewHandler.android.cs rename to BarcodeScanning.Native.Maui/Platforms/Android/CameraViewHandler.cs index 4c0549f..e03ab0e 100644 --- a/BarcodeScanning.Native.Maui/Platforms/Android/CameraViewHandler.android.cs +++ b/BarcodeScanning.Native.Maui/Platforms/Android/CameraViewHandler.cs @@ -2,9 +2,7 @@ using Android.Widget; using AndroidX.Camera.Core; using AndroidX.Camera.View; -using AndroidX.CoordinatorLayout.Widget; using AndroidX.Lifecycle; -using BarcodeScanning.Platforms.Android; using Java.Util.Concurrent; using static Android.Views.ViewGroup; @@ -20,7 +18,7 @@ public partial class CameraViewHandler private bool _cameraStarted = false; - protected override CoordinatorLayout CreatePlatformView() + protected override BarcodeView CreatePlatformView() { DeviceDisplay.Current.MainDisplayInfoChanged += Current_MainDisplayInfoChanged; @@ -117,7 +115,7 @@ private void UpdateCamera() private void UpdateResolution() { if (_cameraController is not null) - _cameraController.ImageAnalysisTargetSize = new CameraController.OutputSize(Platforms.Android.Methods.TargetResolution(VirtualView?.CaptureQuality)); + _cameraController.ImageAnalysisTargetSize = new CameraController.OutputSize(Methods.TargetResolution(VirtualView?.CaptureQuality)); if (_cameraStarted) Start(); diff --git a/BarcodeScanning.Native.Maui/Platforms/Android/Methods.cs b/BarcodeScanning.Native.Maui/Platforms/Android/Methods.cs index 7e06d49..6902cc5 100644 --- a/BarcodeScanning.Native.Maui/Platforms/Android/Methods.cs +++ b/BarcodeScanning.Native.Maui/Platforms/Android/Methods.cs @@ -7,15 +7,14 @@ using Xamarin.Google.MLKit.Vision.Barcode.Common; using Xamarin.Google.MLKit.Vision.BarCode; using Xamarin.Google.MLKit.Vision.Common; - using Image = Android.Media.Image; using Size = Android.Util.Size; -namespace BarcodeScanning.Platforms.Android; +namespace BarcodeScanning; -internal class Methods +public static partial class Methods { - internal static async Task> ScanFromImage(byte[] imageArray) + public static async Task> ScanFromImage(byte[] imageArray) { using Bitmap bitmap = await BitmapFactory.DecodeByteArrayAsync(imageArray, 0, imageArray.Length); if (bitmap is null) diff --git a/BarcodeScanning.Native.Maui/Platforms/iOS/BarcodeAnalyzer.cs b/BarcodeScanning.Native.Maui/Platforms/iOS/BarcodeAnalyzer.cs index b1abc76..90f77ce 100644 --- a/BarcodeScanning.Native.Maui/Platforms/iOS/BarcodeAnalyzer.cs +++ b/BarcodeScanning.Native.Maui/Platforms/iOS/BarcodeAnalyzer.cs @@ -2,7 +2,7 @@ using CoreMedia; using Vision; -namespace BarcodeScanning.Platforms.iOS; +namespace BarcodeScanning; internal class BarcodeAnalyzer : AVCaptureVideoDataOutputSampleBufferDelegate { diff --git a/BarcodeScanning.Native.Maui/Platforms/iOS/BarcodeView.cs b/BarcodeScanning.Native.Maui/Platforms/iOS/BarcodeView.cs index c1d8c42..e4f1a46 100644 --- a/BarcodeScanning.Native.Maui/Platforms/iOS/BarcodeView.cs +++ b/BarcodeScanning.Native.Maui/Platforms/iOS/BarcodeView.cs @@ -3,9 +3,9 @@ using CoreGraphics; using UIKit; -namespace BarcodeScanning.Platforms.iOS; +namespace BarcodeScanning; -internal class BarcodeView : UIView +public class BarcodeView : UIView { private readonly AVCaptureVideoPreviewLayer _previewLayer; private readonly CAShapeLayer _shapeLayer; diff --git a/BarcodeScanning.Native.Maui/Platforms/iOS/CameraViewHandler.ios.cs b/BarcodeScanning.Native.Maui/Platforms/iOS/CameraViewHandler.cs similarity index 88% rename from BarcodeScanning.Native.Maui/Platforms/iOS/CameraViewHandler.ios.cs rename to BarcodeScanning.Native.Maui/Platforms/iOS/CameraViewHandler.cs index 4ed51ef..4011d90 100644 --- a/BarcodeScanning.Native.Maui/Platforms/iOS/CameraViewHandler.ios.cs +++ b/BarcodeScanning.Native.Maui/Platforms/iOS/CameraViewHandler.cs @@ -1,5 +1,4 @@ using AVFoundation; -using BarcodeScanning.Platforms.iOS; using CoreFoundation; using CoreVideo; using Foundation; @@ -19,7 +18,7 @@ public partial class CameraViewHandler private BarcodeView _barcodeView; private UITapGestureRecognizer _uITapGestureRecognizer; - protected override UIView CreatePlatformView() + protected override BarcodeView CreatePlatformView() { _captureSession = new AVCaptureSession(); _uITapGestureRecognizer = new UITapGestureRecognizer(FocusOnTap); @@ -133,10 +132,17 @@ private void UpdateCamera() } _captureDevice?.Dispose(); - _captureDevice = AVCaptureDevice.GetDefaultDevice( - AVCaptureDeviceType.BuiltInWideAngleCamera, - AVMediaTypes.Video, - VirtualView?.CameraFacing == CameraFacing.Front ? AVCaptureDevicePosition.Front : AVCaptureDevicePosition.Back); + if (VirtualView?.CameraFacing == CameraFacing.Front) + { + _captureDevice = AVCaptureDevice.GetDefaultDevice(AVCaptureDeviceType.BuiltInWideAngleCamera, AVMediaTypes.Video, AVCaptureDevicePosition.Front); + } + else + { + _captureDevice = AVCaptureDevice.GetDefaultDevice(AVCaptureDeviceType.BuiltInTripleCamera, AVMediaTypes.Video, AVCaptureDevicePosition.Back); + _captureDevice ??= AVCaptureDevice.GetDefaultDevice(AVCaptureDeviceType.BuiltInDualWideCamera, AVMediaTypes.Video, AVCaptureDevicePosition.Back); + _captureDevice ??= AVCaptureDevice.GetDefaultDevice(AVCaptureDeviceType.BuiltInDualCamera, AVMediaTypes.Video, AVCaptureDevicePosition.Back); + _captureDevice ??= AVCaptureDevice.GetDefaultDevice(AVCaptureDeviceType.BuiltInWideAngleCamera, AVMediaTypes.Video, AVCaptureDevicePosition.Back); + } _captureDevice ??= AVCaptureDevice.GetDefaultDevice(AVMediaTypes.Video); if (_captureDevice is not null) diff --git a/BarcodeScanning.Native.Maui/Platforms/iOS/Methods.cs b/BarcodeScanning.Native.Maui/Platforms/iOS/Methods.cs index cfe2574..e03b201 100644 --- a/BarcodeScanning.Native.Maui/Platforms/iOS/Methods.cs +++ b/BarcodeScanning.Native.Maui/Platforms/iOS/Methods.cs @@ -6,11 +6,11 @@ using UIKit; using Vision; -namespace BarcodeScanning.Platforms.iOS; +namespace BarcodeScanning; -internal class Methods +public static partial class Methods { - internal static async Task> ScanFromImage(byte[] imageArray) + public static async Task> ScanFromImage(byte[] imageArray) { VNBarcodeObservation[] observations = null; diff --git a/BarcodeScanning.Native.Maui/Shared/Methods.cs b/BarcodeScanning.Native.Maui/Shared/Methods.cs index fab4f14..3a5d81c 100644 --- a/BarcodeScanning.Native.Maui/Shared/Methods.cs +++ b/BarcodeScanning.Native.Maui/Shared/Methods.cs @@ -1,6 +1,6 @@ namespace BarcodeScanning; -public static class Methods +public static partial class Methods { public static async Task AskForRequiredPermissionAsync() { @@ -21,14 +21,4 @@ public static async Task AskForRequiredPermissionAsync() } return false; } - - public static Task> ScanFromImageAsync(byte[] imageArray) - { - #if IOS - return Platforms.iOS.Methods.ScanFromImage(imageArray); - #elif ANDROID - return Platforms.Android.Methods.ScanFromImage(imageArray); - #endif - - } } \ No newline at end of file diff --git a/BarcodeScanning.Native.Maui/Shared/OnDetectedEventArg.cs b/BarcodeScanning.Native.Maui/Shared/OnDetectedEventArg.cs index 6816109..c2d230b 100644 --- a/BarcodeScanning.Native.Maui/Shared/OnDetectedEventArg.cs +++ b/BarcodeScanning.Native.Maui/Shared/OnDetectedEventArg.cs @@ -2,10 +2,5 @@ public class OnDetectionFinishedEventArg : EventArgs { - public HashSet BarcodeResults { get; set; } - - public OnDetectionFinishedEventArg() - { - BarcodeResults = new HashSet(); - } + public HashSet BarcodeResults { get; set; } = new(); } \ No newline at end of file