Esempio n. 1
0
        public IdentifyCustomersPage()
        {
            Title = "Identify";

            var screenSize = new Size(App.ScreenWidth, App.ScreenHeight);

            if (Device.RuntimePlatform == Device.UWP || CrossMedia.Current.IsCameraAvailable)
            {
                // Canvas View
                canvasView = new SKCanvasView();
                canvasView.PaintSurface      += OnCanvasViewPaintSurface;
                canvasView.IgnorePixelScaling = !(Device.RuntimePlatform == Device.UWP);

                AbsoluteLayout.SetLayoutBounds(canvasView, new Rectangle(0, 0, 1, 1));
                AbsoluteLayout.SetLayoutFlags(canvasView, AbsoluteLayoutFlags.All);

                // Capture preview window
                cameraPreview                     = new CameraPreview();
                cameraPreview.Filename            = "capture";
                cameraPreview.CameraOption        = Settings.CameraOption;
                cameraPreview.CapturePathCallback = new Action <string>(ProcessCameraPhoto);

                var padSize   = 20;
                var padLeft   = padSize / screenSize.Width;
                var padBottom = 1 - (padSize / screenSize.Height);

                AbsoluteLayout.SetLayoutBounds(cameraPreview, new Rectangle(padLeft, padBottom, screenSize.Width * .2, screenSize.Height * .2));
                AbsoluteLayout.SetLayoutFlags(cameraPreview, AbsoluteLayoutFlags.PositionProportional);

                var layout = new AbsoluteLayout();
                layout.Children.Add(canvasView);
                layout.Children.Add(cameraPreview);
                layout.SizeChanged += Layout_SizeChanged;
                Content             = layout;

                this.ToolbarItems.Add(
                    new ToolbarItem("Toggle Camera", null, () => ToggleCamera())
                {
                    Icon = "toggle.png"
                }
                    );
            }

            else
            {
                var label = new Label()
                {
                    Text = "Camera Not Available",
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    VerticalOptions   = LayoutOptions.CenterAndExpand
                };
                var layout = new StackLayout();
                layout.Children.Add(label);
                Content = layout;
            }
        }
Esempio n. 2
0
        public CapturePage()
        {
            BindingContext = customerModel = ServiceContainer.Resolve <ICreateOrderModel>();
            Title          = "Identify";

            // Activity Indicator
            activityIndicator           = new ActivityIndicator();
            activityIndicator.IsRunning = false;
            activityIndicator.IsVisible = false;

            this.ToolbarItems.Add(
                new ToolbarItem("Pick Photo", null, () => PickPhoto())
            {
                Icon = "folder.png"
            }
                );

            if (Device.RuntimePlatform == Device.UWP || CrossMedia.Current.IsCameraAvailable)
            {
                BackgroundColor = Color.Black;

                // Camera Preview
                cameraPreview                     = new CameraPreview();
                cameraPreview.Filename            = "capture";
                cameraPreview.CameraOption        = Settings.CameraOption;
                cameraPreview.CapturePathCallback = new Action <string>(ProcessCameraPhoto);
                cameraPreview.CameraReady        += (s, e) => StartCamera();

                AbsoluteLayout.SetLayoutBounds(cameraPreview, new Rectangle(1, 1, 1, 1));
                AbsoluteLayout.SetLayoutFlags(cameraPreview, AbsoluteLayoutFlags.All);

                // Capture Button
                var buttonSize    = 60;
                var captureButton = new Button();
                captureButton.Clicked          += CaptureButton_Clicked;
                captureButton.BackgroundColor   = Color.White;
                captureButton.WidthRequest      = buttonSize;
                captureButton.HeightRequest     = buttonSize;
                captureButton.BorderRadius      = buttonSize / 2;
                captureButton.BorderWidth       = 1;
                captureButton.BorderColor       = Color.Black;
                captureButton.HorizontalOptions = LayoutOptions.Center;

                AbsoluteLayout.SetLayoutBounds(captureButton, new Rectangle(.5, .9, buttonSize, buttonSize));
                AbsoluteLayout.SetLayoutFlags(captureButton, AbsoluteLayoutFlags.PositionProportional);

                activityIndicator.Color = Color.White;
                AbsoluteLayout.SetLayoutBounds(activityIndicator, new Rectangle(.5, .5, buttonSize, buttonSize));
                AbsoluteLayout.SetLayoutFlags(activityIndicator, AbsoluteLayoutFlags.PositionProportional);

                var layout = new AbsoluteLayout();
                layout.Children.Add(cameraPreview);
                layout.Children.Add(captureButton);
                layout.Children.Add(activityIndicator);

                Content = layout;

                this.ToolbarItems.Add(
                    new ToolbarItem("Toggle Camera", null, () => ToggleCamera())
                {
                    Icon = "toggle.png"
                }
                    );
            }

            else
            {
                var label = new Label()
                {
                    Text = "Camera Not Available",
                    HorizontalOptions = LayoutOptions.CenterAndExpand
                };

                activityIndicator.Color             = Color.Black;
                activityIndicator.HorizontalOptions = LayoutOptions.CenterAndExpand;

                var centerLayout = new StackLayout();
                centerLayout.HorizontalOptions = LayoutOptions.CenterAndExpand;
                centerLayout.VerticalOptions   = LayoutOptions.CenterAndExpand;
                centerLayout.Children.Add(label);
                centerLayout.Children.Add(activityIndicator);

                Content = centerLayout;
            }
        }