Skip to content

Commit

Permalink
🚧 handle cases where a touch event can be null and result in future N…
Browse files Browse the repository at this point in the history
…PE issues

Fixes Issue #21
  • Loading branch information
nisrulz committed Aug 18, 2018
1 parent 88c3147 commit 5d66a49
Showing 1 changed file with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ class GestureListener extends GestureDetector.SimpleOnGestureListener {

@Override
public boolean onDoubleTap(MotionEvent e) {
touchTypListener.onDoubleTap();
return super.onDoubleTap(e);
if (e != null) {
touchTypListener.onDoubleTap();
return super.onDoubleTap(e);
} else {
return false;
}
}

@Override
public boolean onFling(MotionEvent startevent, MotionEvent finishevent, float velocityX,
float velocityY) {
float velocityY) {

final float deltaX = finishevent.getX() - startevent.getX();
final float deltaY = finishevent.getY() - startevent.getY();
Expand Down Expand Up @@ -67,13 +71,15 @@ public boolean onFling(MotionEvent startevent, MotionEvent finishevent, float ve

@Override
public void onLongPress(MotionEvent e) {
touchTypListener.onLongPress();
super.onLongPress(e);
if (e != null) {
touchTypListener.onLongPress();
super.onLongPress(e);
}
}

@Override
public boolean onScroll(MotionEvent startevent, MotionEvent finishevent, float distanceX,
float distanceY) {
float distanceY) {

float deltaX = finishevent.getX() - startevent.getX();
float deltaY = finishevent.getY() - startevent.getY();
Expand Down Expand Up @@ -103,8 +109,12 @@ public boolean onScroll(MotionEvent startevent, MotionEvent finishevent, float d

@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
touchTypListener.onSingleTap();
return super.onSingleTapConfirmed(e);
if (e != null) {
touchTypListener.onSingleTap();
return super.onSingleTapConfirmed(e);
} else {
return false;
}
}
}

Expand Down Expand Up @@ -155,15 +165,18 @@ public TouchTypeDetector(Context context, TouchTypListener touchTypListener) {
}

boolean onTouchEvent(MotionEvent event) {

switch (event.getActionMasked()) {
case MotionEvent.ACTION_POINTER_DOWN:
if (event.getPointerCount() == 3) {
touchTypListener.onThreeFingerSingleTap();
} else if (event.getPointerCount() == 2) {
touchTypListener.onTwoFingerSingleTap();
}
if (event != null) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_POINTER_DOWN:
if (event.getPointerCount() == 3) {
touchTypListener.onThreeFingerSingleTap();
} else if (event.getPointerCount() == 2) {
touchTypListener.onTwoFingerSingleTap();
}
}
return gDetect.onTouchEvent(event);
} else {
return false;
}
return gDetect.onTouchEvent(event);
}
}

0 comments on commit 5d66a49

Please sign in to comment.