/// <summary>
        /// Called when device camera initialized.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="CameraOperationCompletedEventArgs"/> instance containing the event data.</param>
        private void CameraInitialized(object sender, CameraOperationCompletedEventArgs e)
        {
            if (e.Succeeded)
            {
                // Start scan process in separate thread
                Deployment.Current.Dispatcher.BeginInvoke(
                    () =>
                {
                    while (result == null)
                    {
                        var cameraBuffer = new WriteableBitmap(
                            (int)camera.PreviewResolution.Width,
                            (int)camera.PreviewResolution.Height);

                        camera.GetPreviewBufferArgb32(cameraBuffer.Pixels);
                        cameraBuffer.Invalidate();

                        reader.Decode(cameraBuffer);
                    }
                });
            }
            else
            {
                this.result = new BarcodeScannerTask.ScanResult(TaskResult.None);
                NavigationService.GoBack();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handler for barcode scanner task.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The scan result.</param>
        private void TaskCompleted(object sender, BarcodeScannerTask.ScanResult e)
        {
            PluginResult result;

            switch (e.TaskResult)
            {
            case TaskResult.OK:
                result         = new PluginResult(PluginResult.Status.OK);
                result.Message = JsonHelper.Serialize(new BarcodeResult(e.Barcode));
                break;

            case TaskResult.Cancel:
                // If scan is cancelled we return PluginResult.Status.OK with Message contains cancelled: true
                // See plugin docs https://github.com/MSOpenTech/BarcodeScanner#using-the-plugin
                result         = new PluginResult(PluginResult.Status.OK);
                result.Message = JsonHelper.Serialize(new BarcodeResult());
                break;

            default:
                result = new PluginResult(PluginResult.Status.ERROR);
                break;
            }

            this.DispatchCommandResult(result);
        }
 /// <summary>
 /// Called when a page is no longer the active page in a frame.
 /// </summary>
 /// <param name="e">An object that contains the event data.</param>
 protected override void OnNavigatedFrom(NavigationEventArgs e)
 {
     // If result is null, user is cancelled scan operation
     this.result = this.result ?? new BarcodeScannerTask.ScanResult(TaskResult.Cancel);
     this.Completed(this, this.result);
     this.CleanUp();
     base.OnNavigatedFrom(e);
 }
Esempio n. 4
0
 /// <summary>
 /// Called when a page is no longer the active page in a frame.
 /// </summary>
 /// <param name="e">An object that contains the event data.</param>
 protected override void OnNavigatedFrom(NavigationEventArgs e)
 {
     // If result is null, user is cancelled scan operation
     this.result = this.result ?? new BarcodeScannerTask.ScanResult(TaskResult.Cancel);
     this.Completed(this, this.result);
     this.CleanUp();
     base.OnNavigatedFrom(e);
 }
 /// <summary>
 /// Called when reader find barcode.
 /// </summary>
 /// <param name="obj">Scan result object.</param>
 private void ReaderResultFound(Result obj)
 {
     VibrateController.Default.Start(TimeSpan.FromMilliseconds(100));
     this.result = new BarcodeScannerTask.ScanResult(TaskResult.OK)
     {
         Barcode = obj
     };
     NavigationService.GoBack();
 }
Esempio n. 6
0
 /// <summary>
 /// Called when reader find barcode.
 /// </summary>
 /// <param name="obj">Scan result object.</param>
 private void ReaderResultFound(Result obj)
 {
     VibrateController.Default.Start(TimeSpan.FromMilliseconds(100));
     this.result = new BarcodeScannerTask.ScanResult(TaskResult.OK)
     {
         Barcode = obj
     };
     Deployment.Current.Dispatcher.BeginInvoke(() => NavigationService.GoBack());
 }
Esempio n. 7
0
        /// <summary>
        /// Called when device camera initialized.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="CameraOperationCompletedEventArgs"/> instance containing the event data.</param>
        private void CameraInitialized(object sender, CameraOperationCompletedEventArgs e)
        {
            this.isInit = true;

            if (this.shouldDispose)
            {
                CleanUp();
                return;
            }

            if (e.Succeeded)
            {
                if (this.camera.IsFlashModeSupported(FlashMode.Off))
                {
                    this.camera.FlashMode = FlashMode.Off;
                }

                // Start scan process in separate thread
                Task.Factory.StartNew(async
                                          (_) =>
                {
                    while (this.result == null)
                    {
                        var waitTask = Task.Delay(1500);

                        if (this.camera.IsFocusSupported)
                        {
                            this.camera.Focus();
                        }

                        await waitTask;

                        int width        = (int)this.camera.PreviewResolution.Width;
                        int height       = (int)this.camera.PreviewResolution.Height;
                        int size         = width * height;
                        var cameraBuffer = new int[size];
                        this.camera.GetPreviewBufferArgb32(cameraBuffer);

                        var converted = new byte[size * sizeof(int)];
                        Buffer.BlockCopy(cameraBuffer, 0, converted, 0, converted.Length);

                        try
                        {
                            this.reader.Decode(converted, width, height, RGBLuminanceSource.BitmapFormat.BGRA32);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }, TaskCreationOptions.LongRunning | TaskCreationOptions.DenyChildAttach, CancellationToken.None);
            }
            else
            {
                this.result = new BarcodeScannerTask.ScanResult(TaskResult.None);
                NavigationService.GoBack();
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Called when device camera initialized.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="CameraOperationCompletedEventArgs"/> instance containing the event data.</param>
        private void CameraInitialized(object sender, CameraOperationCompletedEventArgs e)
        {
            if (e.Succeeded)
            {
                if (camera.IsFocusSupported)
                {
                    camera.Focus();
                }

                // Start scan process in separate thread
                this.Dispatcher.BeginInvoke(() => timer.Start());
            }
            else
            {
                this.result = new BarcodeScannerTask.ScanResult(TaskResult.None);
                NavigationService.GoBack();
            }
        }
 /// <summary>
 /// Called when reader find barcode.
 /// </summary>
 /// <param name="obj">Scan result object.</param>
 private void ReaderResultFound(Result obj)
 {
     VibrateController.Default.Start(TimeSpan.FromMilliseconds(100));
     this.result = new BarcodeScannerTask.ScanResult(TaskResult.OK) { Barcode = obj };
     NavigationService.GoBack();
 }
        /// <summary>
        /// Called when device camera initialized.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="CameraOperationCompletedEventArgs"/> instance containing the event data.</param>
        private void CameraInitialized(object sender, CameraOperationCompletedEventArgs e)
        {
            if (e.Succeeded)
            {
                if (camera.IsFocusSupported)
                {
                    camera.Focus();
                }

                // Start scan process in separate thread
                this.Dispatcher.BeginInvoke(() => timer.Start());
            }
            else
            {
                this.result = new BarcodeScannerTask.ScanResult(TaskResult.None);
                NavigationService.GoBack();
            }
        }
Esempio n. 11
0
 private void BarcodeScannerUI_BackKeyPress(object sender, CancelEventArgs e)
 {
     this.result = new BarcodeScannerTask.ScanResult(TaskResult.Cancel);
     NavigationService.GoBack();
 }
Esempio n. 12
0
        /// <summary>
        /// Called when device camera initialized.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="CameraOperationCompletedEventArgs"/> instance containing the event data.</param>
        private void CameraInitialized(object sender, CameraOperationCompletedEventArgs e)
        {
            if (e.Succeeded)
            {
                // Start scan process in separate thread
                Deployment.Current.Dispatcher.BeginInvoke(
                    () =>
                        {
                            while (result == null)
                            {
                                var cameraBuffer = new WriteableBitmap(
                                    (int)camera.PreviewResolution.Width,
                                    (int)camera.PreviewResolution.Height);

                                camera.GetPreviewBufferArgb32(cameraBuffer.Pixels);
                                cameraBuffer.Invalidate();

                                reader.Decode(cameraBuffer);
                            }
                        });
            }
            else
            {
                this.result = new BarcodeScannerTask.ScanResult(TaskResult.None);
                NavigationService.GoBack();
            }
        }