ToggleTorch() public method

public ToggleTorch ( ) : void
return void
Exemplo n.º 1
0
		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 += async 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
				var result = await scanner.Scan();

				HandleScanResult(result);
			};

			Button flashButton;
			View zxingOverlay;

			buttonScanCustomView = this.FindViewById<Button>(Resource.Id.buttonScanCustomView);
			buttonScanCustomView.Click += async 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!
				var result = await scanner.Scan();

				HandleScanResult(result);
			};

			buttonFragmentScanner = FindViewById<Button> (Resource.Id.buttonFragment);
			buttonFragmentScanner.Click += delegate {
				StartActivity (typeof (FragmentActivity));	
			};
		}
		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 += (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);
		}
Exemplo n.º 3
0
		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);
				});
			};

			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
				var zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.ZxingOverlay, null);

				//Find the button from our resource layout and wire up the click event
				var flashButton = zxingOverlay.FindViewById<Button>(Resource.Id.buttonZxingFlash);
				flashButton.Click += (sender, e) => {
					//Tell our scanner to toggle the torch/flash
					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);
				});
			};
		}
Exemplo n.º 4
0
		string Opapp="OP QR Scanner";//Title for error-s
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Create your application here
			SetContentView (Resource.Layout.Gesture);
			scanner = new MobileBarcodeScanner (this);

			//QRScanner Button listener
			Button QRScannerButton = (Button)FindViewById (Resource.Id.QRButton2);
			QRScannerButton.Click += async delegate {
				try
				{

					scanner.UseCustomOverlay=true;//Options TRUE or FALSE
					zxingOverlay=LayoutInflater.FromContext(this).Inflate(Resource.Layout.QROverlay,null);//Start QRScanner Overlay


					flashButton=zxingOverlay.FindViewById<Button>(Resource.Id.buttonZxingFlash);//Instance button for flashlight
					flashButton.Click +=(sender,e)=>scanner.ToggleTorch();//Event to start flashlight

					scanner.CustomOverlay=zxingOverlay;//Display QRScanner View
					var result=await scanner.Scan();//Await scaning result from qr scanner
					HandleScanResult(result);//forwards QRScanner result to HandleScanResult where we can continue to play with him.
					//SetContentView (Resource.Layout.Splash);
					//main=LayoutInflater.FromContext(this).Inflate(Resource.Layout.Splash);
					//StartActivity(typeof(HopSampleApp.Activities.LoginActivity));
				}
				catch(Exception error)
				{
					Log.Error(Opapp,String.Format("Error fetching data: {0}",error.Message));//Print Error if scanning fail.

				}
			};
			//Skip Button listener
			Button SKIPButton = (Button)FindViewById (Resource.Id.SkipButton1);
			SKIPButton.Click += delegate {

				StartActivity(typeof(HopSampleApp.Activities.ContactsActivity));//Skip Splash View and go to ContactsActivity
			};
		}
Exemplo n.º 5
0
		public async Task<BarCodeResult> Read(BarCodeReadConfiguration config, CancellationToken cancelToken) 
		{
			config = config ?? BarCodeReadConfiguration.Default;

			var controller = ((UIViewController)((ExtendedNavigationPage)App.GameNavigation).ViewController);
			var scanner = new MobileBarcodeScanner(controller);

			scanner.UseCustomOverlay = true;
			scanner.CustomOverlay = new BarCodeScannerOverlay(new CGRect(0, 0, (nfloat)App.GameNavigation.Bounds.Width, (nfloat)App.GameNavigation.Bounds.Height), "", "", config.CancelText, config.FlashlightText, () => scanner.Cancel(), () => scanner.ToggleTorch());

			scanner.CancelButtonText = config.CancelText;
			scanner.FlashButtonText = config.FlashlightText;

			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))
			);
		}
        public override void ViewDidLoad()
        {
            //Create a new instance of our scanner
            scanner = new MobileBarcodeScanner(this.NavigationController);

            Root = new RootElement ("ZXing.Net.Mobile") {
                new Section {

                    new StyledStringElement ("Scan with Default View", async () => {
                        //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);
                    }),

                    new StyledStringElement ("Scan Continuously", () => {
                        //Tell our scanner to use the default overlay
                        scanner.UseCustomOverlay = false;

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

                        var opt = new MobileBarcodeScanningOptions ();
                        opt.DelayBetweenContinuousScans = 3000;

                        //Start scanning
                        scanner.ScanContinuously (opt, true, HandleScanResult);
                    }),

                    new StyledStringElement ("Scan with Custom View", async () => {
                        //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);
                    }),

                    new StyledStringElement ("Scan with AVCapture Engine", async () => {
                        //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 (true);

                        HandleScanResult (result);
                    }),

                    new StyledStringElement ("Generate Barcode", () => {
                        NavigationController.PushViewController (new ImageViewController (), true);
                    })
                }
            };
        }
Exemplo n.º 7
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

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

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

            //Create a new instance of our Scanner
            scanner = new MobileBarcodeScanner();
            hideImage = this.FindViewById<Button>(Resource.Id.hideImageBtn);
            previewImage = this.FindViewById<ImageView>(Resource.Id.previewImage);
            hideImage.Visibility = ViewStates.Gone;
            previewImage.Visibility = ViewStates.Gone;

            hideImage.Click += (object sender, System.EventArgs e) => {
                hideImage.Visibility = ViewStates.Gone;
                previewImage.Visibility = ViewStates.Gone;

            };

            buttonScanDefaultView = this.FindViewById<Button>(Resource.Id.buttonScanDefaultView);
            buttonScanDefaultView.Click += async 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
                var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
                options.PossibleFormats = new List<ZXing.BarcodeFormat>() { ZXing.BarcodeFormat.AZTEC };
                var result = await scanner.Scan(options);

                HandleScanResult(result);
            };

            buttonContinuousScan = FindViewById<Button> (Resource.Id.buttonScanContinuous);
            buttonContinuousScan.Click += delegate {

                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!";

                var opt = new MobileBarcodeScanningOptions ();
                opt.DelayBetweenContinuousScans = 3000;

                //Start scanning
                scanner.ScanContinuously(opt, HandleScanResult);
            };

            Button flashButton;
            View zxingOverlay;

            buttonScanCustomView = this.FindViewById<Button>(Resource.Id.buttonScanCustomView);
            buttonScanCustomView.Click += async 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!
                var result = await scanner.Scan();

                HandleScanResult(result);
            };

            buttonFragmentScanner = FindViewById<Button> (Resource.Id.buttonFragment);
            buttonFragmentScanner.Click += delegate {
                StartActivity (typeof (FragmentActivity));
            };

            buttonGenerate = FindViewById<Button> (Resource.Id.buttonGenerate);
            buttonGenerate.Click += delegate {
                StartActivity (typeof (ImageActivity));
            };
        }
		public override void ViewDidLoad ()
		{
			if (is7orgreater)
				EdgesForExtendedLayout = UIRectEdge.None;
	
			NavigationItem.Title = "ZXing.Net.Mobile";

			//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);
			};

			if (is7orgreater)
			{
				buttonAVCaptureScan = new UIButton (UIButtonType.RoundedRect);
				buttonAVCaptureScan.Frame = new RectangleF (20, 140, 280, 40);
				buttonAVCaptureScan.SetTitle ("Scan with AVCapture Engine", UIControlState.Normal);
				buttonAVCaptureScan.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 (true);

					HandleScanResult (result);
				};
			}

			this.View.AddSubview (buttonDefaultScan);
			this.View.AddSubview (buttonCustomScan);

			if (is7orgreater)
				this.View.AddSubview (buttonAVCaptureScan);
		}
Exemplo n.º 9
0
		void buttonSample3_Click (object sender, EventArgs e)
		{
			var scanner = new MobileBarcodeScanner(this);

			var overlay = (LinearLayout)this.LayoutInflater.Inflate(Resource.Layout.ScanOverlayLayout, null, false);

			var buttonCancel = overlay.FindViewById<Button>(Resource.Id.buttonCancelScan);
			var buttonFlash = overlay.FindViewById<Button>(Resource.Id.buttonToggleFlash);

			buttonCancel.Click += (object sender2, EventArgs e2) => 
			{
				scanner.Cancel();
			};

			buttonFlash.Click += (object sender2, EventArgs e2) => 
			{
				scanner.ToggleTorch();
			};

			scanner.UseCustomOverlay = true;
			scanner.CustomOverlay = overlay;

			scanner.Scan().ContinueWith((t) => {
				ShowMessage(t.Result != null ? "Scanned: " + t.Result.Text : "No Barcode Scanned");
			});
		}
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.activity_def_ov);
            scanCode = FindViewById<Button> (Resource.Id.btn_scan);
            scannedResult = FindViewById<TextView> (Resource.Id.tv_scanned_code);
            //Create a new instance of our Scanner
            mobileScanner = new MobileBarcodeScanner(this);
            scanCode.Click += delegate {
                //Tell our scanner we want to use a custom overlay instead of the default
                mobileScanner.UseCustomOverlay = true;

                //Inflate our custom overlay from a resource layout
                customView = LayoutInflater.FromContext(this).Inflate(Resource.Layout.zxing_custom_ov, null);
                //Find the button from our resource layout and wire up the click event
                flashButton = customView.FindViewById<Button> (Resource.Id.buttonFlashOn);
                flashButton.Click += (sender, e) => mobileScanner.ToggleTorch();
                //Set our custom overlay
                mobileScanner.CustomOverlay = customView;
                //Start scanning!
                mobileScanner.Scan().ContinueWith((t) => {
                    if (t.Status == System.Threading.Tasks.TaskStatus.RanToCompletion)
                        HandleScanResult(t.Result);
                });

            };
        }