From 5311a2ef0139e3e1ff9931532ff5be974b764dc6 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Mon, 25 Mar 2013 09:51:16 -0400 Subject: [PATCH] NonLockingScrollview fixes. Implement methods missing in API 7 Fix coordinate reference frame mismatch. Touch events are relative to the view display, whereas view children are relative to the view. --- .../fsck/k9/view/NonLockingScrollView.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/com/fsck/k9/view/NonLockingScrollView.java b/src/com/fsck/k9/view/NonLockingScrollView.java index 5336d11dc..fbb56a618 100644 --- a/src/com/fsck/k9/view/NonLockingScrollView.java +++ b/src/com/fsck/k9/view/NonLockingScrollView.java @@ -65,7 +65,7 @@ public class NonLockingScrollView extends ScrollView { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - final int action = ev.getActionMasked(); + final int action = getActionMasked(ev); final boolean isUp = action == MotionEvent.ACTION_UP; if (isUp && mInCustomDrag) { @@ -91,6 +91,11 @@ public class NonLockingScrollView extends ScrollView { return false; } + private int getActionMasked(MotionEvent ev) { + // Equivalent to MotionEvent.getActionMasked() which is in API 8+ + return ev.getAction() & MotionEvent.ACTION_MASK; + } + @Override protected void onFinishInflate() { super.onFinishInflate(); @@ -116,11 +121,11 @@ public class NonLockingScrollView extends ScrollView { } } - private static final Rect sHitFrame = new Rect(); - private static boolean isEventOverChild(MotionEvent ev, ArrayList children) { - final int actionIndex = ev.getActionIndex(); - final float x = ev.getX(actionIndex); - final float y = ev.getY(actionIndex); + private final Rect sHitFrame = new Rect(); + private boolean isEventOverChild(MotionEvent ev, ArrayList children) { + final int actionIndex = getActionIndex(ev); + final float x = ev.getX(actionIndex) + getScrollX(); + final float y = ev.getY(actionIndex) + getScrollY(); for (View child : children) { if (!canViewReceivePointerEvents(child)) { @@ -136,6 +141,13 @@ public class NonLockingScrollView extends ScrollView { return false; } + @SuppressWarnings("deprecation") + private static int getActionIndex(MotionEvent ev) { + // Equivalent to MotionEvent.getActionIndex() which is in API 8+ + return ((ev.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) + >> MotionEvent.ACTION_POINTER_ID_SHIFT); + } + private static boolean canViewReceivePointerEvents(View child) { return child.getVisibility() == VISIBLE || (child.getAnimation() != null); }