/// <summary> /// Ons the create. /// </summary> /// <returns>The create.</returns> /// <param name="bundle">Bundle.</param> protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.LoginView); progressDialog = new ProgressDialog(this); progressDialog.SetMessage("Loading..."); progressDialog.SetCancelable(false); _loginField = FindViewById <EditText>(Resource.Id.usernameField); _passwordField = FindViewById <EditText>(Resource.Id.passwordField); var registerButton = FindViewById <Button>(Resource.Id.registerButton); registerButton.Touch += (sender, e) => Register(this, new Tuple <string, string>(_loginField.Text, _passwordField.Text)); var loginButton = FindViewById <Button>(Resource.Id.loginButton); loginButton.Touch += (sender, e) => Login(this, new Tuple <string, string>(_loginField.Text, _passwordField.Text)); var app = ChatApplication.GetApplication(this); var state = new ApplicationState(); _presenter = new LoginPresenter(state, new NavigationService(app)); _presenter.SetView(this); app.CurrentActivity = this; }
/// <summary> /// Ons the resume. /// </summary> /// <returns>The resume.</returns> protected override void OnResume() { base.OnResume(); var app = ChatApplication.GetApplication(this); app.CurrentActivity = this; if (_presenter != null) { _presenter.SetView(this); } }
/// <summary> /// Views the did load. /// </summary> /// <returns>The did load.</returns> public override void ViewDidLoad() { base.ViewDidLoad(); View.BackgroundColor = UIColor.White; _presenter.SetView(this); var width = View.Bounds.Width; var height = View.Bounds.Height; Title = "Welcome"; var titleLabel = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Text = "Chat", Font = UIFont.FromName("Helvetica-Bold", 22), TextAlignment = UITextAlignment.Center }; _activityIndicatorView = new UIActivityIndicatorView() { TranslatesAutoresizingMaskIntoConstraints = false, Color = UIColor.Black }; var descriptionLabel = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Text = "Enter your login name to join the chat room.", Font = UIFont.FromName("Helvetica", 18), TextAlignment = UITextAlignment.Center }; _loginTextField = new UITextField() { TranslatesAutoresizingMaskIntoConstraints = false, Placeholder = "Username", Font = UIFont.FromName("Helvetica", 18), BackgroundColor = UIColor.Clear.FromHex("#DFE4E6"), TextAlignment = UITextAlignment.Center }; _passwordTextField = new UITextField() { TranslatesAutoresizingMaskIntoConstraints = false, Placeholder = "Password", Font = UIFont.FromName("Helvetica", 18), BackgroundColor = UIColor.Clear.FromHex("#DFE4E6"), TextAlignment = UITextAlignment.Center }; var buttonView = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }; var loginButton = new UIButton(UIButtonType.RoundedRect) { TranslatesAutoresizingMaskIntoConstraints = false }; loginButton.SetTitle("Login", UIControlState.Normal); loginButton.TouchUpInside += (sender, e) => Login(this, new Tuple <string, string>(_loginTextField.Text, _passwordTextField.Text)); var registerButton = new UIButton(UIButtonType.RoundedRect) { TranslatesAutoresizingMaskIntoConstraints = false }; registerButton.SetTitle("Register", UIControlState.Normal); registerButton.TouchUpInside += (sender, e) => Register(this, new Tuple <string, string>(_loginTextField?.Text, _passwordTextField?.Text)); Add(titleLabel); Add(descriptionLabel); Add(_activityIndicatorView); Add(_loginTextField); Add(_passwordTextField); Add(buttonView); buttonView.Add(loginButton); buttonView.Add(registerButton); var views = new DictionaryViews() { { "titleLabel", titleLabel }, { "descriptionLabel", descriptionLabel }, { "loginTextField", _loginTextField }, { "passwordTextField", _passwordTextField }, { "loginButton", loginButton }, { "registerButton", registerButton }, { "activityIndicatorView", _activityIndicatorView }, { "buttonView", buttonView } }; buttonView.AddConstraints( NSLayoutConstraint.FromVisualFormat("V:|-[registerButton]-|", NSLayoutFormatOptions.DirectionLeftToRight, null, views) .Concat(NSLayoutConstraint.FromVisualFormat("V:|-[loginButton]-|", NSLayoutFormatOptions.DirectionLeftToRight, null, views)) .Concat(NSLayoutConstraint.FromVisualFormat("H:|-[registerButton]-30-[loginButton]-|", NSLayoutFormatOptions.DirectionLeftToRight, null, views)) .ToArray()); View.AddConstraints( NSLayoutConstraint.FromVisualFormat("V:|-100-[titleLabel(50)]-[descriptionLabel(30)]-10-[loginTextField(30)]-10-[passwordTextField(30)]-10-[buttonView]", NSLayoutFormatOptions.DirectionLeftToRight, null, views) .Concat(NSLayoutConstraint.FromVisualFormat("V:|-100-[activityIndicatorView(50)]-[descriptionLabel(30)]-10-[loginTextField(30)]-10-[passwordTextField(30)]-10-[buttonView]", NSLayoutFormatOptions.DirectionLeftToRight, null, views)) .Concat(NSLayoutConstraint.FromVisualFormat("H:|-10-[titleLabel]-10-|", NSLayoutFormatOptions.AlignAllTop, null, views)) .Concat(NSLayoutConstraint.FromVisualFormat("H:[activityIndicatorView(30)]-10-|", NSLayoutFormatOptions.AlignAllTop, null, views)) .Concat(NSLayoutConstraint.FromVisualFormat("H:|-10-[descriptionLabel]-10-|", NSLayoutFormatOptions.AlignAllTop, null, views)) .Concat(NSLayoutConstraint.FromVisualFormat("H:|-30-[loginTextField]-30-|", NSLayoutFormatOptions.AlignAllTop, null, views)) .Concat(NSLayoutConstraint.FromVisualFormat("H:|-30-[passwordTextField]-30-|", NSLayoutFormatOptions.AlignAllTop, null, views)) .Concat(new[] { NSLayoutConstraint.Create(buttonView, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, View, NSLayoutAttribute.CenterX, 1, 1) }) .ToArray()); }