public async Task Add_PartialRejectedAudit()
        {
            var model = new CaptureViewModel
            {
                NotificationId       = notificationId,
                ShipmentNumber       = 1,
                HasNoPrenotification = true,
                ActualShipmentDate   = new Web.ViewModels.Shared.MaskedDateInputViewModel(actualDate),
                Receipt = new ReceiptViewModel
                {
                    ReceivedDate     = new Web.ViewModels.Shared.MaskedDateInputViewModel(rejectedDate),
                    RejectionReason  = "TestRejection",
                    ShipmentTypes    = ShipmentType.Partially,
                    ActualQuantity   = 10,
                    ActualUnits      = ShipmentQuantityUnits.Tonnes,
                    RejectedQuantity = 5,
                    RejectedUnits    = ShipmentQuantityUnits.Tonnes
                },
                Recovery = new RecoveryViewModel
                {
                    IsShipmentFullRejected = false,
                    NotificationType       = NotificationType.Disposal,
                    RecoveryDate           = new Web.ViewModels.Shared.MaskedDateInputViewModel(recoveredDate),
                }
            };

            A.CallTo(() => mediator.SendAsync(A <GetMovementIdIfExists> .Ignored)).Returns(movementId);

            var result = await controller.Create(notificationId, model);

            A.CallTo(() => this.auditService.AddMovementAudit(mediator, notificationId, 1, controller.User.GetUserId(), MovementAuditType.PartiallyRejected)).MustHaveHappened(Repeated.Exactly.Once);
        }
Esempio n. 2
0
        public async Task Add_DisposedAudit()
        {
            var model = new CaptureViewModel
            {
                NotificationId       = notificationId,
                ShipmentNumber       = 1,
                HasNoPrenotification = true,
                ActualShipmentDate   = new Web.ViewModels.Shared.MaskedDateInputViewModel(actualDate),
                Receipt = new ReceiptViewModel
                {
                    WasShipmentAccepted = true,
                    ReceivedDate        = new Web.ViewModels.Shared.MaskedDateInputViewModel(receivedDate),
                    ActualQuantity      = 1,
                    Units = ShipmentQuantityUnits.Kilograms
                },
                Recovery = new RecoveryViewModel
                {
                    RecoveryDate = new Web.ViewModels.Shared.MaskedDateInputViewModel(recoveredDate)
                },
                NotificationType = NotificationType.Disposal
            };

            A.CallTo(() => mediator.SendAsync(A <GetMovementIdIfExists> .Ignored)).Returns(movementId);

            var result = await controller.Create(notificationId, model);

            A.CallTo(() => this.auditService.AddMovementAudit(mediator, notificationId, 1, controller.User.GetUserId(), MovementAuditType.Disposed)).MustHaveHappened(Repeated.Exactly.Once);
        }
Esempio n. 3
0
 public MainPage()
 {
     InitializeComponent();
     //NavigationPage.SetHasNavigationBar(this, false);
     Viewmodel      = new CaptureViewModel();
     BindingContext = Viewmodel;
 }
        public ActionResult CaptureTime([Bind(Include = "EmployeeTimeID,EmployeeID,CapturedDate,TotalBillableHours,ChargableTime,ProjectCode,ProjectOwner,Comments,Client")] CaptureViewModel model)
        {
            var EmployeeModel = db.Employees
                                .Where(c => c.EmployeeID == model.EmployeeId)
                                .SingleOrDefault();

            if (ModelState.IsValid)
            {
                var capture = new EmployeeTime
                {
                    EmployeeID         = model.EmployeeId,
                    CapturedDate       = model.CapturedDate,
                    TotalBillableHours = model.TotalBillableHours,
                    ChargableTime      = model.ChargeableTime,
                    ProjectCode        = model.ProjectCode,
                    ProjectOwner       = model.ProjectOwner,
                    Comments           = model.Comments,
                    Client             = model.Client,
                    // EmployeeTimeID = model.EmployeeTimeID
                };
                db.EmployeeTimes.Add(capture);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("Index"));
        }
        public async Task<ActionResult> Index(Guid id)
        {
            var result = await mediator.SendAsync(new GetMovementReceiptAndRecoveryData(id));

            var model = new CaptureViewModel(result);

            return View(model);
        }
Esempio n. 6
0
        internal CaptureViewModel CreateViewModelForPrenotificationDate(int day, int month, int year)
        {
            var model = new CaptureViewModel();

            model.ShipmentNumber      = 52;
            model.PrenotificationDate = new MaskedDateInputViewModel(new DateTime(year, month, day));
            model.ActualShipmentDate  = new MaskedDateInputViewModel(new DateTime(year, month, day));
            return(model);
        }
        // GET: EmployeeTimes
        public ActionResult Index()
        {
            var model = new CaptureViewModel
            {
                AllocatedProject = _uiToolbox.Form.MultiSelector <EmployeeAllocatedProjects_Result>(null, dbStore.ProjectRepositoryStore.AllocatedProjects(EmployeeId).ToList(), "Id", "Name")
            };

            return(View(model));
        }
        private async Task SaveMovementData(Guid movementId, CaptureViewModel model, Guid notificationId)
        {
            if (model.Receipt.IsComplete() && !model.IsReceived && !model.IsRejected)
            {
                if (!model.Receipt.WasAccepted)
                {
                    await mediator.SendAsync(new RecordRejection(movementId,
                                                                 model.Receipt.ReceivedDate.Date.Value,
                                                                 model.Receipt.RejectionReason));

                    await this.auditService.AddImportMovementAudit(this.mediator,
                                                                   notificationId, model.ShipmentNumber.Value,
                                                                   User.GetUserId(),
                                                                   MovementAuditType.Rejected);
                }
                else
                {
                    await mediator.SendAsync(new RecordReceipt(movementId,
                                                               model.Receipt.ReceivedDate.Date.Value,
                                                               model.Receipt.Units.Value,
                                                               model.Receipt.ActualQuantity.Value));

                    await this.auditService.AddImportMovementAudit(this.mediator,
                                                                   notificationId, model.ShipmentNumber.Value,
                                                                   User.GetUserId(),
                                                                   MovementAuditType.Received);
                }
            }

            if (model.Recovery.IsComplete() &&
                (model.Receipt.IsComplete() || model.IsReceived) &&
                !model.IsOperationCompleted &&
                !model.IsRejected &&
                model.Receipt.WasAccepted)
            {
                await mediator.SendAsync(new RecordCompletedReceipt(movementId,
                                                                    model.Recovery.RecoveryDate.Date.Value));

                await this.auditService.AddImportMovementAudit(this.mediator,
                                                               notificationId, model.ShipmentNumber.Value,
                                                               User.GetUserId(),
                                                               model.NotificationType == NotificationType.Disposal?MovementAuditType.Disposed : MovementAuditType.Recovered);
            }

            if (model.HasComments)
            {
                await mediator.SendAsync(new SetMovementComments(movementId)
                {
                    Comments     = model.Comments,
                    StatsMarking = model.StatsMarking
                });
            }
        }
Esempio n. 9
0
        internal CaptureViewModel CreateViewModelForPrenotificationDate(int day, int month, int year)
        {
            var model = new CaptureViewModel();

            model.ShipmentNumber         = 52;
            model.PrenotificationDate    = new MaskedDateInputViewModel(new DateTime(year, month, day));
            model.ActualShipmentDate     = new MaskedDateInputViewModel(new DateTime(year, month, day));
            model.Receipt.ReceivedDate   = new MaskedDateInputViewModel(new DateTime(year, month, day));
            model.Receipt.ActualQuantity = 10;
            model.Receipt.WasAccepted    = true;
            model.Receipt.ActualUnits    = Core.Shared.ShipmentQuantityUnits.Tonnes;
            return(model);
        }
Esempio n. 10
0
        public async Task <ActionResult> Edit(Guid id, Guid movementId, CaptureViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.IsSaved = false;
                await UpdateSummary(model, id);

                return(View(model));
            }

            await SaveMovementData(movementId, model, id, true);

            return(RedirectToAction("Edit", new { movementId, saved = true }));
        }
Esempio n. 11
0
        public void ActualShipmentDateCanBeSixtyDaysAfterPrenotification()
        {
            var model = new CaptureViewModel();

            model.ShipmentNumber         = 52;
            model.PrenotificationDate    = new MaskedDateInputViewModel(new DateTime(2015, 5, 25));
            model.ActualShipmentDate     = new MaskedDateInputViewModel(new DateTime(2015, 07, 24));
            model.Receipt.ReceivedDate   = new MaskedDateInputViewModel(new DateTime(2016, 6, 1));
            model.Receipt.ActualQuantity = 10;
            model.Receipt.WasAccepted    = true;
            model.Receipt.ActualUnits    = Core.Shared.ShipmentQuantityUnits.Tonnes;

            Assert.Empty(ViewModelValidator.ValidateViewModel(model));
        }
Esempio n. 12
0
        public async Task Add_NoPrenotificationReceivedAudit()
        {
            var model = new CaptureViewModel
            {
                NotificationId       = notificationId,
                ShipmentNumber       = 1,
                HasNoPrenotification = true,
                ActualShipmentDate   = new Web.ViewModels.Shared.MaskedDateInputViewModel(actualDate)
            };

            A.CallTo(() => mediator.SendAsync(A <GetMovementIdIfExists> .Ignored)).Returns(movementId);

            var result = await controller.Create(notificationId, model);

            A.CallTo(() => this.auditService.AddMovementAudit(mediator, notificationId, 1, controller.User.GetUserId(), MovementAuditType.NoPrenotificationReceived)).MustHaveHappened(Repeated.Exactly.Once);
        }
Esempio n. 13
0
        internal CaptureViewModel CreateViewModelForActualDate(int day, int month, int year, bool isDateInPast)
        {
            var model = new CaptureViewModel();

            model.ShipmentNumber = 52;

            if (!isDateInPast)
            {
                model.PrenotificationDate = new MaskedDateInputViewModel(new DateTime(2016, 6, 1));
            }
            else
            {
                model.PrenotificationDate = new MaskedDateInputViewModel(new DateTime(2016, 5, 1));
            }
            model.ActualShipmentDate = new MaskedDateInputViewModel(new DateTime(year, month, day));
            return(model);
        }
        public async Task <ActionResult> Create(Guid id, CaptureViewModel model)
        {
            if (!ModelState.IsValid)
            {
                await UpdateSummary(model, id);

                return(View(model));
            }

            //Check if shipment number exists
            var movementId =
                await mediator.SendAsync(new GetMovementIdIfExists(id, model.ShipmentNumber.Value));

            if (!movementId.HasValue)
            {
                movementId = await mediator.SendAsync(new CreateMovementInternal(id,
                                                                                 model.ShipmentNumber.Value,
                                                                                 model.PrenotificationDate.Date,
                                                                                 model.ActualShipmentDate.Date.Value,
                                                                                 model.HasNoPrenotification));

                await this.auditService.AddMovementAudit(this.mediator,
                                                         id, model.ShipmentNumber.Value,
                                                         User.GetUserId(),
                                                         model.HasNoPrenotification == true?MovementAuditType.NoPrenotificationReceived : MovementAuditType.Prenotified);

                if (movementId.HasValue)
                {
                    await SaveMovementData(movementId.Value, model, id);

                    return(RedirectToAction("Edit", new { movementId, saved = true }));
                }
            }
            else
            {
                ModelState.AddModelError("Number", CaptureMovementControllerResources.NumberExists);
            }

            ModelState.AddModelError("Number", CaptureMovementControllerResources.SaveUnsuccessful);
            await UpdateSummary(model, id);

            return(View(model));
        }
Esempio n. 15
0
        public async Task <ActionResult> Edit(Guid id, Guid movementId, bool saved = false)
        {
            ViewBag.IsSaved = saved;
            var result = await mediator.SendAsync(new GetImportMovementReceiptAndRecoveryData(movementId));

            if (result.Data.IsCancelled)
            {
                return(RedirectToAction("Cancelled"));
            }

            var model = new CaptureViewModel(result);

            await UpdateSummary(model, id);

            model.ShowShipmentDataOverride = await CanShowEditLink();

            model.MovementId     = movementId;
            model.NotificationId = id;
            return(View(model));
        }
Esempio n. 16
0
        public async Task <ActionResult> Create(Guid id, int?shipmentNumber = null)
        {
            var model = new CaptureViewModel();

            if (shipmentNumber.HasValue)
            {
                model.ShipmentNumber = shipmentNumber;
            }

            var result = await mediator.SendAsync(new GetNotificationDetails(id));

            model.Recovery.NotificationType = result.NotificationType;
            model.NotificationType          = result.NotificationType;
            //Set the units based on the notification Id
            var units = await mediator.SendAsync(new GetImportShipmentUnits(id));

            model.Receipt.PossibleUnits = ShipmentQuantityUnitsMetadata.GetUnitsOfThisType(units).ToArray();
            await UpdateSummary(model, id);

            return(View(model));
        }
Esempio n. 17
0
        internal CaptureViewModel CreateViewModelForRecoveredDate(int day, int month, int year, bool isDateInPast)
        {
            var model = new CaptureViewModel();

            model.ShipmentNumber = 52;
            if (!isDateInPast)
            {
                model.PrenotificationDate  = new MaskedDateInputViewModel(new DateTime(2016, 6, 1));
                model.ActualShipmentDate   = new MaskedDateInputViewModel(new DateTime(2016, 6, 1));
                model.Receipt.ReceivedDate = new MaskedDateInputViewModel(new DateTime(2016, 6, 1));
            }
            else
            {
                model.PrenotificationDate  = new MaskedDateInputViewModel(new DateTime(2016, 5, 1));
                model.ActualShipmentDate   = new MaskedDateInputViewModel(new DateTime(2016, 5, 1));
                model.Receipt.ReceivedDate = new MaskedDateInputViewModel(new DateTime(2016, 5, 1));
            }
            model.Receipt.ActualQuantity = 10;
            model.Receipt.ActualUnits    = Core.Shared.ShipmentQuantityUnits.Tonnes;
            model.Recovery.RecoveryDate  = new MaskedDateInputViewModel(new DateTime(year, month, day));
            return(model);
        }
        public async Task<ActionResult> Index(Guid id, CaptureViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            if (model.Receipt.IsComplete() && !model.IsReceived)
            {
                if (!model.Receipt.WasShipmentAccepted)
                {
                    await mediator.SendAsync(new RecordRejectionInternal(id,
                        model.Receipt.ReceivedDate.AsDateTime().Value,
                        model.Receipt.RejectionReason,
                        model.Receipt.RejectionFurtherInformation));
                }
                else
                {
                    await mediator.SendAsync(new RecordReceiptInternal(id, 
                        model.Receipt.ReceivedDate.AsDateTime().Value,
                        model.Receipt.ActualQuantity.Value,
                        model.Receipt.Units.Value));
                }
            }

            if (model.Recovery.IsComplete() 
                && (model.Receipt.IsComplete() || model.IsReceived) 
                && !model.IsOperationCompleted
                && model.Receipt.WasShipmentAccepted)
            {
                await mediator.SendAsync(new RecordOperationCompleteInternal(id,
                    model.Recovery.RecoveryDate.AsDateTime().Value));
            }

            return RedirectToAction("Index", "Home", new { area = "AdminExportNotificationMovements", id = model.NotificationId });
        }
Esempio n. 19
0
        private async Task SaveMovementData(Guid movementId, CaptureViewModel model, Guid notificationId, bool isEdit)
        {
            if (model.Receipt.ShipmentTypes == ShipmentType.Accepted)
            {
                if (model.Receipt.ActualQuantity != null && model.Receipt.ReceivedDate.Date != null && model.IsReceived == false)
                {
                    await mediator.SendAsync(new RecordReceipt(movementId,
                                                               model.Receipt.ReceivedDate.Date.Value,
                                                               model.Receipt.ActualUnits.Value,
                                                               model.Receipt.ActualQuantity.Value));

                    await this.auditService.AddImportMovementAudit(this.mediator,
                                                                   notificationId, model.ShipmentNumber.Value,
                                                                   User.GetUserId(),
                                                                   MovementAuditType.Received);
                }
            }
            else if (model.Receipt.ShipmentTypes == ShipmentType.Rejected)
            {
                var isRejectMovementAvailable = await mediator.SendAsync(new GetImportRejectionByMovementId(movementId));

                if (isEdit == false || isRejectMovementAvailable == false)
                {
                    await mediator.SendAsync(new RecordRejection(movementId,
                                                                 model.Receipt.ReceivedDate.Date.Value,
                                                                 model.Receipt.RejectionReason,
                                                                 model.Receipt.RejectedQuantity.Value,
                                                                 model.Receipt.RejectedUnits.Value));

                    await this.auditService.AddImportMovementAudit(this.mediator,
                                                                   notificationId, model.ShipmentNumber.Value,
                                                                   User.GetUserId(),
                                                                   MovementAuditType.Rejected);
                }
            }
            else
            {
                var isPartailRejectMovementAvailable = await mediator.SendAsync(new GetImportPartialRejectionByMovementId(movementId));

                if (isEdit == false || isPartailRejectMovementAvailable == false)
                {
                    var recoveryDate = (DateTime?)null;
                    if (model.Recovery.RecoveryDate.Date.HasValue)
                    {
                        recoveryDate = model.Recovery.RecoveryDate.Date.Value;
                    }

                    await mediator.SendAsync(new RecordPartialRejection(movementId,
                                                                        model.Receipt.ReceivedDate.Date.Value,
                                                                        model.Receipt.RejectionReason,
                                                                        model.Receipt.ActualQuantity.Value,
                                                                        model.Receipt.ActualUnits.Value,
                                                                        model.Receipt.RejectedQuantity.Value,
                                                                        model.Receipt.RejectedUnits.Value,
                                                                        recoveryDate));

                    await this.auditService.AddImportMovementAudit(this.mediator,
                                                                   notificationId,
                                                                   model.ShipmentNumber.Value,
                                                                   User.GetUserId(),
                                                                   MovementAuditType.PartiallyRejected);

                    if (model.Recovery.RecoveryDate.Date.HasValue)
                    {
                        recoveryDate = model.Recovery.RecoveryDate.Date.Value;
                        await mediator.SendAsync(new RecordPartialOperationCompleteInternal(movementId, recoveryDate));

                        await mediator.SendAsync(new RecordCompletedReceipt(movementId, recoveryDate.Value));

                        await this.auditService.AddImportMovementAudit(this.mediator,
                                                                       notificationId,
                                                                       model.ShipmentNumber.Value,
                                                                       User.GetUserId(),
                                                                       model.NotificationType == NotificationType.Disposal?MovementAuditType.Disposed : MovementAuditType.Recovered);
                    }
                }
                else
                {
                    var recoveryDate = (DateTime?)null;
                    if (model.Recovery.RecoveryDate.Date.HasValue)
                    {
                        recoveryDate = model.Recovery.RecoveryDate.Date.Value;
                        await mediator.SendAsync(new RecordPartialOperationCompleteInternal(movementId, recoveryDate));

                        await mediator.SendAsync(new RecordCompletedReceipt(movementId, recoveryDate.Value));

                        await this.auditService.AddImportMovementAudit(this.mediator,
                                                                       notificationId,
                                                                       model.ShipmentNumber.Value,
                                                                       User.GetUserId(),
                                                                       model.NotificationType == NotificationType.Disposal?MovementAuditType.Disposed : MovementAuditType.Recovered);
                    }
                }
            }

            if (model.Recovery.IsComplete() && !model.IsOperationCompleted && model.Receipt.ShipmentTypes == ShipmentType.Accepted)
            {
                await mediator.SendAsync(new RecordCompletedReceipt(movementId,
                                                                    model.Recovery.RecoveryDate.Date.Value));

                await this.auditService.AddImportMovementAudit(this.mediator,
                                                               notificationId, model.ShipmentNumber.Value,
                                                               User.GetUserId(),
                                                               model.NotificationType == NotificationType.Disposal?MovementAuditType.Disposed : MovementAuditType.Recovered);
            }

            if (model.HasComments)
            {
                await mediator.SendAsync(new SetMovementComments(movementId)
                {
                    Comments     = model.Comments,
                    StatsMarking = model.StatsMarking
                });
            }
            else if (!string.IsNullOrEmpty(model.StatsMarking))
            {
                await mediator.SendAsync(new SetMovementComments(movementId)
                {
                    StatsMarking = model.StatsMarking
                });
            }
        }
Esempio n. 20
0
        private async Task UpdateSummary(CaptureViewModel model, Guid id)
        {
            var summary = await mediator.SendAsync(new GetImportMovementsSummary(id));

            model.SetSummaryData(summary);
        }
Esempio n. 21
0
        public CameraPage()
        {
            BindingContext = captureModel = new CaptureViewModel();
            Title          = "Camera";
            layout         = new RelativeLayout();

            if (CrossMedia.Current.IsCameraAvailable)
            {
                BackgroundColor = Color.Black;

                // Camera Preview
                cameraPreview = new XCameraView();
                //cameraPreview.CameraOption = Settings.CameraOption;
                cameraPreview.CaptureBytesCallback = new Action <byte[]>(ProcessCameraPhoto);
                cameraPreview.CameraReady         += (s, e) => StartCamera();

                layout.Children.Add(cameraPreview,
                                    Constraint.Constant(0),
                                    Constraint.RelativeToParent((parent) =>
                {
                    var viewHeight = MathUtils.FitSize4X3(parent.Width, parent.Height).Height;
                    return(parent.Height / 2 - viewHeight / 2);
                }),
                                    Constraint.RelativeToParent((parent) =>
                {
                    return(MathUtils.FitSize4X3(parent.Width, parent.Height).Width);
                }),
                                    Constraint.RelativeToParent((parent) =>
                {
                    return(MathUtils.FitSize4X3(parent.Width, parent.Height).Height);
                }));

                // Capture Button
                var buttonSize    = 60;
                var captureButton = new Button();
                captureButton.Clicked          += CaptureButton_Clicked;
                captureButton.BackgroundColor   = Color.LightGray.MultiplyAlpha(.5);
                captureButton.WidthRequest      = buttonSize;
                captureButton.HeightRequest     = buttonSize;
                captureButton.CornerRadius      = buttonSize / 2;
                captureButton.BorderWidth       = 1;
                captureButton.BorderColor       = Color.DarkGray;
                captureButton.HorizontalOptions = LayoutOptions.Center;

                layout.Children.Add(captureButton,
                                    Constraint.RelativeToParent((parent) => { return((parent.Width * .5) - (buttonSize * .5)); }),
                                    Constraint.RelativeToParent((parent) => { return((parent.Height * .9) - (buttonSize * .5)); }));

                // Last Capture
                cachedCapture                 = new CachedImage();
                cachedCapture.Aspect          = Aspect.AspectFill;
                cachedCapture.BackgroundColor = Color.White;

                layout.Children.Add(cachedCapture,
                                    Constraint.Constant(20),
                                    Constraint.RelativeToView(captureButton, (parent, sibling) => { return(sibling.Y); }),
                                    Constraint.Constant(buttonSize),
                                    Constraint.Constant(buttonSize));

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

            else
            {
                messageLabel = new Label()
                {
                    WidthRequest            = 300,
                    TextColor               = Color.SlateGray,
                    HorizontalOptions       = LayoutOptions.Center,
                    HorizontalTextAlignment = TextAlignment.Center
                };
                messageLabel.Text = "The camera not supported on this device.";

                layout.Children.Add(messageLabel,
                                    Constraint.RelativeToParent((parent) =>
                {
                    return(parent.Width * .5 - messageLabel.Width * .5);
                }),
                                    Constraint.RelativeToParent((parent) =>
                {
                    return(parent.Height * .4);
                })
                                    );

                titleLabel = new Label()
                {
                    WidthRequest            = 300,
                    HeightRequest           = 20,
                    FontAttributes          = FontAttributes.Bold,
                    TextColor               = Color.Black,
                    HorizontalOptions       = LayoutOptions.Center,
                    HorizontalTextAlignment = TextAlignment.Center
                };
                titleLabel.Text = "No Camera";
                layout.Children.Add(titleLabel,
                                    Constraint.RelativeToParent((parent) =>
                {
                    return(parent.Width * .5 - titleLabel.Width * .5);
                }),
                                    Constraint.RelativeToView(messageLabel, (parent, sibling) =>
                {
                    return(sibling.Y - titleLabel.Height - 10);
                })
                                    );
            }

            Content = layout;
        }
Esempio n. 22
0
        public CapturePage()
        {
            BindingContext = captureModel = new CaptureViewModel(Navigation);
            Title          = "Capture";

            // 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.CornerRadius      = 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
            {
                cameraMissingLabel = new Label()
                {
                    Text = messageCameraNotSupported,
                    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(cameraMissingLabel);
                centerLayout.Children.Add(activityIndicator);

                Content = centerLayout;
            }
        }
Esempio n. 23
0
        public CapturePage()
        {
            BindingContext = captureModel = new CaptureViewModel(Navigation);
            Title          = ApplicationResource.PageCaptureTitle;
            layout         = new RelativeLayout();

            if (CrossMedia.Current.IsCameraAvailable)
            {
                BackgroundColor = Color.Black;

                // Camera Preview
                cameraPreview = new CameraPreview();
                cameraPreview.CameraOption         = Settings.CameraOption;
                cameraPreview.CaptureBytesCallback = new Action <byte[]>(ProcessCameraPhoto);
                cameraPreview.CameraReady         += (s, e) => StartCamera();

                layout.Children.Add(cameraPreview,
                                    Constraint.Constant(0),
                                    Constraint.Constant(0),
                                    Constraint.RelativeToParent((parent) => { return(parent.Width); }),
                                    Constraint.RelativeToParent((parent) => { return(parent.Height); }));

                // Last Capture
                cachedCapture                 = new CachedImage();
                cachedCapture.Aspect          = Aspect.AspectFill;
                cachedCapture.BackgroundColor = Color.White;

                layout.Children.Add(cachedCapture,
                                    Constraint.Constant(5),
                                    Constraint.Constant(5),
                                    Constraint.Constant(80),
                                    Constraint.Constant(80));

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

                layout.Children.Add(captureButton,
                                    Constraint.RelativeToParent((parent) => { return((parent.Width * .5) - (buttonSize * .5)); }),
                                    Constraint.RelativeToParent((parent) => { return((parent.Height * .9) - (buttonSize * .5)); }));

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

            else
            {
                heroImage = new Image();
                heroImage.HeightRequest = heroImage.WidthRequest = 200;
                heroImage.Source        = ImageSource.FromFile("CameraMissing");
                heroImage.SizeChanged  += (s, e) =>
                {
                    layout.ForceLayout();
                };


                layout.Children.Add(heroImage,
                                    Constraint.RelativeToParent((parent) =>
                {
                    return((parent.Width * .5) - (heroImage.Width / 2));
                }),
                                    Constraint.RelativeToParent((parent) =>
                {
                    return(parent.Height * .3 - (heroImage.Height / 2));
                })
                                    );

                messageLabel = new Label()
                {
                    WidthRequest            = 300,
                    TextColor               = Color.SlateGray,
                    HorizontalOptions       = LayoutOptions.Center,
                    HorizontalTextAlignment = TextAlignment.Center
                };
                messageLabel.Text = ApplicationResource.CameraNotSupportedMessage;

                layout.Children.Add(messageLabel,
                                    Constraint.RelativeToParent((parent) =>
                {
                    return((parent.Width * .5) - (messageLabel.Width / 2));
                }),
                                    Constraint.RelativeToParent((parent) =>
                {
                    return((parent.Height * .8) - (messageLabel.Height));
                })
                                    );

                titleLabel = new Label()
                {
                    WidthRequest            = 300,
                    HeightRequest           = 20,
                    FontAttributes          = FontAttributes.Bold,
                    TextColor               = Color.Black,
                    HorizontalOptions       = LayoutOptions.Center,
                    HorizontalTextAlignment = TextAlignment.Center
                };
                titleLabel.Text = ApplicationResource.CameraNotSupportedTitle;
                layout.Children.Add(titleLabel,
                                    Constraint.RelativeToParent((parent) =>
                {
                    return((parent.Width * .5) - (titleLabel.Width / 2));
                }),
                                    Constraint.RelativeToView(messageLabel, (parent, sibling) =>
                {
                    return(messageLabel.Y - titleLabel.Height - 10);
                })
                                    );
            }

            Content = layout;
        }