Ejemplo n.º 1
5
        public ZXingScannerPage (MobileBarcodeScanningOptions options = null, View customOverlay = null) : base ()
        {
            zxing = new ZXingScannerView
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Options = options
            };

            zxing.OnScanResult += (result) => {
                var eh = this.OnScanResult;
                if (eh != null)
                    eh(result);
                    //Device.BeginInvokeOnMainThread (() => eh (result));
            };

            if (customOverlay == null) {
                defaultOverlay = new ZXingDefaultOverlay {
                    TopText = "Hold your phone up to the barcode",
                    BottomText = "Scanning will happen automatically",
                    ShowFlashButton = zxing.HasTorch,
                };
                defaultOverlay.FlashButtonClicked += (sender, e) => {
                    zxing.IsTorchOn = !zxing.IsTorchOn;
                };
                Overlay = defaultOverlay;
            } else {
                Overlay = customOverlay;
            }

            var grid = new Grid
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            grid.Children.Add(zxing);
            grid.Children.Add(Overlay);

            // The root page of your application
            Content = grid;
        }
Ejemplo n.º 2
3
        public void Scan()
        {
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
            options.PossibleFormats = new List<ZXing.BarcodeFormat>() {
                ZXing.BarcodeFormat.PDF_417
            };
            options.TryHarder = true;
            options.AutoRotate = true;
            options.TryInverted = true;

            
            var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
            //Tell our scanner to use the default overlay
            scanner.UseCustomOverlay = false;
            scanner.CameraUnsupportedMessage = "This Device's Camera is not supported.";
            
            //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!";
            scanner.Scan(options).ContinueWith(t => {   
                if (t.Result != null)
                {
                    System.Console.WriteLine("Scanned Barcode: " + t.Result.Text);
                    Toast.MakeText(this, t.Result.Text, ToastLength.Short);
                }
            });
        }
Ejemplo n.º 3
3
        public ZXingScannerPage (MobileBarcodeScanningOptions options = null, View customOverlay = null) : base ()
        {
            zxing = new ZXingScannerView
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Options = options,
                AutomationId = "zxingScannerView"
            };

            zxing.SetBinding( ZXingScannerView.IsTorchOnProperty, new Binding( nameof( IsTorchOn ) ) );
            zxing.SetBinding( ZXingScannerView.IsAnalyzingProperty, new Binding( nameof( IsAnalyzing ) ) );
            zxing.SetBinding( ZXingScannerView.IsScanningProperty, new Binding( nameof( IsScanning ) ) );
            zxing.SetBinding( ZXingScannerView.HasTorchProperty, new Binding( nameof( HasTorch ) ) );
            zxing.SetBinding( ZXingScannerView.ResultProperty, new Binding( nameof( Result ) ) );

            zxing.OnScanResult += (result) => {
                this.OnScanResult?.Invoke( result );
                //Device.BeginInvokeOnMainThread (() => eh (result));
            };

            if (customOverlay == null) {
                defaultOverlay = new ZXingDefaultOverlay () { AutomationId = "zxingDefaultOverlay" };

                defaultOverlay.SetBinding( ZXingDefaultOverlay.TopTextProperty, new Binding( nameof( DefaultOverlayTopText ) ) );
                defaultOverlay.SetBinding( ZXingDefaultOverlay.BottomTextProperty, new Binding( nameof( DefaultOverlayBottomText ) ) );
                defaultOverlay.SetBinding( ZXingDefaultOverlay.ShowFlashButtonProperty, new Binding( nameof( DefaultOverlayShowFlashButton ) ) );

                DefaultOverlayTopText = "Hold your phone up to the barcode";
                DefaultOverlayBottomText = "Scanning will happen automatically";
                DefaultOverlayShowFlashButton = HasTorch;

                defaultOverlay.FlashButtonClicked += (sender, e) => {
                    zxing.IsTorchOn = !zxing.IsTorchOn;
                };

                Overlay = defaultOverlay;
            } else {
                Overlay = customOverlay;
            }

            var grid = new Grid
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            grid.Children.Add(zxing);
            grid.Children.Add(Overlay);

            // The root page of your application
            Content = grid;
        }
Ejemplo n.º 4
1
        void scan ()
        {
            var opts = new MobileBarcodeScanningOptions {
                PossibleFormats = new List<ZXing.BarcodeFormat> {
                    ZXing.BarcodeFormat.QR_CODE
                },
                CameraResolutionSelector = availableResolutions => {

                    foreach (var ar in availableResolutions) {
                        Console.WriteLine ("Resolution: " + ar.Width + "x" + ar.Height);
                    }
                    return null;
                }
            };

            scanFragment.StartScanning (opts, result => {

                // Null result means scanning was cancelled
                if (result == null || string.IsNullOrEmpty (result.Text)) {
                    Toast.MakeText (this, "Scanning Cancelled", ToastLength.Long).Show ();
                    return;
                }

                // Otherwise, proceed with result
                RunOnUiThread (() => Toast.MakeText (this, "Scanned: " + result.Text, ToastLength.Short).Show ());
            });
        }
        public override void ScanContinuously (MobileBarcodeScanningOptions options, Action<Result> scanHandler)
        {                
            var scanIntent = new Intent(lifecycleListener.Context, typeof(ZxingActivity));

            scanIntent.AddFlags(ActivityFlags.NewTask);

            ZxingActivity.UseCustomOverlayView = this.UseCustomOverlay;
            ZxingActivity.CustomOverlayView = this.CustomOverlay;
            ZxingActivity.ScanningOptions = options;
            ZxingActivity.ScanContinuously = true;
            ZxingActivity.TopText = TopText;
            ZxingActivity.BottomText = BottomText;

            ZxingActivity.OnCanceled += () => 
            {
                ZxingActivity.RequestCancel ();
            };

            ZxingActivity.OnScanCompleted += (Result result) => 
            {
                if (scanHandler != null)
                    scanHandler (result);
            };

            lifecycleListener.Context.StartActivity(scanIntent);
        }
Ejemplo n.º 6
0
        private async Task scanBarcode()
        {
            //Creates the barcode scanner and adds camera
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions
            {
                CameraResolutionSelector = HandleCameraResolutionSelectorDelegate
            };

            options.PossibleFormats = new List <ZXing.BarcodeFormat>()
            {
                ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13
            };

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

            scanner.AutoFocus();

            //Grabs the scanner result and displays it in the new page
            //The new page is the itemController
            var result = await scanner.Scan(options, true);

            string code = result.Text;

            if (result != null)
            {
                ItemController controller = new ItemController();
                this.NavigationController.PushViewController(controller, true);
                controller.barCodeLableText = code;
                controller.itemNameText     = "Bandage, Adhsv Shr Strp 1x3 (100/bx 24bx/cs) Mgm16";
                controller.itemNumberText   = "15";
                //controller.addLabelText = query;

                Console.WriteLine("Scanned Barcode: " + result.Text);
            }
        }
Ejemplo n.º 7
0
        public ZxingCameraViewController(MobileBarcodeScanningOptions options, MobileBarcodeScanner scanner)
            : base()
        {
			this.ScanningOptions = options;
			this.Scanner = scanner;
            Initialize();
        }
        public override Task<Result> Scan(MobileBarcodeScanningOptions options)
        {
            return Task.Factory.StartNew(new Func<Result>(() =>
            {
                var scanResultResetEvent = new System.Threading.ManualResetEvent(false);

                Result result = null;

                //Navigate: /ZxingSharp.WindowsPhone;component/Scan.xaml

                ScanPage.ScanningOptions = options;
                ScanPage.ResultFoundAction = (r) => 
                {
                    result = r;
                    scanResultResetEvent.Set();
                };

                ScanPage.UseCustomOverlay = this.UseCustomOverlay;
                ScanPage.CustomOverlay = this.CustomOverlay;
                ScanPage.TopText = TopText;
                ScanPage.BottomText = BottomText;

                Dispatcher.BeginInvoke(() =>
				{
					((Microsoft.Phone.Controls.PhoneApplicationFrame)Application.Current.RootVisual).Navigate(
						new Uri("/ZXingNetMobile;component/ScanPage.xaml", UriKind.Relative));
				});

                scanResultResetEvent.WaitOne();

                return result;
            }));            
        }
Ejemplo n.º 9
0
        private async void startScanning()
        {
            _scanning = true;
            Core.ViewModels.CheckInViewModel viewModel = (this.ViewModel as Core.ViewModels.CheckInViewModel);
            viewModel.IsBusy = true;

            var scanner = new ZXing.Mobile.MobileBarcodeScanner(this.Activity);
            scanner.UseCustomOverlay = true;
            scanner.CustomOverlay = LayoutInflater.FromContext(this.Activity).Inflate(Resource.Layout.ZXingCustomLayout, null);
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
            options.PossibleFormats = new List<ZXing.BarcodeFormat>() { ZXing.BarcodeFormat.QR_CODE };
            await scanner.Scan(options).ContinueWith(t =>
            {
                if (t.Result != null)
                {
                    viewModel.ScannedQRCode = t.Result.Text;
                }
                else
                {
                    viewModel.Message = "The Check In QR code could not be scanned. Please go back and try again.";
                    Task.Delay(500).ContinueWith(async dummy => await viewModel.OnBackButtonPressedAsync());
                }
            });
            viewModel.IsBusy = false;
            _scanning = false;
        }
        public override Task<Result> Scan(MobileBarcodeScanningOptions options)
        {
            var rootFrame = RootFrame ?? Window.Current.Content as Frame ?? ((FrameworkElement) Window.Current.Content).GetFirstChildOfType<Frame>();
            var dispatcher = Dispatcher ?? Window.Current.Dispatcher;

            return Task.Factory.StartNew(new Func<Result>(() =>
            {
                var scanResultResetEvent = new System.Threading.ManualResetEvent(false);

                Result result = null;

                ScanPage.ScanningOptions = options;
                ScanPage.ResultFoundAction = (r) => 
                {
                    result = r;
                    scanResultResetEvent.Set();
                };

                ScanPage.UseCustomOverlay = this.UseCustomOverlay;
                ScanPage.CustomOverlay = this.CustomOverlay;
                ScanPage.TopText = TopText;
                ScanPage.BottomText = BottomText;

                dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    rootFrame.Navigate(typeof(ScanPage));
                });
                
                scanResultResetEvent.WaitOne();

                return result;
            }));            
        }
Ejemplo n.º 11
0
        public async Task <string> ScanAsync()
        {
            var app = new Android.App.Application();

            MobileBarcodeScanner.Initialize(app);

            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();

            options.PossibleFormats = new List <ZXing.BarcodeFormat>()
            {
                ZXing.BarcodeFormat.QR_CODE
            };

            var scanner = new ZXing.Mobile.MobileBarcodeScanner();
            var result  = await scanner.Scan(options);

            if (result != null)
            {
                return(result.Text);
            }
            else
            {
                return(null);
            }
        }
        public async Task ScanCode()
        {
            MobileBarcodeScanner scanner;
            scanner = new MobileBarcodeScanner();
            

            

  
                       
            //scannerO.TryHarder = true;
            
            //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 = "Camera will automatically scan barcode\r\n\r\nPress the 'Back' button to Cancel";
           

            var options = new MobileBarcodeScanningOptions();
            //options.CameraResolutionSelector = ;
            //options.PossibleFormats = new List<ZXing.BarcodeFormat>() {ZXing.BarcodeFormat.Ean8, ZXing.BarcodeFormat.Ean13};



            //options.PossibleFormats = new List<ZXing.BarcodeFormat>() { ZXing.BarcodeFormat.PDF_417 };
            //options.TryHarder = false;
           
            //options.UseNativeScanning = true;

 
            var result = await scanner.Scan(options);
            HandleScanResult(result);
        }
Ejemplo n.º 13
0
        public override async Task<Result> Scan(MobileBarcodeScanningOptions options)
        {
            var rootFrame = RootFrame ?? Window.Current.Content as Frame ?? ((FrameworkElement) Window.Current.Content).GetFirstChildOfType<Frame>();
            var dispatcher = Dispatcher ?? Window.Current.Dispatcher;

            var tcsScanResult = new TaskCompletionSource<Result>();

            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                rootFrame.Navigate(typeof(ScanPage), new ScanPageNavigationParameters
                {
                    Options = options,
                    ResultHandler = r =>
                    {
                        tcsScanResult.SetResult(r);
                    },
                    Scanner = this,
                    ContinuousScanning = false
                });
            });
            
            var result = await tcsScanResult.Task;

            await dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            {
                if (rootFrame.CanGoBack)
                    rootFrame.GoBack();
            });

            return result;
        }
Ejemplo n.º 14
0
        public ZXingSurfaceView (Activity activity, MobileBarcodeScanningOptions options)
            : base (activity)
        {
            this.activity = activity;
            this.scanningOptions = options;

            Init ();
        }
Ejemplo n.º 15
0
		public ZxingViewController(MobileBarcodeScanningOptions options, bool showButtons, bool showOverlay) : base()
		{
			this.Options = options;
			this.ShowButtons = showButtons;
			this.ShowOverlay = showOverlay;

			this.resxMgr = new ResourceManager("Resources", System.Reflection.Assembly.GetExecutingAssembly());
		}
Ejemplo n.º 16
0
		async public void Scannit()
        {
			var scanner = new MobileBarcodeScanner ();
            var opt = new MobileBarcodeScanningOptions();
            opt.PossibleFormats.Clear();
            opt.PossibleFormats.Add(ZXing.BarcodeFormat.QR_CODE);
            var result = await scanner.Scan(opt);
            HandleResult(result);
        }
Ejemplo n.º 17
0
 public ScanController()
 {
     ScanningOptions = new MobileBarcodeScanningOptions();
     ScanningOptions.AutoRotate = false;
     ScanningOptions.PossibleFormats = new List<BarcodeFormat>()
     {
         BarcodeFormat.QR_CODE
     };
 }
Ejemplo n.º 18
0
        private void SetScanOptions()
        {
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();

            //options.TryHarder = true;
            //options.TryInverted = true;
            //options.AutoRotate = true;
            options.PossibleFormats = new List <ZXing.BarcodeFormat>
            {
                ZXing.BarcodeFormat.QR_CODE
            };
            if (Parameters.Options.AcceptBarcode_Code)
            {
                options.PossibleFormats.Append(ZXing.BarcodeFormat.CODE_39);
                options.PossibleFormats.Append(ZXing.BarcodeFormat.CODE_93);
                options.PossibleFormats.Append(ZXing.BarcodeFormat.CODE_128);
                options.PossibleFormats.Append(ZXing.BarcodeFormat.CODABAR);
            }
            if (Parameters.Options.AcceptBarcode_Ean)
            {
                options.PossibleFormats.Append(ZXing.BarcodeFormat.EAN_8);
                options.PossibleFormats.Append(ZXing.BarcodeFormat.EAN_13);
            }
            if (Parameters.Options.AcceptBarcode_Upc)
            {
                options.PossibleFormats.Append(ZXing.BarcodeFormat.UPC_A);
                options.PossibleFormats.Append(ZXing.BarcodeFormat.UPC_E);
                options.PossibleFormats.Append(ZXing.BarcodeFormat.UPC_EAN_EXTENSION);
            }

            // solve camera resolution bug (up to ZXing 3.1.0 beta2)
            options.CameraResolutionSelector = new CameraResolutionSelectorDelegate((List <CameraResolution> availableResolutions) =>
            {
                CameraResolution result = null;

                double aspectTolerance       = 0.1;
                var displayOrientationHeight = DeviceDisplay.MainDisplayInfo.Orientation == DisplayOrientation.Portrait ? DeviceDisplay.MainDisplayInfo.Height : DeviceDisplay.MainDisplayInfo.Width;
                var displayOrientationWidth  = DeviceDisplay.MainDisplayInfo.Orientation == DisplayOrientation.Portrait ? DeviceDisplay.MainDisplayInfo.Width : DeviceDisplay.MainDisplayInfo.Height;

                var targetRatio  = displayOrientationHeight / displayOrientationWidth;
                var targetHeight = displayOrientationHeight;
                var minDiff      = double.MaxValue;

                foreach (var r in availableResolutions.Where(r => Math.Abs(((double)r.Width / r.Height) - targetRatio) < aspectTolerance))
                {
                    if (Math.Abs(r.Height - targetHeight) < minDiff)
                    {
                        minDiff = Math.Abs(r.Height - targetHeight);
                    }
                    result = r;
                }
                return(result);
            });

            zxing.Options = options;
        }
		public AVCaptureScannerViewController(MobileBarcodeScanningOptions options, MobileBarcodeScanner scanner)
		{
			this.ScanningOptions = options;
			this.Scanner = scanner;

			var appFrame = UIScreen.MainScreen.ApplicationFrame;

			View.Frame = new CGRect(0, 0, appFrame.Width, appFrame.Height);
			View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
		}
Ejemplo n.º 20
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = UIColor.White;

            webView = new UIWebView(View.Bounds);
            View.AddSubview(webView);
            webView.ShouldStartLoad = (webView, request, navType) =>
            {
//                System.Console.WriteLine("###" + request.Url.AbsoluteString);
                if (request.Url.AbsoluteString == "myapp://scan")
                {
                    var options = new ZXing.Mobile.MobileBarcodeScanningOptions
                    {
                        PossibleFormats = new List <ZXing.BarcodeFormat>()
                        {
                            ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13, ZXing.BarcodeFormat.CODE_128
                        }
                    };

                    var scanner = new ZXing.Mobile.MobileBarcodeScanner
                    {
                        //                    scanner.ScanContinuously(HandleScanResult);
                        TopText    = "Поднесите камеру к штрих-коду для сканирования",
                        BottomText = "Штрих-код будет автоматически отсканирован"
                    };
                    scanner.Scan(options).ContinueWith(t => {
                        var result = t.Result;

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

                        BeginInvokeOnMainThread(() => {
                            if (value != null && !string.IsNullOrEmpty(value))
                            {
                                webView.EvaluateJavascript("location.href = '/search?q=" + value + "';");
                            }
//                            var av = UIAlertController.Create("Barcode Result", format + "|" + value, UIAlertControllerStyle.Alert);
//                            av.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Cancel, null));
//                            PresentViewController(av, true, null);
                        });
                    });
                }
                return(true);
            };
            var url = "https://mobile.kcentr.ru";

            webView.LoadRequest(new NSUrlRequest(new NSUrl(url)));

            // if this is false, page will be 'zoomed in' to normal size
            webView.ScalesPageToFit = false;
        }
Ejemplo n.º 21
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));
            };
        }
        public void ScanContinuously (MobileBarcodeScanningOptions options, bool useAVCaptureEngine, Action<Result> scanHandler)
        {
            try
            {             
                Version sv = new Version (0, 0, 0);
                Version.TryParse (UIDevice.CurrentDevice.SystemVersion, out sv);

                var is7orgreater = sv.Major >= 7;
                var allRequestedFormatsSupported = true;

                if (useAVCaptureEngine)
                    allRequestedFormatsSupported = AVCaptureScannerView.SupportsAllRequestedBarcodeFormats(options.PossibleFormats);

                this.appController.InvokeOnMainThread(() => {


                    if (useAVCaptureEngine && is7orgreater && allRequestedFormatsSupported)
                    {
                        viewController = new AVCaptureScannerViewController(options, this);
                        viewController.ContinuousScanning = true;
                    }
                    else
                    {           
                        if (useAVCaptureEngine && !is7orgreater)
                            Console.WriteLine("Not iOS 7 or greater, cannot use AVCapture for barcode decoding, using ZXing instead");
                        else if (useAVCaptureEngine && !allRequestedFormatsSupported)
                            Console.WriteLine("Not all requested barcode formats were supported by AVCapture, using ZXing instead");

                        viewController = new ZXing.Mobile.ZXingScannerViewController(options, this);
                        viewController.ContinuousScanning = true;
                    }

                    viewController.OnScannedResult += barcodeResult => {

                        // If null, stop scanning was called
                        if (barcodeResult == null) {
                            ((UIViewController)viewController).InvokeOnMainThread(() => {
                                ((UIViewController)viewController).DismissViewController(true, null);
                            });
                        }

                        scanHandler (barcodeResult);
                    };

                    appController.PresentViewController((UIViewController)viewController, true, null);
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        public ZxingCameraViewController(MobileBarcodeScanningOptions options, MobileBarcodeScanner scanner)
            : base()
        {
			this.ScanningOptions = options;
			this.Scanner = scanner;

			_observer = NSNotificationCenter.DefaultCenter.AddObserver(
				UIApplication.DidEnterBackgroundNotification, n => {
				DismissViewController();
			});

            Initialize();
        }
Ejemplo n.º 24
0
        public async void ShowQRScanner()
        {
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();

            options.PossibleFormats = new List <ZXing.BarcodeFormat>()
            {
                ZXing.BarcodeFormat.QR_CODE
            };
            ShowLoading();
            var result = await Scan(options);

            HideLoading();
            presenter.SetSacnnerResult(result?.Text);
        }
Ejemplo n.º 25
0
		public override Task<Result> Scan (MobileBarcodeScanningOptions options)
		{
			return Task.Factory.StartNew(() => {

				try
				{
					var scanResultResetEvent = new System.Threading.ManualResetEvent(false);
					Result result = null;

					this.appController.InvokeOnMainThread(() => {
						// Free memory first and release resources
						if (viewController != null)
						{
							viewController.Dispose();
							viewController = null;
						}

						viewController = new ZxingCameraViewController(options, this);

						viewController.BarCodeEvent += (BarCodeEventArgs e) => {

							viewController.DismissViewController();

							result = e.BarcodeResult;
							scanResultResetEvent.Set();

						};

						viewController.Canceled += (sender, e) => {

							viewController.DismissViewController();

							scanResultResetEvent.Set();
						};

						appController.PresentViewController(viewController, true, () => { });

					});

					scanResultResetEvent.WaitOne();

					return result;
				}
				catch (Exception ex)
				{
					return null;
				}
			});

		}
		public ZXingSurfaceView (Activity activity, MobileBarcodeScanningOptions options, Action<ZXing.Result> callback)
			: base (activity)
		{
			this.activity = activity;
			this.callback = callback;
			this.options = options;

			lastPreviewAnalysis = DateTime.Now.AddMilliseconds(options.InitialDelayBeforeAnalyzingFrames);

			this.surface_holder = Holder;
			this.surface_holder.AddCallback (this);
			this.surface_holder.SetType (SurfaceType.PushBuffers);
			
			this.tokenSource = new System.Threading.CancellationTokenSource();
		}
Ejemplo n.º 27
0
        public void StartScanning(Action <Result> scanResultCallback, MobileBarcodeScanningOptions options = null)
        {
            this.callback        = scanResultCallback;
            this.scanningOptions = options ?? MobileBarcodeScanningOptions.Default;

            if (surfaceCreated)
            {
                OnSurfaceCreated();
            }

            if (surfaceChanged)
            {
                OnSurfaceChanged();
            }
        }
Ejemplo n.º 28
0
        public ZXingScannerViewController(MobileBarcodeScanningOptions options, MobileBarcodeScanner scanner)
        {
            this.ScanningOptions = options;
            this.Scanner         = scanner;

            var appFrame = UIScreen.MainScreen.ApplicationFrame;

            this.View.Frame            = new CGRect(0, 0, appFrame.Width, appFrame.Height);
            this.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;

            if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
            {
                this.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
            }
        }
Ejemplo n.º 29
0
        public ZXingSurfaceView(Activity activity, MobileBarcodeScanningOptions options, Action <ZXing.Result> callback)
            : base(activity)
        {
            //this.activity = activity;
            this.callback = callback;
            this.options  = options;

            lastPreviewAnalysis = DateTime.Now.AddMilliseconds(options.InitialDelayBeforeAnalyzingFrames);

            this.surface_holder = Holder;
            this.surface_holder.AddCallback(this);
            this.surface_holder.SetType(SurfaceType.PushBuffers);

            this.tokenSource = new System.Threading.CancellationTokenSource();
        }
Ejemplo n.º 30
0
        public void StartScanning(Action <Result> scanResultHandler, MobileBarcodeScanningOptions options = null)
        {
            if (!stopped)
            {
                return;
            }

            stopped = false;

            var perf = PerformanceCounter.Start();

            Setup(this.Frame);

            this.options        = options ?? MobileBarcodeScanningOptions.Default;
            this.resultCallback = scanResultHandler;

            Console.WriteLine("StartScanning");

            this.InvokeOnMainThread(() => {
                if (!SetupCaptureSession())
                {
                    //Setup 'simulated' view:
                    Console.WriteLine("Capture Session FAILED");
                }

                if (Runtime.Arch == Arch.SIMULATOR)
                {
                    var simView              = new UIView(new CGRect(0, 0, this.Frame.Width, this.Frame.Height));
                    simView.BackgroundColor  = UIColor.LightGray;
                    simView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
                    this.InsertSubview(simView, 0);
                }
            });

            if (!analyzing)
            {
                analyzing = true;
            }

            PerformanceCounter.Stop(perf, "PERF: StartScanning() Took {0} ms.");

            var evt = this.OnScannerSetupComplete;

            if (evt != null)
            {
                evt();
            }
        }
Ejemplo n.º 31
0
        public void StartScanning(Action <ZXing.Result> scanCallback, MobileBarcodeScanningOptions options = null)
        {
            ScanCallback    = scanCallback;
            ScanningOptions = options ?? MobileBarcodeScanningOptions.Default;

            this.topText.Text    = TopText;
            this.bottomText.Text = BottomText;

            if (UseCustomOverlay)
            {
                gridCustomOverlay.Children.Clear();
                if (CustomOverlay != null)
                {
                    gridCustomOverlay.Children.Add(CustomOverlay);
                }

                gridCustomOverlay.Visibility  = Visibility.Visible;
                gridDefaultOverlay.Visibility = Visibility.Collapsed;
            }
            else
            {
                gridCustomOverlay.Visibility  = Visibility.Collapsed;
                gridDefaultOverlay.Visibility = Visibility.Visible;
            }

            MobileBarcodeScanner.Log("ZXingScannerControl.StartScanning");

            // Initialize a new instance of SimpleCameraReader with Auto-Focus mode on
            if (_reader == null)
            {
                MobileBarcodeScanner.Log("Creating SimpleCameraReader");

                //_reader = new SimpleCameraReader(options);
                _reader = new AudioVideoCaptureDeviceCameraReader(options);
                _reader.ScanInterval = ScanningOptions.DelayBetweenAnalyzingFrames;

                // AudioVideoCaptureDevice - move this to camera initialized otherwise throws
                // We need to set the VideoBrush we're going to display the preview feed on
                // IMPORTANT that it gets set before Camera initializes
                //_previewVideo.SetSource(_reader.Camera);

                // The reader throws an event when a result is available
                _reader.DecodingCompleted += (o, r) => DisplayResult(r);

                // The reader throws an event when the camera is initialized and ready to use
                _reader.CameraInitialized += ReaderOnCameraInitialized;
            }
        }
Ejemplo n.º 32
0
        public void StartScanning(Action <Result> scanResultCallback, MobileBarcodeScanningOptions options = null)
        {
            //fix Android 7 bug: camera freezes because surfacedestroyed function isn't always called correct, the old surfaceview was still visible.
            this.Visibility = ViewStates.Visible;

            //make sure the camera is setup
            _cameraAnalyzer.SetupCamera();

            ScanningOptions = options ?? MobileBarcodeScanningOptions.Default;

            _cameraAnalyzer.BarcodeFound += (sender, result) =>
            {
                scanResultCallback?.Invoke(result);
            };
            _cameraAnalyzer.ResumeAnalysis();
        }
Ejemplo n.º 33
0
		void buttonSample2_Click (object sender, EventArgs e)
		{
			var scanner = new MobileBarcodeScanner(this);
			var options = new MobileBarcodeScanningOptions()
			{
				PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.All_1D },

			};

			scanner.TopText = "Hold the barcode close to the camera";
			scanner.BottomText = "Barcode will scan automatigically";

			scanner.Scan(options).ContinueWith((t) => {
				ShowMessage(t.Result != null ? "Scanned: " + t.Result.Text : "No Barcode Scanned");
			});
		}
Ejemplo n.º 34
0
		public async void ScanQRCode()
		{
			var scanner = new ZXing.Mobile.MobileBarcodeScanner ();
			var options = new ZXing.Mobile.MobileBarcodeScanningOptions ();

			options.TryHarder = true;
			options.PossibleFormats.Add (ZXing.BarcodeFormat.QR_CODE);

			var result = await scanner.Scan(options);

			if (result != null) {
				Debug.WriteLine ("Scanned barcode: " + result.Text);
			
				RecordAttandance (result.Text);
			}

		}
Ejemplo n.º 35
0
 public override async void ScanContinuously(MobileBarcodeScanningOptions options, Action<Result> scanHandler)
 {
     //Navigate: /ZxingSharp.WindowsPhone;component/Scan.xaml
     var rootFrame = RootFrame ?? Window.Current.Content as Frame ?? ((FrameworkElement) Window.Current.Content).GetFirstChildOfType<Frame>();
     var dispatcher = Dispatcher ?? Window.Current.Dispatcher;
     
     await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         rootFrame.Navigate(typeof(ScanPage), new ScanPageNavigationParameters
         {
             Options = options,
             ResultHandler = scanHandler,
             Scanner = this,
             ContinuousScanning = true
         });
     });
 }
        public override async void ScanContinuously(MobileBarcodeScanningOptions options, Action <Result> scanHandler)
        {
            //Navigate: /ZxingSharp.WindowsPhone;component/Scan.xaml
            var rootFrame  = RootFrame ?? Window.Current.Content as Frame ?? ((FrameworkElement)Window.Current.Content).GetFirstChildOfType <Frame>();
            var dispatcher = Dispatcher ?? Window.Current.Dispatcher;

            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                rootFrame.Navigate(typeof(ScanPage), new ScanPageNavigationParameters
                {
                    Options            = options,
                    ResultHandler      = scanHandler,
                    Scanner            = this,
                    ContinuousScanning = true
                });
            });
        }
        public void StartScanning(Action<ZXing.Result> scanCallback, MobileBarcodeScanningOptions options = null)
        {
            ScanCallback = scanCallback;
            ScanningOptions = options ?? MobileBarcodeScanningOptions.Default;

            this.topText.Text = TopText;
            this.bottomText.Text = BottomText;

            if (UseCustomOverlay)
            {
                gridCustomOverlay.Children.Clear();
                if (CustomOverlay != null)
                    gridCustomOverlay.Children.Add(CustomOverlay);

                gridCustomOverlay.Visibility = Visibility.Visible;
                gridDefaultOverlay.Visibility = Visibility.Collapsed;
            }
            else
            {
                gridCustomOverlay.Visibility = Visibility.Collapsed;
                gridDefaultOverlay.Visibility = Visibility.Visible;
            }

            MobileBarcodeScanner.Log("ZXingScannerControl.StartScanning");

            // Initialize a new instance of SimpleCameraReader with Auto-Focus mode on
            if (_reader == null)
            {
                MobileBarcodeScanner.Log("Creating SimpleCameraReader");

                //_reader = new SimpleCameraReader(options);
                _reader = new AudioVideoCaptureDeviceCameraReader(options);
                _reader.ScanInterval = ScanningOptions.DelayBetweenAnalyzingFrames;

                // AudioVideoCaptureDevice - move this to camera initialized otherwise throws
                // We need to set the VideoBrush we're going to display the preview feed on
                // IMPORTANT that it gets set before Camera initializes
                //_previewVideo.SetSource(_reader.Camera);

                // The reader throws an event when a result is available 
                _reader.DecodingCompleted += (o, r) => DisplayResult(r);

                // The reader throws an event when the camera is initialized and ready to use
                _reader.CameraInitialized += ReaderOnCameraInitialized;
            }
        }
Ejemplo n.º 38
0
        public async Task <string> ScanAsync()
        {
            var scanner = new ZXing.Mobile.MobileBarcodeScanner
            {
                UseCustomOverlay = true
            };

            var options = new ZXing.Mobile.MobileBarcodeScanningOptions()
            {
                TryHarder  = true,
                AutoRotate = false,
                UseFrontCameraIfAvailable = false,
                CameraResolutionSelector  = new CameraResolutionSelectorDelegate(SelectLowestResolutionMatchingDisplayAspectRatio),
                PossibleFormats           = new List <ZXing.BarcodeFormat>()
                {
                    ZXing.BarcodeFormat.QR_CODE
                }
            };

            View      scanView = LayoutInflater.From(Application.Context).Inflate(Resource.Layout.ScanView, null);
            ImageView imgLine  = scanView.FindViewById <ImageView>(Resource.Id.imgLine);
            ImageView imgClose = scanView.FindViewById <ImageView>(Resource.Id.imgClose);

            imgClose.Click += delegate
            {
                scanner.Cancel();
            };
            scanner.CustomOverlay = scanView;

            ObjectAnimator objectAnimator = ObjectAnimator.OfFloat(imgLine, "Y", 0, DpToPixels(240));

            objectAnimator.SetDuration(2500);
            objectAnimator.RepeatCount = -1;
            objectAnimator.SetInterpolator(new LinearInterpolator());
            objectAnimator.RepeatMode = ValueAnimatorRepeatMode.Restart;
            objectAnimator.Start();

            ZXing.Result scanResults = await scanner.Scan(CrossCurrentActivity.Current.Activity, options);

            if (scanResults != null)
            {
                return(scanResults.Text);
            }
            return(string.Empty);
        }
Ejemplo n.º 39
0
        public ZXingScannerPage(ZXing.Mobile.MobileBarcodeScanningOptions options = null, View customOverlay = null) : base()
        {
            zxing = new ZXingScannerView
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };
            zxing.OnScanResult += (result) => {
                var eh = this.OnScanResult;
                if (eh != null)
                {
                    eh(result);
                }
                //Device.BeginInvokeOnMainThread (() => eh (result));
            };

            if (customOverlay == null)
            {
                defaultOverlay = new ZXingDefaultOverlay {
                    TopText         = "Hold your phone up to the barcode",
                    BottomText      = "Scanning will happen automatically",
                    ShowFlashButton = zxing.HasTorch,
                };
                defaultOverlay.FlashButtonClicked += (sender, e) => {
                    zxing.IsTorchOn = !zxing.IsTorchOn;
                };
                Overlay = defaultOverlay;
            }
            else
            {
                Overlay = customOverlay;
            }

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

            grid.Children.Add(zxing);
            grid.Children.Add(Overlay);

            // The root page of your application
            Content = grid;
        }
Ejemplo n.º 40
0
        public void StartScanning(Action <ZXing.Result> callback, MobileBarcodeScanningOptions options)
        {
            this.options        = options;
            this.resultCallback = callback;

            Console.WriteLine("StartScanning");

            this.InvokeOnMainThread(() => {
                if (!SetupCaptureSession())
                {
                    //Setup 'simulated' view:
                    Console.WriteLine("Capture Session FAILED");
                    var simView             = new UIView(this.Frame);
                    simView.BackgroundColor = UIColor.LightGray;
                    this.AddSubview(simView);
                }
            });
        }
Ejemplo n.º 41
0
        //int width, height;
        //MultiFormatReader reader;
        //BarcodeReader reader;

        public ZxingSurfaceView(ZxingActivity activity, MobileBarcodeScanningOptions options)
            : base(activity)
        {
            this.activity = activity;

            screenResolution = new Size(this.activity.WindowManager.DefaultDisplay.Width, this.activity.WindowManager.DefaultDisplay.Height);

            this.options        = options;
            lastPreviewAnalysis = DateTime.Now.AddMilliseconds(options.InitialDelayBeforeAnalyzingFrames);

            //this.reader = this.options.BuildMultiFormatReader();

            this.surface_holder = Holder;
            this.surface_holder.AddCallback(this);
            this.surface_holder.SetType(SurfaceType.PushBuffers);

            this.tokenSource = new System.Threading.CancellationTokenSource();
        }
        public override Task <Result> Scan(MobileBarcodeScanningOptions options)
        {
            return(Task.Factory.StartNew(() => {
                try
                {
                    var scanResultResetEvent = new System.Threading.ManualResetEvent(false);
                    Result result = null;

                    this.appController.InvokeOnMainThread(() => {
                        // Free memory first and release resources
                        if (viewController != null)
                        {
                            viewController.Dispose();
                            viewController = null;
                        }

                        viewController = new ZxingCameraViewController(options, this);

                        viewController.BarCodeEvent += (BarCodeEventArgs e) => {
                            viewController.DismissViewController();

                            result = e.BarcodeResult;
                            scanResultResetEvent.Set();
                        };

                        viewController.Canceled += (sender, e) => {
                            viewController.DismissViewController();

                            scanResultResetEvent.Set();
                        };

                        appController.PresentViewController(viewController, true, () => { });
                    });

                    scanResultResetEvent.WaitOne();

                    return result;
                }
                catch (Exception ex)
                {
                    return null;
                }
            }));
        }
		public override Task<Result> Scan (MobileBarcodeScanningOptions options)
		{
			return Task.Factory.StartNew(() => {

				try
				{
					scanResultResetEvent.Reset();

					Result result = null;

					this.appController.InvokeOnMainThread(() => {

						//viewController = new ZxingCameraViewController(options, this);
						viewController = new ZXing.Mobile.ZXingScannerViewController(options, this);

						viewController.OnScannedResult += barcodeResult => {

							viewController.InvokeOnMainThread(() => {
								viewController.Cancel();
								viewController.DismissViewController(true, () => {

									result = barcodeResult;
									scanResultResetEvent.Set();

								});
							});
						};

						appController.PresentViewController(viewController, true, null);
					});

					scanResultResetEvent.WaitOne();
					viewController.Dispose();

					return result;
				}
				catch (Exception ex)
				{
					Console.WriteLine(ex);
					return null;
				}
			});

		}
Ejemplo n.º 44
0
        public App()
        {
            var scannedLabel = new Label {
                Text = "Scanned Value",
                HeightRequest = 50,
            };

            var scan = new ScannerView {
                HeightRequest = 400,
                WidthRequest = 400,
                CornerRadius=20,
            };

            var btn = new Button {
                Text = "Push To start scanner",
                HeightRequest=50,
            };
            scan.OnCancelPressed = () => scannedLabel.Text = "Canceled";
            var options = new MobileBarcodeScanningOptions ();
            options.UseFrontCameraIfAvailable = true;
            options.PossibleFormats = new List<ZXing.BarcodeFormat> {
                ZXing.BarcodeFormat.QR_CODE
            };

            btn.Clicked += (s, e) => {
                scan.StartScanner((res)=>{
                    scan.StopScanner();
                    scannedLabel.Text=res.Text;
                },options);
            };

            // The root page of your application
            MainPage = new ContentPage {
                Content = new StackLayout {
                    VerticalOptions = LayoutOptions.Center,
                    HorizontalOptions=LayoutOptions.Center,
                    Children = {
                        scan,
                        scannedLabel,
                        btn
                    }
                }
            };
        }
Ejemplo n.º 45
0
		private MobileBarcodeScanningOptions GetXingConfig(BarCodeReadConfiguration cfg) {
            var opts = new MobileBarcodeScanningOptions {
                AutoRotate = cfg.AutoRotate,
                CharacterSet = cfg.CharacterSet,
                DelayBetweenAnalyzingFrames = cfg.DelayBetweenAnalyzingFrames,
                InitialDelayBeforeAnalyzingFrames = cfg.InitialDelayBeforeAnalyzingFrames,
                PureBarcode = cfg.PureBarcode,
                TryHarder = cfg.TryHarder,
                TryInverted = cfg.TryInverted,
                UseFrontCameraIfAvailable = cfg.UseFrontCameraIfAvailable
            };

            if (cfg.Formats != null && cfg.Formats.Count > 0) {
                opts.PossibleFormats = cfg.Formats
                    .Select(x => (BarcodeFormat)(int)x)
                    .ToList();
            }
            return opts;
        }
Ejemplo n.º 46
0
        public async void CallWebViewSendData()
        {
            var scanner = new ZXing.Mobile.MobileBarcodeScanner();

            scanner.AutoFocus();
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();

            options.DelayBetweenAnalyzingFrames = 1000;


            scanner.TopText = "Scanning..";

            var result = await scanner.Scan(options);

            if (result != null)
            {
                wv.LoadUrl("javascript:msg(" + @"'" + result.Text + @"'" + ");");
            }
        }
Ejemplo n.º 47
0
        async Task <DeviceInformation> GetFilteredCameraOrDefaultAsync(MobileBarcodeScanningOptions options)
        {
            var videoCaptureDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            var useFront = options.UseFrontCameraIfAvailable.HasValue && options.UseFrontCameraIfAvailable.Value;

            var selectedCamera = videoCaptureDevices.FirstOrDefault(vcd => vcd.EnclosureLocation != null &&
                                                                    ((!useFront && vcd.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back) ||
                                                                     (useFront && vcd.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front)));


            // we fall back to the first camera that we can find.
            if (selectedCamera == null)
            {
                selectedCamera = videoCaptureDevices.FirstOrDefault();
            }

            return(selectedCamera);
        }
        public void ScanContinuously(Context context, MobileBarcodeScanningOptions options, Action <IScanResult> scanHandler)
        {
            var ctx        = GetContext(context);
            var scanIntent = new Intent(ctx, typeof(ZxingActivity));

            scanIntent.AddFlags(ActivityFlags.NewTask);

            ZxingActivity.UseCustomOverlayView = this.UseCustomOverlay;
            ZxingActivity.CustomOverlayView    = this.CustomOverlay;
            ZxingActivity.ScanningOptions      = options;
            ZxingActivity.ScanContinuously     = true;
            ZxingActivity.TopText    = TopText;
            ZxingActivity.BottomText = BottomText;

            ZxingActivity.ScanCompletedHandler = (IScanResult result)
                                                 => scanHandler?.Invoke(result);

            ctx.StartActivity(scanIntent);
        }
Ejemplo n.º 49
0
        public async void OnClickStart(object sender, EventArgs e)
        {
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();

            options.PossibleFormats = new List <ZXing.BarcodeFormat>()
            {
                ZXing.BarcodeFormat.QR_CODE
            };

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

            var result = await scanner.Scan(options);

            if (result != null)
            {
                ProfileData profileData = JsonConvert.DeserializeObject <ProfileData>(result.Text);
                await Navigation.PushAsync(new ProfilePage(profileData));
            }
        }
		public void StartScanning(Action<ZXing.Result> callback, MobileBarcodeScanningOptions options)
		{
			this.options = options;
			this.resultCallback = callback;

			Console.WriteLine("StartScanning");

			this.InvokeOnMainThread(() => {
				if (!SetupCaptureSession())
				{
					//Setup 'simulated' view:
					Console.WriteLine("Capture Session FAILED");
					var simView = new UIView(this.Frame);
					simView.BackgroundColor = UIColor.LightGray;
					this.AddSubview(simView);

				}
			});
		}
Ejemplo n.º 51
0
        //BarcodeReader reader;

        public ZxingSurfaceView(ZxingActivity activity, MobileBarcodeScanningOptions options)
            : base(activity)
        {
            this.activity = activity;

            screenResolution = new Size(this.activity.WindowManager.DefaultDisplay.Width, this.activity.WindowManager.DefaultDisplay.Height);

            this.options = options;


            this.reader = this.options.BuildMultiFormatReader();

            this.surface_holder = Holder;
            this.surface_holder.AddCallback(this);
            this.surface_holder.SetType(SurfaceType.PushBuffers);



            this.tokenSource = new System.Threading.CancellationTokenSource();
        }
        public override void ScanContinuously(MobileBarcodeScanningOptions options, Action <Result> scanHandler)
        {
            //Navigate: /ZxingSharp.WindowsPhone;component/Scan.xaml
            var rootFrame  = RootFrame ?? Window.Current.Content as Frame ?? ((FrameworkElement)Window.Current.Content).GetFirstChildOfType <Frame>();
            var dispatcher = Dispatcher ?? Window.Current.Dispatcher;

            ScanPage.ScanningOptions   = options;
            ScanPage.ResultFoundAction = scanHandler;

            ScanPage.UseCustomOverlay   = this.UseCustomOverlay;
            ScanPage.CustomOverlay      = this.CustomOverlay;
            ScanPage.TopText            = TopText;
            ScanPage.BottomText         = BottomText;
            ScanPage.ContinuousScanning = true;

            dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                rootFrame.Navigate(typeof(ScanPage));
            });
        }
Ejemplo n.º 53
0
        private static MobileBarcodeScanningOptions GetXingConfig(BarCodeScannerOptions opts) {
            var def = ZXing.Mobile.MobileBarcodeScanningOptions.Default;

            var config = new MobileBarcodeScanningOptions {
                AutoRotate = def.AutoRotate,
                CharacterSet = opts.CharacterSet ?? def.CharacterSet,
                DelayBetweenAnalyzingFrames = opts.DelayBetweenAnalyzingFrames ?? def.DelayBetweenAnalyzingFrames,
                InitialDelayBeforeAnalyzingFrames = (opts.InitialDelayBeforeAnalyzingFrames ?? def.InitialDelayBeforeAnalyzingFrames),
                PureBarcode = opts.PureBarcode,
                TryHarder = opts.TryHarder,
                TryInverted = opts.TryInverted,
                UseFrontCameraIfAvailable = opts.UseFrontCameraIfAvailable
            };
            if (opts.Formats != null && opts.Formats.Count > 0) {
                config.PossibleFormats = opts.Formats
                    .Select(x => (BarcodeFormat)(int)x)
                    .ToList();
            }
            return config;
        }
        public override void ScanContinuously(MobileBarcodeScanningOptions options, Action<Result> scanHandler)
        {
            //Navigate: /ZxingSharp.WindowsPhone;component/Scan.xaml
            var rootFrame = RootFrame ?? Window.Current.Content as Frame ?? ((FrameworkElement) Window.Current.Content).GetFirstChildOfType<Frame>();
            var dispatcher = Dispatcher ?? Window.Current.Dispatcher;

            ScanPage.ScanningOptions = options;
            ScanPage.ResultFoundAction = scanHandler;

            ScanPage.UseCustomOverlay = this.UseCustomOverlay;
            ScanPage.CustomOverlay = this.CustomOverlay;
            ScanPage.TopText = TopText;
            ScanPage.BottomText = BottomText;
            ScanPage.ContinuousScanning = true;
            
            dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                rootFrame.Navigate(typeof(ScanPage));
            });
        }
Ejemplo n.º 55
0
		public Task<Result> Scan (Context context, MobileBarcodeScanningOptions options)
		{
			var ctx = GetContext (context);

			var task = Task.Factory.StartNew(() => {

				var waitScanResetEvent = new System.Threading.ManualResetEvent(false);

				var scanIntent = new Intent(ctx, typeof(ZxingActivity));

				scanIntent.AddFlags(ActivityFlags.NewTask);

				ZxingActivity.UseCustomOverlayView = this.UseCustomOverlay;
				ZxingActivity.CustomOverlayView = this.CustomOverlay;
				ZxingActivity.ScanningOptions = options;
				ZxingActivity.ScanContinuously = false;
				ZxingActivity.TopText = TopText;
				ZxingActivity.BottomText = BottomText;

				Result scanResult = null;

				ZxingActivity.CanceledHandler = () => 
				{
					waitScanResetEvent.Set();
				};

				ZxingActivity.ScanCompletedHandler = (Result result) => 
				{
					scanResult = result;
					waitScanResetEvent.Set();
				};

				ctx.StartActivity (scanIntent);

				waitScanResetEvent.WaitOne();

				return scanResult;
			});

			return task;
		}
        async Task <DeviceInformation> GetFilteredCameraOrDefaultAsync(MobileBarcodeScanningOptions options)
        {
            var videoCaptureDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            var useFront = options.UseFrontCameraIfAvailable.HasValue && options.UseFrontCameraIfAvailable.Value;

            var selectedCamera = videoCaptureDevices.FirstOrDefault(vcd => vcd.EnclosureLocation != null &&
                                                                    ((!useFront && vcd.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back) ||
                                                                     (useFront && vcd.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front)));


            // we fall back to the first camera that we can find.
            if (selectedCamera == null)
            {
                var whichCamera = useFront ? "front" : "back";
                System.Diagnostics.Debug.WriteLine("Finding " + whichCamera + " camera failed, opening first available camera");
                selectedCamera = videoCaptureDevices.FirstOrDefault();
            }

            return(selectedCamera);
        }
        private async Task ShowQRCodeScannerAsync()
        {
            var options = new ZXing.Mobile.MobileBarcodeScanningOptions();

            options.PossibleFormats = new List <ZXing.BarcodeFormat>()
            {
                ZXing.BarcodeFormat.QR_CODE
            };

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

            scanner.TopText = "Scan QR Code from lottiefiles.com";
            scanner.AutoFocus();

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

            if (result != null)
            {
                LoadAnimationFromUrl(result.Text);
            }
        }
Ejemplo n.º 58
0
        public Task <Result> Scan(Context context, MobileBarcodeScanningOptions options)
        {
            var ctx = GetContext(context);

            var task = Task.Factory.StartNew(() => {
                var waitScanResetEvent = new System.Threading.ManualResetEvent(false);

                var scanIntent = new Intent(ctx, typeof(ZxingActivity));

                scanIntent.AddFlags(ActivityFlags.NewTask);

                ZxingActivity.UseCustomOverlayView = this.UseCustomOverlay;
                ZxingActivity.CustomOverlayView    = this.CustomOverlay;
                ZxingActivity.ScanningOptions      = options;
                ZxingActivity.ScanContinuously     = false;
                ZxingActivity.TopText    = TopText;
                ZxingActivity.BottomText = BottomText;

                Result scanResult = null;

                ZxingActivity.CanceledHandler = () =>
                {
                    waitScanResetEvent.Set();
                };

                ZxingActivity.ScanCompletedHandler = (Result result) =>
                {
                    scanResult = result;
                    waitScanResetEvent.Set();
                };

                ctx.StartActivity(scanIntent);

                waitScanResetEvent.WaitOne();

                return(scanResult);
            });

            return(task);
        }
Ejemplo n.º 59
0
        public ZxingSurfaceView(ZxingCameraViewController parentController, MobileBarcodeScanner scanner, MobileBarcodeScanningOptions options, UIView overlayView) : base()
        {
            var screenFrame = UIScreen.MainScreen.Bounds;
            var scale       = UIScreen.MainScreen.Scale;

            screenFrame = new RectangleF(screenFrame.X, screenFrame.Y, screenFrame.Width * scale, screenFrame.Height * scale);

            var picFrameWidth  = Math.Round(screenFrame.Width * 0.90);            //screenFrame.Width;
            var picFrameHeight = Math.Round(screenFrame.Height * 0.60);
            var picFrameX      = (screenFrame.Width - picFrameWidth) / 2;
            var picFrameY      = (screenFrame.Height - picFrameHeight) / 2;

            picFrame = new RectangleF((int)picFrameX, (int)picFrameY, (int)picFrameWidth, (int)picFrameHeight);

            //Console.WriteLine(picFrame.X + ", " + picFrame.Y + " -> " + picFrame.Width + " x " + picFrame.Height);
            this.OverlayView = overlayView;
            this.Scanner     = scanner;
            this.Options     = options;

            Initialize();
            _parentViewController = parentController;
        }
Ejemplo n.º 60
0
        public override void ScanContinuously(MobileBarcodeScanningOptions options, Action <Result> scanHandler)
        {
            //Navigate: /ZxingSharp.WindowsPhone;component/Scan.xaml

            ScanPage.ScanningOptions   = options;
            ScanPage.ResultFoundAction = (r) =>
            {
                scanHandler(r);
            };

            ScanPage.UseCustomOverlay   = this.UseCustomOverlay;
            ScanPage.CustomOverlay      = this.CustomOverlay;
            ScanPage.TopText            = TopText;
            ScanPage.BottomText         = BottomText;
            ScanPage.ContinuousScanning = true;

            Dispatcher.BeginInvoke(() =>
            {
                ((Microsoft.Phone.Controls.PhoneApplicationFrame)Application.Current.RootVisual).Navigate(
                    new Uri("/ZXingNetMobile;component/WindowsPhone/ScanPage.xaml", UriKind.Relative));
            });
        }