ScaleGestureDetector
public
class
ScaleGestureDetector
extends Object
java.lang.Object | |
↳ | android.view.ScaleGestureDetector |
Detects scaling transformation gestures using the supplied MotionEvent
s.
The ScaleGestureDetector.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(MotionEvent)
. The methods defined in your callback will be executed when the events occur.
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 | |
---|---|
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. |
Public methods | |
---|---|
float
|
getCurrentSpan()
Return the average distance between each of the pointers forming the gesture in progress through the focal point. |
float
|
getCurrentSpanX()
Return the average X distance between each of the pointers forming the gesture in progress through the focal point. |
float
|
getCurrentSpanY()
Return the average Y distance between each of the pointers forming the gesture in progress through the focal point. |
long
|
getEventTime()
Return the event time of the current event being processed. |
float
|
getFocusX()
Get the X coordinate of the current gesture's focal point. |
float
|
getFocusY()
Get the Y coordinate of the current gesture's focal point. |
float
|
getPreviousSpan()
Return the previous average distance between each of the pointers forming the gesture in progress through the focal point. |
float
|
getPreviousSpanX()
Return the previous average X distance between each of the pointers forming the gesture in progress through the focal point. |
float
|
getPreviousSpanY()
Return the previous average Y distance between each of the pointers forming the gesture in progress through the focal point. |
float
|
getScaleFactor()
Return the scaling factor from the previous scale event to the current event. |
long
|
getTimeDelta()
Return the time difference in milliseconds between the previous accepted scaling event and the current scaling event. |
boolean
|
isInProgress()
Returns |
boolean
|
isQuickScaleEnabled()
Return whether the quick scale gesture, in which the user performs a double tap followed by a swipe, should perform scaling. |
boolean
|
isStylusScaleEnabled()
Return whether the stylus scale gesture, in which the user uses a stylus and presses the button, should perform scaling. |
boolean
|
onTouchEvent(MotionEvent event)
Accepts MotionEvents and dispatches events to a |
void
|
setQuickScaleEnabled(boolean scales)
Set whether the associated |
void
|
setStylusScaleEnabled(boolean scales)
Sets whether the associates |
Inherited methods | |
---|---|
Public constructors
ScaleGestureDetector
public ScaleGestureDetector (Context context, ScaleGestureDetector.OnScaleGestureListener listener)
Creates a ScaleGestureDetector with the supplied listener.
You may only use this constructor from a Looper
thread.
Parameters | |
---|---|
context |
Context : the application's context |
listener |
ScaleGestureDetector.OnScaleGestureListener : the listener invoked for all the callbacks, this must
not be null. |
Throws | |
---|---|
NullPointerException |
if listener is null.
|
ScaleGestureDetector
public ScaleGestureDetector (Context context, ScaleGestureDetector.OnScaleGestureListener listener, Handler handler)
Creates a ScaleGestureDetector with the supplied listener.
Parameters | |
---|---|
context |
Context : the application's context |
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. |
Throws | |
---|---|
NullPointerException |
if listener is null.
|
See also:
Public methods
getCurrentSpan
public float getCurrentSpan ()
Return the average distance between each of the pointers forming the gesture in progress through the focal point.
Returns | |
---|---|
float |
Distance between pointers in pixels. |
getCurrentSpanX
public float getCurrentSpanX ()
Return the average X distance between each of the pointers forming the gesture in progress through the focal point.
Returns | |
---|---|
float |
Distance between pointers in pixels. |
getCurrentSpanY
public float getCurrentSpanY ()
Return the average Y distance between each of the pointers forming the gesture in progress through the focal point.
Returns | |
---|---|
float |
Distance between pointers in pixels. |
getEventTime
public long getEventTime ()
Return the event time of the current event being processed.
Returns | |
---|---|
long |
Current event time in milliseconds. |
getFocusX
public float getFocusX ()
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 | |
---|---|
float |
X coordinate of the focal point in pixels. |
getFocusY
public float getFocusY ()
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 | |
---|---|
float |
Y coordinate of the focal point in pixels. |
getPreviousSpan
public float getPreviousSpan ()
Return the previous average distance between each of the pointers forming the gesture in progress through the focal point.
Returns | |
---|---|
float |
Previous distance between pointers in pixels. |
getPreviousSpanX
public float getPreviousSpanX ()
Return the previous average X distance between each of the pointers forming the gesture in progress through the focal point.
Returns | |
---|---|
float |
Previous distance between pointers in pixels. |
getPreviousSpanY
public float getPreviousSpanY ()
Return the previous average Y distance between each of the pointers forming the gesture in progress through the focal point.
Returns | |
---|---|
float |
Previous distance between pointers in pixels. |
getScaleFactor
public float getScaleFactor ()
Return the scaling factor from the previous scale event to the current
event. This value is defined as
(getCurrentSpan()
/ getPreviousSpan()
).
Returns | |
---|---|
float |
The current scaling factor. |
getTimeDelta
public long getTimeDelta ()
Return the time difference in milliseconds between the previous accepted scaling event and the current scaling event.
Returns | |
---|---|
long |
Time difference since the last scaling event in milliseconds. |
isInProgress
public boolean isInProgress ()
Returns true
if a scale gesture is in progress.
Returns | |
---|---|
boolean |
isQuickScaleEnabled
public boolean isQuickScaleEnabled ()
Return whether the quick scale gesture, in which the user performs a double tap followed by a swipe, should perform scaling. .
Returns | |
---|---|
boolean |
See also:
isStylusScaleEnabled
public boolean isStylusScaleEnabled ()
Return whether the stylus scale gesture, in which the user uses a stylus and presses the button, should perform scaling.
Returns | |
---|---|
boolean |
See also:
onTouchEvent
public boolean onTouchEvent (MotionEvent event)
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 |
MotionEvent : The event to process |
Returns | |
---|---|
boolean |
true if the event was processed and the detector wants to receive the rest of the MotionEvents in this event stream. |
setQuickScaleEnabled
public void setQuickScaleEnabled (boolean scales)
Set whether the associated ScaleGestureDetector.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
public void setStylusScaleEnabled (boolean scales)
Sets whether the associates ScaleGestureDetector.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.
|
Annotations
Interfaces
- ActionMode.Callback
- ActionProvider.VisibilityListener
- Choreographer.FrameCallback
- CollapsibleActionView
- ContextMenu
- ContextMenu.ContextMenuInfo
- GestureDetector.OnContextClickListener
- GestureDetector.OnDoubleTapListener
- GestureDetector.OnGestureListener
- InputQueue.Callback
- KeyEvent.Callback
- LayoutInflater.Factory
- LayoutInflater.Factory2
- LayoutInflater.Filter
- Menu
- MenuItem
- MenuItem.OnActionExpandListener
- MenuItem.OnMenuItemClickListener
- PixelCopy.OnPixelCopyFinishedListener
- ScaleGestureDetector.OnScaleGestureListener
- SubMenu
- SurfaceHolder
- SurfaceHolder.Callback
- SurfaceHolder.Callback2
- TextureView.SurfaceTextureListener
- View.OnApplyWindowInsetsListener
- View.OnAttachStateChangeListener
- View.OnCapturedPointerListener
- View.OnClickListener
- View.OnContextClickListener
- View.OnCreateContextMenuListener
- View.OnDragListener
- View.OnFocusChangeListener
- View.OnGenericMotionListener
- View.OnHoverListener
- View.OnKeyListener
- View.OnLayoutChangeListener
- View.OnLongClickListener
- View.OnScrollChangeListener
- View.OnSystemUiVisibilityChangeListener
- View.OnTouchListener
- View.OnUnhandledKeyEventListener
- ViewGroup.OnHierarchyChangeListener
- ViewManager
- ViewParent
- ViewStub.OnInflateListener
- ViewTreeObserver.OnDrawListener
- ViewTreeObserver.OnGlobalFocusChangeListener
- ViewTreeObserver.OnGlobalLayoutListener
- ViewTreeObserver.OnPreDrawListener
- ViewTreeObserver.OnScrollChangedListener
- ViewTreeObserver.OnTouchModeChangeListener
- ViewTreeObserver.OnWindowAttachListener
- ViewTreeObserver.OnWindowFocusChangeListener
- Window.Callback
- Window.OnFrameMetricsAvailableListener
- Window.OnRestrictedCaptionAreaChangedListener
- WindowManager
Classes
- AbsSavedState
- ActionMode
- ActionMode.Callback2
- ActionProvider
- Choreographer
- ContextThemeWrapper
- Display
- Display.HdrCapabilities
- Display.Mode
- DisplayCutout
- DragAndDropPermissions
- DragEvent
- FocusFinder
- FrameMetrics
- FrameStats
- GestureDetector
- GestureDetector.SimpleOnGestureListener
- Gravity
- HapticFeedbackConstants
- InputDevice
- InputDevice.MotionRange
- InputEvent
- InputQueue
- KeyboardShortcutGroup
- KeyboardShortcutInfo
- KeyCharacterMap
- KeyCharacterMap.KeyData
- KeyEvent
- KeyEvent.DispatcherState
- LayoutInflater
- MenuInflater
- MotionEvent
- MotionEvent.PointerCoords
- MotionEvent.PointerProperties
- OrientationEventListener
- OrientationListener
- PixelCopy
- PointerIcon
- ScaleGestureDetector
- ScaleGestureDetector.SimpleOnScaleGestureListener
- SearchEvent
- SoundEffectConstants
- Surface
- SurfaceView
- TextureView
- TouchDelegate
- VelocityTracker
- View
- View.AccessibilityDelegate
- View.BaseSavedState
- View.DragShadowBuilder
- View.MeasureSpec
- ViewAnimationUtils
- ViewConfiguration
- ViewDebug
- ViewGroup
- ViewGroup.LayoutParams
- ViewGroup.MarginLayoutParams
- ViewGroupOverlay
- ViewOutlineProvider
- ViewOverlay
- ViewPropertyAnimator
- ViewStructure
- ViewStructure.HtmlInfo
- ViewStructure.HtmlInfo.Builder
- ViewStub
- ViewTreeObserver
- Window
- WindowAnimationFrameStats
- WindowContentFrameStats
- WindowId
- WindowId.FocusObserver
- WindowInsets
- WindowManager.LayoutParams
Enums
Exceptions