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
                {
                    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;
                }
            }));
        }
Example #3
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;
        }
Example #4
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;
        }