to top
Android APIs
public class

ScaleGestureDetector

extends Object
java.lang.Object
   ↳ android.view.ScaleGestureDetector

Class Overview

Detects scaling transformation gestures using the supplied MotionEvents. The ScaleGestureDetector.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
interface ScaleGestureDetector.OnScaleGestureListener The listener for receiving notifications when gestures occur. 
class ScaleGestureDetector.SimpleOnScaleGestureListener A convenience class to extend when you only want to listen for a subset of scaling-related events. 
Public Constructors

? Examples
ScaleGestureDetector( Context context, ScaleGestureDetector.OnScaleGestureListener listener)
Public Methods

? Examples
float getCurrentSpan()
Return the average distance between each of the pointers forming the gesture in progress through the focal point.

? Examples
float getCurrentSpanX()
Return the average X distance between each of the pointers forming the gesture in progress through the focal point.

? Examples
float getCurrentSpanY()
Return the average Y distance between each of the pointers forming the gesture in progress through the focal point.

? Examples
long getEventTime()
Return the event time of the current event being processed.

? Examples
float getFocusX()
Get the X coordinate of the current gesture's focal point.

? Examples
float getFocusY()
Get the Y coordinate of the current gesture's focal point.

? Examples
float getPreviousSpan()
Return the previous average distance between each of the pointers forming the gesture in progress through the focal point.

? Examples
float getPreviousSpanX()
Return the previous average X distance between each of the pointers forming the gesture in progress through the focal point.

? Examples
float getPreviousSpanY()
Return the previous average Y distance between each of the pointers forming the gesture in progress through the focal point.

? Examples
float getScaleFactor()
Return the scaling factor from the previous scale event to the current event.

? Examples
long getTimeDelta()
Return the time difference in milliseconds between the previous accepted scaling event and the current scaling event.

? Examples
boolean isInProgress()
Returns true if a scale gesture is in progress.

? Examples
boolean onTouchEvent( MotionEvent event)
Accepts MotionEvents and dispatches events to a ScaleGestureDetector.OnScaleGestureListener when appropriate.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ScaleGestureDetector (Context context, ScaleGestureDetector.OnScaleGestureListener listener)

Added in API level 8

Public Methods

public float getCurrentSpan ()

Added in API level 8

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

Returns
  • Distance between pointers in pixels.

public float getCurrentSpanX ()

Added in API level 11

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

Returns
  • Distance between pointers in pixels.

public float getCurrentSpanY ()

Added in API level 11

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

Returns
  • Distance between pointers in pixels.

public long getEventTime ()

Added in API level 8

Return the event time of the current event being processed.

Returns
  • Current event time in milliseconds.

public float getFocusX ()

Added in API level 8

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.

Returns
  • X coordinate of the focal point in pixels.

public float getFocusY ()

Added in API level 8

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.

Returns
  • Y coordinate of the focal point in pixels.

public float getPreviousSpan ()

Added in API level 8

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

Returns
  • Previous distance between pointers in pixels.

public float getPreviousSpanX ()

Added in API level 11

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

Returns
  • Previous distance between pointers in pixels.

public float getPreviousSpanY ()

Added in API level 11

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

Returns
  • Previous distance between pointers in pixels.

public float getScaleFactor ()

Added in API level 8

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

Returns
  • The current scaling factor.

public long getTimeDelta ()

Added in API level 8

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

Returns
  • Time difference since the last scaling event in milliseconds.

public boolean isInProgress ()

Added in API level 8

Returns true if a scale gesture is in progress.

public boolean onTouchEvent (MotionEvent event)

Added in API level 8

Accepts MotionEvents and dispatches events to a ScaleGestureDetector.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 The event to process
Returns
  • true if the event was processed and the detector wants to receive the rest of the MotionEvents in this event stream.
No examples for this method.
Frequently called with: [Clear]
Portions of this page are reproduced from work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License. The original page is available here.