Java Code Examples for android.view.View#FOCUS_RIGHT

The following examples show how to use android.view.View#FOCUS_RIGHT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PagedView.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean dispatchUnhandledMove(View focused, int direction) {
    // XXX-RTL: This will be fixed in a future CL
    if (direction == View.FOCUS_LEFT) {
        if (getCurrentPage() > 0) {
            snapToPage(getCurrentPage() - 1);
            return true;
        }
    } else if (direction == View.FOCUS_RIGHT) {
        if (getCurrentPage() < getPageCount() - 1) {
            snapToPage(getCurrentPage() + 1);
            return true;
        }
    }
    return super.dispatchUnhandledMove(focused, direction);
}
 
Example 2
Source File: HorizontalScrollView.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * <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>
 *
 * @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) {
    boolean right = direction == View.FOCUS_RIGHT;
    int width = getWidth();

    if (right) {
        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;
            }
        }
    } else {
        mTempRect.left = getScrollX() - width;
        if (mTempRect.left < 0) {
            mTempRect.left = 0;
        }
    }
    mTempRect.right = mTempRect.left + width;

    return scrollAndFocus(direction, mTempRect.left, mTempRect.right);
}
 
Example 3
Source File: HorizontalScrollView.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * <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>
 *
 * @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) {
    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();
            mTempRect.left = mTempRect.right - width;
        }
    }

    return scrollAndFocus(direction, mTempRect.left, mTempRect.right);
}
 
Example 4
Source File: AwWebContentsDelegateAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void handleKeyboardEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        int direction;
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_DPAD_DOWN:
                direction = View.FOCUS_DOWN;
                break;
            case KeyEvent.KEYCODE_DPAD_UP:
                direction = View.FOCUS_UP;
                break;
            case KeyEvent.KEYCODE_DPAD_LEFT:
                direction = View.FOCUS_LEFT;
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                direction = View.FOCUS_RIGHT;
                break;
            default:
                direction = 0;
                break;
        }
        if (direction != 0 && tryToMoveFocus(direction)) return;
    }
    mContentsClient.onUnhandledKeyEvent(event);
}
 
Example 5
Source File: PagedView.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchUnhandledMove(View focused, int direction) {
    // XXX-RTL: This will be fixed in a future CL
    if (direction == View.FOCUS_LEFT) {
        if (getCurrentPage() > 0) {
            snapToPage(getCurrentPage() - 1);
            return true;
        }
    } else if (direction == View.FOCUS_RIGHT) {
        if (getCurrentPage() < getPageCount() - 1) {
            snapToPage(getCurrentPage() + 1);
            return true;
        }
    }
    return super.dispatchUnhandledMove(focused, direction);
}
 
Example 6
Source File: TrendScrollViewWidget.java    From LotteryTrend with Apache License 2.0 6 votes vote down vote up
public boolean fullScrollH(int direction) {
	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();
			mTempRect.left = mTempRect.right - width;
		}
	}

	return scrollAndFocusH(direction, mTempRect.left, mTempRect.right);
}
 
Example 7
Source File: PagedView.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addFocusables(ArrayList<View> views, int direction, int focusableMode) {
    if (getDescendantFocusability() == FOCUS_BLOCK_DESCENDANTS) {
        return;
    }

    // XXX-RTL: This will be fixed in a future CL
    if (mCurrentPage >= 0 && mCurrentPage < getPageCount()) {
        getPageAt(mCurrentPage).addFocusables(views, direction, focusableMode);
    }
    if (direction == View.FOCUS_LEFT) {
        if (mCurrentPage > 0) {
            getPageAt(mCurrentPage - 1).addFocusables(views, direction, focusableMode);
        }
    } else if (direction == View.FOCUS_RIGHT){
        if (mCurrentPage < getPageCount() - 1) {
            getPageAt(mCurrentPage + 1).addFocusables(views, direction, focusableMode);
        }
    }
}
 
Example 8
Source File: PagedView.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean dispatchUnhandledMove(View focused, int direction) {
    if (super.dispatchUnhandledMove(focused, direction)) {
        return true;
    }

    if (mIsRtl) {
        if (direction == View.FOCUS_LEFT) {
            direction = View.FOCUS_RIGHT;
        } else if (direction == View.FOCUS_RIGHT) {
            direction = View.FOCUS_LEFT;
        }
    }
    if (direction == View.FOCUS_LEFT) {
        if (getCurrentPage() > 0) {
            snapToPage(getCurrentPage() - 1);
            return true;
        }
    } else if (direction == View.FOCUS_RIGHT) {
        if (getCurrentPage() < getPageCount() - 1) {
            snapToPage(getCurrentPage() + 1);
            return true;
        }
    }
    return false;
}
 
Example 9
Source File: ViewPagerLayoutManager.java    From ViewPagerLayoutManager with Apache License 2.0 6 votes vote down vote up
private int getMovement(int direction) {
    if (mOrientation == VERTICAL) {
        if (direction == View.FOCUS_UP) {
            return mShouldReverseLayout ? DIRECTION_FORWARD : DIRECTION_BACKWARD;
        } else if (direction == View.FOCUS_DOWN) {
            return mShouldReverseLayout ? DIRECTION_BACKWARD : DIRECTION_FORWARD;
        } else {
            return DIRECTION_NO_WHERE;
        }
    } else {
        if (direction == View.FOCUS_LEFT) {
            return mShouldReverseLayout ? DIRECTION_FORWARD : DIRECTION_BACKWARD;
        } else if (direction == View.FOCUS_RIGHT) {
            return mShouldReverseLayout ? DIRECTION_BACKWARD : DIRECTION_FORWARD;
        } else {
            return DIRECTION_NO_WHERE;
        }
    }
}
 
Example 10
Source File: PLAAbsListView.java    From Lay-s with MIT License 5 votes vote down vote up
/**
 * What is the distance between the source and destination rectangles given the direction of
 * focus navigation between them? The direction basically helps figure out more quickly what is
 * self evident by the relationship between the rects...
 *
 * @param source the source rectangle
 * @param dest the destination rectangle
 * @param direction the direction
 * @return the distance between the rectangles
 */
static int getDistance(Rect source, Rect dest, int direction) {
    int sX, sY; // source x, y
    int dX, dY; // dest x, y
    switch (direction) {
        case View.FOCUS_RIGHT:
            sX = source.right;
            sY = source.top + source.height() / 2;
            dX = dest.left;
            dY = dest.top + dest.height() / 2;
            break;
        case View.FOCUS_DOWN:
            sX = source.left + source.width() / 2;
            sY = source.bottom;
            dX = dest.left + dest.width() / 2;
            dY = dest.top;
            break;
        case View.FOCUS_LEFT:
            sX = source.left;
            sY = source.top + source.height() / 2;
            dX = dest.right;
            dY = dest.top + dest.height() / 2;
            break;
        case View.FOCUS_UP:
            sX = source.left + source.width() / 2;
            sY = source.top;
            dX = dest.left + dest.width() / 2;
            dY = dest.bottom;
            break;
        default:
            throw new IllegalArgumentException("direction must be one of "
                    + "{FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT}.");
    }
    int deltaX = dX - sX;
    int deltaY = dY - sY;
    return deltaY * deltaY + deltaX * deltaX;
}
 
Example 11
Source File: CustomViewAbove.java    From WeatherStream with Apache License 2.0 5 votes vote down vote up
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_LEFT) {
			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;
}
 
Example 12
Source File: BothScrollView.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
/**
 * When looking for focus in children of a scroll view, need to be a little
 * more careful not to give focus to something that is scrolled off screen.
 *
 * This is more expensive than the default {@link android.view.ViewGroup}
 * implementation, otherwise this behavior might have been made the default.
 */
@Override
protected boolean onRequestFocusInDescendants(int direction,
        Rect previouslyFocusedRect) {

    // convert from forward / backward notation to up / down / left / right
    // (ugh).
    if (direction == View.FOCUS_FORWARD) {
        direction = View.FOCUS_RIGHT;
    } else if (direction == View.FOCUS_BACKWARD) {
        direction = View.FOCUS_LEFT;
    }

    final View nextFocus = previouslyFocusedRect == null ?
            FocusFinder.getInstance().findNextFocus(this, null, direction) :
            FocusFinder.getInstance().findNextFocusFromRect(this,
                    previouslyFocusedRect, direction);

    if (nextFocus == null) {
        return false;
    }

    if (isOffScreen(nextFocus)) {
        return false;
    }

    return nextFocus.requestFocus(direction, previouslyFocusedRect);
}
 
Example 13
Source File: AwWebContentsDelegateAdapter.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public boolean takeFocus(boolean reverse) {
    int direction =
        (reverse == (mContainerView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL)) ?
        View.FOCUS_RIGHT : View.FOCUS_LEFT;
    if (tryToMoveFocus(direction)) return true;
    direction = reverse ? View.FOCUS_UP : View.FOCUS_DOWN;
    return tryToMoveFocus(direction);
}
 
Example 14
Source File: CustomViewAbove.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
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_LEFT) {
			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;
}
 
Example 15
Source File: StaggeredGridLayoutManager.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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.
 */
private 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;
    }

}
 
Example 16
Source File: LinearLayoutManager.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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.
 */
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;
    }

}
 
Example 17
Source File: LazyViewPager.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
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_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;
}
 
Example 18
Source File: ChatLinearLayoutManager.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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.
 */
private int convertFocusDirectionToLayoutDirection(int focusDirection) {
    switch (focusDirection) {
        case View.FOCUS_BACKWARD:
            return LayoutState.LAYOUT_START;
        case View.FOCUS_FORWARD:
            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;
    }

}
 
Example 19
Source File: HeaderLayoutManagerFixed.java    From android-parallax-recyclerview with Apache License 2.0 5 votes vote down vote up
/**
 * 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 RenderState#LAYOUT_START} or {@link RenderState#LAYOUT_END} if focus direction
 * is applicable to current state, {@link RenderState#INVALID_LAYOUT} otherwise.
 */
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;
    }

}
 
Example 20
Source File: VerticalPager.java    From freepager with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchUnhandledMove(View focused, int direction) {
	if (direction == View.FOCUS_LEFT) {
		if (getCurrentPage() > 0) {
			snapToPage(getCurrentPage() - 1);
			return true;
		}
	} else if (direction == View.FOCUS_RIGHT) {
		if (getCurrentPage() < getChildCount() - 1) {
			snapToPage(getCurrentPage() + 1);
			return true;
		}
	}
	return super.dispatchUnhandledMove(focused, direction);
}