ViewConfigurationCompat

Added in 1.1.0

public final class ViewConfigurationCompat


Helper for accessing features in ViewConfiguration.

Summary

Public methods

static float
static int
static int
getScaledMaximumFlingVelocity(
    @NonNull Context context,
    @NonNull ViewConfiguration config,
    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.

static int
getScaledMinimumFlingVelocity(
    @NonNull Context context,
    @NonNull ViewConfiguration config,
    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.

static int

This method is deprecated.

Call getScaledPagingTouchSlop directly.

static float
static boolean

This method is deprecated.

Use hasPermanentMenuKey directly.

static boolean

Check if shortcuts should be displayed in menus.

Public methods

getScaledHorizontalScrollFactor

Added in 1.1.0
public static float getScaledHorizontalScrollFactor(
    @NonNull ViewConfiguration config,
    @NonNull Context context
)
Parameters
@NonNull ViewConfiguration config

Used to get the scaling factor directly from the ViewConfiguration.

@NonNull Context context

Used to locate a resource value.

Returns
float

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

getScaledHoverSlop

Added in 1.1.0
public static int getScaledHoverSlop(@NonNull ViewConfiguration config)
Parameters
@NonNull ViewConfiguration config

Used to get the hover slop directly from the ViewConfiguration.

Returns
int

The hover slop value.

getScaledMaximumFlingVelocity

Added in 1.12.0
public static int getScaledMaximumFlingVelocity(
    @NonNull Context context,
    @NonNull ViewConfiguration config,
    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, 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.

getScaledMinimumFlingVelocity

Added in 1.12.0
public static int getScaledMinimumFlingVelocity(
    @NonNull Context context,
    @NonNull ViewConfiguration config,
    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 AXIS_SCROLL vertical velocities generated from a 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 AXIS_SCROLL velocity from the tracker is calculated in "units per second" (see computeCurrentVelocity, computeCurrentVelocity 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 getDeviceId. Otherwise, use a valid ID that is obtained from getId, or from an InputManager instance (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 getMotionRanges to get all the InputDevice.MotionRanges for the InputDevice, from which you can derive all the valid axes for the device.

source: use getSource if calling this method in response to a MotionEvent. Otherwise, use a valid source for the InputDevice. You can use 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
@NonNull Context context

the Context associated with the view.

@NonNull ViewConfiguration config

the ViewConfiguration to derive the minimum fling velocity from.

int inputDeviceId

the ID of the InputDevice that generated the motion triggering fling.

int axis

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.

int source

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.

getScaledPagingTouchSlop

Added in 1.1.0
Deprecated in 1.1.0
public static int getScaledPagingTouchSlop(ViewConfiguration config)

Call getScaledPagingTouchSlop.

getScaledVerticalScrollFactor

Added in 1.1.0
public static float getScaledVerticalScrollFactor(
    @NonNull ViewConfiguration config,
    @NonNull Context context
)
Parameters
@NonNull ViewConfiguration config

Used to get the scaling factor directly from the ViewConfiguration.

@NonNull Context context

Used to locate a resource value.

Returns
float

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

hasPermanentMenuKey

Added in 1.1.0
Deprecated in 1.1.0
public static boolean hasPermanentMenuKey(ViewConfiguration config)

Report if the device has a permanent menu key available to the user, in a backwards compatible way.

shouldShowMenuShortcutsWhenKeyboardPresent

Added in 1.1.0
public static boolean shouldShowMenuShortcutsWhenKeyboardPresent(
    @NonNull ViewConfiguration config,
    @NonNull Context context
)

Check if shortcuts should be displayed in menus.

Returns
boolean

True if shortcuts should be displayed in menus.