summaryrefslogtreecommitdiffstats
path: root/core/java/android/widget
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2010-03-24 15:11:45 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-03-24 15:11:45 -0700
commit26295d20e3e41f33757043615487f82eab8e14a6 (patch)
tree05e4aa8aabb1de441112b7df4b89175ac8ac46d3 /core/java/android/widget
parent34783aac261f55ba1fbc2ccb60fd0bdb12fdf52a (diff)
parent352b978fa8332808ce38c6f52edd04c8dcb9e7e3 (diff)
downloadframeworks_base-26295d20e3e41f33757043615487f82eab8e14a6.zip
frameworks_base-26295d20e3e41f33757043615487f82eab8e14a6.tar.gz
frameworks_base-26295d20e3e41f33757043615487f82eab8e14a6.tar.bz2
Merge "Fix some bugs/edge cases in ScrollView/HorizontalScrollView"
Diffstat (limited to 'core/java/android/widget')
-rw-r--r--core/java/android/widget/HorizontalScrollView.java38
-rw-r--r--core/java/android/widget/ScrollView.java37
2 files changed, 55 insertions, 20 deletions
diff --git a/core/java/android/widget/HorizontalScrollView.java b/core/java/android/widget/HorizontalScrollView.java
index 0bbf7b8..06da5fa 100644
--- a/core/java/android/widget/HorizontalScrollView.java
+++ b/core/java/android/widget/HorizontalScrollView.java
@@ -372,11 +372,12 @@ public class HorizontalScrollView extends FrameLayout {
private boolean inChild(int x, int y) {
if (getChildCount() > 0) {
+ final int scrollX = mScrollX;
final View child = getChildAt(0);
return !(y < child.getTop()
|| y >= child.getBottom()
- || x < child.getLeft()
- || x >= child.getRight());
+ || x < child.getLeft() - scrollX
+ || x >= child.getRight() - scrollX);
}
return false;
}
@@ -455,6 +456,9 @@ public class HorizontalScrollView extends FrameLayout {
/* Release the drag */
mIsBeingDragged = false;
mActivePointerId = INVALID_POINTER;
+ if (mScroller.springback(mScrollX, mScrollY, 0, getScrollRange(), 0, 0)) {
+ invalidate();
+ }
break;
case MotionEvent.ACTION_POINTER_UP:
onSecondaryPointerUp(ev);
@@ -486,21 +490,22 @@ public class HorizontalScrollView extends FrameLayout {
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN: {
- /*
- * If being flinged and user touches, stop the fling. isFinished
- * will be false if being flinged.
- */
- if (!mScroller.isFinished()) {
- mScroller.abortAnimation();
- }
-
final float x = ev.getX();
if (!(mIsBeingDragged = inChild((int) x, (int) ev.getY()))) {
return false;
}
+ /*
+ * If being flinged and user touches, stop the fling. isFinished
+ * will be false if being flinged.
+ */
+ if (!mScroller.isFinished()) {
+ mScroller.abortAnimation();
+ }
+
// Remember where the motion event started
mLastMotionX = x;
+ mActivePointerId = ev.getPointerId(0);
break;
}
case MotionEvent.ACTION_MOVE:
@@ -544,6 +549,19 @@ public class HorizontalScrollView extends FrameLayout {
}
}
break;
+ case MotionEvent.ACTION_CANCEL:
+ if (mIsBeingDragged && getChildCount() > 0) {
+ if (mScroller.springback(mScrollX, mScrollY, 0, getScrollRange(), 0, 0)) {
+ invalidate();
+ }
+ mActivePointerId = INVALID_POINTER;
+ mIsBeingDragged = false;
+ if (mVelocityTracker != null) {
+ mVelocityTracker.recycle();
+ mVelocityTracker = null;
+ }
+ }
+ break;
case MotionEvent.ACTION_POINTER_UP:
onSecondaryPointerUp(ev);
break;
diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java
index 3cf2af2..36d244f 100644
--- a/core/java/android/widget/ScrollView.java
+++ b/core/java/android/widget/ScrollView.java
@@ -370,9 +370,10 @@ public class ScrollView extends FrameLayout {
private boolean inChild(int x, int y) {
if (getChildCount() > 0) {
+ final int scrollY = mScrollY;
final View child = getChildAt(0);
- return !(y < child.getTop()
- || y >= child.getBottom()
+ return !(y < child.getTop() - scrollY
+ || y >= child.getBottom() - scrollY
|| x < child.getLeft()
|| x >= child.getRight());
}
@@ -452,6 +453,9 @@ public class ScrollView extends FrameLayout {
/* Release the drag */
mIsBeingDragged = false;
mActivePointerId = INVALID_POINTER;
+ if (mScroller.springback(mScrollX, mScrollY, 0, 0, 0, getScrollRange())) {
+ invalidate();
+ }
break;
case MotionEvent.ACTION_POINTER_UP:
onSecondaryPointerUp(ev);
@@ -483,19 +487,19 @@ public class ScrollView extends FrameLayout {
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN: {
- /*
- * If being flinged and user touches, stop the fling. isFinished
- * will be false if being flinged.
- */
- if (!mScroller.isFinished()) {
- mScroller.abortAnimation();
- }
-
final float y = ev.getY();
if (!(mIsBeingDragged = inChild((int) ev.getX(), (int) y))) {
return false;
}
+ /*
+ * If being flinged and user touches, stop the fling. isFinished
+ * will be false if being flinged.
+ */
+ if (!mScroller.isFinished()) {
+ mScroller.abortAnimation();
+ }
+
// Remember where the motion event started
mLastMotionY = y;
mActivePointerId = ev.getPointerId(0);
@@ -542,6 +546,19 @@ public class ScrollView extends FrameLayout {
}
}
break;
+ case MotionEvent.ACTION_CANCEL:
+ if (mIsBeingDragged && getChildCount() > 0) {
+ if (mScroller.springback(mScrollX, mScrollY, 0, 0, 0, getScrollRange())) {
+ invalidate();
+ }
+ mActivePointerId = INVALID_POINTER;
+ mIsBeingDragged = false;
+ if (mVelocityTracker != null) {
+ mVelocityTracker.recycle();
+ mVelocityTracker = null;
+ }
+ }
+ break;
case MotionEvent.ACTION_POINTER_UP:
onSecondaryPointerUp(ev);
break;