public boolean arrowScroll(int direction, boolean horizontal) {
        View currentFocused = findFocus();
        if (currentFocused == this) currentFocused = null;
        View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
        final int maxJump = horizontal ? getMaxScrollAmountHorizontal() : getMaxScrollAmountVertical();

        if (!horizontal) {
            if (nextFocused != null) {
                nextFocused.getDrawingRect(mTempRect);
                offsetDescendantRectToMyCoords(nextFocused, mTempRect);
                int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
                doScroll(0, scrollDelta);
                nextFocused.requestFocus(direction);
            } else {
                // no new focus
                int scrollDelta = maxJump;
                if (direction == View.FOCUS_UP && getScrollY() < scrollDelta) {
                    scrollDelta = getScrollY();
                } else if (direction == View.FOCUS_DOWN) {
                    if (getChildCount() > 0) {
                        int daBottom = getChildAt(0).getBottom();
                        int screenBottom = getScrollY() + getHeight();
                        if (daBottom - screenBottom < maxJump) {
                            scrollDelta = daBottom - screenBottom;
                        }
                    }
                }
                if (scrollDelta == 0) {
                    return false;
                }
                doScroll(0, direction == View.FOCUS_DOWN ? scrollDelta : -scrollDelta);
            }
        } else {
            if (nextFocused != null) {
                nextFocused.getDrawingRect(mTempRect);
                offsetDescendantRectToMyCoords(nextFocused, mTempRect);
                int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
                doScroll(scrollDelta, 0);
                nextFocused.requestFocus(direction);
            } else {
                // no new focus
                int scrollDelta = maxJump;
                if (direction == View.FOCUS_UP && getScrollY() < scrollDelta) {
                    scrollDelta = getScrollY();
                } else if (direction == View.FOCUS_DOWN) {
                    if (getChildCount() > 0) {
                        int daBottom = getChildAt(0).getBottom();
                        int screenBottom = getScrollY() + getHeight();
                        if (daBottom - screenBottom < maxJump) {
                            scrollDelta = daBottom - screenBottom;
                        }
                    }
                }
                if (scrollDelta == 0) {
                    return false;
                }
                doScroll(direction == View.FOCUS_DOWN ? scrollDelta : -scrollDelta, 0);
            }
        }
        return true;
    }
public boolean arrowScroll ( int direction , boolean horizontal ) { View currentFocused = findFocus ( ) ; if ( currentFocused == this ) currentFocused = null ; View nextFocused = FocusFinder . getInstance ( ) . findNextFocus ( this , currentFocused , direction ) ; final int maxJump = horizontal ? getMaxScrollAmountHorizontal ( ) : getMaxScrollAmountVertical ( ) ; if ( ! horizontal ) { if ( nextFocused != null ) { nextFocused . getDrawingRect ( mTempRect ) ; offsetDescendantRectToMyCoords ( nextFocused , mTempRect ) ; int scrollDelta = computeScrollDeltaToGetChildRectOnScreen ( mTempRect ) ; doScroll ( 0 , scrollDelta ) ; nextFocused . requestFocus ( direction ) ; } else { int scrollDelta = maxJump ; if ( direction == View . FOCUS_UP && getScrollY ( ) < scrollDelta ) { scrollDelta = getScrollY ( ) ; } else if ( direction == View . FOCUS_DOWN ) { if ( getChildCount ( ) > 0 ) { int daBottom = getChildAt ( 0 ) . getBottom ( ) ; int screenBottom = getScrollY ( ) + getHeight ( ) ; if ( daBottom - screenBottom < maxJump ) { scrollDelta = daBottom - screenBottom ; } } } if ( scrollDelta == 0 ) { return false ; } doScroll ( 0 , direction == View . FOCUS_DOWN ? scrollDelta : - scrollDelta ) ; } } else { if ( nextFocused != null ) { nextFocused . getDrawingRect ( mTempRect ) ; offsetDescendantRectToMyCoords ( nextFocused , mTempRect ) ; int scrollDelta = computeScrollDeltaToGetChildRectOnScreen ( mTempRect ) ; doScroll ( scrollDelta , 0 ) ; nextFocused . requestFocus ( direction ) ; } else { int scrollDelta = maxJump ; if ( direction == View . FOCUS_UP && getScrollY ( ) < scrollDelta ) { scrollDelta = getScrollY ( ) ; } else if ( direction == View . FOCUS_DOWN ) { if ( getChildCount ( ) > 0 ) { int daBottom = getChildAt ( 0 ) . getBottom ( ) ; int screenBottom = getScrollY ( ) + getHeight ( ) ; if ( daBottom - screenBottom < maxJump ) { scrollDelta = daBottom - screenBottom ; } } } if ( scrollDelta == 0 ) { return false ; } doScroll ( direction == View . FOCUS_DOWN ? scrollDelta : - scrollDelta , 0 ) ; } } return true ; }
Handle scrolling in response to an up or down arrow click.

@param direction The direction corresponding to the arrow key that was
pressed
@return True if we consumed the event, false otherwise