Detect multitouch with Ontouch listener Android - 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

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.

Android: detect driving over an ImageView with a finger?

With which onTouchListener Event i can detect " Driving with the finger over an ImageView"?
You need to implement View.OnTouchListener.
Then override onTouch() in your Activity, and in ACTION_DOWN and ACTION_UP, check the coordinates of the touch point from the MotionEvent to see if they are in the area covered by the ImageView.
That's conflicts principle of giving responsibility to objects. ImageView should be aware of it's touch events, not the activity or fragment.

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 ?

Android MotionEvent - Cant find Left and Right Motion Event

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.

Categories

Resources