public class GestureDetector extends Object
MotionEvent
s.
The GestureDetector.OnGestureListener
callback will notify users when a particular
motion event has occurred. This class should only be used with MotionEvent
s
reported via touch (don't use for trackball events).
To use this class:
GestureDetector
for your View
View.onTouchEvent(MotionEvent)
method ensure you call
onTouchEvent(MotionEvent)
. The methods defined in your callback
will be executed when the events occur.
GestureDetector.OnContextClickListener.onContextClick(MotionEvent)
you must call onGenericMotionEvent(MotionEvent)
in View.onGenericMotionEvent(MotionEvent)
.
Modifier and Type | Class and Description |
---|---|
static interface |
GestureDetector.OnContextClickListener
The listener that is used to notify when a context click occurs.
|
static interface |
GestureDetector.OnDoubleTapListener
The listener that is used to notify when a double-tap or a confirmed
single-tap occur.
|
static interface |
GestureDetector.OnGestureListener
The listener that is used to notify when gestures occur.
|
static class |
GestureDetector.SimpleOnGestureListener
A convenience class to extend when you only want to listen for a subset
of all the gestures.
|
Constructor and Description |
---|
GestureDetector(Context context,
GestureDetector.OnGestureListener listener)
Creates a GestureDetector with the supplied listener.
|
GestureDetector(Context context,
GestureDetector.OnGestureListener listener,
Handler handler)
Creates a GestureDetector with the supplied listener that runs deferred events on the
thread associated with the supplied
Handler . |
GestureDetector(Context context,
GestureDetector.OnGestureListener listener,
Handler handler,
boolean unused)
Creates a GestureDetector with the supplied listener that runs deferred events on the
thread associated with the supplied
Handler . |
GestureDetector(GestureDetector.OnGestureListener listener)
Deprecated.
|
GestureDetector(GestureDetector.OnGestureListener listener,
Handler handler)
|
Modifier and Type | Method and Description |
---|---|
boolean |
isLongpressEnabled() |
boolean |
onGenericMotionEvent(MotionEvent ev)
Analyzes the given generic motion event and if applicable triggers the
appropriate callbacks on the
GestureDetector.OnGestureListener supplied. |
boolean |
onTouchEvent(MotionEvent ev)
Analyzes the given motion event and if applicable triggers the
appropriate callbacks on the
GestureDetector.OnGestureListener supplied. |
void |
setContextClickListener(GestureDetector.OnContextClickListener onContextClickListener)
Sets the listener which will be called for context clicks.
|
void |
setIsLongpressEnabled(boolean isLongpressEnabled)
Set whether longpress is enabled, if this is enabled when a user
presses and holds down you get a longpress event and nothing further.
|
void |
setOnDoubleTapListener(GestureDetector.OnDoubleTapListener onDoubleTapListener)
Sets the listener which will be called for double-tap and related
gestures.
|
@Deprecated public GestureDetector(GestureDetector.OnGestureListener listener, Handler handler)
GestureDetector(android.content.Context,
android.view.GestureDetector.OnGestureListener, android.os.Handler)
instead.listener
- the listener invoked for all the callbacks, this must
not be null.handler
- the handler to useNullPointerException
- if either listener
or
handler
is null.@Deprecated public GestureDetector(GestureDetector.OnGestureListener listener)
GestureDetector(android.content.Context,
android.view.GestureDetector.OnGestureListener)
instead.listener
- the listener invoked for all the callbacks, this must
not be null.NullPointerException
- if listener
is null.Handler.Handler()
public GestureDetector(Context context, GestureDetector.OnGestureListener listener)
Looper
thread.context
- the application's contextlistener
- the listener invoked for all the callbacks, this must
not be null.NullPointerException
- if listener
is null.Handler.Handler()
public GestureDetector(Context context, GestureDetector.OnGestureListener listener, Handler handler)
Handler
.context
- the application's contextlistener
- the listener invoked for all the callbacks, this must
not be null.handler
- the handler to use for running deferred listener events.NullPointerException
- if listener
is null.Handler.Handler()
public GestureDetector(Context context, GestureDetector.OnGestureListener listener, Handler handler, boolean unused)
Handler
.context
- the application's contextlistener
- the listener invoked for all the callbacks, this must
not be null.handler
- the handler to use for running deferred listener events.unused
- currently not used.NullPointerException
- if listener
is null.Handler.Handler()
public void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener onDoubleTapListener)
onDoubleTapListener
- the listener invoked for all the callbacks, or
null to stop listening for double-tap gestures.public void setContextClickListener(GestureDetector.OnContextClickListener onContextClickListener)
onContextClickListener
- the listener invoked for all the callbacks, or null to stop
listening for context clicks.public void setIsLongpressEnabled(boolean isLongpressEnabled)
isLongpressEnabled
- whether longpress should be enabled.public boolean isLongpressEnabled()
public boolean onTouchEvent(MotionEvent ev)
GestureDetector.OnGestureListener
supplied.ev
- The current motion event.GestureDetector.OnGestureListener
consumed the event,
else false.public boolean onGenericMotionEvent(MotionEvent ev)
GestureDetector.OnGestureListener
supplied.ev
- The current motion event.GestureDetector.OnGestureListener
consumed the event,
else false.