diff --git a/src/com/fsck/k9/activity/K9Activity.java b/src/com/fsck/k9/activity/K9Activity.java index 184e55cce..228477489 100644 --- a/src/com/fsck/k9/activity/K9Activity.java +++ b/src/com/fsck/k9/activity/K9Activity.java @@ -135,10 +135,31 @@ public class K9Activity extends Activity { private static final float SWIPE_MAX_OFF_PATH_DIP = 250f; private static final float SWIPE_THRESHOLD_VELOCITY_DIP = 325f; + + protected MotionEvent mLastOnDownEvent = null; + + @Override + public boolean onDown(MotionEvent e) { + mLastOnDownEvent = e; + return super.onDown(e); + } + @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // Do fling-detection if gestures are force-enabled or we have system-wide gestures enabled. if (gesturesEnabled || K9.gesturesEnabled()) { + + // Apparently sometimes e1 is null + // Found a workaround here: http://stackoverflow.com/questions/4151385/ + if (e1 == null) { + e1 = mLastOnDownEvent; + } + + // Make sure we avoid NullPointerExceptions + if (e1 == null || e2 == null) { + return false; + } + // Calculate the minimum distance required for this to count as a swipe. // Convert the constant dips to pixels. final float mGestureScale = getResources().getDisplayMetrics().density;