Android MotionEvent - Cant find Left and Right Motion Event - android

i am developing one application in which there is an imageview...in which i want to move left or right using mouse touch...
for that i found "android.view.MotionEvent" but in MotionEvent there are few events among that
ACTION_CANCEL 2. ACTION_DOWN 3. ACTION_UP ......etc.
hence there is no such event for "LEFT" and "RIGHT" action....
so is there any other way to implement the "LEFT" and "RIGHT" move ??

You misunderstood MotionEvent class events. ACTION_DOWN, ACTION_UP are equal to pressed and unpressed events.
In order to detect events like LEFT and RIGHT swipe, you have to use Gesture Recognition. Try to follow this example.

Related

detect if the touch stopped on an android device screen

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.

capturing both clicks and drags in android

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.

Is it okay for a layout to have both onTouch listener as well as Gesture listener?

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 ?

Detect multitouch with Ontouch listener Android

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

What's the difference between ACTION_CANCEL and ACTION_UP in MotionEvent?

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

Categories

Resources