Skip to content

Instantly share code, notes, and snippets.

Last active Apr 5, 2019
What would you like to do?
Android multitouch helper
import android.view.MotionEvent
typealias PxF = Float
typealias X = PxF
typealias Y = PxF
typealias PointerId = Int
inline fun MotionEvent.multiTouch(
down: (PointerId, X, Y) -> Unit,
move: (PointerId, X, Y) -> Unit,
up: (PointerId, X, Y) -> Unit
) {
val action = actionMasked
for (i in 0 until pointerCount) {
val pointer = getPointerId(i)
val x = getX(i)
val y = getY(i)
when (action) {
down(pointer, x, y)
MotionEvent.ACTION_MOVE ->
move(pointer, x, y)
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL, MotionEvent.ACTION_POINTER_UP ->
up(pointer, x, y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment