Esempio n. 1
0
        public ZXingScanOverlay(ZXingScanOverlayOptions options = null)
        {
            Options = options ?? new ZXingScanOverlayOptions();

            RowSpacing    = 0;
            ColumnSpacing = 0;

            VerticalOptions   = FillAndExpand;
            HorizontalOptions = FillAndExpand;

            RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            RowDefinitions.Add(new RowDefinition {
                Height = Options.ScanHeight
            });
            RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            ColumnDefinitions.Add(new ColumnDefinition {
                Width = Options.ScanWidth
            });
            ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });

            AddScreenArea();

            AddCenterArea();


            SetRow(Options.TopLabel, 0);
            SetColumnSpan(Options.TopLabel, 3);
            Children.Add(Options.TopLabel);


            SetRow(Options.BottomLabel, 2);
            SetColumnSpan(Options.BottomLabel, 3);
            Children.Add(Options.BottomLabel);



            var tapGestureRecognizer = new TapGestureRecognizer();

            tapGestureRecognizer.Tapped += (sender, e) =>
            {
                Options.FlashTappedAction?.Invoke();
            };
            Options.FlashLabel.GestureRecognizers.Add(tapGestureRecognizer);

            if (Options.ShowFlash)
            {
                Children.Add(Options.FlashLabel, 2, 2);
            }
        }
        private async void CustomScanBarCodeBtn_OnClicked(object sender, EventArgs e)
        {
            if (await CheckPerssion())
            {
                var options = new ZXingScanOverlayOptions()
                {
                    ScanColor = Color.Green,
                    ShowFlash = true
                };
                var overlay = new ZXingScanOverlay(options);
                var csPage  = new ZXingCustomScanPage(overlay);

                csPage.OnScanResult = (result) =>
                {
                    if (null != result)
                    {
                        CustomScanResult.Text = result.Text;
                    }
                };

                await Navigation.PushModalAsync(csPage);
            }
        }