예제 #1
0
        public void DidScan(IScanSession session)
        {
            if (session.NewlyRecognizedCodes.Count > 0)
            {
                Barcode code = session.NewlyRecognizedCodes [0];
                Console.WriteLine("Código escaneado: {0}, '{1}'", code.SymbologyName, code.Data);

                // Call GC.Collect() before stopping the scanner as the garbage collector for some reason does not
                // collect objects without references asap but waits for a long time until finally collecting them.
                GC.Collect();

                // Stop the scanner directly on the session.
                session.StopScanning();

                // If you want to edit something in the view hierarchy make sure to run it on the UI thread.
                RunOnUiThread(() => {
                    AlertDialog alert = new AlertDialog.Builder(this)
                                        .SetTitle(code.SymbologyName + " Código de barras detectado")
                                        .SetMessage(code.Data)
                                        .SetPositiveButton("OK", delegate {
                        picker.StartScanning();
                    })
                                        .SetOnCancelListener(this)
                                        .Create();

                    alert.Show();
                });
            }
        }
예제 #2
0
        protected override void OnResume()
        {
            base.OnResume();

            paused = false;
            if ((int)Build.VERSION.SdkInt >= 23)
            {
                GrantCameraPermissionsThenStartScanning();
            }
            else
            {
                barcodePicker.StartScanning();
            }
        }
예제 #3
0
        protected void SetScanState(ScanState state, IScanSession scanSession)
        {
            scanState = state;

            switch (state)
            {
            case ScanState.STOPPED:
                if (scanSession != null)
                {
                    scanSession.StopScanning();
                }
                else
                {
                    picker.StopScanning();
                }
                break;

            case ScanState.SCANNING:
                if (HasCameraPermission())
                {
                    picker.StartScanning();
                }
                else
                {
                    RequestCameraPermission();
                }
                break;
            }
        }
        protected override void OnElementChanged(ElementChangedEventArgs <PickerView> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                pickerView = e.NewElement;

                e.NewElement.StartScanningRequested += OnStartScanningRequested;
                e.NewElement.PauseScanningRequested += OnPauseScanningRequested;

                barcodePicker = new BarcodePicker(context, CreateScanSettings());
                SetNativeControl(barcodePicker.OverlayView.RootView);
                onScanListener = new PickerOnScanListener
                {
                    PickerView          = pickerView,
                    ContinuousAfterScan = pickerView.Settings.ContinuousAfterScan
                };
                barcodePicker.SetOnScanListener(onScanListener);

                ApplyOverlaySettings();
                barcodePicker.StartScanning();
            }
            if (e.OldElement != null)
            {
                e.OldElement.StartScanningRequested -= OnStartScanningRequested;
                e.OldElement.PauseScanningRequested -= OnPauseScanningRequested;
            }
        }
예제 #5
0
            public override void DidScan(BarcodePicker picker, IScanSession session)
            {
                if (session.NewlyRecognizedCodes.Count > 0)
                {
                    Barcode code = session.NewlyRecognizedCodes.GetItem <Barcode> (0);
                    Console.WriteLine("barcode scanned: {0}, '{1}'", code.SymbologyString, code.Data);

                    // Stop the scanner directly on the session.
                    session.StopScanning();

                    // If you want to edit something in the view hierarchy make sure to run it on the UI thread.
                    UIApplication.SharedApplication.InvokeOnMainThread(() => {
                        UIAlertView alert = new UIAlertView()
                        {
                            Title = code.SymbologyString + " Barcode Detected", Message = "" + code.Data
                        };
                        alert.AddButton("OK");

                        alert.Clicked += (object o, UIButtonEventArgs e) => {
                            picker.StartScanning();
                        };

                        alert.Show();
                    });
                }
            }
예제 #6
0
 void GrantCameraPermissionsThenStartScanning()
 {
     if (CheckSelfPermission(Manifest.Permission.Camera) != (int)Permission.Granted)
     {
         if (deniedCameraAccess == false)
         {
             // It's pretty clear for why the camera is required. We don't need to give a
             // detailed reason.
             RequestPermissions(new String[] { Manifest.Permission.Camera }, CameraPermissionRequest);
         }
     }
     else
     {
         Console.WriteLine("starting scanning");
         barcodePicker.StartScanning();
     }
 }
예제 #7
0
        partial void scanButtonClicked(Foundation.NSObject sender)
        {
            // The scanning behavior of the barcode picker is configured through scan
            // settings. We start with empty scan settings and enable a very generous
            // set of symbologies. In your own apps, only enable the symbologies you
            // actually need.
            ScanSettings settings            = ScanSettings.DefaultSettings();
            NSSet        symbologiesToEnable = new NSSet(
                Symbology.EAN13,
                Symbology.EAN8,
                Symbology.UPC12,
                Symbology.UPCE,
                Symbology.Datamatrix,
                Symbology.QR,
                Symbology.Code39,
                Symbology.Code128,
                Symbology.ITF
                );

            settings.EnableSymbologies(symbologiesToEnable);


            // Some 1d barcode symbologies allow you to encode variable-length data. By default, the
            // Scandit BarcodeScanner SDK only scans barcodes in a certain length range. If your
            // application requires scanning of one of these symbologies, and the length is falling
            // outside the default range, you may need to adjust the "active symbol counts" for this
            // symbology. This is shown in the following 3 lines of code.

            NSMutableSet codeLengths = new NSMutableSet();
            int          i           = 0;

            for (i = 7; i <= 20; i++)
            {
                codeLengths.Add(new NSNumber(i));
            }
            settings.SettingsForSymbology(Symbology.Code128).ActiveSymbolCounts = codeLengths;
            // For details on defaults and how to calculate the symbol counts for each symbology, take
            // a look at http://docs.scandit.com/stable/c_api/symbologies.html.

            // Setup the barcode scanner
            BarcodePicker picker = new BarcodePicker(settings);

            picker.OverlayView.ShowToolBar(true);

            // Add delegates for the scan and cancel event. We keep references to the
            // delegates until the picker is no longer used as the delegates are softly
            // referenced and can be removed because of low memory.
            scanDelegate        = new PickerScanDelegate();
            picker.ScanDelegate = scanDelegate;

            cancelDelegate = new OverlayCancelDelegate(this, picker);
            picker.OverlayView.CancelDelegate = cancelDelegate;

            PresentViewController(picker, true, null);

            picker.StartScanning();
        }
예제 #8
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // The scanning behavior of the barcode picker is configured through scan
            // settings. We start with empty scan settings and enable a generous set
            // of 1D symbologies. Matrix scan is currently only supported for 1D
            // symbologies, enabling 2D symbologies will result in unexpected results.
            // In your own apps, only enable the symbologies you actually need.
            ScanSettings settings            = ScanSettings.DefaultSettings();
            NSSet        symbologiesToEnable = new NSSet(
                Symbology.EAN13,
                Symbology.EAN8,
                Symbology.UPC12,
                Symbology.UPCE,
                Symbology.Code39,
                Symbology.Code128,
                Symbology.ITF
                );

            // Enable matrix scan and set the max number of barcodes that can be recognized per frame
            // to some reasonable number for your use case. The max number of codes per frame does not
            // limit the number of codes that can be tracked at the same time, it only limits the
            // number of codes that can be newly recognized per frame.
            settings.EnableSymbologies(symbologiesToEnable);
            settings.MatrixScanEnabled        = true;
            settings.MaxNumberOfCodesPerFrame = 10;
            settings.HighDensityModeEnabled   = true;

            // When matrix scan is enabled beeping/vibrating is often not wanted.
            BarcodePicker picker = new BarcodePicker(settings);

            picker.OverlayView.SetBeepEnabled(false);
            picker.OverlayView.SetVibrateEnabled(false);

            // Register a SBSScanDelegate delegate, in order to be notified about relevant events
            // (e.g. a successfully scanned bar code).
            scanDelegate        = new PickerScanDelegate();
            picker.ScanDelegate = scanDelegate;

            // Register a SBSProcessFrameDelegate delegate to be able to reject tracked codes.
            processFrameDelegate        = new PickerProcessFrameDelegate();
            picker.ProcessFrameDelegate = processFrameDelegate;

            AddChildViewController(picker);
            picker.View.Frame = View.Bounds;
            Add(picker.View);
            picker.DidMoveToParentViewController(this);

            picker.OverlayView.GuiStyle = GuiStyle.MatrixScan;

            picker.StartScanning();
        }
예제 #9
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // The scanning behavior of the barcode picker is configured through scan
            // settings. We start with empty scan settings and enable a very generous
            // set of symbologies. In your own apps, only enable the symbologies you
            // actually need.
            ScanSettings settings            = ScanSettings.DefaultSettings();
            NSSet        symbologiesToEnable = new NSSet(
                Symbology.EAN13,
                Symbology.EAN8,
                Symbology.UPC12,
                Symbology.UPCE,
                Symbology.Datamatrix,
                Symbology.QR,
                Symbology.Code39,
                Symbology.Code128,
                Symbology.ITF
                );

            settings.EnableSymbologies(symbologiesToEnable);

            // Enable and set the restrict active area. This will make sure that codes are only scanned in a very thin band in the center of the image.
            settings.SetActiveScanningArea(new CoreGraphics.CGRect(0, 0.48, 1, 0.04));

            // Setup the barcode scanner
            picker = new BarcodePicker(settings);
            picker.OverlayView.ShowToolBar(false);

            // Add delegate for the scan event. We keep references to the
            // delegates until the picker is no longer used as the delegates are softly
            // referenced and can be removed because of low memory.
            scanDelegate        = new PickerScanDelegate();
            picker.ScanDelegate = scanDelegate;

            AddChildViewController(picker);
            picker.View.Frame = View.Bounds;
            Add(picker.View);
            picker.DidMoveToParentViewController(this);

            // Modify the GUI style to have a "laser" line instead of a square viewfinder.
            picker.OverlayView.GuiStyle = GuiStyle.Laser;

            // Start scanning in paused state.
            picker.StartScanning(true);

            showAimAndScanButton();
        }
예제 #10
0
        void InitializeBarcodeScanning()
        {
            ScanSettings settings = ScanSettings.Create();

            int[] symbologiesToEnable =
            {
                Barcode.SymbologyEan13,
                Barcode.SymbologyEan8,
                Barcode.SymbologyUpca,
                Barcode.SymbologyUpce,
                Barcode.SymbologyDataMatrix,
                Barcode.SymbologyQr,
                Barcode.SymbologyCode39,
                Barcode.SymbologyCode128,
                Barcode.SymbologyInterleaved2Of5
            };

            foreach (int symbology in symbologiesToEnable)
            {
                settings.SetSymbologyEnabled(symbology, true);
            }

            // Enable and set the restrict active area. This will make sure that codes are only scanned in a very thin band in the center of the image.
            settings.SetActiveScanningArea(ScanSettings.OrientationPortrait, new RectF(0f, 0.48f, 1f, 0.52f));

            // Setup the barcode scanner
            barcodePicker = new BarcodePicker(this, settings);

            // Add listener for the scan event. We keep references to the
            // delegates until the picker is no longer used as the delegates are softly
            // referenced and can be removed because of low memory.
            barcodePicker.SetOnScanListener(this);

            // Modify the GUI style to have a "laser" line instead of a square viewfinder.
            barcodePicker.OverlayView.SetGuiStyle(ScanOverlay.GuiStyleLaser);

            // Start scanning in paused state.
            barcodePicker.StartScanning(true);

            (FindViewById(Resource.Id.picker_container) as FrameLayout).AddView(barcodePicker, 0);

            GrantCameraPermissionsThenStartScanning();
        }
        protected override void OnElementChanged(ElementChangedEventArgs <CustomStackLayout> e)
        {
            base.OnElementChanged(e);

            //var test = this as ViewGroup;

            if (e.NewElement != null)
            {
                // Set the app key before instantiating the picker.
                ScanditLicense.AppKey = appKey;

                // The scanning behavior of the barcode picker is configured through scan
                // settings. We start with empty scan settings and enable a very generous
                // set of symbologies. In your own apps, only enable the symbologies you
                // actually need.
                ScanSettings settings            = ScanSettings.Create();
                int[]        symbologiesToEnable = new int[]
                {
                    Barcode.SymbologyEan13,
                    Barcode.SymbologyEan8,
                    Barcode.SymbologyUpca,
                    Barcode.SymbologyDataMatrix,
                    Barcode.SymbologyQr,
                    Barcode.SymbologyCode39,
                    Barcode.SymbologyCode128,
                    Barcode.SymbologyInterleaved2Of5,
                    Barcode.SymbologyUpce
                };

                for (int sym = 0; sym < symbologiesToEnable.Length; sym++)
                {
                    settings.SetSymbologyEnabled(symbologiesToEnable[sym], true);
                }

                //// Some 1d barcode symbologies allow you to encode variable-length data. By default, the
                //// Scandit BarcodeScanner SDK only scans barcodes in a certain length range. If your
                //// application requires scanning of one of these symbologies, and the length is falling
                //// outside the default range, you may need to adjust the "active symbol counts" for this
                //// symbology. This is shown in the following few lines of code.

                SymbologySettings symSettings        = settings.GetSymbologySettings(Barcode.SymbologyCode128);
                short[]           activeSymbolCounts = new short[]
                {
                    7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
                };
                symSettings.SetActiveSymbolCounts(activeSymbolCounts);
                // For details on defaults and how to calculate the symbol counts for each symbology, take
                // a look at http://docs.scandit.com/stable/c_api/symbologies.html.

                picker = new BarcodePicker(this.Context, settings);

                picker.OverlayView.SetViewfinderDimension(0.5f, 0.9f, 0.5f, 0.9f);
                picker.OverlayView.SetTorchEnabled(false);


                // Set listener for the scan event.
                picker.SetOnScanListener(this);

                picker.StartScanning();

                //picker.Scan += (sender, args) =>
                //{

                //};

                AddView(picker);

                //SetNativeControl(picker);
            }
        }
예제 #12
0
 private void StartScanning()
 {
     _picker.StartScanning();
 }
예제 #13
0
 public void OnCancel(IDialogInterface dialog)
 {
     picker.StartScanning();
 }
예제 #14
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            contatinerView = new UIView(CGRect.Empty);
            View.AddSubview(contatinerView);
            freezeButton = new UIButton(CGRect.Empty);
            freezeButton.SetTitle("Freeze", UIControlState.Normal);
            freezeButton.SetBackgroundImage(UIImageExtensions.Brand.GetImage(), UIControlState.Normal);
            freezeButton.TouchUpInside += (sender, e) =>
            {
                var scanning = picker.IsScanning();
                if (scanning)
                {
                    matrixScanHandler.Enabled = false;
                    picker.PauseScanning();
                    freezeButton.SetTitle("Done", UIControlState.Normal);
                }
                else
                {
                    matrixScanHandler.RemoveAllAugmentations();
                    matrixScanHandler.Enabled = true;
                    picker.StartScanning();
                    freezeButton.SetTitle("Freeze", UIControlState.Normal);
                }
            };
            View.AddSubview(freezeButton);

            freezeButton.TranslatesAutoresizingMaskIntoConstraints   = false;
            contatinerView.TranslatesAutoresizingMaskIntoConstraints = false;
            View.AddConstraints(new[]
            {
                contatinerView.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
                contatinerView.TopAnchor.ConstraintEqualTo(View.TopAnchor),
                contatinerView.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor),
                contatinerView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor),
                freezeButton.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor, 20),
                freezeButton.BottomAnchor.ConstraintEqualTo(View.BottomAnchor, -20),
                freezeButton.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor, -20),
                freezeButton.HeightAnchor.ConstraintEqualTo(60)
            });

            var settings = ScanSettings.DefaultSettings();

            settings.SetSymbologyEnabled(Symbology.EAN13, true);
            settings.MatrixScanEnabled        = true;
            settings.MaxNumberOfCodesPerFrame = 15;
            settings.HighDensityModeEnabled   = true;
            picker = new BarcodePicker(settings);
            picker.OverlayView.GuiStyle = GuiStyle.None;

            matrixScanHandler = new MatrixScanHandler(picker);
            matrixScanHandler.ShouldReject += (matrixScanHandler, trackedBarcode) => false;

            // This delegate method is called every time a new frame has been processed.
            // In this case we use it to update the offset of the augmentation.
            matrixScanHandler.DidProcess += (sender, e) =>
            {
                DispatchQueue.MainQueue.DispatchAsync(() =>
                {
                    foreach (var item in e.Frame.TrackedCodes)
                    {
                        var offset = GetYOffSet(item.Value as TrackedBarcode);
                        viewBasedMatrixScanOverlay.SetOffset(offset, item.Key as NSNumber);
                    }
                });
            };

            viewBasedMatrixScanOverlay = new ViewBasedMatrixScanOverlay();

            // This method is called every time a new barcode has been tracked.
            // You can implement this method to return the offset that will be used to position the augmentation
            // with respect to the center of the tracked barcode.
            viewBasedMatrixScanOverlay.OffsetForOverlay += (overlay, barcode, identifier) => GetYOffSet(barcode);

            // This delegate method is called every time a new barcode has been tracked.
            // You can implement this method to return the view that will be used as the augmentation.
            viewBasedMatrixScanOverlay.ViewForOverlay += (overlay, barcode, identifier) =>
            {
                if (barcode.Data == null)
                {
                    return(new UIView(CGRect.Empty));
                }
                var view  = new StockView(new CGRect(0, 0, StockView.StandardWidth, StockView.StandardHeight));
                var model = Model.MockedModel(barcode.Data);
                view.AddGestureRecognizer(new UITapGestureRecognizer(() =>
                {
                    var overlayViewController = new OverlayViewController
                    {
                        Model = model,
                        ModalTransitionStyle   = UIModalTransitionStyle.CoverVertical,
                        ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
                    };
                    PresentViewController(overlayViewController, false, null);
                }));
                view.Model = model;

                return(view);
            };

            // Add a ViewBasedMatrixScanOverlay in order to have custom UIView instances as augmentations.
            matrixScanHandler.AddOverlay(viewBasedMatrixScanOverlay);

            simpleMatrixScanOverlay = new SimpleMatrixScanOverlay();

            // This method is called every time a new barcode has been tracked.
            // You can implement this method to customize the color of the highlight.
            simpleMatrixScanOverlay.ColorForOverlay += (overlay, barcode, identifier) => Model.MockedColor(barcode.Data);

            // Add a SimpleMatrixScanOverlay in order to highlight the barcodes.
            matrixScanHandler.AddOverlay(simpleMatrixScanOverlay);

            AddChildViewController(picker);
            picker.View.Frame            = contatinerView.Frame;
            picker.View.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;
            contatinerView.AddSubview(picker.View);
            picker.DidMoveToParentViewController(this);
            picker.StartScanning();
        }