예제 #1
0
        private static int chooseHorizontal(android.text.Layout layout, int direction, int
                                            off1, int off2)
        {
            int line1 = layout.getLineForOffset(off1);
            int line2 = layout.getLineForOffset(off2);

            if (line1 == line2)
            {
                // same line, so it goes by pure physical direction
                float h1 = layout.getPrimaryHorizontal(off1);
                float h2 = layout.getPrimaryHorizontal(off2);
                if (direction < 0)
                {
                    // to left
                    if (h1 < h2)
                    {
                        return(off1);
                    }
                    else
                    {
                        return(off2);
                    }
                }
                else
                {
                    // to right
                    if (h1 > h2)
                    {
                        return(off1);
                    }
                    else
                    {
                        return(off2);
                    }
                }
            }
            else
            {
                // different line, so which line is "left" and which is "right"
                // depends upon the directionality of the text
                // This only checks at one end, but it's not clear what the
                // right thing to do is if the ends don't agree.  Even if it
                // is wrong it should still not be too bad.
                int line    = layout.getLineForOffset(off1);
                int textdir = layout.getParagraphDirection(line);
                if (textdir == direction)
                {
                    return(System.Math.Max(off1, off2));
                }
                else
                {
                    return(System.Math.Min(off1, off2));
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Move the selection end to the buffer offset physically below
        /// the current selection end.
        /// </summary>
        /// <remarks>
        /// Move the selection end to the buffer offset physically below
        /// the current selection end.
        /// </remarks>
        public static bool extendDown(android.text.Spannable text, android.text.Layout layout
                                      )
        {
            int end  = getSelectionEnd(text);
            int line = layout.getLineForOffset(end);

            if (line < layout.getLineCount() - 1)
            {
                int move;
                if (layout.getParagraphDirection(line) == layout.getParagraphDirection(line + 1))
                {
                    float h = layout.getPrimaryHorizontal(end);
                    move = layout.getOffsetForHorizontal(line + 1, h);
                }
                else
                {
                    move = layout.getLineStart(line + 1);
                }
                extendSelection(text, move);
                return(true);
            }
            else
            {
                if (end != text.Length)
                {
                    extendSelection(text, text.Length);
                    return(true);
                }
            }
            return(true);
        }
예제 #3
0
        /// <summary>
        /// Move the cursor to the buffer offset physically below the current
        /// offset, or return false if the cursor is already on the bottom line.
        /// </summary>
        /// <remarks>
        /// Move the cursor to the buffer offset physically below the current
        /// offset, or return false if the cursor is already on the bottom line.
        /// </remarks>
        public static bool moveDown(android.text.Spannable text, android.text.Layout layout
                                    )
        {
            int start = getSelectionStart(text);
            int end   = getSelectionEnd(text);

            if (start != end)
            {
                int min = System.Math.Min(start, end);
                int max = System.Math.Max(start, end);
                setSelection(text, max);
                if (min == 0 && max == text.Length)
                {
                    return(false);
                }
                return(true);
            }
            else
            {
                int line = layout.getLineForOffset(end);
                if (line < layout.getLineCount() - 1)
                {
                    int move;
                    if (layout.getParagraphDirection(line) == layout.getParagraphDirection(line + 1))
                    {
                        float h = layout.getPrimaryHorizontal(end);
                        move = layout.getOffsetForHorizontal(line + 1, h);
                    }
                    else
                    {
                        move = layout.getLineStart(line + 1);
                    }
                    setSelection(text, move);
                    return(true);
                }
            }
            return(false);
        }