Beispiel #1
0
        /// <summary>
        /// Native implementation of scan
        /// </summary>
        /// <param name="topText">Text displayed at the top of the layout</param>
        /// <param name="bottomText">Text displayed at the bottom of the layout</param>
        /// <param name="cameraUnsupportedMessage">Unsupported camera message</param>
        /// <returns>Native scan result</returns>
        protected override async Task <ZXing.Result> ScanNative(string topText, string bottomText, string cameraUnsupportedMessage)
        {
            // Current activity
            var currentActivity = Mvx.IoCProvider.Resolve <IMvxAndroidCurrentTopActivity>().Activity;

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

            // Create a new instance of our scanner
            var scanner = new MobileBarcodeScanner
            {
                UseCustomOverlay         = false, // Use the default overlay
                TopText                  = topText,
                BottomText               = bottomText,
                CameraUnsupportedMessage = cameraUnsupportedMessage
            };

            try
            {
                // Add option for use correct resolution for mobile
                var options = new MobileBarcodeScanningOptions()
                {
                    CameraResolutionSelector = new CameraResolutionSelectorDelegate(ResolutionSelector)
                };

                // Start scanning
                return(await scanner.Scan(options));
            }
            finally
            {
                // Uninitialize the scanner to avoid memory leaks
                MobileBarcodeScanner.Uninitialize(currentActivity.Application);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Efetua a leitura de um código de barras; Por padrão, lê qualquer formato disponível atualmente
        /// </summary>
        /// <param name="p_sTextoExibicao">Texto que aparecerá para o usuário durante a leitura do código.</param>
        /// <returns></returns>
        public async Task <string> LerCodigo(string p_sTextoExibicao, bool p_bAutoFoco)
        {
            string sRet = string.Empty;
            MobileBarcodeScanningOptions scanOptions = new MobileBarcodeScanningOptions();

            scanOptions.AutoRotate        = false;
            scanOptions.UseNativeScanning = true;
            //scanOptions.TryInverted = true;
            scanOptions.PossibleFormats.Add(ZXing.BarcodeFormat.EAN_13);
            //scanOptions.TryHarder = true;
            scanOptions.DelayBetweenAnalyzingFrames = 712;

            var scanner = new MobileBarcodeScanner();

            if (!string.IsNullOrEmpty(p_sTextoExibicao))
            {
                scanner.TopText = p_sTextoExibicao;
            }

            ZXing.Result zRet = null;

            new Thread(new ThreadStart(delegate
            {
                while (zRet == null)
                {
                    scanner.AutoFocus();
                    Thread.Sleep(1916);
                }
            })).Start();

            zRet = await scanner.Scan(scanOptions);

            if (zRet != null)
            {
                sRet = (!string.IsNullOrEmpty(zRet.Text) ? zRet.Text : "");
            }

            MobileBarcodeScanner.Uninitialize(app);

            return(sRet);
        }
 public void Dispose()
 {
     MobileBarcodeScanner.Uninitialize(_application);
 }