diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/widget/AbsListView.java | 36 | ||||
-rw-r--r-- | core/java/android/widget/Scroller.java | 28 |
2 files changed, 39 insertions, 25 deletions
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index c694ff1..2af59f9 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -2965,7 +2965,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te final int firstPos = mFirstPosition; final int lastPos = firstPos + getChildCount() - 1; - int viewTravelCount = 0; + int viewTravelCount; if (position <= firstPos) { viewTravelCount = firstPos - position + 1; mMode = MOVE_UP_POS; @@ -2998,7 +2998,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te final int firstPos = mFirstPosition; final int lastPos = firstPos + getChildCount() - 1; - int viewTravelCount = 0; + int viewTravelCount; if (position <= firstPos) { final int boundPosFromLast = lastPos - boundPosition; if (boundPosFromLast < 1) { @@ -3059,7 +3059,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te final int childCount = getChildCount(); final int lastPos = firstPos + childCount - 1; - int viewTravelCount = 0; + int viewTravelCount; if (position < firstPos) { viewTravelCount = firstPos - position; } else if (position > lastPos) { @@ -3249,6 +3249,20 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te } /** + * The amount of friction applied to flings. The default value + * is {@link ViewConfiguration#getScrollFriction}. + * + * @return A scalar dimensionless value representing the coefficient of + * friction. + */ + public void setFriction(float friction) { + if (mFlingRunnable == null) { + mFlingRunnable = new FlingRunnable(); + } + mFlingRunnable.mScroller.setFriction(friction); + } + + /** * Smoothly scroll to the specified adapter position. The view will * scroll such that the indicated position is displayed. * @param position Scroll to this adapter position. @@ -3581,22 +3595,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te * @return The position of the first (or only) item in the row containing y */ abstract int findMotionRow(int y); - - /** - * Find the row closest to y. This row will be used as the motion row when scrolling. - * - * @param y Where the user touched - * @return The position of the first (or only) item in the row closest to y - */ - int findClosestMotionRow(int y) { - final int childCount = getChildCount(); - if (childCount == 0) { - return INVALID_POSITION; - } - - final int motionRow = findMotionRow(y); - return motionRow != INVALID_POSITION ? motionRow : mFirstPosition + childCount - 1; - } /** * Causes all the views to be rebuilt and redrawn. diff --git a/core/java/android/widget/Scroller.java b/core/java/android/widget/Scroller.java index 4cb0839..d2e6688 100644 --- a/core/java/android/widget/Scroller.java +++ b/core/java/android/widget/Scroller.java @@ -63,7 +63,8 @@ public class Scroller { private static final int SCROLL_MODE = 0; private static final int FLING_MODE = 1; - private final float mDeceleration; + private float mDeceleration; + private final float mPpi; /** * Create a Scroller with the default duration and interpolator. @@ -79,13 +80,28 @@ public class Scroller { public Scroller(Context context, Interpolator interpolator) { mFinished = true; mInterpolator = interpolator; - float ppi = context.getResources().getDisplayMetrics().density * 160.0f; - mDeceleration = SensorManager.GRAVITY_EARTH // g (m/s^2) - * 39.37f // inch/meter - * ppi // pixels per inch - * ViewConfiguration.getScrollFriction(); + mPpi = context.getResources().getDisplayMetrics().density * 160.0f; + mDeceleration = computeDeceleration(ViewConfiguration.getScrollFriction()); + } + + /** + * The amount of friction applied to flings. The default value + * is {@link ViewConfiguration#getScrollFriction}. + * + * @return A scalar dimensionless value representing the coefficient of + * friction. + */ + public final void setFriction(float friction) { + computeDeceleration(friction); } + private float computeDeceleration(float friction) { + return SensorManager.GRAVITY_EARTH // g (m/s^2) + * 39.37f // inch/meter + * mPpi // pixels per inch + * friction; + } + /** * * Returns whether the scroller has finished scrolling. |