コード例 #1
0
        void Scan()
        {
            var opts = new MobileBarcodeScanningOptions {
                CameraResolutionSelector = availableResolutions => {
                    foreach (var ar in availableResolutions)
                    {
                        Console.WriteLine("Resolution: " + ar.Width + "x" + ar.Height);
                    }
                    return(null);
                }
            };

            scanFragment.StartScanning(result => {
                var resultIntent = new Intent();
                string resultText;
                // Null result means scanning was cancelled
                if (result == null || string.IsNullOrEmpty(result.Text))
                {
                    resultText = "";
                }
                else
                {
                    resultText = result.Text;
                }
                // Otherwise, proceed with result

                resultIntent.PutExtra(Activity1.RESULT_EXTRA_NAME, resultText);
                SetResult(Result.Ok, resultIntent);
                Finish();
            }, opts);
        }
コード例 #2
0
ファイル: FragmentActivity.cs プロジェクト: EFinley/Atropos
        void scan()
        {
            var opts = new MobileBarcodeScanningOptions
            {
                PossibleFormats = new List <ZXing.BarcodeFormat> {
                    ZXing.BarcodeFormat.QR_CODE
                },
                CameraResolutionSelector = availableResolutions =>
                {
                    foreach (var ar in availableResolutions)
                    {
                        Console.WriteLine("Resolution: " + ar.Width + "x" + ar.Height);
                    }
                    return(null);
                }
            };

            scanFragment.StartScanning(result =>
            {
                // Null result means scanning was cancelled
                if (result == null || string.IsNullOrEmpty(result.Text))
                {
                    Toast.MakeText(this, "Scanning Cancelled", ToastLength.Long).Show();
                    return;
                }

                // Otherwise, proceed with result
                RunOnUiThread(() => Toast.MakeText(this, "Scanned: " + result.Text, ToastLength.Short).Show());
            }, opts);
        }
コード例 #3
0
ファイル: IDView.cs プロジェクト: olibd/EphemerisLynxMobile
        protected override void OnResume()
        {
            base.OnResume();
            if (PermissionsHandler.NeedsPermissionRequest(this))
            {
                PermissionsHandler.RequestPermissionsAsync(this);
            }
            _scanner.StartScanning(result =>
            {
                if (!result.Text.Contains(":"))
                {
                    return;
                }

                RunOnUiThread(() =>
                {
                    try
                    {
                        Toast.MakeText(this, "Request Scanned. Please wait.", ToastLength.Long).Show();
                    }
                    catch (Exception e)
                    {
                        var f = e;
                    }
                });

                QrCodeScanCommand.Execute(result.Text);
            },
                                   MobileBarcodeScanningOptions.Default);
        }
コード例 #4
0
        protected override void OnResume()
        {
            base.OnResume();

            if (scanFragment == null)
            {
                scanFragment = new CustomScannerFragment
                {
                    BottomText = learningTask.Description
                };
                SupportFragmentManager.BeginTransaction()
                .Replace(Resource.Id.fragment_container, scanFragment)
                .Commit();
            }

            bool needsPermission = PermissionsHandler.NeedsPermissionRequest(this);

            if (needsPermission)
            {
                PermissionsHandler.RequestPermissionsAsync(this);
            }
            else
            {
                scanFragment.StartScanning(OnScanResult, GetOptions());
            }
        }
コード例 #5
0
        public void StartScanner(ScanCompleteDelegate scd)
        {
            m_scdNotify = scd;

            m_scannerControl.StartScanning(async(result) =>
            {
                var msg = "Found Barcode: " + result.Text;

                await Task.Run(() => m_scdNotify(result));
            }, m_options);
        }
コード例 #6
0
        void Scan()
        {
            var opts = new MobileBarcodeScanningOptions();

            opts.UseFrontCameraIfAvailable = Settings.GetBoolean("UseFrontCameraForEANScan", false);

            scanFragment.StartScanning(result =>
            {
                // Null result means scanning was cancelled
                if (result == null || string.IsNullOrEmpty(result.Text))
                {
                    Toast.MakeText(this, "Scanning Cancelled", ToastLength.Long).Show();
                    return;
                }

                RunOnUiThread(() =>
                {
                    Intent intent = new Intent();
                    intent.PutExtra("EANCode", result.Text);
                    this.SetResult(Result.Ok, intent);
                    this.OnBackPressed();
                });
            }, opts);
        }
コード例 #7
0
        private void StartScanningForQRCode()
        {
            var opts = new MobileBarcodeScanningOptions
            {
                PossibleFormats = new List <ZXing.BarcodeFormat> {
                    ZXing.BarcodeFormat.QR_CODE
                },
                CameraResolutionSelector = availableResolutions => { return(null); },
                AutoRotate = false,
                TryHarder  = false,
                UseFrontCameraIfAvailable = true,
            };

            _scanFragment.StartScanning(result =>
            {
                // Null result means scanning was cancelled
                if (result == null || string.IsNullOrEmpty(result.Text))
                {
                    Toast.MakeText(this, "Scanning Cancelled", ToastLength.Long).Show();
                    return;
                }

                // Otherwise, proceed with result
                try
                {
                    _scanFragment.PauseAnalysis();

                    var url = new Uri(result.Text);

                    // if we don't have a command, exit
                    if (url.Segments.Length < 2)
                    {
                        throw new Exception("QR Code not recognised");
                    }

                    string command = url.Segments[1].Replace("/", "");

                    switch (command)
                    {
                    case "deploymentUser":
                        // if the command isn't exit and we don't have an id to look for, exit
                        if (url.Segments.Length != 3)
                        {
                            throw new Exception("Invalid QR code");
                        }

                        int deploymentUserId          = Int32.Parse(url.Segments[2]);
                        DeploymentUser deploymentUser = _deploymentUsers.SingleOrDefault(du => du.id == deploymentUserId);

                        if (deploymentUser == null)
                        {
                            throw new Exception("Invalid QR code");
                        }
                        else
                        {
                            RunOnUiThread(() =>
                            {
                                _webViewClient.DeviceScanned(_webView, deploymentUser);
                            });
                        }
                        break;

                    case "food":
                        if (url.Segments.Length != 3)
                        {
                            throw new Exception("Invalid QR code");
                        }

                        int foodId = Int32.Parse(url.Segments[2]);

                        // fire off food event
                        RunOnUiThread(() =>
                        {
                            _webViewClient.FoodScanned(_webView, foodId);
                        });
                        break;

                    case "exit":
                        // fire off exit event
                        RunOnUiThread(() =>
                        {
                            _webViewClient.ExitTablet(_webView);
                            _webView.LoadUrl("javascript:location.reload(true)");
                        });
                        break;

                    default:
                        throw new Exception("QR code command not found");
                    }
                }
                catch (Exception e)
                {
                    RunOnUiThread(() =>
                    {
                        Toast.MakeText(this, "Oops I can't understand that", ToastLength.Long).Show();
                    });
                    Crashes.TrackError(e);
                }

                _scanFragment.ResumeAnalysis();
            }, opts);
        }