summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Onorato <joeo@android.com>2010-02-23 19:19:22 -0800
committerJoe Onorato <joeo@android.com>2010-02-24 16:20:33 -0800
commit9f0e8eeab2c9fdce182ad16fb28ad8fa3033eb75 (patch)
tree623d0c228591ea8a8cf51530a0ad44d7d54d06ca
parent8ff1e3f2ec24c6b81b90e1644060e6de25fb456e (diff)
downloadframeworks_base-9f0e8eeab2c9fdce182ad16fb28ad8fa3033eb75.zip
frameworks_base-9f0e8eeab2c9fdce182ad16fb28ad8fa3033eb75.tar.gz
frameworks_base-9f0e8eeab2c9fdce182ad16fb28ad8fa3033eb75.tar.bz2
Make ScrollView only do overscroll if you're grabbing the child view.
-rw-r--r--core/java/android/widget/ScrollView.java70
1 files changed, 49 insertions, 21 deletions
diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java
index 52ed11d..bb3b07e 100644
--- a/core/java/android/widget/ScrollView.java
+++ b/core/java/android/widget/ScrollView.java
@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.FocusFinder;
import android.view.KeyEvent;
import android.view.MotionEvent;
@@ -51,6 +52,8 @@ import java.util.List;
* <p>ScrollView only supports vertical scrolling.
*/
public class ScrollView extends FrameLayout {
+ private static final String TAG = "ScrollView";
+
static final int ANIMATED_SCROLL_GAP = 250;
static final float MAX_SCROLL_FACTOR = 0.5f;
@@ -360,6 +363,17 @@ public class ScrollView extends FrameLayout {
return handled;
}
+ private boolean inChild(int x, int y) {
+ if (getChildCount() > 0) {
+ final View child = getChildAt(0);
+ return !(y < child.getTop()
+ || y >= child.getBottom()
+ || x < child.getLeft()
+ || x >= child.getRight());
+ }
+ return false;
+ }
+
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
/*
@@ -399,6 +413,11 @@ public class ScrollView extends FrameLayout {
break;
case MotionEvent.ACTION_DOWN:
+ if (!inChild((int)ev.getX(), (int)y)) {
+ mIsBeingDragged = false;
+ break;
+ }
+
/* Remember location of down touch */
mLastMotionY = y;
@@ -451,36 +470,45 @@ public class ScrollView extends FrameLayout {
mScroller.abortAnimation();
}
+ if (!inChild((int)ev.getX(), (int)y)) {
+ mIsBeingDragged = false;
+ return false;
+ }
+
// Remember where the motion event started
mLastMotionY = y;
break;
case MotionEvent.ACTION_MOVE:
- // Scroll to follow the motion event
- final int deltaY = (int) (mLastMotionY - y);
- mLastMotionY = y;
+ if (mIsBeingDragged) {
+ // Scroll to follow the motion event
+ final int deltaY = (int) (mLastMotionY - y);
+ mLastMotionY = y;
- overscrollBy(0, deltaY, 0, mScrollY, 0, getScrollRange(),
- 0, getOverscrollMax());
- break;
+ overscrollBy(0, deltaY, 0, mScrollY, 0, getScrollRange(),
+ 0, getOverscrollMax());
+ break;
+ }
case MotionEvent.ACTION_UP:
- final VelocityTracker velocityTracker = mVelocityTracker;
- velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
- int initialVelocity = (int) velocityTracker.getYVelocity();
-
- if (getChildCount() > 0) {
- if ((Math.abs(initialVelocity) > mMinimumVelocity)) {
- fling(-initialVelocity);
- } else {
- final int bottom = getScrollRange();
- if (mScroller.springback(mScrollX, mScrollY, 0, 0, 0, bottom)) {
- invalidate();
+ if (mIsBeingDragged) {
+ final VelocityTracker velocityTracker = mVelocityTracker;
+ velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
+ int initialVelocity = (int) velocityTracker.getYVelocity();
+
+ if (getChildCount() > 0) {
+ if ((Math.abs(initialVelocity) > mMinimumVelocity)) {
+ fling(-initialVelocity);
+ } else {
+ final int bottom = getScrollRange();
+ if (mScroller.springback(mScrollX, mScrollY, 0, 0, 0, bottom)) {
+ invalidate();
+ }
}
}
- }
- if (mVelocityTracker != null) {
- mVelocityTracker.recycle();
- mVelocityTracker = null;
+ if (mVelocityTracker != null) {
+ mVelocityTracker.recycle();
+ mVelocityTracker = null;
+ }
}
}
return true;