# StrokeInput

Artifact: [androidx.ink:ink-strokes](https://developer.android.com/jetpack/androidx/releases/ink) [View Source](https://cs.android.com/search?q=file:androidx/ink/strokes/StrokeInput.kt+class:androidx.ink.strokes.StrokeInput) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

*** ** * ** ***


```
public final class StrokeInput
```

<br />

*** ** * ** ***

A single input specifying position, time since the start of the stream, and optionally `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#pressure()`, `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#tiltRadians()`, `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#orientationRadians()`, and barrel twist (via `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#getBarrelTwistRadians()`).

This data type is used as an input to `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch` and `https://developer.android.com/reference/androidx/ink/strokes/InProgressStroke`. If these are to be created as part of real-time input, it is recommended to use some sort of object pool so that new usages can make use of existing objects that have been recycled, rather than allocating new ones which could introduce unpredictable garbage collection related delays to the time-sensitive input path. This class has the `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#update(kotlin.Float,kotlin.Float,kotlin.Long,androidx.ink.brush.InputToolType,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float)` method for that purpose, rather than being immutable.

## Summary

| ### Constants |
|---|---|
| `static final float` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_ORIENTATION()` |
| `static final float` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_PRESSURE()` |
| `static final float` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_STROKE_UNIT_LENGTH() = 0.0f` |
| `static final float` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_TILT()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#StrokeInput()()` |

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/StrokeInput` | `@https://developer.android.com/reference/androidx/annotation/VisibleForTesting https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#create(kotlin.Float,kotlin.Float,kotlin.Long,androidx.ink.brush.InputToolType,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float)( float x, float y, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long elapsedTimeMillis, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/InputToolType toolType, float strokeUnitLengthCm, float pressure, float tiltRadians, float orientationRadians )` Allocate and return a new `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput`. |
| `boolean` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` |
| `final long` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#getElapsedTimeMillis()()` Time elapsed since the start of the stroke. |
| `final float` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#getOrientationRadians()()` The angle that indicates the direction in which the stylus is pointing in relation to the positive x axis. |
| `final float` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#getPressure()()` Pressure value in the normalized, unitless range of 0, 1 indicating the force exerted during input. |
| `final float` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#getStrokeUnitLengthCm()()` The physical distance in centimeters that the pointer must travel in order to produce an input motion of one stroke unit. |
| `final float` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#getTiltRadians()()` The angle between a stylus and the line perpendicular to the plane of the screen. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/InputToolType` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#getToolType()()` The input device used to generate this stroke input. |
| `final float` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#getX()()` The x-coordinate of the input position in stroke space. |
| `final float` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#getY()()` The y-coordinate of the input position in stroke space. |
| `final boolean` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#hasOrientation()()` Whether the `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#orientationRadians()` field contains a valid orientation value. |
| `final boolean` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#hasPressure()()` Whether the `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#pressure()` field contains a valid pressure value. |
| `final boolean` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#hasTilt()()` Whether the `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#tiltRadians()` field contains a valid tilt value. |
| `int` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#hashCode()()` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#toString()()` |
| `final void` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#update(kotlin.Float,kotlin.Float,kotlin.Long,androidx.ink.brush.InputToolType,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float)( float x, float y, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long elapsedTimeMillis, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/InputToolType toolType, float strokeUnitLengthCm, float pressure, float tiltRadians, float orientationRadians )` Set new values on this instance, clearing values corresponding to optional parameters that are not specified. |

## Constants

### NO_ORIENTATION

```
public static final float NO_ORIENTATION
```

### NO_PRESSURE

```
public static final float NO_PRESSURE
```

### NO_STROKE_UNIT_LENGTH

```
public static final float NO_STROKE_UNIT_LENGTH = 0.0f
```

### NO_TILT

```
public static final float NO_TILT
```

## Public constructors

### StrokeInput

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public StrokeInput()
```

## Public methods

### create

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
@VisibleForTesting
public static final @NonNull StrokeInput create(
    float x,
    float y,
    @IntRange(from = 0) long elapsedTimeMillis,
    @NonNull InputToolType toolType,
    float strokeUnitLengthCm,
    float pressure,
    float tiltRadians,
    float orientationRadians
)
```

Allocate and return a new `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput`. Only intended for test code - real code should use a recycling pattern to avoid allocating during latency-sensitive real-time input, using `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#update(kotlin.Float,kotlin.Float,kotlin.Long,androidx.ink.brush.InputToolType,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float)` on an instance allocated with the zero-argument constructor.

### equals

```
public boolean equals(Object other)
```

### getElapsedTimeMillis

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final long getElapsedTimeMillis()
```

Time elapsed since the start of the stroke.

### getOrientationRadians

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final float getOrientationRadians()
```

The angle that indicates the direction in which the stylus is pointing in relation to the positive x axis. The value should be normalized to fall between 0 and 2π in radians, where 0 means the ray from the stylus tip to the end is along positive x and values increase towards the positive y-axis.

When `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#tiltRadians()` is equal to π/2, the value for `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#orientationRadians()` is indeterminant.

`https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_ORIENTATION()` indicates that orientation is not reported, which can be checked with `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#hasOrientation()`. Note, that this is a separate condition from the orientation being indeterminant when `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#tiltRadians()` is 0.

### getPressure

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final float getPressure()
```

Pressure value in the normalized, unitless range of 0, 1 indicating the force exerted during input.

A value of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_PRESSURE()` indicates that pressure is not reported, which can be checked with `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#hasPressure()`.

### getStrokeUnitLengthCm

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final float getStrokeUnitLengthCm()
```

The physical distance in centimeters that the pointer must travel in order to produce an input motion of one stroke unit. For stylus/touch, this is the real-world distance that the stylus/fingertip must move in physical space; for mouse, this is the visual distance that the mouse pointer must travel along the surface of the display.

A value of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_STROKE_UNIT_LENGTH()` indicates that the relationship between stroke space and physical space is unknown or ill-defined.

### getTiltRadians

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final float getTiltRadians()
```

The angle between a stylus and the line perpendicular to the plane of the screen. The value should be normalized to fall between 0 and π/2 in radians, where 0 is perpendicular to the screen and π/2 is flat against the drawing surface.

`https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_TILT()` indicates that tilt is not reported, which can be checked with `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#hasTilt()`.

### getToolType

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull InputToolType getToolType()
```

The input device used to generate this stroke input.

### getX

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final float getX()
```

The x-coordinate of the input position in stroke space.

### getY

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final float getY()
```

The y-coordinate of the input position in stroke space.

### hasOrientation

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final boolean hasOrientation()
```

Whether the `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#orientationRadians()` field contains a valid orientation value.

### hasPressure

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final boolean hasPressure()
```

Whether the `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#pressure()` field contains a valid pressure value.

### hasTilt

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final boolean hasTilt()
```

Whether the `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#tiltRadians()` field contains a valid tilt value.

### hashCode

```
public int hashCode()
```

### toString

```
public @NonNull String toString()
```

### update

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final void update(
    float x,
    float y,
    @IntRange(from = 0) long elapsedTimeMillis,
    @NonNull InputToolType toolType,
    float strokeUnitLengthCm,
    float pressure,
    float tiltRadians,
    float orientationRadians
)
```

Set new values on this instance, clearing values corresponding to optional parameters that are not specified.

| Parameters |
|---|---|
| `float x` | The `x` position coordinate of the input in the stroke's coordinate space. |
| `float y` | The `y` position coordinate of the input in the stroke's coordinate space. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long elapsedTimeMillis` | Marks the number of milliseconds since the stroke started. On Android, this should be a non-negative timestamp in the `android.os.SystemClock.elapsedRealtime` time base. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/InputToolType toolType` | The type of tool used to create this input data. |
| `float strokeUnitLengthCm` | The physical distance in centimeters that the pointer must travel in order to produce an input motion of one stroke unit. For stylus/touch, this is the real-world distance that the stylus/fingertip must move in physical space; for mouse, this is the visual distance that the mouse pointer must travel along the surface of the display. A value of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_STROKE_UNIT_LENGTH()` indicates that the relationship between stroke space and physical space is unknown or ill-defined. |
| `float pressure` | Must be within 0, 1, though that's not enforced until added to a `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch` object. Absence of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#update(kotlin.Float,kotlin.Float,kotlin.Long,androidx.ink.brush.InputToolType,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float)` data is represented with `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_PRESSURE()`. |
| `float tiltRadians` | Must be within 0, π/2, though that's not enforced until added to a `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch` object. The angle in radians between a stylus and the line perpendicular to the plane of the screen. 0 is perpendicular to the screen and π/2 is flat against the drawing surface. Absence of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#update(kotlin.Float,kotlin.Float,kotlin.Long,androidx.ink.brush.InputToolType,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float)` data is represented with `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_TILT()`. |
| `float orientationRadians` | Must be within 0, 2π, though that's not enforced until added to a `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch` object. Indicates the direction in which the stylus is pointing in relation to the positive x axis in radians. A value of 0 means the ray from the stylus tip to the end is along positive x and values increase towards the positive y-axis. Absence of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#update(kotlin.Float,kotlin.Float,kotlin.Long,androidx.ink.brush.InputToolType,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float)` data is represented with `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_ORIENTATION()`. |