"kotlin swipe listener" Code Answer's
You're definitely familiar with the best coding language Kotlin that developers use to develop their projects and they get all their queries like "kotlin swipe listener" answered properly. Developers are finding an appropriate answer about kotlin swipe listener related to the Kotlin coding language. By visiting this online portal developers get answers concerning Kotlin codes question like kotlin swipe listener. Enter your desired code related query in the search bar and get every piece of information about Kotlin code related question on kotlin swipe listener.
kotlin swipe listener
open class OnSwipeTouchListener : View.OnTouchListener {
private val gestureDetector = GestureDetector(GestureListener())
fun onTouch(event: MotionEvent): Boolean {
return gestureDetector.onTouchEvent(event)
}
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
private val SWIPE_THRESHOLD = 100
private val SWIPE_VELOCITY_THRESHOLD = 100
override fun onDown(e: MotionEvent): Boolean {
return true
}
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
onTouch(e)
return true
}
override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
val result = false
try {
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 (diffX > 0) {
onSwipeRight()
} else {
onSwipeLeft()
}
}
} else {
// onTouch(e);
}
} catch (exception: Exception) {
exception.printStackTrace()
}
return result
}
}
override fun onTouch(v: View, event: MotionEvent): Boolean {
return gestureDetector.onTouchEvent(event)
}
open fun onSwipeRight() {}
open fun onSwipeLeft() {}
open fun onSwipeTop() {}
open fun onSwipeBottom() {}
}
Source: stackoverflow.com
All those coders who are working on the Kotlin based application and are stuck on kotlin swipe listener can get a collection of related answers to their query. Programmers need to enter their query on kotlin swipe listener related to Kotlin code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about kotlin swipe listener for the programmers working on Kotlin code while coding their module. Coders are also allowed to rectify already present answers of kotlin swipe listener while working on the Kotlin language code. Developers can add up suggestions if they deem fit any other answer relating to "kotlin swipe listener". Visit this developer's friendly online web community, CodeProZone, and get your queries like kotlin swipe listener resolved professionally and stay updated to the latest Kotlin updates.