Last active
April 5, 2019 09:08
-
-
Save meoyawn/ec84f0aafd0b763629f282eb249059d8 to your computer and use it in GitHub Desktop.
Android multitouch helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | |
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN -> | |
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