touchMoved Method of Class DoodleView

The touchMoved method (Fig. 7.30) is called when the user moves one or more fingers across the screen. The system MotionEvent passed from onTouchEvent contains touch information for multiple moves on the screen if they occur at the same time. MotionEvent method getPointerCount (line 222) returns the number of touches this MotionEvent describes. For each, we store the finger’s ID (line 225) in pointerID, and store the finger’s corresponding index in this MotionEvent (line 226) in pointerIndex. Then we check whether there’s a corresponding Path in the pathMap HashMap (line 229). If so, we use MotionEvent’s getX and getY methods to get the last coordinates for this drag event for the specified pointerIndex

Get Android™ How to Program, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.