Processing Multitouch Events

Warning, major pain ahead. The multitouch API has been tagged onto the MotionEvent class, which originally only handled single touches. This makes for some major confusion when trying to decode multitouch events. Let's try to make some sense of it.

NOTE: The multitouch API is apparently also confusing for the Android engineers that created it. It received a major overhaul in SDK version 8 (Android 2.2) with new methods, new constants, and even renamed constants. These changes should make working with multitouch a little bit easier. However, they are only available from SDK version 8 onward. To support all multitouch-capable Android versions (2.0 through 2.2.1), we have to use the API of SDK version 5.

Handling multitouch is very similar to handling single-touch events. We still implement the same OnTouchListener interface we implemented for single-touch events. We also get a MotionEvent instance to read the data from. We also process the event types we processed before, like MotionEvent.ACTION_UP, plus a couple of new ones that aren't too big of a deal.

0 0

Post a comment