summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2010-10-11 19:36:59 -0700
committerRomain Guy <romainguy@google.com>2010-10-11 19:38:37 -0700
commit4bede9e425875542976a422222510fa4056a8339 (patch)
tree94b7dab2b98f12b9b2363eb40e72952ab4c10bd4 /core
parent82b400387114634e5b0b8c08ac142cb69ccf14cf (diff)
downloadframeworks_base-4bede9e425875542976a422222510fa4056a8339.zip
frameworks_base-4bede9e425875542976a422222510fa4056a8339.tar.gz
frameworks_base-4bede9e425875542976a422222510fa4056a8339.tar.bz2
Add an API to control AbsListView's friction.
Change-Id: Iafb08cd28703d282c369c472a5d85a22cc5dacb7
Diffstat (limited to 'core')
-rw-r--r--core/java/android/widget/AbsListView.java36
-rw-r--r--core/java/android/widget/Scroller.java28
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.