Playing with Android SDK – Part 2

After getting to know the onTouchEvent() a little better I decided to figure out the coordinate system of the Android graphics system and put in some movement logic. I thought I needed to figure out how to use the velocity tracker in order to do this, which is a very cool class and its a little different approach than other graphics systems I have coded to in the past.  Once I got the concept, I was able to capture where the touch was started and where it ended along with how fast it was.  The key is to coordinate the MotionEvent.ACTION_DOWN and the MotionEvent.ACTION_MOVE event types.  Once I got the concept of how to use these events the code became much easier and I actually didn’t even end up using the velocity tracker!

Here is a basic system I created to figure out where the touch happened and as the square is dragged across the board I calculate what square the touch is over by highlighting the square in blue.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.