mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-31 15:20:09 -05:00
Avoid NullPointerException in the gesture detection code
This commit is contained in:
parent
7e5717ed81
commit
68a6eddfb6
@ -135,10 +135,31 @@ public class K9Activity extends Activity {
|
|||||||
private static final float SWIPE_MAX_OFF_PATH_DIP = 250f;
|
private static final float SWIPE_MAX_OFF_PATH_DIP = 250f;
|
||||||
private static final float SWIPE_THRESHOLD_VELOCITY_DIP = 325f;
|
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
|
@Override
|
||||||
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
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.
|
// Do fling-detection if gestures are force-enabled or we have system-wide gestures enabled.
|
||||||
if (gesturesEnabled || K9.gesturesEnabled()) {
|
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.
|
// Calculate the minimum distance required for this to count as a swipe.
|
||||||
// Convert the constant dips to pixels.
|
// Convert the constant dips to pixels.
|
||||||
final float mGestureScale = getResources().getDisplayMetrics().density;
|
final float mGestureScale = getResources().getDisplayMetrics().density;
|
||||||
|
Loading…
Reference in New Issue
Block a user