public override void Prompt(PromptConfig config) {
            var dialog = new ContentDialog { Title = config.Title };
            var txt = new TextBox {
                PlaceholderText = config.Placeholder,
                Text = config.Text ?? String.Empty
            };
            var stack = new StackPanel {
                Children = {
                    new TextBlock { Text = config.Message },
                    txt
                }
            };
            dialog.Content = stack;

            dialog.PrimaryButtonText = config.OkText;
            dialog.PrimaryButtonCommand = new Command(() => {
                config.OnResult?.Invoke(new PromptResult {
                    Ok = true,
                    Text = txt.Text.Trim()
                });
                dialog.Hide();
            });

            if (config.IsCancellable) {
                dialog.SecondaryButtonText = config.CancelText;
                dialog.SecondaryButtonCommand = new Command(() => {
                    config.OnResult?.Invoke(new PromptResult {
                        Ok = false,
                        Text = txt.Text.Trim()
                    });
                    dialog.Hide();
                });
            }
            this.Dispatch(() => dialog.ShowAsync());
        }
        protected virtual void ShowIOS7Prompt(PromptConfig config)
        {
            var result     = new PromptResult();
            var isPassword = (config.InputType == InputType.Password || config.InputType == InputType.NumericPassword);
            var cancelText = config.IsCancellable ? config.CancelText : null;

            var dlg = new UIAlertView(config.Title ?? String.Empty, config.Message, null, cancelText, config.OkText)
            {
                AlertViewStyle = isPassword
                                        ? UIAlertViewStyle.SecureTextInput
                                        : UIAlertViewStyle.PlainTextInput
            };
            var txt = dlg.GetTextField(0);

            this.SetInputType(txt, config.InputType);
            txt.Placeholder = config.Placeholder;
            if (config.Text != null)
            {
                txt.Text = config.Text;
            }

            dlg.Clicked += (s, e) => {
                result.Ok   = ((int)dlg.CancelButtonIndex != (int)e.ButtonIndex);
                result.Text = txt.Text.Trim();
                config.OnResult(result);
            };
            this.Present(dlg);
        }
示例#3
0
        /// <summary> Gets prompt configuration. </summary>
        /// <exception cref="ArgumentNullException"> Thrown when one or more required arguments are null. </exception>
        /// <param name="config"> The configuration. </param>
        /// <returns> The prompt configuration. </returns>
        private AcrDialogs.PromptConfig GetPromptConfig(UserDialogPromptConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var result = new AcrDialogs.PromptConfig();

            if (config.Title != null)
            {
                result.Title = config.Title;
            }
            if (config.Message != null)
            {
                result.Message = config.Message;
            }
            if (config.OnAction != null)
            {
                result.OnAction = GetPromptResultAction(config.OnAction);
            }
            if (config.IsCancellable != null)
            {
                result.IsCancellable = config.IsCancellable.Value;
            }
            if (config.Text != null)
            {
                result.Text = config.Text;
            }
            if (config.OkText != null)
            {
                result.OkText = config.OkText;
            }
            if (config.CancelText != null)
            {
                result.CancelText = config.CancelText;
            }
            if (config.Placeholder != null)
            {
                result.Placeholder = config.Placeholder;
            }
            if (config.MaxLength != null)
            {
                result.MaxLength = config.MaxLength;
            }
            if (config.AndroidStyleId != null)
            {
                result.AndroidStyleId = config.AndroidStyleId;
            }
            if (config.InputType != null)
            {
                result.InputType = ConvertToAcrInputType(config.InputType.Value);
            }
            if (config.OnTextChanged != null)
            {
                result.OnTextChanged = GetPromptTextChangedArgsAction(config.OnTextChanged);
            }

            return(result);
        }
示例#4
0
        public override IDisposable Prompt(PromptConfig config) => this.Present(() =>
        {
            var alert = new NSAlert
            {
                AlertStyle      = NSAlertStyle.Informational,
                MessageText     = config.Title ?? string.Empty,
                InformativeText = config.Message ?? string.Empty
            };
            alert.AddButton(config.OkText);
            if (config.IsCancellable)
            {
                alert.AddButton(config.CancelText);
            }

            var txtInput = new NSTextField(new CGRect(0, 0, 300, 24))
            {
                PlaceholderString = config.Placeholder ?? string.Empty,
                StringValue       = config.Text ?? String.Empty
            };

            // TODO: Implement input types validation
            if (config.InputType != InputType.Default || config.MaxLength != null)
            {
                Log.Warn("Acr.UserDialogs", "There is no validation of input types nor MaxLength on this implementation");
            }

            alert.AccessoryView = txtInput;
            alert.Layout();

            alert.BeginSheetForResponse(this.windowFunc(), result => config.OnAction?.Invoke(new PromptResult(result == 1000, txtInput.StringValue)));
            return(alert);
        });
        protected virtual void ShowIOS8Prompt(PromptConfig config)
        {
            var         result = new PromptResult();
            var         dlg    = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert);
            UITextField txt    = null;

            if (config.IsCancellable)
            {
                dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Cancel, x => {
                    result.Ok   = false;
                    result.Text = txt.Text.Trim();
                    config.OnResult(result);
                }));
            }
            dlg.AddAction(UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x => {
                result.Ok   = true;
                result.Text = txt.Text.Trim();
                config.OnResult(result);
            }));
            dlg.AddTextField(x => {
                this.SetInputType(x, config.InputType);
                x.Placeholder = config.Placeholder ?? String.Empty;
                if (config.Text != null)
                {
                    x.Text = config.Text;
                }

                txt = x;
            });
            this.Present(dlg);
        }
示例#6
0
        public override void Prompt(PromptConfig config)
        {
            var prompt = new CustomMessageBox {
                Caption            = config.Title,
                Message            = config.Message,
                LeftButtonContent  = config.OkText,
                RightButtonContent = config.CancelText
            };

            var password   = new PasswordBox();
            var inputScope = this.GetInputScope(config.InputType);
            var txt        = new PhoneTextBox {
                PlaceholderText = config.Placeholder,
                InputScope      = inputScope
            };
            var isSecure = config.InputType == InputType.Password;

            if (isSecure)
            {
                prompt.Content = password;
            }
            else
            {
                prompt.Content = txt;
            }

            prompt.Dismissed += (sender, args) => config.OnResult(new PromptResult {
                Ok   = args.Result == CustomMessageBoxResult.LeftButton,
                Text = isSecure
                    ? password.Password
                    : txt.Text.Trim()
            });
            this.Dispatch(prompt.Show);
        }
        public override IDisposable Prompt(PromptConfig config)
        {
            var         dlg = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert);
            UITextField txt = null;

            if (config.IsCancellable)
            {
                dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Cancel, x =>
                                                   config.OnResult(new PromptResult(false, txt.Text.Trim())
                                                                   )));
            }
            dlg.AddAction(UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x =>
                                               config.OnResult(new PromptResult(true, txt.Text.Trim())
                                                               )));
            dlg.AddTextField(x =>
            {
                this.SetInputType(x, config.InputType);
                x.Placeholder = config.Placeholder ?? String.Empty;
                if (config.Text != null)
                {
                    x.Text = config.Text;
                }

                txt = x;
            });
            return(this.Present(dlg));
        }
示例#8
0
        public override IDisposable Prompt(PromptConfig config)
        {
            var dlg = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert);
            UITextField txt = null;

            if (config.IsCancellable)
            {
                dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Cancel, x =>
                    config.OnAction(new PromptResult(false, txt.Text.Trim())
                )));
            }
            dlg.AddAction(UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x =>
                config.OnAction(new PromptResult(true, txt.Text.Trim())
            )));
            dlg.AddTextField(x =>
            {
                this.SetInputType(x, config.InputType);
                x.Placeholder = config.Placeholder ?? String.Empty;
                if (config.Text != null)
                    x.Text = config.Text;

                txt = x;
            });
            return this.Present(dlg);
        }
示例#9
0
        public virtual Task <PromptResult> PromptAsync(PromptConfig config)
        {
            var tcs = new TaskCompletionSource <PromptResult>();

            config.OnResult = x => tcs.TrySetResult(x);
            this.Prompt(config);
            return(tcs.Task);
        }
示例#10
0
        public override IDisposable Prompt(PromptConfig config)
        {
#if WPF
            return(null);
#else
            var dlg = new InputDialog();
            return(new DisposableAction(dlg.Dispose));
#endif
        }
        public override IDisposable Prompt(PromptConfig config)
        {
            return(this.Present(() =>
            {
                var dlg = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert);
                UITextField txt = null;

                if (config.IsCancellable)
                {
                    dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Cancel, x =>
                                                       config.OnAction?.Invoke(new PromptResult(false, txt.Text.Trim())
                                                                               )));
                }

                var btnOk = UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x =>
                                                 config.OnAction?.Invoke(new PromptResult(true, txt.Text.Trim())
                                                                         ));
                dlg.AddAction(btnOk);
                dlg.AddTextField(x =>
                {
                    txt = x;
                    if (config.MaxLength != null)
                    {
                        txt.ShouldChangeCharacters = (field, replacePosition, replacement) =>
                        {
                            var updatedText = new StringBuilder(field.Text);
                            updatedText.Remove((int)replacePosition.Location, (int)replacePosition.Length);
                            updatedText.Insert((int)replacePosition.Location, replacement);
                            return updatedText.ToString().Length <= config.MaxLength.Value;
                        };
                    }

                    if (config.OnTextChanged != null)
                    {
                        txt.Ended += (sender, e) =>
                        {
                            var args = new PromptTextChangedArgs {
                                Value = txt.Text
                            };
                            config.OnTextChanged(args);
                            btnOk.Enabled = args.IsValid;
                            if (!txt.Text.Equals(args.Value))
                            {
                                txt.Text = args.Value;
                            }
                        };
                    }
                    this.SetInputType(txt, config.InputType);
                    txt.Placeholder = config.Placeholder ?? String.Empty;
                    if (config.Text != null)
                    {
                        txt.Text = config.Text;
                    }
                });
                return dlg;
            }));
        }
示例#12
0
        public override void Prompt(PromptConfig config)
        {
            Utils.RequestMainThread(() => {
                var activity = this.GetTopActivity();

                var txt = new EditText(activity)
                {
                    Hint = config.Placeholder
                };

                EventHandler <View.KeyEventArgs> keyHandler = null;
                var successFunc = new Action <bool>(success =>
                {
                    if (keyHandler != null)
                    {
                        txt.KeyPress -= keyHandler;
                    }

                    config.OnResult(new PromptResult {
                        Ok   = success,
                        Text = txt.Text
                    });
                });
                if (config.Text != null)
                {
                    txt.Text = config.Text;
                }

                this.SetInputType(txt, config.InputType);

                var builder = new AlertDialog
                              .Builder(activity)
                              .SetCancelable(false)
                              .SetMessage(config.Message)
                              .SetTitle(config.Title)
                              .SetView(txt)
                              .SetPositiveButton(config.OkText, (s, a) => successFunc(true));

                if (config.IsCancellable)
                {
                    builder.SetNegativeButton(config.CancelText, (s, a) => successFunc(false));
                }

                var dialog = builder.ShowExt();
                keyHandler = new EventHandler <View.KeyEventArgs>((sender, e) =>
                {
                    if (e.KeyCode == Keycode.Enter ||
                        e.KeyCode == Keycode.NumpadEnter)
                    {
                        successFunc(true);
                        dialog.Dismiss();
                    }
                });
                txt.KeyPress += keyHandler;
            });
        }
        public override IDisposable Prompt(PromptConfig config)
        {
            var activity = this.TopActivityFunc();

            if (activity is AppCompatActivity act)
            {
                return(this.ShowDialog <PromptAppCompatDialogFragment, PromptConfig>(act, config));
            }

            return(this.Show(activity, () => new PromptBuilder().Build(activity, config)));
        }
 public override void Prompt(PromptConfig config)
 {
     if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
     {
         this.ShowIOS8Prompt(config);
     }
     else
     {
         this.ShowIOS7Prompt(config);
     }
 }
示例#15
0
        static void ValidatePrompt(UITextField txt, UIAlertAction btn, PromptConfig config)
        {
            var args = new PromptTextChangedArgs {
                Value = txt.Text
            };

            config.OnTextChanged(args);
            btn.Enabled = args.IsValid;
            if (!txt.Text.Equals(args.Value))
            {
                txt.Text = args.Value;
            }
        }
示例#16
0
 public override void Prompt(PromptConfig config)
 {
     UIApplication.SharedApplication.InvokeOnMainThread(() => {
         if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
         {
             this.ShowIOS8Prompt(config);
         }
         else
         {
             this.ShowIOS7Prompt(config);
         }
     });
 }
示例#17
0
        public override void Prompt(PromptConfig config)
        {
            UIApplication.SharedApplication.InvokeOnMainThread(() => {
                var result = new PromptResult();

                if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                {
                    var dlg         = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert);
                    UITextField txt = null;

                    dlg.AddAction(UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x => {
                        result.Ok   = true;
                        result.Text = txt.Text.Trim();
                        config.OnResult(result);
                    }));
                    dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Default, x => {
                        result.Ok   = false;
                        result.Text = txt.Text.Trim();
                        config.OnResult(result);
                    }));
                    dlg.AddTextField(x => {
                        Utils.SetInputType(x, config.InputType);
                        x.Placeholder = config.Placeholder ?? String.Empty;
                        txt           = x;
                    });
                    this.Present(dlg);
                }
                else
                {
                    var isPassword = config.InputType == InputType.Password;

                    var dlg = new UIAlertView(config.Title ?? String.Empty, config.Message, null, config.CancelText, config.OkText)
                    {
                        AlertViewStyle = isPassword
                            ? UIAlertViewStyle.SecureTextInput
                            : UIAlertViewStyle.PlainTextInput
                    };
                    var txt = dlg.GetTextField(0);
                    Utils.SetInputType(txt, config.InputType);
                    txt.Placeholder = config.Placeholder;

                    dlg.Clicked += (s, e) => {
                        result.Ok   = ((int)dlg.CancelButtonIndex != (int)e.ButtonIndex);
                        result.Text = txt.Text.Trim();
                        config.OnResult(result);
                    };
                    dlg.Show();
                }
            });
        }
示例#18
0
        public override async void Prompt(PromptConfig config)
        {
            var input = new InputDialog {
                AcceptButton = config.OkText,
                CancelButton = config.CancelText,
                InputText    = config.Placeholder
            };
            var result = await input.ShowAsync(config.Title, config.Message);

//            input
//                .ShowAsync(title, message)
//                .ContinueWith(x => {
//                    // TODO: how to get button click for this scenario?
//                });
        }
        public override IDisposable Prompt(PromptConfig config)
        {
            var dlg = new InputDialog {
                Title      = config.Title,
                Text       = config.Text,
                OkText     = config.OkText,
                CancelText = config.CancelText,
                IsPassword = config.InputType == InputType.Password
            };

            dlg.ShowDialog();
            config.OnAction(new PromptResult(dlg.WasOk, dlg.Text));

            return(new DisposableAction(dlg.Dispose));
        }
        public override IDisposable Prompt(PromptConfig config)
        {
            var activity = this.TopActivityFunc();

            if (activity is AppCompatActivity)
            {
                return(this.ShowDialog <PromptAppCompatDialogFragment, PromptConfig>((AppCompatActivity)activity, config));
            }

            if (activity is FragmentActivity)
            {
                return(this.ShowDialog <PromptDialogFragment, PromptConfig>((FragmentActivity)activity, config));
            }

            return(this.Show(activity, PromptBuilder.Build(activity, config)));
        }
        public virtual Task <PromptResult> PromptAsync(PromptConfig config, CancellationToken?cancelToken = null)
        {
            var tcs = new TaskCompletionSource <PromptResult>();

            config.OnResult = x => tcs.TrySetResult(x);

            var disp = this.Prompt(config);

            cancelToken?.Register(() =>
            {
                disp.Dispose();
                tcs.TrySetCanceled();
            });

            return(tcs.Task);
        }
示例#22
0
        public override IDisposable Prompt(PromptConfig config)
        {
            var stack = new StackPanel();

            if (!String.IsNullOrWhiteSpace(config.Message))
            {
                stack.Children.Add(new TextBlock {
                    Text = config.Message, TextWrapping = TextWrapping.WrapWholeWords
                });
            }

            var dialog = new ContentDialog
            {
                Title             = config.Title ?? String.Empty,
                Content           = stack,
                DefaultButton     = ContentDialogButton.Primary,
                PrimaryButtonText = config.OkText
            };

            if (config.InputType == InputType.Password)
            {
                this.SetPasswordPrompt(dialog, stack, config);
            }
            else
            {
                this.SetDefaultPrompt(dialog, stack, config);
            }

            if (config.IsCancellable)
            {
                dialog.SecondaryButtonText    = config.CancelText;
                dialog.SecondaryButtonCommand = new Command(() =>
                {
                    config.OnAction?.Invoke(new PromptResult(false, String.Empty));
                    dialog.Hide();
                });
            }

            return(this.DispatchAndDispose(
                       //config.UwpSubmitOnEnterKey,
                       //config.UwpCancelOnEscKey,
                       () => dialog.ShowAsync(),
                       dialog.Hide
                       ));
        }
        public override IDisposable Prompt(PromptConfig config)
        {
            var prompt = new CustomMessageBox
            {
                Caption           = config.Title,
                Message           = config.Message,
                LeftButtonContent = config.OkText
            };

            if (config.IsCancellable)
            {
                prompt.RightButtonContent = config.CancelText;
            }

            var password   = new PasswordBox();
            var inputScope = this.GetInputScope(config.InputType);
            var txt        = new PhoneTextBox
            {
                InputScope = inputScope
            };

            if (config.Text != null)
            {
                txt.Text = config.Text;
            }

            var isSecure = (config.InputType == InputType.NumericPassword || config.InputType == InputType.Password);

            if (isSecure)
            {
                prompt.Content = password;
            }
            else
            {
                prompt.Content = txt;
            }

            prompt.Dismissed += (sender, args) =>
            {
                var ok   = args.Result == CustomMessageBoxResult.LeftButton;
                var text = isSecure ? password.Password : txt.Text.Trim();
                config.OnResult(new PromptResult(ok, text));
            };
            return(this.DispatchWithDispose(prompt.Show, prompt.Dismiss));
        }
示例#24
0
        public virtual async Task <PromptResult> PromptAsync(PromptConfig config, CancellationToken?cancelToken = null)
        {
            if (config.OnAction != null)
            {
                throw new ArgumentException(NO_ONACTION);
            }

            var tcs = new TaskCompletionSource <PromptResult>();

            config.OnAction = x => tcs.TrySetResult(x);

            var disp = this.Prompt(config);

            using (cancelToken?.Register(() => Cancel(disp, tcs)))
            {
                return(await tcs.Task);
            }
        }
示例#25
0
        public override void Prompt(PromptConfig config)
        {
            Utils.RequestMainThread(() => {
                var activity = this.getTopActivity();

                var txt = new EditText(activity)
                {
                    Hint = config.Placeholder
                };
                if (config.Text != null)
                {
                    txt.Text = config.Text;
                }

                this.SetInputType(txt, config.InputType);

                var builder = new AlertDialog
                              .Builder(activity)
                              .SetCancelable(false)
                              .SetMessage(config.Message)
                              .SetTitle(config.Title)
                              .SetView(txt)
                              .SetPositiveButton(config.OkText, (o, e) =>
                                                 config.OnResult(new PromptResult {
                    Ok   = true,
                    Text = txt.Text
                })
                                                 );

                if (config.IsCancellable)
                {
                    builder.SetNegativeButton(config.CancelText, (o, e) =>
                                              config.OnResult(new PromptResult {
                        Ok   = false,
                        Text = txt.Text
                    })
                                              );
                }

                var dialog = builder.Create();
                dialog.Window.SetSoftInputMode(SoftInput.StateVisible);
                dialog.Show();
            });
        }
示例#26
0
        public override IDisposable Prompt(PromptConfig config) => this.Present(() =>
        {
            var dlg         = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert);
            UITextField txt = null;

            if (config.IsCancellable)
            {
                dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Cancel, x =>
                                                   config.OnAction?.Invoke(new PromptResult(false, txt.Text)
                                                                           )));
            }

            var btnOk = UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x =>
                                             config.OnAction?.Invoke(new PromptResult(true, txt.Text)
                                                                     ));
            dlg.AddAction(btnOk);

            dlg.AddTextField(x =>
            {
                txt = x;
                this.SetInputType(txt, config.InputType);
                txt.Placeholder        = config.Placeholder ?? String.Empty;
                txt.Text               = config.Text ?? String.Empty;
                txt.AutocorrectionType = (UITextAutocorrectionType)config.AutoCorrectionConfig;

                if (config.MaxLength != null)
                {
                    txt.ShouldChangeCharacters = (field, replacePosition, replacement) =>
                    {
                        var updatedText = new StringBuilder(field.Text);
                        updatedText.Remove((int)replacePosition.Location, (int)replacePosition.Length);
                        updatedText.Insert((int)replacePosition.Location, replacement);
                        return(updatedText.ToString().Length <= config.MaxLength.Value);
                    };
                }

                if (config.OnTextChanged != null)
                {
                    txt.AddTarget((sender, e) => ValidatePrompt(txt, btnOk, config), UIControlEvent.EditingChanged);
                    ValidatePrompt(txt, btnOk, config);
                }
            });
            return(dlg);
        });
示例#27
0
        public override void Prompt(PromptConfig config)
        {
            var dialog = new ContentDialog {
                Title = config.Title
            };
            var txt = new TextBox {
                PlaceholderText = config.Placeholder,
                Text            = config.Text ?? String.Empty
            };
            var stack = new StackPanel {
                Children =
                {
                    new TextBlock {
                        Text = config.Message
                    },
                    txt
                }
            };

            dialog.Content = stack;

            dialog.PrimaryButtonText    = config.OkText;
            dialog.PrimaryButtonCommand = new Command(() => {
                config.OnResult?.Invoke(new PromptResult {
                    Ok   = true,
                    Text = txt.Text.Trim()
                });
                dialog.Hide();
            });

            if (config.IsCancellable)
            {
                dialog.SecondaryButtonText    = config.CancelText;
                dialog.SecondaryButtonCommand = new Command(() => {
                    config.OnResult?.Invoke(new PromptResult {
                        Ok   = false,
                        Text = txt.Text.Trim()
                    });
                    dialog.Hide();
                });
            }
            this.Dispatch(() => dialog.ShowAsync());
        }
示例#28
0
        public override IDisposable Prompt(PromptConfig config)
        {
            var stack = new StackPanel
            {
                Children =
                {
                    new TextBlock {
                        Text = config.Message
                    }
                }
            };
            var dialog = new ContentDialog
            {
                Title             = config.Title ?? String.Empty,
                Content           = stack,
                PrimaryButtonText = config.OkText
            };

            if (config.InputType == InputType.Password)
            {
                this.SetPasswordPrompt(dialog, stack, config);
            }
            else
            {
                this.SetDefaultPrompt(dialog, stack, config);
            }

            if (config.IsCancellable)
            {
                dialog.SecondaryButtonText    = config.CancelText;
                dialog.SecondaryButtonCommand = new Command(() =>
                {
                    config.OnAction?.Invoke(new PromptResult(false, String.Empty));
                    dialog.Hide();
                });
            }

            return(this.DispatchAndDispose(
                       () => dialog.ShowAsync(),
                       dialog.Hide
                       ));
        }
示例#29
0
        public override void Prompt(PromptConfig config)
        {
            var stack = new StackPanel
            {
                Children =
                {
                    new TextBlock {
                        Text = config.Message
                    }
                }
            };
            var dialog = new ContentDialog
            {
                Title             = config.Title,
                Content           = stack,
                PrimaryButtonText = config.OkText
            };


            if (config.InputType == InputType.Password)
            {
                this.SetPasswordPrompt(dialog, stack, config);
            }
            else
            {
                this.SetDefaultPrompt(dialog, stack, config);
            }

            if (config.IsCancellable)
            {
                dialog.SecondaryButtonText    = config.CancelText;
                dialog.SecondaryButtonCommand = new Command(() =>
                {
                    config.OnResult?.Invoke(new PromptResult {
                        Ok = false
                    });
                    dialog.Hide();
                });
            }

            this.Dispatch(() => dialog.ShowAsync());
        }
示例#30
0
        void SetDefaultPrompt(ContentDialog dialog, StackPanel stack, PromptConfig config)
        {
            var txt = new TextBox
            {
                PlaceholderText = config.Placeholder,
                Text            = config.Text ?? String.Empty
            };

            stack.Children.Add(txt);

            dialog.PrimaryButtonCommand = new Command(() =>
            {
                config.OnResult?.Invoke(new PromptResult
                {
                    Ok   = true,
                    Text = txt.Text.Trim()
                });
                dialog.Hide();
            });
        }
示例#31
0
        public override IDisposable Prompt(PromptConfig config)
        {
            var txt   = new NSTextField(new CGRect(0, 0, 300, 20));
            var alert = new NSAlert
            {
                AccessoryView = txt,
                MessageText   = config.Message
            };

            alert.AddButton(config.OkText);
            if (config.CancelText != null)
            {
                alert.AddButton(config.CancelText);
            }

            var actionIndex = alert.RunModal();

            config.OnAction?.Invoke(new PromptResult(actionIndex == 0, txt.StringValue));

            return(alert);
        }
示例#32
0
        public virtual Task <PromptResult> PromptAsync(PromptConfig config, CancellationToken?cancelToken = null)
        {
            if (config.OnAction != null)
            {
                throw new ArgumentException(NO_ONACTION);
            }

            var tcs = new TaskCompletionSource <PromptResult>();

            config.OnAction = x => tcs.TrySetResult(x);

            var disp = this.Prompt(config);

            cancelToken?.Register(() =>
            {
                disp.Dispose();
                tcs.TrySetCanceled();
            });

            return(tcs.Task);
        }
        public override void Prompt(PromptConfig config)
        {
            var stack = new StackPanel
            {
                Children =
                {
                    new TextBlock { Text = config.Message }
                }
            };
            var dialog = new ContentDialog
            {
                Title = config.Title,
                Content = stack,
                PrimaryButtonText = config.OkText
            };

            if (config.InputType == InputType.Password)
                this.SetPasswordPrompt(dialog, stack, config);
            else
                this.SetDefaultPrompt(dialog, stack, config);

            if (config.IsCancellable) {
                dialog.SecondaryButtonText = config.CancelText;
                dialog.SecondaryButtonCommand = new Command(() =>
                {
                    config.OnResult?.Invoke(new PromptResult { Ok = false });
                    dialog.Hide();
                });
            }

            this.Dispatch(() => dialog.ShowAsync());
        }
示例#34
0
        public override IDisposable Prompt(PromptConfig config)
        {
            return this.Present(() =>
            {
                var dlg = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert);
                UITextField txt = null;

                if (config.IsCancellable)
                {
                    dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Cancel, x =>
                        config.OnAction?.Invoke(new PromptResult(false, txt.Text.Trim())
                    )));
                }
                dlg.AddAction(UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x =>
                    config.OnAction?.Invoke(new PromptResult(true, txt.Text.Trim())
                )));
                dlg.AddTextField(x =>
                {
                    txt = x;
                    if (config.MaxLength != null)
                    {
                        txt.ShouldChangeCharacters = (field, replacePosition, replacement) =>
                        {
                            var updatedText = new StringBuilder(field.Text);
                            updatedText.Remove((int)replacePosition.Location, (int)replacePosition.Length);
                            updatedText.Insert((int)replacePosition.Location, replacement);
                            return updatedText.ToString().Length <= config.MaxLength.Value;
                        };
                    }
                    this.SetInputType(txt, config.InputType);
                    txt.Placeholder = config.Placeholder ?? String.Empty;
                    if (config.Text != null)
                        txt.Text = config.Text;
                });
                return dlg;
            });
        }
示例#35
0
        protected virtual void ShowIOS8Prompt(PromptConfig config)
        {
            var result = new PromptResult();
            var dlg = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert);
            UITextField txt = null;

            if (config.IsCancellable) {
                dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Cancel, x => {
                    result.Ok = false;
                    result.Text = txt.Text.Trim();
                    config.OnResult(result);
                }));
            }
            dlg.AddAction(UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x => {
                result.Ok = true;
                result.Text = txt.Text.Trim();
                config.OnResult(result);
            }));
            dlg.AddTextField(x => {
                this.SetInputType(x, config.InputType);
                x.Placeholder = config.Placeholder ?? String.Empty;
                if (config.Text != null)
                    x.Text = config.Text;

                txt = x;
            });
            this.Present(dlg);
        }
示例#36
0
        public override void Prompt(PromptConfig config)
        {
            Utils.RequestMainThread(() => {
                var activity = this.getTopActivity();

                var txt = new EditText(activity) {
                    Hint = config.Placeholder
                };
                if (config.Text != null)
                    txt.Text = config.Text;

                this.SetInputType(txt, config.InputType);

                var builder = new AlertDialog
                    .Builder(activity)
                    .SetCancelable(false)
                    .SetMessage(config.Message)
                    .SetTitle(config.Title)
                    .SetView(txt)
                    .SetPositiveButton(config.OkText, (o, e) =>
                        config.OnResult(new PromptResult {
                            Ok = true,
                            Text = txt.Text
                        })
                    );

                if (config.IsCancellable) {
                    builder.SetNegativeButton(config.CancelText, (o, e) =>
                        config.OnResult(new PromptResult {
                            Ok = false,
                            Text = txt.Text
                        })
                    );
                }

                var dialog = builder.Create();
                dialog.Window.SetSoftInputMode(SoftInput.StateVisible);
                dialog.Show();
            });
        }
示例#37
0
 public override IDisposable Prompt(PromptConfig config)
 {
     throw new NotImplementedException ();
 }
示例#38
0
        public override IDisposable Prompt(PromptConfig config)
        {
            var stack = new StackPanel();
            if (!String.IsNullOrWhiteSpace(config.Message))
                stack.Children.Add(new TextBlock { Text = config.Message, TextWrapping = TextWrapping.WrapWholeWords });

            var dialog = new ContentDialog
            {
                Title = config.Title ?? String.Empty,
                Content = stack,
                PrimaryButtonText = config.OkText
            };

            if (config.InputType == InputType.Password)
                this.SetPasswordPrompt(dialog, stack, config);
            else
                this.SetDefaultPrompt(dialog, stack, config);

            if (config.IsCancellable)
            {
                dialog.SecondaryButtonText = config.CancelText;
                dialog.SecondaryButtonCommand = new Command(() =>
                {
                    config.OnAction?.Invoke(new PromptResult(false, String.Empty));
                    dialog.Hide();
                });
            }

            return this.DispatchAndDispose(
                () => dialog.ShowAsync(),
                dialog.Hide
            );
        }
示例#39
0
        public override void Prompt(PromptConfig config)
        {
            var prompt = new CustomMessageBox {
                Caption = config.Title,
                Message = config.Message,
                LeftButtonContent = config.OkText
            };
            if (config.IsCancellable)
                prompt.RightButtonContent = config.CancelText;

            var password = new PasswordBox();
            var inputScope = this.GetInputScope(config.InputType);
            var txt = new PhoneTextBox {
                //PlaceholderText = config.Placeholder,
                InputScope = inputScope
            };
            if (config.Text != null)
                txt.Text = config.Text;

            var isSecure = (config.InputType == InputType.NumericPassword || config.InputType == InputType.Password);
            if (isSecure)
                prompt.Content = password;
            else
                prompt.Content = txt;

            prompt.Dismissed += (sender, args) => config.OnResult(new PromptResult {
                Ok = args.Result == CustomMessageBoxResult.LeftButton,
                Text = isSecure
                    ? password.Password
                    : txt.Text.Trim()
            });
            this.Dispatch(prompt.Show);
        }
示例#40
0
        public LoginPage()
        {
            this.BindingContext = model = App.Container.Resolve<LoginViewModel>();
            model.ConfiguraNavegacao(this.Navigation);

            var imgLogoMini = new Image
            {
                Source = ImageSource.FromResource(RetornaCaminhoImagem.GetImagemCaminho("logo.png"))
            };

            var imgFacebook = new Image();
            imgFacebook.Source = ImageSource.FromResource(RetornaCaminhoImagem.GetImagemCaminho("LoginFacebook.png"));
            imgFacebook.VerticalOptions = LayoutOptions.Center;
            imgFacebook.HorizontalOptions = LayoutOptions.CenterAndExpand;
            imgFacebook.HeightRequest = 100;
            imgFacebook.WidthRequest = 100;

            var img_Click = new TapGestureRecognizer();
            img_Click.Tapped += async (sender, e) =>
            {
                if (Device.OS == TargetPlatform.iOS)
                    await this.Navigation.PushModalAsync(new CadastroComFacebookPage());
                else
                    await this.Navigation.PushModalAsync(new CadastroComFacebookPage());
            };

            imgFacebook.GestureRecognizers.Add(img_Click);

            var stackLogo = new StackLayout
            {
                VerticalOptions = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Children = { imgLogoMini }
            };

            var entEmail = new Entry
            {
                Placeholder = AppResources.TextoCampoLoginFormLogin,
                Keyboard = Keyboard.Email
            };
            entEmail.SetBinding<LoginViewModel>(Entry.TextProperty, x => x.login);

            var entSenha = new Entry
            {
                Placeholder = AppResources.TextoCampoSenhaFormLogin,
                IsPassword = true
            };
            entSenha.SetBinding<LoginViewModel>(Entry.TextProperty, x => x.senha);

            var btnEntrar = new Button
            {
                Style = Estilos._estiloPadraoButton,
                Text = AppResources.TextoBotaoOKLogin
            };
            btnEntrar.SetBinding(Button.CommandProperty, "btnEntrar_Click");

            var entryStack = new StackLayout
            {
                Children = { entEmail, entSenha }
            };

            var controlStack = new StackLayout
            {
                Spacing = 140,
                Children = { stackLogo, entryStack }
            };

            var stackBtnEntrar = new StackLayout
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.Center,
                Children = { btnEntrar }
            };

            var btnEsqueciMinhaSenha = new Button
            {
                Text = AppResources.TextoBotaoEsqueciMinhaSenha,
                VerticalOptions = LayoutOptions.Center
            };
            btnEsqueciMinhaSenha.Clicked += async (sender, e) =>
            {
                var confirmConfigs = new Acr.UserDialogs.PromptConfig
                {
                    CancelText = AppResources.TextoBotaoCancelarLogin,
                    OkText = AppResources.TextoResetarSenha,
                    Message = AppResources.TextoEsqueciMinhaSenha,
                };
					
                var result = await Acr.UserDialogs.UserDialogs.Instance.PromptAsync(confirmConfigs);

                if (result.Ok)
                {
                    await model.EsqueciMinhaSenha(result.Text);
                }
            };

            var mainLayout = new StackLayout
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Orientation = StackOrientation.Vertical,
                Padding = 50,
                Spacing = 5,
                Children =
                {
                    controlStack,
                    stackBtnEntrar,
                    btnEsqueciMinhaSenha
                }
            };

            this.Content = new ScrollView
            {
                Content = mainLayout
            };
        }
 public abstract void Prompt(PromptConfig config);
        void SetPasswordPrompt(ContentDialog dialog, StackPanel stack, PromptConfig config)
        {
            var txt = new PasswordBox
            {
                PlaceholderText = config.Placeholder,
                Password = config.Text ?? String.Empty
            };
            stack.Children.Add(txt);

            dialog.PrimaryButtonCommand = new Command(() =>
            {
                config.OnResult?.Invoke(new PromptResult
                {
                    Ok = true,
                    Text = txt.Password
                });
                dialog.Hide();
            });
        }
示例#43
0
 public override IDisposable Prompt(PromptConfig config)
 {
     #if WPF
     return null;
     #else
     var dlg = new InputDialog();
     return new DisposableAction(dlg.Dispose);
     #endif
 }
示例#44
0
 public override void Prompt(PromptConfig config)
 {
     UIApplication.SharedApplication.InvokeOnMainThread(() => {
         if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
             this.ShowIOS8Prompt(config);
         else
             this.ShowIOS7Prompt(config);
     });
 }
示例#45
0
        protected virtual void SetPasswordPrompt(ContentDialog dialog, StackPanel stack, PromptConfig config)
        {
            var txt = new PasswordBox
            {
                PlaceholderText = config.Placeholder ?? String.Empty,
                Password = config.Text ?? String.Empty
            };
            if (config.MaxLength != null)
                txt.MaxLength = config.MaxLength.Value;

            stack.Children.Add(txt);
            dialog.PrimaryButtonCommand = new Command(() =>
            {
                config.OnAction?.Invoke(new PromptResult(true, txt.Password));
                dialog.Hide();
            });
        }
示例#46
0
 public override void Prompt(PromptConfig config)
 {
     if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
         this.ShowIOS8Prompt(config);
     else
         this.ShowIOS7Prompt(config);
 }
示例#47
0
        public override IDisposable Prompt(PromptConfig config)
        {
            var prompt = new CustomMessageBox
            {
                Caption = config.Title,
                Message = config.Message,
                LeftButtonContent = config.OkText
            };
            if (config.IsCancellable)
                prompt.RightButtonContent = config.CancelText;

            var password = new PasswordBox();
            var inputScope = this.GetInputScope(config.InputType);
            var txt = new PhoneTextBox
            {
                InputScope = inputScope
            };
            if (config.Text != null)
                txt.Text = config.Text;

            var isSecure = (config.InputType == InputType.NumericPassword || config.InputType == InputType.Password);
            if (isSecure)
                prompt.Content = password;
            else
                prompt.Content = txt;

            prompt.Dismissed += (sender, args) =>
            {
                var ok = args.Result == CustomMessageBoxResult.LeftButton;
                var text = isSecure ? password.Password : txt.Text.Trim();
                config.OnAction(new PromptResult(ok, text));
            };
            return this.DispatchWithDispose(prompt.Show, prompt.Dismiss);
        }
示例#48
0
        protected virtual void ShowIOS7Prompt(PromptConfig config)
        {
            var result = new PromptResult();
            var isPassword = (config.InputType == InputType.Password || config.InputType == InputType.NumericPassword);
            var cancelText = config.IsCancellable ? config.CancelText : null;

            var dlg = new UIAlertView(config.Title ?? String.Empty, config.Message, null, cancelText, config.OkText) {
                AlertViewStyle = isPassword
                    ? UIAlertViewStyle.SecureTextInput
                    : UIAlertViewStyle.PlainTextInput
            };
            var txt = dlg.GetTextField(0);
            this.SetInputType(txt, config.InputType);
            txt.Placeholder = config.Placeholder;
            if (config.Text != null)
                txt.Text = config.Text;

            dlg.Clicked += (s, e) => {
                result.Ok = ((int)dlg.CancelButtonIndex != (int)e.ButtonIndex);
                result.Text = txt.Text.Trim();
                config.OnResult(result);
            };
            this.Present(dlg);
        }
示例#49
0
 public override void Prompt(PromptConfig config)
 {
     throw new NotImplementedException();
 }
 public virtual Task<PromptResult> PromptAsync(PromptConfig config)
 {
     var tcs = new TaskCompletionSource<PromptResult>();
     config.OnResult = x => tcs.TrySetResult(x);
     this.Prompt(config);
     return tcs.Task;
 }