-
public final class GestureDetectorCompat
Detects various gestures and events using the supplied MotionEvents. The OnGestureListener callback will notify users when a particular motion event has occurred. This class should only be used with MotionEvents reported via touch (don't use for trackball events).
This compatibility implementation of the framework's GestureDetector guarantees the newer focal point scrolling behavior from Jellybean MR1 on all platform versions.
To use this class:- Create an instance of the
{@code GestureDetectorCompat}
for your View - In the onTouchEvent method ensure you call onTouchEvent. The methods defined in your callback will be executed when the events occur.
- Create an instance of the
-
-
Constructor Summary
Constructors Constructor Description GestureDetectorCompat(Context context, GestureDetector.OnGestureListener listener)
Creates a GestureDetectorCompat with the supplied listener.As usual, you may only use this constructor from a UI thread. GestureDetectorCompat(Context context, GestureDetector.OnGestureListener listener, Handler handler)
Creates a GestureDetectorCompat with the supplied listener.As usual, you may only use this constructor from a UI thread.
-
Method Summary
Modifier and Type Method Description boolean
isLongpressEnabled()
boolean
onTouchEvent(MotionEvent event)
Analyzes the given motion event and if applicable triggers theappropriate callbacks on the OnGestureListener supplied. void
setIsLongpressEnabled(boolean enabled)
Set whether longpress is enabled, if this is enabled when a userpresses and holds down you get a longpress event and nothing further.If it's disabled the user can press and hold down and then latermoved their finger and you will get scroll events. void
setOnDoubleTapListener(GestureDetector.OnDoubleTapListener listener)
Sets the listener which will be called for double-tap and relatedgestures. -
-
Constructor Detail
-
GestureDetectorCompat
GestureDetectorCompat(Context context, GestureDetector.OnGestureListener listener)
Creates a GestureDetectorCompat with the supplied listener.As usual, you may only use this constructor from a UI thread.- Parameters:
context
- the application's contextlistener
- the listener invoked for all the callbacks, this mustnot be null.
-
GestureDetectorCompat
GestureDetectorCompat(Context context, GestureDetector.OnGestureListener listener, Handler handler)
Creates a GestureDetectorCompat with the supplied listener.As usual, you may only use this constructor from a UI thread.- Parameters:
context
- the application's contextlistener
- the listener invoked for all the callbacks, this mustnot be null.handler
- the handler that will be used for posting deferred messages
-
-
Method Detail
-
isLongpressEnabled
boolean isLongpressEnabled()
-
onTouchEvent
boolean onTouchEvent(MotionEvent event)
Analyzes the given motion event and if applicable triggers theappropriate callbacks on the OnGestureListener supplied.
- Parameters:
event
- The current motion event.
-
setIsLongpressEnabled
void setIsLongpressEnabled(boolean enabled)
Set whether longpress is enabled, if this is enabled when a userpresses and holds down you get a longpress event and nothing further.If it's disabled the user can press and hold down and then latermoved their finger and you will get scroll events. By defaultlongpress is enabled.
- Parameters:
enabled
- whether longpress should be enabled.
-
setOnDoubleTapListener
void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener listener)
Sets the listener which will be called for double-tap and relatedgestures.
- Parameters:
listener
- the listener invoked for all the callbacks, ornull to stop listening for double-tap gestures.
-
-
-
-