fix NPE thrown in onFling

This commit is contained in:
darthpaul 2022-11-25 08:15:28 +00:00
parent 47bc591035
commit fd82e35215
2 changed files with 16 additions and 7 deletions

View File

@ -366,20 +366,16 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
@SuppressLint("ClickableViewAccessibility")
private fun initModeSwitcher() {
val gestureDetector = GestureDetectorCompat(this, object : GestureDetector.SimpleOnGestureListener() {
val gestureDetector = GestureDetectorCompat(this, object : GestureDetectorListener() {
override fun onDown(e: MotionEvent): Boolean {
// we have to return true here so ACTION_UP
// (and onFling) can be dispatched
return true
}
override fun onFling(event1: MotionEvent, event2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
override fun onFling(event1: MotionEvent?, event2: MotionEvent?, velocityX: Float, velocityY: Float): Boolean {
// these can be null even if the docs say they cannot, getting event1.x in itself can cause crashes
try {
if (event1 == null || event2 == null || event1.x == null || event2.x == null) {
return true
}
} catch (e: NullPointerException) {
if (event1 == null || event2 == null) {
return true
}

View File

@ -0,0 +1,13 @@
package com.simplemobiletools.camera.helpers;
import android.view.GestureDetector;
import android.view.MotionEvent;
import androidx.annotation.Nullable;
public class GestureDetectorListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onFling(@Nullable MotionEvent e1, @Nullable MotionEvent e2, float velocityX, float velocityY) {
return super.onFling(e1, e2, velocityX, velocityY);
}
}