mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 19:52:17 -05:00
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:
parent
fa962e7bd7
commit
5311a2ef01
@ -65,7 +65,7 @@ public class NonLockingScrollView extends ScrollView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||||
final int action = ev.getActionMasked();
|
final int action = getActionMasked(ev);
|
||||||
final boolean isUp = action == MotionEvent.ACTION_UP;
|
final boolean isUp = action == MotionEvent.ACTION_UP;
|
||||||
|
|
||||||
if (isUp && mInCustomDrag) {
|
if (isUp && mInCustomDrag) {
|
||||||
@ -91,6 +91,11 @@ public class NonLockingScrollView extends ScrollView {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getActionMasked(MotionEvent ev) {
|
||||||
|
// Equivalent to MotionEvent.getActionMasked() which is in API 8+
|
||||||
|
return ev.getAction() & MotionEvent.ACTION_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onFinishInflate() {
|
protected void onFinishInflate() {
|
||||||
super.onFinishInflate();
|
super.onFinishInflate();
|
||||||
@ -116,11 +121,11 @@ public class NonLockingScrollView extends ScrollView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Rect sHitFrame = new Rect();
|
private final Rect sHitFrame = new Rect();
|
||||||
private static boolean isEventOverChild(MotionEvent ev, ArrayList<View> children) {
|
private boolean isEventOverChild(MotionEvent ev, ArrayList<View> children) {
|
||||||
final int actionIndex = ev.getActionIndex();
|
final int actionIndex = getActionIndex(ev);
|
||||||
final float x = ev.getX(actionIndex);
|
final float x = ev.getX(actionIndex) + getScrollX();
|
||||||
final float y = ev.getY(actionIndex);
|
final float y = ev.getY(actionIndex) + getScrollY();
|
||||||
|
|
||||||
for (View child : children) {
|
for (View child : children) {
|
||||||
if (!canViewReceivePointerEvents(child)) {
|
if (!canViewReceivePointerEvents(child)) {
|
||||||
@ -136,6 +141,13 @@ public class NonLockingScrollView extends ScrollView {
|
|||||||
return false;
|
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) {
|
private static boolean canViewReceivePointerEvents(View child) {
|
||||||
return child.getVisibility() == VISIBLE || (child.getAnimation() != null);
|
return child.getVisibility() == VISIBLE || (child.getAnimation() != null);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user