# 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)

*** ** * ** ***


```
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/kotlin/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/kotlin/androidx/core/view/GestureDetectorCompat#GestureDetectorCompat(android.content.Context,android.view.GestureDetector.OnGestureListener))( context: https://developer.android.com/reference/android/content/Context.html, listener: https://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html )` **This function is deprecated.** Deprecated in Java |
| `[GestureDetectorCompat](https://developer.android.com/reference/kotlin/androidx/core/view/GestureDetectorCompat#GestureDetectorCompat(android.content.Context,android.view.GestureDetector.OnGestureListener,android.os.Handler))( context: https://developer.android.com/reference/android/content/Context.html, listener: https://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html, handler: https://developer.android.com/reference/android/os/Handler.html? )` **This function is deprecated.** Deprecated in Java |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `[isLongpressEnabled](https://developer.android.com/reference/kotlin/androidx/core/view/GestureDetectorCompat#isLongpressEnabled())()` **This function is deprecated.** Deprecated in Java |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `[onTouchEvent](https://developer.android.com/reference/kotlin/androidx/core/view/GestureDetectorCompat#onTouchEvent(android.view.MotionEvent))(event: https://developer.android.com/reference/android/view/MotionEvent.html)` **This function is deprecated.** Deprecated in Java |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `[setIsLongpressEnabled](https://developer.android.com/reference/kotlin/androidx/core/view/GestureDetectorCompat#setIsLongpressEnabled(boolean))(enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` **This function is deprecated.** Deprecated in Java |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `[setOnDoubleTapListener](https://developer.android.com/reference/kotlin/androidx/core/view/GestureDetectorCompat#setOnDoubleTapListener(android.view.GestureDetector.OnDoubleTapListener))(listener: https://developer.android.com/reference/android/view/GestureDetector.OnDoubleTapListener.html?)` **This function 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)

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

> [!CAUTION]
> **This function 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 |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | the application's context |
| `listener: https://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html` | 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)

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

> [!CAUTION]
> **This function 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 |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | the application's context |
| `listener: https://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html` | the listener invoked for all the callbacks, this must not be null. |
| `handler: https://developer.android.com/reference/android/os/Handler.html?` | the handler that will be used for posting deferred messages |

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

## Public functions

### 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)

```
fun [isLongpressEnabled](https://developer.android.com/reference/kotlin/androidx/core/view/GestureDetectorCompat#isLongpressEnabled())(): Boolean
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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)

```
fun [onTouchEvent](https://developer.android.com/reference/kotlin/androidx/core/view/GestureDetectorCompat#onTouchEvent(android.view.MotionEvent))(event: MotionEvent): Boolean
```

> [!CAUTION]
> **This function 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 |
|---|---|
| `event: https://developer.android.com/reference/android/view/MotionEvent.html` | The current motion event. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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)

```
fun [setIsLongpressEnabled](https://developer.android.com/reference/kotlin/androidx/core/view/GestureDetectorCompat#setIsLongpressEnabled(boolean))(enabled: Boolean): Unit
```

> [!CAUTION]
> **This function 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 |
|---|---|
| `enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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)

```
fun [setOnDoubleTapListener](https://developer.android.com/reference/kotlin/androidx/core/view/GestureDetectorCompat#setOnDoubleTapListener(android.view.GestureDetector.OnDoubleTapListener))(listener: GestureDetector.OnDoubleTapListener?): Unit
```

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

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

| Parameters |
|---|---|
| `listener: https://developer.android.com/reference/android/view/GestureDetector.OnDoubleTapListener.html?` | the listener invoked for all the callbacks, or null to stop listening for double-tap gestures. |