Esempio n. 1
0
        IndexedPosition GetPosition(UITextRange range, UITextLayoutDirection direction)
        {
            // Note that this sample assumes LTR text direction
            IndexedRange r   = (IndexedRange)range;
            int          pos = r.Range.Location;

            // For this sample, we just return the extent of the given range if the
            // given direction is "forward" in a LTR context (UITextLayoutDirectionRight
            // or UITextLayoutDirectionDown), otherwise we return just the range position
            switch (direction)
            {
            case UITextLayoutDirection.Up:
            case UITextLayoutDirection.Left:
                pos = r.Range.Location;
                break;

            case UITextLayoutDirection.Right:
            case UITextLayoutDirection.Down:
                pos = r.Range.Location + r.Range.Length;
                break;
            }

            // Return text position using our UITextPosition implementation.
            // Note that position is not currently checked against document range.
            return(IndexedPosition.GetPosition(pos));
        }
Esempio n. 2
0
 public (int, int) GetSelection()
 {
     if (editText == null)
     {
         return(0, 0);
     }
     if (NSThread.IsMain)
     {
         UITextRange selectedRange = editText.SelectedTextRange;
         if (selectedRange == null)
         {
             return(0, 0);
         }
         else
         {
             int start = (int)editText.GetOffsetFromPosition(editText.BeginningOfDocument, selectedRange.Start);
             int end   = (int)editText.GetOffsetFromPosition(editText.BeginningOfDocument, selectedRange.End);
             return(start, end);
         }
     }
     else
     {
         return(BeginInvokeOnMainThreadAsync(() => { return GetSelection(); }).Result);
     }
 }
Esempio n. 3
0
        void ReplaceRange(UITextRange range, string text)
        {
            IndexedRange r = (IndexedRange)range;
            NSRange      selectedNSRange = textView.SelectedTextRange;

            // Determine if replaced range intersects current selection range
            // and update selection range if so.
            if (r.Range.Location + r.Range.Length <= selectedNSRange.Location)
            {
                // This is the easy case.
                selectedNSRange.Location -= (r.Range.Length - text.Length);
            }
            else
            {
                // Need to also deal with overlapping ranges.  Not addressed
                // in this simplified sample.
            }

            // Now replace characters in text storage
            this.text.Remove(r.Range.Location, r.Range.Length);
            this.text.Insert(r.Range.Location, text);

            // Update underlying SimpleCoreTextView
            textView.Text = this.text.ToString();
            textView.SelectedTextRange = selectedNSRange;
        }
Esempio n. 4
0
        public override void Presented(UIAlertView alertView)
        {
            UITextRange textRange = alertView.GetTextField(0).SelectedTextRange;

            alertView.GetTextField(0).SelectAll(null);
            alertView.GetTextField(0).SelectedTextRange = textRange;
        }
Esempio n. 5
0
        public bool ShouldChangeTextWithReplacementText(UITextView textView, NSRange range, string text)
        {
            if (text != "\n")
            {
                return(true);
            }

            // Get the replacement range of the UITextView
            UITextPosition beginning = BeginningOfDocument;
            UITextPosition start     = GetPosition(beginning, range.Location);
            UITextPosition end       = GetPosition(start, range.Length);
            UITextRange    textRange = GetTextRange(start, end);

            string sufix = FindIdentationPrefixWithRange(start);

            if (string.IsNullOrEmpty(sufix))
            {
                return(true);
            }

            string identation = "\n" + sufix;

            // Insert that newline character *and* a tab
            // at the point at which the user inputted just the
            // newline character
            ReplaceText(textRange, identation);

            // Update the cursor position accordingly
            NSRange cursor = new NSRange(range.Location + identation.Length, 0);

            SelectedRange = cursor;
            return(false);
        }
        public override bool ShouldChangeTextInRange(UITextRange inRange, string replacementText)
        {
            if (replacementText.Equals("\n"))
            {
                this.ResignFirstResponder();
            }

            return(base.ShouldChangeTextInRange(inRange, replacementText));
        }
Esempio n. 7
0
        RectangleF FirstRect(UITextRange range)
        {
            // FIXME: the Objective-C code doesn't get a null range
            // This is the reason why we don't get the autocorrection suggestions
            // (it'll just autocorrect without showing any suggestions).
            // Possibly due to http://bugzilla.xamarin.com/show_bug.cgi?id=265
            IndexedRange r = (IndexedRange)(range ?? IndexedRange.GetRange(new NSRange(0, 1)));
            // Use underlying SimpleCoreTextView to get rect for range
            RectangleF rect = textView.FirstRect(r.Range);

            // Convert rect to our view coordinates
            return(ConvertRectFromView(rect, textView));
        }
		RectangleF FirstRect (UITextRange range)
		{
			// FIXME: the Objective-C code doesn't get a null range
			// This is the reason why we don't get the autocorrection suggestions
			// (it'll just autocorrect without showing any suggestions).
			// Possibly due to http://bugzilla.xamarin.com/show_bug.cgi?id=265
			IndexedRange r = (IndexedRange) (range ?? IndexedRange.GetRange (new NSRange (0, 1)));
			// Use underlying SimpleCoreTextView to get rect for range
			RectangleF rect = textView.FirstRect (r.Range);
			// Convert rect to our view coordinates
			return ConvertRectFromView (rect, textView);
		}
		void SetBaseWritingDirection (UITextWritingDirection writingDirection, UITextRange range)
		{
			// This sample assumes LTR text direction and does not currently support BiDi or RTL.
		}
		IndexedPosition GetPosition (UITextRange range, UITextLayoutDirection direction)
		{
			// Note that this sample assumes LTR text direction
			IndexedRange r = (IndexedRange) range;
			int pos = r.Range.Location;
			
			// For this sample, we just return the extent of the given range if the
			// given direction is "forward" in a LTR context (UITextLayoutDirectionRight
			// or UITextLayoutDirectionDown), otherwise we return just the range position
			switch (direction) {
			case UITextLayoutDirection.Up:
			case UITextLayoutDirection.Left:
				pos = r.Range.Location;
				break;
			case UITextLayoutDirection.Right:
			case UITextLayoutDirection.Down:
				pos = r.Range.Location + r.Range.Length;
				break;
			}
			
			// Return text position using our UITextPosition implementation.
			// Note that position is not currently checked against document range.
			return IndexedPosition.GetPosition (pos);
		}
		void ReplaceRange (UITextRange range, string text)
		{
			IndexedRange r = (IndexedRange) range;
			NSRange selectedNSRange = textView.SelectedTextRange;
			// Determine if replaced range intersects current selection range
			// and update selection range if so.
			if (r.Range.Location + r.Range.Length <= selectedNSRange.Location) {
				// This is the easy case. 
				selectedNSRange.Location -= (r.Range.Length - text.Length);
			} else {
				// Need to also deal with overlapping ranges.  Not addressed
				// in this simplified sample.
			}
			
			// Now replace characters in text storage
			this.text.Remove (r.Range.Location, r.Range.Length);
			this.text.Insert (r.Range.Location, text);
			
			// Update underlying SimpleCoreTextView
			textView.Text = this.text.ToString ();
			textView.SelectedTextRange = selectedNSRange;
		}
		string TextInRange (UITextRange range)
		{
			IndexedRange r = (IndexedRange) range;
			return text.ToString ().Substring (r.Range.Location, r.Range.Length);
		}
Esempio n. 13
0
 public void Select(int start, int length)
 => SelectedTextRange = this.GetTextRange(start: start, end: start + length);
Esempio n. 14
0
 UITextPosition ClosestPosition(PointF point, UITextRange range)
 {
     // Not implemented in this sample.  Could utilize underlying
     // SimpleCoreTextView:closestIndexToPoint:point
     return(null);
 }
 // Remove selection
 public override UITextSelectionRect[] GetSelectionRects(UITextRange range)
 {
     return(null);
 }
Esempio n. 16
0
 string TextInRange(UITextRange range)
 {
     throw new NotImplementedException();
 }
		UITextPosition ClosestPosition (PointF point, UITextRange range)
		{
			// Not implemented in this sample.  Could utilize underlying 
			// SimpleCoreTextView:closestIndexToPoint:point
			return null;
		}
Esempio n. 18
0
        string TextInRange(UITextRange range)
        {
            IndexedRange r = (IndexedRange)range;

            return(text.ToString().Substring(r.Range.Location, r.Range.Length));
        }
Esempio n. 19
0
 UITextPosition ClosestPosition(PointF point, UITextRange range)
 {
     return(null);
 }
Esempio n. 20
0
 RectangleF FirstRect(UITextRange range)
 {
     throw new NotImplementedException();
 }
Esempio n. 21
0
 IndexedPosition GetPosition(UITextRange range, UITextLayoutDirection direction)
 {
     throw new NotImplementedException();
 }
Esempio n. 22
0
 void ReplaceRange(UITextRange range, string text)
 {
     throw new NotImplementedException();
 }
Esempio n. 23
0
 void SetBaseWritingDirection(UITextWritingDirection writingDirection, UITextRange range)
 {
     // This sample assumes LTR text direction and does not currently support BiDi or RTL.
 }
Esempio n. 24
0
        void SetupPlaceViews()
        {
            ccText.Text = "11112222333344445555";

            UITextPosition start     = ccText.BeginningOfDocument;
            UITextPosition end       = ccText.GetPosition(start, 20);
            UITextRange    range     = ccText.GetTextRange(start, end);
            RectangleF     r         = ccText.GetFirstRectForRange(range);
            SizeF          frameRect = r.Size;

            frameRect.Width = (r.Size.Width / 24.0f);
            ccText.Font     = JudoSDKManager.FIXED_WIDTH_FONT_SIZE_20;
            r.Size          = frameRect;
            ccText.Text     = "";


            RectangleF frame = ccPlaceHolder.Frame;

            ccPlaceHolder.Font = JudoSDKManager.FIXED_WIDTH_FONT_SIZE_20;
            ccPlaceHolder.Text = "0000 0000 0000 0000";

            ccPlaceHolder.SetShowTextOffSet(0);
            ccPlaceHolder.Offset = r;

            ccPlaceHolder.BackgroundColor = UIColor.Clear;
            textScroller.InsertSubview(ccPlaceHolder, 0);

            /////////

            expiryText.Text = "MM/YY";

            UITextPosition exStart     = expiryText.BeginningOfDocument;
            UITextPosition exEnd       = expiryText.GetPosition(exStart, 5);
            UITextRange    exRange     = expiryText.GetTextRange(exStart, exEnd);
            RectangleF     exR         = expiryText.GetFirstRectForRange(exRange);
            SizeF          exFrameRect = exR.Size;

            exFrameRect.Width = (exR.Size.Width / 24.0f);
            expiryText.Font   = JudoSDKManager.FIXED_WIDTH_FONT_SIZE_20;
            exR.Size          = exFrameRect;
            expiryText.Text   = "";



            RectangleF expiryFrame = expiryPlaceHolder.Frame;

            expiryPlaceHolder.Font = expiryText.Font;
            expiryPlaceHolder.Text = "MM/YY";

            expiryPlaceHolder.SetShowTextOffSet(0);
            expiryPlaceHolder.Offset = exR;

            expiryPlaceHolder.BackgroundColor = UIColor.Clear;
            textScroller.InsertSubview(expiryPlaceHolder, 1);

            ////

            cvTwoText.Text = "CV2";

            UITextPosition cvStart     = cvTwoText.BeginningOfDocument;
            UITextPosition cvEnd       = cvTwoText.GetPosition(cvStart, 3);
            UITextRange    cvRange     = cvTwoText.GetTextRange(cvStart, cvEnd);
            RectangleF     cvR         = cvTwoText.GetFirstRectForRange(cvRange);
            SizeF          cvFrameRect = cvR.Size;

            cvFrameRect.Width = (cvR.Size.Width / 24.0f);
            cvTwoText.Font    = JudoSDKManager.FIXED_WIDTH_FONT_SIZE_20;
            cvR.Size          = cvFrameRect;
            cvTwoText.Text    = "";

            RectangleF cvTwoFrame = cvTwoPlaceHolder.Frame;

            cvTwoPlaceHolder.Font = cvTwoText.Font;
            cvTwoPlaceHolder.Text = "CV2";

            cvTwoPlaceHolder.SetShowTextOffSet(0);
            cvTwoPlaceHolder.Offset = cvR;

            cvTwoPlaceHolder.BackgroundColor = UIColor.Clear;
            textScroller.InsertSubview(cvTwoPlaceHolder, 2);
        }