# GestureDetectorCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/view/GestureDetectorCompat.java+class:androidx.core.view.GestureDetectorCompat) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

*** ** * ** ***


```
public final class GestureDetectorCompat
```

<br />

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
>
> Use `https://developer.android.com/reference/android/view/GestureDetector.html` directly

Detects various gestures and events using the supplied `https://developer.android.com/reference/android/view/MotionEvent.html`s. The `https://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html` callback will notify users when a particular motion event has occurred. This class should only be used with `https://developer.android.com/reference/android/view/MotionEvent.html`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 `GestureDetectorCompat` for your `https://developer.android.com/reference/android/view/View.html`
- In the `https://developer.android.com/reference/android/view/View.html#onTouchEvent(android.view.MotionEvent)` method ensure you call `https://developer.android.com/reference/androidx/core/view/GestureDetectorCompat#onTouchEvent(android.view.MotionEvent)`. The methods defined in your callback will be executed when the events occur.

## Summary

| ### Public constructors |
|---|
| `[GestureDetectorCompat](https://developer.android.com/reference/androidx/core/view/GestureDetectorCompat#GestureDetectorCompat(android.content.Context,android.view.GestureDetector.OnGestureListener))( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html listener )` **This method is deprecated.** Deprecated in Java |
| `[GestureDetectorCompat](https://developer.android.com/reference/androidx/core/view/GestureDetectorCompat#GestureDetectorCompat(android.content.Context,android.view.GestureDetector.OnGestureListener,android.os.Handler))( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html listener, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Handler.html handler )` **This method is deprecated.** Deprecated in Java |

| ### Public methods |
|---|---|
| `boolean` | `[isLongpressEnabled](https://developer.android.com/reference/androidx/core/view/GestureDetectorCompat#isLongpressEnabled())()` **This method is deprecated.** Deprecated in Java |
| `boolean` | `[onTouchEvent](https://developer.android.com/reference/androidx/core/view/GestureDetectorCompat#onTouchEvent(android.view.MotionEvent))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/MotionEvent.html event)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setIsLongpressEnabled](https://developer.android.com/reference/androidx/core/view/GestureDetectorCompat#setIsLongpressEnabled(boolean))(boolean enabled)` **This method is deprecated.** Deprecated in Java |
| `void` | `[setOnDoubleTapListener](https://developer.android.com/reference/androidx/core/view/GestureDetectorCompat#setOnDoubleTapListener(android.view.GestureDetector.OnDoubleTapListener))( @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/view/GestureDetector.OnDoubleTapListener.html listener )` **This method is deprecated.** Deprecated in Java |

## Public constructors

### GestureDetectorCompat

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
public [GestureDetectorCompat](https://developer.android.com/reference/androidx/core/view/GestureDetectorCompat#GestureDetectorCompat(android.content.Context,android.view.GestureDetector.OnGestureListener))(
    @NonNull Context context,
    @NonNull GestureDetector.OnGestureListener listener
)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Creates a GestureDetectorCompat with the supplied listener. As usual, you may only use this constructor from a UI thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | the application's context |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html listener` | the listener invoked for all the callbacks, this must not be null. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/os/Handler.html#Handler()` |   |

### GestureDetectorCompat

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
public [GestureDetectorCompat](https://developer.android.com/reference/androidx/core/view/GestureDetectorCompat#GestureDetectorCompat(android.content.Context,android.view.GestureDetector.OnGestureListener,android.os.Handler))(
    @NonNull Context context,
    @NonNull GestureDetector.OnGestureListener listener,
    @Nullable Handler handler
)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Creates a GestureDetectorCompat with the supplied listener. As usual, you may only use this constructor from a UI thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | the application's context |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html listener` | the listener invoked for all the callbacks, this must not be null. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Handler.html handler` | the handler that will be used for posting deferred messages |

| See also |
|---|---|
| `https://developer.android.com/reference/android/os/Handler.html#Handler()` |   |

## Public methods

### isLongpressEnabled

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
public boolean [isLongpressEnabled](https://developer.android.com/reference/androidx/core/view/GestureDetectorCompat#isLongpressEnabled())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

| Returns |
|---|---|
| `boolean` | true if longpress is enabled, else false. |

### onTouchEvent

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
public boolean [onTouchEvent](https://developer.android.com/reference/androidx/core/view/GestureDetectorCompat#onTouchEvent(android.view.MotionEvent))(@NonNull MotionEvent event)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Analyzes the given motion event and if applicable triggers the appropriate callbacks on the `https://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html` supplied.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/MotionEvent.html event` | The current motion event. |

| Returns |
|---|---|
| `boolean` | true if the `https://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html` consumed the event, else false. |

### setIsLongpressEnabled

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
public void [setIsLongpressEnabled](https://developer.android.com/reference/androidx/core/view/GestureDetectorCompat#setIsLongpressEnabled(boolean))(boolean enabled)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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.

| Parameters |
|---|---|
| `boolean enabled` | whether longpress should be enabled. |

### setOnDoubleTapListener

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
public void [setOnDoubleTapListener](https://developer.android.com/reference/androidx/core/view/GestureDetectorCompat#setOnDoubleTapListener(android.view.GestureDetector.OnDoubleTapListener))(
    @Nullable GestureDetector.OnDoubleTapListener listener
)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Sets the listener which will be called for double-tap and related gestures.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/view/GestureDetector.OnDoubleTapListener.html listener` | the listener invoked for all the callbacks, or null to stop listening for double-tap gestures. |