List of usage examples for android.view View requestFocus
public boolean requestFocus(int direction, Rect previouslyFocusedRect)
From source file:android.support.v17.leanback.widget.GridLayoutManager.java
private boolean gridOnRequestFocusInDescendantsAligned(RecyclerView recyclerView, int direction, Rect previouslyFocusedRect) {/*from w ww .j a v a 2 s.c o m*/ View view = findViewByPosition(mFocusPosition); if (view != null) { boolean result = view.requestFocus(direction, previouslyFocusedRect); if (!result && DEBUG) { Log.w(getTag(), "failed to request focus on " + view); } return result; } return false; }
From source file:android.support.v17.leanback.widget.GridLayoutManager.java
private boolean gridOnRequestFocusInDescendantsUnaligned(RecyclerView recyclerView, int direction, Rect previouslyFocusedRect) {/*from ww w.j a va 2 s. c o m*/ // focus to view not overlapping padding area to avoid scrolling in gaining focus int index; int increment; int end; int count = getChildCount(); if ((direction & View.FOCUS_FORWARD) != 0) { index = 0; increment = 1; end = count; } else { index = count - 1; increment = -1; end = -1; } int left = mWindowAlignment.mainAxis().getPaddingLow(); int right = mWindowAlignment.mainAxis().getClientSize() + left; for (int i = index; i != end; i += increment) { View child = getChildAt(i); if (child.getVisibility() == View.VISIBLE) { if (getViewMin(child) >= left && getViewMax(child) <= right) { if (child.requestFocus(direction, previouslyFocusedRect)) { return true; } } } } return false; }
From source file:org.bangbang.support.v4.widget.HListView.java
/** * To avoid horizontal focus searches changing the selected item, we * manually focus search within the selected item (as applicable), and * prevent focus from jumping to something within another item. * @param direction one of {View.FOCUS_LEFT, View.FOCUS_RIGHT} * @return Whether this consumes the key event. *//*from ww w . ja va 2s . c om*/ private boolean handleHorizontalFocusWithinListItem(int direction) { if (direction != View.FOCUS_UP && direction != View.FOCUS_DOWN) { throw new IllegalArgumentException("direction must be one of" + " {View.FOCUS_UP, View.FOCUS_DOWN}"); } final int numChildren = getChildCount(); if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) { final View selectedView = getSelectedView(); if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) { final View currentFocus = selectedView.findFocus(); final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView, currentFocus, direction); if (nextFocus != null) { // do the math to get interesting rect in next focus' coordinates currentFocus.getFocusedRect(mTempRect); offsetDescendantRectToMyCoords(currentFocus, mTempRect); offsetRectIntoDescendantCoords(nextFocus, mTempRect); if (nextFocus.requestFocus(direction, mTempRect)) { return true; } } // we are blocking the key from being handled (by returning true) // if the global result is going to be some other view within this // list. this is to acheive the overall goal of having // horizontal d-pad navigation remain in the current item. final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(), currentFocus, direction); if (globalNextFocus != null) { return isViewAncestorOf(globalNextFocus, this); } } } return false; }
From source file:com.zhongsou.souyue.ui.HListView.java
/** * To avoid horizontal focus searches changing the selected item, we manually focus search within the selected item (as * applicable), and prevent focus from jumping to something within another item. * * @param direction one of {View.FOCUS_LEFT, View.FOCUS_RIGHT} * @return Whether this consumes the key event. */// ww w. j a v a 2 s.c om private boolean handleHorizontalFocusWithinListItem(int direction) { // TODO: implement this if (direction != View.FOCUS_LEFT && direction != View.FOCUS_RIGHT) { throw new IllegalArgumentException("direction must be one of" + " {View.FOCUS_LEFT, View.FOCUS_RIGHT}"); } final int numChildren = getChildCount(); if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) { final View selectedView = getSelectedView(); if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) { final View currentFocus = selectedView.findFocus(); final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView, currentFocus, direction); if (nextFocus != null) { // do the math to get interesting rect in next focus' coordinates currentFocus.getFocusedRect(mTempRect); offsetDescendantRectToMyCoords(currentFocus, mTempRect); offsetRectIntoDescendantCoords(nextFocus, mTempRect); if (nextFocus.requestFocus(direction, mTempRect)) { return true; } } // we are blocking the key from being handled (by returning true) // if the global result is going to be some other view within this // list. this is to acheive the overall goal of having // horizontal d-pad navigation remain in the current item. final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(), currentFocus, direction); if (globalNextFocus != null) { return isViewAncestorOf(globalNextFocus, this); } } } return false; }
From source file:com.appunite.list.HorizontalListView.java
/** * To avoid horizontal focus searches changing the selected item, we * manually focus search within the selected item (as applicable), and * prevent focus from jumping to something within another item. * @param direction one of {View.FOCUS_LEFT, View.FOCUS_RIGHT} * @return Whether this consumes the key event. *//* w w w .j av a 2 s.c o m*/ private boolean handleHorizontalFocusWithinListItem(int direction) { if (direction != View.FOCUS_UP && direction != View.FOCUS_DOWN) { throw new IllegalArgumentException("direction must be one of" + " {View.FOCUS_UP, View.FOCUS_DOWN}"); } final int numChildren = getChildCount(); if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) { final View selectedView = getSelectedView(); if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) { final View currentFocus = selectedView.findFocus(); final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView, currentFocus, direction); if (nextFocus != null) { // do the math to get interesting rect in next focus' coordinates currentFocus.getFocusedRect(mTempRect); offsetDescendantRectToMyCoords(currentFocus, mTempRect); offsetRectIntoDescendantCoords(nextFocus, mTempRect); if (nextFocus.requestFocus(direction, mTempRect)) { return true; } } // we are blocking the key from being handled (by returning true) // if the global result is going to be some other view within this // list. this is to acheive the overall goal of having // horizontal d-pad navigation remain in the current item. final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(), currentFocus, direction); if (globalNextFocus != null) { return isViewAncestorOf(globalNextFocus, this); } } } return false; }
From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java
/** * To avoid horizontal focus searches changing the selected item, we manually focus search within the selected item (as * applicable), and prevent focus from jumping to something within another item. * //w w w . j av a2s. c o m * @param direction * one of {View.FOCUS_LEFT, View.FOCUS_RIGHT} * @return Whether this consumes the key event. */ private boolean handleHorizontalFocusWithinListItem(int direction) { // TODO: implement this if (direction != View.FOCUS_UP && direction != View.FOCUS_DOWN) { throw new IllegalArgumentException("direction must be one of" + " {View.FOCUS_UP, View.FOCUS_DOWN}"); } final int numChildren = getChildCount(); if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) { final View selectedView = getSelectedView(); if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) { final View currentFocus = selectedView.findFocus(); final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView, currentFocus, direction); if (nextFocus != null) { // do the math to get interesting rect in next focus' coordinates currentFocus.getFocusedRect(mTempRect); offsetDescendantRectToMyCoords(currentFocus, mTempRect); offsetRectIntoDescendantCoords(nextFocus, mTempRect); if (nextFocus.requestFocus(direction, mTempRect)) { return true; } } // we are blocking the key from being handled (by returning true) // if the global result is going to be some other view within this // list. this is to acheive the overall goal of having // horizontal d-pad navigation remain in the current item. final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(), currentFocus, direction); if (globalNextFocus != null) { return isViewAncestorOf(globalNextFocus, this); } } } return false; }
From source file:com.appunite.list.ListView.java
/** * To avoid horizontal focus searches changing the selected item, we * manually focus search within the selected item (as applicable), and * prevent focus from jumping to something within another item. * @param direction one of {View.FOCUS_LEFT, View.FOCUS_RIGHT} * @return Whether this consumes the key event. *///from w ww . j av a 2s .com private boolean handleHorizontalFocusWithinListItem(int direction) { if (direction != View.FOCUS_LEFT && direction != View.FOCUS_RIGHT) { throw new IllegalArgumentException("direction must be one of" + " {View.FOCUS_LEFT, View.FOCUS_RIGHT}"); } final int numChildren = getChildCount(); if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) { final View selectedView = getSelectedView(); if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) { final View currentFocus = selectedView.findFocus(); final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView, currentFocus, direction); if (nextFocus != null) { // do the math to get interesting rect in next focus' coordinates currentFocus.getFocusedRect(mTempRect); offsetDescendantRectToMyCoords(currentFocus, mTempRect); offsetRectIntoDescendantCoords(nextFocus, mTempRect); if (nextFocus.requestFocus(direction, mTempRect)) { return true; } } // we are blocking the key from being handled (by returning true) // if the global result is going to be some other view within this // list. this is to acheive the overall goal of having // horizontal d-pad navigation remain in the current item. final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(), currentFocus, direction); if (globalNextFocus != null) { return isViewAncestorOf(globalNextFocus, this); } } } return false; }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
/** * To avoid horizontal/vertical focus searches changing the selected item, * we manually focus search within the selected item (as applicable), and * prevent focus from jumping to something within another 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 av a2 s .com * * @return Whether this consumes the key event. */ private boolean handleFocusWithinItem(int direction) { forceValidInnerFocusDirection(direction); final int numChildren = getChildCount(); if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) { final View selectedView = getSelectedView(); if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) { final View currentFocus = selectedView.findFocus(); final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView, currentFocus, direction); if (nextFocus != null) { // Do the math to get interesting rect in next focus' coordinates currentFocus.getFocusedRect(mTempRect); offsetDescendantRectToMyCoords(currentFocus, mTempRect); offsetRectIntoDescendantCoords(nextFocus, mTempRect); if (nextFocus.requestFocus(direction, mTempRect)) { return true; } } // We are blocking the key from being handled (by returning true) // if the global result is going to be some other view within this // list. This is to achieve the overall goal of having horizontal/vertical // d-pad navigation remain in the current item depending on the current // orientation in this view. final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(), currentFocus, direction); if (globalNextFocus != null) { return isViewAncestorOf(globalNextFocus, this); } } } return false; }
From source file:com.artifex.mupdf.view.ThumbnailViews.java
/** * To avoid horizontal/vertical focus searches changing the selected item, * we manually focus search within the selected item (as applicable), and * prevent focus from jumping to something within another item. * //from w w w . j a 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 Whether this consumes the key event. */ private boolean handleFocusWithinItem(int direction) { forceValidInnerFocusDirection(direction); final int numChildren = getChildCount(); if (mItemsCanFocus && numChildren > 0 && mSelectedPosition != INVALID_POSITION) { final View selectedView = getSelectedView(); if (selectedView != null && selectedView.hasFocus() && selectedView instanceof ViewGroup) { final View currentFocus = selectedView.findFocus(); final View nextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) selectedView, currentFocus, direction); if (nextFocus != null) { // Do the math to get interesting rect in next focus' // coordinates currentFocus.getFocusedRect(mTempRect); offsetDescendantRectToMyCoords(currentFocus, mTempRect); offsetRectIntoDescendantCoords(nextFocus, mTempRect); if (nextFocus.requestFocus(direction, mTempRect)) { return true; } } // We are blocking the key from being handled (by returning // true) // if the global result is going to be some other view within // this // list. This is to achieve the overall goal of having // horizontal/vertical // d-pad navigation remain in the current item depending on the // current // orientation in this view. final View globalNextFocus = FocusFinder.getInstance().findNextFocus((ViewGroup) getRootView(), currentFocus, direction); if (globalNextFocus != null) { return isViewAncestorOf(globalNextFocus, this); } } } return false; }