コード例 #1
0
        async void btnEscanear_Clicked(object sender, EventArgs e)
        {
            var scann = new ZXingBarcodeImageView();
            //setup options
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions
            {
                AutoRotate = false,
                UseFrontCameraIfAvailable = false,
                TryHarder         = true,
                UseNativeScanning = true,
            };



            var pagina = new ZXingScannerPage();

            pagina.AutoFocus();
            pagina.Title = "Escaneando codigo de barra";

            await Navigation.PushAsync(pagina);

            pagina.OnScanResult += (resultado) =>
            {
                pagina.IsScanning = false;

                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopAsync();
                    lblResultado.Text = resultado.Text;
                });
            };
        }
コード例 #2
0
        private void ScanQR()
        {
            scanPage = new ZXingScannerPage();
            //scanPage.Options.PossibleFormats.Add(BarcodeFormat.QR_CODE);
            scanPage.OnScanResult += (result) =>
            {
                if (scanPage.IsScanning)
                {
                    scanPage.AutoFocus();
                }

                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopModalAsync();
                    if (result != null)
                    {
                        await DisplayAlert("Scanned QR code", result.Text, "OK");
                        MessagingCenter.Instance.Send(this, "MessageModel", new MessageModel {
                            Data = result.Text
                        });
                    }
                });
            };
            Navigation.PushModalAsync(scanPage);
        }
コード例 #3
0
        private async void _ScanBarcode()
        {
            var scanPage = new ZXingScannerPage();

            scanPage.IsScanning = true;
            scanPage.AutoFocus();

            // Navigate to our scanner page
            await Navigation.PushAsync(scanPage);

            //NavigationPage.SetHasNavigationBar(scanPage, false);

            scanPage.OnScanResult += (result) =>
            {
                // Stop scanning
                scanPage.IsScanning = false;
                // Pop the page and show the result
                Device.BeginInvokeOnMainThread(async() =>
                {
                    iau.PlayWavSuccess();
                    await Navigation.PopAsync();
                    await DisplayAlert("Scanned Barcode", result.Text, "OK");
                });
            };
        }
コード例 #4
0
 //For QR camera scanning focus (most cameras don't need this as their own autofocus suffices)
 public void ScannerFocus()
 {
     while (ScannerPage.Result == null)
     {
         Thread.Sleep(2000);
         ScannerPage.AutoFocus();
     }
 }
コード例 #5
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            var option = new ZXing.Mobile.MobileBarcodeScanningOptions();

            option.AutoRotate      = true;
            option.PossibleFormats = new List <ZXing.BarcodeFormat>()
            {
                ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13, ZXing.BarcodeFormat.CODE_128
            };
            var scanPage = new ZXingScannerPage(option);

            scanPage.HeightRequest = 300;
            scanPage.WidthRequest  = 200;

            scanPage.OnScanResult += (result) =>
            {
                // Stop scanning
                scanPage.IsScanning = false;
                if (scanPage.IsScanning)
                {
                    scanPage.AutoFocus();
                }

                // Pop the page and show the result
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopAsync();
                    // await DisplayAlert("Scanned Barcode", result.Text, "OK");
                    try
                    {
                        var data = result.Text.Split(';');
                        if (data.Length > 0)
                        {
                            var context    = BindingContext as TracingViewModel;
                            var resultData = await context.Find(data[0], data[1]);
                            if (result != null)
                            {
                                await Navigation.PushAsync(new TrackingDetail(resultData));
                            }
                        }
                        else
                        {
                            throw new SystemException("Ulangi Scan QR Code");
                        }
                    }
                    catch (Exception ex)
                    {
                        await DisplayAlert("Error", ex.Message, "OK");
                    }
                });
            };
            // Navigate to our scanner page
            await Navigation.PushAsync(scanPage);
        }
コード例 #6
0
        public async void ButtonScanClick(object sender, EventArgs e)
        {
            scanPage = new ZXingScannerPage();
            scanPage.AutoFocus();
            scanPage.OnScanResult += (result) =>
            {
                scanPage.IsScanning = false;
                Device.BeginInvokeOnMainThread(() =>
                {
                    Navigation.PopAsync();
                    entry.Text = result.Text;
                    scanPage   = null;
                });
            };

            await Navigation.PushAsync(scanPage);
        }
コード例 #7
0
        async void btnEscanear_Clicked(object sender, EventArgs e)
        {
            var scann = new ZXingBarcodeImageView();
            //setup options
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions
            {
                AutoRotate = false,
                UseFrontCameraIfAvailable = false,
                TryHarder         = true,
                UseNativeScanning = true,
                //PossibleFormats = new List<ZXing.BarcodeFormat>
                //        {
                //            ZXing.BarcodeFormat.CODABAR,
                //           ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13
                //        }
            };



            var pagina = new ZXingScannerPage();

            pagina.AutoFocus();
            //pagina.ToggleTorch();
            //pagina.IsTorchOn = true;
            //pagina.DefaultOverlayShowFlashButton = true;
            pagina.Title = "Escaneando codigo de barra";

            await Navigation.PushAsync(pagina);

            pagina.OnScanResult += (resultado) =>
            {
                pagina.IsScanning = false;

                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopAsync();
                    lblResultado.Text = resultado.Text;
                });
            };
        }
コード例 #8
0
        private async void ToolbarItem_Clicked_1(object sender, EventArgs e)
        {
            var opts = new ZXing.Mobile.MobileBarcodeScanningOptions
            {
                PossibleFormats = new List <ZXing.BarcodeFormat> {
                    ZXing.BarcodeFormat.QR_CODE, ZXing.BarcodeFormat.ITF,
                    ZXing.BarcodeFormat.All_1D, ZXing.BarcodeFormat.EAN_13, ZXing.BarcodeFormat.CODE_39, ZXing.BarcodeFormat.CODE_128,
                    ZXing.BarcodeFormat.PDF_417, ZXing.BarcodeFormat.UPC_EAN_EXTENSION
                }
            };

            opts.TryHarder         = false;
            opts.UseNativeScanning = true;
            var barcodeReader = opts.BuildBarcodeReader();

            barcodeReader.Options.AllowedLengths = new[] { 44 };
            barcodeReader.AutoRotate             = false;


            ZXingScannerPage scanPage = new ZXingScannerPage(opts);

            scanPage.HasTorch   = true;
            scanPage.IsScanning = false;

            scanPage.AutoFocus();

            scanPage.OnScanResult += (result) =>
            {
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopAsync();
                    vm.commessa = result.Text.Trim();
                    await vm.searchForCommessaOrTarga();
                });
            };

            await Navigation.PushAsync(scanPage);
        }
コード例 #9
0
        private void AbrirPaginaEscaner(View arg1, object arg2)
        {
            _escanearCodigo.Opacity = 0.5f;
            Device.StartTimer(TimeSpan.FromMilliseconds(300), () =>
            {
                var paginaEscaner = new ZXingScannerPage();

                paginaEscaner.OnScanResult += (result) =>
                {
                    // Detiene el escaner
                    paginaEscaner.IsScanning = false;

                    //Hace autofoco, particularmente para los códigos de barra
                    var ts = new TimeSpan(0, 0, 0, 3, 0);
                    Device.StartTimer(ts, () =>
                    {
                        if (paginaEscaner.IsScanning)
                        {
                            paginaEscaner.AutoFocus();
                        }
                        return(true);
                    });

                    // Cierra la página del escaner y llama a la página del producto
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Navigation.PopModalAsync();
                        IrAlProducto(result.Text);
                    });
                };

                // Abre la página del escaner
                Navigation.PushModalAsync(paginaEscaner);

                _escanearCodigo.Opacity = 1f;
                return(false);
            });
        }
コード例 #10
0
        async void Handle_Tapped(object sender, System.EventArgs e)
        {
            try
            {
                var scanPage = new ZXingScannerPage();
                scanPage.AutoFocus();
                await Navigation.PushAsync(scanPage);

                scanPage.OnScanResult += (result) =>
                {
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        await Navigation.PopAsync();

                        searchBar.Text = result.Text;
                    });
                };
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", ex.Message, "OK");
            }
        }
コード例 #11
0
        private void AbrirPaginaEscaner(object sender, EventArgs args)
        {
            BotonEscaner.BackgroundColor = Color.FromHex("#FB9F0B");
            Device.StartTimer(TimeSpan.FromMilliseconds(200), () =>
            {
                var paginaEscaner = new ZXingScannerPage();

                paginaEscaner.OnScanResult += (result) =>
                {
                    // Detiene el escaner
                    paginaEscaner.IsScanning = false;

                    //Hace autofoco, particularmente para los códigos de barra
                    var ts = new TimeSpan(0, 0, 0, 3, 0);
                    Device.StartTimer(ts, () =>
                    {
                        if (paginaEscaner.IsScanning)
                        {
                            paginaEscaner.AutoFocus();
                        }
                        return(true);
                    });

                    // Cierra la página del escaner y llama a la página del producto
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Navigation.PopModalAsync();
                        IrAlProducto(result.Text);
                    });
                };

                // Abre la página del escaner
                Navigation.PushModalAsync(paginaEscaner);
                BotonEscaner.BackgroundColor = Color.FromHex("#FD8A18");
                return(false);
            });
        }
コード例 #12
0
      private async void ShowScanner()
      {
          var scanner = new ZXing.Mobile.MobileBarcodeScanner
          {
              FlashButtonText  = "Flash",
              UseCustomOverlay = false,
              CancelButtonText = "Cancel"
          };
          var overlay = new ZXingDefaultOverlay
          {
              TopText         = string.Empty,
              BottomText      = string.Empty,
              ShowFlashButton = _flash,
          };

          var options = new ZXing.Mobile.MobileBarcodeScanningOptions
          {
              AutoRotate = _autorotate,
              TryHarder  = _tryHarder,

              TryInverted       = _tryInverted,
              UseNativeScanning = _NativeScanning,
              PossibleFormats   = new List <ZXing.BarcodeFormat>()
              {
                  ZXing.BarcodeFormat.QR_CODE,
                  ZXing.BarcodeFormat.AZTEC, ZXing.BarcodeFormat.CODE_128, ZXing.BarcodeFormat.CODE_39,
                  ZXing.BarcodeFormat.CODE_93, ZXing.BarcodeFormat.EAN_13, ZXing.BarcodeFormat.EAN_8,
                  ZXing.BarcodeFormat.PDF_417, ZXing.BarcodeFormat.UPC_E
              }
          };

          ScannerPage = new ZXingScannerPage(options, overlay)
          {
              DefaultOverlayShowFlashButton = true,
              HasTorch    = true,
              IsScanning  = true,
              IsAnalyzing = true,
          };

          overlay.FlashButtonClicked += (s, ed) =>
          {
              ScannerPage.ToggleTorch();
          };

          var toolbarItem = new ToolbarItem {
              Text = "Cancel"
          };

          toolbarItem.Clicked += (s, e) =>
          {
              ScannerPage.IsScanning = false;
              Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopModalAsync();
                });
          };

          try
          {
              ScannerPage.AutoFocus();
              ScannerPage.OnScanResult += (result) =>
              {
                  ScannerPage.IsScanning = false;

                  Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        await Navigation.PopModalAsync();
                        if (_scanning)
                        {
                            return;
                        }

                        _scanning = true;

                        if (DateTime.Now.Year < 2019)
                        {
                            return;
                        }

                        if (result != null)
                        {
                            ScannerPage.IsScanning = false;
                            scanResultText.Text    = result.Text;
                        }

                        _scanning = false;
                    });
              };

              var navPage = new NavigationPage(ScannerPage);
              navPage.ToolbarItems.Add(toolbarItem);

              await Navigation.PushModalAsync(navPage);
          }
          catch (Exception ex)
          {
              throw;
          }
      }
コード例 #13
0
ファイル: Scaner.cs プロジェクト: KotVezdehod/ScanBee
        public async void ScanBarcode(ContentPage Context, string ScanPurpose)
        {
            var options = new MobileBarcodeScanningOptions
            {
                AutoRotate = false,
                //PureBarcode = true,
                UseNativeScanning         = true,
                UseFrontCameraIfAvailable = true,
                TryHarder = true,
                DelayBetweenAnalyzingFrames       = Convert.ToInt32(new CommonProcs().GetProperty("ext_DelayBetweenAnalyzingFrames")),
                InitialDelayBeforeAnalyzingFrames = Convert.ToInt32(new CommonProcs().GetProperty("ext_InitialDelayBeforeAnalyzingFrames")),
                DelayBetweenContinuousScans       = Convert.ToInt32(new CommonProcs().GetProperty("ext_DelayBetweenContinuousScans")),
                PossibleFormats = new List <ZXing.BarcodeFormat>(),
            };

            SetUpBarcodeFormats(options);

            switch (ScanPurpose)
            {
            case "SettingsBarcodeScan":
                options.PossibleFormats = new List <ZXing.BarcodeFormat> {
                    ZXing.BarcodeFormat.QR_CODE
                };
                break;

            default:
                break;
            }


            var ScanPage = new ZXingScannerPage()
            {
                DefaultOverlayShowFlashButton = true,
            };

            ScanPage.OnScanResult += (result) =>
            {
                // Stop scanning
                ScanPage.IsScanning = false;
                if (Convert.ToBoolean(new CommonProcs().GetProperty("ext_Torch")) &&
                    Convert.ToInt32(new CommonProcs().GetProperty("ext_ScanHardWare")) == 1)
                {
                    if (IsTorchOn)
                    {
                        ScanPage.ToggleTorch();
                        IsTorchOn = false;
                    }
                }
                SendingNow = false;
                // Pop the page and show the result
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Context.Navigation.PopAsync();
                    new ScanSupport().BarcodeScanned(result.Text, ScanPurpose);
                });
            };

            await Context.Navigation.PushAsync(ScanPage);

            SendingNow = true;
            if (Convert.ToBoolean(new CommonProcs().GetProperty("ext_Autofocus")))
            {
                TimeSpan ts = new TimeSpan(0, 0, 0, 2, 0);
                Device.StartTimer(ts, () =>
                {
                    if (SendingNow)
                    {
                        if (!IsTorchOn)
                        {
                            if (Convert.ToBoolean(new CommonProcs().GetProperty("ext_Torch")) &&
                                Convert.ToInt32(new CommonProcs().GetProperty("ext_ScanHardWare")) == 1)
                            {
                                ScanPage.ToggleTorch();
                                IsTorchOn = true;
                            }
                        }
                        ScanPage.AutoFocus();
                    }
                    return(true);
                });
            }



            return;
        }
コード例 #14
0
        /*
         * Function:  barcodeScanner()
         * --------------------
         *  inputs: object sender, EventArgs args
         *
         *  onClick for barcode scanner button
         */
        private async void barcodeScanner(object sender, EventArgs args)
        {
            // Gets barcode data for converting part number to model number
            // Data stored locally
            var barcodeData = JsonConvert.DeserializeObject <List <Barcode> >(barcodeContent);

            // Config scanner
            var overlay = new ZXingDefaultOverlay
            {
                ShowFlashButton = false, // Show Flash button off
                // Messages shown on top and bottom of scanner
                TopText    = "Scan Part Number Barcode",
                BottomText = "Motor Controller Will Be Selected Once Scanned",
            };

            overlay.BindingContext = overlay; // Declare overlays

            // New scanner page
            var scan = new ZXingScannerPage(null, overlay);

            // Wait for scanner to return, pass it the scanner config
            await Navigation.PushAsync(scan);

            if (Device.RuntimePlatform == Device.iOS)
            {
                scan.AutoFocus(); // Autofocus if iOS
            }
            if (isLightOn == true)
            {
                scan.ToggleTorch(); // Turn torch on if user had it on before
            }

            // On return result
            scan.OnScanResult += (result) =>
            {
                // Begin on main thread
                Device.BeginInvokeOnMainThread(async() =>
                {
                    // Controller and model number result varibales declared
                    string controllerToSelect = "";
                    int scannerResult         = 0;

                    // Await scanner to return
                    await Navigation.PopAsync();

                    try
                    {
                        scannerResult = Int32.Parse(result.Text); // Set scanner result to int if possible
                    }
                    catch (FormatException)
                    {
                        // if not possible, catch error and display invalid barcode popup
                        await DisplayAlert("Invalid Barcode", "Please scan the Part Number Barcode on a Curtis Motor Controller", "OK");
                        scannerResult = 0; // Set scanner result to 0, error
                    }

                    // if result has been read
                    if (scannerResult != 0)
                    {
                        // Iterate through the data
                        for (int i = 0; i < barcodeData.Count(); i++)
                        {
                            // Check for part number
                            if (barcodeData[i].Part == scannerResult)
                            {
                                // if found, set controller to corresponding model number
                                controllerToSelect = barcodeData[i].Model;
                            }
                        }

                        // Iterate through names to find index to set picker to
                        for (int i = 0; i < names.Count(); i++)
                        {
                            // Check for name
                            if (names[i] == controllerToSelect)
                            {
                                // If found, set selectedIndex to index it was found at
                                mcPicker.SelectedIndex = i;

                                // Turn torch off when scanner is turned off and code is found
                                isLightOn = false;
                            }
                        }

                        // if picker is 0 and fault code isn't display error popup
                        if (mcPicker.SelectedIndex == 0 && controllerToSelect != names[0])
                        {
                            await DisplayAlert("Invalid Barcode", "Please scan the Part Number Barcode on a Curtis Motor Controller", "OK");
                        }
                    }
                });
            };
        }
コード例 #15
0
        private async void SkanowanieEan()
        {
            opts = new ZXing.Mobile.MobileBarcodeScanningOptions()
            {
                AutoRotate      = false,
                PossibleFormats = new List <ZXing.BarcodeFormat>()
                {
                    //ZXing.BarcodeFormat.EAN_8,
                    ZXing.BarcodeFormat.EAN_13,
                    //ZXing.BarcodeFormat.CODE_128,
                    //ZXing.BarcodeFormat.CODABAR,
                    ZXing.BarcodeFormat.CODE_39,
                },
                // CameraResolutionSelector = availableResolutions => {

                //     foreach (var ar in availableResolutions)
                //     {
                //         Console.WriteLine("Resolution: " + ar.Width + "x" + ar.Height);
                //     }
                //     return availableResolutions[0];
                // },
                //DelayBetweenContinuousScans=3000
            };

            opts.TryHarder = true;



            var torch = new Switch
            {
            };

            torch.Toggled += delegate
            {
                scanPage.ToggleTorch();
            };

            // scanPage.ToggleTorch();

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

            var Overlay = new ZXingDefaultOverlay
            {
                TopText         = "Włącz latarkę",
                BottomText      = "Skanowanie rozpocznie się automatycznie",
                ShowFlashButton = true,
                AutomationId    = "zxingDefaultOverlay",
            };



            var customOverlay = new StackLayout
            {
                HorizontalOptions = LayoutOptions.EndAndExpand,
                VerticalOptions   = LayoutOptions.EndAndExpand
            };

            //customOverlay.Children.Add(btn_Manual);

            // var scanner = new ZXing.Mobile.MobileBarcodeScanner();

            grid.Children.Add(Overlay);
            Overlay.Children.Add(torch);
            Overlay.BindingContext = Overlay;

            scanPage = new ZXingScannerPage(opts, customOverlay: Overlay)
            {
                DefaultOverlayTopText = "Zeskanuj kod ",
                //DefaultOverlayBottomText = " Skanuj kod ";
                DefaultOverlayShowFlashButton = true,
                IsTorchOn = true,  //////dodane
            };


            scanPage.OnScanResult += (result) =>
            {
                scanPage.IsScanning = false;
                scanPage.AutoFocus();
                scanPage.IsTorchOn = true; //dodane
                scanPage.HasTorch  = true; //dodane
                Device.BeginInvokeOnMainThread(() =>
                {
                    Device.StartTimer(new TimeSpan(0, 0, 0, 2), () =>
                    {
                        if (scanPage.IsScanning)
                        {
                            scanPage.AutoFocus();
                            scanPage.IsTorchOn = true;
                        }

                        return(true);
                    });
                    Navigation.PopModalAsync();
                    pobierztwrkod(result.Text);
                    entry_ilosc.Focus();
                });
            };
            await Navigation.PushModalAsync(scanPage); /////!!!!!!!


            Device.StartTimer(new TimeSpan(0, 0, 0, 2), () =>
            {
                scanPage.IsTorchOn = true;
                torch.IsToggled    = true;

                return(false);
            });
        }
コード例 #16
0
        private async void btnScan_Clicked(object sender, EventArgs e)
        {
            btnScan.IsEnabled = false;
            PermissionStatus status = await CrossPermissions.Current.CheckPermissionStatusAsync <CameraPermission>();

            if (status != PermissionStatus.Granted)
            {
                status = await CrossPermissions.Current.RequestPermissionAsync <CameraPermission>();
            }
            if (status != PermissionStatus.Granted)
            {
                await DisplayAlert("Odmowa", "Skanowanie kodu QR wymaga uprawnień do użycia kamery. Użytkownik odmówił tego uprawnienia. Spróbuj jeszcze raz i przyznaj odpowiednie uprawnienie", "OK");
            }
            else
            {
                var options = new ZXing.Mobile.MobileBarcodeScanningOptions
                {
                    PossibleFormats = new List <ZXing.BarcodeFormat>
                    {
                        ZXing.BarcodeFormat.QR_CODE
                    },
                    TryHarder   = false,
                    AutoRotate  = false,
                    TryInverted = false,
                };
                scanPage = new ZXingScannerPage();
                scanPage.AutoFocus();
                scanPage.OnScanResult += (result) =>
                {
                    //DateTime _start = DateTime.Now;
                    scanPage.IsScanning = false;

                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        Navigation.PopAsync();
                        PopupNavigation.Instance.PushAsync(new LoadingScreen(), true);
                        try
                        {
                            //check if this is MES process string
                            string[] mesStr = Regex.Split(result.Text, ";");
                            if (mesStr.Length == 7)
                            {
                                //there are 7 fields split by ; in the string, there's good chance it comes from MES
                                MesString ms = new MesString();
                                try
                                {
                                    ms.MesId          = mesStr[0];
                                    ms.MesDate        = DateTime.Parse(mesStr[1]);
                                    ms.SetName        = mesStr[2];
                                    ms.ActionTypeName = mesStr[3];
                                    ms.Reason         = mesStr[5];
                                }
                                catch (Exception ex)
                                {
                                    await DisplayAlert("Problem z kodem", string.Format("Coś poszło nie tak podczas deserializacji kodu {0}", result.Text) + ". Opis błędu: " + ex.Message, "OK");
                                }
                                try
                                {
                                    //check if such a mesId exists before creating new one
                                    ProcessKeeper pKeeper = new ProcessKeeper();
                                    Process nProcess      = await pKeeper.GetProcess(ms.MesId);

                                    //pass everything to ProcessPage.xaml
                                    if (nProcess == null)
                                    {
                                        await Application.Current.MainPage.Navigation.PushAsync(new ProcessPage(ms));
                                    }
                                    else
                                    {
                                        await Application.Current.MainPage.Navigation.PushAsync(new ProcessPage(ms, nProcess, true));
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Static.Functions.CreateError(ex, "No connection", nameof(scanPage.OnScanResult), this.GetType().Name);
                                }
                            }
                            else if (result.Text.Contains("<Part>"))
                            {
                                //it's a part
                                string res = result.Text.Replace("<Part>", "");

                                Part Part = await new PartKeeper().GetByToken(res);
                                if (Part != null)
                                {
                                    if (Part.IsArchived == true)
                                    {
                                        await Application.Current.MainPage.DisplayAlert("Część zarchiwizowana", "Ta część została zarchiwizowana! Być może ta część występuje teraz pod nowym numerem, w takim przypadku należy wydrukować i okleić ją nowym kodem", "OK");
                                    }
                                    else
                                    {
                                        await Application.Current.MainPage.Navigation.PushAsync(new PartPage(Part));
                                    }
                                }
                                else
                                {
                                    DependencyService.Get <IToaster>().ShortAlert($"Nie znaleziono części oznaczonej kodem {res}..");
                                }
                            }
                            else
                            {
                                //try to find place of such token
                                Place = await Keeper.GetPlace(result.Text);
                                if (Place == null)
                                {
                                    await DisplayAlert("Brak dopasowań", string.Format("Zeskanowany kod: {0} nie odpowiada żadnemu istniejącemu zasobowi. Spróbuj zeskanować kod jeszcze raz.", result.Text), "OK");
                                }
                                else
                                {
                                    try
                                    {
                                        if (Place.IsArchived == true)
                                        {
                                            await Application.Current.MainPage.DisplayAlert("Zasób zarchiwizowany", "Ten zasób został zarchiwizowany! Być może ten zasób występuje teraz pod nowym numerem, w takim przypadku należy wydrukować i okleić go nowym kodem", "OK");
                                        }
                                        else
                                        {
                                            await Navigation.PushAsync(new ScanningResults(Place, true));
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        if (PopupNavigation.Instance.PopupStack.Any())
                                        {
                                            await PopupNavigation.Instance.PopAllAsync(true);
                                        }                                                                                                 // Hide loading screen
                                        await DisplayAlert("Brak połączenia", "Nie można połączyć się z serwerem. Prawdopodobnie utraciłeś połączenie internetowe. Upewnij się, że masz połączenie z internetem i spróbuj jeszcze raz", "OK");
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            await DisplayAlert("Brak połączenia", "Nie można połączyć się z serwerem. Prawdopodobnie utraciłeś połączenie internetowe. Upewnij się, że masz połączenie z internetem i spróbuj jeszcze raz", "OK");
                        }
                        if (PopupNavigation.Instance.PopupStack.Any())
                        {
                            await PopupNavigation.Instance.PopAllAsync(true);
                        }                                                                                                     // Hide loading screen
                    });
                };

                await Navigation.PushAsync(scanPage);
            }

            btnScan.IsEnabled = true;
        }
コード例 #17
0
ファイル: QrHandler.cs プロジェクト: robs23/TestZXing-master
        public async Task <string> Scan()
        {
            try
            {
                PermissionStatus status = await CrossPermissions.Current.CheckPermissionStatusAsync <CameraPermission>();

                if (status != PermissionStatus.Granted)
                {
                    status = await CrossPermissions.Current.RequestPermissionAsync <CameraPermission>();
                }
                if (status != PermissionStatus.Granted)
                {
                    IsSuccessful = false;
                    Result       = "Skanowanie kodu QR wymaga uprawnień do użycia kamery. Użytkownik odmówił tego uprawnienia. Spróbuj jeszcze raz i przyznaj odpowiednie uprawnienie";
                }
                else
                {
                    var options = new ZXing.Mobile.MobileBarcodeScanningOptions
                    {
                        PossibleFormats = new List <ZXing.BarcodeFormat>
                        {
                            ZXing.BarcodeFormat.QR_CODE
                        },
                        TryHarder   = false,
                        AutoRotate  = false,
                        TryInverted = false,
                    };
                    scanPage = new ZXingScannerPage();
                    scanPage.AutoFocus();
                    using (SemaphoreSlim semaphoreSlim = new SemaphoreSlim(0, 1))
                    {
                        scanPage.OnScanResult += (result) =>
                        {
                            //DateTime _start = DateTime.Now;
                            scanPage.IsScanning = false;

                            Device.BeginInvokeOnMainThread(async() =>
                            {
                                Application.Current.MainPage.Navigation.PopAsync();
                                try
                                {
                                    Result = result.Text;
                                }
                                catch (Exception ex)
                                {
                                    Result = ex.Message;
                                }
                                semaphoreSlim.Release();
                            });
                        };
                        await Application.Current.MainPage.Navigation.PushAsync(scanPage);

                        await semaphoreSlim.WaitAsync();
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(Result);
        }
コード例 #18
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            opts = new ZXing.Mobile.MobileBarcodeScanningOptions()
            {
                AutoRotate      = false,
                PossibleFormats = new List <ZXing.BarcodeFormat>()
                {
                    ZXing.BarcodeFormat.CODE_128,
                    ZXing.BarcodeFormat.CODABAR,
                    ZXing.BarcodeFormat.CODE_39,
                }
            };

            opts.TryHarder = true;

            zxing = new ZXingScannerView
            {
                IsScanning   = false,
                IsTorchOn    = false,
                IsAnalyzing  = false,
                AutomationId = "zxingDefaultOverlay",//zxingScannerView
                Opacity      = 22,
                Options      = opts
            };

            var torch = new Switch
            {
            };

            torch.Toggled += delegate
            {
                scanPage.ToggleTorch();
            };

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

            var Overlay = new ZXingDefaultOverlay
            {
                TopText         = "Włącz latarkę",
                BottomText      = "Skanowanie rozpocznie się automatycznie",
                ShowFlashButton = true,
                AutomationId    = "zxingDefaultOverlay",
            };

            var customOverlay = new StackLayout
            {
                HorizontalOptions = LayoutOptions.EndAndExpand,
                VerticalOptions   = LayoutOptions.EndAndExpand
            };

            grid.Children.Add(Overlay);
            Overlay.Children.Add(torch);
            Overlay.BindingContext = Overlay;

            scanPage = new ZXingScannerPage(opts, customOverlay: Overlay)
            {
                DefaultOverlayTopText = "Zeskanuj kod ",
                //DefaultOverlayBottomText = " Skanuj kod ";
                DefaultOverlayShowFlashButton = true
            };
            scanPage.OnScanResult += (result) =>
            {
                scanPage.IsScanning = false;
                scanPage.AutoFocus();
                Device.BeginInvokeOnMainThread(() =>
                {
                    Device.StartTimer(new TimeSpan(0, 0, 0, 2), () =>
                    {
                        if (scanPage.IsScanning)
                        {
                            scanPage.AutoFocus();
                        }
                        return(true);
                    });
                    Navigation.PopModalAsync();
                    entry_MM.Text = result.Text;
                    viewModel.ExecInsertToBase(result.Text);
                });
            };
            await Navigation.PushModalAsync(scanPage);
        }
コード例 #19
0
ファイル: QRPageUtil.cs プロジェクト: zzangzk/PKHeX.Mobile
        public static async Task <PKM> ScanQRPKM(SaveFile sav, INavigation nav)
        {
            var scanPage = new ZXingScannerPage
            {
                DefaultOverlayTopText    = "Hold camera up to QR code",
                DefaultOverlayBottomText = "Camera will automatically scan QR code/Barcode \r\n\rPress the 'Back' button to cancel"
            };

            scanPage.AutoFocus();

            PKM  pkm      = null;
            bool finished = false;

            scanPage.OnScanResult += async result =>
            {
                // disable scanning until message is acknowledged; if we get a good result, we're done scanning anyway
                scanPage.IsScanning = false;
                if (result.BarcodeFormat != BarcodeFormat.QR_CODE)
                {
                    await UserDialogs.Instance.AlertAsync("That's not a QR code.").ConfigureAwait(false);

                    scanPage.IsScanning = true;
                    return;
                }

                var pk = QRUtil.GetPKMFromQRMessage(result.Text, sav.Generation);
                if (pk == null)
                {
                    await UserDialogs.Instance.AlertAsync("Please scan a PKM QR code.").ConfigureAwait(false);

                    scanPage.IsScanning = true;
                    return;
                }

                pkm = PKMConverter.ConvertToType(pk, sav.PKMType, out var c);
                if (pkm == null)
                {
                    Console.WriteLine(c);
                    await UserDialogs.Instance.AlertAsync("Please scan a compatible PKM format QR code." + Environment.NewLine + $"Received {pk.GetType().Name}").ConfigureAwait(false);

                    scanPage.IsScanning = true;
                    return;
                }

                finished = true;
            };
            scanPage.Disappearing += (s, e) => finished = true;

            await nav.PushAsync(scanPage).ConfigureAwait(false);

            while (!finished)
            {
                await Task.Delay(100).ConfigureAwait(false);
            }
            if (pkm == null) // canceled
            {
                return(null);
            }
            Device.BeginInvokeOnMainThread(async() => await nav.PopAsync().ConfigureAwait(false));
            return(pkm);
        }