Beispiel #1
0
        protected ReusableLoginPage(string logoFileImageSource)
        {
            On <iOS>().SetUseSafeArea(true);

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

            LogoFileImageSource = logoFileImageSource;

            _logoSlogan = new StyledLabel
            {
                Opacity = 0,
                Text    = "Delighting Developers."
            };
            _loginEntry = new StyledEntry
            {
                AutomationId = AutomationIdConstants.LoginPage_UsernameEntry,
                Placeholder  = "Username",
                ReturnType   = ReturnType.Next
            };

            _passwordEntry = new StyledEntry
            {
                AutomationId  = AutomationIdConstants.LoginPage_PasswordEntry,
                Placeholder   = "Password",
                IsPassword    = true,
                ReturnType    = ReturnType.Go,
                ReturnCommand = new Command(() => HandleLoginButtonClicked(_passwordEntry, EventArgs.Empty))
            };

            _loginButton = new StyledButton(Borders.Thin)
            {
                AutomationId = AutomationIdConstants.LoginPage_LoginButton,
                Text         = "Login",
            };
            _loginButton.Clicked += HandleLoginButtonClicked;

            _newUserSignUpButton = new StyledButton(Borders.None)
            {
                AutomationId = AutomationIdConstants.LoginPage_NewUserSignUpButton,
                Text         = "Sign-up",
            };
            _newUserSignUpButton.Clicked += HandleNewUserSignUpButtonClicked;

            _forgotPasswordButton = new StyledButton(Borders.None)
            {
                AutomationId = AutomationIdConstants.LoginPage_ForgotPasswordButton,
                Text         = "Forgot Password?",
            };
            _forgotPasswordButton.Clicked += HandleForgotPasswordButtonClicked;

            MainLayout.Children.Add(_logo,
                                    Constraint.Constant(100),
                                    Constraint.Constant(250),
                                    Constraint.RelativeToParent(p => p.Width - 200));

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

            MainLayout.Children.Add(_loginEntry,
                                    Constraint.Constant(40),
                                    Constraint.RelativeToView(_logoSlogan, (p, v) => v.Y + v.Height + _relativeLayoutPadding),
                                    Constraint.RelativeToParent(p => p.Width - 80));
            MainLayout.Children.Add(_passwordEntry,
                                    Constraint.Constant(40),
                                    Constraint.RelativeToView(_loginEntry, (p, v) => v.Y + v.Height + _relativeLayoutPadding),
                                    Constraint.RelativeToParent(p => p.Width - 80));

            MainLayout.Children.Add(_loginButton,
                                    Constraint.Constant(40),
                                    Constraint.RelativeToView(_passwordEntry, (p, v) => v.Y + v.Height + _relativeLayoutPadding),
                                    Constraint.RelativeToParent(p => p.Width - 80));
            MainLayout.Children.Add(_newUserSignUpButton,
                                    Constraint.RelativeToParent(p => (p.Width / 2) - (getNewUserButtonWidth(p) / 2)),
                                    Constraint.RelativeToView(_loginButton, (p, v) => v.Y + _loginButton.Height + 15));
            MainLayout.Children.Add(_forgotPasswordButton,
                                    Constraint.RelativeToParent(p => (p.Width / 2) - (getForgotButtonWidth(p) / 2)),
                                    Constraint.RelativeToView(_newUserSignUpButton, (p, v) => v.Y + _newUserSignUpButton.Height + _relativeLayoutPadding));

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

            double getNewUserButtonWidth(RelativeLayout p) => _newUserSignUpButton.Measure(p.Width, p.Height).Request.Width;
            double getForgotButtonWidth(RelativeLayout p) => _forgotPasswordButton.Measure(p.Width, p.Height).Request.Width;
            double getLogoSloganWidth(RelativeLayout p) => _logoSlogan.Measure(p.Width, p.Height).Request.Width;
        }
Beispiel #2
0
        public FirstPage() : base(PageTitleConstants.FirstPage)
        {
            const string entryTextPaceHolder = "Enter text and click 'Go'";

            var goButton = new StyledButton(Borders.Thin, 1)
            {
                Text         = "Go",
                AutomationId = AutomationIdConstants.FirstPage_GoButton // This provides an ID that can be referenced in UITests
            };

            goButton.Clicked += HandleButtonClicked;
            goButton.SetBinding(Button.CommandProperty, nameof(FirstViewModel.GoButtonCommand));
            goButton.SetBinding(Button.CommandParameterProperty, nameof(FirstViewModel.EntryText));

            var textEntry = new StyledEntry(1)
            {
                Placeholder             = entryTextPaceHolder,
                AutomationId            = AutomationIdConstants.FirstPage_TextEntry, // This provides an ID that can be referenced in UITests
                HorizontalTextAlignment = TextAlignment.Center,
                ReturnType = ReturnType.Go
            };

            textEntry.SetBinding(Entry.TextProperty, nameof(FirstViewModel.EntryText));
            textEntry.SetBinding(Entry.ReturnCommandProperty, nameof(FirstViewModel.GoButtonCommand));
            textEntry.SetBinding(Entry.ReturnCommandParameterProperty, nameof(FirstViewModel.EntryText));

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

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

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

            listPageButton.Clicked += HandleListPageButtonClicked;

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

            activityIndicator.SetBinding(IsVisibleProperty, nameof(FirstViewModel.IsActiityIndicatorRunning));
            activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(FirstViewModel.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 #3
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");
            }
        }