Пример #1
0
        protected virtual void HookTextChanged(Dialog dialog, EditText txt, Action <PromptTextChangedArgs> onChange)
        {
            if (onChange == null)
            {
                return;
            }

            var buttonId   = (int)Android.Content.DialogButtonType.Positive;
            var promptArgs = new PromptTextChangedArgs {
                Value = String.Empty
            };

            dialog.ShowEvent += (sender, args) =>
            {
                onChange(promptArgs);
                ((AlertDialog)dialog).GetButton(buttonId).Enabled = promptArgs.IsValid;
            };
            txt.AfterTextChanged += (sender, args) =>
            {
                promptArgs.IsValid = true;
                promptArgs.Value   = txt.Text;
                onChange(promptArgs);
                ((AlertDialog)dialog).GetButton(buttonId).Enabled = promptArgs.IsValid;

                if (!txt.Text.Equals(promptArgs.Value))
                {
                    txt.Text = promptArgs.Value;
                    txt.SetSelection(txt.Text.Length);
                }
            };
        }
        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;
            }
        }
Пример #3
0
        protected virtual void HookTextChanged(Dialog dialog, EditText txt, PromptConfig config)
        {
            if (config.OnTextChanged == null)
            {
                return;
            }

            // HACK: this is a temporary fix to deal with restarting input and causing the result action to fire
            // this will at least block completion of your prompt via the soft keyboard
            txt.ImeOptions = ImeAction.None;
            var buttonId   = (int)DialogButtonType.Positive;
            var promptArgs = new PromptTextChangedArgs {
                Value = String.Empty
            };

            dialog.ShowEvent += (sender, args) =>
            {
                config.OnTextChanged(promptArgs);
                this.GetButton(dialog, buttonId).Enabled = promptArgs.IsValid;
                //this.ChangeImeOption(config, txt, promptArgs.IsValid);
            };
            txt.AfterTextChanged += (sender, args) =>
            {
                promptArgs.IsValid = true;
                promptArgs.Value   = txt.Text;
                config.OnTextChanged(promptArgs);
                this.GetButton(dialog, buttonId).Enabled = promptArgs.IsValid;
                //this.ChangeImeOption(config, txt, promptArgs.IsValid);

                if (!txt.Text.Equals(promptArgs.Value))
                {
                    txt.Text = promptArgs.Value;
                    txt.SetSelection(txt.Text.Length);
                }
            };
        }
Пример #4
0
        public override IDisposable Prompt(PromptConfig config)
        {
            Dispatch(() =>
            {
                var dialog = new FormsContentDialog()
                {
                    DataContext = config,
                    Title       = config.Title,
                    // Content will be set
                    IsPrimaryButtonEnabled   = true,
                    PrimaryButtonText        = config.OkText,
                    IsSecondaryButtonEnabled = config.IsCancellable,
                    SecondaryButtonText      = config.CancelText
                };

                if (config.InputType == Acr.UserDialogs.InputType.Password || config.InputType == Acr.UserDialogs.InputType.NumericPassword)
                {
                    var control = new PasswordPromptControl();
                    control.PasswordEdit.PasswordChanged += (s, e) =>
                    {
                        config.Text = control.PasswordEdit.Password;
                        if (config.OnTextChanged != null)
                        {
                            var args = new PromptTextChangedArgs()
                            {
                                Value = control.PasswordEdit.Password
                            };
                            config.OnTextChanged(args);
                            dialog.IsPrimaryButtonEnabled = args.IsValid;
                            if (control.PasswordEdit.Password != args.Value)
                            {
                                control.PasswordEdit.Password = args.Value;
                            }
                        }
                    };
                    dialog.Content = control;
                    // First run of text changed
                    if (config.OnTextChanged != null)
                    {
                        var args = new PromptTextChangedArgs()
                        {
                            Value = control.PasswordEdit.Password
                        };
                        config.OnTextChanged(args);
                        dialog.IsPrimaryButtonEnabled = args.IsValid;
                        control.PasswordEdit.Password = args.Value;
                    }
                }
                else
                {
                    var control = new DefaultPromptControl();
                    control.TextEdit.TextChanged += (s, e) =>
                    {
                        if (config.OnTextChanged != null)
                        {
                            var args = new PromptTextChangedArgs()
                            {
                                Value = control.TextEdit.Text
                            };
                            config.OnTextChanged(args);
                            dialog.IsPrimaryButtonEnabled = args.IsValid;
                            if (control.TextEdit.Text != args.Value)
                            {
                                int selStart                    = control.TextEdit.SelectionStart;
                                control.TextEdit.Text           = args.Value;
                                control.TextEdit.SelectionStart = selStart;
                            }
                        }
                    };
                    dialog.Content = control;
                    // First run of text changed
                    if (config.OnTextChanged != null)
                    {
                        var args = new PromptTextChangedArgs()
                        {
                            Value = control.TextEdit.Text
                        };
                        config.OnTextChanged(args);
                        dialog.IsPrimaryButtonEnabled = args.IsValid;
                        int selStart                    = control.TextEdit.SelectionStart;
                        control.TextEdit.Text           = args.Value;
                        control.TextEdit.SelectionStart = selStart;
                    }
                }

                dialog.PrimaryButtonClick   += (s, e) => { HideContentDialog(); config.OnAction(new PromptResult(true, config.Text)); e.Cancel = true; };
                dialog.SecondaryButtonClick += (s, e) => { HideContentDialog(); config.OnAction(new PromptResult(false, config.Text)); e.Cancel = true; };
                ShowContentDialog(dialog);
            });
            return(new DisposableAction(HideContentDialog));
        }