Ejemplo n.º 1
0
        protected override void OnCreate(Bundle bundle)
        {
            Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn);

            base.OnCreate(bundle);

            ActionBar.SetHomeButtonEnabled(true);
            ActionBar.SetDisplayHomeAsUpEnabled(true);

            SetContentView(Resource.Layout.BarcodeActivity);

            SetTitle(Resource.String.scan_barcode);

            _scanView   = FindViewById <BarcodeScanView>(Resource.Id.barcode_scan_view);
            _resultText = FindViewById <TextView>(Resource.Id.text_result);

            _scanView.SetConfigFromAsset("BarcodeConfig.json");

            _scanView.InitAnyline(MainActivity.LicenseKey, this);

            // limit the barcode scanner to QR codes or CODE_128 codes
            //scanView.SetBarcodeFormats(BarcodeScanView.BarcodeFormat.QR_CODE, BarcodeScanView.BarcodeFormat.CODE_128);

            _scanView.SetBeepOnResult(true);

            _scanView.SetCancelOnResult(false);

            _scanView.CameraOpened += Camera_Opened;
            _scanView.CameraError  += Camera_Error;
        }
 public void FlashToggleButton_Clicked(object sender, EventArgs e)
 {
     if (FlashToggleButton.IsToggled)
     {
         BarcodeScanView.ToggleTorch();
     }
     else
     {
         BarcodeScanView.IsTorchOn = false;
     }
 }
Ejemplo n.º 3
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            if (_ScanView == null)
            {
                if (Device.RuntimePlatform == Device.Android || Device.RuntimePlatform == Device.iOS)
                {
                    var scanView = new BarcodeScanView(XamBarcodeFormat.QrCode);
                    scanView.OnBarcodeScanResult += OnScanResult;
                    _ScanView = scanView;
                }

                if (_ScanView == null)
                {
                    if (Device.RuntimePlatform != Device.Android && Device.RuntimePlatform != Device.iOS)
                    {
                        this.scanMessage.Text = "Barcode scan not supported in this platform!";
                    }
                    else
                    {
                        var cameraStatus = await Permissions.CheckStatusAsync <Permissions.Camera>();

                        if (cameraStatus != PermissionStatus.Granted)
                        {
                            this.scanMessage.Text = "Check the Camera permissions to scan barcodes";
                        }
                        else
                        {
                            this.scanMessage.Text = "Generic error";
                        }
                    }
                    this.scanMessage.IsVisible = true;
                }
                else
                {
                    this.scanMessage.IsVisible = false;

                    _ScanView.VerticalOptions   = LayoutOptions.FillAndExpand;
                    _ScanView.HorizontalOptions = LayoutOptions.FillAndExpand;
                    this.scanView.Children.Add(_ScanView, 0, 0);
                }
            }
            else
            {
                if (Device.RuntimePlatform == Device.Android || Device.RuntimePlatform == Device.iOS)
                {
                    ((BarcodeScanView)_ScanView).OnBarcodeScanResult -= OnScanResult;
                    ((BarcodeScanView)_ScanView).OnBarcodeScanResult += OnScanResult;
                    ((BarcodeScanView)_ScanView).StartCamera?.Invoke(true);
                }
            }
        }