public void AutoFocus()
 {
     if (zxing != null)
     {
         zxing.AutoFocus();
     }
 }
예제 #2
0
        public QrScan()
        {
            InitializeComponent();

            zxing = new ZXingScannerView
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };

            zxing.AutoFocus();

            zxing.OnScanResult += (result) =>
                                  Device.BeginInvokeOnMainThread(async() =>
            {
                // Остановить анализ пока мы не вернемся на страницу
                zxing.IsAnalyzing = false;

                if (result.Text != null)
                {
                    if (RoomData.isThatRoom(result.Text) != null)
                    {
                        // если помещение с имянем на QR есть в системе - открыть его страницу
                        await Shell.Current.GoToAsync($"roomdetails?name={result.Text}"); zxing.IsAnalyzing = true;
                    }
                    else
                    {
                        // иначе вывести содержимое кода
                        await DisplayAlert("Информация с кода: ", result.Text, "OK"); zxing.IsAnalyzing = true;
                    }
                }

                zxing.IsAnalyzing = true;
            });

            overlay = new ZXingDefaultOverlay
            {
                TopText         = "Поднесите телефон к штрих-коду",
                BottomText      = "Сканирование произойдет автоматически",
                ShowFlashButton = zxing.HasTorch,
            };
            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);

            Content = grid;
        }
예제 #3
0
        public ScanPage()
        {
            InitializeComponent();

            var tapGestureRecognizer = new TapGestureRecognizer();

            tapGestureRecognizer.Tapped += (s, e) =>
            {
                try
                {
                    MasterDetailPage ParentPage = (MasterDetailPage)this.Parent;
                    ParentPage.IsPresented = (ParentPage.IsPresented == false) ? true : false;
                }
                catch (Exception ex)
                {
                    var msg = ex.Message;
                }
            };
            img.GestureRecognizers.Add(tapGestureRecognizer);



            #region BarCode
            QRCodeScanner = new ZXingScannerView()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
            };
            QRCodeScanner.AutoFocus();
            QRCodeScanner.OnScanResult += ScanResult;

            Scanneroverlay = new ZXingDefaultOverlay
            {
                //TopText = "Scan BarCode.",
                //BackgroundColor = Color.Transparent
            };
            Grid gridScannerBody = new Grid
            {
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            gridScannerBody.Children.Add(QRCodeScanner);
            gridScannerBody.Children.Add(Scanneroverlay);
            #endregion

            ScannerStack.Children.Add(gridScannerBody);
        }
예제 #4
0
        public void ScanAsync()
        {
            scanner = new ZXingScannerView();
            MobileBarcodeScanningOptions scanningOptions = new MobileBarcodeScanningOptions
            {
                UseNativeScanning         = true,
                UseFrontCameraIfAvailable = true,
                PossibleFormats           = new List <BarcodeFormat>(),
                TryHarder  = true,
                AutoRotate = false,
            };

            scanner.Options = scanningOptions;
            scanner.Options.PossibleFormats.Add(BarcodeFormat.QR_CODE);
            scanner.Options.PossibleFormats.Add(BarcodeFormat.DATA_MATRIX);
            scanner.Options.PossibleFormats.Add(BarcodeFormat.EAN_13);

            scanner.OnScanResult += (result) => {
                scanner.IsScanning = false;
                if (scanner.IsScanning)
                {
                    scanner.AutoFocus();
                }

                Device.BeginInvokeOnMainThread(async() => {
                    if (result != null)
                    {
                        bool scanOK = await DisplayAlert("Полученное изделие", result.Text, "OK", "Cancel");
                        if (scanOK)
                        {
                            await Navigation.PopAsync();
                        }
                        else
                        {
                            scanner.Result = null;
                            await Navigation.PopAsync();
                        };
                    }
                });
            };
        }
예제 #5
0
        public ScanPage(BottomTabbedPage tabbedContext)
        {
            InitializeComponent();

            _tabbedContext = tabbedContext;

            zxing = new ZXingScannerView
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };
            zxing.IsAnalyzing = true;
            zxing.IsScanning  = true;
            zxing.Options.PossibleFormats.Add(BarcodeFormat.QR_CODE);
            zxing.Options.PossibleFormats.Add(BarcodeFormat.DATA_MATRIX);
            zxing.Options.PossibleFormats.Add(BarcodeFormat.EAN_13);
            zxing.AutoFocus();
            zxing.OnScanResult += OnScan;

            overlay = new ZXingDefaultOverlay
            {
                TopText         = "Hold your phone up to the QR code",
                BottomText      = "Scanning will happen automatically",
                ShowFlashButton = zxing.HasTorch,
            };
            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);

            Content  = grid;
            _message = DependencyService.Get <IMessage>();
        }
예제 #6
0
        private async void scanView_OnScanResult(ZXing.Result result)
        {
            scanner.Options = new MobileBarcodeScanningOptions()
            {
                UseFrontCameraIfAvailable = false, //update later to come from settings
                PossibleFormats           = new List <BarcodeFormat>(),
                TryHarder   = true,
                AutoRotate  = false,
                TryInverted = true,
                DelayBetweenContinuousScans = 2000
            };

            scanner.IsVisible = false;
            scanner.Options.PossibleFormats.Add(BarcodeFormat.QR_CODE);
            scanner.Options.PossibleFormats.Add(BarcodeFormat.DATA_MATRIX);
            scanner.Options.PossibleFormats.Add(BarcodeFormat.EAN_13);

            if (scanner.IsScanning)
            {
                scanner.AutoFocus();
            }

            try
            {
                if (string.IsNullOrEmpty(Preferences.Get(App.USERSIGNEDINKEY, string.Empty)))
                {
                    await Navigation.PushModalAsync(new LoginPage());

                    return;
                }

                Device.BeginInvokeOnMainThread(async() =>
                {
                    var res = await ApiServices.MarkAttendance(Preferences.Get("userId", string.Empty), result.Text);

                    if (res == null)
                    {
                        //await DisplayAlert("", "You have already marked the attendance", "Alright");
                        MessageDialog.Show("", "Your record is not fond in this church", "Cancel");
                    }
                    else
                    {
                        if (res.status)
                        {
                            await PopupNavigation.PushAsync(new MarkPopup());

                            await PopupNavigation.PopAsync();
                            // await DisplayAlert("", res.message, "Alright");
                        }
                        else
                        {
                            await DisplayAlert("", res.message, "Cancel");
                        }
                    }

                    await Navigation.PopAsync();
                    // await DisplayAlert("Scanned result", "The barcode's text is " + result.Text + ". The barcode's format is " + result.BarcodeFormat, "OK");
                });
            }
            catch
            {
                await DisplayAlert("", "You have already marked the attendance", "Alright");
            }
        }
예제 #7
0
        private void InitializeQr()
        {
            _scannerView = new ZXingScannerView
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                AutomationId      = "zxingScannerView",
            };

            _scannerView.AutoFocus();

            _scannerView.OnScanResult += (result) =>
                                         Device.BeginInvokeOnMainThread(async() =>
            {
                await ProcessQr(result.Text);
            });

            var overlay = new Grid {
                AutomationId = "zxingDefaultOverlay"
            };

            overlay.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });                                                                                             //0
            overlay.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });                                                                                             //1
            overlay.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });                                                                                             //2
            overlay.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });                                                                                             //3
            overlay.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });                                                                                             //4
            overlay.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });                                                                                                  //0
            overlay.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });                                                                                                  //1
            overlay.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });                                                                                                  //2
            overlay.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });                                                                                                  //3
            overlay.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });                                                                                                  //4

            Image imageButton = new Image
            {
                Source            = "backscanner.png",
                Aspect            = Aspect.AspectFit,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Transparent,
            };

            var back = new Button
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Transparent,
            };

            back.Clicked += OnBackButtonClicked;
            overlay.Children.Add(imageButton, 2, 4);
            overlay.Children.Add(back, 2, 4);

            Image scannerImage = new Image
            {
                Source            = "scannerhud.png",
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                Aspect            = Aspect.Fill,
            };

            overlay.Children.Add(scannerImage, 0, 0);
            Grid.SetColumnSpan(scannerImage, 5);
            Grid.SetRowSpan(scannerImage, 4);

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

            grid.Children.Add(_scannerView);
            grid.Children.Add(overlay);

            Content = grid;
        }
예제 #8
0
        private async void LoadLectorQR()
        {
            if (isLoadLectorQR)
            {
                return;
            }

            isLoadLectorQR = true;

            await MainViewModel.GetInstace().CollectViewModel.ShowDialog();

            bool statePermission = await Permissions.GetPermissions(Permission.Camera);

            if (statePermission)
            {
                try
                {
                    await Task.Delay(1000);

                    scanner = new ZXingScannerView
                    {
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        VerticalOptions   = LayoutOptions.FillAndExpand,
                        Options           = new MobileBarcodeScanningOptions()
                        {
                            PossibleFormats = new List <ZXing.BarcodeFormat>
                            {
                                ZXing.BarcodeFormat.QR_CODE,
                            },
                            DelayBetweenContinuousScans = 2000
                        },
                    };
                    scanner.OnScanResult += (result) =>
                    {
                        scanner.IsAnalyzing = false;
                        if (scanner.IsScanning)
                        {
                            scanner.AutoFocus();
                        }

                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            await MainViewModel.GetInstace().CollectViewModel.ProcessTransaction(result.Text);
                            scanner.IsAnalyzing = true;
                        });
                    };

                    MainPageContainer.Children.Add(scanner);

                    scanner.IsEnabled   = true;
                    scanner.IsAnalyzing = true;
                    scanner.IsScanning  = true;
                }
                catch (Exception ex)
                {
                    ServiceBackgroundWorker.GetInstance().SendExceptionWorker(ex.ToString());
                }
            }
            isFirstTimeOnLoad = false;
            await MainViewModel.GetInstace().CollectViewModel.CloseDialog();

            isLoadLectorQR = false;
        }