Added in API level 1

GestureDetector

open class GestureDetector
kotlin.Any
   ↳ android.view.GestureDetector

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). To use this class:

Summary

Nested classes
abstract

The listener that is used to notify when a context click occurs.

abstract

The listener that is used to notify when a double-tap or a confirmed single-tap occur.

abstract

The listener that is used to notify when gestures occur.

open

A convenience class to extend when you only want to listen for a subset of all the gestures.

Public constructors

Creates a GestureDetector with the supplied listener.

Creates a GestureDetector with the supplied listener.

Creates a GestureDetector with the supplied listener.

Creates a GestureDetector with the supplied listener that runs deferred events on the thread associated with the supplied android.os.Handler.

GestureDetector(context: Context?, listener: GestureDetector.OnGestureListener, handler: Handler?, unused: Boolean)

Creates a GestureDetector with the supplied listener that runs deferred events on the thread associated with the supplied android.os.Handler.

Public methods
open Boolean

open Boolean

Analyzes the given generic motion event and if applicable triggers the appropriate callbacks on the OnGestureListener supplied.

open Boolean

Analyzes the given motion event and if applicable triggers the appropriate callbacks on the OnGestureListener supplied.

open Unit

Sets the listener which will be called for context clicks.

open Unit
setIsLongpressEnabled(isLongpressEnabled: Boolean)

Set whether longpress is enabled, if this is enabled when a user presses and holds down you get a longpress event and nothing further.

open Unit

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

Public constructors

GestureDetector

Added in API level 1
GestureDetector(
    listener: GestureDetector.OnGestureListener,
    handler: Handler?)

Deprecated: Use GestureDetector(android.content.Context,android.view.GestureDetector.OnGestureListener,android.os.Handler) instead.

Creates a GestureDetector with the supplied listener. This variant of the constructor should be used from a non-UI thread (as it allows specifying the Handler).

Parameters
listener GestureDetector.OnGestureListener: the listener invoked for all the callbacks, this must not be null.
handler Handler?: the handler to use This value may be null.
Exceptions
java.lang.NullPointerException if listener is null.

GestureDetector

Added in API level 1
GestureDetector(listener: GestureDetector.OnGestureListener)

Deprecated: Use GestureDetector(android.content.Context,android.view.GestureDetector.OnGestureListener) instead.

Creates a GestureDetector with the supplied listener. You may only use this constructor from a UI thread (this is the usual situation).

Parameters
listener GestureDetector.OnGestureListener: the listener invoked for all the callbacks, this must not be null.
Exceptions
java.lang.NullPointerException if listener is null.

GestureDetector

Added in API level 1
GestureDetector(
    context: Context?,
    listener: GestureDetector.OnGestureListener)

Creates a GestureDetector with the supplied listener. You may only use this constructor from a android.os.Looper thread.

Parameters
context Context?: An android.app.Activity or a Context created from Context#createWindowContext(int, Bundle) This value may be null.
listener GestureDetector.OnGestureListener: the listener invoked for all the callbacks, this must not be null. If the listener implements the OnDoubleTapListener or OnContextClickListener then it will also be set as the listener for these callbacks (for example when using the SimpleOnGestureListener).
Exceptions
java.lang.NullPointerException if listener is null.

GestureDetector

Added in API level 1
GestureDetector(
    context: Context?,
    listener: GestureDetector.OnGestureListener,
    handler: Handler?)

Creates a GestureDetector with the supplied listener that runs deferred events on the thread associated with the supplied android.os.Handler.

Parameters
context Context?: An android.app.Activity or a Context created from Context#createWindowContext(int, Bundle) This value may be null.
listener GestureDetector.OnGestureListener: the listener invoked for all the callbacks, this must not be null. If the listener implements the OnDoubleTapListener or OnContextClickListener then it will also be set as the listener for these callbacks (for example when using the SimpleOnGestureListener).
handler Handler?: the handler to use for running deferred listener events. This value may be null.
Exceptions
java.lang.NullPointerException if listener is null.

GestureDetector

Added in API level 1
GestureDetector(
    context: Context?,
    listener: GestureDetector.OnGestureListener,
    handler: Handler?,
    unused: Boolean)

Creates a GestureDetector with the supplied listener that runs deferred events on the thread associated with the supplied android.os.Handler.

Parameters
context Context?: An android.app.Activity or a Context created from Context#createWindowContext(int, Bundle) This value may be null.
listener GestureDetector.OnGestureListener: the listener invoked for all the callbacks, this must not be null.
handler Handler?: the handler to use for running deferred listener events. This value may be null.
unused Boolean: currently not used.
Exceptions
java.lang.NullPointerException if listener is null.

Public methods

isLongpressEnabled

Added in API level 1
open fun isLongpressEnabled(): Boolean
Return
Boolean true if longpress is enabled, else false.

onGenericMotionEvent

Added in API level 23
open fun onGenericMotionEvent(ev: MotionEvent): Boolean

Analyzes the given generic motion event and if applicable triggers the appropriate callbacks on the OnGestureListener supplied.

Parameters
ev MotionEvent: The current motion event. This value cannot be null.
Return
Boolean true if the OnGestureListener consumed the event, else false.

onTouchEvent

Added in API level 1
open fun onTouchEvent(ev: MotionEvent): Boolean

Analyzes the given motion event and if applicable triggers the appropriate callbacks on the OnGestureListener supplied.

Parameters
ev MotionEvent: The current motion event. This value cannot be null.
Return
Boolean true if the OnGestureListener consumed the event, else false.

setContextClickListener

Added in API level 23
open fun setContextClickListener(onContextClickListener: GestureDetector.OnContextClickListener?): Unit

Sets the listener which will be called for context clicks.

Parameters
onContextClickListener GestureDetector.OnContextClickListener?: the listener invoked for all the callbacks, or null to stop listening for context clicks.

setIsLongpressEnabled

Added in API level 1
open fun setIsLongpressEnabled(isLongpressEnabled: Boolean): Unit

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
isLongpressEnabled Boolean: whether longpress should be enabled.

setOnDoubleTapListener

Added in API level 3
open fun setOnDoubleTapListener(onDoubleTapListener: GestureDetector.OnDoubleTapListener?): Unit

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

Parameters
onDoubleTapListener GestureDetector.OnDoubleTapListener?: the listener invoked for all the callbacks, or null to stop listening for double-tap gestures.