From 55c034ae4effb94144909aa55c82b697a57e1bb7 Mon Sep 17 00:00:00 2001 From: tom Date: Wed, 16 May 2018 20:41:38 +0800 Subject: [PATCH] BUGFIX - Forms Android SurfaceView when IsScanning is set to False the camera is disabled but never enabled when IsScanning is to True updated sample Forms to include buttons to turn off camera and then on as described in documentation by using IsScanning --- Samples/Forms/Core/CustomScanPage.cs | 36 ++++++++++++++++++- .../ZXingSurfaceView.cs | 1 + 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Samples/Forms/Core/CustomScanPage.cs b/Samples/Forms/Core/CustomScanPage.cs index d7f990cc6..0476b3705 100644 --- a/Samples/Forms/Core/CustomScanPage.cs +++ b/Samples/Forms/Core/CustomScanPage.cs @@ -31,7 +31,7 @@ public CustomScanPage () : base () await DisplayAlert ("Scanned Barcode", result.Text, "OK"); // Navigate away - await Navigation.PopAsync (); + //await Navigation.PopAsync (); }); overlay = new ZXingDefaultOverlay @@ -49,8 +49,42 @@ public CustomScanPage () : base () VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, }; + + var stopButton = new Button + { + WidthRequest = 100, + HeightRequest = 50, + HorizontalOptions = LayoutOptions.Start, + VerticalOptions = LayoutOptions.End, + Text = "disable", + Command = new Command(() => zxing.IsScanning=false) + }; + + var cancelButton = new Button + { + WidthRequest = 100, + HeightRequest = 50, + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.End, + Text = "cancel", + Command = new Command(async () => await Navigation.PopAsync()) + }; + + var startButton = new Button + { + WidthRequest = 100, + HeightRequest = 50, + HorizontalOptions = LayoutOptions.End, + VerticalOptions = LayoutOptions.End, + Text = "enable", + Command = new Command(() => zxing.IsScanning = true) + }; + grid.Children.Add(zxing); grid.Children.Add(overlay); + grid.Children.Add(startButton); + grid.Children.Add(cancelButton); + grid.Children.Add(stopButton); // The root page of your application Content = grid; diff --git a/Source/ZXing.Net.Mobile.Android/ZXingSurfaceView.cs b/Source/ZXing.Net.Mobile.Android/ZXingSurfaceView.cs index 6e4130a04..1f16f2766 100644 --- a/Source/ZXing.Net.Mobile.Android/ZXingSurfaceView.cs +++ b/Source/ZXing.Net.Mobile.Android/ZXingSurfaceView.cs @@ -98,6 +98,7 @@ public void AutoFocus(int x, int y) public void StartScanning(Action scanResultCallback, MobileBarcodeScanningOptions options = null) { + _cameraAnalyzer.SetupCamera(); ScanningOptions = options ?? MobileBarcodeScanningOptions.Default; _cameraAnalyzer.BarcodeFound += (sender, result) =>