Difference between onSingleTapConfirmed and onSingleTapUp - android

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.

Related

android why swipe on a textview will trigger onclick event?

I am using the default project template from Android Studio. When I swipe on the textView, the onClick event will get triggered. Is it the designed behavior or where did I do something wrong?
In my experience OnClick is triggered because when you put your finger on textView its ACTION_DOWN method gets called internally and after swipe when you remove your finger its ACTION_UP method gets called internally. So whenever these two combination gets called it calls the onClick method. So when you touch (ACTION_DOWN) the textView and swipe left/right and move your finger outside (without the ACTION_UP event) it won't get called because its ACTION_UP is not called.
PS. This is not the official definition/working of onClick... This is how it worked in my experience.
my solution is extending the parent viewgroup and examining motionevent in the onInterceptTouchEvent.

Cancel onTouchEvent when GestureDetector's onDoubleTap triggers

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.

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.

View.setClickable(false) but ACTION_DOWN events fired

I am trying to understand what clickable in Android means. I have a simple Button subclass which overrides onTouchEvent() and also implements OnTouchListener.onTouch() (returns false to let the event bubble up to the view) and I noticed that the callbacks are called with MotionEvent.ACTION_DOWN (listener first, the view method later), and nothing more. I thought clickable = false disables touch events completely, but apparently not. What does it really do? How can I make sure the view doesn't get any touch events at all (setEnabled(false) seems not to work at all, events for ACTION_DOWN, _MOVE and _UP are fired unhindered).
Why are some touch events handled and other are not for clickable = false? I find it pretty surprising behavior and inconsistent - I would expect MotionEvent.ACTION_UP to be fired as well, but maybe click listeners should not be called. Any guidance?
Update With setEnabled(false) only the View.onTouchEvent method is called, the listener is ignored. Even stranger...
As I understand, setClickable is for calling the onClickListener when you click on it, and the actions like ACTION_DOWN, ACTION_MOVE, ACTION_UP are for handling finger events on the View within a OnTouchListener.

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

Categories

Resources