ColorSequence.Builder


public static final class ColorSequence.Builder
extends Object

java.lang.Object
   ↳ android.hardware.lights.ColorSequence.Builder


Builder for ColorSequence objects.

Summary

Public constructors

Builder()

Public methods

ColorSequence.Builder addControlPoint(long delayMillis, int color)

Adds the next control point for the effect.

ColorSequence.Builder addControlPoints(ColorSequence sequence)

Appends the provided ColorSequence to this sequence.

ColorSequence.Builder addControlPoints(long[] delaysMillis, int[] colors)

Adds multiple control points to the sequence.

ColorSequence build()

Builds the light effect.

ColorSequence.Builder setInterpolationMode(int interpolationMode)

Sets the interpolation mode to use to transition between control point colors.

Inherited methods

Public constructors

Builder

public Builder ()

Public methods

addControlPoint

public ColorSequence.Builder addControlPoint (long delayMillis, 
                int color)

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.

Returns
ColorSequence.Builder a reference to this builder.
This value cannot be null.

Throws
IllegalArgumentException if delaysMillis is 0 for a non initial condition, or negative.

addControlPoints

public ColorSequence.Builder addControlPoints (ColorSequence sequence)

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.

Returns
ColorSequence.Builder a reference to this builder.
This value cannot be null.

Throws
IllegalArgumentException if the sequence would cause the final sequence to be invalid.

See also:

addControlPoints

public ColorSequence.Builder addControlPoints (long[] delaysMillis, 
                int[] colors)

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 long: array with the delays for the colors in the colors parameter.
This value cannot be null.

colors int: array with the control point color targets.
This value cannot be null.

Returns
ColorSequence.Builder a reference to this builder.
This value cannot be null.

Throws
IllegalArgumentException if the arrays have different sizes or the sequence contains invalid values.

See also:

build

public ColorSequence build ()

Builds the light effect.

Returns
ColorSequence the color sequence with the configuration provided.
This value cannot be null.

setInterpolationMode

public ColorSequence.Builder setInterpolationMode (int interpolationMode)

Sets the interpolation mode to use to transition between control point colors.

By default, the builder configures the sequence with ColorSequence.INTERPOLATION_MODE_LINEAR.

Parameters
interpolationMode int: specifying how to ramp the light between control points.
Value is one of the following:
Returns
ColorSequence.Builder This value cannot be null.