コード例 #1
0
 protected void Bind(UITextField textField, Action <String> action, string text = null)
 {
     if (text != null)
     {
         textField.Text = text;
     }
     textField.AddTarget((s, e) => {
         UITextField tf = s as UITextField;
         action(tf.Text);
     }, UIControlEvent.EditingChanged);
     textField.ShouldReturn = TextFieldShouldReturn;
 }
コード例 #2
0
        public void SetTextFieldTextBinding(UITextField textField, string propertyPath, Func <object, string> converter = null, Func <string, object> backConverter = null)
        {
            var registration = SetBinding(propertyPath, sourceValue =>
            {
                string text;

                if (converter != null)
                {
                    text = converter(sourceValue);
                }
                else
                {
                    text = sourceValue as string;
                }

                textField.Text = text;
            });

            EventHandler handler = new WeakEventHandler <EventArgs>(delegate
            {
                object value;

                if (backConverter != null)
                {
                    value = backConverter(textField.Text);
                }
                else
                {
                    value = textField.Text;
                }

                registration.SetSourceValue(value);
            }).Handler;

            // Note that need to listen to EditingDidEnd so that autosuggest corrections are consumed: https://github.com/MvvmCross/MvvmCross/pull/2682
            textField.AddTarget(handler, UIControlEvent.EditingChanged);
            textField.AddTarget(handler, UIControlEvent.EditingDidEnd);
        }
コード例 #3
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())
                                                                               )));
                }

                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.ValueChanged += (sender, e) => ValidatePrompt(txt, btnOk, config);
                        txt.AddTarget((sender, e) => ValidatePrompt(txt, btnOk, config), UIControlEvent.EditingChanged);
                        ValidatePrompt(txt, btnOk, config);
                    }
                    this.SetInputType(txt, config.InputType);
                    txt.Placeholder = config.Placeholder ?? String.Empty;
                    if (config.Text != null)
                    {
                        txt.Text = config.Text;
                    }
                });
                return dlg;
            }));
        }
コード例 #4
0
        public static UIAlertController Build(PromptConfig config)
        {
            var controller = UIAlertController.Create(config.Title, config.Message, UIAlertControllerStyle.Alert);

            UITextField txt = null;

            var okButton = UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, (_) => config.OnAction?.Invoke(new PromptResult(true, txt?.Text)));

            controller.AddAction(okButton);

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

            controller.AddTextField((f) =>
            {
                txt = f;
                SetInputType(txt, config.InputType);

                txt.Placeholder = config.Placeholder ?? string.Empty;
                txt.Text        = config.Text ?? string.Empty;

                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, okButton, config), UIControlEvent.EditingChanged);
                    ValidatePrompt(txt, okButton, config);
                }
            });

            return(controller);
        }
        public void showControl(string controlName)
        {
            Console.WriteLine(controlName);

            switch (controlName)
            {
            case UICONTROL_NAMES.textField:

                UITextField textField = new UITextField(new CoreGraphics.CGRect(25, this.View.Frame.Size.Height / 3, this.View.Frame.Size.Width - 50, this.View.Frame.Size.Height / 3));
                textField.Text          = "Hey I am TextField!";
                textField.BorderStyle   = UITextBorderStyle.Line;
                textField.TextAlignment = UITextAlignment.Center;
                this.View.AddSubview(textField);

                break;

            case UICONTROL_NAMES.inputTextField:
                UITextField inputTextField = new UITextField(new CoreGraphics.CGRect(25, this.View.Frame.Size.Height / 3, this.View.Frame.Size.Width - 50, 50));
                inputTextField.BorderStyle   = UITextBorderStyle.RoundedRect;
                inputTextField.TextAlignment = UITextAlignment.Center;
                inputTextField.Placeholder   = "Enter your name";
                inputTextField.Delegate      = this;
                inputTextField.WeakDelegate  = this;

                inputTextField.AddTarget((sender, e) =>
                {
                    Console.WriteLine("Editing Begin");
                }, UIControlEvent.EditingDidBegin);

                inputTextField.AddTarget((sender, e) =>
                {
                    Console.WriteLine("Editing changed");
                }, UIControlEvent.EditingChanged);


                this.View.AddSubview(inputTextField);
                break;

            case UICONTROL_NAMES.button:

                UIButton button = new UIButton(new CoreGraphics.CGRect(25, this.View.Frame.Size.Height / 3, this.View.Frame.Size.Width - 50, 50));
                button.SetTitleColor(UIColor.Black, UIControlState.Normal);
                button.SetTitle("Sample Button", UIControlState.Normal);
                button.Layer.BorderColor    = UIColor.Brown.CGColor;
                button.Layer.BorderWidth    = 10;
                button.TitleLabel.TextColor = UIColor.Blue;
                button.TouchUpInside       += delegate
                {
                    new UIAlertView("Touch1", "TouchUpInside handled", null, "OK", null).Show();
                };
                this.View.AddSubview(button);


                break;

            case UICONTROL_NAMES.toolBar:

                UIToolbar toolbar = new UIToolbar(new CoreGraphics.CGRect(25, this.View.Frame.Size.Height / 3, this.View.Frame.Size.Width - 50, 50));
                toolbar.Alpha = 1;

                UIBarButtonItem barButtonItem = new UIBarButtonItem("Bar1", UIBarButtonItemStyle.Done, null);
                barButtonItem.Title = "Bar1";

                UIBarButtonItem barButtonItem2 = new UIBarButtonItem("Bar1", UIBarButtonItemStyle.Bordered, null);
                barButtonItem.Title = "Bar2";


                var items = new UIBarButtonItem[2];
                items[0] = barButtonItem;
                items[1] = barButtonItem2;

                toolbar.SetItems(items, true);
                this.View.AddSubview(toolbar);
                break;

            case UICONTROL_NAMES.statusBar:

                UINavigationBar nav = this.NavigationController?.NavigationBar;

                nav.BarTintColor        = UIColor.Red;
                nav.TintColor           = UIColor.White;
                nav.TitleTextAttributes = new UIStringAttributes()
                {
                    ForegroundColor   = UIColor.Red,
                    KerningAdjustment = 3
                };


                this.SetNeedsStatusBarAppearanceUpdate();
                UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent;


                break;

            case UICONTROL_NAMES.navigationBar:
                UINavigationBar navigationBar = this.NavigationController?.NavigationBar;
                navigationBar.BarTintColor = UIColor.LightGray;
                //navigationBar.TintColor = UIColor.White;
                navigationBar.TopItem.Title = "Sample Nav";

                break;

            case UICONTROL_NAMES.tabBar:

                UITabBar tabBar = new UITabBar(new CoreGraphics.CGRect(25, this.View.Frame.Size.Height / 3, this.View.Frame.Size.Width - 50, 50));

                var tabBarItems = new UITabBarItem[3];
                for (int i = 0; i < 3; i++)
                {
                    var tabBarItem = new UITabBarItem("TAB " + i, null, i);
                    tabBarItems[i] = tabBarItem;
                }

                tabBar.Items       = tabBarItems;
                tabBar.ItemSpacing = 10;

                tabBar.ItemSelected += (object sender, UITabBarItemEventArgs e) =>
                {
                    Console.WriteLine($"{e.Item} has selected");
                    if (e.Item.Tag == 0)
                    {
                        new UIAlertView(e.Item.Tag.ToString(), "ItemSelected handled", null, "OK", null).Show();
                    }
                    else if (e.Item.Tag == 1)
                    {
                        new UIAlertView(e.Item.Tag.ToString(), "ItemSelected handled", null, "OK", null).Show();
                    }
                    else if (e.Item.Tag == 2)
                    {
                        new UIAlertView(e.Item.Tag.ToString(), "ItemSelected handled", null, "OK", null).Show();
                    }
                };
                this.View.AddSubview(tabBar);

                break;

            case UICONTROL_NAMES.imageView:
                UIImageView imageView = new UIImageView(new CoreGraphics.CGRect(25, this.View.Frame.Size.Height / 3, this.View.Frame.Size.Width - 50, this.View.Frame.Size.Height / 3));
                imageView.BackgroundColor = UIColor.Blue;
                imageView.Image           = UIImage.FromFile("mac.png");
                this.View.AddSubview(imageView);
                break;

            case UICONTROL_NAMES.scrollView:
                UIScrollView scrollView = new UIScrollView(new CoreGraphics.CGRect(10, 100, this.View.Frame.Size.Width - 20, this.View.Frame.Size.Height * 1.5));
                scrollView.AlwaysBounceVertical = true;
                CGSize size = new CGSize(this.View.Frame.Size.Width - 50, this.View.Frame.Size.Height * 1.5);
                scrollView.ContentSize     = size;
                scrollView.BackgroundColor = UIColor.LightGray;

                UILabel scrollText = new UILabel();
                scrollText.Frame = new CoreGraphics.CGRect(5, scrollView.Frame.Y, scrollView.Frame.Size.Width - 10, scrollView.Frame.Size.Height - 50);
                scrollText.Text  = "By the 4th century BCE, the late Achaemenid period, the inscriptions of Artaxerxes II and Artaxerxes III differ enough from the language of Darius' inscriptions to be called a pre-Middle Persian, or post-Old Persian.[14] Old Persian subsequently evolved into Middle Persian, which is in turn the ancestor of New Persian. Professor Gilbert Lazard, a famous Iranologist and the author of the book Persian Grammar states: The language known as New Persian, which usually is called at this period (early Islamic times) by the name of Parsi-Dari, can be classified linguistically as a continuation of Middle Persian, the official religious and literary language of Sassanian Iran, itself a continuation of Old Persian, the language of the Achaemenids. Unlike the other languages and dialects, ancient and modern, of the Iranian group such as Avestan, Parthian, Soghdian, Kurdish, Pashto, etc., Old, Middle and New Persian represent one and the same language at three states of its history. It had its origin in Fars and is differentiated by dialectical features, still easily recognizable from the dialect prevailing in north-western and eastern Iran. Middle Persian, also sometimes called Pahlavi, is a direct continuation of old Persian and was used as the written official language of the country.[16][17] Comparison of the evolution at each stage of the language shows great simplification in grammar and syntax. However, New Persian is a direct descendent of Middle and Old Persian.[18]";
                scrollText.Lines = 0;

                scrollView.AddSubview(scrollText);
                this.View.AddSubview(scrollView);
                break;

            case UICONTROL_NAMES.tableView:

                UITableView tableView = new UITableView();
                tableView.Frame           = new CGRect(0, 100, this.View.Frame.Size.Width, this.View.Frame.Size.Height);
                tableView.DataSource      = this;
                tableView.Delegate        = this;
                tableView.AllowsSelection = true;
                this.View.AddSubview(tableView);
                break;

            case UICONTROL_NAMES.collectionView:
                UICollectionViewFlowLayout collectionViewFlowLayout = new UICollectionViewFlowLayout();

                collectionViewFlowLayout.ItemSize = new CGSize(this.View.Bounds.Size.Width, this.View.Bounds.Size.Height);

                UICollectionView collectionView = new UICollectionView(frame: this.View.Bounds, layout: collectionViewFlowLayout);
                collectionView.Delegate        = this;
                collectionView.DataSource      = this;
                collectionView.BackgroundColor = UIColor.Cyan;


                collectionView.RegisterClassForCell(typeof(MyCollectionViewCell), "MyCollectionViewCell");

                this.View.AddSubview(collectionView);

                break;

            case UICONTROL_NAMES.splitView:
                Console.WriteLine("Better try again");


                break;

            case UICONTROL_NAMES.textView:

                UITextView textView = new UITextView();
                textView.Frame         = new CGRect(25, 100, this.View.Frame.Size.Width - 50, this.View.Frame.Size.Height * 1.5);
                textView.Text          = "The name India is derived from Indus, which originates from the Old Persian word Hindu.[24] The latter term stems from the Sanskrit word Sindhu, which was the historical local appellation for the Indus River.[25] The ancient Greeks referred to the Indians as Indoi (Ἰνδοί), which translates as The people of the Indus.The geographical term Bharat, which is recognised by the Constitution of India as an official name for the country,[27] is used by many Indian languages in its variations. \n\n It is a modernisation of the historical name Bharatavarsha, which traditionally referred to the Indian subcontinent and gained increasing currency from the mid-19th century as a native name for India.[28][29] \n Scholars believe it to be named after the Vedic tribe of Bhāratas in the second millennium BCE.[30] It is also traditionally associated with the rule of the legendary emperor Bharata.[31] The Hindu text Skanda Purana states that the region was named Bharat after Bharata Chakravartin.Gaṇarājya(literally, people's State) is the Sanskrit/Hindi term for republic dating back to ancient times. Hindustan([ɦɪnd̪ʊˈst̪aːn](About this sound listen)) is a Persian name for India dating back to the 3rd century BCE.It was introduced into India by the Mughals and widely used since then. \n \n Its meaning varied, referring to a region that encompassed northern India and Pakistan or India in its entirety.[28][29][35] Currently, the name may refer to either the northern part of India or the entire country";
                textView.ScrollEnabled = true;

                var attributedText = new NSMutableAttributedString(textView.Text);
                attributedText.AddAttribute(UIStringAttributeKey.ForegroundColor, UIColor.Red, new NSRange(0, textView.Text.Length));
                textView.AttributedText = attributedText;
                this.View.AddSubview(textView);

                break;

            case UICONTROL_NAMES.viewTransition:

                UIView view1 = new UIView(frame: new CGRect(25, this.View.Frame.Size.Height / 4, this.View.Frame.Size.Width - 50, this.View.Frame.Size.Height / 6));
                view1.BackgroundColor = UIColor.Red;
                this.View.AddSubview(view1);

                UIView view2 = new UIView(frame: new CGRect(25, this.View.Frame.Size.Height / 2, this.View.Frame.Size.Width - 50, this.View.Frame.Size.Height / 6));
                view2.BackgroundColor = UIColor.Red;
                this.View.AddSubview(view2);

                UIButton transitionButton = new UIButton(frame: new CoreGraphics.CGRect(25, this.View.Frame.Size.Height / 1.3, this.View.Frame.Size.Width - 50, this.View.Frame.Size.Width / 5));
                transitionButton.SetTitle("Show transition", UIControlState.Normal);
                transitionButton.BackgroundColor = UIColor.Brown;
                transitionButton.TitleLabel.Text = "Show transition";

                transitionButton.TouchUpInside += delegate
                {
                    if (transitionButton.Selected == true)
                    {
                        transitionButton.Selected = false;
                        UIView.Transition(view1, 0.4, UIViewAnimationOptions.TransitionCrossDissolve, null, () =>
                        {
                            view1.BackgroundColor = UIColor.Blue;
                            view2.BackgroundColor = UIColor.Red;
                        });
                    }
                    else
                    {
                        transitionButton.Selected = true;

                        UIView.Transition(view1, 0.4, UIViewAnimationOptions.TransitionCrossDissolve, null, () =>
                        {
                            view1.BackgroundColor = UIColor.Red;
                            view2.BackgroundColor = UIColor.Blue;
                        });
                    }
                };
                this.View.AddSubview(transitionButton);

                break;

            case UICONTROL_NAMES.picker:

                UILabel valueLabel = new UILabel(frame: new CoreGraphics.CGRect(25, this.View.Frame.Size.Height / 1.3, this.View.Frame.Size.Width - 50, this.View.Frame.Size.Width / 5));
                valueLabel.BackgroundColor = UIColor.Brown;
                valueLabel.Text            = "Show transition";

                UIPickerView pickerView = new UIPickerView();
                pickerView.Frame      = new CoreGraphics.CGRect(25, this.View.Frame.Size.Height / 3, this.View.Frame.Size.Width - 50, this.View.Frame.Size.Width / 3);
                pickerView.DataSource = this;
                pickerView.Delegate   = this;
                this.View.AddSubview(pickerView);

                break;

            case UICONTROL_NAMES.switches:

                UILabel switchStatusLabel = new UILabel(frame: new CoreGraphics.CGRect(25, this.View.Frame.Size.Height / 1.3, this.View.Frame.Size.Width - 50, this.View.Frame.Size.Width / 5));
                switchStatusLabel.BackgroundColor = UIColor.Black;
                switchStatusLabel.TextAlignment   = UITextAlignment.Center;
                switchStatusLabel.TextColor       = UIColor.White;
                switchStatusLabel.Text            = "Switch Status";
                this.View.AddSubview(switchStatusLabel);

                UISwitch switchObject = new UISwitch();
                switchObject.Frame         = new CoreGraphics.CGRect(this.View.Frame.Size.Width / 2, this.View.Frame.Size.Height / 3, 10f, 10f);
                switchObject.ValueChanged += delegate {
                    if (switchObject.On)
                    {
                        Console.WriteLine("TRUE");
                        switchStatusLabel.BackgroundColor = UIColor.Green;
                        switchStatusLabel.Text            = "Switch ON";
                    }
                    else
                    {
                        Console.WriteLine("FALSE");
                        switchStatusLabel.BackgroundColor = UIColor.Red;
                        switchStatusLabel.Text            = "Switch OFF";
                    }
                };
                this.View.AddSubview(switchObject);

                break;

            case UICONTROL_NAMES.sliders:

                UILabel sliderStatusLabel = new UILabel(frame: new CoreGraphics.CGRect(25, this.View.Frame.Size.Height / 1.3, this.View.Frame.Size.Width - 50, this.View.Frame.Size.Width / 5));
                sliderStatusLabel.TextAlignment   = UITextAlignment.Center;
                sliderStatusLabel.TextColor       = UIColor.White;
                sliderStatusLabel.BackgroundColor = UIColor.Blue;
                sliderStatusLabel.Text            = "Slider Value";
                this.View.AddSubview(sliderStatusLabel);


                UISlider slider = new UISlider(frame: new CoreGraphics.CGRect(25, this.View.Frame.Size.Height / 2, this.View.Frame.Size.Width - 50, this.View.Frame.Size.Width / 5));
                slider.MinValue = 0;
                slider.MaxValue = 100;
                slider.MinimumTrackTintColor = UIColor.FromRGB(0xE6, 0x00, 0x06);
                slider.ThumbTintColor        = UIColor.Red;
                slider.MinimumTrackTintColor = UIColor.Orange;
                slider.MaximumTrackTintColor = UIColor.Yellow;

                slider.ValueChanged += delegate {
                    sliderStatusLabel.Text = "Slider Value :" + slider.Value.ToString();
                };

                this.View.AddSubview(slider);


                break;

            case UICONTROL_NAMES.alerts:

                var alert = UIAlertController.Create("Sample Alert", "Now You are on Visual Studio with Xamarin.iOS", UIAlertControllerStyle.ActionSheet);

                // set up button event handlers
                alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, a => taskCompletionSource.SetResult(true)));
                alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Default, a => taskCompletionSource.SetResult(false)));
                //
                //      var userClickedOk = await ShowOKCancel(this, "Action Sheet Title", " It is just awesome!");
                // go on to use the result in some way

                //if (userClickedOk)
                //{
                //    Console.WriteLine("Clicked on Okay");
                //}
                //else
                //{

                //    Console.WriteLine("Clicked on Cancel");
                //};


                // show it
                this.PresentViewController(alert, true, null);
                break;

            default:
                Console.WriteLine("Invalid grade");
                break;
            }
        }
コード例 #6
0
        public FormEntryTableViewCell(
            string labelName           = null,
            bool useTextView           = false,
            nfloat?height              = null,
            bool useLabelAsPlaceholder = false,
            float leadingConstant      = 15f)
            : base(UITableViewCellStyle.Default, nameof(FormEntryTableViewCell))
        {
            var descriptor = UIFontDescriptor.PreferredBody;
            var pointSize  = descriptor.PointSize;

            if (labelName != null && !useLabelAsPlaceholder)
            {
                Label = new UILabel
                {
                    Text = labelName,
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Font      = UIFont.FromDescriptor(descriptor, 0.8f * pointSize),
                    TextColor = ThemeHelpers.MutedColor
                };

                ContentView.Add(Label);
            }

            if (useTextView)
            {
                TextView = new UITextView
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Font            = UIFont.FromDescriptor(descriptor, pointSize),
                    TextColor       = ThemeHelpers.TextColor,
                    TintColor       = ThemeHelpers.TextColor,
                    BackgroundColor = ThemeHelpers.BackgroundColor
                };

                if (!ThemeHelpers.LightTheme)
                {
                    TextView.KeyboardAppearance = UIKeyboardAppearance.Dark;
                }

                ContentView.Add(TextView);
                ContentView.AddConstraints(new NSLayoutConstraint[] {
                    NSLayoutConstraint.Create(TextView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Leading, 1f, leadingConstant),
                    NSLayoutConstraint.Create(ContentView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, TextView, NSLayoutAttribute.Trailing, 1f, 15f),
                    NSLayoutConstraint.Create(ContentView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, TextView, NSLayoutAttribute.Bottom, 1f, 10f)
                });

                if (labelName != null && !useLabelAsPlaceholder)
                {
                    ContentView.AddConstraint(
                        NSLayoutConstraint.Create(TextView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, Label, NSLayoutAttribute.Bottom, 1f, 10f));
                }
                else
                {
                    ContentView.AddConstraint(
                        NSLayoutConstraint.Create(TextView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Top, 1f, 10f));
                }

                if (height.HasValue)
                {
                    ContentView.AddConstraint(
                        NSLayoutConstraint.Create(TextView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1f, height.Value));
                }

                TextView.Changed += (object sender, EventArgs e) =>
                {
                    ValueChanged?.Invoke(sender, e);
                };
            }

            else
            {
                TextField = new UITextField
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    BorderStyle     = UITextBorderStyle.None,
                    Font            = UIFont.FromDescriptor(descriptor, pointSize),
                    ClearButtonMode = UITextFieldViewMode.WhileEditing,
                    TextColor       = ThemeHelpers.TextColor,
                    TintColor       = ThemeHelpers.TextColor,
                    BackgroundColor = ThemeHelpers.BackgroundColor
                };

                if (!ThemeHelpers.LightTheme)
                {
                    TextField.KeyboardAppearance = UIKeyboardAppearance.Dark;
                }

                if (useLabelAsPlaceholder)
                {
                    TextField.Placeholder = labelName;
                }

                ContentView.Add(TextField);
                ContentView.AddConstraints(new NSLayoutConstraint[] {
                    NSLayoutConstraint.Create(TextField, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Leading, 1f, leadingConstant),
                    NSLayoutConstraint.Create(ContentView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, TextField, NSLayoutAttribute.Trailing, 1f, 15f),
                    NSLayoutConstraint.Create(ContentView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, TextField, NSLayoutAttribute.Bottom, 1f, 10f)
                });

                if (labelName != null && !useLabelAsPlaceholder)
                {
                    ContentView.AddConstraint(
                        NSLayoutConstraint.Create(TextField, NSLayoutAttribute.Top, NSLayoutRelation.Equal, Label, NSLayoutAttribute.Bottom, 1f, 10f));
                }
                else
                {
                    ContentView.AddConstraint(
                        NSLayoutConstraint.Create(TextField, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Top, 1f, 10f));
                }

                if (height.HasValue)
                {
                    ContentView.AddConstraint(
                        NSLayoutConstraint.Create(TextField, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1f, height.Value));
                }

                TextField.AddTarget((object sender, EventArgs e) =>
                {
                    ValueChanged?.Invoke(sender, e);
                }, UIControlEvent.EditingChanged);
            }

            if (labelName != null && !useLabelAsPlaceholder)
            {
                ContentView.AddConstraints(new NSLayoutConstraint[] {
                    NSLayoutConstraint.Create(Label, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Leading, 1f, leadingConstant),
                    NSLayoutConstraint.Create(Label, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Top, 1f, 10f),
                    NSLayoutConstraint.Create(ContentView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, Label, NSLayoutAttribute.Trailing, 1f, 15f)
                });
            }
        }
コード例 #7
0
        public override void OnViewModelLoadedOverride()
        {
            AddTopSectionDivider();

            _errorContainer = new BareUIVisibilityContainer()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                IsVisible = false
            };
            {
                var stackViewIncorrect = new UIStackView()
                {
                    Axis = UILayoutConstraintAxis.Vertical
                };
                stackViewIncorrect.AddArrangedSubview(new UIView()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false
                }.SetHeight(8));
                _labelError = new UILabel()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Text      = "Error",
                    Lines     = 0,
                    TextColor = UIColor.Red
                };
                stackViewIncorrect.AddArrangedSubview(_labelError);
                _labelError.StretchWidth(stackViewIncorrect, left: 16, right: 16);
                stackViewIncorrect.AddArrangedSubview(new UIView()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false
                }.SetHeight(8));

                AddDivider(stackViewIncorrect);

                _errorContainer.Child = stackViewIncorrect;
            }
            StackView.AddArrangedSubview(_errorContainer);
            _errorContainer.StretchWidth(StackView);

            var textField = new UITextField()
            {
                Placeholder            = "New username",
                AutocapitalizationType = UITextAutocapitalizationType.None,
                AutocorrectionType     = UITextAutocorrectionType.No,
                KeyboardType           = UIKeyboardType.ASCIICapable,
                ReturnKeyType          = UIReturnKeyType.Done
            };

            textField.AddTarget(new WeakEventHandler <EventArgs>(delegate
            {
                _errorContainer.IsVisible = false;
            }).Handler, UIControlEvent.EditingChanged);
            AddTextField(textField, nameof(ViewModel.Username), firstResponder: true);

            AddSectionDivider();

            var buttonContinue = new UIButton(UIButtonType.System)
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            buttonContinue.TouchUpInside += new WeakEventHandler <EventArgs>(delegate { ViewModel.Update(); }).Handler;
            buttonContinue.SetTitle("Update Username", UIControlState.Normal);
            StackView.AddArrangedSubview(buttonContinue);
            buttonContinue.StretchWidth(StackView);
            buttonContinue.SetHeight(44);

            AddBottomSectionDivider();

            ViewModel.ActionError += new WeakEventHandler <string>(ViewModel_ActionError).Handler;

            BindingHost.SetBinding(nameof(ViewModel.IsUpdatingUsername), delegate
            {
                IsLoadingOverlayVisible = ViewModel.IsUpdatingUsername;
            });

            base.OnViewModelLoadedOverride();
        }
コード例 #8
0
        public override void InitializeControls(UITableView tableView)
        {
            if (Entry == null)
            {
                SizeF size   = ComputeEntryPosition(tableView, Cell);
                var   _entry = new UITextField(new RectangleF(size.Width, (Cell.ContentView.Bounds.Height - size.Height) / 2 - 1, 290 - size.Width, size.Height))
                {
                    Tag = 1, Placeholder = _Placeholder ?? "", SecureTextEntry = _IsPassword
                };
                _entry.Font = UIFont.SystemFontOfSize(17);
                _entry.AddTarget(delegate { Value = _entry.Text; }, UIControlEvent.ValueChanged);

                Entry = _entry;

                Entry.Ended += delegate
                {
                    Value = Entry.Text;
                };

                Entry.ShouldReturn += delegate
                {
                    EntryElement focus = null;
                    foreach (var e in (Parent as ISection).Elements)
                    {
                        if (e == this)
                        {
                            focus = this;
                        }
                        else if (focus != null && e is EntryElement)
                        {
                            focus = e as EntryElement;
                        }
                    }

                    if (focus != this)
                    {
                        tableView.ScrollToRow(focus.IndexPath, UITableViewScrollPosition.Middle, true);
                        focus.Entry.BecomeFirstResponder();
                    }
                    else
                    {
                        focus.Entry.ResignFirstResponder();
                    }

                    return(true);
                };

                Entry.Started += delegate
                {
                    var bindingExpression = GetBindingExpression("Value");

                    if (bindingExpression != null)
                    {
                        Entry.Text = (string)bindingExpression.ConvertbackValue(Value);
                    }
                    else
                    {
                        Entry.Text = Value;
                    }

                    EntryElement self       = null;
                    var          returnType = UIReturnKeyType.Done;

                    foreach (var e in (Parent as ISection).Elements)
                    {
                        if (e == this)
                        {
                            self = this;
                        }
                        else if (self != null && e is EntryElement)
                        {
                            returnType = UIReturnKeyType.Next;
                        }
                    }

                    Entry.ReturnKeyType = returnType;
                };
            }

            Entry.KeyboardType  = KeyboardType;
            Entry.TextAlignment = UITextAlignment.Right;

            Entry.Text = Value;

            Cell.TextLabel.Text = Caption;

            Cell.ContentView.AddSubview(Entry);
        }
コード例 #9
0
        public override void OnViewModelLoadedOverride()
        {
            AddTopSectionDivider();

            AddSpacing(8);
            var label = new UILabel()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Text  = "Please confirm your identity by entering your Power Planner account password.",
                Lines = 0
            };

            StackView.AddArrangedSubview(label);
            label.StretchWidth(StackView, left: 16, right: 16);
            AddSpacing(8);

            AddDivider();

            _incorrectViewContainer = new BareUIVisibilityContainer()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                IsVisible = false
            };
            {
                var stackViewIncorrect = new UIStackView()
                {
                    Axis = UILayoutConstraintAxis.Vertical
                };
                stackViewIncorrect.AddArrangedSubview(new UIView()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false
                }.SetHeight(8));
                var labelIncorrect = new UILabel()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Text      = "Incorrect password. Please try again.",
                    Lines     = 0,
                    TextColor = UIColor.Red
                };
                stackViewIncorrect.AddArrangedSubview(labelIncorrect);
                labelIncorrect.StretchWidth(stackViewIncorrect, left: 16, right: 16);
                stackViewIncorrect.AddArrangedSubview(new UIView()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false
                }.SetHeight(8));

                AddDivider(stackViewIncorrect);

                _incorrectViewContainer.Child = stackViewIncorrect;
            }
            StackView.AddArrangedSubview(_incorrectViewContainer);
            _incorrectViewContainer.StretchWidth(StackView);

            var textField = new UITextField()
            {
                Placeholder     = "Current password",
                SecureTextEntry = true,
                ReturnKeyType   = UIReturnKeyType.Done
            };

            textField.AddTarget(new WeakEventHandler <EventArgs>(delegate
            {
                _incorrectViewContainer.IsVisible = false;
            }).Handler, UIControlEvent.EditingChanged);
            AddTextField(textField, nameof(ViewModel.Password), firstResponder: true);

            AddSectionDivider();

            var buttonContinue = new UIButton(UIButtonType.System)
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            buttonContinue.TouchUpInside += new WeakEventHandler <EventArgs>(delegate { ViewModel.Continue(); }).Handler;
            buttonContinue.SetTitle("Continue", UIControlState.Normal);
            StackView.AddArrangedSubview(buttonContinue);
            buttonContinue.StretchWidth(StackView);
            buttonContinue.SetHeight(44);

            if (ViewModel.ShowForgotPassword)
            {
                AddDivider(fullWidth: true);

                var forgotViews = new UIView()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    BackgroundColor = ColorResources.InputSectionDividers
                };

                {
                    var buttonForgotPassword = new UIButton(UIButtonType.System)
                    {
                        TranslatesAutoresizingMaskIntoConstraints = false,
                        HorizontalAlignment = UIControlContentHorizontalAlignment.Center,
                        Font = UIFont.PreferredCaption1
                    };
                    buttonForgotPassword.TouchUpInside += new WeakEventHandler(delegate { ViewModel.ForgotPassword(); }).Handler;
                    buttonForgotPassword.SetTitle("Forgot Password", UIControlState.Normal);
                    forgotViews.Add(buttonForgotPassword);
                    buttonForgotPassword.StretchWidth(forgotViews);
                    buttonForgotPassword.StretchHeight(forgotViews, top: 16, bottom: 16);
                }

                StackView.AddArrangedSubview(forgotViews);
                forgotViews.StretchWidth(StackView);
                forgotViews.SetHeight(44);
            }

            else
            {
                AddBottomSectionDivider();
            }

            ViewModel.ActionIncorrectPassword += new WeakEventHandler(ViewModel_ActionIncorrectPassword).Handler;

            base.OnViewModelLoadedOverride();
        }
コード例 #10
0
        private bool Alert(Color backgroundcolor, Color fontColor, string title, string content, string positiveButton, string negativeButton, string neutralButton, Action <string> callback, InputConfig config, bool isGetInput, bool iscontentleftalign)
        {
            UIApplication.SharedApplication.InvokeOnMainThread(() =>
            {
                var pushView         = UIAlertController.Create(title, content, UIAlertControllerStyle.Alert);
                var window           = UIApplication.SharedApplication.KeyWindow;
                var visualEffectView = GetTransparentView();
                UITextField field    = null;
                var posbut           = UIAlertAction.Create(positiveButton, UIAlertActionStyle.Default, (obj) =>
                {
                    visualEffectView.RemoveFromSuperview();
                    if (field != null && !string.IsNullOrEmpty(field.Text))
                    {
                        callback(field.Text);
                    }
                    else
                    {
                        callback(positiveButton);
                    }
                });
                if (isGetInput)
                {
                    pushView.AddTextField((textField) =>
                    {
                        field = textField;
                        if (isGetInput)
                        {
                            UIView[] array2 = pushView.View.Subviews;
                            if (config != null)
                            {
                                array2[0].Subviews[0].TintColor = UIColor.Gray;
                                if (config.MinLength != 0)
                                {
                                    posbut.Enabled = false;
                                    field.AddTarget((w, me) =>
                                    {
                                        if (field.Text.Trim().Length >= config.MinLength)
                                        {
                                            pushView.View.TintColor = fontColor.ToUIColor();
                                            //array2[0].Subviews[0].Subviews[1].TintColor = fontColor.ToUIColor();
                                            posbut.Enabled = true;
                                        }
                                        else
                                        {
                                            //array2[0].Subviews[0].TintColor = UIColor.Gray;
                                            posbut.Enabled = false;
                                        }
                                    }, UIControlEvent.EditingChanged);
                                }
                                else
                                {
                                    posbut.Enabled          = true;
                                    pushView.View.TintColor = fontColor.ToUIColor();
                                }
                            }
                        }
                        if (config != null)
                        {
                            if (config.keyboard == Keyboard.Telephone)
                            {
                                field.KeyboardType = UIKeyboardType.PhonePad;
                            }
                            else if (config.keyboard == Keyboard.Text)
                            {
                                field.KeyboardType = UIKeyboardType.Default;
                            }
                            else if (config.keyboard == Keyboard.Numeric)
                            {
                                field.KeyboardType = UIKeyboardType.NumberPad;
                            }
                            else if (config.keyboard == Keyboard.Email)
                            {
                                field.KeyboardType = UIKeyboardType.EmailAddress;
                            }

                            field.Placeholder     = config.placeholder;
                            field.TextColor       = config.FontColor.ToUIColor();
                            field.BackgroundColor = config.BackgroundColor.ToUIColor();
                            if (config.MinLength != 0)
                            {
                                field.ShouldChangeCharacters = (UITextField sd, NSRange range, string replacementString) =>
                                {
                                    var length = textField.Text.Length - range.Length + replacementString.Length;
                                    return(length <= config.MaxLength);
                                };
                            }
                            if (!string.IsNullOrEmpty(config.DefaultValue))
                            {
                                field.Text = config.DefaultValue;
                            }
                        }
                        field.AutocorrectionType = UITextAutocorrectionType.No;
                        field.ClearButtonMode    = UITextFieldViewMode.WhileEditing;
                        field.ReturnKeyType      = UIReturnKeyType.Done;
                        field.BorderStyle        = UITextBorderStyle.RoundedRect;
                    });

                    var frameRect  = field.Frame;
                    frameRect.Size = new CGSize(frameRect.Width, 53);
                    field.Frame    = frameRect;
                }
                pushView.AddAction(posbut);


                //Customization/Hack
                UIView[] array = pushView.View.Subviews;

                if (config != null && config.MinLength != 0)
                {
                    //TODO:Need to Fix this
                    //array[0].Subviews[0].TintColor = UIColor.Gray;
                    array[0].Subviews[0].Subviews[1].TintColor = fontColor.ToUIColor();
                }
                else
                {
                    array[0].Subviews[0].TintColor = fontColor.ToUIColor();
                }
                foreach (var item in array[0].Subviews[0].Subviews[0].Subviews)
                {
                    item.BackgroundColor = backgroundcolor.ToUIColor();
                }

                UIStringAttributes bodystyle = new UIStringAttributes
                {
                    ForegroundColor = fontColor.ToUIColor(),
                };

                if (iscontentleftalign)
                {
                    NSMutableParagraphStyle style = new NSMutableParagraphStyle();
                    style.Alignment          = UITextAlignment.Left;
                    bodystyle.ParagraphStyle = style;
                }

                UIStringAttributes titlecolor = new UIStringAttributes
                {
                    ForegroundColor = fontColor.ToUIColor(),
                    Font            = UIFont.FromName("Helvetica-Bold", 18f),
                };

                pushView.SetValueForKey(new NSAttributedString(title, titlecolor), new NSString("attributedTitle"));
                pushView.SetValueForKey(new NSAttributedString(content, bodystyle), new NSString("attributedMessage"));
                if (negativeButton != null)
                {
                    pushView.AddAction(UIAlertAction.Create(negativeButton, UIAlertActionStyle.Cancel, (obj) =>
                    {
                        //visualEffectView.Alpha=0
                        visualEffectView.RemoveFromSuperview();
                        callback(negativeButton);
                    }));
                }
                if (neutralButton != null)
                {
                    pushView.AddAction(UIAlertAction.Create(neutralButton, UIAlertActionStyle.Default, (obj) =>
                    {
                        visualEffectView.RemoveFromSuperview();
                        callback(neutralButton);
                    }));
                }
                window.MakeKeyAndVisible();
                window.RootViewController.PresentViewController(pushView, true, null);
                window.RootViewController.View.AddSubview(visualEffectView);
            });
            return(true);
        }
コード例 #11
0
        public override void OnViewModelLoadedOverride()
        {
            base.OnViewModelLoadedOverride();

            AddTopSectionDivider();

            _errorContainer = new BareUIVisibilityContainer()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                IsVisible = false
            };
            {
                var stackViewIncorrect = new UIStackView()
                {
                    Axis = UILayoutConstraintAxis.Vertical
                };
                stackViewIncorrect.AddArrangedSubview(new UIView()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false
                }.SetHeight(8));
                _labelError = new UILabel()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Text      = "Error",
                    Lines     = 0,
                    TextColor = UIColor.Red
                };
                stackViewIncorrect.AddArrangedSubview(_labelError);
                _labelError.StretchWidth(stackViewIncorrect, left: 16, right: 16);
                stackViewIncorrect.AddArrangedSubview(new UIView()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false
                }.SetHeight(8));

                AddDivider(stackViewIncorrect);

                _errorContainer.Child = stackViewIncorrect;
            }
            StackView.AddArrangedSubview(_errorContainer);
            _errorContainer.StretchWidth(StackView);

            var textField = new UITextField()
            {
                Placeholder            = "Provide your email",
                AutocapitalizationType = UITextAutocapitalizationType.None,
                AutocorrectionType     = UITextAutocorrectionType.Yes,
                KeyboardType           = UIKeyboardType.EmailAddress,
                ReturnKeyType          = UIReturnKeyType.Done
            };

            textField.AddTarget(new WeakEventHandler <EventArgs>(delegate
            {
                _errorContainer.IsVisible = false;
            }).Handler, UIControlEvent.EditingChanged);
            AddTextField(textField, nameof(ViewModel.Email), firstResponder: true);

            AddSectionDivider();

            var buttonConvert = new UIButton(UIButtonType.System)
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            buttonConvert.TouchUpInside += new WeakEventHandler <EventArgs>(async delegate
            {
                ShowLoadingOverlay();
                await ViewModel.CreateOnlineAccountAsync();
                HideLoadingOverlay();
            }).Handler;
            buttonConvert.SetTitle("Convert to Online Account", UIControlState.Normal);
            StackView.AddArrangedSubview(buttonConvert);
            buttonConvert.StretchWidth(StackView);
            buttonConvert.SetHeight(44);

            var mergeExistingContainer = new UIStackView()
            {
                Axis = UILayoutConstraintAxis.Vertical
            };

            {
                mergeExistingContainer.AddSectionDivider();

                mergeExistingContainer.AddSpacing(16);
                var labelMergeExistingExplanation = new UILabel()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Text      = PowerPlannerResources.GetString("Settings_ConvertToOnline_TextBlockConfirmMergeExisting.Text"),
                    Lines     = 0,
                    TextColor = UIColor.Red
                };
                mergeExistingContainer.AddArrangedSubview(labelMergeExistingExplanation);
                labelMergeExistingExplanation.StretchWidth(mergeExistingContainer, left: 16, right: 16);
                mergeExistingContainer.AddSpacing(16);

                mergeExistingContainer.AddDivider();

                var buttonContinue = new UIButton(UIButtonType.System)
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    TintColor = UIColor.Red
                };
                buttonContinue.TouchUpInside += new WeakEventHandler <EventArgs>(async delegate
                {
                    ShowLoadingOverlay();
                    await ViewModel.MergeExisting();
                    HideLoadingOverlay();
                }).Handler;
                buttonContinue.SetTitle(PowerPlannerResources.GetString("Settings_ConfirmIdentityPage_ButtonContinue.Content"), UIControlState.Normal);
                mergeExistingContainer.AddArrangedSubview(buttonContinue);
                buttonContinue.StretchWidth(mergeExistingContainer);
                buttonContinue.SetHeight(44);

                mergeExistingContainer.AddDivider();

                var buttonCancel = new UIButton(UIButtonType.System)
                {
                    TranslatesAutoresizingMaskIntoConstraints = false
                };
                buttonCancel.TouchUpInside += new WeakEventHandler <EventArgs>(delegate
                {
                    ViewModel.CancelMergeExisting();
                }).Handler;
                buttonCancel.SetTitle(PowerPlannerResources.GetString("Buttons_Cancel.Content"), UIControlState.Normal);
                mergeExistingContainer.AddArrangedSubview(buttonCancel);
                buttonCancel.StretchWidth(mergeExistingContainer);
                buttonCancel.SetHeight(44);
            }
            AddUnderVisiblity(mergeExistingContainer, nameof(ViewModel.ShowConfirmMergeExisting));

            AddBottomSectionDivider();

            BindingHost.SetBinding(nameof(ViewModel.Error), delegate
            {
                if (string.IsNullOrWhiteSpace(ViewModel.Error))
                {
                    _errorContainer.IsVisible = false;
                }
                else
                {
                    _errorContainer.IsVisible = true;
                    _labelError.Text          = ViewModel.Error;
                }
            });

            base.OnViewModelLoadedOverride();
        }
コード例 #12
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            //scrollView = stackView.Superview as UIScrollView;
            //scrollView.KeyboardDismissMode = UIScrollViewKeyboardDismissMode.OnDrag;
            //scrollView.ScrollEnabled = true;
            // Set up Navigation Bar
            var saveButton = new UIBarButtonItem (UIBarButtonSystemItem.Save, save);
            var cancelButton = new UIBarButtonItem (UIBarButtonSystemItem.Cancel, cancel);
            NavigationItem.Title = "New Medication:";
            NavigationItem.RightBarButtonItem = saveButton;
            NavigationItem.HidesBackButton = true;
            NavigationItem.LeftBarButtonItem = cancelButton;

            //NSNotificationCenter.DefaultCenter.AddObserver (this, new ObjCRuntime.Selector("keyboardDidAppear:"), UIKeyboard.DidShowNotification, null);
            //NSNotificationCenter.DefaultCenter.AddObserver (this, new ObjCRuntime.Selector ("keyboardWillDissapear:"), UIKeyboard.WillHideNotification, null);

            // Set up the date formatter
            dateFormat = new NSDateFormatter();
            dateFormat.DateStyle = NSDateFormatterStyle.None;
            dateFormat.TimeStyle = NSDateFormatterStyle.Short;

            // Set up new pet form
            nameField = new UITextField();
            nameField.Text = "Medication Name";
            nameField.BorderStyle = UITextBorderStyle.RoundedRect;
            nameField.ReturnKeyType = UIReturnKeyType.Done;

            medTypeLabel = new UILabel ();
            medTypeLabel.Text = "Type of Medication";
            medTypeButton = new UIButton (UIButtonType.RoundedRect);
            medTypeButton.AddTarget (editMedType, UIControlEvent.TouchUpInside);
            medTypeButton.SetTitle ("Pill", UIControlState.Normal);
            medTypeButton.TitleLabel.Font = medTypeButton.TitleLabel.Font.WithSize (medTypeLabel.Font.PointSize);
            medTypePicker = new UIPickerView ();
            medTypePicker.Delegate = new MedTypePickerDelegate (this);
            medTypePicker.DataSource = new MedTypePickerDataSource ();

            freqLabel = new UILabel ();
            freqLabel.Text = "Frequency";
            freqTextField = new UITextField ();
            freqTextField.Text = "1";
            freqTextField.KeyboardType = UIKeyboardType.NumberPad;
            freqTextField.BorderStyle = UITextBorderStyle.RoundedRect;
            freqTextField.Enabled = false;
            freqTextField.AddTarget (freqTextFieldChanged, UIControlEvent.EditingDidEnd | UIControlEvent.EditingDidEndOnExit);
            freqStepper = new UIStepper ();
            freqStepper.Value = 1;
            freqStepper.MinimumValue = 1;
            freqStepper.Enabled = false;
            freqStepper.AddTarget (freqStepperIncremented, UIControlEvent.ValueChanged);
            UIStackView freqStackView = new UIStackView (new UIView[] { freqTextField, freqStepper });
            freqStackView.Spacing = 8;
            freqStackView.Axis = UILayoutConstraintAxis.Horizontal;
            freqButton = new UIButton (UIButtonType.RoundedRect);
            freqButton.SetTitle ("Daily", UIControlState.Normal);
            freqButton.TitleLabel.Font = freqButton.TitleLabel.Font.WithSize (medTypeLabel.Font.PointSize);
            freqButton.AddTarget (editFrequency, UIControlEvent.TouchUpInside);
            freqPicker = new UIPickerView ();
            freqPicker.Delegate = new MedFreqPickerDelegate (this);
            freqPicker.DataSource = new MedFreqPickerDataSource ();

            timePicker = new UIDatePicker ();
            gregorian = new NSCalendar (NSCalendarType.Gregorian);
            timePicker.Date = gregorian.DateBySettingsHour (9, 0, 0, NSDate.Now, NSCalendarOptions.MatchNextTime);
            timePicker.Mode = UIDatePickerMode.Time;
            timePicker.AddTarget (timePickerChanged, UIControlEvent.AllEvents);

            UILabel timeLabel = new UILabel ();
            timeLabel.Text = "Time";
            timeButtons = new UIButton[1];
            timeDates = new NSDate[1];
            timeDates [0] = gregorian.DateBySettingsHour (9, 0, 0, NSDate.Now, NSCalendarOptions.MatchNextTime);
            timeButtons [0] = new UIButton (UIButtonType.RoundedRect);
            timeButtons [0].SetTitle ("9:00 AM", UIControlState.Normal);
            timeButtons [0].AddTarget (openTimePicker, UIControlEvent.TouchUpInside);
            timeStack = new UIStackView ();
            timeStack.Alignment = UIStackViewAlignment.Leading;
            timeStack.Distribution = UIStackViewDistribution.FillProportionally;
            timeStack.Spacing = 5;
            timeStack.Axis = UILayoutConstraintAxis.Vertical;
            timeStack.AddArrangedSubview (timeLabel);
            foreach (var button in timeButtons) {
                timeStack.AddArrangedSubview (button);
            }
            timeStack.AddArrangedSubview (timePicker);
            timePicker.Hidden = true;

            dayLabel = new UILabel ();
            dayLabel.Text = "Day";
            dayLabel.Hidden = true;
            dayButton = new UIButton (UIButtonType.RoundedRect);
            var day = gregorian.GetComponentFromDate (NSCalendarUnit.Weekday, NSDate.Now);
            dayButton.SetTitle (gregorian.WeekdaySymbols[day], UIControlState.Normal);
            dayButton.AddTarget (openDayPicker, UIControlEvent.TouchUpInside);
            dayButton.Hidden = true;
            dayPicker = new UIDatePicker ();
            dayPicker.Mode = UIDatePickerMode.Date;
            dayPicker.MinimumDate = NSDate.Now;
            dayPicker.MaximumDate = NSDate.Now.AddSeconds (604800);
            dayPicker.AddTarget (dayPickerChanged, UIControlEvent.AllEvents);
            dayPicker.Hidden = true;

            prescriptionLengthLabel = new UILabel ();
            prescriptionLengthLabel.Text = "Prescription Length";
            prescriptionLengthTextField = new UITextField ();
            prescriptionLengthTextField.Text = "20";
            prescriptionLengthTextField.AddTarget (prescriptionTextFieldChanged, UIControlEvent.EditingDidEnd | UIControlEvent.EditingDidEndOnExit);
            prescriptionLengthTextField.KeyboardType = UIKeyboardType.NumberPad;
            prescriptionLengthTextField.BorderStyle = UITextBorderStyle.RoundedRect;
            prescriptionLengthStepper = new UIStepper ();
            prescriptionLengthStepper.Value = 20;
            prescriptionLengthStepper.MinimumValue = 1;
            prescriptionLengthStepper.AddTarget (prescriptionStepperIncremented, UIControlEvent.ValueChanged);
            prescriptionDayLabel = new UILabel ();
            prescriptionDayLabel.Text = "Days";
            UIStackView prescriptionStackView = new UIStackView (new UIView[] {
                prescriptionLengthTextField,
                prescriptionLengthStepper,
                prescriptionDayLabel
            });
            prescriptionStackView.Axis = UILayoutConstraintAxis.Horizontal;
            prescriptionStackView.Alignment = UIStackViewAlignment.Leading;
            prescriptionStackView.Distribution = UIStackViewDistribution.FillProportionally;
            prescriptionStackView.Spacing = 5;

            refillsLabel = new UILabel ();
            refillsLabel.Text = "Refills Remaining";
            refillsTextField = new UITextField ();
            refillsTextField.Text = "0";
            refillsTextField.KeyboardType = UIKeyboardType.NumberPad;
            refillsTextField.BorderStyle = UITextBorderStyle.RoundedRect;
            refillsTextField.AddTarget (refillsTextFieldChanged, UIControlEvent.EditingDidEnd | UIControlEvent.EditingDidEndOnExit);
            refillsStepper = new UIStepper ();
            refillsStepper.Value = 0;
            refillsStepper.MinimumValue = 0;
            refillsStepper.AddTarget (refillsStepperIncremented, UIControlEvent.ValueChanged);
            UIStackView refillsStackView = new UIStackView (new UIView[] { refillsTextField, refillsStepper });
            refillsStackView.Spacing = 5;
            refillsStackView.Alignment = UIStackViewAlignment.Leading;
            refillsStackView.Distribution = UIStackViewDistribution.FillProportionally;
            refillsStackView.Axis = UILayoutConstraintAxis.Horizontal;

            pharmacyTextView = new UITextView ();
            pharmacyTextView.Text = "Pharmacy Address";
            pharmacyTextView.ScrollEnabled = false;
            pharmacyTextView.BackgroundColor = UIColor.LightGray;
            pharmacyTextField = new UITextField ();
            pharmacyTextField.Text = "Pharmacy Address";
            pharmacyTextField.BorderStyle = UITextBorderStyle.RoundedRect;

            // Sets up the stackview
            stackView.Spacing = 5;
            stackView.Alignment = UIStackViewAlignment.Leading;
            stackView.Distribution = UIStackViewDistribution.EqualSpacing;
            stackView.AddArrangedSubview (nameField);
            UIView spaceView = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER));
            spaceView.AddConstraint (NSLayoutConstraint.Create (spaceView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER));
            stackView.AddArrangedSubview (spaceView);
            stackView.AddArrangedSubview (medTypeLabel);
            stackView.AddArrangedSubview (medTypeButton);
            stackView.AddArrangedSubview (medTypePicker);
            medTypePicker.Hidden = true;
            UIView spaceView2 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER));
            spaceView2.AddConstraint (NSLayoutConstraint.Create (spaceView2, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER));
            stackView.AddArrangedSubview (spaceView2);
            stackView.AddArrangedSubview (freqLabel);
            stackView.AddArrangedSubview (freqStackView);
            stackView.AddArrangedSubview (freqButton);
            stackView.AddArrangedSubview (freqPicker);
            freqPicker.Hidden = true;
            UIView spaceView3 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER));
            spaceView3.AddConstraint (NSLayoutConstraint.Create (spaceView3, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER));
            stackView.AddArrangedSubview (spaceView3);
            stackView.AddArrangedSubview (timeStack);
            stackView.AddArrangedSubview (dayLabel);
            stackView.AddArrangedSubview (dayButton);
            stackView.AddArrangedSubview (dayPicker);
            UIView spaceView4 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER));
            spaceView4.AddConstraint (NSLayoutConstraint.Create (spaceView4, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER));
            stackView.AddArrangedSubview (spaceView4);
            stackView.AddArrangedSubview (prescriptionLengthLabel);
            stackView.AddArrangedSubview (prescriptionStackView);
            UIView spaceView5 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER));
            spaceView5.AddConstraint (NSLayoutConstraint.Create (spaceView5, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER));
            stackView.AddArrangedSubview (spaceView5);
            stackView.AddArrangedSubview (refillsLabel);
            stackView.AddArrangedSubview (refillsStackView);
            UIView spaceView6 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER));
            spaceView6.AddConstraint (NSLayoutConstraint.Create (spaceView6, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER));
            stackView.AddArrangedSubview (spaceView6);
            stackView.AddArrangedSubview (pharmacyTextField);
            UIView spaceView7 = new UIView (CoreGraphics.CGRect.FromLTRB (0, 0, 50, SECTION_SPACER));
            spaceView7.AddConstraint (NSLayoutConstraint.Create (spaceView7, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, SECTION_SPACER));
            stackView.AddArrangedSubview (spaceView7);
        }
コード例 #13
0
        public override void OnViewModelLoadedOverride()
        {
            AddTopSectionDivider();

            AddSpacing(8);
            var label = new UILabel()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Text  = "Your online account's username or password has changed. Please log back in to continue using your online account.",
                Lines = 0
            };

            StackView.AddArrangedSubview(label);
            label.StretchWidth(StackView, left: 16, right: 16);
            AddSpacing(8);

            AddDivider();

            _errorContainer = new BareUIVisibilityContainer()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                IsVisible = false
            };
            {
                var stackViewIncorrect = new UIStackView()
                {
                    Axis = UILayoutConstraintAxis.Vertical
                };
                stackViewIncorrect.AddArrangedSubview(new UIView()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false
                }.SetHeight(8));
                _labelError = new UILabel()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    Text      = "Error",
                    Lines     = 0,
                    TextColor = UIColor.Red
                };
                stackViewIncorrect.AddArrangedSubview(_labelError);
                _labelError.StretchWidth(stackViewIncorrect, left: 16, right: 16);
                stackViewIncorrect.AddArrangedSubview(new UIView()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false
                }.SetHeight(8));

                AddDivider(stackViewIncorrect);

                _errorContainer.Child = stackViewIncorrect;
            }
            StackView.AddArrangedSubview(_errorContainer);
            _errorContainer.StretchWidth(StackView);

            var textFieldUsername = new UITextField()
            {
                Placeholder            = "Username",
                AutocapitalizationType = UITextAutocapitalizationType.None,
                AutocorrectionType     = UITextAutocorrectionType.No,
                KeyboardType           = UIKeyboardType.ASCIICapable,
                ReturnKeyType          = UIReturnKeyType.Next
            };

            textFieldUsername.AddTarget(new WeakEventHandler <EventArgs>(delegate
            {
                _errorContainer.IsVisible = false;
            }).Handler, UIControlEvent.EditingChanged);
            AddTextField(textFieldUsername, nameof(ViewModel.Username));

            AddDivider();

            var textFieldPassword = new UITextField()
            {
                Placeholder     = "Password",
                SecureTextEntry = true,
                ReturnKeyType   = UIReturnKeyType.Done
            };

            textFieldPassword.AddTarget(new WeakEventHandler <EventArgs>(delegate
            {
                _errorContainer.IsVisible = false;
            }).Handler, UIControlEvent.EditingChanged);
            AddTextField(textFieldPassword, nameof(ViewModel.Password), firstResponder: true);

            AddSectionDivider();

            var buttonLogin = new UIButton(UIButtonType.System)
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            buttonLogin.TouchUpInside += new WeakEventHandler <EventArgs>(delegate { ViewModel.LogIn(); }).Handler;
            buttonLogin.SetTitle("Log In", UIControlState.Normal);
            StackView.AddArrangedSubview(buttonLogin);
            buttonLogin.StretchWidth(StackView);
            buttonLogin.SetHeight(44);

            AddDivider(fullWidth: true);

            var forgotViews = new UIView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                BackgroundColor = ColorResources.InputSectionDividers
            };

            {
                var leftSpacer = new UIView()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false
                };
                forgotViews.Add(leftSpacer);
                var rightSpacer = new UIView()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false
                };
                forgotViews.Add(rightSpacer);

                var buttonForgotUsername = new UIButton(UIButtonType.System)
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    HorizontalAlignment = UIControlContentHorizontalAlignment.Right,
                    Font = UIFont.PreferredCaption1
                };
                buttonForgotUsername.TouchUpInside += new WeakEventHandler(delegate { ViewModel.ForgotUsername(); }).Handler;
                buttonForgotUsername.SetTitle("Forgot Username", UIControlState.Normal);
                forgotViews.Add(buttonForgotUsername);
                buttonForgotUsername.StretchHeight(forgotViews);

                var verticalDivider = new UIView()
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    BackgroundColor = UIColor.FromWhiteAlpha(0.7f, 1)
                };
                forgotViews.Add(verticalDivider);
                verticalDivider.StretchHeight(forgotViews, top: 16, bottom: 16);

                var buttonForgotPassword = new UIButton(UIButtonType.System)
                {
                    TranslatesAutoresizingMaskIntoConstraints = false,
                    HorizontalAlignment = UIControlContentHorizontalAlignment.Left,
                    Font = UIFont.PreferredCaption1
                };
                buttonForgotPassword.TouchUpInside += new WeakEventHandler(delegate { ViewModel.ForgotPassword(); }).Handler;
                buttonForgotPassword.SetTitle("Forgot Password", UIControlState.Normal);
                forgotViews.Add(buttonForgotPassword);
                buttonForgotPassword.StretchHeight(forgotViews);

                forgotViews.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|[leftSpacer][forgotUsername]-8-[verticalDivider(1)]-8-[forgotPassword][rightSpacer(==leftSpacer)]|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary(
                                                                                   "forgotUsername", buttonForgotUsername,
                                                                                   "verticalDivider", verticalDivider,
                                                                                   "forgotPassword", buttonForgotPassword,
                                                                                   "leftSpacer", leftSpacer,
                                                                                   "rightSpacer", rightSpacer)));
            }
            StackView.AddArrangedSubview(forgotViews);
            forgotViews.StretchWidth(StackView);
            forgotViews.SetHeight(44);

            BindingHost.SetBinding(nameof(ViewModel.Error), delegate
            {
                if (string.IsNullOrWhiteSpace(ViewModel.Error))
                {
                    _errorContainer.IsVisible = false;
                }
                else
                {
                    _errorContainer.IsVisible = true;
                    _labelError.Text          = ViewModel.Error;
                }
            });

            BindingHost.SetBinding(nameof(ViewModel.IsLoggingIn), delegate
            {
                IsLoadingOverlayVisible = ViewModel.IsLoggingIn;
            });

            base.OnViewModelLoadedOverride();
        }
コード例 #14
0
		protected virtual void PrepareEntry(UITableView tableview){
			SizeF size = _computeEntryPosition(tableview);
			
			_entry = new UITextField (new RectangleF (size.Width+10, (ContentView.Bounds.Height-size.Height)/2-1, 320-size.Width, size.Height));
			
			TextLabel.BackgroundColor = UIColor.Clear;
			_entry.AutoresizingMask = UIViewAutoresizing.FlexibleWidth |
				UIViewAutoresizing.FlexibleLeftMargin;
			
			_entry.ValueChanged += delegate {
				if (_element != null)
					_element.Value = _entry.Text;
			};
			_entry.Ended += delegate {
				if (_element != null)
					_element.Value = _entry.Text;
			};
			
			_entry.AddTarget((object o, EventArgs r)=>{
				if (_element != null)
					_element.Value = _entry.Text;
				}, UIControlEvent.EditingChanged);
				
			_entry.ShouldReturn += delegate {
				Element elementToFocusOn = null;
				
				foreach (var c in ((Section)_element.Parent).Elements){
					if (c == _element)
						elementToFocusOn = c;
					else if (elementToFocusOn != null && c is EntryElement)
						elementToFocusOn = c as EntryElement;
				}
				if (elementToFocusOn != _element && elementToFocusOn!=null) {
                    var index = elementToFocusOn.GetIndexPath();
					var cell = tableview.CellAt(index);
                    tableview.ScrollToRow(index, UITableViewScrollPosition.Bottom, true);
					cell.BecomeFirstResponder();
				}
				else 
					_entry.ResignFirstResponder();

                if (_entry.ReturnKeyType == UIReturnKeyType.Go) {
                    _element.FireGo(this, EventArgs.Empty);
                }

				return true;
			};
			_entry.Started += delegate {
				EntryElement self = null;
				var returnType = _element.ReturnKeyType;

                if (returnType != UIReturnKeyType.Default) {
                    foreach (var e in (_element.Parent as Section).Elements){
                        if (e == _element)
                            self = _element;
                        else if (self != null && e is EntryElement)
                            returnType = UIReturnKeyType.Next;
                    }
                }
                _entry.ReturnKeyType = returnType;
			};
				
			ContentView.AddSubview (_entry);
		}
コード例 #15
0
        public void 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?.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;

                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);
                }
            });

            var app = UIApplication.SharedApplication;

            app.InvokeOnMainThread(() =>
            {
                var top = UIApplication.SharedApplication.GetTopViewController();
                if (dlg.PreferredStyle == UIAlertControllerStyle.ActionSheet && UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                {
                    var x    = top.View.Bounds.Width;
                    var y    = top.View.Bounds.Bottom;
                    var rect = new CGRect(x, y, 0, 0);

                    dlg.PopoverPresentationController.SourceView = top.View;
                    dlg.PopoverPresentationController.SourceRect = rect;
                    dlg.PopoverPresentationController.PermittedArrowDirections = UIPopoverArrowDirection.Unknown;
                }
                top.PresentViewController(dlg, true, null);
            });
            //return new DisposableAction(() =>
            //{
            //    try
            //    {
            //        app.InvokeOnMainThread(() => dlg.DismissViewController(true, null));
            //    }
            //    catch { }
            //});
        }