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)
                                  => OnScanResult?.Invoke(result);

            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;
        }
Example #2
0
        public ZXingCustomScanPage(ZXingScanOverlay overlay = null) : base()
        {
            _overlay = overlay ?? new ZXingScanOverlay();

            Title = "扫一扫";

            _zxing = new ZXingScannerView
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                AutomationId      = "zxingScannerView",
            };

            // 返回结果
            _zxing.OnScanResult += (result) =>
                                   Device.BeginInvokeOnMainThread(async() =>
            {
                _zxing.IsAnalyzing = false;

                await Navigation.PopModalAsync();    //安卓可能报错

                OnScanResult?.Invoke(result);
            });

            // 闪光灯
            _overlay.Options.FlashTappedAction = () =>
            {
                _zxing.IsTorchOn = !_zxing.IsTorchOn;
            };

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

            grid.Children.Add(_zxing);
            grid.Children.Add(_overlay);

            Content = grid;
        }
Example #3
0
 public void RaiseScanResult(Result result)
 {
     Result = result;
     OnScanResult?.Invoke(Result);
     ScanResultCommand?.Execute(Result);
 }
Example #4
0
 public void OnTagRead(NfcManager nfcManager, string content)
 {
     OnScanResult.Invoke(content);
 }
Example #5
0
 private void OnTagReadDataResult(string data)
 {
     OnScanResult.Invoke(data);
 }