6

i am trying to make a drawing application.

i want to draw a single-touch motion path in android - like the way the Swype keyboard does it.

And consequently i want to store x-y coordinates of EACH of the pixels of the motion path into a data structure.

How can i use the MotionEvent pointers to do this?

enter image description here

Rakib
  • 12,376
  • 16
  • 77
  • 113

2 Answers2

3

You probably don't have to store every pixel - just store a new one when certain parameters are met such as the pixel is further along or if the angle between one pixel and the next is greater than a certain threshold. From that you'll have a more compact poly line that will be easier to work with.

Luther
  • 1,786
  • 3
  • 21
  • 38
2

You should look how to handle touch events here : http://developer.android.com/guide/topics/ui/ui-events.html

The example in the documentation of MotionEvent ( http://developer.android.com/reference/android/view/MotionEvent.html ) shows you how to get the coordinates of the touch event motion.

Then all you have to do is draw it (and maybe smooth it up a little)

Matthieu
  • 16,103
  • 10
  • 59
  • 86
  • i thought of using this......... but when i call myMotionEvent.getPointerCount() to get all the points of the touch motion, it is always returning 0. so how do i get all the pointers of the touch event that just took place – Rakib Mar 17 '11 at 07:32
  • Did you try the example code ? Did you register the onTouchListener ? – Matthieu Mar 17 '11 at 17:14
  • i basically put my code in the the view's overriden onTouchEvent() method.... that's the same as registering an onTouchListener right? – Rakib Mar 18 '11 at 20:02
  • Does it get called ? You can check this : http://stackoverflow.com/questions/5279182/android-how-to-register-ontouchevent-for-entire-activity-main-content-view – Matthieu Mar 18 '11 at 20:19
  • the view's built-in onTouchEvent() method does get called when the screen is touched... i am interested in finding the number of touch points that were generated due to my touch motion event. – Rakib Mar 19 '11 at 10:50