Added in API level 1

ViewConfiguration


public class ViewConfiguration
extends Object

java.lang.Object
   ↳ android.view.ViewConfiguration


Contains methods to standard constants used in the UI for timeouts, sizes, and distances.

Summary

Public constructors

ViewConfiguration()

This constructor is deprecated. Use get(android.content.Context) instead.

Public methods

static ViewConfiguration get(Context context)

Returns a configuration for the specified visual Context.

static float getAmbiguousGestureMultiplier()

This method was deprecated in API level 30. Use getScaledAmbiguousGestureMultiplier().

static long getDefaultActionModeHideDuration()
static int getDoubleTapTimeout()
static int getEdgeSlop()

This method was deprecated in API level 15. Use getScaledEdgeSlop() instead.

static int getFadingEdgeLength()

This method was deprecated in API level 15. Use getScaledFadingEdgeLength() instead.

static long getGlobalActionKeyTimeout()

This method was deprecated in API level 20. This timeout should not be used by applications

static int getJumpTapTimeout()
static int getKeyRepeatDelay()
static int getKeyRepeatTimeout()
static int getLongPressTimeout()

Used for both key and motion events.

static int getMaximumDrawingCacheSize()

This method was deprecated in API level 15. Use getScaledMaximumDrawingCacheSize() instead.

static int getMaximumFlingVelocity()

This method was deprecated in API level 15. Use getScaledMaximumFlingVelocity() instead.

static int getMinimumFlingVelocity()

This method was deprecated in API level 15. Use getScaledMinimumFlingVelocity() instead.

static int getMultiPressTimeout()
static int getPressedStateDuration()
float getScaledAmbiguousGestureMultiplier()

The multiplication factor for inhibiting default gestures.

int getScaledDoubleTapSlop()
int getScaledEdgeSlop()
int getScaledFadingEdgeLength()
int getScaledHandwritingGestureLineMargin()
int getScaledHandwritingSlop()
float getScaledHorizontalScrollFactor()
int getScaledHoverSlop()
int getScaledMaximumDrawingCacheSize()

The maximum drawing cache size expressed in bytes.

int getScaledMaximumFlingVelocity(int inputDeviceId, int axis, int source)

Maximum absolute value of velocity to initiate a fling for a motion generated by an InputDevice with an id of inputDeviceId, from an input source and on a given motion event axis.

int getScaledMaximumFlingVelocity()
int getScaledMinimumFlingVelocity(int inputDeviceId, int axis, int source)

Minimum absolute value of velocity to initiate a fling for a motion generated by an InputDevice with an id of inputDeviceId, from an input source and on a given motion event axis.

int getScaledMinimumFlingVelocity()
int getScaledMinimumScalingSpan()

Retrieves the distance in pixels between touches that must be reached for a gesture to be interpreted as scaling.

int getScaledOverflingDistance()
int getScaledOverscrollDistance()
int getScaledPagingTouchSlop()
int getScaledScrollBarSize()
int getScaledTouchSlop()
float getScaledVerticalScrollFactor()
int getScaledWindowTouchSlop()
static int getScrollBarFadeDuration()
static int getScrollBarSize()

This method was deprecated in API level 15. Use getScaledScrollBarSize() instead.

static int getScrollDefaultDelay()
static float getScrollFriction()

The amount of friction applied to scrolls and flings.

static int getTapTimeout()
static int getTouchSlop()

This method was deprecated in API level 15. Use getScaledTouchSlop() instead.

static int getWindowTouchSlop()

This method was deprecated in API level 15. Use getScaledWindowTouchSlop() instead.

static long getZoomControlsTimeout()

The amount of time that the zoom controls should be displayed on the screen expressed in milliseconds.

boolean hasPermanentMenuKey()

Report if the device has a permanent menu key available to the user.

boolean shouldShowMenuShortcutsWhenKeyboardPresent()

Check if shortcuts should be displayed in menus.

Inherited methods

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Public constructors

ViewConfiguration

Added in API level 1
public ViewConfiguration ()

This constructor is deprecated.
Use get(android.content.Context) instead.

Public methods

get

Added in API level 3
public static ViewConfiguration get (Context context)

Returns a configuration for the specified visual Context. The configuration depends on various parameters of the Context, like the dimension of the display or the density of the display.

Parameters
context Context: A visual Context used to initialize the view configuration. It must be Activity or other Context created with Context#createWindowContext(int, Bundle). This value cannot be null.

getAmbiguousGestureMultiplier

Added in API level 29
Deprecated in API level 30
public static float getAmbiguousGestureMultiplier ()

This method was deprecated in API level 30.
Use getScaledAmbiguousGestureMultiplier().

The multiplication factor for inhibiting default gestures. If a MotionEvent has MotionEvent.CLASSIFICATION_AMBIGUOUS_GESTURE set, then certain actions, such as scrolling, will be inhibited. However, to account for the possibility of an incorrect classification, existing gesture thresholds (e.g. scrolling touch slop and the long-press timeout) should be scaled by this factor and remain in effect.

Returns
float Value is 1.0 or greater

getDefaultActionModeHideDuration

Added in API level 23
public static long getDefaultActionModeHideDuration ()

Returns
long the default duration in milliseconds for ActionMode#hide(long).

getDoubleTapTimeout

Added in API level 3
public static int getDoubleTapTimeout ()

Returns
int the duration in milliseconds between the first tap's up event and the second tap's down event for an interaction to be considered a double-tap.

getEdgeSlop

Added in API level 1
Deprecated in API level 15
public static int getEdgeSlop ()

This method was deprecated in API level 15.
Use getScaledEdgeSlop() instead.

Returns
int Inset in dips to look for touchable content when the user touches the edge of the screen

getFadingEdgeLength

Added in API level 1
Deprecated in API level 15
public static int getFadingEdgeLength ()

This method was deprecated in API level 15.
Use getScaledFadingEdgeLength() instead.

Returns
int the length of the fading edges in dips

getGlobalActionKeyTimeout

Added in API level 1
Deprecated in API level 20
public static long getGlobalActionKeyTimeout ()

This method was deprecated in API level 20.
This timeout should not be used by applications

The amount of time a user needs to press the relevant key to bring up the global actions dialog.

Returns
long how long a user needs to press the relevant key to bring up the global actions dialog.

getJumpTapTimeout

Added in API level 1
public static int getJumpTapTimeout ()

Returns
int the duration in milliseconds we will wait to see if a touch event is a jump tap. If the user does not move within this interval, it is considered to be a tap.

getKeyRepeatDelay

Added in API level 12
public static int getKeyRepeatDelay ()

Returns
int the time between successive key repeats in milliseconds.

getKeyRepeatTimeout

Added in API level 12
public static int getKeyRepeatTimeout ()

Returns
int the time before the first key repeat in milliseconds.

getLongPressTimeout

Added in API level 1
public static int getLongPressTimeout ()

Used for both key and motion events.

Returns
int the duration in milliseconds before a press turns into a long press

getMaximumDrawingCacheSize

Added in API level 1
Deprecated in API level 15
public static int getMaximumDrawingCacheSize ()

This method was deprecated in API level 15.
Use getScaledMaximumDrawingCacheSize() instead.

The maximum drawing cache size expressed in bytes.

Returns
int the maximum size of View's drawing cache expressed in bytes

getMaximumFlingVelocity

Added in API level 4
Deprecated in API level 15
public static int getMaximumFlingVelocity ()

This method was deprecated in API level 15.
Use getScaledMaximumFlingVelocity() instead.

Returns
int Maximum velocity to initiate a fling, as measured in dips per second.

getMinimumFlingVelocity

Added in API level 1
Deprecated in API level 15
public static int getMinimumFlingVelocity ()

This method was deprecated in API level 15.
Use getScaledMinimumFlingVelocity() instead.

Returns
int Minimum velocity to initiate a fling, as measured in dips per second.

getMultiPressTimeout

Added in API level 31
public static int getMultiPressTimeout ()

Returns
int the duration in milliseconds between the first tap's up event and the second tap's down event for an interaction to be considered part of the same multi-press.

getPressedStateDuration

Added in API level 1
public static int getPressedStateDuration ()

Returns
int the duration in milliseconds of the pressed state in child components.

getScaledAmbiguousGestureMultiplier

Added in API level 30
public float getScaledAmbiguousGestureMultiplier ()

The multiplication factor for inhibiting default gestures. If a MotionEvent has MotionEvent.CLASSIFICATION_AMBIGUOUS_GESTURE set, then certain actions, such as scrolling, will be inhibited. However, to account for the possibility of an incorrect classification, existing gesture thresholds (e.g. scrolling touch slop and the long-press timeout) should be scaled by this factor and remain in effect.

Returns
float Value is 1.0 or greater

getScaledDoubleTapSlop

Added in API level 3
public int getScaledDoubleTapSlop ()

Returns
int Distance in pixels between the first touch and second touch to still be considered a double tap

getScaledEdgeSlop

Added in API level 3
public int getScaledEdgeSlop ()

Returns
int Inset in pixels to look for touchable content when the user touches the edge of the screen

getScaledFadingEdgeLength

Added in API level 3
public int getScaledFadingEdgeLength ()

Returns
int the length of the fading edges in pixels

getScaledHandwritingGestureLineMargin

Added in API level 34
public int getScaledHandwritingGestureLineMargin ()

Returns
int margin in pixels around text line bounds where stylus handwriting gestures should be supported.

getScaledHandwritingSlop

Added in API level 34
public int getScaledHandwritingSlop ()

Returns
int Distance in pixels a stylus touch can wander before we think the user is handwriting.

getScaledHorizontalScrollFactor

Added in API level 26
public float getScaledHorizontalScrollFactor ()

Returns
float Amount to scroll in response to a horizontal MotionEvent#ACTION_SCROLL event. Multiply this by the event's axis value to obtain the number of pixels to be scrolled.

getScaledHoverSlop

Added in API level 28
public int getScaledHoverSlop ()

Returns
int Distance in pixels a hover can wander while it is still considered "stationary".

getScaledMaximumDrawingCacheSize

Added in API level 3
public int getScaledMaximumDrawingCacheSize ()

The maximum drawing cache size expressed in bytes.

Returns
int the maximum size of View's drawing cache expressed in bytes

getScaledMaximumFlingVelocity

Added in API level 34
public int getScaledMaximumFlingVelocity (int inputDeviceId, 
                int axis, 
                int source)

Maximum absolute value of velocity to initiate a fling for a motion generated by an InputDevice with an id of inputDeviceId, from an input source and on a given motion event axis.

Similar to getScaledMinimumFlingVelocity(int, int, int), but for maximum fling velocity, instead of minimum. Also, unlike that method which returns Integer.MAX_VALUE for bad input device ID, source and/or motion event axis inputs, this method returns Integer.MIN_VALUE for such bad inputs.

Parameters
inputDeviceId int

axis int

source int

Returns
int

getScaledMaximumFlingVelocity

Added in API level 4
public int getScaledMaximumFlingVelocity ()

Returns
int Maximum velocity to initiate a fling, as measured in pixels per second.

getScaledMinimumFlingVelocity

Added in API level 34
public int getScaledMinimumFlingVelocity (int inputDeviceId, 
                int axis, 
                int source)

Minimum absolute value of velocity to initiate a fling for a motion generated by an InputDevice with an id of inputDeviceId, from an input source and on a given motion event axis.

Before utilizing this method to get a minimum fling velocity for a motion generated by the input device, scale the velocity of the motion events generated by the input device to pixels per second.

For instance, if you tracked MotionEvent#AXIS_SCROLL vertical velocities generated from a InputDevice#SOURCE_ROTARY_ENCODER, the velocity returned from VelocityTracker will be in the units with which the axis values were reported in the motion event. Before comparing that velocity against the minimum fling velocity specified here, make sure that the MotionEvent#AXIS_SCROLL velocity from the tracker is calculated in "units per second" (see VelocityTracker#computeCurrentVelocity(int), VelocityTracker#computeCurrentVelocity(int, float) to adjust your velocity computations to "per second"), and use getScaledVerticalScrollFactor() to change this velocity value to "pixels/second".

If the provided inputDeviceId is not valid, or if the input device whose ID is provided does not support the given motion event source and/or axis, this method will return Integer.MAX_VALUE.

Obtaining the correct arguments for this method call

inputDeviceId: if calling this method in response to a MotionEvent, use the device ID that is reported by the event, which can be obtained using MotionEvent#getDeviceId(). Otherwise, use a valid ID that is obtained from InputDevice#getId(), or from an InputManager instance (InputManager#getInputDeviceIds() gives all the valid input device IDs).

axis: a MotionEvent may report data for multiple axes, and each axis may have multiple data points for different pointers. Use the axis for which you obtained the velocity for (VelocityTracker lets you calculate velocities for a specific axis. Use the axis for which you calculated velocity). You can use InputDevice#getMotionRanges() to get all the InputDevice.MotionRanges for the InputDevice, from which you can derive all the valid axes for the device.

source: use MotionEvent#getSource() if calling this method in response to a MotionEvent. Otherwise, use a valid source for the InputDevice. You can use InputDevice#getMotionRanges() to get all the InputDevice.MotionRanges for the InputDevice, from which you can derive all the valid sources for the device.

This method optimizes calls over multiple input device IDs, so caching the return value of the method is not necessary if you are handling multiple input devices.

Parameters
inputDeviceId int: the ID of the InputDevice that generated the motion triggering fling.

axis int: the axis on which the motion triggering the fling happened. This axis should be a valid axis that can be reported by the provided input device from the provided input device source.

source int: the input source of the motion causing fling. This source should be a valid source for the InputDevice whose ID is inputDeviceId.

Returns
int the minimum velocity, in pixels/second, to trigger fling.

getScaledMinimumFlingVelocity

Added in API level 3
public int getScaledMinimumFlingVelocity ()

Returns
int Minimum velocity to initiate a fling, as measured in pixels per second.

getScaledMinimumScalingSpan

Added in API level 29
public int getScaledMinimumScalingSpan ()

Retrieves the distance in pixels between touches that must be reached for a gesture to be interpreted as scaling. In general, scaling shouldn't start until this distance has been met or surpassed, and scaling should end when the distance in pixels between touches drops below this distance.

Returns
int The distance in pixels

Throws
IllegalStateException if this method is called on a ViewConfiguration that was instantiated using a constructor with no Context parameter.

getScaledOverflingDistance

Added in API level 9
public int getScaledOverflingDistance ()

Returns
int The maximum distance a View should overfling by when showing edge effects (in pixels).

getScaledOverscrollDistance

Added in API level 9
public int getScaledOverscrollDistance ()

Returns
int The maximum distance a View should overscroll by when showing edge effects (in pixels).

getScaledPagingTouchSlop

Added in API level 8
public int getScaledPagingTouchSlop ()

Returns
int Distance in pixels a touch can wander before we think the user is scrolling a full page

getScaledScrollBarSize

Added in API level 3
public int getScaledScrollBarSize ()

Returns
int The width of the horizontal scrollbar and the height of the vertical scrollbar in pixels

getScaledTouchSlop

Added in API level 3
public int getScaledTouchSlop ()

Returns
int Distance in pixels a touch can wander before we think the user is scrolling

getScaledVerticalScrollFactor

Added in API level 26
public float getScaledVerticalScrollFactor ()

Returns
float Amount to scroll in response to a vertical MotionEvent#ACTION_SCROLL event. Multiply this by the event's axis value to obtain the number of pixels to be scrolled.

getScaledWindowTouchSlop

Added in API level 3
public int getScaledWindowTouchSlop ()

Returns
int Distance in pixels a touch must be outside the bounds of a window for it to be counted as outside the window for purposes of dismissing that window.

getScrollBarFadeDuration

Added in API level 5
public static int getScrollBarFadeDuration ()

Returns
int Duration of the fade when scrollbars fade away in milliseconds

getScrollBarSize

Added in API level 1
Deprecated in API level 15
public static int getScrollBarSize ()

This method was deprecated in API level 15.
Use getScaledScrollBarSize() instead.

Returns
int The width of the horizontal scrollbar and the height of the vertical scrollbar in dips

getScrollDefaultDelay

Added in API level 5
public static int getScrollDefaultDelay ()

Returns
int Default delay before the scrollbars fade in milliseconds

getScrollFriction

Added in API level 1
public static float getScrollFriction ()

The amount of friction applied to scrolls and flings.

Returns
float A scalar dimensionless value representing the coefficient of friction.

getTapTimeout

Added in API level 1
public static int getTapTimeout ()

Returns
int the duration in milliseconds we will wait to see if a touch event is a tap or a scroll. If the user does not move within this interval, it is considered to be a tap.

getTouchSlop

Added in API level 1
Deprecated in API level 15
public static int getTouchSlop ()

This method was deprecated in API level 15.
Use getScaledTouchSlop() instead.

Returns
int Distance in dips a touch can wander before we think the user is scrolling

getWindowTouchSlop

Added in API level 1
Deprecated in API level 15
public static int getWindowTouchSlop ()

This method was deprecated in API level 15.
Use getScaledWindowTouchSlop() instead.

Returns
int Distance in dips a touch must be outside the bounds of a window for it to be counted as outside the window for purposes of dismissing that window.

getZoomControlsTimeout

Added in API level 1
public static long getZoomControlsTimeout ()

The amount of time that the zoom controls should be displayed on the screen expressed in milliseconds.

Returns
long the time the zoom controls should be visible expressed in milliseconds.

hasPermanentMenuKey

Added in API level 14
public boolean hasPermanentMenuKey ()

Report if the device has a permanent menu key available to the user.

As of Android 3.0, devices may not have a permanent menu key available. Apps should use the action bar to present menu options to users. However, there are some apps where the action bar is inappropriate or undesirable. This method may be used to detect if a menu key is present. If not, applications should provide another on-screen affordance to access functionality.

Returns
boolean true if a permanent menu key is present, false otherwise.

shouldShowMenuShortcutsWhenKeyboardPresent

Added in API level 28
public boolean shouldShowMenuShortcutsWhenKeyboardPresent ()

Check if shortcuts should be displayed in menus.

Returns
boolean True if shortcuts should be displayed in menus.