Game Development Reference
In-Depth Information
ï?® A touch - up event happened ( MotionEvent.ACTION_UP ,
MotionEvent.ACTION_POINTER_UP , or MotionEvent.CANCEL ): We set the touch
state to false for that pointer identifier and save its last known coordinates.
ï?® One or more fingers were dragged across the screen ( MotionEvent.
ACTION_MOVE ): We check how many events are contained in the MotionEvent
and then update the coordinates for the pointer indices 0 to MotionEvent.
getPointerCount()-1 . For each event, we fetch the corresponding
pointer ID and update the coordinates.
Once the event is processed, we update the TextView via a call to the updateView() method we
defined earlier. Finally, we return true , indicating that we processed the touch event.
Figure 4-7 shows the output of the activity produced by touching five fingers on a Samsung
Galaxy Nexus and dragging them around a little.
Figure 4-7. Fun with multitouch
We can observe a few things when we run this example:
If we start it on a device or emulator with an Android version lower than 2.0,
ï?®
we get a nasty exception because we've used an API that is not available on
those earlier versions. We can work around this by determining the Android
version the application is running, using the single-touch code on devices
Search WWH ::




Custom Search