List of usage examples for android.widget ListAdapter isEnabled
boolean isEnabled(int position);
From source file:com.huewu.pla.lib.internal.PLA_ListView.java
@Override protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); if (DEBUG)/*w ww .j av a 2 s . co m*/ Log.v("PLA_ListView", "onFocusChanged"); int closetChildIndex = -1; if (gainFocus && previouslyFocusedRect != null) { // previouslyFocusedRect.offset(mScrollX, mScrollY); previouslyFocusedRect.offset(getScrollX(), getScrollY()); final ListAdapter adapter = mAdapter; // 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; } } } if (closetChildIndex >= 0) { setSelection(closetChildIndex + mFirstPosition); } else { requestLayout(); } }
From source file:org.bangbang.support.v4.widget.HListView.java
/** * @param direction either {@link android.view.View#FOCUS_UP} or * {@link android.view.View#FOCUS_DOWN}. * @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. *//*w ww . ja v a 2 s. c om*/ private int lookForSelectablePositionOnScreen(int direction) { final int firstPosition = mFirstPosition; if (direction == View.FOCUS_RIGHT) { int startPos = (mSelectedPosition != INVALID_POSITION) ? mSelectedPosition + 1 : firstPosition; if (startPos >= mAdapter.getCount()) { return INVALID_POSITION; } if (startPos < firstPosition) { startPos = firstPosition; } final int lastVisiblePos = getLastVisiblePosition(); final ListAdapter adapter = getAdapter(); for (int pos = startPos; pos <= lastVisiblePos; pos++) { if (adapter.isEnabled(pos) && getChildAt(pos - firstPosition).getVisibility() == View.VISIBLE) { return pos; } } } else { int last = firstPosition + getChildCount() - 1; int startPos = (mSelectedPosition != INVALID_POSITION) ? mSelectedPosition - 1 : firstPosition + getChildCount() - 1; if (startPos < 0) { return INVALID_POSITION; } if (startPos > last) { startPos = last; } final ListAdapter adapter = getAdapter(); 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:org.bangbang.support.v4.widget.HListView.java
@Override protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); int closetChildIndex = -1; if (gainFocus && previouslyFocusedRect != null) { previouslyFocusedRect.offset(getScrollX(), getScrollY()); // figure out which item should be selected based on previously // focused rect Rect otherRect = mTempRect;/*from w w w . j av a 2 s .c om*/ int minDistance = Integer.MAX_VALUE; final int childCount = getChildCount(); final int firstPosition = mFirstPosition; final ListAdapter adapter = mAdapter; 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; } } } if (closetChildIndex >= 0) { setSelection(closetChildIndex + mFirstPosition); } else { requestLayout(); } }
From source file:org.bangbang.support.v4.widget.HListView.java
@Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { boolean populated = super.dispatchPopulateAccessibilityEvent(event); // If the item count is less than 15 then subtract disabled items from the count and // position. Otherwise ignore disabled items. if (!populated) { int itemCount = 0; int currentItemIndex = getSelectedItemPosition(); ListAdapter adapter = getAdapter(); if (adapter != null) { final int count = adapter.getCount(); if (count < 15) { for (int i = 0; i < count; i++) { if (adapter.isEnabled(i)) { itemCount++; } else if (i <= currentItemIndex) { currentItemIndex--; }//from w w w . j a va2 s . c o m } } else { itemCount = count; } } event.setItemCount(itemCount); event.setCurrentItemIndex(currentItemIndex); } return populated; }
From source file:com.appunite.list.HorizontalListView.java
/** * @param direction either {@link android.view.View#FOCUS_UP} or * {@link android.view.View#FOCUS_DOWN}. * @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. *//*from w w w. j a v a 2 s. c o m*/ private int lookForSelectablePositionOnScreen(int direction) { final int firstPosition = mFirstPosition; if (direction == View.FOCUS_DOWN) { int startPos = (mSelectedPosition != INVALID_POSITION) ? mSelectedPosition + 1 : firstPosition; if (startPos >= mAdapter.getCount()) { return INVALID_POSITION; } if (startPos < firstPosition) { startPos = firstPosition; } final int lastVisiblePos = getLastVisiblePosition(); final ListAdapter adapter = getAdapter(); for (int pos = startPos; pos <= lastVisiblePos; pos++) { if (adapter.isEnabled(pos) && getChildAt(pos - firstPosition).getVisibility() == View.VISIBLE) { return pos; } } } else { int last = firstPosition + getChildCount() - 1; int startPos = (mSelectedPosition != INVALID_POSITION) ? mSelectedPosition - 1 : firstPosition + getChildCount() - 1; if (startPos < 0 || startPos >= mAdapter.getCount()) { return INVALID_POSITION; } if (startPos > last) { startPos = last; } final ListAdapter adapter = getAdapter(); 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:org.bangbang.support.v4.widget.HListView.java
/** * Find a position that can be selected (i.e., is not a separator). */*from www .j a va 2 s. c o m*/ * @param position The starting position to look at. * @param lookDown Whether to look down for other positions. * @return The next selectable position starting at position and then searching either up or * down. Returns {@link #INVALID_POSITION} if nothing can be found. */ @Override int lookForSelectablePosition(int position, boolean lookDown) { final ListAdapter adapter = mAdapter; if (adapter == null || isInTouchMode()) { return INVALID_POSITION; } final int count = adapter.getCount(); if (!mAreAllItemsSelectable) { if (lookDown) { position = Math.max(0, position); while (position < count && !adapter.isEnabled(position)) { position++; } } else { position = Math.min(position, count - 1); while (position >= 0 && !adapter.isEnabled(position)) { position--; } } if (position < 0 || position >= count) { return INVALID_POSITION; } return position; } else { if (position < 0 || position >= count) { return INVALID_POSITION; } return position; } }
From source file:com.appunite.list.HorizontalListView.java
/** * Find a position that can be selected (i.e., is not a separator). * * @param position The starting position to look at. * @param lookRight Whether to look down for other positions. * @return The next selectable position starting at position and then searching either up or * down. Returns {@link #INVALID_POSITION} if nothing can be found. *///from w ww. ja va 2s . co m @Override int lookForSelectablePosition(int position, boolean lookRight) { final ListAdapter adapter = mAdapter; if (adapter == null || isInTouchMode()) { return INVALID_POSITION; } final int count = adapter.getCount(); if (!mAreAllItemsSelectable) { if (lookRight) { position = Math.max(0, position); while (position < count && !adapter.isEnabled(position)) { position++; } } else { position = Math.min(position, count - 1); while (position >= 0 && !adapter.isEnabled(position)) { position--; } } if (position < 0 || position >= count) { return INVALID_POSITION; } return position; } else { if (position < 0 || position >= count) { return INVALID_POSITION; } return position; } }
From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java
/** * Find a position that can be selected (i.e., is not a separator). * /* w w w . j a va2 s .c o m*/ * @param position * The starting position to look at. * @param lookDown * Whether to look down for other positions. * @return The next selectable position starting at position and then searching either up or down. Returns * {@link #INVALID_POSITION} if nothing can be found. */ @Override protected int lookForSelectablePosition(int position, boolean lookDown) { final ListAdapter adapter = mAdapter; if (adapter == null || isInTouchMode()) { return INVALID_POSITION; } final int count = adapter.getCount(); if (!mAreAllItemsSelectable) { if (lookDown) { position = Math.max(0, position); while (position < count && !adapter.isEnabled(position)) { position++; } } else { position = Math.min(position, count - 1); while (position >= 0 && !adapter.isEnabled(position)) { position--; } } if (position < 0 || position >= count) { return INVALID_POSITION; } return position; } else { if (position < 0 || position >= count) { return INVALID_POSITION; } return position; } }
From source file:com.appunite.list.ListView.java
/** * Find a position that can be selected (i.e., is not a separator). * * @param position The starting position to look at. * @param lookDown Whether to look down for other positions. * @return The next selectable position starting at position and then searching either up or * down. Returns {@link #INVALID_POSITION} if nothing can be found. *///from w w w .j a v a 2 s. c o m @Override int lookForSelectablePosition(int position, boolean lookDown) { final ListAdapter adapter = mAdapter; if (adapter == null || isInTouchMode()) { return INVALID_POSITION; } final int count = adapter.getCount(); if (!mAreAllItemsSelectable) { if (lookDown) { position = Math.max(0, position); while (position < count && !adapter.isEnabled(position)) { position++; } } else { position = Math.min(position, count - 1); while (position >= 0 && !adapter.isEnabled(position)) { position--; } } if (position < 0 || position >= count) { return INVALID_POSITION; } return position; } else { if (position < 0 || position >= count) { return INVALID_POSITION; } return position; } }
From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java
@Override protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); final ListAdapter adapter = mAdapter; int closetChildIndex = -1; int closestChildLeft = 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();// w ww . j a v a 2 s.c o m } // 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; closestChildLeft = other.getLeft(); } } } if (closetChildIndex >= 0) { setSelectionFromLeft(closetChildIndex + mFirstPosition, closestChildLeft); } else { requestLayout(); } }