{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

InjectionScope

public interface InjectionScope extends Density

Known direct subclasses
KeyInjectionScope

The receiver scope of the key input injection lambda from performKeyInput.

MouseInjectionScope

The receiver scope of the mouse input injection lambda from performMouseInput.

MultiModalInjectionScope

The receiver scope of the multi-modal input injection lambda from performMultiModalInput.

RotaryInjectionScope

The receiver scope of rotary input injection lambda from performRotaryScrollInput.

TouchInjectionScope

The receiver scope of the touch input injection lambda from performTouchInput.


The receiver scope of all input injection lambdas offered in ui-test, such as performTouchInput and performMouseInput.

This scope offers several properties that allow you to get coordinates within the node you're interacting on, like the topLeft corner, its center, or some percentage of the size (percentOffset).

All positional properties are expressed in pixels. InjectionScope implements Density so you can convert between px and dp as you wish. The density used is taken from the SemanticsNode from the SemanticsNodeInteraction on which the input injection method is called.

Summary

Public methods

abstract void
advanceEventTime(long durationMillis)

Adds the given durationMillis to the current event time, delaying the next event by that time.

default float

The y-coordinate for the bottom of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The center of the bottom edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The bottom left corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The bottom right corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The center of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The center of the left edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The center of the right edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default float

The x-coordinate for the center of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default float

The y-coordinate for the center of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default long

The default time between two successive events.

default int

The height of the node in px.

default float

The x-coordinate for the left edge of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default float

The x-coordinate for the right edge of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default float

The y-coordinate for the bottom of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The center of the top edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The top left corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The top right corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

abstract @NonNull ViewConfiguration

The ViewConfiguration in use by the SemanticsNode from the SemanticsNodeInteraction on which the input injection method is called.

abstract @NonNull IntSize

The size of the visible part of the node we're interacting with in px, i.e. its clipped bounds.

default int

The width of the node in px.

default @NonNull Offset
percentOffset(float x, float y)

Creates an Offset relative to the size of the node we're interacting with.

Inherited methods

From androidx.compose.ui.unit.Density
abstract float

The logical density of the display.

abstract float

Current user preference for the scaling factor for fonts.

default int

Convert Dp to Int by rounding

default int

Convert Sp to Int by rounding

default @NonNull Dp

Convert Sp to Dp.

default @NonNull Dp
orgKt.toDp(int receiver)

Convert an Int pixel value to Dp.

default @NonNull Dp
orgKt.toDp(float receiver)

Convert a Float pixel value to a Dp

default @NonNull DpSize

Convert a Size to a DpSize.

default float
orgKt.toPx(@NonNull Dp receiver)

Convert Dp to pixels.

default float

Convert Sp to pixels.

default @NonNull Rect

Convert a DpRect to a Rect.

default @NonNull Size

Convert a DpSize to a Size.

default @NonNull TextUnit
orgKt.toSp(@NonNull Dp receiver)

Convert Dp to Sp.

default @NonNull TextUnit
orgKt.toSp(int receiver)

Convert an Int pixel value to Sp.

default @NonNull TextUnit
orgKt.toSp(float receiver)

Convert a Float pixel value to a Sp

Public methods

advanceEventTime

abstract void advanceEventTime(long durationMillis)

Adds the given durationMillis to the current event time, delaying the next event by that time.

getBottom

default float getBottom()

The y-coordinate for the bottom of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Note that, unless height == 0, bottom != height. In particular, bottom == height - 1f, because pixels are 0-based. If height == 0, bottom == 0 too.

getBottomCenter

default @NonNull Offset getBottomCenter()

The center of the bottom edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Note that bottomCenter.y != height, see bottom.

getBottomLeft

default @NonNull Offset getBottomLeft()

The bottom left corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Note that bottomLeft.y != height, see bottom.

getBottomRight

default @NonNull Offset getBottomRight()

The bottom right corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Note that bottomRight.x != width and bottomRight.y != height, see right and bottom.

getCenter

default @NonNull Offset getCenter()

The center of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

getCenterLeft

default @NonNull Offset getCenterLeft()

The center of the left edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

getCenterRight

default @NonNull Offset getCenterRight()

The center of the right edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Note that centerRight.x != width, see right.

getCenterX

default float getCenterX()

The x-coordinate for the center of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

getCenterY

default float getCenterY()

The y-coordinate for the center of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

getEventPeriodMillis

default long getEventPeriodMillis()

The default time between two successive events.

getHeight

default int getHeight()

The height of the node in px. Shorthand for visibleSize.height.

getLeft

default float getLeft()

The x-coordinate for the left edge of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

getRight

default float getRight()

The x-coordinate for the right edge of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Note that, unless width == 0, right != width. In particular, right == width - 1f, because pixels are 0-based. If width == 0, right == 0 too.

getTop

default float getTop()

The y-coordinate for the bottom of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

getTopCenter

default @NonNull Offset getTopCenter()

The center of the top edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

getTopLeft

default @NonNull Offset getTopLeft()

The top left corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

getTopRight

default @NonNull Offset getTopRight()

The top right corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Note that topRight.x != width, see right.

getViewConfiguration

abstract @NonNull ViewConfiguration getViewConfiguration()

The ViewConfiguration in use by the SemanticsNode from the SemanticsNodeInteraction on which the input injection method is called.

getVisibleSize

abstract @NonNull IntSize getVisibleSize()

The size of the visible part of the node we're interacting with in px, i.e. its clipped bounds.

getWidth

default int getWidth()

The width of the node in px. Shorthand for visibleSize.width.

percentOffset

default @NonNull Offset percentOffset(float x, float y)

Creates an Offset relative to the size of the node we're interacting with. x and y are fractions of the width and height, between -1 and 1.

Note that percentOffset(1f, 1f) != bottomRight, see right and bottom.

For example: percentOffset(.5f, .5f) is the same as the center; centerLeft + percentOffset(.1f, 0f) is a point 10% inward from the middle of the left edge; and bottomRight - percentOffset(.2f, .1f) is a point 20% to the left and 10% to the top of the bottom right corner.