public void stopScanner(string options)
        {
            if (canvas != null)
            {
                ScannerPage.isClosing = true;
                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                    if (scannerPage != null)
                    {
                        BarcodeScannerPage.ScannerPage.cameraDevice.Dispose();
                        if ((int)ScannerPage.param_OverlayMode == 1)
                        {
                            MWOverlay.removeOverlay();
                        }
                        else if ((int)ScannerPage.param_OverlayMode == 1)
                        {
                            canvas.Children.Remove(imgOverlay);
                        }

                        (currentPage.FindName("LayoutRoot") as Grid).Children.Remove(canvas);
                        if (flashButton != null)
                        {
                            (currentPage.FindName("LayoutRoot") as Grid).Children.Remove(flashButton);
                            flashButton = null;
                        }

                        scannerPage.stopCamera();
                        scannerPage = null;
                        canvas      = null;
                        videoBrush  = null;
                    }
                });
            }
        }
Esempio n. 2
0
        public void generateQr()
        {
            if (Source != null || License != null)
            {
                var dataqu = scannerServices.reqQrCode(License);
                Images = new ScannerModel {
                    ImageSource    = generatecodeQr.makeQrCode(dataqu["kode_parkir"]),
                    License_number = License,
                    AreaKatName    = dataqu["areaKatName"],
                    Areanumber     = Convert.ToInt32(dataqu["areaNumber"]),
                    FeesValue      = Convert.ToInt32(dataqu["fees"]),
                    Kodeparkir     = dataqu["kode_parkir"],
                    ImageOri       = Sourceres
                };

                if (scanerwindow == null)
                {
                    scanerwindow = new ScannerPage(Images);
                    scanerwindow.Show();
                }
                else
                {
                    resetForm(Images);
                }
            }
            else
            {
                Messages = "License manual wajib di isi";
            }

            //Console.WriteLine(License);
            //scannerServices.reqQrCode(License);
        }
Esempio n. 3
0
        /// <summary>
        /// TestZXingCommand execute.
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private async Task TestZXing(object arg)
        {
            DateTime creationTime = DateTime.Now;

            ScannerPage scannerPage = new ScannerPage(ScanningOptions.ToModel());

            scannerPage.Appearing    += ScannerPage_Appearing;
            scannerPage.Disappearing += ScannerPage_Disappearing;

            //Add tap to focus.
            TapGestureRecognizer tapToFocusGesture = new TapGestureRecognizer();

            tapToFocusGesture.Tapped += (o, e) => scannerPage.SetFocus();
            scannerPage.Overlay.GestureRecognizers.Add(tapToFocusGesture);

            scannerPage.OnScanResult += (result) =>
            {
                // Stop scanning
                scannerPage.IsScanning = false;
                Barcode       = result.Text;
                BarcodeFormat = result.BarcodeFormat;

                DateTime scannedTime = DateTime.Now;
                TimeToScan = scannedTime - creationTime;

                // Pop the page and show the result
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await NavigationHelper.PopAsync();
                });
            };

            // Navigate to our scanner page
            await NavigationHelper.PushAsync(scannerPage);
        }
        public ScannerPage CreateScannerPage()
        {
            scannerPage?.DisableScanner();
            scannerPage = new ScannerPage();

            return(scannerPage);
        }
        public void startScannerView(string options)
        {
            Deployment.Current.Dispatcher.BeginInvoke(delegate()
            {
                if (canvas == null)
                {
                    string[] paramsList = JsonHelper.Deserialize <string[]>(options);
                    mwbScanner          = this;
                    kallbackID          = paramsList[4];

                    bool firstTimePageLoad = false;
                    if (currentPage == null)
                    {
                        firstTimePageLoad = true;
                        currentPage       = (((PhoneApplicationFrame)Application.Current.RootVisual).Content as PhoneApplicationPage);
                    }

                    var screenWidth  = (currentPage.Orientation == PageOrientation.Portrait || currentPage.Orientation == PageOrientation.PortraitUp || currentPage.Orientation == PageOrientation.PortraitDown) ? Application.Current.Host.Content.ActualWidth : Application.Current.Host.Content.ActualHeight;
                    var screenHeight = (currentPage.Orientation == PageOrientation.Landscape || currentPage.Orientation == PageOrientation.LandscapeLeft || currentPage.Orientation == PageOrientation.LandscapeRight) ? Application.Current.Host.Content.ActualWidth : Application.Current.Host.Content.ActualHeight;


                    var pX      = Convert.ToInt32(paramsList[0]);
                    var pY      = Convert.ToInt32(paramsList[1]);
                    var pWidth  = Convert.ToInt32(paramsList[2]);
                    var pHeight = Convert.ToInt32(paramsList[3]);

                    var x  = (float)pX / 100 * screenWidth;
                    var y  = (float)pY / 100 * screenHeight;
                    width  = (float)pWidth / 100 * screenWidth;
                    height = (float)pHeight / 100 * screenHeight;

                    videoBrush = new System.Windows.Media.VideoBrush();

                    canvas = new Canvas()
                    {
                        Background          = videoBrush,
                        VerticalAlignment   = VerticalAlignment.Top,
                        HorizontalAlignment = HorizontalAlignment.Left
                    };
                    float heightTmp = (float)height;
                    float widthTmp  = (float)width;
                    heightClip      = 0;
                    widthClip       = 0;

                    float AR = (float)screenHeight / (float)screenWidth;
                    if (width * AR >= height)
                    {
                        heightTmp  = (int)(width * AR);
                        heightClip = (float)(heightTmp - height) / 2;
                    }
                    else
                    {
                        widthTmp  = (int)(height / AR);
                        widthClip = (float)(widthTmp - width) / 2;
                    }
                    canvas.Width  = widthTmp;
                    canvas.Height = heightTmp;

                    RectangleGeometry rg = new RectangleGeometry();
                    rg.Rect       = new System.Windows.Rect(widthClip, heightClip, width, height);
                    canvas.Clip   = rg;
                    canvas.Margin = new Thickness(x - widthClip, y - heightClip, 0, 0);

                    if (pX == 0 && pY == 0 && pWidth == 1 && pHeight == 1)
                    {
                        canvas.Visibility = Visibility.Collapsed;
                    }
                    (currentPage.FindName("LayoutRoot") as Grid).Children.Add(canvas);

                    scannerPage            = new ScannerPage();
                    scannerPage.videoBrush = videoBrush;
                    ScannerPage.isPage     = false;
                    scannerPage.InitializeCamera(CameraSensorLocation.Back);
                    scannerPage.fixOrientation(currentPage.Orientation);
                    setAutoRect();
                    if ((int)ScannerPage.param_OverlayMode == 1)
                    {
                        MWOverlay.addOverlay(canvas);
                    }
                    else if ((int)ScannerPage.param_OverlayMode == 2)
                    {
                        imgOverlay = new Image()
                        {
                            Stretch = Stretch.Fill,
                            Width   = width,
                            Height  = height,
                            Margin  = new Thickness(widthClip, heightClip, 0, 0)
                        };

                        BitmapImage BitImg = new BitmapImage(new Uri("/Plugins/manateeworks-barcodescanner/overlay_mw.png", UriKind.Relative));
                        imgOverlay.Source  = BitImg;
                        canvas.Children.Add(imgOverlay);
                    }
                    if (ScannerPage.param_EnableFlash)
                    {
                        flashButton = new Button()
                        {
                            Width           = 70,
                            Height          = 70,
                            BorderThickness = new Thickness(0, 0, 0, 0),
                            Margin          = new Thickness(x + 5, y + 5, 0, 0),
                            Background      = new ImageBrush()
                            {
                                ImageSource = new BitmapImage(new Uri("/Plugins/manateeworks-barcodescanner/flashbuttonoff.png", UriKind.Relative))
                            },
                            HorizontalAlignment = HorizontalAlignment.Left,
                            VerticalAlignment   = VerticalAlignment.Top
                        };
                        flashButton.Click += delegate
                        {
                            scannerPage.flashButton_Click(null, null);
                        };

                        (currentPage.FindName("LayoutRoot") as Grid).Children.Add(flashButton);
                    }

                    if (firstTimePageLoad)
                    {
                        currentPage.NavigationService.Navigating += delegate
                        {
                            stopScanner("");
                        };


                        currentPage.OrientationChanged += delegate
                        {
                            Deployment.Current.Dispatcher.BeginInvoke(delegate()
                            {
                                if (canvas != null)
                                {
                                    if ((int)ScannerPage.param_OverlayMode == 1)
                                    {
                                        MWOverlay.removeOverlay();
                                    }


                                    screenWidth  = (currentPage.Orientation == PageOrientation.Portrait || currentPage.Orientation == PageOrientation.PortraitUp || currentPage.Orientation == PageOrientation.PortraitDown) ? Application.Current.Host.Content.ActualWidth : Application.Current.Host.Content.ActualHeight;
                                    screenHeight = (currentPage.Orientation == PageOrientation.Landscape || currentPage.Orientation == PageOrientation.LandscapeLeft || currentPage.Orientation == PageOrientation.LandscapeRight) ? Application.Current.Host.Content.ActualWidth : Application.Current.Host.Content.ActualHeight;
                                    x            = (float)pX / 100 * screenWidth;
                                    y            = (float)pY / 100 * screenHeight;
                                    width        = (float)pWidth / 100 * screenWidth;
                                    height       = (float)pHeight / 100 * screenHeight;
                                    heightTmp    = (float)height;
                                    widthTmp     = (float)width;
                                    heightClip   = 0;
                                    widthClip    = 0;

                                    AR = (float)screenHeight / (float)screenWidth;
                                    if (width * AR >= height)
                                    {
                                        heightTmp  = (float)(width * AR);
                                        heightClip = (float)(heightTmp - height) / 2;
                                    }
                                    else
                                    {
                                        widthTmp  = (float)(height / AR);
                                        widthClip = (float)(widthTmp - width) / 2;
                                    }

                                    canvas.Width  = widthTmp;
                                    canvas.Height = heightTmp;
                                    rg            = new RectangleGeometry();
                                    rg.Rect       = new System.Windows.Rect(widthClip, heightClip, width, height);
                                    canvas.Clip   = rg;
                                    canvas.Margin = new Thickness(x - widthClip, y - heightClip, 0, 0);

                                    if (flashButton != null)
                                    {
                                        flashButton.Margin = new Thickness(x + 5, y + 5, 0, 0);
                                    }
                                    scannerPage.fixOrientation(currentPage.Orientation);
                                    setAutoRect();
                                    if ((int)ScannerPage.param_OverlayMode == 1)
                                    {
                                        Observable
                                        .Timer(TimeSpan.FromMilliseconds(100))
                                        .SubscribeOnDispatcher()
                                        .Subscribe(_ =>
                                        {
                                            Deployment.Current.Dispatcher.BeginInvoke(delegate()
                                            {
                                                MWOverlay.addOverlay(canvas);
                                            });
                                        });
                                    }
                                    else if ((int)ScannerPage.param_OverlayMode == 2)
                                    {
                                        imgOverlay.Width  = width;
                                        imgOverlay.Height = height;
                                        imgOverlay.Margin = new Thickness(widthClip, heightClip, 0, 0);
                                    }
                                }
                            });
                        };
                    }
                }
                else
                {
                    setAutoRect();
                }
            });
        }
Esempio n. 6
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Page> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || Element == null)
            {
                return;
            }

            listItems = ((ScanPage)Element).AllItems;
            try { editListIndex = int.Parse(((ScanPage)Element).editListIndex.ToString()); } catch { }
            try { editItemIndex = int.Parse(((ScanPage)Element).editItemIndex.ToString()); } catch { }

            try
            {
                customDecoderInit();

                scanner = new ScannerPage();

                /*
                 * Customize the scanner by using options below
                 */

                /* Select desired scanner interface orientation
                 * Available options are: LandscapeLeft, LandscapeRight, Portrait, All; Default: LandscapeLeft
                 */
                //scanner.setInterfaceOrientation("All");

                /* Toggle visibility of Flash button
                 * Available options are: true, false; Default: true
                 */
                //scanner.useFlash = false;

                /* The initial state of the camera flash
                 * Available options are: true, false; Default: false
                 */
                //scanner.flashOnByDefault(true);

                /* Choose between overlay types
                 * Available options are: OM_NONE, OM_MWOVERLAY (dynamic viewfinder), OM_IMAGE (static image overlay); Default: OM_MWOVERLAY
                 */
                //scanner.overlayMode = (int)ScannerPage.OverlayMode.OM_NONE;

                /* Toggle visibility of Zoom button
                 * Available options are: true, false; Default: true
                 */
                //scanner.useZoom = false;

                /* Set the number of CPU cores to be used
                 * Available options are: 1,2,3..; Max = Environment.ProcessorCount; Default: Max;
                 */
                //scanner.setMaxThreads(2);

                /* Close scanner after successful scan
                 * Available options are: true, false (continuous scanning if set to false); Default: true;
                 * if set to false:
                 *      Use scanner.resumeScanning() - to resume after successful scan
                 *      Use scanner.closeScanner()   - to close the scanner
                 */
                //scanner.closeScannerOnDecode = false;

                /* Show on screen location of scanned code
                 * Available options are: true, false; Default: true;
                 *
                 * Customise line width and line color with the provided params below
                 */
                //scanner.enableShowLocation = false;
                //MWOverlay.locationLineColor = 0x008000;
                //MWOverlay.locationLineWidth = 2;

                /*
                 * Use the front camera of the device
                 *
                 * Available options are: true, false; Default: false;
                 *
                 */
                //scanner.useFrontCamera = true;

                ScannerPage.OnScanCompleted += SaveScanResult;

                SetNativeControl(scanner);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(@"      ERROR: ", ex.Message);
            }
        }
Esempio n. 7
0
 public void resetForm(ScannerModel scannerModel)
 {
     scanerwindow.Close();
     scanerwindow = new ScannerPage(Images);
     scanerwindow.Show();
 }