# StrokeInputBatch

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

*** ** * ** ***


```
public abstract class StrokeInputBatch
```

<br />

Known direct subclasses [ImmutableStrokeInputBatch](https://developer.android.com/reference/androidx/ink/strokes/ImmutableStrokeInputBatch), [MutableStrokeInputBatch](https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch)

|---|---|
| `https://developer.android.com/reference/androidx/ink/strokes/ImmutableStrokeInputBatch` | An immutable implementation of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch`. |
| `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch` | A mutable implementation of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch`. |

*** ** * ** ***

A read-only view of an object that stores multiple `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput` values together in a more memory-efficient manner than just `List<StrokeInput>`. The input points in this batch are guaranteed to be consistent with one another -- for example, they all have the same `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#toolType()` and the same set of optional fields like pressure/tilt/orientation/twist, and their timestamps are all monotonically non-decreasing. This can be an `https://developer.android.com/reference/androidx/ink/strokes/ImmutableStrokeInputBatch` for data that cannot change, or a `https://developer.android.com/reference/androidx/ink/strokes/MutableStrokeInputBatch` for data that is meant to be modified or incrementally built.

## Summary

| ### Nested types |
|---|
| `public static class https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch.Companion` |

| ### Public methods |
|---|---|
| `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. |
| `abstract @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/StrokeInputBatch#toImmutable()()` |

| ### Extension functions |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/PartitionedMesh` | `https://developer.android.com/reference/androidx/ink/strokes/MeshCreation.https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#(androidx.ink.strokes.StrokeInputBatch).createClosedShape()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch receiver)` Creates a `https://developer.android.com/reference/androidx/ink/geometry/PartitionedMesh` of the shape enclosed by the given `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch` input points. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull byte[]` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatchExtensions.https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#(androidx.ink.strokes.StrokeInputBatch).encode()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch receiver)` Write a gzip-compressed `ink.proto.CodedStrokeInputBatch` binary proto message representing the `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch` to the given `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html`. |
| `final void` | `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatchExtensions.https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#(androidx.ink.strokes.StrokeInputBatch).encode(java.io.OutputStream)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/io/OutputStream.html output )` Write a gzip-compressed `ink.proto.CodedStrokeInputBatch` binary proto message representing the `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch` to the given `https://developer.android.com/reference/java/io/OutputStream.html`. |

## Public methods

### get

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

```
public final @NonNull StrokeInput get(int index)
```

Gets the value of the i-th input. Requires that `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#get(kotlin.Int)` is non-negative and less than `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#size()`.

In performance-sensitive code, prefer to use `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#populate(kotlin.Int,androidx.ink.strokes.StrokeInput)` to pass in a pre-allocated instance and reuse that instance across multiple calls to this function.

### getBasePaintAnimationPhase

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

```
public final @FloatRange(from = 0.0, to = 1.0, toInclusive = false) float 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.

### getDurationMillis

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

```
public final long getDurationMillis()
```

The duration between the first and last input in milliseconds.

### getNoiseSeed

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

```
public final int 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. If no seed value has yet been set for this input batch, returns the default seed of zero.

### getSize

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

```
public final int getSize()
```

Number of `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput` objects in the batch.

### 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.

### getToolType

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

```
public final @NonNull InputToolType 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()`.

### hasOrientation

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

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

Whether all of the individual inputs have a defined value for `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#orientationRadians()`. If not, then no input items have an orientation value.

### hasPressure

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

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

Whether all of the individual inputs have a defined value for `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#pressure()`. If not, then no input items have a pressure value.

### hasStrokeUnitLength

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

```
public final boolean 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()`.

### hasTilt

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

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

Whether all of the individual inputs have a defined value for `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput#tiltRadians()`. If not, then no input items have a tilt value.

### isEmpty

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

```
public final boolean isEmpty()
```

`true` if there are no `https://developer.android.com/reference/androidx/ink/strokes/StrokeInput` objects in the batch, and `false` otherwise.

### populate

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

```
public final @NonNull StrokeInput populate(int index, @NonNull 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. Requires that `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#populate(kotlin.Int,androidx.ink.strokes.StrokeInput)` is non-negative and less than `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch#size()`.

### toImmutable

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

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

## Extension functions

### MeshCreation.createClosedShape

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/MeshCreation.kt+function:createClosedShape)

```
public final @NonNull PartitionedMesh MeshCreation.createClosedShape(@NonNull StrokeInputBatch receiver)
```

Creates a `https://developer.android.com/reference/androidx/ink/geometry/PartitionedMesh` of the shape enclosed by the given `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch` input points. A typical use case is selecting a region of the scene and performing hit testing with the resulting `https://developer.android.com/reference/androidx/ink/geometry/PartitionedMesh`.

For a given stroke this algorithm aims to:

1. Identify and create any connections that the user may have intended to make but did not fully connect.

2. Trim any extra end points that the user did not intend to be part of the selected area.

Example usage:

```
fun onStrokeFinished(stroke: Stroke) {
   val selectionRegion = stroke.inputs.createClosedShape()
   for (stroke in myScene.strokes) {
       if (stroke.shape.intersects(selectionRegion)) {
           myScene.setSelected(stroke, true)
       }
   }
}
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch receiver` | The `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch` to create a closed shape from. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/PartitionedMesh` | The `https://developer.android.com/reference/androidx/ink/geometry/PartitionedMesh` of the closed shape. If there are fewer than 3 input points, or if there are fewer than 3 points remaining after removing points with the same (x,y) coordinates as the previous point, this function will return a `https://developer.android.com/reference/androidx/ink/geometry/PartitionedMesh` that is point-like (1 point remaining) or segment-like (2 points remaining). The resulting mesh will have an area of 0 but can still be used for hit testing via intersection. |

### StrokeInputBatchExtensions.encode

Artifact: [androidx.ink:ink-storage](https://developer.android.com/jetpack/androidx/releases/ink) [View Source](https://cs.android.com/search?q=file:androidx/ink/storage/StrokeInputBatchExtensions.kt+function:encode)

```
public final @NonNull byte[] StrokeInputBatchExtensions.encode(@NonNull StrokeInputBatch receiver)
```

Write a gzip-compressed `ink.proto.CodedStrokeInputBatch` binary proto message representing the `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch` to the given `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html`.

### StrokeInputBatchExtensions.encode

Artifact: [androidx.ink:ink-storage](https://developer.android.com/jetpack/androidx/releases/ink) [View Source](https://cs.android.com/search?q=file:androidx/ink/storage/StrokeInputBatchExtensions.jvmAndAndroid.kt+function:encode)

```
public final void StrokeInputBatchExtensions.encode(
    @NonNull StrokeInputBatch receiver,
    @NonNull OutputStream output
)
```

Write a gzip-compressed `ink.proto.CodedStrokeInputBatch` binary proto message representing the `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch` to the given `https://developer.android.com/reference/java/io/OutputStream.html`.