Beispiel #1
0
        public FirstPage() : base(PageTitleConstants.FirstPage)
        {
            const string entryTextPaceHolder = "Enter text and click 'Go'";

            _goButton = new StyledButton(Borders.Thin, 1)
            {
                Text         = "Go",
                AutomationId = AutomationIdConstants.GoButton, // This provides an ID that can be referenced in UITests
            };
            _goButton.SetBinding(Button.CommandProperty, nameof(ViewModel.GoButtonCommand));

            var textEntry = new StyledEntry(1)
            {
                Placeholder             = entryTextPaceHolder,
                AutomationId            = AutomationIdConstants.TextEntry, // This provides an ID that can be referenced in UITests
                PlaceholderColor        = Color.FromHex("749FA8"),
                HorizontalTextAlignment = TextAlignment.Center
            };

            CustomReturnEffect.SetReturnType(textEntry, ReturnType.Go);
            textEntry.SetBinding(CustomReturnEffect.ReturnCommandProperty, nameof(ViewModel.GoButtonCommand));
            textEntry.SetBinding(Entry.TextProperty, nameof(ViewModel.EntryText));

            var textLabel = new StyledLabel
            {
                AutomationId      = AutomationIdConstants.TextLabel, // This provides an ID that can be referenced in UITests
                HorizontalOptions = LayoutOptions.Center
            };

            textLabel.SetBinding(Label.TextProperty, nameof(ViewModel.LabelText));

            _listPageButton = new StyledButton(Borders.Thin, 1)
            {
                Text         = "Go to List Page",
                AutomationId = AutomationIdConstants.ListViewButton // This provides an ID that can be referenced in UITests
            };

            var activityIndicator = new ActivityIndicator
            {
                AutomationId = AutomationIdConstants.BusyActivityIndicator, // This provides an ID that can be referenced in UITests
                Color        = Color.White
            };

            activityIndicator.SetBinding(IsVisibleProperty, nameof(ViewModel.IsActiityIndicatorRunning));
            activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(ViewModel.IsActiityIndicatorRunning));

            Func <RelativeLayout, double> getTextEntryWidth         = (p) => textEntry.Measure(p.Width, p.Height).Request.Width;
            Func <RelativeLayout, double> getGoButtonWidth          = (p) => _goButton.Measure(p.Width, p.Height).Request.Width;
            Func <RelativeLayout, double> getActivityIndicatorWidth = (p) => activityIndicator.Measure(p.Width, p.Height).Request.Width;
            Func <RelativeLayout, double> getTextLabelWidth         = (p) => textLabel.Measure(p.Width, p.Height).Request.Width;

            var relativeLayout = new RelativeLayout();

            relativeLayout.Children.Add(textEntry,
                                        Constraint.RelativeToParent((parent) => parent.X),
                                        Constraint.RelativeToParent((parent) => parent.Y),
                                        Constraint.RelativeToParent((parent) => parent.Width - 20));
            relativeLayout.Children.Add(_goButton,
                                        Constraint.RelativeToParent((parent) => parent.X),
                                        Constraint.RelativeToView(textEntry, (parent, view) => view.Y + view.Height + _relativeLayoutPadding),
                                        Constraint.RelativeToParent((parent) => parent.Width - 20));
            relativeLayout.Children.Add(activityIndicator,
                                        Constraint.RelativeToParent((parent) => parent.Width / 2 - getActivityIndicatorWidth(parent) / 2),
                                        Constraint.RelativeToView(_goButton, (parent, view) => view.Y + view.Height + _relativeLayoutPadding));
            relativeLayout.Children.Add(textLabel,
                                        Constraint.RelativeToParent((parent) => parent.Width / 2 - getTextLabelWidth(parent) / 2),
                                        Constraint.RelativeToView(_goButton, (parent, view) => view.Y + view.Height + _relativeLayoutPadding));
            relativeLayout.Children.Add(_listPageButton,
                                        Constraint.RelativeToParent((parent) => parent.X),
                                        Constraint.RelativeToView(_goButton, (parent, view) => view.Y + view.Height + _relativeLayoutPadding * 15),
                                        Constraint.RelativeToParent((parent) => parent.Width - 20));

            Padding = GetPagePadding();
            Content = relativeLayout;
        }
Beispiel #2
0
        public FirstPage()
        {
            const string entryTextPaceHolder = "Enter text and click 'Go'";

            var viewModel = new FirstPageViewModel();

            BindingContext = viewModel;

            _goButton = new StyledButton(Borders.Thin, 1)
            {
                Text         = "Go",
                AutomationId = AutomationIdConstants.GoButton,                 // This provides an ID that can be referenced in UITests
            };
            _goButton.SetBinding <FirstPageViewModel>(Button.CommandProperty, vm => vm.GoButtonTapped);

            var textEntry = new StyledEntry(1)
            {
                Placeholder      = entryTextPaceHolder,
                AutomationId     = AutomationIdConstants.TextEntry,             // This provides an ID that can be referenced in UITests
                PlaceholderColor = Color.FromHex("749FA8"),
                ReturnType       = ReturnType.Go
            };

            textEntry.Completed += (sender, e) => viewModel?.GoButtonTapped?.Execute(null);
            textEntry.SetBinding <FirstPageViewModel>(Entry.TextProperty, vm => vm.EntryText);

            var textLabel = new StyledLabel
            {
                AutomationId      = AutomationIdConstants.TextLabel,            // This provides an ID that can be referenced in UITests
                HorizontalOptions = LayoutOptions.Center
            };

            textLabel.SetBinding <FirstPageViewModel>(Label.TextProperty, vm => vm.LabelText);

            _listPageButton = new StyledButton(Borders.Thin, 1)
            {
                Text         = "Go to List Page",
                AutomationId = AutomationIdConstants.ListViewButton                 // This provides an ID that can be referenced in UITests
            };

            var activityIndicator = new ActivityIndicator
            {
                AutomationId = AutomationIdConstants.BusyActivityIndicator,                 // This provides an ID that can be referenced in UITests
                Color        = Color.White
            };

            activityIndicator.SetBinding <FirstPageViewModel>(ActivityIndicator.IsVisibleProperty, vm => vm.IsActiityIndicatorRunning);
            activityIndicator.SetBinding <FirstPageViewModel>(ActivityIndicator.IsRunningProperty, vm => vm.IsActiityIndicatorRunning);

            var stackLayout = new StackLayout
            {
                Children =
                {
                    textEntry,
                    _goButton,
                    activityIndicator,
                    textLabel,
                },
                VerticalOptions   = LayoutOptions.StartAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand
            };

            var relativeLayout = new RelativeLayout();

            relativeLayout.Children.Add(stackLayout,
                                        Constraint.RelativeToParent((parent) =>
            {
                return(parent.X);
            }),
                                        Constraint.RelativeToParent((parent) =>
            {
                return(parent.Y);
            }),
                                        Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width - 20);
            }),
                                        Constraint.RelativeToParent((parent) =>
            {
                return(parent.Height / 2);
            })
                                        );

            relativeLayout.Children.Add(_listPageButton,
                                        Constraint.RelativeToParent((parent) =>
            {
                return(parent.X);
            }),
                                        Constraint.Constant(250),
                                        Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width - 20);
            })
                                        );

            Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);
            Title   = "First Page";
            Content = relativeLayout;
        }
Beispiel #3
0
        public NewUserSignUpPage()
        {
            ViewModel.SaveFailed                += HandleSaveFailed;
            ViewModel.TakePhotoFailed           += HandleTakePhotoFailed;
            ViewModel.SaveSuccessfullyCompleted += HandleSaveSuccessfullyCompleted;

            BackgroundColor = Color.FromHex("2980b9");

            var passwordEntry = new StyledEntry(1)
            {
                Placeholder             = "Password",
                IsPassword              = true,
                HorizontalOptions       = LayoutOptions.Fill,
                HorizontalTextAlignment = TextAlignment.End,
                VerticalOptions         = LayoutOptions.Fill,
                PlaceholderColor        = Color.FromHex("749FA8"),
                ReturnType              = ReturnType.Done
            };

            passwordEntry.ReturnCommand = new Command(() => passwordEntry.Unfocus());
            passwordEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(ViewModel.PasswordEntryText));

            var usernameEntry = new StyledEntry(1)
            {
                Placeholder             = "Username",
                HorizontalOptions       = LayoutOptions.Fill,
                HorizontalTextAlignment = TextAlignment.End,
                PlaceholderColor        = Color.FromHex("749FA8"),
                ReturnType    = ReturnType.Next,
                ReturnCommand = new Command(() => passwordEntry.Focus())
            };

            usernameEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(ViewModel.UsernameEntryText));

            _saveUsernameButton = new StyledButton(Borders.Thin, 1)
            {
                Text = "Save User",
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.EndAndExpand
            };
            _saveUsernameButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive));
            _saveUsernameButton.SetBinding(Button.CommandProperty, nameof(ViewModel.SaveButtonCommand));

            _cancelButton = new StyledButton(Borders.Thin, 1)
            {
                Text = "Cancel",
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.End
            };
            _cancelButton.Clicked += HandleCancelButtonClicked;
            _cancelButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive));
            _cancelButton.SetBinding(Button.CommandProperty, nameof(ViewModel.CancelButtonCommand));

            _takePhotoButton = new StyledButton(Borders.Thin, 1)
            {
                Text = "Take Photo",
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.EndAndExpand
            };
            _takePhotoButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive));
            _takePhotoButton.SetBinding(Button.CommandProperty, nameof(ViewModel.TakePhotoButtonCommand));

            var isFacialRecognitionCompletedDescriptionLabel = new StyledLabel
            {
                Text = "Facial Recognition Completed",
                VerticalTextAlignment = TextAlignment.Center
            };

            var isFacialRecognitionCompletedLabel = new FontAwesomeIcon
            {
                TextColor               = Color.White,
                VerticalTextAlignment   = TextAlignment.Center,
                HorizontalTextAlignment = TextAlignment.Center
            };

            isFacialRecognitionCompletedLabel.SetBinding(Label.TextProperty, nameof(ViewModel.FontAwesomeLabelText));

            if (Device.RuntimePlatform is Device.iOS)
            {
                isFacialRecognitionCompletedLabel.SetBinding(IsVisibleProperty, nameof(ViewModel.IsInternetConnectionInactive));
            }

            var activityIndicator = new ActivityIndicator
            {
                Color             = Color.White,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.EndAndExpand,
            };

            activityIndicator.SetBinding(IsVisibleProperty, nameof(ViewModel.IsInternetConnectionActive));
            activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(ViewModel.IsInternetConnectionActive));

            var facialRecognitionStackLayout = new StackLayout
            {
                Orientation       = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.Center,

                Children =
                {
                    isFacialRecognitionCompletedDescriptionLabel,
                    isFacialRecognitionCompletedLabel
                }
            };

            var stackLayout = new StackLayout
            {
                Padding         = new Thickness(20, 50, 20, 20),
                VerticalOptions = LayoutOptions.FillAndExpand,

                Children =
                {
                    new Label
                    {
                        Text              = "Please enter username",
                        TextColor         = Color.White,
                        HorizontalOptions = LayoutOptions.Start
                    },

                    usernameEntry,

                    new Label
                    {
                        Text              = "Please enter password",
                        TextColor         = Color.White,
                        HorizontalOptions = LayoutOptions.Start
                    },

                    passwordEntry,
                    _takePhotoButton,
                    facialRecognitionStackLayout,
                }
            };

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                facialRecognitionStackLayout.Children.Add(activityIndicator);
                break;

            case Device.Android:
                stackLayout.Children.Add(activityIndicator);
                break;

            default:
                throw new NotSupportedException("Device Runtime Unsupported");
            }
            stackLayout.Children.Add(_saveUsernameButton);
            stackLayout.Children.Add(_cancelButton);

            Content = new Xamarin.Forms.ScrollView {
                Content = stackLayout
            };

            On <Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);
        }
Beispiel #4
0
        public LoginPage()
        {
            try
            {
                ViewModel.LoginFailed   += HandleLoginFailed;
                ViewModel.LoginApproved += HandleLoginApproved;

                BackgroundColor = Color.FromHex("#3498db");
                Padding         = GetPagePadding();

                _logo = new Image {
                    Source = "xamarin_logo"
                };

                _logoSlogan = new StyledLabel
                {
                    Opacity = 0,
                    Text    = "ABSENSI",
                };
                _usernameEntry = new StyledEntry
                {
                    Placeholder   = "Username",
                    ReturnType    = ReturnType.Next,
                    ReturnCommand = new Command(() => _passwordEntry.Focus())
                };
                _usernameEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(ViewModel.UsernameEntryText));

                _passwordEntry = new StyledEntry
                {
                    Placeholder = "Password",
                    IsPassword  = true,
                    ReturnType  = ReturnType.Done
                };
                _passwordEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(ViewModel.PasswordEntryText));
                _passwordEntry.SetBinding(Xamarin.Forms.Entry.ReturnCommandProperty, nameof(ViewModel.LoginButtonTappedCommand));

                _loginButton = new StyledButton(Borders.Thin)
                {
                    Text = "Login"
                };
                _loginButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive));
                _loginButton.SetBinding(Button.CommandProperty, nameof(ViewModel.LoginButtonTappedCommand));

                _newUserSignUpButton = new StyledButton(Borders.None)
                {
                    Text = "Sign-up"
                };
                _newUserSignUpButton.Clicked += HandleNewUserSignUpButtonClicked;
                _newUserSignUpButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive));

                _HomeAutomationButton = new StyledButton(Borders.None)
                {
                    Text = "Home Automation"
                };
                _HomeAutomationButton.Clicked += HandleHomeAutomationClicked;
                _HomeAutomationButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive));

                var activityIndicator = new ActivityIndicator {
                    Color = Color.White
                };
                activityIndicator.SetBinding(IsVisibleProperty, nameof(ViewModel.IsInternetConnectionActive));
                activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(ViewModel.IsInternetConnectionActive));

                On <Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);

                Func <RelativeLayout, double> getNewUserButtonWidth      = (p) => _newUserSignUpButton.Measure(p.Width, p.Height).Request.Width;
                Func <RelativeLayout, double> getLogoSloganWidth         = (p) => _logoSlogan.Measure(p.Width, p.Height).Request.Width;
                Func <RelativeLayout, double> getActivityIndicatorHeight = (p) => activityIndicator.Measure(p.Width, p.Height).Request.Height;
                Func <RelativeLayout, double> getActivityIndicatorWidth  = (p) => activityIndicator.Measure(p.Width, p.Height).Request.Width;

                _relativeLayout = new RelativeLayout();
                _relativeLayout.Children.Add(
                    _logo,
                    xConstraint: Constraint.Constant(100),
                    yConstraint: Constraint.Constant(250),
                    widthConstraint: Constraint.RelativeToParent(p => p.Width - 200)
                    );

                _relativeLayout.Children.Add(
                    _logoSlogan,
                    xConstraint: Constraint.RelativeToParent(p => (p.Width / 2) - (getLogoSloganWidth(p) / 2)),
                    yConstraint: Constraint.Constant(125)
                    );

                _relativeLayout.Children.Add(
                    _usernameEntry,
                    xConstraint: Constraint.Constant(40),
                    yConstraint: Constraint.RelativeToView(_logoSlogan, (p, v) => v.Y + v.Height + _relativeLayoutPadding),
                    widthConstraint: Constraint.RelativeToParent(p => p.Width - 80)
                    );
                _relativeLayout.Children.Add(
                    _passwordEntry,
                    xConstraint: Constraint.Constant(40),
                    yConstraint: Constraint.RelativeToView(_usernameEntry, (p, v) => v.Y + v.Height + _relativeLayoutPadding),
                    widthConstraint: Constraint.RelativeToParent(p => p.Width - 80)
                    );

                _relativeLayout.Children.Add(
                    _loginButton,
                    xConstraint: Constraint.Constant(40),
                    yConstraint: Constraint.RelativeToView(_passwordEntry, (p, v) => v.Y + v.Height + _relativeLayoutPadding),
                    widthConstraint: Constraint.RelativeToParent(p => p.Width - 80)
                    );
                _relativeLayout.Children.Add(
                    _newUserSignUpButton,
                    xConstraint: Constraint.RelativeToParent(p => (p.Width / 2) - (getNewUserButtonWidth(p) / 2)),
                    yConstraint: Constraint.RelativeToView(_loginButton, (p, v) => v.Y + _loginButton.Height + 15)
                    );

                _relativeLayout.Children.Add(
                    _HomeAutomationButton,
                    xConstraint: Constraint.Constant(40),
                    yConstraint: Constraint.RelativeToView(_newUserSignUpButton, (p, v) => v.Y + v.Height + _relativeLayoutPadding),
                    widthConstraint: Constraint.RelativeToParent(p => p.Width - 80)
                    );

                _relativeLayout.Children.Add(activityIndicator,
                                             xConstraint: Constraint.RelativeToParent(parent => parent.Width / 2 - getActivityIndicatorWidth(parent) / 2),
                                             yConstraint: Constraint.RelativeToParent(parent => parent.Height / 2 - getActivityIndicatorHeight(parent) / 2));

                Content = new Xamarin.Forms.ScrollView {
                    Content = _relativeLayout
                };
            }
            catch (Exception ec)
            {
                DisplayAlert("Error", ec.ToString(), "Ok");
            }
        }