List of usage examples for android.widget ListAdapter isEnabled
boolean isEnabled(int position);
From source file:com.aliasapps.seq.scroller.TwoWayView.java
/** * @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 www. ja v a 2 s. co m*/ * * @return The position of the next selectable position of the views that * are currently visible, taking into account the fact that there might * be no selection. Returns {@link #INVALID_POSITION} if there is no * selectable view on screen in the given direction. */ private int lookForSelectablePositionOnScreen(int direction) { forceValidFocusDirection(direction); final int firstPosition = mFirstPosition; final ListAdapter adapter = getAdapter(); if (direction == View.FOCUS_DOWN || direction == View.FOCUS_RIGHT) { int startPos = (mSelectedPosition != INVALID_POSITION ? mSelectedPosition + 1 : firstPosition); if (startPos >= adapter.getCount()) { return INVALID_POSITION; } if (startPos < firstPosition) { startPos = firstPosition; } final int lastVisiblePos = getLastVisiblePosition(); for (int pos = startPos; pos <= lastVisiblePos; pos++) { if (adapter.isEnabled(pos) && getChildAt(pos - firstPosition).getVisibility() == View.VISIBLE) { return pos; } } } else { final int last = firstPosition + getChildCount() - 1; int startPos = (mSelectedPosition != INVALID_POSITION) ? mSelectedPosition - 1 : firstPosition + getChildCount() - 1; if (startPos < 0 || startPos >= adapter.getCount()) { return INVALID_POSITION; } if (startPos > last) { startPos = last; } for (int pos = startPos; pos >= firstPosition; pos--) { if (adapter.isEnabled(pos) && getChildAt(pos - firstPosition).getVisibility() == View.VISIBLE) { return pos; } } } return INVALID_POSITION; }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
@Override protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); if (gainFocus && mSelectedPosition < 0 && !isInTouchMode()) { if (!mIsAttached && mAdapter != null) { // Data may have changed while we were detached and it's valid // to change focus while detached. Refresh so we don't die. mDataChanged = true;/* w ww .j a v a 2 s. c o m*/ mOldItemCount = mItemCount; mItemCount = mAdapter.getCount(); } resurrectSelection(); } final ListAdapter adapter = mAdapter; int closetChildIndex = INVALID_POSITION; int closestChildStart = 0; if (adapter != null && gainFocus && previouslyFocusedRect != null) { previouslyFocusedRect.offset(getScrollX(), getScrollY()); // Don't cache the result of getChildCount or mFirstPosition here, // it could change in layoutChildren. if (adapter.getCount() < getChildCount() + mFirstPosition) { mLayoutMode = LAYOUT_NORMAL; layoutChildren(); } // Figure out which item should be selected based on previously // focused rect. Rect otherRect = mTempRect; int minDistance = Integer.MAX_VALUE; final int childCount = getChildCount(); final int firstPosition = mFirstPosition; for (int i = 0; i < childCount; i++) { // Only consider selectable views if (!adapter.isEnabled(firstPosition + i)) { continue; } View other = getChildAt(i); other.getDrawingRect(otherRect); offsetDescendantRectToMyCoords(other, otherRect); int distance = getDistance(previouslyFocusedRect, otherRect, direction); if (distance < minDistance) { minDistance = distance; closetChildIndex = i; closestChildStart = (mIsVertical ? other.getTop() : other.getLeft()); } } } if (closetChildIndex >= 0) { setSelectionFromOffset(closetChildIndex + mFirstPosition, closestChildStart); } else { requestLayout(); } }
From source file:com.artifex.mupdflib.TwoWayView.java
@Override protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); if (gainFocus && mSelectedPosition < 0 && !isInTouchMode()) { if (!mIsAttached && mAdapter != null) { // Data may have changed while we were detached and it's valid // to change focus while detached. Refresh so we don't die. mDataChanged = true;//www . j av a 2 s. c om mOldItemCount = mItemCount; mItemCount = mAdapter.getCount(); } resurrectSelection(); } final ListAdapter adapter = mAdapter; int closetChildIndex = INVALID_POSITION; int closestChildStart = 0; if (adapter != null && gainFocus && previouslyFocusedRect != null) { previouslyFocusedRect.offset(getScrollX(), getScrollY()); // Don't cache the result of getChildCount or mFirstPosition here, // it could change in layoutChildren. if (adapter.getCount() < getChildCount() + mFirstPosition) { mLayoutMode = LAYOUT_NORMAL; layoutChildren(); } // Figure out which item should be selected based on previously // focused rect. Rect otherRect = mTempRect; int minDistance = Integer.MAX_VALUE; final int childCount = getChildCount(); final int firstPosition = mFirstPosition; for (int i = 0; i < childCount; i++) { // Only consider selectable views if (!adapter.isEnabled(firstPosition + i)) { continue; } View other = getChildAt(i); other.getDrawingRect(otherRect); offsetDescendantRectToMyCoords(other, otherRect); int distance = getDistance(previouslyFocusedRect, otherRect, direction); if (distance < minDistance) { minDistance = distance; closetChildIndex = i; closestChildStart = getChildStartEdge(other); } } } if (closetChildIndex >= 0) { setSelectionFromOffset(closetChildIndex + mFirstPosition, closestChildStart); } else { requestLayout(); } }