Cancel onTouchEvent when GestureDetector's onDoubleTap triggers - android

A View for freehand writing implements onTouchEvent for the drawing operations.
Besides, a GestureDetector recognises double tap events to wipe the drawing. However, when the double tap occurs, onTouchEvent triggers an ACTION_UP, which draws an unwanted point on the view.
In iOS I handled these kind of problems with the touchesCancelled method, is there something similar in Android?

I solved by handling onDoubleTapEvent instead of onDoubleTap.

Related

Difference between onSingleTapConfirmed and onSingleTapUp

What is the difference between onSingleTapConfirmed and onSingleTapUp in GestureDetector.SimpleOnGestureListener? Which one of these is similar to onClick methods?
According to the GestureDetector.SimpleOnGestureListener documentation,
onSingleTapConfirmed
Notified when a single-tap occurs.
UnlikeĀ onSingleTapUp(MotionEvent), this will only be called after the
detector is confident that the user's first tap is not followed by a
second tap leading to a double-tap gesture.
onSingleTapUp
Notified when a tap occurs with the upĀ MotionEventĀ that triggered it.
I think the onClick method is similar to onSingleTapConfirmed.
The onSingleTapUp() callback will occur when a tap gesture takes place with an up motion that triggered it, whilst onSingleTapConfirmed() will occur when a detected tap gesture is confirmed by the system as a single tap and not part of a double tap gesture.

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 ?

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

touchlisteners and textviews

Actually I'm trying to implement an ontouchlistener into my android (1.5) application.
therefore i implemented the "ontouchlistener" into the class, and then i put my code into the:
public boolean onTouchEvent (MotionEvent e){
//code
}
The problem is, that if I am dragging over an (e.g.) Spinner or EditTextView than this Method isn't called. The only way to solve this which i figured out is to add an ontouchlistener to each of this views manually:
((Spinner)(findViewById(R.id.spinner1))).setOnTouchListener(tl);
((Spinner)(findViewById(R.id.spinner2))).setOnTouchListener(tl);
(tl is the ontouchlistener)
So isn't there a way to catch the touch event before it gets to each of those views?
thanks in advance
Ripei
What exactly do you want to do - do you want to:
Detect whole gestures in some
Activity.
Detect touches only for a given
View
If you want the former:
Take a look at this example:
Fling gesture detection on grid layout.
Basically, you redirect all registered touch events to a GestureDetector.
It understands what exactly is the user input (single tap, double tap, scroll, etc.) and calls the corresponding callback in a SimpleOnGestureListener, which you should implement.
If you want the latter:
You can either:
Override the View's onTouchEvent().
Implement and hook onTouchListener (if you want to get the touch before it's dispatched to it).
If you want to implement onTouchListener, you'll be doing your work not in the onTouchEvent() method, but in the interface's onTouch() method.
Hope that helps.

Categories

Resources