Example usage for android.view View FOCUS_DOWN

List of usage examples for android.view View FOCUS_DOWN

Introduction

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

Prototype

int FOCUS_DOWN

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

Click Source Link

Document

Use with #focusSearch(int) .

Usage

From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java

/**
 * <p>Handles scrolling in response to a "page up/down" shortcut press. This
 * method will scroll the view by one page up or down and give the focus
 * to the topmost/bottommost component in the new visible area. If no
 * component is a good candidate for focus, this scrollview reclaims the
 * focus.</p>//w  ww .ja v a2s.  c o m
 *
 * @param direction the scroll direction: {@link android.view.View#FOCUS_UP}
 *                  to go one page up or
 *                  {@link android.view.View#FOCUS_DOWN} to go one page down
 * @return true if the key event is consumed by this method, false otherwise
 */
public boolean pageScroll(int direction) {
    boolean down = direction == View.FOCUS_DOWN;
    int height = getHeight();

    if (down) {
        mTempRect.top = getScrollY() + height;
        int count = getChildCount();
        if (count > 0) {
            View view = getChildAt(count - 1);
            if (mTempRect.top + height > view.getBottom()) {
                mTempRect.top = view.getBottom() - height;
            }
        }
    } else {
        mTempRect.top = getScrollY() - height;
        if (mTempRect.top < 0) {
            mTempRect.top = 0;
        }
    }
    mTempRect.bottom = mTempRect.top + height;

    return scrollAndFocus(direction, mTempRect.top, mTempRect.bottom);
}

From source file:android.support.v7.extensions.BaseLayoutManager.java

/**
 * Converts a focusDirection to orientation.
 *
 * @param focusDirection One of {@link android.view.View#FOCUS_UP}, {@link android.view.View#FOCUS_DOWN},
 *                       {@link android.view.View#FOCUS_LEFT}, {@link android.view.View#FOCUS_RIGHT},
 *                       {@link android.view.View#FOCUS_BACKWARD}, {@link android.view.View#FOCUS_FORWARD}
 *                       or 0 for not applicable
 * @return {@link RenderState#LAYOUT_START} or {@link RenderState#LAYOUT_END} if focus direction
 * is applicable to current state, {@link RenderState#INVALID_LAYOUT} otherwise.
 *//*from  w ww  . ja v  a2 s.  c o m*/
private int convertFocusDirectionToLayoutDirection(int focusDirection) {
    switch (focusDirection) {
    case View.FOCUS_BACKWARD:
        return RenderState.LAYOUT_START;
    case View.FOCUS_FORWARD:
        return RenderState.LAYOUT_END;
    case View.FOCUS_UP:
        return mOrientation == VERTICAL ? RenderState.LAYOUT_START : RenderState.INVALID_LAYOUT;
    case View.FOCUS_DOWN:
        return mOrientation == VERTICAL ? RenderState.LAYOUT_END : RenderState.INVALID_LAYOUT;
    case View.FOCUS_LEFT:
        return mOrientation == HORIZONTAL ? RenderState.LAYOUT_START : RenderState.INVALID_LAYOUT;
    case View.FOCUS_RIGHT:
        return mOrientation == HORIZONTAL ? RenderState.LAYOUT_END : RenderState.INVALID_LAYOUT;
    default:
        if (DEBUG) {
            Log.d(TAG, "Unknown focus request:" + focusDirection);
        }
        return RenderState.INVALID_LAYOUT;
    }

}

From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java

/**
 * <p>Handles scrolling in response to a "home/end" shortcut press. This
 * method will scroll the view to the top or bottom and give the focus
 * to the topmost/bottommost component in the new visible area. If no
 * component is a good candidate for focus, this scrollview reclaims the
 * focus.</p>/* ww  w  .  java 2  s . c o  m*/
 *
 * @param direction the scroll direction: {@link android.view.View#FOCUS_UP}
 *                  to go the top of the view or
 *                  {@link android.view.View#FOCUS_DOWN} to go the bottom
 * @return true if the key event is consumed by this method, false otherwise
 */
public boolean fullScroll(int direction) {
    boolean down = direction == View.FOCUS_DOWN;
    int height = getHeight();

    mTempRect.top = 0;
    mTempRect.bottom = height;

    if (down) {
        int count = getChildCount();
        if (count > 0) {
            View view = getChildAt(count - 1);
            mTempRect.bottom = view.getBottom() + getPaddingBottom();
            mTempRect.top = mTempRect.bottom - height;
        }
    }

    return scrollAndFocus(direction, mTempRect.top, mTempRect.bottom);
}

From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java

/**
 * Handle scrolling in response to an up or down arrow click.
 *
 * @param direction The direction corresponding to the arrow key that was
 *                  pressed/*from w ww.  j  av  a 2s  .  c  om*/
 * @return True if we consumed the event, false otherwise
 */
public boolean arrowScroll(int direction) {

    View currentFocused = findFocus();
    if (currentFocused == this)
        currentFocused = null;

    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);

    final int maxJump = getMaxScrollAmount();

    if (nextFocused != null && isWithinDeltaOfScreen(nextFocused, maxJump, getHeight())) {
        nextFocused.getDrawingRect(mTempRect);
        offsetDescendantRectToMyCoords(nextFocused, mTempRect);
        int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
        doScrollY(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() - getPaddingBottom();
                if (daBottom - screenBottom < maxJump) {
                    scrollDelta = daBottom - screenBottom;
                }
            }
        }
        if (scrollDelta == 0) {
            return false;
        }
        doScrollY(direction == View.FOCUS_DOWN ? scrollDelta : -scrollDelta);
    }

    if (currentFocused != null && currentFocused.isFocused() && isOffScreen(currentFocused)) {
        // previously focused item still has focus and is off screen, give
        // it up (take it back to ourselves)
        // (also, need to temporarily force FOCUS_BEFORE_DESCENDANTS so we are
        // sure to
        // get it)
        final int descendantFocusability = getDescendantFocusability(); // save
        setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
        requestFocus();
        setDescendantFocusability(descendantFocusability); // restore
    }
    return true;
}

From source file:org.cm.podd.report.activity.ReportActivity.java

@Override
public boolean onSoftKeyAction(TextView view, int actionId, KeyEvent event) {
    switch (actionId) {
    case EditorInfo.IME_ACTION_NEXT:
        Log.d(TAG, "action NEXT");
        View nextTextView = view.focusSearch(View.FOCUS_DOWN);
        if (nextTextView != null) {
            nextTextView.requestFocus();
            if (!(nextTextView instanceof EditText)) {
                hideKeyboard();//w  ww  . ja  v a 2  s  .c o m
            }
            return true;
        }
    case EditorInfo.IME_ACTION_DONE:
        Log.d(TAG, "action DONE");
        nextScreen();
        hideKeyboard();
        return true;
    }
    return false;
}

From source file:com.hippo.widget.BothScrollView.java

/**
 * <p>Handles scrolling in response to a "page up/down" shortcut press. This
 * method will scroll the view by one page left or right and give the focus
 * to the leftmost/rightmost component in the new visible area. If no
 * component is a good candidate for focus, this scrollview reclaims the
 * focus.</p>// ww w  .  jav a 2s  .  co m
 *
 * @param direction the scroll direction: {@link android.view.View#FOCUS_LEFT}
 *                  to go one page left or {@link android.view.View#FOCUS_RIGHT}
 *                  to go one page right
 * @return true if the key event is consumed by this method, false otherwise
 */
public boolean pageScroll(int direction) {
    int width = getWidth();
    int height = getHeight();

    if (direction == View.FOCUS_UP) {
        mTempRect.top = getScrollY() - height;
        if (mTempRect.top < 0) {
            mTempRect.top = 0;
        }
        mTempRect.bottom = mTempRect.top + height;
        return scrollAndFocusVertically(direction, mTempRect.top, mTempRect.bottom);
    } else if (direction == View.FOCUS_DOWN) {
        mTempRect.top = getScrollY() + height;
        int count = getChildCount();
        if (count > 0) {
            View view = getChildAt(count - 1);
            if (mTempRect.top + height > view.getBottom()) {
                mTempRect.top = view.getBottom() - height;
            }
        }
        mTempRect.bottom = mTempRect.top + height;
        return scrollAndFocusVertically(direction, mTempRect.top, mTempRect.bottom);
    } else if (direction == View.FOCUS_LEFT) {
        mTempRect.left = getScrollX() - width;
        if (mTempRect.left < 0) {
            mTempRect.left = 0;
        }
        mTempRect.right = mTempRect.left + width;
        return scrollAndFocusHorizontally(direction, mTempRect.left, mTempRect.right);
    } else {
        mTempRect.left = getScrollX() + width;
        int count = getChildCount();
        if (count > 0) {
            View view = getChildAt(0);
            if (mTempRect.left + width > view.getRight()) {
                mTempRect.left = view.getRight() - width;
            }
        }
        mTempRect.right = mTempRect.left + width;
        return scrollAndFocusHorizontally(direction, mTempRect.left, mTempRect.right);
    }
}

From source file:com.android.ex.chips.RecipientEditTextView.java

private boolean focusNext() {
    final View next = focusSearch(View.FOCUS_DOWN);
    if (next != null) {
        next.requestFocus();//w  ww  .  jav  a  2  s . co m
        return true;
    }
    return false;
}

From source file:com.hippo.widget.BothScrollView.java

/**
 * <p>Handles scrolling in response to a "home/end" shortcut press. This
 * method will scroll the view to the left or right and give the focus
 * to the leftmost/rightmost component in the new visible area. If no
 * component is a good candidate for focus, this scrollview reclaims the
 * focus.</p>// w w w.ja  va  2 s .c  om
 *
 * @param direction the scroll direction: {@link android.view.View#FOCUS_LEFT}
 *                  to go the left of the view or {@link android.view.View#FOCUS_RIGHT}
 *                  to go the right
 * @return true if the key event is consumed by this method, false otherwise
 */
public boolean fullScroll(int direction) {
    if (direction == View.FOCUS_LEFT || direction == View.FOCUS_RIGHT) {
        boolean right = direction == View.FOCUS_RIGHT;
        int width = getWidth();

        mTempRect.left = 0;
        mTempRect.right = width;

        if (right) {
            int count = getChildCount();
            if (count > 0) {
                View view = getChildAt(0);
                mTempRect.right = view.getRight() + getPaddingRight();
                mTempRect.left = mTempRect.right - width;
            }
        }

        return scrollAndFocusHorizontally(direction, mTempRect.left, mTempRect.right);
    } else {
        boolean down = direction == View.FOCUS_DOWN;
        int height = getHeight();

        mTempRect.top = 0;
        mTempRect.bottom = height;

        if (down) {
            int count = getChildCount();
            if (count > 0) {
                View view = getChildAt(count - 1);
                mTempRect.bottom = view.getBottom() + getPaddingBottom();
                mTempRect.top = mTempRect.bottom - height;
            }
        }

        return scrollAndFocusVertically(direction, mTempRect.top, mTempRect.bottom);
    }
}

From source file:com.peerless2012.twowaynestedscrollview.TwoWayNestedScrollView.java

/**
 * Handle scrolling in response to an up or down arrow click.
 *
 * @param direction/* w w w .j a v  a 2 s .  co m*/
 *            The direction corresponding to the arrow key that was pressed
 * @return True if we consumed the event, false otherwise
 */
public boolean arrowScroll(int direction) {

    View currentFocused = findFocus();
    if (currentFocused == this)
        currentFocused = null;

    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);

    final int maxJump = getMaxScrollYAmount();

    if (nextFocused != null && isWithinDeltaOfScreen(nextFocused, maxJump, getHeight())) {
        nextFocused.getDrawingRect(mTempRect);
        offsetDescendantRectToMyCoords(nextFocused, mTempRect);
        int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(mTempRect);
        doScrollY(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() - getPaddingBottom();
                if (daBottom - screenBottom < maxJump) {
                    scrollDelta = daBottom - screenBottom;
                }
            }
        }
        if (scrollDelta == 0) {
            return false;
        }
        doScrollY(direction == View.FOCUS_DOWN ? scrollDelta : -scrollDelta);
    }

    if (currentFocused != null && currentFocused.isFocused() && isOffScreen(currentFocused)) {
        // previously focused item still has focus and is off screen, give
        // it up (take it back to ourselves)
        // (also, need to temporarily force FOCUS_BEFORE_DESCENDANTS so we
        // are
        // sure to
        // get it)
        final int descendantFocusability = getDescendantFocusability(); // save
        setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
        requestFocus();
        setDescendantFocusability(descendantFocusability); // restore
    }
    return true;
}