Skip to content

Commit

Permalink
1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
afriscic committed Dec 20, 2023
1 parent 170794a commit 78ecba8
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios</TargetFrameworks>
<TargetFrameworks>net8.0;net8.0-android;net8.0-ios</TargetFrameworks>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.2.0</Version>
<Version>1.2.1</Version>
<Authors>Alen Friščić</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand All @@ -17,6 +17,11 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.1</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup Condition="!($(TargetFramework.StartsWith('net')) == true AND $(TargetFramework.EndsWith('.0')) == true AND $(TargetFramework.Contains('-')) != true)">
<Compile Remove="**\NET\**\*.cs" />
<None Include="**\NET\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
Expand Down
1 change: 0 additions & 1 deletion BarcodeScanning.Native.Maui/CameraView.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Windows.Input;

using Timer = System.Timers.Timer;

namespace BarcodeScanning;
Expand Down
13 changes: 3 additions & 10 deletions BarcodeScanning.Native.Maui/CameraViewHandler.cs
Original file line number Diff line number Diff line change
@@ -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<CameraView, NativeCameraView>
public partial class CameraViewHandler : ViewHandler<CameraView, BarcodeView>
{
public static readonly PropertyMapper<CameraView, CameraViewHandler> CameraViewMapper = new()
{
Expand All @@ -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();
}
}
5 changes: 5 additions & 0 deletions BarcodeScanning.Native.Maui/NET/BarcodeView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace BarcodeScanning;

public class BarcodeView
{
}
16 changes: 16 additions & 0 deletions BarcodeScanning.Native.Maui/NET/CameraViewHandler.cs
Original file line number Diff line number Diff line change
@@ -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();

}
6 changes: 6 additions & 0 deletions BarcodeScanning.Native.Maui/NET/Methods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace BarcodeScanning;

public static partial class Methods
{
public static Task<HashSet<BarcodeResult>> ScanFromImage(byte[] imageArray) => throw new NotImplementedException();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
5 changes: 2 additions & 3 deletions BarcodeScanning.Native.Maui/Platforms/Android/BarcodeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
7 changes: 3 additions & 4 deletions BarcodeScanning.Native.Maui/Platforms/Android/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HashSet<BarcodeResult>> ScanFromImage(byte[] imageArray)
public static async Task<HashSet<BarcodeResult>> ScanFromImage(byte[] imageArray)
{
using Bitmap bitmap = await BitmapFactory.DecodeByteArrayAsync(imageArray, 0, imageArray.Length);
if (bitmap is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using CoreMedia;
using Vision;

namespace BarcodeScanning.Platforms.iOS;
namespace BarcodeScanning;

internal class BarcodeAnalyzer : AVCaptureVideoDataOutputSampleBufferDelegate
{
Expand Down
4 changes: 2 additions & 2 deletions BarcodeScanning.Native.Maui/Platforms/iOS/BarcodeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AVFoundation;
using BarcodeScanning.Platforms.iOS;
using CoreFoundation;
using CoreVideo;
using Foundation;
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions BarcodeScanning.Native.Maui/Platforms/iOS/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HashSet<BarcodeResult>> ScanFromImage(byte[] imageArray)
public static async Task<HashSet<BarcodeResult>> ScanFromImage(byte[] imageArray)
{
VNBarcodeObservation[] observations = null;

Expand Down
12 changes: 1 addition & 11 deletions BarcodeScanning.Native.Maui/Shared/Methods.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace BarcodeScanning;

public static class Methods
public static partial class Methods
{
public static async Task<bool> AskForRequiredPermissionAsync()
{
Expand All @@ -21,14 +21,4 @@ public static async Task<bool> AskForRequiredPermissionAsync()
}
return false;
}

public static Task<HashSet<BarcodeResult>> ScanFromImageAsync(byte[] imageArray)
{
#if IOS
return Platforms.iOS.Methods.ScanFromImage(imageArray);
#elif ANDROID
return Platforms.Android.Methods.ScanFromImage(imageArray);
#endif

}
}
7 changes: 1 addition & 6 deletions BarcodeScanning.Native.Maui/Shared/OnDetectedEventArg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@

public class OnDetectionFinishedEventArg : EventArgs
{
public HashSet<BarcodeResult> BarcodeResults { get; set; }

public OnDetectionFinishedEventArg()
{
BarcodeResults = new HashSet<BarcodeResult>();
}
public HashSet<BarcodeResult> BarcodeResults { get; set; } = new();
}

0 comments on commit 78ecba8

Please sign in to comment.