Merge "Fix bugs 3077517 and 3309579 - ListView bugs" into honeycomb

This commit is contained in:
Adam Powell
2011-01-12 23:50:05 -08:00
committed by Android (Google) Code Review

View File

@@ -2323,7 +2323,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
} }
if (mPositionScroller != null) { if (mPositionScroller != null) {
removeCallbacks(mPositionScroller); mPositionScroller.stop();
} }
if (mClearScrollingCache != null) { if (mClearScrollingCache != null) {
@@ -2353,6 +2353,9 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
// let the fling runnable report it's new state which // let the fling runnable report it's new state which
// should be idle // should be idle
mFlingRunnable.endFling(); mFlingRunnable.endFling();
if (mPositionScroller != null) {
mPositionScroller.stop();
}
if (mScrollY != 0) { if (mScrollY != 0) {
mScrollY = 0; mScrollY = 0;
finishGlows(); finishGlows();
@@ -2720,6 +2723,9 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
if (mFlingRunnable != null) { if (mFlingRunnable != null) {
mFlingRunnable.endFling(); mFlingRunnable.endFling();
} }
if (mPositionScroller != null) {
mPositionScroller.stop();
}
if (mScrollY != 0) { if (mScrollY != 0) {
mScrollY = 0; mScrollY = 0;
@@ -2760,6 +2766,9 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
switch (mTouchMode) { switch (mTouchMode) {
case TOUCH_MODE_OVERFLING: { case TOUCH_MODE_OVERFLING: {
mFlingRunnable.endFling(); mFlingRunnable.endFling();
if (mPositionScroller != null) {
mPositionScroller.stop();
}
mTouchMode = TOUCH_MODE_OVERSCROLL; mTouchMode = TOUCH_MODE_OVERSCROLL;
mMotionY = mLastY = (int) ev.getY(); mMotionY = mLastY = (int) ev.getY();
mMotionCorrection = 0; mMotionCorrection = 0;
@@ -3102,6 +3111,9 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
if (mFlingRunnable != null) { if (mFlingRunnable != null) {
mFlingRunnable.endFling(); mFlingRunnable.endFling();
} }
if (mPositionScroller != null) {
mPositionScroller.stop();
}
} }
} }
} else { } else {
@@ -3508,6 +3520,11 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
} else { } else {
mEdgeGlowBottom.onAbsorb(vel); mEdgeGlowBottom.onAbsorb(vel);
} }
} else {
mTouchMode = TOUCH_MODE_REST;
if (mPositionScroller != null) {
mPositionScroller.stop();
}
} }
invalidate(); invalidate();
post(this); post(this);
@@ -3526,9 +3543,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
removeCallbacks(this); removeCallbacks(this);
removeCallbacks(mCheckFlywheel); removeCallbacks(mCheckFlywheel);
if (mPositionScroller != null) {
removeCallbacks(mPositionScroller);
}
reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
clearScrollingCache(); clearScrollingCache();
@@ -3679,6 +3693,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
} }
void start(int position) { void start(int position) {
stop();
final int firstPos = mFirstPosition; final int firstPos = mFirstPosition;
final int lastPos = firstPos + getChildCount() - 1; final int lastPos = firstPos + getChildCount() - 1;
@@ -3707,6 +3723,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
} }
void start(int position, int boundPosition) { void start(int position, int boundPosition) {
stop();
if (boundPosition == INVALID_POSITION) { if (boundPosition == INVALID_POSITION) {
start(position); start(position);
return; return;
@@ -3770,6 +3788,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
} }
void startWithOffset(int position, int offset, int duration) { void startWithOffset(int position, int offset, int duration) {
stop();
mTargetPos = position; mTargetPos = position;
mOffsetFromTop = offset; mOffsetFromTop = offset;
mBoundPos = INVALID_POSITION; mBoundPos = INVALID_POSITION;
@@ -3947,11 +3967,22 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
final int position = mTargetPos; final int position = mTargetPos;
final int lastPos = firstPos + childCount - 1; final int lastPos = firstPos + childCount - 1;
int viewTravelCount = 0;
if (position < firstPos) { if (position < firstPos) {
smoothScrollBy(-getHeight(), mScrollDuration); viewTravelCount = firstPos - position + 1;
} else if (position > lastPos) {
viewTravelCount = position - lastPos;
}
// Estimate how many screens we should travel
final float screenTravelCount = (float) viewTravelCount / childCount;
final float modifier = Math.min(Math.abs(screenTravelCount), 1.f);
if (position < firstPos) {
smoothScrollBy((int) (-getHeight() * modifier), mScrollDuration);
post(this); post(this);
} else if (position > lastPos) { } else if (position > lastPos) {
smoothScrollBy(getHeight(), mScrollDuration); smoothScrollBy((int) (getHeight() * modifier), mScrollDuration);
post(this); post(this);
} else { } else {
// On-screen, just scroll. // On-screen, just scroll.
@@ -4067,12 +4098,26 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
if (mFlingRunnable == null) { if (mFlingRunnable == null) {
mFlingRunnable = new FlingRunnable(); mFlingRunnable = new FlingRunnable();
} }
// No sense starting to scroll if we're not going anywhere // No sense starting to scroll if we're not going anywhere
if (distance != 0) { final int firstPos = mFirstPosition;
final int childCount = getChildCount();
final int lastPos = firstPos + childCount;
final int topLimit = getPaddingTop();
final int bottomLimit = getHeight() - getPaddingBottom();
if (distance == 0 ||
firstPos == INVALID_POSITION ||
(firstPos == 0 && getChildAt(0).getTop() == topLimit && distance < 0) ||
(lastPos == mItemCount - 1 &&
getChildAt(childCount - 1).getBottom() == bottomLimit && distance > 0)) {
mFlingRunnable.endFling();
if (mPositionScroller != null) {
mPositionScroller.stop();
}
} else {
reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING); reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
mFlingRunnable.startScroll(distance, duration); mFlingRunnable.startScroll(distance, duration);
} else {
mFlingRunnable.endFling();
} }
} }
@@ -4519,7 +4564,9 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
mResurrectToPosition = INVALID_POSITION; mResurrectToPosition = INVALID_POSITION;
removeCallbacks(mFlingRunnable); removeCallbacks(mFlingRunnable);
removeCallbacks(mPositionScroller); if (mPositionScroller != null) {
mPositionScroller.stop();
}
mTouchMode = TOUCH_MODE_REST; mTouchMode = TOUCH_MODE_REST;
clearScrollingCache(); clearScrollingCache();
mSpecificTop = selectedTop; mSpecificTop = selectedTop;