Builder
class Builder
| kotlin.Any | |
| ↳ | android.hardware.lights.ColorSequence.Builder |
Builder for ColorSequence objects.
Summary
| Public constructors | |
|---|---|
Builder() |
|
| Public methods | |
|---|---|
| ColorSequence.Builder |
addControlPoint(delayMillis: Long, color: Int)Adds the next control point for the effect. |
| ColorSequence.Builder |
addControlPoints(sequence: ColorSequence)Appends the provided ColorSequence to this sequence. |
| ColorSequence.Builder |
addControlPoints(delaysMillis: LongArray, colors: IntArray)Adds multiple control points to the sequence. |
| ColorSequence |
build()Builds the light effect. |
| ColorSequence.Builder |
setInterpolationMode(interpolationMode: Int)Sets the interpolation mode to use to transition between control point colors. |
Public constructors
Builder
Builder()
Public methods
addControlPoint
fun addControlPoint(
delayMillis: Long,
color: Int
): ColorSequence.Builder
Adds the next control point for the effect. The transition between control point colors takes delayMillis milliseconds. During that time, the light colors will be smoothly interpolated from the start to the end value according to the interpolation algorithm and the light's update interval.
When specifying a delay:
- Any negative value is considered an error and will cause an
IllegalArgumentException - Any positive value corresponds to the transition time in milliseconds, relative to the end of the previous control point.
- A value of 0 can only be specified for the very first control point in the sequence as a way to provide an initial state for the effect. It will cause an IllegalArgumentException if found in any other index.
- All delays MUST be whole multiples of the light's update period (frame period) (
Light.getMinUpdatePeriodMillis()). If any specified delay is a fractional number of frames, the system will truncate the delay potentially altering initially expected interpolation values and relative timing with other lights.
Providing an initial state is not required and the effect will take the last known state as the starting point for the interpolation, creating smooth transitions between effects.
| Parameters | |
|---|---|
delayMillis |
Long: transition time for the light to change to the target color. |
color |
Int: the target color for the light at the end of the transition time. |
| Return | |
|---|---|
ColorSequence.Builder |
a reference to this builder. This value cannot be null. |
| Exceptions | |
|---|---|
java.lang.IllegalArgumentException |
if delaysMillis is 0 for a non initial condition, or negative. |
addControlPoints
fun addControlPoints(sequence: ColorSequence): ColorSequence.Builder
Appends the provided ColorSequence to this sequence.
If the two color sequences have different interpolation modes, the interpolation mode of the builder takes precedence over the interpolation mode from the argument.
| Parameters | |
|---|---|
sequence |
ColorSequence: An existing ColorSequence to append to this builder. This value cannot be null. |
| Return | |
|---|---|
ColorSequence.Builder |
a reference to this builder. This value cannot be null. |
| Exceptions | |
|---|---|
java.lang.IllegalArgumentException |
if the sequence would cause the final sequence to be invalid. |
See Also
addControlPoints
fun addControlPoints(
delaysMillis: LongArray,
colors: IntArray
): ColorSequence.Builder
Adds multiple control points to the sequence.
Both arrays provided MUST have the same size and be in the order in which they should be inserted.
| Parameters | |
|---|---|
delaysMillis |
LongArray: array with the delays for the colors in the colors parameter. This value cannot be null. |
colors |
IntArray: array with the control point color targets. This value cannot be null. |
| Return | |
|---|---|
ColorSequence.Builder |
a reference to this builder. This value cannot be null. |
| Exceptions | |
|---|---|
java.lang.IllegalArgumentException |
if the arrays have different sizes or the sequence contains invalid values. |
See Also
build
fun build(): ColorSequence
Builds the light effect.
| Return | |
|---|---|
ColorSequence |
the color sequence with the configuration provided. This value cannot be null. |
setInterpolationMode
fun setInterpolationMode(interpolationMode: Int): ColorSequence.Builder
Sets the interpolation mode to use to transition between control point colors.
By default, the builder configures the sequence with INTERPOLATION_MODE_LINEAR.
| Parameters | |
|---|---|
interpolationMode |
Int: specifying how to ramp the light between control points. Value is one of the following: |
| Return | |
|---|---|
ColorSequence.Builder |
This value cannot be null. |