protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
mInLayout = true;
+ final int childCount = getChildCount();
if (changed) {
- int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
getChildAt(i).forceLayout();
}
mRecycler.markChildrenDirty();
}
- if (mFastScroller != null && (mItemCount != mOldItemCount || mDataChanged)) {
- mFastScroller.onItemCountChanged(mItemCount);
- }
-
layoutChildren();
mInLayout = false;
mOverscrollMax = (b - t) / OVERSCROLL_LIMIT_DIVISOR;
+
+ // TODO: Move somewhere sane. This doesn't belong in onLayout().
+ if (mFastScroller != null) {
+ mFastScroller.onItemCountChanged(getChildCount(), mItemCount);
+ }
}
/**
mHasPendingDrag = false;
}
};
+ private int mOldItemCount;
+ private int mOldChildCount;
/**
* Used to delay hiding fast scroll decorations.
public FastScroller(AbsListView listView) {
mList = listView;
mOverlay = listView.getOverlay();
+ mOldItemCount = listView.getCount();
+ mOldChildCount = listView.getChildCount();
final Context context = listView.getContext();
mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
final ImageView trackImage = new ImageView(context);
mTrackImage = trackImage;
+ updateLongList(mOldChildCount, mOldItemCount);
int width = 0;
// Add track to overlay if it has an image.
updateLayout();
}
- public void onItemCountChanged(int totalItemCount) {
- final int visibleItemCount = mList.getChildCount();
- final boolean hasMoreItems = totalItemCount - visibleItemCount > 0;
- if (hasMoreItems && mState != STATE_DRAGGING) {
- final int firstVisibleItem = mList.getFirstVisiblePosition();
- setThumbPos(getPosFromItemCount(firstVisibleItem, visibleItemCount, totalItemCount));
- }
+ public void onItemCountChanged(int childCount, int itemCount) {
+ if (mOldItemCount != itemCount || mOldChildCount != childCount) {
+ mOldItemCount = itemCount;
+ mOldChildCount = childCount;
- updateLongList(visibleItemCount, totalItemCount);
+ final boolean hasMoreItems = itemCount - childCount > 0;
+ if (hasMoreItems && mState != STATE_DRAGGING) {
+ final int firstVisibleItem = mList.getFirstVisiblePosition();
+ setThumbPos(getPosFromItemCount(firstVisibleItem, childCount, itemCount));
+ }
+
+ updateLongList(childCount, itemCount);
+ }
}
- private void updateLongList(int visibleItemCount, int totalItemCount) {
- final boolean longList = visibleItemCount > 0
- && totalItemCount / visibleItemCount >= MIN_PAGES;
+ private void updateLongList(int childCount, int itemCount) {
+ final boolean longList = childCount > 0 && itemCount / childCount >= MIN_PAGES;
if (mLongList != longList) {
mLongList = longList;