Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

draw a single-touch motion path in android

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

like image 936
Rakib Avatar asked Mar 05 '11 07:03

Rakib


2 Answers

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.

like image 109
Luther Avatar answered Sep 28 '22 02:09

Luther


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)

like image 32
Matthieu Avatar answered Sep 28 '22 02:09

Matthieu