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

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

            return(result == null || String.IsNullOrWhiteSpace(result.Text)
                ? BarCodeResult.Fail
                : new BarCodeResult(result.Text, FromXingFormat(result.BarcodeFormat))
                   );
        }
Beispiel #2
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);
        }
		public async Task<BarCodeResult> Read(BarCodeReadConfiguration config, CancellationToken cancelToken) {
			config = config ?? BarCodeReadConfiguration.Default;
#if __IOS__
            var scanner = new MobileBarcodeScanner { UseCustomOverlay = false };
#elif __ANDROID__
            var topActivity = Mvx.Resolve<Cirrious.CrossCore.Droid.Platform.IMvxAndroidCurrentTopActivity>().Activity;
            var scanner = new MobileBarcodeScanner(topActivity) { UseCustomOverlay = false };
#elif WINDOWS_PHONE
            var scanner = new MobileBarcodeScanner(System.Windows.Deployment.Current.Dispatcher) { UseCustomOverlay = false };
#endif
			cancelToken.Register(scanner.Cancel);

            var result = await scanner.Scan(this.GetXingConfig(config));
            return (result == null || String.IsNullOrWhiteSpace(result.Text)
                ? BarCodeResult.Fail
                : new BarCodeResult(result.Text, FromXingFormat(result.BarcodeFormat))
            );
        }
		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;
        }