Android Programming: The Big Nerd Ranch Guide, 5th Edition
by Bryan Sills, Brian Gardner, Kristin Marsicano, Chris Stewart
Challenge: Rotating Boxes
For a harder challenge, make it so that you can use a second finger to rotate your rectangles. To do this, you will need to handle multiple pointers in your MotionEvent handling code. You will also need to rotate your canvas.
When dealing with multiple touches, you need these extra ideas:
|
pointer index |
tells you which pointer in the current set of pointers the event is for |
|
pointer ID |
gives you a unique ID for a specific finger in a gesture |
The pointer index may change, but the pointer ID will not.
For more details, check out the documentation for the following MotionEvent functions:
final fun getActionMasked(): Int final fun getActionIndex(): Int final fun getPointerId(pointerIndex: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access