Example usage for android.view View FOCUS_UP

List of usage examples for android.view View FOCUS_UP

Introduction

In this page you can find the example usage for android.view View FOCUS_UP.

Prototype

int FOCUS_UP

To view the source code for android.view View FOCUS_UP.

Click Source Link

Document

Use with #focusSearch(int) .

Usage

From source file:com.aliasapps.seq.scroller.TwoWayView.java

/**
 * Go to the last or first item if possible (not worrying about panning across or navigating
 * within the internal focus of the currently selected item.)
 *
 * @param direction either {@link View#FOCUS_UP} or {@link View#FOCUS_DOWN} or
 *        {@link View#FOCUS_LEFT} or {@link View#FOCUS_RIGHT} depending on the
 *        current view orientation./*  w w  w  .  ja v  a  2 s  .com*/
 *
 * @return whether selection was moved
 */
boolean fullScroll(int direction) {
    forceValidFocusDirection(direction);

    boolean moved = false;
    if (direction == View.FOCUS_UP || direction == View.FOCUS_LEFT) {
        if (mSelectedPosition != 0) {
            int position = lookForSelectablePosition(0, true);
            if (position >= 0) {
                mLayoutMode = LAYOUT_FORCE_TOP;
                setSelectionInt(position);
                invokeOnItemScrollListener();
            }

            moved = true;
        }
    } else if (direction == View.FOCUS_DOWN || direction == View.FOCUS_RIGHT) {
        if (mSelectedPosition < mItemCount - 1) {
            int position = lookForSelectablePosition(mItemCount - 1, true);
            if (position >= 0) {
                mLayoutMode = LAYOUT_FORCE_BOTTOM;
                setSelectionInt(position);
                invokeOnItemScrollListener();
            }

            moved = true;
        }
    }

    if (moved && !awakenScrollbarsInternal()) {
        awakenScrollbarsInternal();
        invalidate();
    }

    return moved;
}

From source file:com.artifex.mupdflib.TwoWayView.java

/**
 * Scrolls up or down by the number of items currently present on screen.
 *
 * @param direction either {@link View#FOCUS_UP} or {@link View#FOCUS_DOWN} or
 *        {@link View#FOCUS_LEFT} or {@link View#FOCUS_RIGHT} depending on the
 *        current view orientation./* w  w w .ja v  a 2s.  c  om*/
 *
 * @return whether selection was moved
 */
boolean pageScroll(int direction) {
    forceValidFocusDirection(direction);

    boolean forward = false;
    int nextPage = -1;

    if (direction == View.FOCUS_UP || direction == View.FOCUS_LEFT) {
        nextPage = Math.max(0, mSelectedPosition - getChildCount() - 1);
    } else if (direction == View.FOCUS_DOWN || direction == View.FOCUS_RIGHT) {
        nextPage = Math.min(mItemCount - 1, mSelectedPosition + getChildCount() - 1);
        forward = true;
    }

    if (nextPage < 0) {
        return false;
    }

    final int position = lookForSelectablePosition(nextPage, forward);
    if (position >= 0) {
        mLayoutMode = LAYOUT_SPECIFIC;
        mSpecificStart = getStartEdge() + getFadingEdgeLength();

        if (forward && position > mItemCount - getChildCount()) {
            mLayoutMode = LAYOUT_FORCE_BOTTOM;
        }

        if (!forward && position < getChildCount()) {
            mLayoutMode = LAYOUT_FORCE_TOP;
        }

        setSelectionInt(position);
        invokeOnItemScrollListener();

        if (!awakenScrollbarsInternal()) {
            invalidate();
        }

        return true;
    }

    return false;
}

From source file:com.aliasapps.seq.scroller.TwoWayView.java

/**
 * When selection changes, it is possible that the previously selected or the
 * next selected item will change its size.  If so, we need to offset some folks,
 * and re-layout the items as appropriate.
 *
 * @param selectedView The currently selected view (before changing selection).
 *   should be <code>null</code> if there was no previous selection.
 * @param direction either {@link View#FOCUS_UP} or {@link View#FOCUS_DOWN} or
 *        {@link View#FOCUS_LEFT} or {@link View#FOCUS_RIGHT} depending on the
 *        current view orientation.//from   www .  ja v a2 s  . c  o m
 * @param newSelectedPosition The position of the next selection.
 * @param newFocusAssigned whether new focus was assigned.  This matters because
 *        when something has focus, we don't want to show selection (ugh).
 */
private void handleNewSelectionChange(View selectedView, int direction, int newSelectedPosition,
        boolean newFocusAssigned) {
    forceValidFocusDirection(direction);

    if (newSelectedPosition == INVALID_POSITION) {
        throw new IllegalArgumentException("newSelectedPosition needs to be valid");
    }

    // Whether or not we are moving down/right or up/left, we want to preserve the
    // top/left of whatever view is at the start:
    // - moving down/right: the view that had selection
    // - moving up/left: the view that is getting selection
    final int selectedIndex = mSelectedPosition - mFirstPosition;
    final int nextSelectedIndex = newSelectedPosition - mFirstPosition;
    int startViewIndex, endViewIndex;
    boolean topSelected = false;
    View startView;
    View endView;

    if (direction == View.FOCUS_UP || direction == View.FOCUS_LEFT) {
        startViewIndex = nextSelectedIndex;
        endViewIndex = selectedIndex;
        startView = getChildAt(startViewIndex);
        endView = selectedView;
        topSelected = true;
    } else {
        startViewIndex = selectedIndex;
        endViewIndex = nextSelectedIndex;
        startView = selectedView;
        endView = getChildAt(endViewIndex);
    }

    final int numChildren = getChildCount();

    // start with top view: is it changing size?
    if (startView != null) {
        startView.setSelected(!newFocusAssigned && topSelected);
        measureAndAdjustDown(startView, startViewIndex, numChildren);
    }

    // is the bottom view changing size?
    if (endView != null) {
        endView.setSelected(!newFocusAssigned && !topSelected);
        measureAndAdjustDown(endView, endViewIndex, numChildren);
    }
}

From source file:com.appunite.list.GridView.java

/**
 * Is childIndex a candidate for next focus given the direction the focus
 * change is coming from?//from ww w . j  av a2 s  . c  o m
 * @param childIndex The index to check.
 * @param direction The direction, one of
 *        {FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, FOCUS_BACKWARD}
 * @return Whether childIndex is a candidate.
 */
private boolean isCandidateSelection(int childIndex, int direction) {
    final int count = getChildCount();
    final int invertedIndex = count - 1 - childIndex;

    int rowStart;
    int rowEnd;

    if (!mStackFromBottom) {
        rowStart = childIndex - (childIndex % mNumColumns);
        rowEnd = Math.max(rowStart + mNumColumns - 1, count);
    } else {
        rowEnd = count - 1 - (invertedIndex - (invertedIndex % mNumColumns));
        rowStart = Math.max(0, rowEnd - mNumColumns + 1);
    }

    switch (direction) {
    case View.FOCUS_RIGHT:
        // coming from left, selection is only valid if it is on left
        // edge
        return childIndex == rowStart;
    case View.FOCUS_DOWN:
        // coming from top; only valid if in top row
        return rowStart == 0;
    case View.FOCUS_LEFT:
        // coming from right, must be on right edge
        return childIndex == rowEnd;
    case View.FOCUS_UP:
        // coming from bottom, need to be in last row
        return rowEnd == count - 1;
    case View.FOCUS_FORWARD:
        // coming from top-left, need to be first in top row
        return childIndex == rowStart && rowStart == 0;
    case View.FOCUS_BACKWARD:
        // coming from bottom-right, need to be last in bottom row
        return childIndex == rowEnd && rowEnd == count - 1;
    default:
        throw new IllegalArgumentException("direction must be one of "
                + "{FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, " + "FOCUS_FORWARD, FOCUS_BACKWARD}.");
    }
}

From source file:com.artifex.mupdf.view.ThumbnailViews.java

/**
 * When selection changes, it is possible that the previously selected or
 * the next selected item will change its size. If so, we need to offset
 * some folks, and re-layout the items as appropriate.
 * //from w  w  w  .  j  ava2s  .  c  o  m
 * @param selectedView
 *            The currently selected view (before changing selection).
 *            should be <code>null</code> if there was no previous
 *            selection.
 * @param direction
 *            either {@link View#FOCUS_UP} or {@link View#FOCUS_DOWN} or
 *            {@link View#FOCUS_LEFT} or {@link View#FOCUS_RIGHT} depending
 *            on the current view orientation.
 * @param newSelectedPosition
 *            The position of the next selection.
 * @param newFocusAssigned
 *            whether new focus was assigned. This matters because when
 *            something has focus, we don't want to show selection (ugh).
 */
private void handleNewSelectionChange(View selectedView, int direction, int newSelectedPosition,
        boolean newFocusAssigned) {
    forceValidFocusDirection(direction);

    if (newSelectedPosition == INVALID_POSITION) {
        throw new IllegalArgumentException("newSelectedPosition needs to be valid");
    }

    // Whether or not we are moving down/right or up/left, we want to
    // preserve the
    // top/left of whatever view is at the start:
    // - moving down/right: the view that had selection
    // - moving up/left: the view that is getting selection
    final int selectedIndex = mSelectedPosition - mFirstPosition;
    final int nextSelectedIndex = newSelectedPosition - mFirstPosition;
    int startViewIndex, endViewIndex;
    boolean topSelected = false;
    View startView;
    View endView;

    if (direction == View.FOCUS_UP || direction == View.FOCUS_LEFT) {
        startViewIndex = nextSelectedIndex;
        endViewIndex = selectedIndex;
        startView = getChildAt(startViewIndex);
        endView = selectedView;
        topSelected = true;
    } else {
        startViewIndex = selectedIndex;
        endViewIndex = nextSelectedIndex;
        startView = selectedView;
        endView = getChildAt(endViewIndex);
    }

    final int numChildren = getChildCount();

    // start with top view: is it changing size?
    if (startView != null) {
        startView.setSelected(!newFocusAssigned && topSelected);
        measureAndAdjustDown(startView, startViewIndex, numChildren);
    }

    // is the bottom view changing size?
    if (endView != null) {
        endView.setSelected(!newFocusAssigned && !topSelected);
        measureAndAdjustDown(endView, endViewIndex, numChildren);
    }
}

From source file:com.aliasapps.seq.scroller.TwoWayView.java

/**
 * Do an arrow scroll based on focus searching.  If a new view is
 * given focus, return the selection delta and amount to scroll via
 * an {@link ArrowScrollFocusResult}, otherwise, return null.
 *
 * @param direction either {@link View#FOCUS_UP} or {@link View#FOCUS_DOWN} or
 *        {@link View#FOCUS_LEFT} or {@link View#FOCUS_RIGHT} depending on the
 *        current view orientation./*from ww w  .  ja  v a2  s .  co m*/
 *
 * @return The result if focus has changed, or <code>null</code>.
 */
private ArrowScrollFocusResult arrowScrollFocused(final int direction) {
    forceValidFocusDirection(direction);

    final View selectedView = getSelectedView();
    final View newFocus;
    final int searchPoint;

    if (selectedView != null && selectedView.hasFocus()) {
        View oldFocus = selectedView.findFocus();
        newFocus = FocusFinder.getInstance().findNextFocus(this, oldFocus, direction);
    } else {
        if (direction == View.FOCUS_DOWN || direction == View.FOCUS_RIGHT) {
            final int start = (mIsVertical ? getPaddingTop() : getPaddingLeft());

            final int selectedStart;
            if (selectedView != null) {
                selectedStart = (mIsVertical ? selectedView.getTop() : selectedView.getLeft());
            } else {
                selectedStart = start;
            }

            searchPoint = Math.max(selectedStart, start);
        } else {
            final int end = (mIsVertical ? getHeight() - getPaddingBottom() : getWidth() - getPaddingRight());

            final int selectedEnd;
            if (selectedView != null) {
                selectedEnd = (mIsVertical ? selectedView.getBottom() : selectedView.getRight());
            } else {
                selectedEnd = end;
            }

            searchPoint = Math.min(selectedEnd, end);
        }

        final int x = (mIsVertical ? 0 : searchPoint);
        final int y = (mIsVertical ? searchPoint : 0);
        mTempRect.set(x, y, x, y);

        newFocus = FocusFinder.getInstance().findNextFocusFromRect(this, mTempRect, direction);
    }

    if (newFocus != null) {
        final int positionOfNewFocus = positionOfNewFocus(newFocus);

        // If the focus change is in a different new position, make sure
        // we aren't jumping over another selectable position.
        if (mSelectedPosition != INVALID_POSITION && positionOfNewFocus != mSelectedPosition) {
            final int selectablePosition = lookForSelectablePositionOnScreen(direction);

            final boolean movingForward = (direction == View.FOCUS_DOWN || direction == View.FOCUS_RIGHT);
            final boolean movingBackward = (direction == View.FOCUS_UP || direction == View.FOCUS_LEFT);

            if (selectablePosition != INVALID_POSITION
                    && ((movingForward && selectablePosition < positionOfNewFocus)
                            || (movingBackward && selectablePosition > positionOfNewFocus))) {
                return null;
            }
        }

        int focusScroll = amountToScrollToNewFocus(direction, newFocus, positionOfNewFocus);

        final int maxScrollAmount = getMaxScrollAmount();
        if (focusScroll < maxScrollAmount) {
            // Not moving too far, safe to give next view focus
            newFocus.requestFocus(direction);
            mArrowScrollFocusResult.populate(positionOfNewFocus, focusScroll);
            return mArrowScrollFocusResult;
        } else if (distanceToView(newFocus) < maxScrollAmount) {
            // Case to consider:
            // Too far to get entire next focusable on screen, but by going
            // max scroll amount, we are getting it at least partially in view,
            // so give it focus and scroll the max amount.
            newFocus.requestFocus(direction);
            mArrowScrollFocusResult.populate(positionOfNewFocus, maxScrollAmount);
            return mArrowScrollFocusResult;
        }
    }

    return null;
}

From source file:com.boutline.sports.helpers.TwoWayView.java

/**
 * Do an arrow scroll based on focus searching.  If a new view is
 * given focus, return the selection delta and amount to scroll via
 * an {@link ArrowScrollFocusResult}, otherwise, return null.
 *
 * @param direction either {@link android.view.View#FOCUS_UP} or {@link android.view.View#FOCUS_DOWN} or
 *        {@link android.view.View#FOCUS_LEFT} or {@link android.view.View#FOCUS_RIGHT} depending on the
 *        current view orientation./* ww  w.j av  a  2 s .  c om*/
 *
 * @return The result if focus has changed, or <code>null</code>.
 */
private ArrowScrollFocusResult arrowScrollFocused(final int direction) {
    forceValidFocusDirection(direction);

    final View selectedView = getSelectedView();
    final View newFocus;
    final int searchPoint;

    if (selectedView != null && selectedView.hasFocus()) {
        View oldFocus = selectedView.findFocus();
        newFocus = FocusFinder.getInstance().findNextFocus(this, oldFocus, direction);
    } else {
        if (direction == View.FOCUS_DOWN || direction == View.FOCUS_RIGHT) {
            final int start = getStartEdge();

            final int selectedStart;
            if (selectedView != null) {
                selectedStart = (mIsVertical ? selectedView.getTop() : selectedView.getLeft());
            } else {
                selectedStart = start;
            }

            searchPoint = Math.max(selectedStart, start);
        } else {
            final int end = getEndEdge();

            final int selectedEnd;
            if (selectedView != null) {
                selectedEnd = getChildEndEdge(selectedView);
            } else {
                selectedEnd = end;
            }

            searchPoint = Math.min(selectedEnd, end);
        }

        final int x = (mIsVertical ? 0 : searchPoint);
        final int y = (mIsVertical ? searchPoint : 0);
        mTempRect.set(x, y, x, y);

        newFocus = FocusFinder.getInstance().findNextFocusFromRect(this, mTempRect, direction);
    }

    if (newFocus != null) {
        final int positionOfNewFocus = positionOfNewFocus(newFocus);

        // If the focus change is in a different new position, make sure
        // we aren't jumping over another selectable position.
        if (mSelectedPosition != INVALID_POSITION && positionOfNewFocus != mSelectedPosition) {
            final int selectablePosition = lookForSelectablePositionOnScreen(direction);

            final boolean movingForward = (direction == View.FOCUS_DOWN || direction == View.FOCUS_RIGHT);
            final boolean movingBackward = (direction == View.FOCUS_UP || direction == View.FOCUS_LEFT);

            if (selectablePosition != INVALID_POSITION
                    && ((movingForward && selectablePosition < positionOfNewFocus)
                            || (movingBackward && selectablePosition > positionOfNewFocus))) {
                return null;
            }
        }

        int focusScroll = amountToScrollToNewFocus(direction, newFocus, positionOfNewFocus);

        final int maxScrollAmount = getMaxScrollAmount();
        if (focusScroll < maxScrollAmount) {
            // Not moving too far, safe to give next view focus
            newFocus.requestFocus(direction);
            mArrowScrollFocusResult.populate(positionOfNewFocus, focusScroll);
            return mArrowScrollFocusResult;
        } else if (distanceToView(newFocus) < maxScrollAmount) {
            // Case to consider:
            // Too far to get entire next focusable on screen, but by going
            // max scroll amount, we are getting it at least partially in view,
            // so give it focus and scroll the max amount.
            newFocus.requestFocus(direction);
            mArrowScrollFocusResult.populate(positionOfNewFocus, maxScrollAmount);
            return mArrowScrollFocusResult;
        }
    }

    return null;
}

From source file:com.artifex.mupdf.view.ThumbnailViews.java

/**
 * Do an arrow scroll based on focus searching. If a new view is given
 * focus, return the selection delta and amount to scroll via an
 * {@link ArrowScrollFocusResult}, otherwise, return null.
 * /*from   w w  w . j  a  v  a2  s .c  om*/
 * @param direction
 *            either {@link View#FOCUS_UP} or {@link View#FOCUS_DOWN} or
 *            {@link View#FOCUS_LEFT} or {@link View#FOCUS_RIGHT} depending
 *            on the current view orientation.
 * 
 * @return The result if focus has changed, or <code>null</code>.
 */
private ArrowScrollFocusResult arrowScrollFocused(final int direction) {
    forceValidFocusDirection(direction);

    final View selectedView = getSelectedView();
    final View newFocus;
    final int searchPoint;

    if (selectedView != null && selectedView.hasFocus()) {
        View oldFocus = selectedView.findFocus();
        newFocus = FocusFinder.getInstance().findNextFocus(this, oldFocus, direction);
    } else {
        if (direction == View.FOCUS_DOWN || direction == View.FOCUS_RIGHT) {
            final int start = (mIsVertical ? getPaddingTop() : getPaddingLeft());

            final int selectedStart;
            if (selectedView != null) {
                selectedStart = (mIsVertical ? selectedView.getTop() : selectedView.getLeft());
            } else {
                selectedStart = start;
            }

            searchPoint = Math.max(selectedStart, start);
        } else {
            final int end = (mIsVertical ? getHeight() - getPaddingBottom() : getWidth() - getPaddingRight());

            final int selectedEnd;
            if (selectedView != null) {
                selectedEnd = (mIsVertical ? selectedView.getBottom() : selectedView.getRight());
            } else {
                selectedEnd = end;
            }

            searchPoint = Math.min(selectedEnd, end);
        }

        final int x = (mIsVertical ? 0 : searchPoint);
        final int y = (mIsVertical ? searchPoint : 0);
        mTempRect.set(x, y, x, y);

        newFocus = FocusFinder.getInstance().findNextFocusFromRect(this, mTempRect, direction);
    }

    if (newFocus != null) {
        final int positionOfNewFocus = positionOfNewFocus(newFocus);

        // If the focus change is in a different new position, make sure
        // we aren't jumping over another selectable position.
        if (mSelectedPosition != INVALID_POSITION && positionOfNewFocus != mSelectedPosition) {
            final int selectablePosition = lookForSelectablePositionOnScreen(direction);

            final boolean movingForward = (direction == View.FOCUS_DOWN || direction == View.FOCUS_RIGHT);
            final boolean movingBackward = (direction == View.FOCUS_UP || direction == View.FOCUS_LEFT);

            if (selectablePosition != INVALID_POSITION
                    && ((movingForward && selectablePosition < positionOfNewFocus)
                            || (movingBackward && selectablePosition > positionOfNewFocus))) {
                return null;
            }
        }

        int focusScroll = amountToScrollToNewFocus(direction, newFocus, positionOfNewFocus);

        final int maxScrollAmount = getMaxScrollAmount();
        if (focusScroll < maxScrollAmount) {
            // Not moving too far, safe to give next view focus
            newFocus.requestFocus(direction);
            mArrowScrollFocusResult.populate(positionOfNewFocus, focusScroll);
            return mArrowScrollFocusResult;
        } else if (distanceToView(newFocus) < maxScrollAmount) {
            // Case to consider:
            // Too far to get entire next focusable on screen, but by going
            // max scroll amount, we are getting it at least partially in
            // view,
            // so give it focus and scroll the max amount.
            newFocus.requestFocus(direction);
            mArrowScrollFocusResult.populate(positionOfNewFocus, maxScrollAmount);
            return mArrowScrollFocusResult;
        }
    }

    return null;
}

From source file:com.artifex.mupdflib.TwoWayView.java

/**
 * Do an arrow scroll based on focus searching.  If a new view is
 * given focus, return the selection delta and amount to scroll via
 * an {@link ArrowScrollFocusResult}, otherwise, return null.
 *
 * @param direction either {@link View#FOCUS_UP} or {@link View#FOCUS_DOWN} or
 *        {@link View#FOCUS_LEFT} or {@link View#FOCUS_RIGHT} depending on the
 *        current view orientation./*from w ww.java 2s . co  m*/
 *
 * @return The result if focus has changed, or <code>null</code>.
 */
private ArrowScrollFocusResult arrowScrollFocused(final int direction) {
    forceValidFocusDirection(direction);

    final View selectedView = getSelectedView();
    final View newFocus;
    final int searchPoint;

    if (selectedView != null && selectedView.hasFocus()) {
        View oldFocus = selectedView.findFocus();
        newFocus = FocusFinder.getInstance().findNextFocus(this, oldFocus, direction);
    } else {
        if (direction == View.FOCUS_DOWN || direction == View.FOCUS_RIGHT) {
            boolean fadingEdgeShowing = (mFirstPosition > 0);
            final int start = getStartEdge() + (fadingEdgeShowing ? getArrowScrollPreviewLength() : 0);

            final int selectedStart;
            if (selectedView != null) {
                selectedStart = getChildStartEdge(selectedView);
            } else {
                selectedStart = start;
            }

            searchPoint = Math.max(selectedStart, start);
        } else {
            final boolean fadingEdgeShowing = (mFirstPosition + getChildCount() - 1) < mItemCount;
            final int end = getEndEdge() - (fadingEdgeShowing ? getArrowScrollPreviewLength() : 0);

            final int selectedEnd;
            if (selectedView != null) {
                selectedEnd = getChildEndEdge(selectedView);
            } else {
                selectedEnd = end;
            }

            searchPoint = Math.min(selectedEnd, end);
        }

        final int x = (mIsVertical ? 0 : searchPoint);
        final int y = (mIsVertical ? searchPoint : 0);
        mTempRect.set(x, y, x, y);

        newFocus = FocusFinder.getInstance().findNextFocusFromRect(this, mTempRect, direction);
    }

    if (newFocus != null) {
        final int positionOfNewFocus = positionOfNewFocus(newFocus);

        // If the focus change is in a different new position, make sure
        // we aren't jumping over another selectable position.
        if (mSelectedPosition != INVALID_POSITION && positionOfNewFocus != mSelectedPosition) {
            final int selectablePosition = lookForSelectablePositionOnScreen(direction);

            final boolean movingForward = (direction == View.FOCUS_DOWN || direction == View.FOCUS_RIGHT);
            final boolean movingBackward = (direction == View.FOCUS_UP || direction == View.FOCUS_LEFT);

            if (selectablePosition != INVALID_POSITION
                    && ((movingForward && selectablePosition < positionOfNewFocus)
                            || (movingBackward && selectablePosition > positionOfNewFocus))) {
                return null;
            }
        }

        int focusScroll = amountToScrollToNewFocus(direction, newFocus, positionOfNewFocus);

        final int maxScrollAmount = getMaxScrollAmount();
        if (focusScroll < maxScrollAmount) {
            // Not moving too far, safe to give next view focus
            newFocus.requestFocus(direction);
            mArrowScrollFocusResult.populate(positionOfNewFocus, focusScroll);
            return mArrowScrollFocusResult;
        } else if (distanceToView(newFocus) < maxScrollAmount) {
            // Case to consider:
            // Too far to get entire next focusable on screen, but by going
            // max scroll amount, we are getting it at least partially in view,
            // so give it focus and scroll the max amount.
            newFocus.requestFocus(direction);
            mArrowScrollFocusResult.populate(positionOfNewFocus, maxScrollAmount);
            return mArrowScrollFocusResult;
        }
    }

    return null;
}

From source file:administrator.example.com.myscrollview.VerticalViewPager.java

/**
 * Pagekeypad?/*ww w. ja  va 2s .  c om*/
 * @param direction ?
 * @return handled
 */
public boolean arrowScroll(int direction) {
    View currentFocused = findFocus();
    if (currentFocused == this)
        currentFocused = null;

    boolean handled = false;

    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
    if (nextFocused != null && nextFocused != currentFocused) {
        if (direction == View.FOCUS_UP) {
            // If there is nothing to the left, or this is causing us to
            // jump to the down, then what we really want to do is page up.
            if (currentFocused != null && nextFocused.getTop() >= currentFocused.getTop()) {
                handled = pageUp();
            } else {
                handled = nextFocused.requestFocus();
            } /* end of if */
        } else if (direction == View.FOCUS_DOWN) {
            // If there is nothing to the right, or this is causing us to
            // jump to the left, then what we really want to do is page right.
            if (currentFocused != null && nextFocused.getTop() <= currentFocused.getTop()) {
                handled = pageDown();
            } else {
                handled = nextFocused.requestFocus();
            } /* end of if */
        } /* end of if */
    } else if (direction == FOCUS_UP || direction == FOCUS_BACKWARD) {
        // Trying to move left and nothing there; try to page.
        handled = pageUp();
    } else if (direction == FOCUS_DOWN || direction == FOCUS_FORWARD) {
        // Trying to move right and nothing there; try to page.
        handled = pageDown();
    } /* end of if */
    if (handled) {
        playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
    } /* end of if */
    return handled;
}