Ejemplo n.º 1
0
        public NewUserSignUpPage()
        {
            BackgroundColor = Color.FromHex("2980b9");

            _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(Entry.TextProperty, nameof(ViewModel.UsernameEntryText));

            _passwordEntry = new StyledEntry(1)
            {
                Placeholder             = "Password",
                IsPassword              = true,
                HorizontalOptions       = LayoutOptions.Fill,
                HorizontalTextAlignment = TextAlignment.End,
                VerticalOptions         = LayoutOptions.Fill,
                PlaceholderColor        = Color.FromHex("749FA8"),
                ReturnType              = ReturnType.Done,
                ReturnCommand           = new Command(() => _passwordEntry.Unfocus())
            };
            _passwordEntry.SetBinding(Entry.TextProperty, nameof(ViewModel.PasswordEntryText));

            _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.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"
            };

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

            isFacialRecognitionCompletedLabel.SetBinding(Label.TextProperty, nameof(ViewModel.FontAwesomeLabelText));
            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                isFacialRecognitionCompletedLabel.SetBinding(IsVisibleProperty, nameof(ViewModel.IsInternetConnectionInactive));
                break;
            }

            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 Exception("Device Runtime Unsupported");
            }
            stackLayout.Children.Add(_saveUsernameButton);
            stackLayout.Children.Add(_cancelButton);

            Content = new ScrollView {
                Content = stackLayout
            };
        }
Ejemplo n.º 2
0
        public LoginPage()
        {
            BackgroundColor = Color.FromHex("#3498db");
            Padding         = GetPagePadding();

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

            _logoSlogan = new StyledLabel
            {
                Opacity = 0,
                Text    = "Delighting Developers."
            };
            _usernameEntry = new StyledEntry {
                Placeholder = "Username"
            };
            _usernameEntry.SetBinding(Entry.TextProperty, nameof(ViewModel.UsernameEntryText));
            CustomReturnEffect.SetReturnType(_usernameEntry, ReturnType.Next);
            CustomReturnEffect.SetReturnCommand(_usernameEntry, new Command(() => _passwordEntry.Focus()));

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

            _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.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));

            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(activityIndicator,
                                         xConstraint: Constraint.RelativeToParent(parent => parent.Width / 2 - getActivityIndicatorWidth(parent) / 2),
                                         yConstraint: Constraint.RelativeToParent(parent => parent.Height / 2 - getActivityIndicatorHeight(parent) / 2));

            Content = new ScrollView {
                Content = _relativeLayout
            };
        }
Ejemplo n.º 3
0
        public LoginPage()
        {
            ViewModel.LoginFailed   += HandleLoginFailed;
            ViewModel.LoginApproved += HandleLoginApproved;

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

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

            _logoSlogan = new StyledLabel
            {
                Opacity = 0,
                Text    = "Login to your account with facial recognition.",
            };
            _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));

            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(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
            };
        }
Ejemplo n.º 4
0
        public LoginPage()
        {
            ViewModel.LoginFailed   += HandleLoginFailed;
            ViewModel.LoginApproved += HandleLoginApproved;

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

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

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

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

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

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

            var activityIndicator = new ActivityIndicator {
                Color = Color.White
            };

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

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

            _relativeLayout = new RelativeLayout();
            _relativeLayout.Children.Add(_logo,
                                         Constraint.Constant(100),
                                         Constraint.Constant(250),
                                         Constraint.RelativeToParent(parent => parent.Width - 200));

            _relativeLayout.Children.Add(_logoSlogan,
                                         Constraint.RelativeToParent(parent => parent.Width / 2 - getWidth(parent, _logoSlogan) / 2),
                                         Constraint.Constant(125));

            _relativeLayout.Children.Add(_usernameEntry,
                                         Constraint.Constant(40),
                                         Constraint.RelativeToView(_logoSlogan, (parent, view) => view.Y + view.Height + _relativeLayoutPadding),
                                         Constraint.RelativeToParent(parent => parent.Width - 80));

            _relativeLayout.Children.Add(_passwordEntry,
                                         Constraint.Constant(40),
                                         Constraint.RelativeToView(_usernameEntry, (parent, view) => view.Y + view.Height + _relativeLayoutPadding),
                                         Constraint.RelativeToParent(parent => parent.Width - 80));

            _relativeLayout.Children.Add(_loginButton,
                                         Constraint.Constant(40),
                                         Constraint.RelativeToView(_passwordEntry, (parent, view) => view.Y + view.Height + _relativeLayoutPadding),
                                         Constraint.RelativeToParent(parent => parent.Width - 80));

            _relativeLayout.Children.Add(_newUserSignUpButton,
                                         Constraint.RelativeToParent(parent => parent.Width / 2 - getWidth(parent, _newUserSignUpButton) / 2),
                                         Constraint.RelativeToView(_loginButton, (parent, view) => view.Y + getHeight(parent, _loginButton) + 15));

            _relativeLayout.Children.Add(activityIndicator,
                                         Constraint.RelativeToParent(parent => parent.Width / 2 - getWidth(parent, activityIndicator) / 2),
                                         Constraint.RelativeToParent(parent => parent.Height / 2 - getHeight(parent, activityIndicator) / 2));

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