I want the coordinates of the finger when user drops the object and remove the finger.
I got the position of user when touch the screen but not getting the coordinates when user remove the finger
I'm not sure what exactly you're doing. But onTouchListener gives you all the information about any user interaction event. Event.ACTION_DOWN is when the user starts the event, and Event.ACTION_UP is when the user ends the event (removes their finger)
Related
I'm making simple app where user can move squares with finger on screen. First I'm checking if touch coords are on square to allow the move. Then square is moving along GLSurfaceView#onTouchEvent event coordinates.
It works OK. But when finger is moving too quick (like swipe) square looses the focus and stays still. It seems that OpenGL renders square after the move event occurs, so coordinates check fail.
Please point some keywords to figure out the question (googling gives same links again and again) or some docs. Thanks.
You need hold focus on sprite. If sprite got event "down" it holds focus until doesn't get "up" or "cancel" event. So, while sprite holds focus all touch events send to it.
I dynamically create a View with onTouchListner. The problem is it doesn't work when the view is being created the same time the user keeps his finger on the screen.
To trigger onTouch() user has to put his finger off the screen and touch it again.
How to solve that?
May be you can try to track coordinates of the touch event when user moves the finger.If the Coordinates are in your views coordinates boundary you can intercept that event and play sound.
I have some text on circles, and I would like the user to be able to touch and drag the text, and have it constrained to move along the circle...
I got this far using Canvas, but I can't figure out how to make it respond to touch this way. I am not objected to starting over and taking a non-canvas approach.
How can I make this happen? Pseudocode would be appreciated.
I might be wrong, but considering this is a canvas. Then, it is your job to detect which text is touched.
Once you set your onTouchListener for the view, you get the event coordinates of the ACTION_DOWN event. You check and get the text that was touched. If none, return false. Else, return true.
Now, if the user moves his finger, you will receive more events with ACTION_MOVE. In that case, you would probably want to move the chosen text according to the difference between this event and the last one. Once you calculate the new position of the texts, you call invalidate() which should force a redraw.
Finally, when the user stops moving, you will receive an event with ACTION_UP. That is when you have to either put the texts back to their original position, or whatever you want.
I am trying to develop a game with Android where I need to move a tile in all directions. My question is how can I get the motion of the finger on the screen(right,left,top) using getX() and getY()?
Thanks.
Take a look at getHistoricalSize, getHistoricalX(int) and getHistoricalY(int).
When the finger is touching the screen, Android records the move positions and saves them. You can then call getHistorySize to get the number of motions recorded, and then call getHistoricalX and getHistoricalY with a parameter less that the history size to get the x/y at that history position.
So, for example, you can call getHistoricalY with a parameter that indicates that previous motion event, and then compare it to the current one. If the current one is bigger, then the finger is swiping down.
Note: Motion events recording applies only to ACTION_MOVE.
I am currently using pure OpenGL to paint buttons in my own little way.
I can detect if a button is pushed with onTouchEvent, but I want to know if the user is holding the button down, or if the user is no longer touching the screen.
After the initial MotionEvent.ACTION_DOWN event, all of the subsequent touch events(user keeps finger on the screen) will be MotionEvent.ACTION_MOVE events until the user lifts their finger off of the screen which will register as an MotionEvent.ACTION_UP event.
If you want to make sure the user still has their finger on the button do bounds checking during MotionEvent.ACTION_MOVE events or if you don't care if the user drags their finger off of the button just check for a MotionEvent.ACTION_UP event.