Avoid warnings in OnSwipeTouchListener
This commit is contained in:
@@ -1,23 +1,26 @@
|
|||||||
package com.tutpro.baresip
|
package com.tutpro.baresip
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.GestureDetector
|
import android.view.GestureDetector
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener {
|
open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener {
|
||||||
|
|
||||||
private val gestureDetector: GestureDetector
|
private val gestureDetector: GestureDetector
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val SWIPE_THRESHOLD = 100
|
private const val SWIPE_THRESHOLD = 100
|
||||||
private val SWIPE_VELOCITY_THRESHOLD = 100
|
private const val SWIPE_VELOCITY_THRESHOLD = 100
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
gestureDetector = GestureDetector(ctx, GestureListener())
|
gestureDetector = GestureDetector(ctx, GestureListener())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onTouch(view: View?, event: MotionEvent?): Boolean {
|
override fun onTouch(view: View?, event: MotionEvent?): Boolean {
|
||||||
return gestureDetector.onTouchEvent(event)
|
return gestureDetector.onTouchEvent(event)
|
||||||
}
|
}
|
||||||
@@ -33,8 +36,8 @@ open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener {
|
|||||||
try {
|
try {
|
||||||
val diffY = e2!!.y - e1!!.y
|
val diffY = e2!!.y - e1!!.y
|
||||||
val diffX = e2.x - e1.x
|
val diffX = e2.x - e1.x
|
||||||
if (Math.abs(diffX) > Math.abs(diffY)) {
|
if (abs(diffX) > abs(diffY)) {
|
||||||
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velX) > SWIPE_VELOCITY_THRESHOLD) {
|
if (abs(diffX) > SWIPE_THRESHOLD && abs(velX) > SWIPE_VELOCITY_THRESHOLD) {
|
||||||
if (diffX > 0) {
|
if (diffX > 0) {
|
||||||
onSwipeRight()
|
onSwipeRight()
|
||||||
} else {
|
} else {
|
||||||
@@ -42,13 +45,13 @@ open class OnSwipeTouchListener(ctx: Context) : View.OnTouchListener {
|
|||||||
}
|
}
|
||||||
result = true
|
result = true
|
||||||
}
|
}
|
||||||
} else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velY) > SWIPE_VELOCITY_THRESHOLD) {
|
} else if (abs(diffY) > SWIPE_THRESHOLD && abs(velY) > SWIPE_VELOCITY_THRESHOLD) {
|
||||||
if (diffY > 0) {
|
result = if (diffY > 0) {
|
||||||
onSwipeBottom()
|
onSwipeBottom()
|
||||||
result = false
|
false
|
||||||
} else {
|
} else {
|
||||||
onSwipeTop()
|
onSwipeTop()
|
||||||
result = true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
Reference in New Issue
Block a user