draw a single-touch motion path in android - 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?

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.

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)

Related

Best way to store points of a curve created by touch movements?

We are creating an app where it is necessary to draw lines (curves) based on touch events but we also need to store the points that correspond to specific lines.
Android.Graphics.Path gave us really nice smooth lines as we dragged our finger. However, there does not seem to be anyway to access the points from the Path objects.
What we do now is basically connect lines as a person drags their finger (using y=mx+b). So if the last recognized touch place was 0,0 and then they move past our threshold to (4,4) we call a function to make points from the line connecting these two ((0,0),(1,1),(2,2),(3,3),(4,4)). These points we add to an ArrayList.
This is giving us kinda choppy curves (obviously cause we are using y=mx+b), but more importantly it slows our program considerably after several lines are drawn.
Is there a better way to generate the points of a curve that follows a user's swipe movements? Or a better way to store these? Path seems to do it so well, is there any reason it hides the actual points?
Thanks!
A way to achieve smoothness is using the Path class' method quadTo.
quadTo(float x1, float y1, float x2, float y2) Add a quadratic bezier
from the last point, approaching control point (x1,y1), and ending at
(x2,y2).
Bezier curves are what you want to solve this problem. You should be able to detect a change in direction of the user's finger and stop the current curve and start a new one at that point. You really don't want to be storing every point along a path as I could just let my finger linger on the screen and clog up the datastructure.

Drawing and storing a user's touch path in libgdx

I'm struggling with something I would expect to be straight forward with libgdx.
In short this is a "finger paint" app where I want to draw a path of a certain width where the user touches the screen.
I've earlier done this by using a plain Android android.view.View. I had a android.graphics.Path in which I stored the coordinates of the user's current touch. In the onDraw() method of the view I drew the path to the android.graphics.Canvas. Whenever the user released a finger I drew the path to an offline canvas/android.graphics.Bitmap which also was drawn in the onDraw() method. Plain and simple.
How can that be done using libgdx?
I have tried using a com.badlogic.gdx.graphics.Pixmap that I can draw a line to whenever the user moves a finger. This works well except the fact that I'm unable to control the witdh of the line using Gdx.gl.glLineWidth(). I know I can draw a rectangle instead of a line to set the width, but Pixmap doesn't seem to have any means of rotating, so I don't see how this can be done.
I can use a com.badlogic.gdx.graphics.glutils.ShapeRenderer for drawing lines (or rectangles) in com.badlogic.gdx.Screen.render(). As far as I can see I then need to store every single touch point of the current touch, and then draw all lines on render. Whenever the user relases a finger I guess I can store the screen as-is with something like com.badlogic.gdx.utils.ScreenUtils.getFrameBufferPixmap(). Hopefully there is a easier way to achieve what I want.
I ended up drawing circles on a pixmap where the line should be:
One circle on touchDown
Several circles from last touch point to next touch point reported to touchDragged
I'm not very happy with this solution, but it kinda works.
Maybe you can calculate line dot coordinates manually and use triangles to draw them on pixmap? Like use 2 triangles to form (rotated) box?

Android: best way to handle point, line and circular gestures

I need to handle 3 types of gestures in my app: points, lines and circles.
Circles and lines are vectored (may be drawn in different directions, like in windows 8 picture password).
Now I'm looking for a better way for it - read about GestureOverlayView, but, how I understood, those gestures should be given initially, and my lines will be at different angles, and circles at different diameters.
Is there any easy way to do it, or better to use onTouchEvent and detect gestures mathematically?
When you said you "need to handle 3 types of gestures", what exactly do you mean by 'handle', ie. what do you need to do with the gestures? Do you mean that you need to determine if a particular gesture is a point, line or circle?
If you want to analyse a gesture, as it is being drawn or after it is drawn, you could create a Path object and update it in each onTouchEvent. Then you would do your mathematical calculations with the points along that Path. http://developer.android.com/reference/android/graphics/Path.html

how to detect the shape that touch the touch screen

I have received requirement like this http://www.youtube.com/watch?v=7MYQicokwmY&feature=plcp I am reviewing this requirement.As per requirement we have to build touch detection like in video link for Android enabled Tablets.
In that video toys (toys with circular, star or rectangle shape) uses Conductive Silicone Sensors with that they are detecting touch on screen & deciding shape of external world object like triangle,circle or a star & further processing the shape.
I have to use same touch detection for android tablets.Can anybody help me to find the way to implement this on Android platform ? Is there any API or framework to implement it?
If you see the video around 1:13, they show what I am guessing are some prototypes, the circle has three points, the hexagon too...
My best guess is that the biggest part of the object is non-conductive and only has a few points that are conductive and would actually register as touch points on the screen. The key is that each of them will be different enough that you would be able to recognize them no matter what the orientation is, what the position (and depending on your requirements whether you have several of those objects at the same time on the screen).
You can also play with the area of each conductive points so in your code, you will get the touch information, you can get different pressure values from the MotionEvent
Now how you place the conductive points and how many on each shape is completely up to you and would really depend on what your requirements are (recognizing arbitrary shape is not an option...)
Most touch screens would reject the touch if the area is too large (that's palm rejection), so I don't think there are much other ways to do this...

Detecting touch area on Android

Is it possible to detect every pixel being touched? More specifically, when the user touches the screen, is it possible to track all the x-y coordinates of the cluster of points touched by the user? How can I tell the difference between when users are drawing with their thumb and when they are drawing with the tip of a finger? I would like to reflect the brush difference depending on how users touch the screen, and would also like to track x-y coordinates of all the pixels being touched over time. Thanks so much in advance for any help.
This would be very tricky primarily because every android phone is going to behave differently. There are some touch screen devices that are very, very sensitive and some that are basically "dull" by comparison.
It also sounds more like you are wanting to track pressure - how hard is the user pushing on the screen - which is actually supported on android devices.
I think some of your answer may be found by monitoring all of the touch events - in practice, most applications ignore a great number of events or perform some kind of "smoothing" of the events since there is literally a deluge of touch events when the user is manipulating the screen. Doing this may negatively impact your applications performance though.
I would recommend that you look into pressure sensitivity and calculate a circular region around the primary touch point based on pressure, then build your brush around that.
Another idea would be to incorporate more of a gesture approach to what you are trying to do - for example, visualize touching the screen with the tip of two fingers together (index and middle) and rolling the middle finger around the index finger or simply moving the middle finger up and down in relation to the index finger. Both fingers would be moved together for painting. This could be used to manipulate drawing angle on the fly or perhaps even toggle between a set of pre-selected brushes or could change brush size on the fly as you are painting.
Some of the above ideas I would love to see implemented - let me know when you have your app ready.
Good luck!
Rodney
If you have a listener on your image it will respond that there was a touch within that bounding box, basically.
So, to get what you want, you could, but, I would never do this, create a box around every pixel, or small group of pixels, and listen for a touch.
Wherever you get a touch, it may fire off an event, then you can react accordingly.
I can't think of any other solution that will give you each pixel that a person touched, at one time.
You may want to read up on multitouch though, as there are some suggestions in here that my help you:
http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
If you're looking for a way to get your content view as a View after Activity#setContentView(int), then you can set an id on the outer-most element of your layout:
android:id="#+id/entire_view" and reference it in your onCreate() method after setContentView:
View view = getViewById(R.id.entire_view);
view.setOnTouchListener( ... );

Categories

Resources