Try to catch onFling null pointer exception
This commit is contained in:
@ -18,26 +18,23 @@ open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener {
|
||||
gestureDetector = GestureDetector(ctx, GestureListener())
|
||||
}
|
||||
|
||||
override fun onTouch(v: View?, e: MotionEvent?): Boolean {
|
||||
return if (v != null && e != null)
|
||||
gestureDetector.onTouchEvent(e)
|
||||
else
|
||||
false
|
||||
override fun onTouch(view: View?, event: MotionEvent?): Boolean {
|
||||
return gestureDetector.onTouchEvent(event)
|
||||
}
|
||||
|
||||
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
|
||||
|
||||
override fun onDown(e: MotionEvent): Boolean {
|
||||
override fun onDown(event: MotionEvent): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
|
||||
override fun onFling(e1: MotionEvent?, e2: MotionEvent?, velX: Float, velY: Float): Boolean {
|
||||
var result = false
|
||||
try {
|
||||
val diffY = e2.y - e1.y
|
||||
val diffY = e2!!.y - e1!!.y
|
||||
val diffX = e2.x - e1.x
|
||||
if (Math.abs(diffX) > Math.abs(diffY)) {
|
||||
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velX) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
if (diffX > 0) {
|
||||
onSwipeRight()
|
||||
} else {
|
||||
@ -45,7 +42,7 @@ open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener {
|
||||
}
|
||||
result = true
|
||||
}
|
||||
} else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
} else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velY) > SWIPE_VELOCITY_THRESHOLD) {
|
||||
if (diffY > 0) {
|
||||
onSwipeBottom()
|
||||
result = false
|
||||
@ -54,8 +51,9 @@ open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
} catch (e: Exception) {
|
||||
Log.e("Baresip", "onFling exception $e")
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user