Inheritance: Xamarin.Forms.View
Beispiel #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <ZXingScannerView> e)
        {
            AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;

            formsView = Element;

            if (zxingView == null)
            {
                // Process requests for autofocus
                formsView.AutoFocusRequested += (x, y) => {
                    if (zxingView != null)
                    {
                        if (x < 0 && y < 0)
                        {
                            zxingView.AutoFocus();
                        }
                        else
                        {
                            zxingView.AutoFocus(x, y);
                        }
                    }
                };


                zxingView = new iOSZXing.ZXingScannerView();
                zxingView.UseCustomOverlayView = true;
                zxingView.AutoresizingMask     = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;

                base.SetNativeControl(zxingView);

                if (formsView.IsScanning)
                {
                    zxingView.StartScanning(formsView.RaiseScanResult, formsView.Options);
                }

                if (!formsView.IsAnalyzing)
                {
                    zxingView.PauseAnalysis();
                }

                if (formsView.IsTorchOn)
                {
                    zxingView.Torch(formsView.IsTorchOn);
                }
            }

            base.OnElementChanged(e);
        }
        public CustomScanPage () : base ()
        {
            zxing = new ZXingScannerView
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                AutomationId = "zxingScannerView",
            };
            zxing.OnScanResult += (result) => 
                Device.BeginInvokeOnMainThread (async () => {

                    // Stop analysis until we navigate away so we don't keep reading barcodes
                    zxing.IsAnalyzing = false;

                    // Show an alert
                    await DisplayAlert ("Scanned Barcode", result.Text, "OK");

                    // Navigate away
                    await Navigation.PopAsync ();
                });

            overlay = new ZXingDefaultOverlay
            {
                TopText = "Hold your phone up to the barcode",
                BottomText = "Scanning will happen automatically",
                ShowFlashButton = zxing.HasTorch,
                AutomationId = "zxingDefaultOverlay",
            };
            overlay.FlashButtonClicked += (sender, e) => {
                zxing.IsTorchOn = !zxing.IsTorchOn;
            };
            var grid = new Grid
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            grid.Children.Add(zxing);
            grid.Children.Add(overlay);

            // The root page of your application
            Content = grid;
        }
Beispiel #3
0
        public ZXingScannerPage(MobileBarcodeScanningOptions options = null, View customOverlay = null) : base()
        {
            zxing = new ZXingScannerView
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                Options           = options,
                AutomationId      = "zxingScannerView"
            };

            zxing.SetBinding(ZXingScannerView.IsTorchOnProperty, new Binding(nameof(IsTorchOn)));
            zxing.SetBinding(ZXingScannerView.IsAnalyzingProperty, new Binding(nameof(IsAnalyzing)));
            zxing.SetBinding(ZXingScannerView.IsScanningProperty, new Binding(nameof(IsScanning)));
            zxing.SetBinding(ZXingScannerView.HasTorchProperty, new Binding(nameof(HasTorch)));
            zxing.SetBinding(ZXingScannerView.ResultProperty, new Binding(nameof(Result)));

            zxing.OnScanResult += (result) =>
            {
                this.OnScanResult?.Invoke(result);
                //Device.BeginInvokeOnMainThread (() => eh (result));
            };

            zxing.OnTakePicture += OnTakePicture;
            if (customOverlay == null)
            {
                defaultOverlay = new ZXingDefaultOverlay()
                {
                    AutomationId = "zxingDefaultOverlay"
                };

                defaultOverlay.SetBinding(ZXingDefaultOverlay.TopTextProperty, new Binding(nameof(DefaultOverlayTopText)));
                defaultOverlay.SetBinding(ZXingDefaultOverlay.BottomTextProperty, new Binding(nameof(DefaultOverlayBottomText)));
                defaultOverlay.SetBinding(ZXingDefaultOverlay.ShowFlashButtonProperty, new Binding(nameof(DefaultOverlayShowFlashButton)));

                DefaultOverlayTopText         = "Hold your phone up to the barcode";
                DefaultOverlayBottomText      = "Scanning will happen automatically";
                DefaultOverlayShowFlashButton = HasTorch;

                defaultOverlay.FlashButtonClicked += (sender, e) =>
                {
                    zxing.IsTorchOn = !zxing.IsTorchOn;
                };

                Overlay = defaultOverlay;
            }
            else
            {
                Overlay = customOverlay;
            }

            var grid = new Grid
            {
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };

            grid.Children.Add(zxing);
            grid.Children.Add(Overlay);

            // The root page of your application
            Content = grid;
        }