示例#1
0
		public override void Login(LoginConfig config)
		{
			var context = this.getTopActivity();
			var txtUser = new EditText(context) {
				Hint = config.LoginPlaceholder,
				InputType = InputTypes.TextVariationVisiblePassword,
				Text = config.LoginValue ?? String.Empty
			};
			var txtPass = new EditText(context) {
				Hint = config.PasswordPlaceholder ?? "*"
			};
			this.SetInputType(txtPass, InputType.Password);
			var layout = new LinearLayout(context) {
				Orientation = Orientation.Vertical
			};
			txtUser.SetMaxLines(1);
			txtPass.SetMaxLines(1);
			layout.AddView(txtUser, ViewGroup.LayoutParams.MatchParent);
			layout.AddView(txtPass, ViewGroup.LayoutParams.MatchParent);
			Utils.RequestMainThread(() =>
				{
					var dialog = new AlertDialog
					.Builder(this.getTopActivity())
					.SetCancelable(false)
					.SetTitle(config.Title)
					.SetMessage(config.Message)
					.SetView(layout)
					.SetPositiveButton(config.OkText, (o, e) =>
						config.OnResult(new LoginResult(txtUser.Text, txtPass.Text, true))
					             )
					.SetNegativeButton(config.CancelText, (o, e) =>
						config.OnResult(new LoginResult(txtUser.Text, txtPass.Text, false))
					             )
					.Create();
					dialog.Window.SetSoftInputMode(SoftInput.StateVisible);
					dialog.Show();
				});
		}
示例#2
0
		public abstract void Login(LoginConfig config);
示例#3
0
		public override void Login(LoginConfig config)
		{
			UITextField txtUser = null;
			UITextField txtPass = null;
			UIApplication.SharedApplication.InvokeOnMainThread(() =>
				{
					if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
					{
						var dlg = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert);
						dlg.AddAction(UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x => config.OnResult(new LoginResult(txtUser.Text, txtPass.Text, true))));
						dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Default, x => config.OnResult(new LoginResult(txtUser.Text, txtPass.Text, false))));
						dlg.AddTextField(x =>
							{
								txtUser = x;
								x.Placeholder = config.LoginPlaceholder;
								x.Text = config.LoginValue ?? String.Empty;
							});
						dlg.AddTextField(x =>
							{
								txtPass = x;
								x.Placeholder = config.PasswordPlaceholder;
								x.SecureTextEntry = true;
							});
						this.Present(dlg);
					}
					else
					{
						var dlg = new UIAlertView { AlertViewStyle = UIAlertViewStyle.LoginAndPasswordInput };
						txtUser = dlg.GetTextField(0);
						txtPass = dlg.GetTextField(1);
						txtUser.Placeholder = config.LoginPlaceholder;
						txtUser.Text = config.LoginValue ?? String.Empty;
						txtPass.Placeholder = config.PasswordPlaceholder;
						dlg.Clicked += (s, e) =>
						{
							var ok = ((int)dlg.CancelButtonIndex != (int)e.ButtonIndex);
							config.OnResult(new LoginResult(txtUser.Text, txtPass.Text, ok));
						};
						dlg.Show();
					}
				});
		}
示例#4
0
		public virtual Task<LoginResult> LoginAsync(LoginConfig config)
		{
			var tcs = new TaskCompletionSource<LoginResult>();
			config.OnResult = x => tcs.TrySetResult(x);
			this.Login(config);
			return tcs.Task;
		}