# MutableStrokeInputBatch

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/StrokeInputBatch.kt+class:androidx.ink.strokes.MutableStrokeInputBatch) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

*** ** * ** ***


```
public final class MutableStrokeInputBatch extends StrokeInputBatch
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.ink.strokes.StrokeInputBatch](https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch) ||
|   | ↳ | [androidx.ink.strokes.MutableStrokeInputBatch](https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch) |

*** ** * ** ***

A mutable implementation of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch`. For an immutable alternative, see `https://developer.android.com/reference/androidx/ink/strokes/ImmutableStrokeInputBatch`.

Each appended `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput` value is validated compared to the existing batch contents. This means:

1. All floating point values are required to be finite and the format of all inputs must be consistent. This means all inputs must have the same set of optional member variables that hold a value. For example, every input holds a `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#pressure()` value if-and-only-if every other input holds a `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#pressure()` value. This is also true for `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()`.

2. The sequence of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput` values must not contain repeated x-y-t triplets, and the time values must be non-negative and non-decreasing.

3. Values of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#strokeUnitLengthCm()` must be finite and positive, or be `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_STROKE_UNIT_LENGTH()`.

4. Values of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#pressure()` must fall within the range of 0, 1 or be `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_PRESSURE()`

5. Values of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#tiltRadians()` must fall within the range of 0, π/2 or be `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_TILT()`.

6. Values of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#orientationRadians()` must fall within the range of \[0, 2π) or be `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_ORIENTATION()`.

7. Values returned by `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#getBarrelTwistRadians()` must fall within the range of \[0, 2π) or be `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput.Companion#NO_BARREL_TWIST()`.

8. The `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#toolType()` and `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#strokeUnitLengthCm()` values must be the same across all inputs.

## Summary

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

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch` | `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#add(androidx.ink.strokes.StrokeInputBatch)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch inputBatch)` Validates and appends an `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#add(androidx.ink.strokes.StrokeInputBatch)`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch` | `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#add(androidx.ink.strokes.StrokeInput)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/StrokeInput input)` Adds an `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#add(androidx.ink.strokes.StrokeInput)` to the batch if valid. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch` | `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#add(kotlin.collections.Collection)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Collection.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/StrokeInput> inputs)` Validates and appends a collection of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch` | `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#add(androidx.ink.brush.InputToolType,kotlin.Float,kotlin.Float,kotlin.Long,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/InputToolType type, float x, float y, long elapsedTimeMillis, float strokeUnitLengthCm, float pressure, float tiltRadians, float orientationRadians )` Variant of `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#add(androidx.ink.brush.InputToolType,kotlin.Float,kotlin.Float,kotlin.Long,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float)` that takes individual parameters instead of a `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput`. |
| `final void` | `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#clear()()` |
| `final void` | `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#setNoiseSeed(kotlin.Int)(int seed)` Sets the per-stroke seed value that should be used when regenerating a stroke from this input batch. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/ImmutableStrokeInputBatch` | `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#toImmutable()()` Create `https://developer.android.com/reference/androidx/ink/strokes/ImmutableStrokeInputBatch` with the accumulated StrokeInputs. |
| `@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/MutableStrokeInputBatch#toString()()` |

### Inherited methods

From [androidx.ink.strokes.StrokeInputBatch](https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch) `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/StrokeInput` `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#get(kotlin.Int)(int index)`

Gets the value of the i-th input.
`final @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0, toInclusive = false) float` `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#getBasePaintAnimationPhase()()`

Returns the \[0, 1) value that will determine the stroke's overall paint animation progress at some arbitrary zero clock state, so that different strokes can be animated correctly relative to each other.
`final long` `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#getDurationMillis()()`

The duration between the first and last input in milliseconds.
`final int` `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#getNoiseSeed()()`

Returns the seed value that should be used for seeding any noise generators for brush behaviors when a full stroke is regenerated with this input batch.
`final int` `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#getSize()()`

Number of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput` objects in the batch.
`final float` `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#getStrokeUnitLengthCm()()`

The physical distance in centimeters that the pointer must travel in order to produce an input motion of one stroke unit.
`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/StrokeInputBatch#getToolType()()`

How this input stream should be interpreted, as coming from a `https://developer.android.com/reference/androidx/ink/brush/InputToolType#MOUSE()`, `https://developer.android.com/reference/androidx/ink/brush/InputToolType#TOUCH()`, or `https://developer.android.com/reference/androidx/ink/brush/InputToolType#STYLUS()`.
`final boolean` `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#hasOrientation()()`

Whether all of the individual inputs have a defined value for `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#orientationRadians()`.
`final boolean` `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#hasPressure()()`

Whether all of the individual inputs have a defined value for `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#pressure()`.
`final boolean` `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#hasStrokeUnitLength()()`

Whether `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#strokeUnitLengthCm()` has a valid value, which is something other than `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_STROKE_UNIT_LENGTH()`.
`final boolean` `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#hasTilt()()`

Whether all of the individual inputs have a defined value for `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#tiltRadians()`.
`final boolean` `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#isEmpty()()`

`true` if there are no `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput` objects in the batch, and `false` otherwise.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/StrokeInput` `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#populate(kotlin.Int,androidx.ink.strokes.StrokeInput)(int index, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/StrokeInput outStrokeInput)`

Gets the value of the i-th input and overwrites `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#populate(kotlin.Int,androidx.ink.strokes.StrokeInput)`, which it then returns.

## Public constructors

### MutableStrokeInputBatch

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

```
public MutableStrokeInputBatch()
```

## Public methods

### add

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

```
public final @NonNull MutableStrokeInputBatch add(@NonNull StrokeInputBatch inputBatch)
```

Validates and appends an `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#add(androidx.ink.strokes.StrokeInputBatch)`. Invalid `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#add(androidx.ink.strokes.StrokeInputBatch)` will result in no change. An exception will be thrown for invalid additions.

### add

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

```
public final @NonNull MutableStrokeInputBatch add(@NonNull StrokeInput input)
```

Adds an `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#add(androidx.ink.strokes.StrokeInput)` to the batch if valid.

Inputs are invalid if they contain values out of the valid range, duplicate a previous input, have an elapsed time before a previous input, or have a different tool type or set different optional fields (pressure, tilt, orientation, or barrel twist) than the inputs already in the batch.

Returns this instance to allow call chaining.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/StrokeInput input` | The `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput` to add to the batch. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch` | `this` |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If the input is not valid. Note that this can be a common occurrence with real user input on certain devices, in particular due to duplicate or out-of-order inputs. Therefore, users should either catch and handle this exception or sanitize the input to avoid ensure validity before passing it to this function. |

### add

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

```
public final @NonNull MutableStrokeInputBatch add(@NonNull Collection<@NonNull StrokeInput> inputs)
```

Validates and appends a collection of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput`. Invalid `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#add(kotlin.collections.Collection)` will result in no change. An exception will be thrown for invalid additions.

Returns this instance to allow call chaining.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Collection.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/StrokeInput> inputs` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html` of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput`s to add to the batch. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch` | `this` |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If the input is not valid. Note that this can be a common occurrence with real user input on certain devices, in particular due to duplicate or out-of-order inputs. Therefore, users should either catch and handle this exception or sanitize the input to avoid ensure validity before passing it to this function. |

### add

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

```
public final @NonNull MutableStrokeInputBatch add(
    @NonNull InputToolType type,
    float x,
    float y,
    long elapsedTimeMillis,
    float strokeUnitLengthCm,
    float pressure,
    float tiltRadians,
    float orientationRadians
)
```

Variant of `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#add(androidx.ink.brush.InputToolType,kotlin.Float,kotlin.Float,kotlin.Long,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float)` that takes individual parameters instead of a `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput`.

Returns this instance to allow call chaining.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/InputToolType type` | The `https://developer.android.com/reference/androidx/ink/brush/InputToolType` to use for the input. |
| `float x` | The x-coordinate of the input position in stroke space. |
| `float y` | The y-coordinate of the input position in stroke space. |
| `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. |
| `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 if present. Absence of `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch#add(androidx.ink.brush.InputToolType,kotlin.Float,kotlin.Float,kotlin.Long,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 if present. 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/MutableStrokeInputBatch#add(androidx.ink.brush.InputToolType,kotlin.Float,kotlin.Float,kotlin.Long,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π if present. 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/MutableStrokeInputBatch#add(androidx.ink.brush.InputToolType,kotlin.Float,kotlin.Float,kotlin.Long,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float)` data is represented with `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#NO_ORIENTATION()`. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch` | `this` |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If the input is not valid. Note that this can be a common occurrence with real user input on certain devices, in particular due to duplicate or out-of-order inputs. Therefore, users should either catch and handle this exception or sanitize the input to avoid ensure validity before passing it to this function. |

### clear

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

```
public final void clear()
```

### setNoiseSeed

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

```
public final void setNoiseSeed(int seed)
```

Sets the per-stroke seed value that should be used when regenerating a stroke from this input batch.

### toImmutable

```
public @NonNull ImmutableStrokeInputBatch toImmutable()
```

Create `https://developer.android.com/reference/androidx/ink/strokes/ImmutableStrokeInputBatch` with the accumulated StrokeInputs.

### toString

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