private async Task ScanNow()
        {
            MobileBarcodeScanner scanner = new MobileBarcodeScanner();
            Result result = null;
            bool   isBack = false;

            TimeSpan timeSpan = new TimeSpan(0, 0, 0, 5, 0);

            Device.StartTimer(timeSpan, () =>
            {
                if (result == null && !isBack)
                {
                    scanner.AutoFocus();
                    return(true);
                }
                return(false);
            });

            result = await scanner.Scan();

            isBack = true;

            if (result != null)
            {
                await DisplayAlert("Scanned Barcode", result.Text, "OK");
            }

            //await Application.Current.MainPage.Navigation.PushAsync(new ScanPage());
        }
Пример #2
0
        private async void custom_scan()
        {
            View zxingOverlay;

            MobileBarcodeScanner.Initialize(Application);
            scanner = new MobileBarcodeScanner();

            var options = new MobileBarcodeScanningOptions
            {
                AutoRotate = false,
                UseFrontCameraIfAvailable = false,
                TryHarder       = true,
                PossibleFormats = new List <ZXing.BarcodeFormat>
                {
                    ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13, ZXing.BarcodeFormat.QR_CODE
                }
            };

            //Tell our scanner we want to use a custom overlay instead of the default
            scanner.UseCustomOverlay = true;
            //Inflate our custom overlay from a resource layout
            zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.ZxingOverlay, null);
            //Set our custom overlay
            scanner.CustomOverlay = zxingOverlay;
            new Task(async() =>
            {
                await Task.Delay(3000);
                scanner.AutoFocus();
            }).Start();
            //Start scanning!
            var result = await scanner.Scan(this, options);

            HandleScanResult(result);
        }
Пример #3
0
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        var         view    = inflater.Inflate(Resource.Layout.MySettingsView, container, false);
        ImageButton scanBtn = view.FindViewById <ImageButton>(Resource.Id.btnScan);
        TextView    results = view.FindViewById <TextView>(Resource.Id.results);

        scanBtn.Click += async(sender, e) =>
        {
            MobileBarcodeScanner.Initialize(Activity.Application);
            var scanner = new MobileBarcodeScanner();
            var result  = (ZXing.Result)null;
            new Thread(new ThreadStart(delegate
            {
                while (result == null)
                {
                    scanner.AutoFocus();
                    Thread.Sleep(2000);
                }
            })).Start();
            result = await scanner.Scan();

            if (result == null)
            {
                return;
            }
            Console.WriteLine($"Scanned Barcode: {result}");
            Activity.RunOnUiThread(() =>
            {
                results.Text = result.Text;
            });
        };
        return(view);
    }
Пример #4
0
        private async void Scan_Click(object sender, RoutedEventArgs e)
        {
            scanner.UseCustomOverlay = true;
            scanner.CustomOverlay    = new CustomOverlay();
            scanner.AutoFocus();
            scanner.RootFrame = Frame;

            try
            {
                MediaCapture capture = new MediaCapture();
                await capture.InitializeAsync(new MediaCaptureInitializationSettings
                {
                    StreamingCaptureMode = StreamingCaptureMode.Video
                });

                await scanner.Scan(new MobileBarcodeScanningOptions()
                {
                    PossibleFormats = new List <BarcodeFormat>()
                    {
                        BarcodeFormat.QR_CODE
                    }
                }).ContinueWith(t =>
                {
                    HandleScanResult(t.Result);

                    didScan = true;
                });
            }
            catch (UnauthorizedAccessException)
            {
                AccessDeniedDialog dialog = new AccessDeniedDialog();
                await dialog.ShowAsync();
            }
        }
Пример #5
0
        public async Task <byte[]> ScanBarcodeAsync()
        {
            string msg = "";

            byte[] scanData = null;
            MobileBarcodeScanningOptions scanoptions = new MobileBarcodeScanningOptions();

            scanoptions.TryInverted  = true;
            scanoptions.TryHarder    = true;
            scanoptions.AutoRotate   = false;
            scanner.UseCustomOverlay = false;
            scanner.AutoFocus();

            scanner.TopText    = "请扫码";
            scanner.BottomText = "Wait for the barcode to automatically scan!";

            //Start scanning
            var result = await scanner.Scan(scanoptions);


            if (result != null && !string.IsNullOrEmpty(result.Text))
            {
                msg      = result.Text;
                scanData = System.Text.Encoding.Default.GetBytes(msg);
            }

            return(scanData);
        }
Пример #6
0
        public MainPage()
        {
            InitializeComponent();

            _injector = InputInjector.TryCreate();
            if (_injector == null)
            {
                Console.WriteLine("Can't work, no InputInjector available");
                Application.Current.Exit();
            }

            //Create a new instance of our scanner
            _scanner            = new MobileBarcodeScanner(Dispatcher);
            _scanner.RootFrame  = Frame;
            _scanner.Dispatcher = Dispatcher;

            //Tell our scanner to use the default overlay
            _scanner.UseCustomOverlay = false;
            //We can customize the top and bottom text of our default overlay
            _scanner.TopText    = "Hold camera up to barcode";
            _scanner.BottomText = "The code will be typed in the active app";
            //Start scanning
            _scanner.AutoFocus();
            Loaded += OnLoaded;
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            MobileBarcodeScanner.Initialize(Application);

            SetContentView(Resource.Layout.Main);
            Window.SetBackgroundDrawableResource(Resource.Drawable.background);

            scanner = new MobileBarcodeScanner();
            scanner.AutoFocus();
            scanner.FlashButtonText = "flash";

            var toolbar = FindViewById <Toolbar> (Resource.Id.toolbar);

            //Toolbar will now take on default actionbar characteristics
            SetActionBar(toolbar);
            ActionBar.SetIcon(Resource.Drawable.iconsamll);

            ActionBar.Title = "QR & Bar Code Reader";
            ActionBar.Title.TrimEnd();

            var btnSingle = FindViewById <Button> (Resource.Id.btnSingle);

            btnSingle.Click += BtnSingle_Click;

            var btnMulty = FindViewById <Button>(Resource.Id.btnMulty);

            btnMulty.Click += BtnMulty_Click;


            Common.HistoryItem = new List <string>();
            readXml();



            var toolbarBottom = FindViewById <Toolbar>(Resource.Id.toolbar_bottom);

            //toolbarBottom.Title = "Settings";
            toolbarBottom.InflateMenu(Resource.Menu.photo_edit);
            toolbarBottom.MenuItemClick += (sender, e) =>
            {
                if (e.Item.TitleFormatted.ToString() == "Delete")
                {
                    Android.App.AlertDialog.Builder dialog = new AlertDialog.Builder(this);
                    AlertDialog alert = dialog.Create();

                    alert.SetMessage("Clear History?");
                    alert.SetButton("OK", (c, ev) =>
                    {
                        var conn = new SQLiteConnection(Common.DirectoryPath);
                        conn.Execute("Delete FROM ConfigDetails");
                        Toast.MakeText(this, "Complete", ToastLength.Short).Show();
                    });
                    alert.SetButton2("CANCEL", (c, ev) => { });
                    alert.Show();
                }
            };
        }
Пример #8
0
 public CommonScan()
 {
     _options = new MobileBarcodeScanningOptions
     {
         CameraResolutionSelector = HandleCameraResolutionSelectorDelegate
     };
     _scanner = new MobileBarcodeScanner();
     _scanner.AutoFocus();
 }
Пример #9
0
        async partial void BtnScanBarcode_TouchUpInside(UIButton sender)
        {
            var scanner = new MobileBarcodeScanner(); 
 scanner.AutoFocus(); 
 scanner.TopText = "Hold the camera up to the barcode"; 
 scanner.BottomText = "Wait for scanner to complete the scan"; 
 
 var options = new MobileBarcodeScanningOptions(); 
 options.UseCode39ExtendedMode = true; 
 options.TryHarder = true; 
 options.AutoRotate = false; 

 var result = await scanner.Scan(new MobileBarcodeScanningOptions { AutoRotate = false }); 

            if (result != null && !string.IsNullOrEmpty(result.Text))

            {
                
            {
                    
 txtBarcodeText.Text = result.Text; 

                }
            }
            

        }
        private async void Scan()
        {
            MobileBarcodeScanningOptions options = new MobileBarcodeScanningOptions();

            options.AutoRotate = false;

            var scanner = new MobileBarcodeScanner();

            scanner.AutoFocus();
            var result = await scanner.Scan(options);

            if (result != null)
            {
                searchView.SetQuery(result.Text, true);
            }
        }
Пример #11
0
        private async void Scanner()
        {
            ZXing.Result result = null;
            scanner.TopText = "Aguarde o escaneamento do código de barras";

            new Thread(new ThreadStart(delegate
            {
                while (result == null)
                {
                    scanner.AutoFocus();
                    Thread.Sleep(2000);
                }
            })).Start();

            result = await scanner.Scan();

            HandleScanResult(result);
        }
Пример #12
0
        private async void btn_clicked(object sender, EventArgs e)
        {
            var scanner = new MobileBarcodeScanner();
            var mobileBarcodeScanningOptions = new MobileBarcodeScanningOptions();

            mobileBarcodeScanningOptions.AutoRotate = true;
            scanner.AutoFocus();
            if (!scanner.IsTorchOn)
            {
                scanner.Torch(true);
            }
            scanner.TopText    = "Hold the camera up to  the barcode ";
            scanner.BottomText = "wait for the barcode automatically  scan!";

            ZXing.Result result = await scanner.Scan(mobileBarcodeScanningOptions);

            HandleResult(result);
        }
Пример #13
0
        public async Task StartScan(MobileBarcodeScanningOptions options = null)
        {
            try
            {
                var scanner = new MobileBarcodeScanner()
                {
                    TopText = "Scan Code"
                };
                scanner.ScanContinuously(options ?? new MobileBarcodeScanningOptions
                {
                    PossibleFormats = new List <BarcodeFormat>
                    {
                        BarcodeFormat.EAN_8,
                        BarcodeFormat.EAN_13,
                        BarcodeFormat.CODE_39,
                        BarcodeFormat.CODE_128,
                        BarcodeFormat.QR_CODE
                    },
                    AutoRotate = false,
                    UseFrontCameraIfAvailable = false,
                    TryHarder = true
                }, (result) =>
                {
                    CrossSimpleAudioPlayer.Current.Load("beep.wav");
                    CrossSimpleAudioPlayer.Current.Play();

                    OnScanned?.Invoke(this, result.Text);
                    MessagingCenter.Send(this, MessageKey.BARCODE_SCANNED, result.Text);
                });

                Device.StartTimer(TimeSpan.FromSeconds(3), () =>
                {
                    scanner.AutoFocus();
                    return(true);
                });
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert(TranslateExtension.GetValue("alert_title_error"), ex.Message, TranslateExtension.GetValue("alert_message_ok"));
            }
        }
Пример #14
0
        /// <summary>
        /// Efetua a leitura de um código de barras; Por padrão, lê qualquer formato disponível atualmente
        /// </summary>
        /// <param name="p_sTextoExibicao">Texto que aparecerá para o usuário durante a leitura do código.</param>
        /// <returns></returns>
        public async Task <string> LerCodigo(string p_sTextoExibicao, bool p_bAutoFoco)
        {
            string sRet = string.Empty;
            MobileBarcodeScanningOptions scanOptions = new MobileBarcodeScanningOptions();

            scanOptions.AutoRotate        = false;
            scanOptions.UseNativeScanning = true;
            //scanOptions.TryInverted = true;
            scanOptions.PossibleFormats.Add(ZXing.BarcodeFormat.EAN_13);
            //scanOptions.TryHarder = true;
            scanOptions.DelayBetweenAnalyzingFrames = 712;

            var scanner = new MobileBarcodeScanner();

            if (!string.IsNullOrEmpty(p_sTextoExibicao))
            {
                scanner.TopText = p_sTextoExibicao;
            }

            ZXing.Result zRet = null;

            new Thread(new ThreadStart(delegate
            {
                while (zRet == null)
                {
                    scanner.AutoFocus();
                    Thread.Sleep(1916);
                }
            })).Start();

            zRet = await scanner.Scan(scanOptions);

            if (zRet != null)
            {
                sRet = (!string.IsNullOrEmpty(zRet.Text) ? zRet.Text : "");
            }

            MobileBarcodeScanner.Uninitialize(app);

            return(sRet);
        }
Пример #15
0
        public async Task <string> ScanAsync()
        {
            CameraResolution HandleCameraResolutionSelectorDelegate(List <CameraResolution> availableResolutions)
            {
                //Don't know if this will ever be null or empty

                if (availableResolutions == null || availableResolutions.Count < 1)
                {
                    return new CameraResolution()
                           {
                               Height = 900, Width = 800
                           }
                }
                ;

                //Debugging revealed that the last element in the list
                //expresses the highest resolution. This could probably be more thorough.
                return(availableResolutions[availableResolutions.Count - 1]);
            }

            var options = new MobileBarcodeScanningOptions
            {
                TryHarder       = true,
                PossibleFormats = new List <BarcodeFormat> {
                    BarcodeFormat.PDF_417
                }
            };

            var scanner = new MobileBarcodeScanner()
            {
                TopText    = "Acerca la camara al elemento",
                BottomText = "Toca la pantalla para enfocar",
            };

            scanner.AutoFocus();
            var scanResult = await scanner.Scan(options);

            return(scanResult.Text);
        }
    }
Пример #16
0
        public static async Task <String> ScanAsync()
        {
            try
            {
                if (!Application.Context.PackageManager.HasSystemFeature(PackageManager.FeatureCamera))
                {
                    return(string.Empty);
                }
                //if (!IsCameraCanUse())
                //{
                //    return string.Empty;
                //}
                Application app = new Application();
                MobileBarcodeScanner.Initialize(app);
                MobileBarcodeScanningOptions opts = new MobileBarcodeScanningOptions
                {
                    PossibleFormats = new List <BarcodeFormat>
                    {
                        BarcodeFormat.CODE_39,
                        BarcodeFormat.CODE_93,
                        BarcodeFormat.CODE_128,
                        BarcodeFormat.EAN_13,
                        BarcodeFormat.EAN_8,
                        BarcodeFormat.QR_CODE
                    }
                };
                opts.DisableAutofocus = false;
                var scanner = new MobileBarcodeScanner();
                scanner.TopText = Application.Context.Resources.GetString(Resource.String.Scan);
                scanner.AutoFocus();
                var result = await scanner.Scan(opts);

                return(result?.Text ?? string.Empty);
            }
            catch (Exception Ex)
            {
                WriteErrorLog(Ex);
                return("");
            }
        }
        public async Task StartScan(bool useFrontCamera = false, MobileBarcodeScanningOptions options = null)
        {
            try
            {
                var scanner = new MobileBarcodeScanner()
                {
                    TopText = "Scan Code"
                };
                scanner.ScanContinuously(options ?? new MobileBarcodeScanningOptions
                {
                    PossibleFormats = new List <BarcodeFormat>
                    {
                        BarcodeFormat.EAN_8,
                        BarcodeFormat.EAN_13,
                        BarcodeFormat.CODE_39,
                        BarcodeFormat.CODE_128,
                        BarcodeFormat.QR_CODE
                    },
                    AutoRotate = false,
                    UseFrontCameraIfAvailable = useFrontCamera,
                    TryHarder        = true,
                    DisableAutofocus = false
                }, (result) =>
                {
                    BarcodeScanned?.Invoke(this, result.Text);
                    MessagingCenter.Send(this, Constants.BARCODE_SCANNED, result.Text);
                });

                Device.StartTimer(TimeSpan.FromSeconds(3), () =>
                {
                    scanner.AutoFocus();
                    return(true);
                });
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "Ok");
            }
        }
Пример #18
0
        public async Task <string> ScanAsync()
        {
            var scanner = new MobileBarcodeScanner();

            Xamarin.Forms.Device.StartTimer(new TimeSpan(0, 0, 0, 1, 500), () =>
            {
                if (scanning)
                {
                    scanner.AutoFocus();
                    return(true);
                }

                return(false);
            });

            scanning = true;
            var result = await scanner.Scan(options);

            scanning = false;

            return(result != null ? result.Text : string.Empty);
        }
Пример #19
0
        private async void ScanBarcode(long?burialAppId)
        {
            _scanner = new MobileBarcodeScanner
            {
                TopText          = "Hold the camera up to the barcode\nAbout 6 inches away",
                BottomText       = "Wait for the barcode to automatically scan!",
                CancelButtonText = "Return",
                FlashButtonText  = "Flash"
            };

            var opt = new MobileBarcodeScanningOptions {
                DelayBetweenContinuousScans = 3000
            };

            opt.AutoRotate = true;
            _scanner.Torch(true);
            _scanner.AutoFocus();
            try
            {
                var results = await _scanner.Scan(opt);

                HandleScanResult(results, burialAppId);

                if (_burialOutPut != null)
                {
                    _burialOutPut.SupervisorId = SupervisorId;
                    await Application.Current.MainPage.Navigation.PushAsync(
                        new Undertaker(_burialOutPut, _apiBurial) { Title = _burialOutPut.Cemetery + " Burials" });
                }
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Error on scanner Api",
                                                                ex.Message,
                                                                "OK");
            }
        }
Пример #20
0
 public void AutoFocus()
 {
     _scanner.AutoFocus();
 }
Пример #21
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            MobileBarcodeScanner.Initialize(Application);

            SetContentView(Resource.Layout.Search);

            scanner = new MobileBarcodeScanner();
            scanner.UseCustomOverlay = false;
            scanner.TopText          = "Hold the camera up to the barcode\nAbout 6 inches away";
            scanner.BottomText       = "Wait for the barcode to automatically scan!";
            isbnEditText             = this.FindViewById <EditText>(Resource.Id.isbnEditText);
            buttonScan        = this.FindViewById <Button>(Resource.Id.scanButton);
            buttonSearch      = this.FindViewById <Button>(Resource.Id.searchButton);
            buttonScan.Click += async delegate
            {
                Result result = null;
                new Thread(new ThreadStart(delegate
                {
                    while (result == null)
                    {
                        scanner.AutoFocus();
                        Thread.Sleep(1000);
                    }
                })).Start();

                result = await scanner.Scan();

                if (result != null && !string.IsNullOrEmpty(result.Text))
                {
                    isbnEditText.Text = result.Text;

                    var isbn = new IsbnSearchRequest()
                    {
                        Isbn = isbnEditText.Text
                    };
                    var isbnRequest = JsonConvert.SerializeObject(isbn);
                    var utils       = new Utilities();
                    var response    = await Utilities.MakeAjaxRequestAsync(Constants.SEARCH_URL, isbnRequest, Constants.JSON_CONTENT);

                    if (response == "Status: Not found")
                    {
                        Toast toast = Toast.MakeText(this, "Title not found.", ToastLength.Long);
                        toast.Show();
                    }
                    else
                    {
                        var intent = new Intent(this, typeof(BibDisplayActivity));
                        intent.PutExtra("response", response);
                        StartActivity(intent);
                    }
                }
            };
            buttonSearch.Click += async(sender, e) =>
            {
                try
                {
                    var isbn = new IsbnSearchRequest()
                    {
                        Isbn = isbnEditText.Text
                    };
                    var isbnRequest = JsonConvert.SerializeObject(isbn);
                    var utils       = new Utilities();
                    var response    = await Utilities.MakeAjaxRequestAsync(Constants.SEARCH_URL, isbnRequest, Constants.JSON_CONTENT);

                    var intent = new Intent(this, typeof(BibDisplayActivity));
                    intent.PutExtra("response", response);
                    StartActivity(intent);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            };
        }