Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// On element changed event
        /// </summary>
        /// <param name="e"></param>
        protected override void OnElementChanged(ElementChangedEventArgs <ScandItCamera> e)
        {
            base.OnElementChanged(e);
            //assign new elemnt value to scanned it camera
            _scanedItCamera = e.NewElement;

            if (Control == null)
            {
                try
                {
                    var scanLicense = new ScanditLicense();
                    scanLicense.AppKey = ScanditAppKey;
                    ScanSettings scanSettings = ScanSettings.DefaultSettings();
                    //set code duplication filter
                    if (_scanedItCamera.AllowDuplicate)
                    {
                        scanSettings.CodeDuplicateFilter = 1500; //1.5 sec delay for duplication scanning
                    }
                    else
                    {
                        scanSettings.CodeDuplicateFilter = -1;
                    }

                    //Bar code symbologies
                    scanSettings.SetSymbologyEnabled(Symbology.EAN13, true);
                    scanSettings.SetSymbologyEnabled(Symbology.QR, true);
                    scanSettings.SetSymbologyEnabled(Symbology.UPC12, true);
                    scanSettings.SetSymbologyEnabled(Symbology.Code128, true);
                    scanSettings.SetSymbologyEnabled(Symbology.Code39, true);
                    scanSettings.SetSymbologyEnabled(Symbology.EAN8, true);
                    //update code 128 settings
                    var code128Settings = scanSettings.SettingsForSymbology(Symbology.Code128);
                    var countArray      = NSArray.FromObjects(4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
                                                              28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40);
                    code128Settings.ActiveSymbolCounts = new NSSet(countArray);
                    //apply scan settings
                    _picker = new BarcodePicker(scanSettings);
                    _picker.OverlayView.SetBeepEnabled(true);
                    _picker.OverlayView.SetVibrateEnabled(true);
                    _picker.OverlayView.SetCameraSwitchVisibility(CameraSwitchVisibility.Never);
                    _picker.OverlayView.GuiStyle = GuiStyle.None;
                    //to set picker gui style
                    if (_scanedItCamera.ShowFocus)
                    {
                        _picker.OverlayView.GuiStyle = GuiStyle.Default;
                    }
                    else
                    {
                        _picker.OverlayView.GuiStyle = GuiStyle.None;
                    }
                    _picker.DidScan += DidScan;
                    //set native control as picker view
                    SetNativeControl(_picker.View);

                    //enable action for start and stop scanning
                    if (_scanedItCamera != null)
                    {
                        _scanedItCamera.StartScanning = StartScanning;
                        _scanedItCamera.StopScanning  = StopScanning;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
        }