Пример #1
0
		public async Task<BarCodeResult> Read(BarCodeReadConfiguration config, CancellationToken cancelToken) 
		{
			config = config ?? BarCodeReadConfiguration.Default;

			var scanner = new MobileBarcodeScanner(Forms.Context) { UseCustomOverlay = false };

			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))
			);
		}
Пример #2
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))
			);
		}
Пример #3
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;
		}
Пример #4
0
		/// <summary>
		/// Handles the scanner click.
		/// </summary>
		/// <param name="sender">Sender of event.</param>
		private async void HandleScannerClicked(object sender)
		{
			App.Click();

			var scanner = DependencyService.Get<IBarCodeScanner>();
			var config = new BarCodeReadConfiguration();

			config.CancelText = Catalog.GetString("Cancel");
			config.FlashlightText = Catalog.GetString("Flash");

			var result = await scanner.Read(config, System.Threading.CancellationToken.None);

			if (result.Success) 
			{
				InputText = result.Code;
			}
		}