Example #1
0
        public override bool ShouldChangeCharacters(UITextField textField, Foundation.NSRange range, string replacementString)
        {
            NSString original    = NSObject.FromObject(textField.Text) as NSString;
            NSString replacement = NSObject.FromObject(replacementString) as NSString;
            NSString updated     = original.Replace(range, replacement);

            var result = Validator.ValidateFloat(updated);

            return(result == Validator.ValidationResult.Intermediate || result == Validator.ValidationResult.Valid);
        }
Example #2
0
 // requested in http://bugzilla.xamarin.com/show_bug.cgi?id=1870
 public void Replace_Range()
 {
     using (NSString s1 = new NSString("Sebastien"))
         using (NSString s2 = new NSString("é"))
             using (NSString s3 = new NSString("sébastien"))
                 using (NSString result = s1.Replace(new NSRange(1, 1), s2))
                 {
                     NSStringCompareOptions options = NSStringCompareOptions.CaseInsensitiveSearch;
                     Assert.That(result.Compare(s3, options),
                                 Is.EqualTo(NSComparisonResult.Same), "Replace");
                 }
 }
        bool ActionChangeSliderValue(UITextField textField, NSRange range, string replacementString)
        {
            int      maxValue = 0;
            UISlider seekBar  = null;

            switch (textField.Tag)
            {
            case 0:
                maxValue = 360;
                seekBar  = seekTime;
                break;

            case 1:
                maxValue = 250;
                seekBar  = seekDistance;
                break;

            case 2:
                maxValue = 400;
                seekBar  = seekTSS;
                break;
            }

            string newValue = "";

            using (NSString original = new NSString(textField.Text), replace = new NSString(replacementString.ToUpper()))
            {
                newValue = original.Replace(range, replace);
            }
            var nValue = newValue == "" ? 0 : float.Parse(newValue);

            if (nValue >= 0 && nValue <= maxValue)
            {
                seekBar.Value  = nValue;
                textField.Text = newValue;
            }
            return(false);
        }
		bool ShouldChangeCharacters (UITextField textField, NSRange range, string replacementString)
		{
			bool hasInvalidChars = replacementString.ToCharArray ().Any (c => !IsValidMorseCharacter (c));
		
			if (hasInvalidChars)
			{
				UIView.Animate (0.2f, 0f, UIViewAnimationOptions.Autoreverse,
					() => this.txtMorse.BackgroundColor = UIColor.Red,
					() => this.txtMorse.BackgroundColor = UIColor.White);

				return false;
			}

			// Morse only has uppercase characters.
			replacementString = replacementString.ToUpperInvariant ();
			var nativeString = new NSString (this.txtMorse.Text);
			this.txtMorse.Text = nativeString.Replace (range, new NSString (replacementString));

			// Remember last message.
			CrossSettings.Current.AddOrUpdateValue (SETTING_LAST_MESSAGE, this.txtMorse.Text);

			// Return FALSE because we update the content ourselves (uppercasing everything).
			return false;
		}
Example #5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor    = UIColor.FromPatternImage(UIImage.FromFile("Assets/background.png"));
            lblRefineAddress.Font   = AppStyle.NormalTextFont;
            lblRefineAddress.Text   = Localize.GetValue("StreetNumberLabel");
            lblStreetName.Font      = AppStyle.BoldTextFont;
            lblStreetName.TextColor = AppStyle.DarkText;
            AppButtons.FormatStandardButton((GradientButton)btnSearch, Localize.GetValue("StreetNumberSearchBt"), AppStyle.ButtonColor.Grey, "Assets/Search/SearchIcon.png", "Assets/Cells/rightArrow.png");
            AppButtons.FormatStandardButton(btnPlaces, Localize.GetValue("StreetNumberPlacesBt"), AppStyle.ButtonColor.Grey, "Assets/Search/SearchPlace.png", "Assets/Cells/rightArrow.png");

            AppButtons.FormatStandardButton(btnClear, Localize.GetValue("DeleteAddressBt"), AppStyle.ButtonColor.Red, "Assets/Search/cancel.png");

            btnSearch.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
            btnPlaces.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
            btnClear.HorizontalAlignment  = UIControlContentHorizontalAlignment.Left;

            txtStreetNumber.ShouldReturn = delegate {
                txtStreetNumber.ResignFirstResponder();
                return(true);
            };


            txtStreetNumber.ShouldChangeCharacters = (textField, range, replacementString) =>
            {
                using (NSString original = new NSString(textField.Text), replace = new NSString(replacementString.ToUpper()))
                {
                    return(original.Replace(range, replace).Length <= ViewModel.NumberOfCharAllowed);
                }
                //return false;
            };

            var button = new UIBarButtonItem(Localize.GetValue("Done"), UIBarButtonItemStyle.Plain, delegate
            {
                ViewModel.SaveCommand.Execute();
            });

            NavigationItem.RightBarButtonItem = button;

            var set = this.CreateBindingSet <BookStreetNumberView, BookStreetNumberViewModel>();

            set.Bind(txtStreetNumber)
            .For(v => v.Text)
            .To(vm => vm.StreetNumberOrBuildingName);

            set.Bind(lblStreetName)
            .For(v => v.Text)
            .To(vm => vm.StreetCity);

            set.Bind(btnPlaces)
            .For("TouchUpInside")
            .To(vm => vm.NavigateToPlaces);

            set.Bind(btnClear)
            .For("TouchUpInside")
            .To(vm => vm.DeleteAddressCommand);

            set.Bind(btnSearch)
            .For("TouchUpInside")
            .To(vm => vm.NavigateToSearch);

            set.Apply();

            ViewModel.OnViewLoaded();
            View.ApplyAppFont();
        }
Example #6
0
        protected virtual void PrepareEntry(UITableView tableview)
        {
            SizeF size = _computeEntryPosition(tableview);

            _entry          = new CustomTextField(new RectangleF(size.Width + 10, (ContentView.Bounds.Height - size.Height) / 2 - 10, 320 - size.Width - 20, size.Height + 20));
            _delegate       = new CustomTextFieldDelegate();
            _entry.Delegate = _delegate;

            _entry.VerticalAlignment = UIControlContentVerticalAlignment.Center;

            TextLabel.BackgroundColor = UIColor.Clear;
            _entry.AutoresizingMask   = UIViewAutoresizing.FlexibleWidth |
                                        UIViewAutoresizing.FlexibleLeftMargin;

            _entry.MaxCharacters = 5;

            _entry.Started += delegate {
                var position = tableview.IndexPathForCell(this);
                tableview.SelectRow(position, false, UITableViewScrollPosition.None);
            };

            _entry.ValueChanged += delegate {
                if (_element != null)
                {
                    _element.Value = _entry.Text;
                }
            };
            _entry.EnablesReturnKeyAutomatically = true;
            _entry.Ended += (object sender, EventArgs e) => {
                if (_element != null)
                {
                    _element.Value = _entry.Text;

                    if (_element.OnValueChanged != null)
                    {
                        _element.OnValueChanged(_element);
                    }
                }

                var position = tableview.IndexPathForCell(this);
                if (tableview.IndexPathForSelectedRow != null && position != null && position.Compare(tableview.IndexPathForSelectedRow) == 0)
                {
                    tableview.DeselectRow(position, false);
                }
            };
            _entry.ShouldChangeCharacters = (textField, range, replacement) =>
            {
                if (_element.MaxLength < 0)
                {
                    return(true);
                }
                if (_element.MaxLength == 0)
                {
                    return(false);
                }
                using (NSString original = new NSString(textField.Text))
                {
                    var replace = original.Replace(range, new NSString(replacement));
                    if (replace.Length > _element.MaxLength)
                    {
                        return(false);
                    }
                }
                return(true);
            };

            _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 cell = tableview.CellAt(elementToFocusOn.GetIndexPath());
                    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);
        }
Example #7
0
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            UITableViewCell cell = tableView.DequeueReusableCell(cellIdentifier);

            if (cell == null)
            {
                cell = new UITableViewCell(UITableViewCellStyle.Default, cellIdentifier);
            }

            var profileImageView       = new UIImageView();
            var editProfileImageButton = new UIButton();

            if (indexPath.Row == 0)
            {
                var picturesize = 250;
                profileImageView.Layer.CornerRadius  = 125;
                profileImageView.Layer.BorderWidth   = 1;
                profileImageView.Layer.MasksToBounds = true;
                profileImageView.Layer.BorderColor   = UIColor.Clear.CGColor;
                profileImageView.ContentMode         = UIViewContentMode.ScaleAspectFill;
                profileImageView.TintColor           = UIColor.FromRGB(198, 123, 112);
                profileImageView.Frame = new CGRect((UIScreen.MainScreen.Bounds.Size.Width - picturesize) / 2, (tableView.RowHeight - picturesize) / 2, picturesize, picturesize);
                if (profileImage == null)
                {
                    profileImageView.Image = UIImage.FromBundle("ProfileEmptyIcon").ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
                }
                else
                {
                    profileImageView.Image = profileImage;
                }

                editProfileImageButton.Frame          = new CGRect(profileImageView.Frame.Location, profileImageView.Frame.Size);
                editProfileImageButton.TouchUpInside += (sender, e) => viewController.EditAvatar();
            }

            var labelLeft      = new UILabel();
            var textFieldRight = new UITextField();

            if (indexPath.Row > 0)
            {
                int    leftBorder  = 15;
                int    rightBorder = 25;
                int    spaceBetweenLabelAndTextField = 20;
                nfloat height = (tableView.RowHeight - spaceBetweenLabelAndTextField * 2) / 2;

                labelLeft.Frame      = new CGRect(leftBorder, spaceBetweenLabelAndTextField, UIScreen.MainScreen.Bounds.Size.Width - rightBorder, height);
                textFieldRight.Frame = new CGRect(leftBorder, labelLeft.Frame.Height + spaceBetweenLabelAndTextField, UIScreen.MainScreen.Bounds.Size.Width - rightBorder, height);

                labelLeft.Font = UIFont.SystemFontOfSize(16, UIFontWeight.Regular);

                textFieldRight.Font                      = UIFont.SystemFontOfSize(18, UIFontWeight.Light);
                textFieldRight.ClearButtonMode           = UITextFieldViewMode.Always;
                textFieldRight.AdjustsFontSizeToFitWidth = true;
                textFieldRight.TextAlignment             = UITextAlignment.Left;
                textFieldRight.AttributedPlaceholder     = new NSAttributedString("Enter a new " + userProfileLabels[indexPath.Row - 1], foregroundColor: UIColor.Gray, font: UIFont.SystemFontOfSize(18, UIFontWeight.UltraLight));

                labelLeft.Text      = userProfileLabels[indexPath.Row - 1];
                textFieldRight.Text = userItems[indexPath.Row - 1];

                if (labelLeft.Text == "Email")
                {
                    textFieldRight.KeyboardType           = UIKeyboardType.EmailAddress;
                    textFieldRight.AutocapitalizationType = UITextAutocapitalizationType.None;
                }

                if (labelLeft.Text == "Password")
                {
                    textFieldRight.SecureTextEntry = true;
                }

                textFieldRight.ShouldChangeCharacters = (textField, range, replacementString) =>
                {
                    using (NSString original = new NSString(textField.Text), replace = new NSString(replacementString))
                    {
                        userItems[indexPath.Row - 1] = original.Replace(range, replace);
                        textField.Text = userItems[indexPath.Row - 1];

                        // Sharing data with EditProfileViewController
                        EditProfileSharedData.EditedUserInfo[indexPath.Row - 1] = userItems[indexPath.Row - 1];
                    }
                    return(false);
                };

                // Assign empty values after ClearButton was pressed
                textFieldRight.ShouldClear = (textField) =>
                {
                    textField.Text = null;
                    userItems[indexPath.Row - 1] = null;

                    // Sharing data with EditProfileViewController
                    EditProfileSharedData.EditedUserInfo[indexPath.Row - 1] = userItems[indexPath.Row - 1];

                    return(true);
                };

                textFieldRight.ReturnKeyType = UIReturnKeyType.Done;
                textFieldRight.ShouldReturn  = ((textField) =>
                {
                    // Dismiss the Keyboard
                    textFieldRight.ResignFirstResponder();
                    return(true);
                });
            }

            cell.SelectionStyle  = UITableViewCellSelectionStyle.None;
            cell.BackgroundColor = UIColor.Clear;

            cell.ContentView.AddSubviews(profileImageView, editProfileImageButton, labelLeft, textFieldRight);
            //}
            return(cell);
        }
		protected virtual void PrepareEntry(UITableView tableview){
			SizeF size = _computeEntryPosition(tableview);
			
			_entry = new CustomTextField (new RectangleF (size.Width+10, (ContentView.Bounds.Height-size.Height)/2-10, 320-size.Width-20, size.Height+20));
			_delegate = new CustomTextFieldDelegate ();
			_entry.Delegate = _delegate;

			_entry.VerticalAlignment = UIControlContentVerticalAlignment.Center;

			TextLabel.BackgroundColor = UIColor.Clear;
			_entry.AutoresizingMask = UIViewAutoresizing.FlexibleWidth |
				UIViewAutoresizing.FlexibleLeftMargin;

			_entry.MaxCharacters = 5;

			_entry.Started += delegate {
				var position = tableview.IndexPathForCell(this);
				tableview.SelectRow(position, false, UITableViewScrollPosition.None);
			};

			_entry.ValueChanged += delegate {
				if (_element != null) {
					_element.Value = _entry.Text;
				}
			};
			_entry.EnablesReturnKeyAutomatically = true;
			_entry.Ended += (object sender, EventArgs e) => {
				if (_element != null) {
					_element.Value = _entry.Text;
					
					if (_element.OnValueChanged!=null)
						_element.OnValueChanged(_element);
				}
				
				var position = tableview.IndexPathForCell(this);
				if (tableview.IndexPathForSelectedRow!=null && position!=null && position.Compare(tableview.IndexPathForSelectedRow)==0){
					tableview.DeselectRow(position, false);
				}

			};
			_entry.ShouldChangeCharacters = (textField, range, replacement) => 
			{
				if (_element.MaxLength<0) return true;
				if (_element.MaxLength==0) return false;
				using (NSString original = new NSString(textField.Text))
				{
					var replace = original.Replace(range, new NSString(replacement));
					if (replace.Length>_element.MaxLength)
						return false;
				}
				return true;
			};

			_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 cell = tableview.CellAt(elementToFocusOn.GetIndexPath());
					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);
		}