MutableStrokeInputBatch



A mutable implementation of StrokeInputBatch. For an immutable alternative, see ImmutableStrokeInputBatch.

Each appended 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 StrokeInput.pressure value if-and-only-if every other input holds a StrokeInput.pressure value. This is also true for StrokeInput.tiltRadians and StrokeInput.orientationRadians.

  2. The sequence of StrokeInput values must not contain repeated x-y-t triplets, and the time values must be non-negative and non-decreasing.

  3. Values of StrokeInput.strokeUnitLengthCm must be finite and positive, or be StrokeInput.NO_STROKE_UNIT_LENGTH.

  4. Values of StrokeInput.pressure must fall within the range of 0, 1 or be StrokeInput.NO_PRESSURE

  5. Values of StrokeInput.tiltRadians must fall within the range of 0, π/2 or be StrokeInput.NO_TILT.

  6. Values of StrokeInput.orientationRadians must fall within the range of [0, 2π) or be StrokeInput.NO_ORIENTATION.

  7. The StrokeInput.toolType and StrokeInput.strokeUnitLengthCm values must be the same across all inputs.

Summary

Public constructors

Cmn

Public functions

MutableStrokeInputBatch
add(inputBatch: StrokeInputBatch)

Validates and appends an inputBatch.

Cmn
MutableStrokeInputBatch
add(input: StrokeInput)

Adds an input to the batch if valid.

Cmn
MutableStrokeInputBatch

Validates and appends a collection of StrokeInput.

Cmn
MutableStrokeInputBatch
add(
    type: InputToolType,
    x: Float,
    y: Float,
    elapsedTimeMillis: Long,
    strokeUnitLengthCm: Float,
    pressure: Float,
    tiltRadians: Float,
    orientationRadians: Float
)

Variant of add that takes individual parameters instead of a StrokeInput.

Cmn
Unit
Cmn
Unit

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

Cmn
open String
Cmn

Inherited functions

From androidx.ink.strokes.StrokeInputBatch
operator StrokeInput
get(index: Int)

Gets the value of the i-th input.

Cmn
Long

The duration between the first and last input in milliseconds.

Cmn
Int

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.

Cmn
Float

The physical distance in centimeters that the pointer must travel in order to produce an input motion of one stroke unit.

Cmn
InputToolType

How this input stream should be interpreted, as coming from a InputToolType.MOUSE, InputToolType.TOUCH, or InputToolType.STYLUS.

Cmn
Boolean

Whether all of the individual inputs have a defined value for StrokeInput.orientationRadians.

Cmn
Boolean

Whether all of the individual inputs have a defined value for StrokeInput.pressure.

Cmn
Boolean

Whether StrokeInput.strokeUnitLengthCm has a valid value, which is something other than StrokeInput.NO_STROKE_UNIT_LENGTH.

Cmn
Boolean

Whether all of the individual inputs have a defined value for StrokeInput.tiltRadians.

Cmn
Boolean

true if there are no StrokeInput objects in the batch, and false otherwise.

Cmn
StrokeInput
populate(index: Int, outStrokeInput: StrokeInput)

Gets the value of the i-th input and overwrites outStrokeInput, which it then returns.

Cmn

Inherited properties

From androidx.ink.strokes.StrokeInputBatch
Int

Number of StrokeInput objects in the batch.

Cmn

Public constructors

MutableStrokeInputBatch

MutableStrokeInputBatch()

Public functions

add

fun add(inputBatch: StrokeInputBatch): MutableStrokeInputBatch

Validates and appends an inputBatch. Invalid inputBatch will result in no change. An exception will be thrown for invalid additions.

add

fun add(input: StrokeInput): MutableStrokeInputBatch

Adds an input 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, or orientation) than the inputs already in the batch.

Returns this instance to allow call chaining.

Parameters
input: StrokeInput

The StrokeInput to add to the batch.

Throws
IllegalArgumentException

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

fun add(inputs: Collection<StrokeInput>): MutableStrokeInputBatch

Validates and appends a collection of StrokeInput. Invalid inputs will result in no change. An exception will be thrown for invalid additions.

Returns this instance to allow call chaining.

Parameters
inputs: Collection<StrokeInput>

Collection of StrokeInputs to add to the batch.

Throws
IllegalArgumentException

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

fun add(
    type: InputToolType,
    x: Float,
    y: Float,
    elapsedTimeMillis: Long,
    strokeUnitLengthCm: Float = StrokeInput.NO_STROKE_UNIT_LENGTH,
    pressure: Float = StrokeInput.NO_PRESSURE,
    tiltRadians: Float = StrokeInput.NO_TILT,
    orientationRadians: Float = StrokeInput.NO_ORIENTATION
): MutableStrokeInputBatch

Variant of add that takes individual parameters instead of a StrokeInput.

Returns this instance to allow call chaining.

Parameters
type: InputToolType

The InputToolType to use for the input.

x: Float

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

y: Float

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

elapsedTimeMillis: Long

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.

strokeUnitLengthCm: Float = StrokeInput.NO_STROKE_UNIT_LENGTH

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 StrokeInput.NO_STROKE_UNIT_LENGTH indicates that the relationship between stroke space and physical space is unknown or ill-defined.

pressure: Float = StrokeInput.NO_PRESSURE

Should be within 0, 1 but it's not enforced until added to a StrokeInputBatch object. Absence of pressure data is represented with StrokeInput.NO_PRESSURE.

tiltRadians: Float = StrokeInput.NO_TILT

The angle in radians between a stylus and the line perpendicular to the plane of the screen. 0 is perpendicular to the screen and PI/2 is flat against the drawing surface. Absence of tiltRadians data is represented with StrokeInput.NO_TILT.

orientationRadians: Float = StrokeInput.NO_ORIENTATION

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 orientationRadians data is represented with StrokeInput.NO_ORIENTATION.

Throws
IllegalArgumentException

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

fun clear(): Unit

setNoiseSeed

fun setNoiseSeed(seed: Int): Unit

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

toString

open fun toString(): String