ScaleGestureDetector
open class ScaleGestureDetector
kotlin.Any | |
↳ | android.view.ScaleGestureDetector |
Detects scaling transformation gestures using the supplied MotionEvent
s. The OnScaleGestureListener
callback will notify users when a particular gesture event has occurred. This class should only be used with MotionEvent
s reported via touch. To use this class:
- Create an instance of the
ScaleGestureDetector
for yourView
- In the
View.onTouchEvent(MotionEvent)
method ensure you callonTouchEvent(android.view.MotionEvent)
. The methods defined in your callback will be executed when the events occur.
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 | |
---|---|
ScaleGestureDetector(context: Context, listener: ScaleGestureDetector.OnScaleGestureListener) Creates a ScaleGestureDetector with the supplied listener. |
|
ScaleGestureDetector(context: Context, listener: ScaleGestureDetector.OnScaleGestureListener, handler: Handler?) 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 |
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 |
onTouchEvent(event: MotionEvent) Accepts MotionEvents and dispatches events to a |
open Unit |
setQuickScaleEnabled(scales: Boolean) Set whether the associated |
open Unit |
setStylusScaleEnabled(scales: Boolean) Sets whether the associated |
Public constructors
ScaleGestureDetector
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
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. |
See Also
Public methods
getCurrentSpan
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
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
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
open fun getEventTime(): Long
Return the event time of the current event being processed.
Return | |
---|---|
Long |
Current event time in milliseconds. |
getFocusX
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
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
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
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
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
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
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
open fun isInProgress(): Boolean
Returns true
if a scale gesture is in progress.
isQuickScaleEnabled
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
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
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
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
open fun setStylusScaleEnabled(scales: Boolean): Unit
Sets whether the associated 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. |