Beispiel #1
0
 public virtual void setDigitsWatcher(android.text.TextWatcher watcher)
 {
     java.lang.CharSequence text = ((android.text.Editable)mDigits.getText());
     android.text.Spannable span = (android.text.Spannable)text;
     span.setSpan(watcher, 0, text.Length, android.text.SpannedClass.SPAN_INCLUSIVE_INCLUSIVE
                  );
 }
Beispiel #2
0
        private static void addParagraphSpan(android.text.Spannable buffer, object what,
                                             int start, int end)
        {
            int len = buffer.Length;

            if (start != 0 && start != len && buffer[start - 1] != '\n')
            {
                for (start--; start > 0; start--)
                {
                    if (buffer[start - 1] == '\n')
                    {
                        break;
                    }
                }
            }
            if (end != 0 && end != len && buffer[end - 1] != '\n')
            {
                for (end++; end < len; end++)
                {
                    if (buffer[end - 1] == '\n')
                    {
                        break;
                    }
                }
            }
            buffer.setSpan(what, start, end, android.text.SpannedClass.SPAN_PARAGRAPH);
        }
Beispiel #3
0
        // private static int pin(int value, int min, int max) {
        //     return value < min ? 0 : (value > max ? max : value);
        // }
        /// <summary>
        /// Set the selection anchor to <code>start</code> and the selection edge
        /// to <code>stop</code>.
        /// </summary>
        /// <remarks>
        /// Set the selection anchor to <code>start</code> and the selection edge
        /// to <code>stop</code>.
        /// </remarks>
        public static void setSelection(android.text.Spannable text, int start, int stop)
        {
            // int len = text.length();
            // start = pin(start, 0, len);  XXX remove unless we really need it
            // stop = pin(stop, 0, len);
            int ostart = getSelectionStart(text);
            int oend   = getSelectionEnd(text);

            if (ostart != start || oend != stop)
            {
                text.setSpan(SELECTION_START, start, start, android.text.SpannedClass.SPAN_POINT_POINT
                             | android.text.SpannedClass.SPAN_INTERMEDIATE);
                text.setSpan(SELECTION_END, stop, stop, android.text.SpannedClass.SPAN_POINT_POINT
                             );
            }
        }
Beispiel #4
0
 /// <summary>Move the selection edge to offset <code>index</code>.</summary>
 /// <remarks>Move the selection edge to offset <code>index</code>.</remarks>
 public static void extendSelection(android.text.Spannable text, int index)
 {
     if (text.getSpanStart(SELECTION_END) != index)
     {
         text.setSpan(SELECTION_END, index, index, android.text.SpannedClass.SPAN_POINT_POINT
                      );
     }
 }
        private static void adjust(android.text.Spannable content, object what)
        {
            int current = content.getSpanFlags(what);

            if (current == PRESSED)
            {
                content.setSpan(what, 0, 0, USED);
            }
            else
            {
                if (current == RELEASED)
                {
                    content.removeSpan(what);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Marks the specified region of <code>content</code> as having
        /// contained <code>original</code> prior to AutoText replacement.
        /// </summary>
        /// <remarks>
        /// Marks the specified region of <code>content</code> as having
        /// contained <code>original</code> prior to AutoText replacement.
        /// Call this method when you have done or are about to do an
        /// AutoText-style replacement on a region of text and want to let
        /// the same mechanism (the user pressing DEL immediately after the
        /// change) undo the replacement.
        /// </remarks>
        /// <param name="content">the Editable text where the replacement was made</param>
        /// <param name="start">the start of the replaced region</param>
        /// <param name="end">the end of the replaced region; the location of the cursor</param>
        /// <param name="original">the text to be restored if the user presses DEL</param>
        public static void markAsReplaced(android.text.Spannable content, int start, int
                                          end, string original)
        {
            android.text.method.QwertyKeyListener.Replaced[] repl = content.getSpans <android.text.method.QwertyKeyListener
                                                                                      .Replaced>(0, content.Length);
            {
                for (int a = 0; a < repl.Length; a++)
                {
                    content.removeSpan(repl[a]);
                }
            }
            int len = original.Length;

            char[] orig = new char[len];
            Sharpen.StringHelper.GetCharsForString(original, 0, len, orig, 0);
            content.setSpan(new android.text.method.QwertyKeyListener.Replaced(orig), start,
                            end, android.text.SpannedClass.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        public override bool onTouchEvent(android.widget.TextView widget, android.text.Spannable
                                          buffer, android.view.MotionEvent @event)
        {
            int initialScrollX = -1;
            int initialScrollY = -1;
            int action         = @event.getAction();

            if (action == android.view.MotionEvent.ACTION_UP)
            {
                initialScrollX = android.text.method.Touch.getInitialScrollX(widget, buffer);
                initialScrollY = android.text.method.Touch.getInitialScrollY(widget, buffer);
            }
            bool handled = android.text.method.Touch.onTouchEvent(widget, buffer, @event);

            if (widget.isFocused() && !widget.didTouchFocusSelect())
            {
                if (action == android.view.MotionEvent.ACTION_DOWN)
                {
                    if (isSelecting(buffer))
                    {
                        int offset = widget.getOffsetForPosition(@event.getX(), @event.getY());
                        buffer.setSpan(LAST_TAP_DOWN, offset, offset, android.text.SpannedClass.SPAN_POINT_POINT
                                       );
                        // Disallow intercepting of the touch events, so that
                        // users can scroll and select at the same time.
                        // without this, users would get booted out of select
                        // mode once the view detected it needed to scroll.
                        widget.getParent().requestDisallowInterceptTouchEvent(true);
                    }
                }
                else
                {
                    if (action == android.view.MotionEvent.ACTION_MOVE)
                    {
                        if (isSelecting(buffer) && handled)
                        {
                            // Before selecting, make sure we've moved out of the "slop".
                            // handled will be true, if we're in select mode AND we're
                            // OUT of the slop
                            // Turn long press off while we're selecting. User needs to
                            // re-tap on the selection to enable long press
                            widget.cancelLongPress();
                            // Update selection as we're moving the selection area.
                            // Get the current touch position
                            int offset = widget.getOffsetForPosition(@event.getX(), @event.getY());
                            android.text.Selection.extendSelection(buffer, offset);
                            return(true);
                        }
                    }
                    else
                    {
                        if (action == android.view.MotionEvent.ACTION_UP)
                        {
                            // If we have scrolled, then the up shouldn't move the cursor,
                            // but we do need to make sure the cursor is still visible at
                            // the current scroll offset to avoid the scroll jumping later
                            // to show it.
                            if ((initialScrollY >= 0 && initialScrollY != widget.getScrollY()) || (initialScrollX
                                                                                                   >= 0 && initialScrollX != widget.getScrollX()))
                            {
                                widget.moveCursorToVisibleOffset();
                                return(true);
                            }
                            int offset = widget.getOffsetForPosition(@event.getX(), @event.getY());
                            if (isSelecting(buffer))
                            {
                                buffer.removeSpan(LAST_TAP_DOWN);
                                android.text.Selection.extendSelection(buffer, offset);
                            }
                            else
                            {
                                if (!widget.shouldIgnoreActionUpEvent())
                                {
                                    android.text.Selection.setSelection(buffer, offset);
                                }
                            }
                            android.text.method.MetaKeyKeyListener.adjustMetaAfterKeypress(buffer);
                            android.text.method.MetaKeyKeyListener.resetLockedMeta(buffer);
                            return(true);
                        }
                    }
                }
            }
            return(handled);
        }
Beispiel #8
0
        /// <summary>
        /// Make a layout for the transformed text (password transformation
        /// being the primary example of a transformation)
        /// that will be updated as the base text is changed.
        /// </summary>
        /// <remarks>
        /// Make a layout for the transformed text (password transformation
        /// being the primary example of a transformation)
        /// that will be updated as the base text is changed.
        /// If ellipsize is non-null, the Layout will ellipsize the text
        /// down to ellipsizedWidth.
        /// *
        /// *@hide
        /// </remarks>
        public DynamicLayout(java.lang.CharSequence @base, java.lang.CharSequence display
                             , android.text.TextPaint paint, int width, android.text.Layout.Alignment?align,
                             android.text.TextDirectionHeuristic textDir, float spacingmult, float spacingadd
                             , bool includepad, android.text.TextUtils.TruncateAt?ellipsize_1, int ellipsizedWidth
                             ) : base((ellipsize_1 == null) ? display : (display is android.text.Spanned) ? new
                                      android.text.Layout.SpannedEllipsizer(display) : new android.text.Layout.Ellipsizer
                                          (display), paint, width, align, textDir, spacingmult, spacingadd)
        {
            mBase    = @base;
            mDisplay = display;
            if (ellipsize_1 != null)
            {
                mInts            = new android.text.PackedIntVector(COLUMNS_ELLIPSIZE);
                mEllipsizedWidth = ellipsizedWidth;
                mEllipsizeAt     = ellipsize_1;
            }
            else
            {
                mInts            = new android.text.PackedIntVector(COLUMNS_NORMAL);
                mEllipsizedWidth = width;
                mEllipsizeAt     = null;
            }
            mObjects    = new android.text.PackedObjectVector <android.text.Layout.Directions>(1);
            mIncludePad = includepad;
            if (ellipsize_1 != null)
            {
                android.text.Layout.Ellipsizer e = (android.text.Layout.Ellipsizer)getText();
                e.mLayout  = this;
                e.mWidth   = ellipsizedWidth;
                e.mMethod  = ellipsize_1;
                mEllipsize = true;
            }
            // Initial state is a single line with 0 characters (0 to 0),
            // with top at 0 and bottom at whatever is natural, and
            // undefined ellipsis.
            int[] start;
            if (ellipsize_1 != null)
            {
                start = new int[COLUMNS_ELLIPSIZE];
                start[ELLIPSIS_START] = ELLIPSIS_UNDEFINED;
            }
            else
            {
                start = new int[COLUMNS_NORMAL];
            }
            android.text.Layout.Directions[]      dirs = new android.text.Layout.Directions[] { DIRS_ALL_LEFT_TO_RIGHT };
            android.graphics.Paint.FontMetricsInt fm   = paint.getFontMetricsInt();
            int asc  = fm.ascent;
            int desc = fm.descent;

            start[DIR]     = DIR_LEFT_TO_RIGHT << DIR_SHIFT;
            start[TOP]     = 0;
            start[DESCENT] = desc;
            mInts.insertAt(0, start);
            start[TOP] = desc - asc;
            mInts.insertAt(1, start);
            mObjects.insertAt(0, dirs);
            // Update from 0 characters to whatever the real text is
            reflow(@base, 0, 0, @base.Length);
            if (@base is android.text.Spannable)
            {
                if (mWatcher == null)
                {
                    mWatcher = new android.text.DynamicLayout.ChangeWatcher(this);
                }
                // Strip out any watchers for other DynamicLayouts.
                android.text.Spannable sp = (android.text.Spannable)@base;
                android.text.DynamicLayout.ChangeWatcher[] spans = sp.getSpans <android.text.DynamicLayout
                                                                                .ChangeWatcher>(0, sp.Length);
                {
                    for (int i = 0; i < spans.Length; i++)
                    {
                        sp.removeSpan(spans[i]);
                    }
                }
                sp.setSpan(mWatcher, 0, @base.Length, android.text.SpannedClass.SPAN_INCLUSIVE_INCLUSIVE
                           | (PRIORITY << android.text.SpannedClass.SPAN_PRIORITY_SHIFT));
            }
        }
 /// <summary>Start selecting text.</summary>
 /// <remarks>Start selecting text.</remarks>
 /// <hide>pending API review</hide>
 public static void startSelecting(android.view.View view, android.text.Spannable
                                   content)
 {
     content.setSpan(SELECTING, 0, 0, PRESSED);
 }