Skip to content

Commit

Permalink
1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
afriscic committed Jan 9, 2024
1 parent c9ad1c3 commit 2504c6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.2.2</Version>
<Version>1.2.3</Version>
<Authors>Alen Friščić</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
19 changes: 13 additions & 6 deletions BarcodeScanning.Native.Maui/Platforms/Android/CameraViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ public partial class CameraViewHandler
private LifecycleCameraController _cameraController;
private PreviewView _previewView;

private readonly int _delay = 200;
private bool _cameraStarted = false;

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)
Expand Down Expand Up @@ -55,6 +57,8 @@ private void Start()
if (lifecycleOwner is null)
return;

UpdateAnalyzer();

_cameraController.BindToLifecycle(lifecycleOwner);
_cameraStarted = true;
}
Expand All @@ -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
Expand All @@ -94,7 +102,6 @@ private void UpdateAnalyzer()
_barcodeAnalyzer?.Dispose();
_barcodeAnalyzer = new BarcodeAnalyzer(VirtualView, _previewView);
_cameraController.SetImageAnalysisAnalyzer(_cameraExecutor, _barcodeAnalyzer);
_cameraController.ImageAnalysisBackpressureStrategy = ImageAnalysis.StrategyKeepOnlyLatest;
}
}

Expand Down Expand Up @@ -140,7 +147,7 @@ private void DisposeView()
{
_ = Task.Run(async () =>
{
await Task.Delay(100);
await Task.Delay(_delay);
MainThread.BeginInvokeOnMainThread(() =>
{
this.Stop();
Expand All @@ -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
Expand Down

0 comments on commit 2504c6a

Please sign in to comment.