Example #1
0
        public override void ViewDidLoad()
        {
            //Create a new instance of our scanner
            scanner = new MobileBarcodeScanner();

            //Setup our button
            buttonDefaultScan       = new UIButton(UIButtonType.RoundedRect);
            buttonDefaultScan.Frame = new RectangleF(20, 80, 280, 40);
            buttonDefaultScan.SetTitle("Scan with Default View", UIControlState.Normal);
            buttonDefaultScan.TouchUpInside += (sender, e) =>
            {
                //Tell our scanner to use the default overlay
                scanner.UseCustomOverlay = false;
                //We can customize the top and bottom text of the default overlay
                scanner.TopText    = "Hold camera up to barcode to scan";
                scanner.BottomText = "Barcode will automatically scan";

                //Start scanning
                scanner.Scan().ContinueWith((t) =>
                {
                    //Our scanning finished callback
                    if (t.Status == System.Threading.Tasks.TaskStatus.RanToCompletion)
                    {
                        HandleScanResult(t.Result);
                    }
                });
            };

            buttonCustomScan       = new UIButton(UIButtonType.RoundedRect);
            buttonCustomScan.Frame = new RectangleF(20, 20, 280, 40);
            buttonCustomScan.SetTitle("Scan with Custom View", UIControlState.Normal);
            buttonCustomScan.TouchUpInside += (sender, e) =>
            {
                //Create an instance of our custom overlay
                customOverlay = new CustomOverlayView();
                //Wireup the buttons from our custom overlay
                customOverlay.ButtonTorch.TouchUpInside += delegate {
                    scanner.ToggleTorch();
                };
                customOverlay.ButtonCancel.TouchUpInside += delegate {
                    scanner.Cancel();
                };

                //Tell our scanner to use our custom overlay
                scanner.UseCustomOverlay = true;
                scanner.CustomOverlay    = customOverlay;

                scanner.Scan().ContinueWith((t) =>
                {
                    //Our scanning finished callback
                    if (t.Status == System.Threading.Tasks.TaskStatus.RanToCompletion)
                    {
                        HandleScanResult(t.Result);
                    }
                });
            };

            this.View.AddSubview(buttonDefaultScan);
            this.View.AddSubview(buttonCustomScan);
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            //Create a new instance of our Scanner
            scanner = new MobileBarcodeScanner(this);

            buttonScanDefaultView        = this.FindViewById <Button>(Resource.Id.buttonScanDefaultView);
            buttonScanDefaultView.Click += delegate {
                //Tell our scanner to use the default overlay
                scanner.UseCustomOverlay = false;

                //We can customize the top and bottom text of the default overlay
                scanner.TopText    = "Hold the camera up to the barcode\nAbout 6 inches away";
                scanner.BottomText = "Wait for the barcode to automatically scan!";

                //Start scanning
                scanner.Scan().ContinueWith((t) => {
                    if (t.Status == System.Threading.Tasks.TaskStatus.RanToCompletion)
                    {
                        HandleScanResult(t.Result);
                    }
                });
            };

            Button flashButton;
            View   zxingOverlay;

            buttonScanCustomView        = this.FindViewById <Button>(Resource.Id.buttonScanCustomView);
            buttonScanCustomView.Click += delegate {
                //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);

                //Find the button from our resource layout and wire up the click event
                flashButton        = zxingOverlay.FindViewById <Button>(Resource.Id.buttonZxingFlash);
                flashButton.Click += (sender, e) => scanner.ToggleTorch();

                //Set our custom overlay
                scanner.CustomOverlay = zxingOverlay;

                //Start scanning!
                scanner.Scan().ContinueWith((t) => {
                    if (t.Status == System.Threading.Tasks.TaskStatus.RanToCompletion)
                    {
                        HandleScanResult(t.Result);
                    }
                });
            };
        }
Example #3
0
        private String m_qtyString = "1";  // use string for input // TODO

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            // Create your application here
            this.SetContentView(Resource.Layout.Checkin);

            this.FindViewById <Button>(Resource.Id.buttonBack).Click += this.Back;

            // Initialize scanner
            MobileBarcodeScanner.Initialize(Application);
            scanner = new ZXing.Mobile.MobileBarcodeScanner();

            // set up scanning options
            var scanOptions = new ZXing.Mobile.MobileBarcodeScanningOptions();

            scanOptions.PossibleFormats = new List <ZXing.BarcodeFormat>()
            {
                ZXing.BarcodeFormat.EAN_8,
                ZXing.BarcodeFormat.EAN_13,
                ZXing.BarcodeFormat.UPC_A,
                ZXing.BarcodeFormat.UPC_E,
                ZXing.BarcodeFormat.UPC_EAN_EXTENSION
            };

            // quick scan code
            buttonQuickScan        = this.FindViewById <Button>(Resource.Id.buttonQuickScan);
            buttonQuickScan.Click += async delegate
            {
                scanner.UseCustomOverlay = false;
                scanner.TopText          = "Scanning for barcode";
                var result = await scanner.Scan();
                await AddOneToInventory(result);

                DisplayConfirm(1);
            };

            // quantities scan code
            buttonQtyScan        = this.FindViewById <Button>(Resource.Id.buttonQtyScan);
            buttonQtyScan.Click += async delegate
            {
                scanner.UseCustomOverlay = false;
                scanner.TopText          = "Scanning for barcode";
                var result = await scanner.Scan();

                await GetQuantityDialog(result);

                //DisplayConfirm();
                //await AddQtyToInventory(result, Int32.Parse(m_qtyString));
            };
        }
Example #4
0
        async void btnDefault_Click(object sender, EventArgs e)
        {
            //不使用自定义界面
            scanner.UseCustomOverlay = false;

            //设置上下提示文字
            scanner.TopText    = "上面的文字";
            scanner.BottomText = "下面的文字";

            var result = await scanner.Scan();

            HandleScanResult(result);
        }
Example #5
0
        public override void ViewDidLoad()
        {
            //Create a new instance of our scanner
            scanner = new MobileBarcodeScanner(this.NavigationController);

            //Setup our button
            buttonDefaultScan       = new UIButton(UIButtonType.RoundedRect);
            buttonDefaultScan.Frame = new RectangleF(20, 80, 280, 40);
            buttonDefaultScan.SetTitle("Scan with Default View", UIControlState.Normal);
            buttonDefaultScan.TouchUpInside += async(sender, e) =>
            {
                //Tell our scanner to use the default overlay
                scanner.UseCustomOverlay = false;
                //We can customize the top and bottom text of the default overlay
                scanner.TopText    = "Hold camera up to barcode to scan";
                scanner.BottomText = "Barcode will automatically scan";

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

                HandleScanResult(result);
            };

            buttonCustomScan       = new UIButton(UIButtonType.RoundedRect);
            buttonCustomScan.Frame = new RectangleF(20, 20, 280, 40);
            buttonCustomScan.SetTitle("Scan with Custom View", UIControlState.Normal);
            buttonCustomScan.TouchUpInside += async(sender, e) =>
            {
                //Create an instance of our custom overlay
                customOverlay = new CustomOverlayView();
                //Wireup the buttons from our custom overlay
                customOverlay.ButtonTorch.TouchUpInside += delegate {
                    scanner.ToggleTorch();
                };
                customOverlay.ButtonCancel.TouchUpInside += delegate {
                    scanner.Cancel();
                };

                //Tell our scanner to use our custom overlay
                scanner.UseCustomOverlay = true;
                scanner.CustomOverlay    = customOverlay;

                var result = await scanner.Scan();

                HandleScanResult(result);
            };

            this.View.AddSubview(buttonDefaultScan);
            this.View.AddSubview(buttonCustomScan);
        }
Example #6
0
        public async void ScanPDF()
        {
            //Tell our scanner to activiyt use the default overlay
            scanner.UseCustomOverlay = false;

            //We can customize the top and bottom text of the default overlay
            scanner.TopText    = "Hold the camera up to the barcode\nAbout 6 inches away";
            scanner.BottomText = "Wait for the barcode to automatically scan!";

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

            // Handler for the result returned by the scanner.
            HandleScanResult(result);
        }
Example #7
0
        public async void StartScanning()
        {
            _scanner = new MobileBarcodeScanner();

            ScanStatusChanged?.Invoke(this, new ScanStatusEventArgs {
                ScanStatus = "Starting Scan"
            });
            var result = await _scanner.Scan();

            if (result != null)
            {
                ScanStatusChanged?.Invoke(this, new ScanStatusEventArgs {
                    ScanStatus = "Scan Result Received"
                });
                ScanResultFound?.Invoke(this, new ScanResultEventArgs {
                    ScannedText = result.Text
                });
            }
            else
            {
                ScanStatusChanged?.Invoke(this, new ScanStatusEventArgs {
                    ScanStatus = "Scan Cancelled"
                });
            }
        }
        private async void Import()
        {
            if (Reachability.IsHostReachable(AppSettings.ApiEndpoint))
            {
                var scanner = new MobileBarcodeScanner(this);
                var result  = await scanner.Scan();

                if (result == null)
                {
                    View.Add(_loadPopup);
                    await Task.Run(() => _accountService.TryImport(result.Text)).ContinueWith(r =>
                    {
                        if (r.Result)
                        {
                            _loadPopup.Hide();
                            tableView.ReloadData();
                        }
                        else
                        {
                            this.ShowError(IosLocalizator.Translate(Constants.MESSAGE_IMPORT_ERROR));
                        }
                    }, TaskScheduler.FromCurrentSynchronizationContext());
                }
            }
            else
            {
                this.ShowError(IosLocalizator.Translate(Constants.MESSAGE_CHECK_CONNECTION));
            }
        }
Example #9
0
        private async void ButtonScan_Click(object sender, System.EventArgs e)
        {
            var scanner = new MobileBarcodeScanner();

            scanner.UseCustomOverlay = false;
            var result = await scanner.Scan(MobileBarcodeScanningOptions.Default);

            TextView QRtextView = FindViewById <TextView>(Resource.Id.QRresult);

            if (result != null)
            {
                System.Diagnostics.Debug.WriteLine("Scanned Barcode: " + result.Text);
                Toast.MakeText(ApplicationContext, "Scanned Barcode: " + result.Text, ToastLength.Long).Show();
                QRtextView.Text = "";

                string qrcode   = result.Text;
                var    getIPAdd = new Intent(this, typeof(GetIPAddress));
                getIPAdd.PutExtra("qrcode", qrcode);
                StartActivity(getIPAdd);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("No QR Found :-(");
                //Toast.MakeText(ApplicationContext, "No QR Found :-(", ToastLength.Long).Show();
                QRtextView.Text = "No QR Found. Please Scan again";
            }
        }
Example #10
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here

            MobileBarcodeScanner.Initialize(Application);       //条形码扫描初始化

            try
            {
                var scanner = new MobileBarcodeScanner();       //定义scanner

                //scanner.UseCustomOverlay = true;
                //scanner.BottomText = "Ensure the barcode is inside the viewfinder";
                //scanner.FlashButtonText = "Flash";
                //scanner.CancelButtonText = "Cancel";
                //scanner.Torch(true);
                //scanner.AutoFocus();

                var result = await scanner.Scan();             //获取scan的内容

                if (!string.IsNullOrEmpty(result.Text))        //判断内容是否为空
                {
                    Intent intent = new Intent();              //定义意向
                    intent.PutExtra("parcelNum", result.Text); //传递快递单号
                    SetResult(Result.Ok, intent);              //返回意向
                    Finish();                                  //activity结束
                }
            }
            catch
            {
                Finish();           //activity结束
            }
        }
Example #11
0
        public async Task <ScanResult> Scan()
        {
            _logger.Info("Starting the barcode scanner.  Stand back.");

            var context = Forms.Context;
            var scanner = new MobileBarcodeScanner(context)
            {
                UseCustomOverlay = false,
                BottomText       = "Scanning will happen automatically",
                TopText          = "Hold your camera about \n6 inches away from the barcode",
            };

            try
            {
                var result = await scanner.Scan();

                return(new ScanResult
                {
                    Text = result.Text,
                });
            }
            catch (System.Exception)
            {
                _logger.Info("User hit back");
                return(new ScanResult
                {
                    Text = string.Empty,
                });
            }
        }
Example #12
0
        /// <summary>
        /// ScanCode
        /// Scan a QR Code using the ZXing library
        /// </summary>
        /// <returns></returns>
        private async Task ScanCode()
        {
            Scanner.UseCustomOverlay = false;
            Scanner.TopText          = "Hold camera up to QR code";
            Scanner.BottomText       = "Camera will automatically scan QR code\r\n\rPress the 'Back' button to cancel";

            ZXing.Result result = await Scanner.Scan().ConfigureAwait(true);

            if (result == null || (string.IsNullOrEmpty(result.Text)))
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    MessageDialog dialog = new MessageDialog("An error occured while scanning the QRCode. Try again");
                    await dialog.ShowAsync();
                });
            }
            else
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    TBConnectionString.Text = result.Text;
                    TBDeviceName.Text       = CTD.ExtractDeviceIdFromConnectionString(result.Text);
                });
            }
        }
Example #13
0
        private async void Import()
        {
            var connectionInfo = ((ConnectivityManager)GetSystemService(ConnectivityService)).ActiveNetworkInfo;

            if (connectionInfo != null && connectionInfo.IsConnected)
            {
                var scanner = new MobileBarcodeScanner();
                var result  = await scanner.Scan();

                if (result != null)
                {
                    var dialog = this.ShowProgress();
                    await Task.Run(() => _accountService.TryImport(result.Text)).ContinueWith(r =>
                    {
                        dialog.Dismiss();
                        if (r.Result)
                        {
                            _accounts = _accountService.GetAll().ToCT1ItemList();
                            (_listView.Adapter as CT1ActionAdapter).Update(_accounts);
                        }
                        else
                        {
                            this.ShowError(AndroidLocalizator.Translate(Resource.String.MESSAGE_IMPORT_ERROR));
                        }
                    }, TaskScheduler.FromCurrentSynchronizationContext());
                }
            }
            else
            {
                this.ShowError(AndroidLocalizator.Translate(Resource.String.MESSAGE_CHECK_CONNECTION));
            }
        }
Example #14
0
        public async Task <string> ScanAsync()
        {
            var optionsDefault = new MobileBarcodeScanningOptions();
            var optionsCustom  = new MobileBarcodeScanningOptions();

            var scanner = new MobileBarcodeScanner();

            scanner.TopText    = "Scan the QR Code";
            scanner.BottomText = "Processing ... ";



            try
            {
                var scanResult = await scanner.Scan(optionsCustom);

                return(scanResult.Text);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }


            return(null);
        }
Example #15
0
        public async Task <string> ScanQrImageAsync()
        {
            var barcodeScanner = new MobileBarcodeScanner();
            var result         = await barcodeScanner.Scan();

            return(result != null ? result.Text : string.Empty);
        }
        /// <summary>
        /// Product code scanning
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async void Code_Clicked(object sender, EventArgs e)
        {
            var scanner = new MobileBarcodeScanner();
            var result  = await scanner.Scan();

            if (result == null)
            {
                return;
            }

            var resultString = result.Text;

            foreach (Item item in viewModel.Items)
            {
                if (item.CodeString.Equals(resultString))
                {
                    await DisplayAlert("Product is detected",
                                       "Scanner code is " + resultString,
                                       "OK");

                    await Navigation.PushAsync(new ItemDetailPage(new ItemDetailViewModel(item)));

                    return;
                }
            }

            await DisplayAlert("Product is not detected",
                               "Scanner code is " + resultString
                               + ". Press ADD for new product adding",
                               "OK");
        }
Example #17
0
        public async Task <ZXing.Result> ScanCode()
        {
            ZXing.Result result = null;
            MobileBarcodeScanningOptions opts = new MobileBarcodeScanningOptions
            {
                TryHarder       = true,
                PossibleFormats = new List <ZXing.BarcodeFormat>
                {
                    BarcodeFormat.CODE_128,
                    BarcodeFormat.EAN_13,
                    BarcodeFormat.EAN_8,
                    BarcodeFormat.QR_CODE,
                    BarcodeFormat.CODE_128,
                    BarcodeFormat.CODE_39,
                    BarcodeFormat.CODE_93
                }
            };

            try
            {
                Scanner = new MobileBarcodeScanner();
                result  = await Scanner.Scan(opts);
            }
            catch (Exception Ex)
            {
                Toast.MakeText(this, Ex.Message, ToastLength.Short).Show();
            }
            return(result);
        }
Example #18
0
        public async void ScanAsync()
        {
            MobileBarcodeScanningOptions options = new MobileBarcodeScanningOptions();

            if (isDifficulty)
            {
                options = new MobileBarcodeScanningOptions()
                {
                    TryHarder   = true,
                    AutoRotate  = true,
                    TryInverted = true
                };
            }

            MobileBarcodeScanner scanner = new MobileBarcodeScanner()
            {
                TopText                  = "Hold the camera up to the barcode\nAbout 6 inches away",
                BottomText               = "Wait for the barcode to automatically scan!",
                CancelButtonText         = "Cancel",
                CameraUnsupportedMessage = "The device's camera is not supported"
            };
            Result result = await scanner.Scan(options);

            if (result != null)
            {
                ShowProperlyResult(result.Text, GetResultType(result));
            }
            else
            {
                throw new NullReferenceException();
            }
        }
        public async Task <string> ScanAsync()
        {
            var scanner     = new MobileBarcodeScanner();
            var scanResults = await scanner.Scan();

            return(scanResults.Text);
        }
Example #20
0
        /// <summary>
        /// Native implementation of scan
        /// </summary>
        /// <param name="topText">Text displayed at the top of the layout</param>
        /// <param name="bottomText">Text displayed at the bottom of the layout</param>
        /// <param name="cameraUnsupportedMessage">Unsupported camera message</param>
        /// <returns>Native scan result</returns>
        protected override async Task <ZXing.Result> ScanNative(string topText, string bottomText, string cameraUnsupportedMessage)
        {
            // Current activity
            var currentActivity = Mvx.IoCProvider.Resolve <IMvxAndroidCurrentTopActivity>().Activity;

            // Initialize the scanner first so we can track the current context
            MobileBarcodeScanner.Initialize(currentActivity.Application);

            // Create a new instance of our scanner
            var scanner = new MobileBarcodeScanner
            {
                UseCustomOverlay         = false, // Use the default overlay
                TopText                  = topText,
                BottomText               = bottomText,
                CameraUnsupportedMessage = cameraUnsupportedMessage
            };

            try
            {
                // Add option for use correct resolution for mobile
                var options = new MobileBarcodeScanningOptions()
                {
                    CameraResolutionSelector = new CameraResolutionSelectorDelegate(ResolutionSelector)
                };

                // Start scanning
                return(await scanner.Scan(options));
            }
            finally
            {
                // Uninitialize the scanner to avoid memory leaks
                MobileBarcodeScanner.Uninitialize(currentActivity.Application);
            }
        }
Example #21
0
        private async void BtnTest_Click(object sender, EventArgs e)
        {
            var intent = new Intent("Xamarin.Broadcast.Test2");

            SendBroadcast(intent);
            //
            ZXing.Mobile.MobileBarcodeScanner.Initialize(Application);
            ZXing.Mobile.MobileBarcodeScanner scanner = new MobileBarcodeScanner();
            try
            {
                var result = await scanner.Scan();

                if (!string.IsNullOrEmpty(result.Text))
                {
                    ScanResultHandle(result);
                }
            }
            catch (Exception exception)
            {
                //Console.WriteLine(exception);
                //throw;
            }


            //throw new NotImplementedException();
        }
Example #22
0
        private async void StartGame()
        {
            var scannerOptions = new MobileBarcodeScanningOptions
            {
                PossibleFormats = new List <BarcodeFormat>
                {
                    BarcodeFormat.QR_CODE
                }
            };
            var scanner = new MobileBarcodeScanner
            {
                TopText          = "Zeskanuj kod startowy",
                CancelButtonText = "Anuluj"
            };

            var scanResult = await scanner.Scan(scannerOptions);

            if (scanResult != null &&
                VerifyStartingCode(scanResult.Text))
            {
                _gameStateService.StartGame();
                ShowViewModelAndClearBackStack <GameViewModel>();
            }
            else
            {
                _dialogInteraction.Raise(new DialogInteraction
                {
                    Title = "Niepoprawny kod",
                    Text  = "Kod, który próbujesz zeskanować jest niepoprawny, lub nie nadaje się do zeskanowania w tym momencie gry. Skontaktuj się z organizatorem."
                });
            }
        }
        async void doScan()
        {
            continueScan = false;
            var result = await scanner.Scan();

            HandleScanResult(result);
        }
Example #24
0
        public async Task <BarCodeResult> Read(BarCodeReadConfiguration config, CancellationToken cancelToken)
        {
            config = config ?? BarCodeReadConfiguration.Default;
#if __IOS__
            var scanner = new MobileBarcodeScanner {
                UseCustomOverlay = false
            };
#elif __ANDROID__
            var topActivity = Mvx.Resolve <Cirrious.CrossCore.Droid.Platform.IMvxAndroidCurrentTopActivity>().Activity;
            var scanner     = new MobileBarcodeScanner(topActivity)
            {
                UseCustomOverlay = false
            };
#elif WINDOWS_PHONE
            var scanner = new MobileBarcodeScanner(System.Windows.Deployment.Current.Dispatcher)
            {
                UseCustomOverlay = false
            };
#endif
            cancelToken.Register(scanner.Cancel);

            var result = await scanner.Scan(this.GetXingConfig(config));

            return(result == null || String.IsNullOrWhiteSpace(result.Text)
                ? BarCodeResult.Fail
                : new BarCodeResult(result.Text, FromXingFormat(result.BarcodeFormat))
                   );
        }
Example #25
0
        public async void Scan()
        {
            scanner.UseCustomOverlay = true;
            var options = new MobileBarcodeScanningOptions()
            {
                AutoRotate  = false,
                TryInverted = true
            };

            zxingOverlay = LayoutInflater.FromContext(Android.App.Application.Context).Inflate(Resource.Layout.ScanCustom, null);
            //zxingOverlay.scree

            flashButton        = zxingOverlay.FindViewById <Android.Widget.Button>(Resource.Id.buttonFlash);
            flashButton.Click += (sender, e) =>
            {
                if (flashButton.Text == "Tắt Flash")
                {
                    flashButton.Text = "Bật Flash";
                }
                else
                {
                    flashButton.Text = "Tắt Flash";
                }
                scanner.ToggleTorch();
            };
            scanner.CustomOverlay = zxingOverlay;

            //scanner.TopText = "Giữ camera cách mã khoảng 6inch";
            //scanner.BottomText = "Đợi một chút...";

            var result = await scanner.Scan(options);

            System.Diagnostics.Debug.WriteLine("Đợi két quả");
            HandleScanResult(result);
        }
        public Java.Lang.String UITestBackdoorScan(string param)
        {
            var expectedFormat = BarcodeFormat.QR_CODE;

            Enum.TryParse(param, out expectedFormat);
            var opts = new MobileBarcodeScanningOptions {
                PossibleFormats = new List <BarcodeFormat> {
                    expectedFormat
                }
            };
            var barcodeScanner = new MobileBarcodeScanner();

            Console.WriteLine("Scanning " + expectedFormat);

            //Start scanning
            barcodeScanner.Scan(opts).ContinueWith(t => {
                var result = t.Result;

                var format = result?.BarcodeFormat.ToString() ?? string.Empty;
                var value  = result?.Text ?? string.Empty;

                RunOnUiThread(() => {
                    AlertDialog dialog = null;
                    dialog             = new AlertDialog.Builder(this)
                                         .SetTitle("Barcode Result")
                                         .SetMessage(format + "|" + value)
                                         .SetNeutralButton("OK", (sender, e) => {
                        dialog.Cancel();
                    }).Create();
                    dialog.Show();
                });
            });

            return(new Java.Lang.String());
        }
Example #27
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();
            }
        }
Example #28
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            try
            {
                var app = new Android.App.Application();
                MobileBarcodeScanner.Initialize(app);

                var scanner = new MobileBarcodeScanner();
                scanner.TopText    = "Hold the camera up to the QR code\nAbout 6 inches away";
                scanner.BottomText = "Wait for the QR code to automatically scan!";

                //This will start scanning
                ZXing.Result result = await scanner.Scan();

                string[] lines = result.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

                ProductsModel productsModel = new ProductsModel()
                {
                    ProductId          = lines[0].Substring(lines[0].IndexOf('-') + 1),
                    SerialNo           = "1",
                    ProductDescription = lines[1].Substring(lines[1].IndexOf('-') + 1),
                    UnitPrice          = lines[2].Substring(lines[2].IndexOf('-') + 1),
                    SellPrice          = lines[3].Substring(lines[3].IndexOf('-') + 1),
                    Quantity           = lines[4].Substring(lines[4].IndexOf('-') + 1)
                };
                await Navigation.PushAsync(new ProductListPage(productsModel, UserId));
            }
            catch (Exception ex)
            {
                //await DisplayAlert("Error", ex.Message, "Ok");
            }
        }
Example #29
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            ProductDB.Init();
            SetContentView(Resource.Layout.Main);
            MobileBarcodeScanner.Initialize(Application);
            _barcodeScanner = new MobileBarcodeScanner();

            Button scanButton = this.FindViewById <Button>(Resource.Id.scanButton);

            scanButton.Click += async delegate
            {
                _barcodeScanner.UseCustomOverlay = false;
                //We can customize the top and bottom text of the default overlay
                _barcodeScanner.TopText    = "Hold the camera up to the barcode\nAbout 6 inches away";
                _barcodeScanner.BottomText = "Wait for the barcode to automatically scan!";

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

                HandleScanResult(result);
            };

            Button listButton = FindViewById <Button>(Resource.Id.listButton);

            listButton.Click += delegate
            {
                Intent intent = new Intent(this, typeof(ProductList));
                StartActivity(intent);
            };
        }
Example #30
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            if (!telaCriada)
            {
                base.OnCreate(savedInstanceState);
                SetContentView(Resource.Layout.RegistrarPulseira);

                btnBuscarUsuarioRegistroPulseira = FindViewById <Button>(Resource.Id.btnBuscarUsuarioRegistroPulseira);
                _usuarioListView = FindViewById <ListView>(Resource.Id.lstUsuario);


                if (_usuarioListView != null)
                {
                    _usuarioListView.ItemClick += async(object sender, AdapterView.ItemClickEventArgs e) =>
                    {
                        var scanner = new MobileBarcodeScanner();
                        var result  = await scanner.Scan();

                        if (result != null)
                        {
                            ValidarPulseira(result.Text);
                        }
                    };
                }


                if (btnBuscarUsuarioRegistroPulseira != null)
                {
                    btnBuscarUsuarioRegistroPulseira.Click += (sender, e) =>
                    {
                        Atualizar();
                    };
                }
            }
        }