diff options
| author | 2009-08-31 17:46:47 -0700 | |
|---|---|---|
| committer | 2009-08-31 17:46:47 -0700 | |
| commit | 0f44220b34e346ef333cdb4cd4b4903b5212dad2 (patch) | |
| tree | 557acb04c88a4903e7efd125e56c1c07b3a88317 | |
| parent | ad82219718cd1751dcf84bab0cd1aedcb6805eb1 (diff) | |
| parent | 6198ae8468668bf7374535c2eeeab8de7f8e7e99 (diff) | |
Merge change 23381 into eclair
* changes:
Prevent ListView from scrolling/flinging its content when the content fits on screen.
| -rw-r--r-- | core/java/android/view/View.java | 1 | ||||
| -rw-r--r-- | core/java/android/widget/AbsListView.java | 35 | ||||
| -rw-r--r-- | core/java/android/widget/ListView.java | 30 |
3 files changed, 42 insertions, 24 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 425ccabd1acf..d56922020441 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -46,7 +46,6 @@ import android.os.SystemClock; import android.os.SystemProperties; import android.util.AttributeSet; import android.util.Config; -import android.util.DisplayMetrics; import android.util.EventLog; import android.util.Log; import android.util.Pool; diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index 67721c936fed..2f292d58aeb2 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -1996,7 +1996,10 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te if (y != mLastY) { deltaY -= mMotionCorrection; int incrementalDeltaY = mLastY != Integer.MIN_VALUE ? y - mLastY : deltaY; - trackMotionScroll(deltaY, incrementalDeltaY); + // No need to do all this work if we're not going to move anyway + if (incrementalDeltaY != 0) { + trackMotionScroll(deltaY, incrementalDeltaY); + } // Check to see if we have bumped into the scroll limit View motionView = this.getChildAt(mMotionPosition - mFirstPosition); @@ -2063,7 +2066,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te if (mSelector != null) { Drawable d = mSelector.getCurrent(); if (d != null && d instanceof TransitionDrawable) { - ((TransitionDrawable)d).resetTransition(); + ((TransitionDrawable) d).resetTransition(); } } postDelayed(new Runnable() { @@ -2087,15 +2090,27 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te mTouchMode = TOUCH_MODE_REST; break; case TOUCH_MODE_SCROLL: - final VelocityTracker velocityTracker = mVelocityTracker; - velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); - final int initialVelocity = (int) velocityTracker.getYVelocity(); - if (Math.abs(initialVelocity) > mMinimumVelocity && (getChildCount() > 0)) { - if (mFlingRunnable == null) { - mFlingRunnable = new FlingRunnable(); + final int childCount = getChildCount(); + if (childCount > 0) { + if (mFirstPosition == 0 && getChildAt(0).getTop() >= mListPadding.top && + mFirstPosition + childCount < mItemCount && + getChildAt(childCount - 1).getBottom() <= + getHeight() - mListPadding.bottom) { + mTouchMode = TOUCH_MODE_REST; + reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); + } else { + final VelocityTracker velocityTracker = mVelocityTracker; + velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); + final int initialVelocity = (int) velocityTracker.getYVelocity(); + + if (Math.abs(initialVelocity) > mMinimumVelocity) { + if (mFlingRunnable == null) { + mFlingRunnable = new FlingRunnable(); + } + reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING); + mFlingRunnable.start(-initialVelocity); + } } - reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING); - mFlingRunnable.start(-initialVelocity); } else { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java index 993b7cbcdb45..6316864c24d1 100644 --- a/core/java/android/widget/ListView.java +++ b/core/java/android/widget/ListView.java @@ -1328,19 +1328,23 @@ public class ListView extends AbsListView { // Make sure we are 1) Too low, and 2) Either there are more rows below the // last row or the last row is scrolled off the bottom of the drawable area - if (topOffset > 0 && (lastPosition < mItemCount - 1 || lastBottom > end)) { - if (lastPosition == mItemCount - 1 ) { - // Don't pull the bottom too far up - topOffset = Math.min(topOffset, lastBottom - end); - } - // Move everything up - offsetChildrenTopAndBottom(-topOffset); - if (lastPosition < mItemCount - 1) { - // Fill the gap that was opened below the last position with more rows, if - // possible - fillDown(lastPosition + 1, lastChild.getBottom() + mDividerHeight); - // Close up the remaining gap - adjustViewsUpOrDown(); + if (topOffset > 0) { + if (lastPosition < mItemCount - 1 || lastBottom > end) { + if (lastPosition == mItemCount - 1) { + // Don't pull the bottom too far up + topOffset = Math.min(topOffset, lastBottom - end); + } + // Move everything up + offsetChildrenTopAndBottom(-topOffset); + if (lastPosition < mItemCount - 1) { + // Fill the gap that was opened below the last position with more rows, if + // possible + fillDown(lastPosition + 1, lastChild.getBottom() + mDividerHeight); + // Close up the remaining gap + adjustViewsUpOrDown(); + } + } else if (lastPosition == mItemCount - 1) { + adjustViewsUpOrDown(); } } } |