List of usage examples for android.widget ListAdapter isEnabled
boolean isEnabled(int position);
From source file:com.appunite.list.HorizontalListView.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) { final int scrollX = getScrollX(); final int scrollY = getScrollY(); previouslyFocusedRect.offset(scrollX, scrollY); // 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 w w. ja va2s .c om } // 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(); } }
From source file:com.appunite.list.ListView.java
@Override protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); final ListAdapter adapter = mAdapter; int closetChildIndex = -1; int closestChildTop = 0; if (adapter != null && gainFocus && previouslyFocusedRect != null) { final int scrollX = getScrollX(); final int scrollY = getScrollY(); previouslyFocusedRect.offset(scrollX, scrollY); // Don't cache the result of getChildCount or mFirstPosition here, // it could change in layoutChildren. if (adapter.getCount() < getChildCount() + mFirstPosition) { mLayoutMode = LAYOUT_NORMAL; layoutChildren();/*from w ww . jav a2s.co 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; closestChildTop = other.getTop(); } } } if (closetChildIndex >= 0) { setSelectionFromTop(closetChildIndex + mFirstPosition, closestChildTop); } else { requestLayout(); } }
From source file:com.huewu.pla.lib.internal.PLAListView.java
@Override protected void dispatchDraw(final Canvas canvas) { // Draw the dividers final int dividerHeight = mDividerHeight; final Drawable overscrollHeader = mOverScrollHeader; final Drawable overscrollFooter = mOverScrollFooter; final boolean drawOverscrollHeader = overscrollHeader != null; final boolean drawOverscrollFooter = overscrollFooter != null; final boolean drawDividers = dividerHeight > 0 && mDivider != null; if (drawDividers || drawOverscrollHeader || drawOverscrollFooter) { // Only modify the top and bottom in the loop, we set the left and // right here final Rect bounds = mTempRect; // bounds.left = mPaddingLeft; // bounds.right = mRight - mLeft - mPaddingRight; bounds.left = getPaddingLeft();//w w w . ja v a 2 s. com bounds.right = getRight() - getLeft() - getPaddingRight(); final int count = getChildCount(); final int headerCount = mHeaderViewInfos.size(); final int itemCount = mItemCount; final int footerLimit = itemCount - mFooterViewInfos.size() - 1; final boolean headerDividers = mHeaderDividersEnabled; final boolean footerDividers = mFooterDividersEnabled; final int first = mFirstPosition; final boolean areAllItemsSelectable = mAreAllItemsSelectable; final ListAdapter adapter = mAdapter; // If the list is opaque *and* the background is not, we want to // fill a rect where the dividers would be for non-selectable items // If the list is opaque and the background is also opaque, we don't // need to draw anything since the background will do it for us final boolean fillForMissingDividers = drawDividers && isOpaque() && !super.isOpaque(); if (fillForMissingDividers && mDividerPaint == null && mIsCacheColorOpaque) { mDividerPaint = new Paint(); mDividerPaint.setColor(getCacheColorHint()); } final Paint paint = mDividerPaint; // final int listBottom = mBottom - mTop - mListPadding.bottom + // mScrollY; final int listBottom = getBottom() - getTop() - mListPadding.bottom + getScrollY(); if (!mStackFromBottom) { int bottom = 0; // Draw top divider or header for overscroll // final int scrollY = mScrollY; final int scrollY = getScrollY(); if (count > 0 && scrollY < 0) { if (drawOverscrollHeader) { bounds.bottom = 0; bounds.top = scrollY; drawOverscrollHeader(canvas, overscrollHeader, bounds); } else if (drawDividers) { bounds.bottom = 0; bounds.top = -dividerHeight; drawDivider(canvas, bounds, -1); } } for (int i = 0; i < count; i++) { if ((headerDividers || first + i >= headerCount) && (footerDividers || first + i < footerLimit)) { final View child = getChildAt(i); bottom = child.getBottom(); // Don't draw dividers next to items that are not // enabled if (drawDividers && bottom < listBottom && !(drawOverscrollFooter && i == count - 1)) { if (areAllItemsSelectable || adapter.isEnabled(first + i) && (i == count - 1 || adapter.isEnabled(first + i + 1))) { bounds.top = bottom; bounds.bottom = bottom + dividerHeight; drawDivider(canvas, bounds, i); } else if (fillForMissingDividers) { bounds.top = bottom; bounds.bottom = bottom + dividerHeight; canvas.drawRect(bounds, paint); } } } } // final int overFooterBottom = mBottom + mScrollY; final int overFooterBottom = getBottom() + getScrollY(); if (drawOverscrollFooter && first + count == itemCount && overFooterBottom > bottom) { bounds.top = bottom; bounds.bottom = overFooterBottom; drawOverscrollFooter(canvas, overscrollFooter, bounds); } } else { int top; final int listTop = mListPadding.top; // final int scrollY = mScrollY; final int scrollY = getScrollY(); if (count > 0 && drawOverscrollHeader) { bounds.top = scrollY; bounds.bottom = getChildAt(0).getTop(); drawOverscrollHeader(canvas, overscrollHeader, bounds); } final int start = drawOverscrollHeader ? 1 : 0; for (int i = start; i < count; i++) { if ((headerDividers || first + i >= headerCount) && (footerDividers || first + i < footerLimit)) { final View child = getChildAt(i); top = child.getTop(); // Don't draw dividers next to items that are not // enabled if (drawDividers && top > listTop) { if (areAllItemsSelectable || adapter.isEnabled(first + i) && (i == count - 1 || adapter.isEnabled(first + i + 1))) { bounds.top = top - dividerHeight; bounds.bottom = top; // Give the method the child ABOVE the divider, // so we // subtract one from our child // position. Give -1 when there is no child // above the // divider. drawDivider(canvas, bounds, i - 1); } else if (fillForMissingDividers) { bounds.top = top - dividerHeight; bounds.bottom = top; canvas.drawRect(bounds, paint); } } } } if (count > 0 && scrollY > 0) { if (drawOverscrollFooter) { // final int absListBottom = mBottom; final int absListBottom = getBottom(); bounds.top = absListBottom; bounds.bottom = absListBottom + scrollY; drawOverscrollFooter(canvas, overscrollFooter, bounds); } else if (drawDividers) { bounds.top = listBottom; bounds.bottom = listBottom + dividerHeight; drawDivider(canvas, bounds, -1); } } } } // Draw the indicators (these should be drawn above the dividers) and // children super.dispatchDraw(canvas); }
From source file:org.bangbang.support.v4.widget.HListView.java
@Override protected void dispatchDraw(Canvas canvas) { // Draw the dividers final int dividerHeight = mDividerWidth; if (dividerHeight > 0 && mDivider != null) { // Only modify the top and bottom in the loop, we set the left and right here final Rect bounds = mTempRect; bounds.left = getPaddingLeft(); bounds.right = getRight() - getLeft() - getPaddingRight(); final int count = getChildCount(); final int headerCount = mHeaderViewInfos.size(); final int footerLimit = mItemCount - mFooterViewInfos.size() - 1; final boolean headerDividers = mHeaderDividersEnabled; final boolean footerDividers = mFooterDividersEnabled; final int first = mFirstPosition; final boolean areAllItemsSelectable = mAreAllItemsSelectable; final ListAdapter adapter = mAdapter; // If the list is opaque *and* the background is not, we want to // fill a rect where the dividers would be for non-selectable items // If the list is opaque and the background is also opaque, we don't // need to draw anything since the background will do it for us final boolean fillForMissingDividers = ReflectUtil.view_isOpaque(this)//isOpaque() && !super.isOpaque(); if (fillForMissingDividers && mDividerPaint == null && mIsCacheColorOpaque) { mDividerPaint = new Paint(); mDividerPaint.setColor(getCacheColorHint()); }//from w ww .j a v a 2 s.com final Paint paint = mDividerPaint; if (!mStackFromBottom) { int bottom; int listBottom = getBottom() - getTop() - mListPadding.bottom; for (int i = 0; i < count; i++) { if ((headerDividers || first + i >= headerCount) && (footerDividers || first + i < footerLimit)) { View child = getChildAt(i); bottom = child.getBottom(); // Don't draw dividers next to items that are not enabled if (bottom < listBottom) { if ((areAllItemsSelectable || (adapter.isEnabled(first + i) && (i == count - 1 || adapter.isEnabled(first + i + 1))))) { bounds.top = bottom; bounds.bottom = bottom + dividerHeight; drawDivider(canvas, bounds, i); } else if (fillForMissingDividers) { bounds.top = bottom; bounds.bottom = bottom + dividerHeight; canvas.drawRect(bounds, paint); } } } } } else { int top; int listTop = mListPadding.top; for (int i = 0; i < count; i++) { if ((headerDividers || first + i >= headerCount) && (footerDividers || first + i < footerLimit)) { View child = getChildAt(i); top = child.getTop(); // Don't draw dividers next to items that are not enabled if (top > listTop) { if ((areAllItemsSelectable || (adapter.isEnabled(first + i) && (i == count - 1 || adapter.isEnabled(first + i + 1))))) { bounds.top = top - dividerHeight; bounds.bottom = top; // Give the method the child ABOVE the divider, so we // subtract one from our child // position. Give -1 when there is no child above the // divider. drawDivider(canvas, bounds, i - 1); } else if (fillForMissingDividers) { bounds.top = top - dividerHeight; bounds.bottom = top; canvas.drawRect(bounds, paint); } } } } } } // Draw the indicators (these should be drawn above the dividers) and children super.dispatchDraw(canvas); }
From source file:com.huewu.pla.lib.internal.PLA_ListView.java
@Override protected void dispatchDraw(Canvas canvas) { // Draw the dividers final int dividerHeight = mDividerHeight; final Drawable overscrollHeader = mOverScrollHeader; final Drawable overscrollFooter = mOverScrollFooter; final boolean drawOverscrollHeader = overscrollHeader != null; final boolean drawOverscrollFooter = overscrollFooter != null; final boolean drawDividers = dividerHeight > 0 && mDivider != null; if (drawDividers || drawOverscrollHeader || drawOverscrollFooter) { // Only modify the top and bottom in the loop, we set the left and // right here final Rect bounds = mTempRect; // bounds.left = mPaddingLeft; // bounds.right = mRight - mLeft - mPaddingRight; bounds.left = getPaddingLeft();/* w w w .j a v a 2s . c o m*/ bounds.right = getRight() - getLeft() - getPaddingRight(); final int count = getChildCount(); final int headerCount = mHeaderViewInfos.size(); final int itemCount = mItemCount; final int footerLimit = itemCount - mFooterViewInfos.size() - 1; final boolean headerDividers = mHeaderDividersEnabled; final boolean footerDividers = mFooterDividersEnabled; final int first = mFirstPosition; final boolean areAllItemsSelectable = mAreAllItemsSelectable; final ListAdapter adapter = mAdapter; // If the list is opaque *and* the background is not, we want to // fill a rect where the dividers would be for non-selectable items // If the list is opaque and the background is also opaque, we don't // need to draw anything since the background will do it for us final boolean fillForMissingDividers = drawDividers && isOpaque() && !super.isOpaque(); if (fillForMissingDividers && mDividerPaint == null && mIsCacheColorOpaque) { mDividerPaint = new Paint(); mDividerPaint.setColor(getCacheColorHint()); } final Paint paint = mDividerPaint; // final int listBottom = mBottom - mTop - mListPadding.bottom + // mScrollY; final int listBottom = getBottom() - getTop() - mListPadding.bottom + getScrollY(); if (!mStackFromBottom) { int bottom = 0; // Draw top divider or header for overscroll // final int scrollY = mScrollY; final int scrollY = getScrollY(); if (count > 0 && scrollY < 0) { if (drawOverscrollHeader) { bounds.bottom = 0; bounds.top = scrollY; drawOverscrollHeader(canvas, overscrollHeader, bounds); } else if (drawDividers) { bounds.bottom = 0; bounds.top = -dividerHeight; drawDivider(canvas, bounds, -1); } } for (int i = 0; i < count; i++) { if ((headerDividers || first + i >= headerCount) && (footerDividers || first + i < footerLimit)) { View child = getChildAt(i); bottom = child.getBottom(); // Don't draw dividers next to items that are not // enabled if (drawDividers && (bottom < listBottom && !(drawOverscrollFooter && i == count - 1))) { if ((areAllItemsSelectable || (adapter.isEnabled(first + i) && (i == count - 1 || adapter.isEnabled(first + i + 1))))) { bounds.top = bottom; bounds.bottom = bottom + dividerHeight; drawDivider(canvas, bounds, i); } else if (fillForMissingDividers) { bounds.top = bottom; bounds.bottom = bottom + dividerHeight; canvas.drawRect(bounds, paint); } } } } // final int overFooterBottom = mBottom + mScrollY; final int overFooterBottom = getBottom() + getScrollY(); if (drawOverscrollFooter && first + count == itemCount && overFooterBottom > bottom) { bounds.top = bottom; bounds.bottom = overFooterBottom; drawOverscrollFooter(canvas, overscrollFooter, bounds); } } else { int top; int listTop = mListPadding.top; // final int scrollY = mScrollY; final int scrollY = getScrollY(); if (count > 0 && drawOverscrollHeader) { bounds.top = scrollY; bounds.bottom = getChildAt(0).getTop(); drawOverscrollHeader(canvas, overscrollHeader, bounds); } final int start = drawOverscrollHeader ? 1 : 0; for (int i = start; i < count; i++) { if ((headerDividers || first + i >= headerCount) && (footerDividers || first + i < footerLimit)) { View child = getChildAt(i); top = child.getTop(); // Don't draw dividers next to items that are not // enabled if (drawDividers && top > listTop) { if ((areAllItemsSelectable || (adapter.isEnabled(first + i) && (i == count - 1 || adapter.isEnabled(first + i + 1))))) { bounds.top = top - dividerHeight; bounds.bottom = top; // Give the method the child ABOVE the divider, // so we // subtract one from our child // position. Give -1 when there is no child // above the // divider. drawDivider(canvas, bounds, i - 1); } else if (fillForMissingDividers) { bounds.top = top - dividerHeight; bounds.bottom = top; canvas.drawRect(bounds, paint); } } } } if (count > 0 && scrollY > 0) { if (drawOverscrollFooter) { // final int absListBottom = mBottom; final int absListBottom = getBottom(); bounds.top = absListBottom; bounds.bottom = absListBottom + scrollY; drawOverscrollFooter(canvas, overscrollFooter, bounds); } else if (drawDividers) { bounds.top = listBottom; bounds.bottom = listBottom + dividerHeight; drawDivider(canvas, bounds, -1); } } } } // Draw the indicators (these should be drawn above the dividers) and // children super.dispatchDraw(canvas); }
From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java
@Override protected void dispatchDraw(Canvas canvas) { if (mCachingStarted) { mCachingActive = true;/*from w w w. ja v a 2 s.com*/ } // Draw the dividers final int dividerWidth = mDividerWidth; final Drawable overscrollHeader = mOverScrollHeader; final Drawable overscrollFooter = mOverScrollFooter; final boolean drawOverscrollHeader = overscrollHeader != null; final boolean drawOverscrollFooter = overscrollFooter != null; final boolean drawDividers = dividerWidth > 0 && mDivider != null; if (drawDividers || drawOverscrollHeader || drawOverscrollFooter) { // Only modify the top and bottom in the loop, we set the left and right here final Rect bounds = mTempRect; bounds.top = getPaddingTop(); bounds.bottom = getBottom() - getTop() - getPaddingBottom(); final int count = getChildCount(); final int headerCount = mHeaderViewInfos.size(); final int itemCount = mItemCount; final int footerLimit = itemCount - mFooterViewInfos.size() - 1; final boolean headerDividers = mHeaderDividersEnabled; final boolean footerDividers = mFooterDividersEnabled; final int first = mFirstPosition; final boolean areAllItemsSelectable = mAreAllItemsSelectable; final ListAdapter adapter = mAdapter; // If the list is opaque *and* the background is not, we want to // fill a rect where the dividers would be for non-selectable items // If the list is opaque and the background is also opaque, we don't // need to draw anything since the background will do it for us final boolean fillForMissingDividers = isOpaque() && !super.isOpaque(); if (fillForMissingDividers && mDividerPaint == null && mIsCacheColorOpaque) { mDividerPaint = new Paint(); mDividerPaint.setColor(getCacheColorHint()); } final Paint paint = mDividerPaint; int effectivePaddingLeft = 0; int effectivePaddingRight = 0; // if ( ( mGroupFlags & CLIP_TO_PADDING_MASK ) == CLIP_TO_PADDING_MASK ) { // effectivePaddingTop = mListPadding.top; // effectivePaddingBottom = mListPadding.bottom; // } final int listRight = getRight() - getLeft() - effectivePaddingRight + getScrollX(); if (!mStackFromRight) { int right = 0; // Draw top divider or header for overscroll final int scrollX = getScrollX(); if (count > 0 && scrollX < 0) { if (drawOverscrollHeader) { bounds.right = 0; bounds.left = scrollX; drawOverscrollHeader(canvas, overscrollHeader, bounds); } else if (drawDividers) { bounds.right = 0; bounds.left = -dividerWidth; drawDivider(canvas, bounds, -1); } } for (int i = 0; i < count; i++) { if ((headerDividers || first + i >= headerCount) && (footerDividers || first + i < footerLimit)) { View child = getChildAt(i); right = child.getRight(); // Don't draw dividers next to items that are not enabled if (drawDividers && (right < listRight && !(drawOverscrollFooter && i == count - 1))) { if ((areAllItemsSelectable || (adapter.isEnabled(first + i) && (i == count - 1 || adapter.isEnabled(first + i + 1))))) { bounds.left = right; bounds.right = right + dividerWidth; drawDivider(canvas, bounds, i); } else if (fillForMissingDividers) { bounds.left = right; bounds.right = right + dividerWidth; canvas.drawRect(bounds, paint); } } } } final int overFooterBottom = getRight() + getScrollX(); if (drawOverscrollFooter && first + count == itemCount && overFooterBottom > right) { bounds.left = right; bounds.right = overFooterBottom; drawOverscrollFooter(canvas, overscrollFooter, bounds); } } else { int left; final int scrollX = getScrollX(); if (count > 0 && drawOverscrollHeader) { bounds.left = scrollX; bounds.right = getChildAt(0).getLeft(); drawOverscrollHeader(canvas, overscrollHeader, bounds); } final int start = drawOverscrollHeader ? 1 : 0; for (int i = start; i < count; i++) { if ((headerDividers || first + i >= headerCount) && (footerDividers || first + i < footerLimit)) { View child = getChildAt(i); left = child.getLeft(); // Don't draw dividers next to items that are not enabled if (left > effectivePaddingLeft) { if ((areAllItemsSelectable || (adapter.isEnabled(first + i) && (i == count - 1 || adapter.isEnabled(first + i + 1))))) { bounds.left = left - dividerWidth; bounds.right = left; // Give the method the child ABOVE the divider, so we // subtract one from our child // position. Give -1 when there is no child above the // divider. drawDivider(canvas, bounds, i - 1); } else if (fillForMissingDividers) { bounds.left = left - dividerWidth; bounds.right = left; canvas.drawRect(bounds, paint); } } } } if (count > 0 && scrollX > 0) { if (drawOverscrollFooter) { final int absListRight = getRight(); bounds.left = absListRight; bounds.right = absListRight + scrollX; drawOverscrollFooter(canvas, overscrollFooter, bounds); } else if (drawDividers) { bounds.left = listRight; bounds.right = listRight + dividerWidth; drawDivider(canvas, bounds, -1); } } } } // Draw the indicators (these should be drawn above the dividers) and children super.dispatchDraw(canvas); }
From source file:com.appunite.list.HorizontalListView.java
@Override protected void dispatchDraw(Canvas canvas) { if (mCachingStarted) { mCachingActive = true;/* w ww . j a v a 2s.c o m*/ } // Draw the dividers final int dividerWidth = mDividerWidth; final Drawable overscrollHeader = mOverScrollHeader; final Drawable overscrollFooter = mOverScrollFooter; final boolean drawOverscrollHeader = overscrollHeader != null; final boolean drawOverscrollFooter = overscrollFooter != null; final boolean drawDividers = dividerWidth > 0 && mDivider != null; if (drawDividers || drawOverscrollHeader || drawOverscrollFooter) { // Only modify the top and bottom in the loop, we set the left and right here final Rect bounds = mTempRect; bounds.top = getPaddingTop(); bounds.bottom = getBottom() - getTop() - getPaddingBottom(); final int count = getChildCount(); final int headerCount = mHeaderViewInfos.size(); final int itemCount = mItemCount; final int footerLimit = itemCount - mFooterViewInfos.size() - 1; final boolean headerDividers = mHeaderDividersEnabled; final boolean footerDividers = mFooterDividersEnabled; final int first = mFirstPosition; final boolean areAllItemsSelectable = mAreAllItemsSelectable; final ListAdapter adapter = mAdapter; // If the list is opaque *and* the background is not, we want to // fill a rect where the dividers would be for non-selectable items // If the list is opaque and the background is also opaque, we don't // need to draw anything since the background will do it for us final boolean fillForMissingDividers = isOpaque() && !super.isOpaque(); if (fillForMissingDividers && mDividerPaint == null && mIsCacheColorOpaque) { mDividerPaint = new Paint(); mDividerPaint.setColor(getCacheColorHint()); } final Paint paint = mDividerPaint; int effectivePaddingLeft = 0; int effectivePaddingRight = 0; if (mClipToPadding) { effectivePaddingLeft = mListPadding.left; effectivePaddingRight = mListPadding.right; } final int viewLeft = getLeft(); final int viewRight = getRight(); final int scrollX = getScrollX(); final int listRight = viewLeft - viewRight - effectivePaddingRight + scrollX; if (!mStackFromRight) { int right = 0; // Draw top divider or header for overscroll if (count > 0 && scrollX < 0) { if (drawOverscrollHeader) { bounds.right = 0; bounds.left = scrollX; drawOverscrollHeader(canvas, overscrollHeader, bounds); } else if (drawDividers) { bounds.right = 0; bounds.left = -dividerWidth; drawDivider(canvas, bounds, -1); } } for (int i = 0; i < count; i++) { if ((headerDividers || first + i >= headerCount) && (footerDividers || first + i < footerLimit)) { View child = getChildAt(i); right = child.getRight(); // Don't draw dividers next to items that are not enabled if (drawDividers && (right < listRight && !(drawOverscrollFooter && i == count - 1))) { if ((areAllItemsSelectable || (adapter.isEnabled(first + i) && (i == count - 1 || adapter.isEnabled(first + i + 1))))) { bounds.left = right; bounds.right = right + dividerWidth; drawDivider(canvas, bounds, i); } else if (fillForMissingDividers) { bounds.left = right; bounds.right = right + dividerWidth; canvas.drawRect(bounds, paint); } } } } final int overFooterRight = viewLeft + scrollX; if (drawOverscrollFooter && first + count == itemCount && overFooterRight > right) { bounds.left = right; bounds.right = overFooterRight; drawOverscrollFooter(canvas, overscrollFooter, bounds); } } else { int left; if (count > 0 && drawOverscrollHeader) { bounds.left = scrollX; bounds.right = getChildAt(0).getLeft(); drawOverscrollHeader(canvas, overscrollHeader, bounds); } final int start = drawOverscrollHeader ? 1 : 0; for (int i = start; i < count; i++) { if ((headerDividers || first + i >= headerCount) && (footerDividers || first + i < footerLimit)) { View child = getChildAt(i); left = child.getLeft(); // Don't draw dividers next to items that are not enabled if (left > effectivePaddingLeft) { if ((areAllItemsSelectable || (adapter.isEnabled(first + i) && (i == count - 1 || adapter.isEnabled(first + i + 1))))) { bounds.left = left - dividerWidth; bounds.right = left; // Give the method the child ABOVE the divider, so we // subtract one from our child // position. Give -1 when there is no child above the // divider. drawDivider(canvas, bounds, i - 1); } else if (fillForMissingDividers) { bounds.left = left - dividerWidth; bounds.right = left; canvas.drawRect(bounds, paint); } } } } if (count > 0 && scrollX > 0) { if (drawOverscrollFooter) { final int absListRight = viewLeft; bounds.left = absListRight; bounds.right = absListRight + scrollX; drawOverscrollFooter(canvas, overscrollFooter, bounds); } else if (drawDividers) { bounds.left = listRight; bounds.right = listRight + dividerWidth; drawDivider(canvas, bounds, -1); } } } } // Draw the indicators (these should be drawn above the dividers) and children super.dispatchDraw(canvas); }
From source file:com.appunite.list.ListView.java
@Override protected void dispatchDraw(Canvas canvas) { if (mCachingStarted) { mCachingActive = true;/*from w ww . j a v a 2 s .co m*/ } // Draw the dividers final int dividerHeight = mDividerHeight; final Drawable overscrollHeader = mOverScrollHeader; final Drawable overscrollFooter = mOverScrollFooter; final boolean drawOverscrollHeader = overscrollHeader != null; final boolean drawOverscrollFooter = overscrollFooter != null; final boolean drawDividers = dividerHeight > 0 && mDivider != null; if (drawDividers || drawOverscrollHeader || drawOverscrollFooter) { // Only modify the top and bottom in the loop, we set the left and right here final Rect bounds = mTempRect; bounds.left = getPaddingLeft(); bounds.right = getRight() - getLeft() - getPaddingRight(); final int count = getChildCount(); final int headerCount = mHeaderViewInfos.size(); final int itemCount = mItemCount; final int footerLimit = itemCount - mFooterViewInfos.size() - 1; final boolean headerDividers = mHeaderDividersEnabled; final boolean footerDividers = mFooterDividersEnabled; final int first = mFirstPosition; final boolean areAllItemsSelectable = mAreAllItemsSelectable; final ListAdapter adapter = mAdapter; // If the list is opaque *and* the background is not, we want to // fill a rect where the dividers would be for non-selectable items // If the list is opaque and the background is also opaque, we don't // need to draw anything since the background will do it for us final boolean fillForMissingDividers = isOpaque() && !super.isOpaque(); if (fillForMissingDividers && mDividerPaint == null && mIsCacheColorOpaque) { mDividerPaint = new Paint(); mDividerPaint.setColor(getCacheColorHint()); } final Paint paint = mDividerPaint; int effectivePaddingTop = 0; int effectivePaddingBottom = 0; if (mClipToPadding) { effectivePaddingTop = mListPadding.top; effectivePaddingBottom = mListPadding.bottom; } final int viewBottom = getBottom(); final int viewTop = getTop(); final int scrollY = getScrollY(); final int listBottom = viewBottom - viewTop - effectivePaddingBottom + scrollY; if (!mStackFromBottom) { int bottom = 0; // Draw top divider or header for overscroll if (count > 0 && scrollY < 0) { if (drawOverscrollHeader) { bounds.bottom = 0; bounds.top = scrollY; drawOverscrollHeader(canvas, overscrollHeader, bounds); } else if (drawDividers) { bounds.bottom = 0; bounds.top = -dividerHeight; drawDivider(canvas, bounds, -1); } } for (int i = 0; i < count; i++) { if ((headerDividers || first + i >= headerCount) && (footerDividers || first + i < footerLimit)) { View child = getChildAt(i); bottom = child.getBottom(); // Don't draw dividers next to items that are not enabled if (drawDividers && (bottom < listBottom && !(drawOverscrollFooter && i == count - 1))) { if ((areAllItemsSelectable || (adapter.isEnabled(first + i) && (i == count - 1 || adapter.isEnabled(first + i + 1))))) { bounds.top = bottom; bounds.bottom = bottom + dividerHeight; drawDivider(canvas, bounds, i); } else if (fillForMissingDividers) { bounds.top = bottom; bounds.bottom = bottom + dividerHeight; canvas.drawRect(bounds, paint); } } } } final int overFooterBottom = viewBottom + scrollY; if (drawOverscrollFooter && first + count == itemCount && overFooterBottom > bottom) { bounds.top = bottom; bounds.bottom = overFooterBottom; drawOverscrollFooter(canvas, overscrollFooter, bounds); } } else { int top; if (count > 0 && drawOverscrollHeader) { bounds.top = scrollY; bounds.bottom = getChildAt(0).getTop(); drawOverscrollHeader(canvas, overscrollHeader, bounds); } final int start = drawOverscrollHeader ? 1 : 0; for (int i = start; i < count; i++) { if ((headerDividers || first + i >= headerCount) && (footerDividers || first + i < footerLimit)) { View child = getChildAt(i); top = child.getTop(); // Don't draw dividers next to items that are not enabled if (top > effectivePaddingTop) { if ((areAllItemsSelectable || (adapter.isEnabled(first + i) && (i == count - 1 || adapter.isEnabled(first + i + 1))))) { bounds.top = top - dividerHeight; bounds.bottom = top; // Give the method the child ABOVE the divider, so we // subtract one from our child // position. Give -1 when there is no child above the // divider. drawDivider(canvas, bounds, i - 1); } else if (fillForMissingDividers) { bounds.top = top - dividerHeight; bounds.bottom = top; canvas.drawRect(bounds, paint); } } } } if (count > 0 && scrollY > 0) { if (drawOverscrollFooter) { final int absListBottom = viewBottom; bounds.top = absListBottom; bounds.bottom = absListBottom + scrollY; drawOverscrollFooter(canvas, overscrollFooter, bounds); } else if (drawDividers) { bounds.top = listBottom; bounds.bottom = listBottom + dividerHeight; drawDivider(canvas, bounds, -1); } } } } // Draw the indicators (these should be drawn above the dividers) and children super.dispatchDraw(canvas); }
From source file:com.appunite.list.AbsHorizontalListView.java
/** * {@inheritDoc}/* w w w .j a va 2 s .com*/ */ @Override public void addTouchables(ArrayList<View> views) { final int count = getChildCount(); final int firstPosition = mFirstPosition; final ListAdapter adapter = mAdapter; if (adapter == null) { return; } for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (adapter.isEnabled(firstPosition + i)) { views.add(child); } child.addTouchables(views); } }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
private int lookForSelectablePosition(int position, boolean lookDown) { final ListAdapter adapter = mAdapter; if (adapter == null || isInTouchMode()) { return INVALID_POSITION; }/*w w w .ja v a 2s .com*/ final int itemCount = mItemCount; if (!mAreAllItemsSelectable) { if (lookDown) { position = Math.max(0, position); while (position < itemCount && !adapter.isEnabled(position)) { position++; } } else { position = Math.min(position, itemCount - 1); while (position >= 0 && !adapter.isEnabled(position)) { position--; } } if (position < 0 || position >= itemCount) { return INVALID_POSITION; } return position; } else { if (position < 0 || position >= itemCount) { return INVALID_POSITION; } return position; } }