List of usage examples for android.view View FOCUS_DOWN
int FOCUS_DOWN
To view the source code for android.view View FOCUS_DOWN.
Click Source Link
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 w w. ja va 2 s . co 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 ww . j a va 2 s .c o m*/ * * @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.j a v a2s . c o m*/ * * @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.skytree.epubtest.BookViewActivity.java
public void moveSearchScrollViewToEnd() { searchScrollView.post(new Runnable() { @Override//w w w . j av a 2 s . c o m public void run() { searchScrollView.fullScroll(View.FOCUS_DOWN); } }); }
From source file:com.appunite.list.GridView.java
/** * Is childIndex a candidate for next focus given the direction the focus * change is coming from?/* ww w . jav a 2 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.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./* w w w .ja v a 2s . c o 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.//from ww w. j a va 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) { 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. * /* w ww.ja v a 2 s .co m*/ * @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 ww w.j a va2s . c o 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?/*from w ww.j a v a 2 s .com*/ * @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; }