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.
This commit is contained in:
Joe Steele 2013-03-25 09:51:16 -04:00
parent fa962e7bd7
commit 5311a2ef01
1 changed files with 18 additions and 6 deletions

View File

@ -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<View> 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<View> 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);
}