TouchInjectionScope

Dispatches well-formed MotionEvent streams through a real View.dispatchTouchEvent chain.

View.performClick() invokes the click listener directly, so it only proves a listener is installed. Use this instead to exercise hit testing, touch slop, press state, long-press scheduling, TouchDelegates, and ACTION_CANCEL from an intercepting ancestor.

Coordinates are in target's coordinate space.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Gap placed between successive events, in milliseconds. Raise it for a slow drag, lower it for a flick; anything measuring velocity or duration reads this.

Link copied to clipboard

Whether the most recently dispatched event was consumed by the hierarchy.

Functions

Link copied to clipboard

Advances the main looper's clock, running anything scheduled in the interval. Long-press detection is a delayed message, so timing-sensitive gestures advance time rather than sleep.

Link copied to clipboard

Sends ACTION_CANCEL, as an intercepting ancestor causes to be delivered to the child.

Link copied to clipboard
fun click(x: Float, y: Float, pointerId: Int = 0): TouchInjectionScope

A complete tap: down then up, with no intervening movement.

Link copied to clipboard
fun down(x: Float, y: Float, pointerId: Int = 0): TouchInjectionScope

Presses pointerId down at (x, y). The first pointer down starts the gesture.

Link copied to clipboard

A press held past ViewConfiguration.getLongPressTimeout and then released.

Link copied to clipboard

Moves pointerId just past ViewConfiguration.getScaledTouchSlop, the threshold a scrolling ancestor uses to claim the gesture. Note a lone clickable view abandons its tap on leaving its bounds, not on travel distance, so this alone still clicks.

Link copied to clipboard
fun moveBy(dx: Float, dy: Float, pointerId: Int = 0): TouchInjectionScope

Moves pointerId by (dx, dy) from its current position.

Link copied to clipboard
fun moveTo(x: Float, y: Float, pointerId: Int = 0): TouchInjectionScope

Moves pointerId to the absolute position (x, y).

Link copied to clipboard
fun swipe(fromX: Float, fromY: Float, toX: Float, toY: Float, steps: Int = DEFAULT_SWIPE_STEPS, durationMs: Long = DEFAULT_SWIPE_DURATION_MS, pointerId: Int = 0): TouchInjectionScope

A drag from (fromX, fromY) to (toX, toY) broken into steps ACTION_MOVEs.

Link copied to clipboard
fun up(pointerId: Int = 0): TouchInjectionScope

Lifts pointerId. Lifting the last pointer ends the gesture.