Added in API level 8

ScaleGestureDetector


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

Detects scaling transformation gestures using the supplied MotionEvents. The OnScaleGestureListener callback will notify users when a particular gesture event has occurred. This class should only be used with MotionEvents reported via touch. To use this class:

Summary

Nested classes
abstract

The listener for receiving notifications when gestures occur.

open

A convenience class to extend when you only want to listen for a subset of scaling-related events.

Public constructors

Creates a ScaleGestureDetector with the supplied listener.

Creates a ScaleGestureDetector with the supplied listener.

Public methods
open Float

Return the average distance between each of the pointers forming the gesture in progress through the focal point.

open Float

Return the average X distance between each of the pointers forming the gesture in progress through the focal point.

open Float

Return the average Y distance between each of the pointers forming the gesture in progress through the focal point.

open Long

Return the event time of the current event being processed.

open Float

Get the X coordinate of the current gesture's focal point.

open Float

Get the Y coordinate of the current gesture's focal point.

open Float

Return the previous average distance between each of the pointers forming the gesture in progress through the focal point.

open Float

Return the previous average X distance between each of the pointers forming the gesture in progress through the focal point.

open Float

Return the previous average Y distance between each of the pointers forming the gesture in progress through the focal point.

open Float

Return the scaling factor from the previous scale event to the current event.

open Long

Return the time difference in milliseconds between the previous accepted scaling event and the current scaling event.

open Boolean

Returns true if a scale gesture is in progress.

open Boolean

Return whether the quick scale gesture, in which the user performs a double tap followed by a swipe, should perform scaling.

open Boolean

Return whether the stylus scale gesture, in which the user uses a stylus and presses the button, should perform scaling.

open Boolean

Accepts MotionEvents and dispatches events to a OnScaleGestureListener when appropriate.

open Unit

Set whether the associated OnScaleGestureListener should receive onScale callbacks when the user performs a doubleTap followed by a swipe.

open Unit

Sets whether the associates OnScaleGestureListener should receive onScale callbacks when the user uses a stylus and presses the button.

Public constructors

ScaleGestureDetector

Added in API level 8
ScaleGestureDetector(
    context: Context,
    listener: ScaleGestureDetector.OnScaleGestureListener)

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

Parameters
context Context: the application's context This value cannot be null.
listener ScaleGestureDetector.OnScaleGestureListener: the listener invoked for all the callbacks, this must not be null.
Exceptions
java.lang.NullPointerException if listener is null.

ScaleGestureDetector

Added in API level 19
ScaleGestureDetector(
    context: Context,
    listener: ScaleGestureDetector.OnScaleGestureListener,
    handler: Handler?)

Creates a ScaleGestureDetector with the supplied listener.

Parameters
context Context: the application's context This value cannot be null.
listener ScaleGestureDetector.OnScaleGestureListener: 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.
Exceptions
java.lang.NullPointerException if listener is null.

Public methods

getCurrentSpan

Added in API level 8
open fun getCurrentSpan(): Float

Return the average distance between each of the pointers forming the gesture in progress through the focal point.

Return
Float Distance between pointers in pixels.

getCurrentSpanX

Added in API level 11
open fun getCurrentSpanX(): Float

Return the average X distance between each of the pointers forming the gesture in progress through the focal point.

Return
Float Distance between pointers in pixels.

getCurrentSpanY

Added in API level 11
open fun getCurrentSpanY(): Float

Return the average Y distance between each of the pointers forming the gesture in progress through the focal point.

Return
Float Distance between pointers in pixels.

getEventTime

Added in API level 8
open fun getEventTime(): Long

Return the event time of the current event being processed.

Return
Long Current event time in milliseconds.

getFocusX

Added in API level 8
open fun getFocusX(): Float

Get the X coordinate of the current gesture's focal point. If a gesture is in progress, the focal point is between each of the pointers forming the gesture. If isInProgress() would return false, the result of this function is undefined.

Return
Float X coordinate of the focal point in pixels.

getFocusY

Added in API level 8
open fun getFocusY(): Float

Get the Y coordinate of the current gesture's focal point. If a gesture is in progress, the focal point is between each of the pointers forming the gesture. If isInProgress() would return false, the result of this function is undefined.

Return
Float Y coordinate of the focal point in pixels.

getPreviousSpan

Added in API level 8
open fun getPreviousSpan(): Float

Return the previous average distance between each of the pointers forming the gesture in progress through the focal point.

Return
Float Previous distance between pointers in pixels.

getPreviousSpanX

Added in API level 11
open fun getPreviousSpanX(): Float

Return the previous average X distance between each of the pointers forming the gesture in progress through the focal point.

Return
Float Previous distance between pointers in pixels.

getPreviousSpanY

Added in API level 11
open fun getPreviousSpanY(): Float

Return the previous average Y distance between each of the pointers forming the gesture in progress through the focal point.

Return
Float Previous distance between pointers in pixels.

getScaleFactor

Added in API level 8
open fun getScaleFactor(): Float

Return the scaling factor from the previous scale event to the current event. This value is defined as (getCurrentSpan() / getPreviousSpan()).

Return
Float The current scaling factor.

getTimeDelta

Added in API level 8
open fun getTimeDelta(): Long

Return the time difference in milliseconds between the previous accepted scaling event and the current scaling event.

Return
Long Time difference since the last scaling event in milliseconds.

isInProgress

Added in API level 8
open fun isInProgress(): Boolean

Returns true if a scale gesture is in progress.

isQuickScaleEnabled

Added in API level 19
open fun isQuickScaleEnabled(): Boolean

Return whether the quick scale gesture, in which the user performs a double tap followed by a swipe, should perform scaling. {@see #setQuickScaleEnabled(boolean)}.

isStylusScaleEnabled

Added in API level 23
open fun isStylusScaleEnabled(): Boolean

Return whether the stylus scale gesture, in which the user uses a stylus and presses the button, should perform scaling. {@see #setStylusScaleEnabled(boolean)}

onTouchEvent

Added in API level 8
open fun onTouchEvent(event: MotionEvent): Boolean

Accepts MotionEvents and dispatches events to a OnScaleGestureListener when appropriate.

Applications should pass a complete and consistent event stream to this method. A complete and consistent event stream involves all MotionEvents from the initial ACTION_DOWN to the final ACTION_UP or ACTION_CANCEL.

Parameters
event MotionEvent: The event to process This value cannot be null.
Return
Boolean true if the event was processed and the detector wants to receive the rest of the MotionEvents in this event stream.

setQuickScaleEnabled

Added in API level 19
open fun setQuickScaleEnabled(scales: Boolean): Unit

Set whether the associated OnScaleGestureListener should receive onScale callbacks when the user performs a doubleTap followed by a swipe. Note that this is enabled by default if the app targets API 19 and newer.

Parameters
scales Boolean: true to enable quick scaling, false to disable

setStylusScaleEnabled

Added in API level 23
open fun setStylusScaleEnabled(scales: Boolean): Unit

Sets whether the associates OnScaleGestureListener should receive onScale callbacks when the user uses a stylus and presses the button. Note that this is enabled by default if the app targets API 23 and newer.

Parameters
scales Boolean: true to enable stylus scaling, false to disable.