List of usage examples for android.view View addFocusables
public void addFocusables(ArrayList<View> views, @FocusDirection int direction, @FocusableMode int focusableMode)
From source file:administrator.example.com.myscrollview.VerticalViewPager.java
/** * We only want the current page that is being shown to be focusable. *///from ww w . j av a2s . c o m @Override public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { final int focusableCount = views.size(); final int descendantFocusability = getDescendantFocusability(); if (descendantFocusability != FOCUS_BLOCK_DESCENDANTS) { for (int i = 0; i < getChildCount(); i++) { final View child = getChildAt(i); if (child.getVisibility() == VISIBLE) { ItemInfo ii = infoForChild(child); if (ii != null && ii.position == mCurItem) { child.addFocusables(views, direction, focusableMode); } /* end of if */ } /* end of if */ } /* end of for */ } /* end of if */ // we add ourselves (if focusable) in all cases except for when we are // FOCUS_AFTER_DESCENDANTS and there are some descendants focusable. this is // to avoid the focus search finding layouts when a more precise search // among the focusable children would be more interesting. if (descendantFocusability != FOCUS_AFTER_DESCENDANTS || // No focusable descendants (focusableCount == views.size())) { // Note that we can't call the superclass here, because it will // add all views in. So we need to do the same thing View does. if (!isFocusable()) { return; } /* end of if */ if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && isInTouchMode() && !isFocusableInTouchMode()) { return; } /* end of if */ if (views != null) { views.add(this); } /* end of if */ } /* end of if */ }
From source file:com.example.view.VerticalViewPager.java
/** * We only want the current page that is being shown to be focusable. *//* w w w . j av a 2s .c o m*/ @Override public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { final int focusableCount = views.size(); final int descendantFocusability = getDescendantFocusability(); if (descendantFocusability != FOCUS_BLOCK_DESCENDANTS) { for (int i = 0; i < getChildCount(); i++) { final View child = getChildAt(i); if (child.getVisibility() == VISIBLE) { ItemInfo ii = infoForChild(child); if (ii != null && ii.position == mCurItem) { child.addFocusables(views, direction, focusableMode); } /* end of if */ } /* end of if */ } /* end of for */ } /* end of if */ // we add ourselves (if focusable) in all cases except for when we are // FOCUS_AFTER_DESCENDANTS and there are some descendants focusable. // this is // to avoid the focus search finding layouts when a more precise search // among the focusable children would be more interesting. if (descendantFocusability != FOCUS_AFTER_DESCENDANTS || // No focusable descendants (focusableCount == views.size())) { // Note that we can't call the superclass here, because it will // add all views in. So we need to do the same thing View does. if (!isFocusable()) { return; } /* end of if */ if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && isInTouchMode() && !isFocusableInTouchMode()) { return; } /* end of if */ if (views != null) { views.add(this); } /* end of if */ } /* end of if */ }
From source file:com.jackie.sample.custom_view.CustomViewPagerInternal.java
/** * We only want the current page that is being shown to be focusable. *//* w w w . java2 s. c o m*/ @Override public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { final int focusableCount = views.size(); final int descendantFocusability = getDescendantFocusability(); if (descendantFocusability != FOCUS_BLOCK_DESCENDANTS) { for (int i = 0; i < getChildCount(); i++) { final View child = getChildAt(i); if (child.getVisibility() == VISIBLE) { ItemInfo ii = infoForChild(child); if (ii != null && ii.position == mCurItem) { child.addFocusables(views, direction, focusableMode); } } } } // we add ourselves (if focusable) in all cases except for when we are // FOCUS_AFTER_DESCENDANTS and there are some descendants focusable. this is // to avoid the focus search finding layouts when a more precise search // among the focusable children would be more interesting. if (descendantFocusability != FOCUS_AFTER_DESCENDANTS || // No focusable descendants (focusableCount == views.size())) { // Note that we can't call the superclass here, because it will // add all views in. So we need to do the same thing View does. if (!isFocusable()) { return; } if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && isInTouchMode() && !isFocusableInTouchMode()) { return; } if (views != null) { views.add(this); } } }
From source file:com.isapp.android.circularviewpager.CircularViewPager.java
/** * We only want the current page that is being shown to be focusable. *//* ww w .j a v a2 s .c o m*/ @Override public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { final int focusableCount = views.size(); final int descendantFocusability = getDescendantFocusability(); if (descendantFocusability != FOCUS_BLOCK_DESCENDANTS) { for (int i = 0; i < getChildCount(); i++) { final View child = getChildAt(i); if (child.getVisibility() == VISIBLE) { ItemInfo ii = infoForChild(child); if (ii != null && ii.position == mCurItem) { child.addFocusables(views, direction, focusableMode); } } } } // we add ourselves (if focusable) in all cases except for when we are // FOCUS_AFTER_DESCENDANTS and there are some descendants focusable. this is // to avoid the focus search finding layouts when a more precise search // among the focusable children would be more interesting. if (descendantFocusability != FOCUS_AFTER_DESCENDANTS || // No focusable descendants (focusableCount == views.size())) { // Note that we can't call the superclass here, because it will // add all views in. So we need to do the same thing View does. if (!isFocusable()) { return; } if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && isInTouchMode() && !isFocusableInTouchMode()) { return; } if (views != null) { views.add(this); } } }
From source file:VerticalViewPager.java
/** * We only want the current page that is being shown to be focusable. *///from w w w . ja va 2 s . c om @Override public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { final int focusableCount = views.size(); final int descendantFocusability = getDescendantFocusability(); if (descendantFocusability != FOCUS_BLOCK_DESCENDANTS) { for (int i = 0; i < getChildCount(); i++) { final View child = getChildAt(i); if (child.getVisibility() == VISIBLE) { ItemInfo ii = infoForChild(child); if (ii != null && ii.position == mCurItem) { child.addFocusables(views, direction, focusableMode); } } } } // we add ourselves (if focusable) in all cases except for when we are // FOCUS_AFTER_DESCENDANTS and there are some descendants focusable. this is // to avoid the focus search finding layouts when a more precise search // among the focusable children would be more interesting. if (descendantFocusability != FOCUS_AFTER_DESCENDANTS || // No focusable descendants (focusableCount == views.size())) { // Note that we can't call the superclass here, because it will // add all views in. So we need to do the same thing View does. if (!isFocusable()) { return; } if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && isInTouchMode() && !isFocusableInTouchMode()) { return; } if (views != null) { views.add(this); } } }
From source file:com.honeywell.printer.tabhost.CustomViewPager.java
/** * We only want the current page that is being shown to be focusable. *//*from w w w . j av a2 s . c o m*/ @Override public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { if (views == null) { throw new IllegalStateException("addFocusables views is null"); } final int focusableCount = views.size(); final int descendantFocusability = getDescendantFocusability(); if (descendantFocusability != FOCUS_BLOCK_DESCENDANTS) { for (int i = 0; i < getChildCount(); i++) { final View child = getChildAt(i); if (child.getVisibility() == VISIBLE) { ItemInfo ii = infoForChild(child); if (ii != null && ii.position == mCurItem) { child.addFocusables(views, direction, focusableMode); } } } } // we add ourselves (if focusable) in all cases except for when we are // FOCUS_AFTER_DESCENDANTS and there are some descendants focusable. this is // to avoid the focus search finding layouts when a more precise search // among the focusable children would be more interesting. if (descendantFocusability != FOCUS_AFTER_DESCENDANTS || // No focusable descendants (focusableCount == views.size())) { // Note that we can't call the superclass here, because it will // add all views in. So we need to do the same thing View does. if (!isFocusable()) { return; } if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && isInTouchMode() && !isFocusableInTouchMode()) { return; } if (views != null) { views.add(this); } } }
From source file:com.example.sky.test.view.ViewPager.java
/** * We only want the current page that is being shown to be focusable. *///from ww w .j ava 2 s .c o m @Override public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { final int focusableCount = views.size(); final int descendantFocusability = getDescendantFocusability(); if (descendantFocusability != FOCUS_BLOCK_DESCENDANTS) { for (int i = 0; i < getChildCount(); i++) { final View child = getChildAt(i); if (child.getVisibility() == VISIBLE) { ItemInfo ii = infoForChild(child); if (ii != null && ii.position == mCurItem) { child.addFocusables(views, direction, focusableMode); } } } } // we add ourselves (if focusable) in all cases except for when we are // FOCUS_AFTER_DESCENDANTS and there are some descendants focusable. this is // to avoid the focus search finding layouts when a more precise search // among the focusable children would be more interesting. if (descendantFocusability != FOCUS_AFTER_DESCENDANTS || (focusableCount == views.size())) { // No focusable descendants // Note that we can't call the superclass here, because it will // add all views in. So we need to do the same thing View does. if (!isFocusable()) { return; } if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && isInTouchMode() && !isFocusableInTouchMode()) { return; } if (views != null) { views.add(this); } } }
From source file:android.support.v17.leanback.widget.GridLayoutManager.java
@Override public boolean onAddFocusables(RecyclerView recyclerView, ArrayList<View> views, int direction, int focusableMode) { if (mFocusSearchDisabled) { return true; }/*w ww .j a v a 2 s .c o m*/ // If this viewgroup or one of its children currently has focus then we // consider our children for focus searching in main direction on the same row. // If this viewgroup has no focus and using focus align, we want the system // to ignore our children and pass focus to the viewgroup, which will pass // focus on to its children appropriately. // If this viewgroup has no focus and not using focus align, we want to // consider the child that does not overlap with padding area. if (recyclerView.hasFocus()) { if (mPendingMoveSmoothScroller != null) { // don't find next focusable if has pending movement. return true; } final int movement = getMovement(direction); final View focused = recyclerView.findFocus(); final int focusedIndex = findImmediateChildIndex(focused); final int focusedPos = getPositionByIndex(focusedIndex); // Add focusables of focused item. if (focusedPos != NO_POSITION) { findViewByPosition(focusedPos).addFocusables(views, direction, focusableMode); } if (mGrid == null || getChildCount() == 0) { // no grid information, or no child, bail out. return true; } if ((movement == NEXT_ROW || movement == PREV_ROW) && mGrid.getNumRows() <= 1) { // For single row, cannot navigate to previous/next row. return true; } // Add focusables of neighbor depending on the focus search direction. final int focusedRow = mGrid != null && focusedPos != NO_POSITION ? mGrid.getLocation(focusedPos).row : NO_POSITION; final int focusableCount = views.size(); int inc = movement == NEXT_ITEM || movement == NEXT_ROW ? 1 : -1; int loop_end = inc > 0 ? getChildCount() - 1 : 0; int loop_start; if (focusedIndex == NO_POSITION) { loop_start = inc > 0 ? 0 : getChildCount() - 1; } else { loop_start = focusedIndex + inc; } for (int i = loop_start; inc > 0 ? i <= loop_end : i >= loop_end; i += inc) { final View child = getChildAt(i); if (child.getVisibility() != View.VISIBLE || !child.hasFocusable()) { continue; } // if there wasn't any focusing item, add the very first focusable // items and stop. if (focusedPos == NO_POSITION) { child.addFocusables(views, direction, focusableMode); if (views.size() > focusableCount) { break; } continue; } int position = getPositionByIndex(i); Grid.Location loc = mGrid.getLocation(position); if (loc == null) { continue; } if (movement == NEXT_ITEM) { // Add first focusable item on the same row if (loc.row == focusedRow && position > focusedPos) { child.addFocusables(views, direction, focusableMode); if (views.size() > focusableCount) { break; } } } else if (movement == PREV_ITEM) { // Add first focusable item on the same row if (loc.row == focusedRow && position < focusedPos) { child.addFocusables(views, direction, focusableMode); if (views.size() > focusableCount) { break; } } } else if (movement == NEXT_ROW) { // Add all focusable items after this item whose row index is bigger if (loc.row == focusedRow) { continue; } else if (loc.row < focusedRow) { break; } child.addFocusables(views, direction, focusableMode); } else if (movement == PREV_ROW) { // Add all focusable items before this item whose row index is smaller if (loc.row == focusedRow) { continue; } else if (loc.row > focusedRow) { break; } child.addFocusables(views, direction, focusableMode); } } } else { int focusableCount = views.size(); if (mFocusScrollStrategy != BaseGridView.FOCUS_SCROLL_ALIGNED) { // adding views not overlapping padding area to avoid scrolling in gaining focus int left = mWindowAlignment.mainAxis().getPaddingLow(); int right = mWindowAlignment.mainAxis().getClientSize() + left; for (int i = 0, count = getChildCount(); i < count; i++) { View child = getChildAt(i); if (child.getVisibility() == View.VISIBLE) { if (getViewMin(child) >= left && getViewMax(child) <= right) { child.addFocusables(views, direction, focusableMode); } } } // if we cannot find any, then just add all children. if (views.size() == focusableCount) { for (int i = 0, count = getChildCount(); i < count; i++) { View child = getChildAt(i); if (child.getVisibility() == View.VISIBLE) { child.addFocusables(views, direction, focusableMode); } } } } else { View view = findViewByPosition(mFocusPosition); if (view != null) { view.addFocusables(views, direction, focusableMode); } } // if still cannot find any, fall through and add itself if (views.size() != focusableCount) { return true; } if (recyclerView.isFocusable()) { views.add(recyclerView); } } return true; }
From source file:io.github.clendy.leanback.widget.GridLayoutManager.java
@Override public boolean onAddFocusables(RecyclerView recyclerView, ArrayList<View> views, int direction, int focusableMode) { if (mFocusSearchDisabled) { return true; }//from ww w . j av a2 s .c o m // If this viewgroup or one of its children currently has focus then we // consider our children for focus searching in main direction on the same row. // If this viewgroup has no focus and using focus align, we want the system // to ignore our children and pass focus to the viewgroup, which will pass // focus on to its children appropriately. // If this viewgroup has no focus and not using focus align, we want to // consider the child that does not overlap with padding area. if (recyclerView.hasFocus()) { final int movement = getMovement(direction); if (movement != PREV_ITEM && movement != NEXT_ITEM) { // Move on secondary direction uses default addFocusables(). return false; } if (mPendingMoveSmoothScroller != null) { // don't find next focusable if has pending movement. return true; } final View focused = recyclerView.findFocus(); final int focusedPos = getPositionByIndex(findImmediateChildIndex(focused)); // Add focusables of focused item. if (focusedPos != NO_POSITION) { findViewByPosition(focusedPos).addFocusables(views, direction, focusableMode); } final int focusedRow = mGrid != null && focusedPos != NO_POSITION ? mGrid.getLocation(focusedPos).row : NO_POSITION; // Add focusables of next neighbor of same row on the focus search direction. if (mGrid != null) { final int focusableCount = views.size(); for (int i = 0, count = getChildCount(); i < count; i++) { int index = movement == NEXT_ITEM ? i : count - 1 - i; final View child = getChildAt(index); if (child.getVisibility() != View.VISIBLE || !child.hasFocusable()) { continue; } int position = getPositionByIndex(index); Grid.Location loc = mGrid.getLocation(position); if (focusedRow == NO_POSITION || (loc != null && loc.row == focusedRow)) { if (focusedPos == NO_POSITION || (movement == NEXT_ITEM && position > focusedPos) || (movement == PREV_ITEM && position < focusedPos)) { child.addFocusables(views, direction, focusableMode); if (views.size() > focusableCount) { break; } } } } } } else { if (mFocusScrollStrategy != BaseGridView.FOCUS_SCROLL_ALIGNED) { // adding views not overlapping padding area to avoid scrolling in gaining focus int left = mWindowAlignment.mainAxis().getPaddingLow(); int right = mWindowAlignment.mainAxis().getClientSize() + left; int focusableCount = views.size(); for (int i = 0, count = getChildCount(); i < count; i++) { View child = getChildAt(i); if (child.getVisibility() == View.VISIBLE) { if (getViewMin(child) >= left && getViewMax(child) <= right) { child.addFocusables(views, direction, focusableMode); } } } // if we cannot find any, then just add all children. if (views.size() == focusableCount) { for (int i = 0, count = getChildCount(); i < count; i++) { View child = getChildAt(i); if (child.getVisibility() == View.VISIBLE) { child.addFocusables(views, direction, focusableMode); } } if (views.size() != focusableCount) { return true; } } else { return true; } // if still cannot find any, fall through and add itself } if (recyclerView.isFocusable()) { views.add(recyclerView); } } return true; }