Drag events
Now that we're already reacting to ACTION_DOWN and ACTION_UP events, we will add a bit more complexity by reacting to ACTION_MOVE as well.
Let's update the angle, based on the amount of dragging in both directions. To do so, we need to store where the user pressed in the first place, so we'll store the variables lastX and lastY with the X and Y coordinates on the ACTION_DOWN event.
When we receive an ACTION_MOVE event, we calculate the difference between the lastX and lastY coordinates and the current values we received with the event. We update selectedAngle with the average of the X and Y difference, and we finally update the lastX and lastY coordinates. We have to remember to call invalidate or otherwise our view will not be ...
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