Skip to content

Commit

Permalink
Merge pull request #126 from doo/develop
Browse files Browse the repository at this point in the history
[EPIC-4283]- Xamarin Document SDK 4.2.0
  • Loading branch information
ildar-scanbot authored Apr 25, 2024
2 parents 9d7932f + 5b734ff commit d7af58c
Show file tree
Hide file tree
Showing 24 changed files with 1,159 additions and 415 deletions.
853 changes: 660 additions & 193 deletions Libraries.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
<JavaMaximumHeapSize></JavaMaximumHeapSize>
<AndroidFastDeploymentType></AndroidFastDeploymentType>
<AndroidManifest></AndroidManifest>
<AssemblyOriginatorKeyFile></AssemblyOriginatorKeyFile>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<LangVersion>8.0</LangVersion>
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
Expand All @@ -69,7 +68,7 @@
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2612" />
<PackageReference Include="ScanbotSDK.Xamarin.Forms">
<Version>3.10.2</Version>
<Version>4.2.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Collections.Generic;
using AndroidBarcode = IO.Scanbot.Sdk.Barcode.Entity.BarcodeItem;
using ScanbotSDK.Xamarin.Forms;
using IO.Scanbot.Barcodescanner.Model;

/*
This is the Android Custom Renderer that will provide the actual implementation for BarcodeCameraView.
Expand All @@ -43,6 +44,7 @@ class AndroidBarcodeCameraRenderer : ViewRenderer<BarcodeCameraView, FrameLayout
protected BarcodeScannerView cameraView;
private readonly int REQUEST_PERMISSION_CODE = 200;
BarcodeResultDelegate resultHandler;
private bool showToast;

public AndroidBarcodeCameraRenderer(Context context) : base(context)
{
Expand Down Expand Up @@ -136,14 +138,26 @@ public void OnCameraOpened()

private void OnSelectionOverlayBarcodeClicked(object sender, AndroidBarcode e)
{
var items = new List<AndroidBarcode> { e };
var args = new BarcodeEventArgs(new IO.Scanbot.Sdk.Barcode.Entity.BarcodeScanningResult(items, new Java.Util.Date().Time), null);
OnBarcodeResult(this, args);
ScanbotSDK.Xamarin.Forms.BarcodeScanningResult outResult = new ScanbotSDK.Xamarin.Forms.BarcodeScanningResult
{
Barcodes = new List<Barcode> { e.ToFormsBarcode() },
Image = e.Image.ToImageSource()
};

Element.OnBarcodeScanResult?.Invoke(outResult);
}

private void OnBarcodeResult(object sender, BarcodeEventArgs e)
{
if (e.Result != null)
if (!SBSDK.IsLicenseValid && !showToast)
{
showToast = true;
cameraView.Post(() => Toast.MakeText(Context.GetActivity(), "License has expired!", ToastLength.Long).Show());
return;
}

var overlayEnabled = Element.OverlayConfiguration?.Enabled ?? false;
if (overlayEnabled == false || Element.OverlayConfiguration?.AutomaticSelectionEnabled == true)
{
ScanbotSDK.Xamarin.Forms.BarcodeScanningResult outResult = new ScanbotSDK.Xamarin.Forms.BarcodeScanningResult
{
Expand All @@ -153,11 +167,6 @@ private void OnBarcodeResult(object sender, BarcodeEventArgs e)

Element.OnBarcodeScanResult?.Invoke(outResult);
}

if (e.Error != null)
{
cameraView.Post(() => Toast.MakeText(Context.GetActivity(), "License has expired!", ToastLength.Long).Show());
}
}

#endregion
Expand Down Expand Up @@ -186,11 +195,6 @@ private void SetSelectionOverlayConfiguration()
cameraView.SelectionOverlayController.SetEnabled(Element.OverlayConfiguration.Enabled);
cameraView.SelectionOverlayController.SetBarcodeHighlightedDelegate(this);
cameraView.SelectionOverlayController.SetBarcodeAppearanceDelegate(this);

if (resultHandler != null)
{
resultHandler.Success -= OnBarcodeResult;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Native.Renderers.Example.Forms.iOS.Utils;
using ScanbotSDK.iOS;
using ScanbotSDK.Xamarin.Forms;

namespace Native.Renderers.Example.Forms.iOS
{
// Since we cannot directly inherit from SBSDKBarcodeScannerViewControllerDelegate in our ViewRenderer,
// we have created this wrapper class to allow binding to its events through the use of delegates
class BarcodeScannerDelegate : SBSDKBarcodeScannerViewControllerDelegate
{
internal bool isScanning = true;
public delegate void OnDetectHandler(SBSDKBarcodeScannerResult[] codes);
public OnDetectHandler OnDetect;

public override void DidDetectBarcodes(SBSDKBarcodeScannerViewController controller, SBSDKBarcodeScannerResult[] codes)
{
if (controller.BarcodeImageGenerationType == SBSDKBarcodeImageGenerationType.CapturedImage)
{
isScanning = false; // it will restrict further scans and stop scanning when the image is captured.
}
OnDetect?.Invoke(codes);
}

public override bool ShouldDetectBarcodes(SBSDKBarcodeScannerViewController controller)
{
if (!SBSDK.IsLicenseValid)
{
ViewUtils.ShowAlert("License Expired!", "Ok");
return false;
}

return isScanning;
}
}

internal class BarcodeTrackingOverlayDelegate : SBSDKBarcodeTrackingOverlayControllerDelegate
{
public delegate void DidTapOnBarcodeAROverlay(SBSDKBarcodeScannerResult barcode);
public DidTapOnBarcodeAROverlay DidTapBarcodeOverlay;

public override void DidTapOnBarcode(SBSDKBarcodeTrackingOverlayController controller, SBSDKBarcodeScannerResult barcode)
{
DidTapBarcodeOverlay?.Invoke(barcode);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
<None Include="Info.plist" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Renderers\IOSBarcodeCameraRenderer.cs" />
<Compile Include="Renderers\Extensions.cs" />
<Compile Include="Delegates\BarcodeScannerDelegates.cs" />
<Compile Include="Utils\ViewUtils.cs" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="Resources\LaunchScreen.storyboard" />
Expand Down Expand Up @@ -135,12 +138,14 @@
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2612" />
<PackageReference Include="ScanbotSDK.Xamarin.Forms">
<Version>3.10.2</Version>
<Version>4.2.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>
<Folder Include="Renderers\" />
<Folder Include="Utils\" />
<Folder Include="Delegates\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Native.Renderers.Example.Forms\Native.Renderers.Example.Forms.csproj">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Foundation;
using ScanbotSDK.iOS;

namespace Native.Renderers.Example.Forms.iOS.Renderers
{
// Since we cannot directly inherit from SBSDKBarcodeScannerViewControllerDelegate in our ViewRenderer,
// we have created this wrapper class to allow binding to its events through the use of delegates
class BarcodeScannerDelegate : SBSDKBarcodeScannerViewControllerDelegate
{
internal bool isScanning = true;
public delegate void OnDetectHandler(SBSDKBarcodeScannerResult[] codes);
public OnDetectHandler OnDetect;

public override void DidDetectBarcodes(SBSDKBarcodeScannerViewController controller, SBSDKBarcodeScannerResult[] codes)
{
if (controller.BarcodeImageGenerationType == SBSDKBarcodeImageGenerationType.CapturedImage)
{
isScanning = false; // it will restrict further scans and stop scanning when the image is captured.
}
OnDetect?.Invoke(codes);
}

public override bool ShouldDetectBarcodes(SBSDKBarcodeScannerViewController controller)
{
return isScanning;
}
}

class BarcodeTrackingOverlayDelegate : SBSDKBarcodeTrackingOverlayControllerDelegate
{
public delegate void DidTapOnBarcodeAROverlay(SBSDKBarcodeScannerResult barcode);
public DidTapOnBarcodeAROverlay DidTapBarcodeOverlay;

[Export("barcodeTrackingOverlay:didTapOnBarcode:")]
public override void DidTapOnBarcode(SBSDKBarcodeTrackingOverlayController controller, SBSDKBarcodeScannerResult barcode)
{
DidTapBarcodeOverlay?.Invoke(barcode);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using ScanbotSDK.iOS;
using ScanbotSDK.Xamarin.Forms;

namespace Native.Renderers.Example.Forms.iOS.Renderers
{
public static class Extension
{
public static SBSDKBarcodeOverlayFormat ToNative(this OverlayFormat overlayTextFormat)
{
switch (overlayTextFormat)
{
case OverlayFormat.None:
return SBSDKBarcodeOverlayFormat.None;
case OverlayFormat.Code:
return SBSDKBarcodeOverlayFormat.Code;
default:
return SBSDKBarcodeOverlayFormat.CodeAndType;
}
}

public static SBSDKBarcodeImageGenerationType ToNative(this BarcodeImageGenerationType imageGenerationType)
{
switch (imageGenerationType)
{
case BarcodeImageGenerationType.None:
return SBSDKBarcodeImageGenerationType.None;
case BarcodeImageGenerationType.CapturedImage:
return SBSDKBarcodeImageGenerationType.CapturedImage;
case BarcodeImageGenerationType.FromVideoFrame:
return SBSDKBarcodeImageGenerationType.FromVideoFrame;
default:
return SBSDKBarcodeImageGenerationType.None;
}
}
}
}
Loading

0 comments on commit d7af58c

Please sign in to comment.