From ec2e08f19e5fe2309fbaa87dc63504af07014bac Mon Sep 17 00:00:00 2001 From: scottm Date: Mon, 20 Apr 2020 14:47:47 -0400 Subject: [PATCH] Add support for reducing the scanning area to the bounds of a specific View. Many users need to scan barcodes that are close together. This update allows those barcodes to be easily scanned. Add additional logic to Sample.Android project to demonstrate new capability. --- .../FragmentActivityCustomScanArea.cs | 317 ++++++++++++++++++ Samples/Sample.Android/MainActivity.cs | 261 +++++++++++++- .../Resources/drawable/magnify_minus.png | Bin 0 -> 829 bytes .../Resources/drawable/magnify_plus.png | Bin 0 -> 824 bytes .../Resources/drawable/scanborder.xml | 4 + .../Sample.Android/Resources/layout/Main.axml | 16 +- .../layout/ZxingOverlayCustomScanArea.xml | 119 +++++++ .../Resources/values/colors.xml | 7 + Samples/Sample.Android/Sample.Android.csproj | 18 +- .../CameraAccess/CameraAnalyzer.android.cs | 233 +++++++++++-- .../CameraAccess/CameraController.android.cs | 123 ++++--- .../Android/MobileBarcodeScanner.android.cs | 4 +- .../Android/ZXingScannerFragment.android.cs | 22 +- .../Android/ZXingSurfaceView.android.cs | 13 + .../Android/ZxingActivity.android.cs | 12 +- 15 files changed, 1052 insertions(+), 97 deletions(-) create mode 100644 Samples/Sample.Android/FragmentActivityCustomScanArea.cs create mode 100644 Samples/Sample.Android/Resources/drawable/magnify_minus.png create mode 100644 Samples/Sample.Android/Resources/drawable/magnify_plus.png create mode 100644 Samples/Sample.Android/Resources/drawable/scanborder.xml create mode 100644 Samples/Sample.Android/Resources/layout/ZxingOverlayCustomScanArea.xml create mode 100644 Samples/Sample.Android/Resources/values/colors.xml diff --git a/Samples/Sample.Android/FragmentActivityCustomScanArea.cs b/Samples/Sample.Android/FragmentActivityCustomScanArea.cs new file mode 100644 index 000000000..322c0f4b3 --- /dev/null +++ b/Samples/Sample.Android/FragmentActivityCustomScanArea.cs @@ -0,0 +1,317 @@ +using System; +using System.Collections.Generic; +using ZXing.Mobile; +using Android.OS; + +using Android.App; +using Android.Widget; +using Android.Content.PM; +using Android.Views; +using Xamarin.Essentials; +using Android.Content; +using AndroidX.ConstraintLayout.Widget; + +namespace Sample.Android +{ + [Activity(Label = "ZXing.Net.Mobile", Theme = "@style/Theme.AppCompat.Light", ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden)] + public class FragmentActivityCustomScanArea : AndroidX.Fragment.App.FragmentActivity + { + ZXingScannerFragment scanFragment; + Button buttonRectangle; + Button buttonSquare; + Button buttonRandom; + ImageButton buttonIncrease; + ImageButton buttonDecrease; + ToggleButton scanViewPosition; + View scanArea; + bool scanAreaIsRectangle = true; + bool isScanAreaCentered = false; + + protected override void OnCreate (Bundle savedInstanceState) + { + base.OnCreate (savedInstanceState); + + SetContentView (Resource.Layout.FragmentActivity); + + } + + protected override void OnResume () + { + base.OnResume (); + + + if (scanFragment == null) + { + var zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.ZxingOverlayCustomScanArea, null); + scanArea = zxingOverlay.FindViewById(Resource.Id.scanView); + + //Find all the buttons and wire up their events + buttonRectangle = zxingOverlay.FindViewById