-
public class ScaleGestureDetectorDetects 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:
- Create an instance of the
{@code ScaleGestureDetector}for your View - In the onTouchEvent method ensure you call onTouchEvent. The methods defined in your callback will be executed when the events occur.
- Create an instance of the
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceScaleGestureDetector.OnScaleGestureListenerThe listener for receiving notifications when gestures occur.If you want to listen for all the different gestures then implementthis interface. If you only want to listen for a subset it mightbe easier to extend SimpleOnScaleGestureListener.An application will receive events in the following order:
- One onScaleBegin
- Zero or more onScale
- One onScaleEnd
public classScaleGestureDetector.SimpleOnScaleGestureListenerA convenience class to extend when you only want to listen for a subsetof scaling-related events. This implements all methods in OnScaleGestureListener but does nothing. onScale returns
{@code false}so that a subclass can retrieve the accumulated scalefactor in an overridden onScaleEnd. onScaleBegin returns{@code true}.
-
Constructor Summary
Constructors Constructor Description ScaleGestureDetector(Context context, ScaleGestureDetector.OnScaleGestureListener listener)Creates a ScaleGestureDetector with the supplied listener. ScaleGestureDetector(Context context, ScaleGestureDetector.OnScaleGestureListener listener, Handler handler)Creates a ScaleGestureDetector with the supplied listener.
-
Method Summary
Modifier and Type Method Description booleanonTouchEvent(MotionEvent event)Accepts MotionEvents and dispatches events to a OnScaleGestureListener when appropriate. voidsetQuickScaleEnabled(boolean scales)Set whether the associated OnScaleGestureListener should receive onScale callbackswhen the user performs a doubleTap followed by a swipe. booleanisQuickScaleEnabled()Return whether the quick scale gesture, in which the user performs a double tap followed by aswipe, should perform scaling. voidsetStylusScaleEnabled(boolean scales)Sets whether the associates OnScaleGestureListener should receiveonScale 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. booleanisStylusScaleEnabled()Return whether the stylus scale gesture, in which the user uses a stylus and presses thebutton, should perform scaling. booleanisInProgress()Returns {@code true}if a scale gesture is in progress.floatgetFocusX()Get the X coordinate of the current gesture's focal point.If a gesture is in progress, the focal point is betweeneach of the pointers forming the gesture. floatgetFocusY()Get the Y coordinate of the current gesture's focal point.If a gesture is in progress, the focal point is betweeneach of the pointers forming the gesture. floatgetCurrentSpan()Return the average distance between each of the pointers forming thegesture in progress through the focal point. floatgetCurrentSpanX()Return the average X distance between each of the pointers forming thegesture in progress through the focal point. floatgetCurrentSpanY()Return the average Y distance between each of the pointers forming thegesture in progress through the focal point. floatgetPreviousSpan()Return the previous average distance between each of the pointers forming thegesture in progress through the focal point. floatgetPreviousSpanX()Return the previous average X distance between each of the pointers forming thegesture in progress through the focal point. floatgetPreviousSpanY()Return the previous average Y distance between each of the pointers forming thegesture in progress through the focal point. floatgetScaleFactor()Return the scaling factor from the previous scale event to the currentevent. longgetTimeDelta()Return the time difference in milliseconds between the previousaccepted scaling event and the current scaling event. longgetEventTime()Return the event time of the current event being processed. -
-
Constructor Detail
-
ScaleGestureDetector
ScaleGestureDetector(Context context, ScaleGestureDetector.OnScaleGestureListener listener)
Creates a ScaleGestureDetector with the supplied listener.- Parameters:
context- the application's contextlistener- the listener invoked for all the callbacks, this mustnot be null.
-
ScaleGestureDetector
ScaleGestureDetector(Context context, ScaleGestureDetector.OnScaleGestureListener listener, Handler handler)
Creates a ScaleGestureDetector with the supplied listener.- Parameters:
context- the application's contextlistener- the listener invoked for all the callbacks, this mustnot be null.handler- the handler to use for running deferred listener events.
-
-
Method Detail
-
onTouchEvent
boolean onTouchEvent(MotionEvent event)
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 initialACTION_DOWN to the final ACTION_UP or ACTION_CANCEL.
- Parameters:
event- The event to process
-
setQuickScaleEnabled
void setQuickScaleEnabled(boolean scales)
Set whether the associated OnScaleGestureListener should receive onScale callbackswhen the user performs a doubleTap followed by a swipe. Note that this is enabled by defaultif the app targets API 19 and newer.
- Parameters:
scales- true to enable quick scaling, false to disable
-
isQuickScaleEnabled
boolean isQuickScaleEnabled()
Return whether the quick scale gesture, in which the user performs a double tap followed by aswipe, should perform scaling. {@see #setQuickScaleEnabled(boolean)}.
-
setStylusScaleEnabled
void setStylusScaleEnabled(boolean scales)
Sets whether the associates OnScaleGestureListener should receiveonScale 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- true to enable stylus scaling, false to disable.
-
isStylusScaleEnabled
boolean isStylusScaleEnabled()
Return whether the stylus scale gesture, in which the user uses a stylus and presses thebutton, should perform scaling. {@see #setStylusScaleEnabled(boolean)}
-
isInProgress
boolean isInProgress()
Returns
{@code true}if a scale gesture is in progress.
-
getFocusX
float getFocusX()
Get the X coordinate of the current gesture's focal point.If a gesture is in progress, the focal point is betweeneach of the pointers forming the gesture.If isInProgress would return false, the result of thisfunction is undefined.
-
getFocusY
float getFocusY()
Get the Y coordinate of the current gesture's focal point.If a gesture is in progress, the focal point is betweeneach of the pointers forming the gesture.If isInProgress would return false, the result of thisfunction is undefined.
-
getCurrentSpan
float getCurrentSpan()
Return the average distance between each of the pointers forming thegesture in progress through the focal point.
-
getCurrentSpanX
float getCurrentSpanX()
Return the average X distance between each of the pointers forming thegesture in progress through the focal point.
-
getCurrentSpanY
float getCurrentSpanY()
Return the average Y distance between each of the pointers forming thegesture in progress through the focal point.
-
getPreviousSpan
float getPreviousSpan()
Return the previous average distance between each of the pointers forming thegesture in progress through the focal point.
-
getPreviousSpanX
float getPreviousSpanX()
Return the previous average X distance between each of the pointers forming thegesture in progress through the focal point.
-
getPreviousSpanY
float getPreviousSpanY()
Return the previous average Y distance between each of the pointers forming thegesture in progress through the focal point.
-
getScaleFactor
float getScaleFactor()
Return the scaling factor from the previous scale event to the currentevent. This value is defined as(getCurrentSpan / getPreviousSpan).
-
getTimeDelta
long getTimeDelta()
Return the time difference in milliseconds between the previousaccepted scaling event and the current scaling event.
-
getEventTime
long getEventTime()
Return the event time of the current event being processed.
-
-
-
-