From fb75738ee28839c67bef4abc15d6c7a407c34f55 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Tue, 18 Jan 2011 18:42:33 -0800 Subject: [PATCH] Never drag scroll views with no children. Fixes a regression from Froyo. Previously, when a scroll view had no children, its onTouchEvent would return because the scroll view would only start dragging if the user touched one of its children. In Gingerbread, the user can drag from anywhere within the scroll view, not just by touching a child. However, it makes no sense to drag a scroll view that has no children so an empty scroll view should just ignore touches like any other empty view group would. This change fixes applications that for some reason or other happen to have empty scroll views in strange places. Bug: 3246230 Change-Id: Iada6e886e8363e6778f42fc4861de228512d8bed --- core/java/android/widget/HorizontalScrollView.java | 8 +++++--- core/java/android/widget/ScrollView.java | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/java/android/widget/HorizontalScrollView.java b/core/java/android/widget/HorizontalScrollView.java index f6b1dbc99b400..db22a0cb1e311 100644 --- a/core/java/android/widget/HorizontalScrollView.java +++ b/core/java/android/widget/HorizontalScrollView.java @@ -511,8 +511,10 @@ public class HorizontalScrollView extends FrameLayout { switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { - final float x = ev.getX(); - mIsBeingDragged = true; + mIsBeingDragged = getChildCount() != 0; + if (!mIsBeingDragged) { + return false; + } /* * If being flinged and user touches, stop the fling. isFinished @@ -523,7 +525,7 @@ public class HorizontalScrollView extends FrameLayout { } // Remember where the motion event started - mLastMotionX = x; + mLastMotionX = ev.getX(); mActivePointerId = ev.getPointerId(0); break; } diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java index 8558c70e40de8..ce6da72a2c98f 100644 --- a/core/java/android/widget/ScrollView.java +++ b/core/java/android/widget/ScrollView.java @@ -521,8 +521,10 @@ public class ScrollView extends FrameLayout { switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { - final float y = ev.getY(); - mIsBeingDragged = true; + mIsBeingDragged = getChildCount() != 0; + if (!mIsBeingDragged) { + return false; + } /* * If being flinged and user touches, stop the fling. isFinished @@ -537,7 +539,7 @@ public class ScrollView extends FrameLayout { } // Remember where the motion event started - mLastMotionY = y; + mLastMotionY = ev.getY(); mActivePointerId = ev.getPointerId(0); break; }