I want to fire a method after a touch has been initiated and left the screen. I can detect the beginning of a touch by setting a OnTouch event to the View but can't detect when the hand leave the screen. I want to detect when does the touch stops. How can i detect this?
What you're looking for is http://developer.android.com/reference/android/view/MotionEvent.html - Specifically the use of MotionEvent.ACTION_UP. There is a lot of information on the link I've provided :)
A gesture starts with a motion event with ACTION_DOWN that provides the location of the first pointer down. As each additional pointer that goes down or up, the framework will generate a motion event with ACTION_POINTER_DOWN or ACTION_POINTER_UP accordingly. Pointer movements are described by motion events with ACTION_MOVE. Finally, a gesture end either when the final pointer goes up as represented by a motion event with ACTION_UP or when gesture is canceled with ACTION_CANCEL.
you can use MotionEvent.ACTION_UP to detect touch up.
I would look at this answer. Basically it says that you need to return true to process anything other than ACTION_DOWN.
Related
I am overriding both onTouch and onClick. Each is supposed to result in different actions (very important). I don't want a touch to be both a touch and a click: it must be either-or. I am not having much luck. How do I get my app to discriminate between onTouch and onClick? Right now, either I get onTouch by itself or I get both onTouch and onClick together (based on whether I change onTouch to return true or false).
An easy solution is to just use onTouch(). Look for ACTION_UP and ACTION_DOWN. Store the position of the touch in ACTION_DOWN, and in ACTION_UP if the distance between the touch and the stored touch are < X then fire a custom click event, otherwise fire the drag event.
I am a newbie in Android, lately I got this weird thing:
I have my customized View, in onTouchEvent method, i tried to detect multitouch gesture, but the MotionEvent.ACTION_POINTER_DOWN will always be triggered no matter my second finger touches the view or not.
It seems like ACTION_POINTER_DOWN doesn't behaves the same as ACTION_DOWN, since ACTION_DOWN will not be triggered if my finger didn't touch the view.
Please tell me what's wrong with that, is that a bug?
Its working as intended. Once you touch down, all touch events go to your view until a cancel or an up occurs.
Hi all in my android app I move objects on screen as per user input.
Basically I have to take care of two inputs - drag and UP(touch & remove)
So I implemented Gesture listener where the two methods -
onScroll() & onSingleTapUp() were used to handle these two input events.
But onSingleTapUp() does not work if the user has kept her finger for a long time on screen and then lifted it up.
So the conditions now require me implement onTouch to harness the MotionEvent.ACTION_UP functionality.
But would it be a good idea to use both onTouch & Gesture Listener.
Or should I shift my code to onTouch and remove gesture listener ?
I currently have an imageview element that upon being touched, that tests if the action is an actiondown event, and if it is, it gets the coordinates of the touch with getraw(x or y) and then carries out an action based on those coordinates. How would I implement this to get two sets of coordinates from a two finger multitouch event?
Take a look at the ACTION_POINTER_DOWN action define in MotionEvent. This is the event that will get called when additional fingers come down after the first ACTION_DOWN triggers. You can use methods like getActionMasked() to assist you in determining which finger events are related to.
MotionEvent Docs
HTH
This is a nice example
I want to track a finger touch on the screen. So what I did was to start recording the position when MotionEvent triggers ACTION_DOWN, but how do I know when the action is finished, at ACTION_CANCEL, or ACTION_UP?
What's the exact difference between them?
MotionEvent:
ACTION_UP: A pressed gesture has finished, the motion contains the final release location as well as any intermediate points since the last down or move event.
ACTION_CANCEL: The current gesture has been aborted.
ACTION_CANCEL occurs when the parent takes possession of the motion, for example when the user has dragged enough across a list view that it will start scrolling instead of letting you press the buttons inside of it. You can find out more about it at the viewgroup documentation: onInterceptTouchEvent.
so use ACTION_CANCEL when the action is dragged out of the parent, and ACTION_UP otherwise.
In general ACTION_UP is triggered by user when the guest is finished to definitely indicate that the user completed interacting with movement.
On the other hand ACTION_CANCEL is called by Android system to indicate that one of views took control using onInterceptTouchEvent() which returned true as a result system finished propagating the touch event.
Please take a look at a diagram