FileDocCategorySizeDatePackage
GestureDetectorCompat.javaAPI DocAndroid 5.1 API22916Thu Mar 12 22:22:56 GMT 2015android.support.v4.view

GestureDetectorCompat

public class GestureDetectorCompat extends Object
Detects various gestures and events using the supplied {@link MotionEvent}s. The {@link OnGestureListener} callback will notify users when a particular motion event has occurred. This class should only be used with {@link MotionEvent}s 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 {@link View}
  • In the {@link View#onTouchEvent(MotionEvent)} method ensure you call {@link #onTouchEvent(MotionEvent)}. The methods defined in your callback will be executed when the events occur.

Fields Summary
private final GestureDetectorCompatImpl
mImpl
Constructors Summary
public GestureDetectorCompat(android.content.Context context, android.view.GestureDetector.OnGestureListener listener)
Creates a GestureDetectorCompat with the supplied listener. As usual, you may only use this constructor from a UI thread.

see
android.os.Handler#Handler()
param
context the application's context
param
listener the listener invoked for all the callbacks, this must not be null.

        this(context, listener, null);
    
public GestureDetectorCompat(android.content.Context context, android.view.GestureDetector.OnGestureListener listener, android.os.Handler handler)
Creates a GestureDetectorCompat with the supplied listener. As usual, you may only use this constructor from a UI thread.

see
android.os.Handler#Handler()
param
context the application's context
param
listener the listener invoked for all the callbacks, this must not be null.
param
handler the handler that will be used for posting deferred messages

        if (Build.VERSION.SDK_INT > 17) {
            mImpl = new GestureDetectorCompatImplJellybeanMr2(context, listener, handler);
        } else {
            mImpl = new GestureDetectorCompatImplBase(context, listener, handler);
        }
    
Methods Summary
public booleanisLongpressEnabled()

return
true if longpress is enabled, else false.

        return mImpl.isLongpressEnabled();
    
public booleanonTouchEvent(android.view.MotionEvent event)
Analyzes the given motion event and if applicable triggers the appropriate callbacks on the {@link OnGestureListener} supplied.

param
event The current motion event.
return
true if the {@link OnGestureListener} consumed the event, else false.

        return mImpl.onTouchEvent(event);
    
public voidsetIsLongpressEnabled(boolean enabled)
Set whether longpress is enabled, if this is enabled when a user presses and holds down you get a longpress event and nothing further. If it's disabled the user can press and hold down and then later moved their finger and you will get scroll events. By default longpress is enabled.

param
enabled whether longpress should be enabled.

        mImpl.setIsLongpressEnabled(enabled);
    
public voidsetOnDoubleTapListener(android.view.GestureDetector.OnDoubleTapListener listener)
Sets the listener which will be called for double-tap and related gestures.

param
listener the listener invoked for all the callbacks, or null to stop listening for double-tap gestures.

        mImpl.setOnDoubleTapListener(listener);