Example usage for android.view View FOCUS_LEFT

List of usage examples for android.view View FOCUS_LEFT

Introduction

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

Prototype

int FOCUS_LEFT

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

Click Source Link

Document

Use with #focusSearch(int) .

Usage

From source file:cn.ismartv.tvrecyclerview.widget.LinearLayoutManager.java

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

}

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.//from w  w  w. j ava  2s .  c  om
 *
 * @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./*from   ww w.j a va 2  s  .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.//  w  w  w  . j av  a 2 s .com
 * @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?/* w  w w  .ja va 2s  . 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.
 * //  w  ww.  ja v a 2s . com
 * @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.chenglong.muscle.ui.LazyViewPager.java

public boolean arrowScroll(int direction) {
    View currentFocused = findFocus();
    if (currentFocused == this)
        currentFocused = null;/*from w  w w  .j  a v  a 2  s  .co  m*/
    boolean handled = false;
    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
    if (nextFocused != null && nextFocused != currentFocused) {
        if (direction == View.FOCUS_LEFT) {
            // If there is nothing to the left, or this is causing us to
            // jump to the right, then what we really want to do is page
            // left.
            if (currentFocused != null && nextFocused.getLeft() >= currentFocused.getLeft()) {
                handled = pageLeft();
            } else {
                handled = nextFocused.requestFocus();
            }
        } else if (direction == View.FOCUS_RIGHT) {
            // 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.getLeft() <= currentFocused.getLeft()) {
                handled = pageRight();
            } else {
                handled = nextFocused.requestFocus();
            }
        }
    } else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) {
        // Trying to move left and nothing there; try to page.
        handled = pageLeft();
    } else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) {
        // Trying to move right and nothing there; try to page.
        handled = pageRight();
    }
    if (handled) {
        playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
    }
    return handled;
}

From source file:com.tylz.jiaoyanglogistics.view.LazyViewPager.java

public boolean arrowScroll(int direction) {
    View currentFocused = findFocus();
    if (currentFocused == this) {
        currentFocused = null;//from   w  ww. j  ava 2s .  c  om
    }

    boolean handled = false;

    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
    if (nextFocused != null && nextFocused != currentFocused) {
        if (direction == View.FOCUS_LEFT) {
            // If there is nothing to the left, or this is causing us to
            // jump to the right, then what we really want to do is page left.
            if (currentFocused != null && nextFocused.getLeft() >= currentFocused.getLeft()) {
                handled = pageLeft();
            } else {
                handled = nextFocused.requestFocus();
            }
        } else if (direction == View.FOCUS_RIGHT) {
            // 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.getLeft() <= currentFocused.getLeft()) {
                handled = pageRight();
            } else {
                handled = nextFocused.requestFocus();
            }
        }
    } else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) {
        // Trying to move left and nothing there; try to page.
        handled = pageLeft();
    } else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) {
        // Trying to move right and nothing there; try to page.
        handled = pageRight();
    }
    if (handled) {
        playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
    }
    return handled;
}

From source file:com.tencent.tws.assistant.support.v4.view.ViewPager.java

public boolean arrowScroll(int direction) {
    View currentFocused = findFocus();
    if (currentFocused == this)
        currentFocused = null;//from   w  w  w  . j  a  va  2s  .  c  o  m

    boolean handled = false;
    // tws-start::modify this view must be descendant 20141230
    if (currentFocused != null) {
        ViewParent mParent = currentFocused.getParent();
        if (mParent == null) {
            return handled;
        }
    }
    // tws-end::modify this view must be descendant 20141230
    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
    if (nextFocused != null && nextFocused != currentFocused) {
        if (direction == View.FOCUS_LEFT) {
            // If there is nothing to the left, or this is causing us to
            // jump to the right, then what we really want to do is page left.
            if (currentFocused != null && nextFocused.getLeft() >= currentFocused.getLeft()) {
                handled = pageLeft();
            } else {
                handled = nextFocused.requestFocus();
            }
        } else if (direction == View.FOCUS_RIGHT) {
            // 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.getLeft() <= currentFocused.getLeft()) {
                handled = pageRight();
            } else {
                handled = nextFocused.requestFocus();
            }
        }
    } else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) {
        // Trying to move left and nothing there; try to page.
        handled = pageLeft();
    } else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) {
        // Trying to move right and nothing there; try to page.
        handled = pageRight();
    }
    if (handled) {
        playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
    }
    return handled;
}

From source file:beichen.douban.ui.view.LazyViewPager.java

public boolean arrowScroll(int direction) {
    View currentFocused = findFocus();
    if (currentFocused == this)
        currentFocused = null;//from  w  w  w.  j  a  v  a2  s.  c  om

    boolean handled = false;

    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
    if (nextFocused != null && nextFocused != currentFocused) {
        if (direction == View.FOCUS_LEFT) {
            // If there is nothing to the left, or this is causing us to
            // jump to the right, then what we really want to do is page
            // left.
            if (currentFocused != null && nextFocused.getLeft() >= currentFocused.getLeft()) {
                handled = pageLeft();
            } else {
                handled = nextFocused.requestFocus();
            }
        } else if (direction == View.FOCUS_RIGHT) {
            // 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.getLeft() <= currentFocused.getLeft()) {
                handled = pageRight();
            } else {
                handled = nextFocused.requestFocus();
            }
        }
    } else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) {
        // Trying to move left and nothing there; try to page.
        handled = pageLeft();
    } else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) {
        // Trying to move right and nothing there; try to page.
        handled = pageRight();
    }
    if (handled) {
        playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
    }
    return handled;
}