Package 

Class ScaleGestureDetector


  • 
    public class 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:

    • 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.
    • Method Summary

      Modifier and Type Method Description
      boolean onTouchEvent(MotionEvent event) Accepts MotionEvents and dispatches events to a OnScaleGestureListener when appropriate.
      void setQuickScaleEnabled(boolean scales) Set whether the associated OnScaleGestureListener should receive onScale callbackswhen the user performs a doubleTap followed by a swipe.
      boolean isQuickScaleEnabled() Return whether the quick scale gesture, in which the user performs a double tap followed by aswipe, should perform scaling.
      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.
      boolean isStylusScaleEnabled() Return whether the stylus scale gesture, in which the user uses a stylus and presses thebutton, should perform scaling.
      boolean isInProgress() Returns {@code true} if a scale gesture is in progress.
      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.
      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.
      float getCurrentSpan() Return the average distance between each of the pointers forming thegesture in progress through the focal point.
      float getCurrentSpanX() Return the average X distance between each of the pointers forming thegesture in progress through the focal point.
      float getCurrentSpanY() Return the average Y distance between each of the pointers forming thegesture in progress through the focal point.
      float getPreviousSpan() Return the previous average distance between each of the pointers forming thegesture in progress through the focal point.
      float getPreviousSpanX() Return the previous average X distance between each of the pointers forming thegesture in progress through the focal point.
      float getPreviousSpanY() Return the previous average Y distance between each of the pointers forming thegesture in progress through the focal point.
      float getScaleFactor() Return the scaling factor from the previous scale event to the currentevent.
      long getTimeDelta() Return the time difference in milliseconds between the previousaccepted scaling event and the current scaling event.
      long getEventTime() Return the event time of the current event being processed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ScaleGestureDetector

        ScaleGestureDetector(Context context, ScaleGestureDetector.OnScaleGestureListener listener)
        Creates a ScaleGestureDetector with the supplied listener.
        Parameters:
        context - the application's context
        listener - 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 context
        listener - 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.

      • 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.