예제 #1
0
        private async Task Create_Scanner()
        {
            try
            {
                this.session = DbFactory.Open(App.ConnectionString);

                this.scanner = new QXScanner();

                if (this.deviceType == DeviceFormFactorType.Phone)
                {
                    this.scanner.IsMobile = true;
                    this.vibDevice        = VibrationDevice.GetDefault();
                }

                this.scanner.IsFront  = false;
                this.scanner.Interval = 300;

                this.scanner.CaptureStart += Scanner_CaptureStart;
                this.scanner.CaptureImage += Scanner_CaptureImage;
                this.scanner.CaptureFail  += Scanner_CaptureFail;

                await this.scanner.SetPreviewAsync(this.PreviewControl);

                await this.scanner.Start(_displayInformation.CurrentOrientation);
            }
            catch (Exception ex)
            {
                await App.Logger.Write("Initialize Fail: " + ex.Message);

                //camera error
                var dialog = new MessageDialog(ex.Message, "Initialize Fail");

                dialog.Commands.Add(new UICommand("OK")
                {
                    Id = 0
                });

                var result = await dialog.ShowAsync();

                var action = (int)result.Id;
            }
        }
예제 #2
0
        private void UpdateButtonOrientation()
        {
            int device  = QXScanner.ConvertDeviceOrientationToDegrees(_deviceOrientation);
            int display = QXScanner.ConvertDisplayOrientationToDegrees(_displayOrientation);

            if (_displayInformation.NativeOrientation == DisplayOrientations.Portrait)
            {
                device -= 90;
            }

            // Combine both rotations and make sure that 0 <= result < 360
            var angle = (360 + display + device) % 360;

            // Rotate the buttons in the UI to match the rotation of the device
            var transform = new RotateTransform {
                Angle = angle
            };

            this.btnList.RenderTransform = transform;
            this.btnOpen.RenderTransform = transform;
        }
예제 #3
0
        private async Task Clean_Scanner()
        {
            if (this.scanner != null)
            {
                this.scanner.CaptureStart -= Scanner_CaptureStart;
                this.scanner.CaptureImage -= Scanner_CaptureImage;
                this.scanner.CaptureFail  -= Scanner_CaptureFail;

                this.scanner.Dispose();
                this.scanner = null;
            }

            if (this.session != null)
            {
                this.session.Close();
                this.session = null;
            }

            _displayInformation.OrientationChanged -= DisplayInformation_OrientationChanged;

            DisplayInformation.AutoRotationPreferences = DisplayOrientations.None;

            if (this._orientationSensor != null)
            {
                this._orientationSensor.OrientationChanged -= OrientationSensor_OrientationChanged;
            }

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // Cleanup the UI
                this.PreviewControl.Source = null;

                // Allow the device screen to sleep now that the preview is stopped
                _displayRequest.RequestRelease();
            });
        }