FileDocCategorySizeDatePackage
ScrollingMovementMethod.javaAPI DocAndroid 1.5 API7749Wed May 06 22:41:56 BST 2009android.text.method

ScrollingMovementMethod

public class ScrollingMovementMethod extends Object implements MovementMethod

Fields Summary
private static ScrollingMovementMethod
sInstance
Constructors Summary
Methods Summary
public booleancanSelectArbitrarily()

        return false;
    
protected booleandown(android.widget.TextView widget, Spannable buffer)
Scrolls the text down if possible.

        Layout layout = widget.getLayout();

        int padding = widget.getTotalPaddingTop() +
                      widget.getTotalPaddingBottom();

        int areabot = widget.getScrollY() + widget.getHeight() - padding;
        int line = layout.getLineForVertical(areabot);

        if (layout.getLineTop(line+1) < areabot + 1) {
            // Less than a pixel of this line is out of view,
            // so we must have tried to make it entirely in view
            // and now want the next line to be in view instead.

            line++;
        }

        if (line <= layout.getLineCount() - 1) {
            widget.scrollTo(widget.getScrollX(), layout.getLineTop(line+1) -
                            (widget.getHeight() - padding));
            Touch.scrollTo(widget, layout,
                                widget.getScrollX(), widget.getScrollY());
            return true;
        }

        return false;
    
private booleanexecuteDown(android.widget.TextView widget, Spannable buffer, int keyCode)

        boolean handled = false;

        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            handled |= left(widget, buffer);
            break;

        case KeyEvent.KEYCODE_DPAD_RIGHT:
            handled |= right(widget, buffer);
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            handled |= up(widget, buffer);
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            handled |= down(widget, buffer);
            break;
        }

        return handled;
    
public static MovementMethodgetInstance()

        if (sInstance == null)
            sInstance = new ScrollingMovementMethod();

        return sInstance;
    
public voidinitialize(android.widget.TextView widget, Spannable text)

 
protected booleanleft(android.widget.TextView widget, Spannable buffer)
Scrolls the text to the left if possible.

        Layout layout = widget.getLayout();
        
        int scrolly = widget.getScrollY();
        int scr = widget.getScrollX();
        int em = Math.round(layout.getPaint().getFontSpacing());

        int padding = widget.getTotalPaddingTop() +
                      widget.getTotalPaddingBottom();
        int top = layout.getLineForVertical(scrolly);
        int bottom = layout.getLineForVertical(scrolly + widget.getHeight() -
                                               padding);
        int left = Integer.MAX_VALUE;

        for (int i = top; i <= bottom; i++) {
            left = (int) Math.min(left, layout.getLineLeft(i));
        }

        if (scr > left) {
            int s = Math.max(scr - em, left);
            widget.scrollTo(s, widget.getScrollY());
            return true;
        }

        return false;
    
public booleanonKeyDown(android.widget.TextView widget, Spannable buffer, int keyCode, android.view.KeyEvent event)

        return executeDown(widget, buffer, keyCode);
    
public booleanonKeyOther(android.widget.TextView view, Spannable text, android.view.KeyEvent event)

        int code = event.getKeyCode();
        if (code != KeyEvent.KEYCODE_UNKNOWN
                && event.getAction() == KeyEvent.ACTION_MULTIPLE) {
            int repeat = event.getRepeatCount();
            boolean first = true;
            boolean handled = false;
            while ((--repeat) > 0) {
                if (first && executeDown(view, text, code)) {
                    handled = true;
                    MetaKeyKeyListener.adjustMetaAfterKeypress(text);
                    MetaKeyKeyListener.resetLockedMeta(text);
                }
                first = false;
            }
            return handled;
        }
        return false;
    
public booleanonKeyUp(android.widget.TextView widget, Spannable buffer, int keyCode, android.view.KeyEvent event)

        return false;
    
public voidonTakeFocus(android.widget.TextView widget, Spannable text, int dir)

        Layout layout = widget.getLayout();

        if (layout != null && (dir & View.FOCUS_FORWARD) != 0) {
            widget.scrollTo(widget.getScrollX(),
                            layout.getLineTop(0));
        }
        if (layout != null && (dir & View.FOCUS_BACKWARD) != 0) {
            int padding = widget.getTotalPaddingTop() +
                          widget.getTotalPaddingBottom();
            int line = layout.getLineCount() - 1;

            widget.scrollTo(widget.getScrollX(),
                            layout.getLineTop(line+1) -
                            (widget.getHeight() - padding));
        }
    
public booleanonTouchEvent(android.widget.TextView widget, Spannable buffer, android.view.MotionEvent event)

        return Touch.onTouchEvent(widget, buffer, event);
    
public booleanonTrackballEvent(android.widget.TextView widget, Spannable text, android.view.MotionEvent event)

        return false;
    
protected booleanright(android.widget.TextView widget, Spannable buffer)
Scrolls the text to the right if possible.

        Layout layout = widget.getLayout();

        int scrolly = widget.getScrollY();
        int scr = widget.getScrollX();
        int em = Math.round(layout.getPaint().getFontSpacing());

        int padding = widget.getTotalPaddingTop() +
                      widget.getTotalPaddingBottom();
        int top = layout.getLineForVertical(scrolly);
        int bottom = layout.getLineForVertical(scrolly + widget.getHeight() -
                                               padding);
        int right = 0;

        for (int i = top; i <= bottom; i++) {
            right = (int) Math.max(right, layout.getLineRight(i));
        }

        padding = widget.getTotalPaddingLeft() + widget.getTotalPaddingRight();
        if (scr < right - (widget.getWidth() - padding)) {
            int s = Math.min(scr + em, right - (widget.getWidth() - padding));
            widget.scrollTo(s, widget.getScrollY());
            return true;
        }

        return false;
    
protected booleanup(android.widget.TextView widget, Spannable buffer)
Scrolls the text up if possible.

        Layout layout = widget.getLayout();

        int areatop = widget.getScrollY();
        int line = layout.getLineForVertical(areatop);
        int linetop = layout.getLineTop(line);

        // If the top line is partially visible, bring it all the way
        // into view; otherwise, bring the previous line into view.
        if (areatop == linetop)
            line--;

        if (line >= 0) {
            Touch.scrollTo(widget, layout,
                           widget.getScrollX(), layout.getLineTop(line));
            return true;
        }

        return false;