{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

FloatExponentialDecaySpec

public final class FloatExponentialDecaySpec implements FloatDecayAnimationSpec


This is a decay animation where the friction/deceleration is always proportional to the velocity. As a result, the velocity goes under an exponential decay. The constructor parameter, frictionMultiplier, can be tuned to adjust the amount of friction applied in the decay. The higher the multiplier, the higher the friction, the sooner the animation will stop, and the shorter distance the animation will travel with the same starting condition.

Summary

Public constructors

FloatExponentialDecaySpec(
    float frictionMultiplier,
    float absVelocityThreshold
)

Public methods

float

This is the absolute value of a velocity threshold, below which the animation is considered finished.

long
getDurationNanos(float initialValue, float initialVelocity)

Returns the duration of the decay animation, in nanoseconds.

float
getTargetValue(float initialValue, float initialVelocity)

Returns the target value of the animation based on the starting condition of the animation ( i.e. start value and start velocity).

float
getValueFromNanos(
    long playTimeNanos,
    float initialValue,
    float initialVelocity
)

Returns the value of the animation at the given time.

float
getVelocityFromNanos(
    long playTimeNanos,
    float initialValue,
    float initialVelocity
)

Returns the velocity of the animation at the given time.

Public constructors

FloatExponentialDecaySpec

public FloatExponentialDecaySpec(
    float frictionMultiplier,
    float absVelocityThreshold
)
Parameters
float frictionMultiplier

The friction multiplier, indicating how quickly the animation should stop. This should be greater than 0, with a default value of 1.0.

float absVelocityThreshold

The speed at which the animation is considered close enough to rest for the animation to finish.

Public methods

getAbsVelocityThreshold

public float getAbsVelocityThreshold()

This is the absolute value of a velocity threshold, below which the animation is considered finished.

getDurationNanos

public long getDurationNanos(float initialValue, float initialVelocity)

Returns the duration of the decay animation, in nanoseconds.

Parameters
float initialValue

start value of the animation

float initialVelocity

start velocity of the animation

getTargetValue

public float getTargetValue(float initialValue, float initialVelocity)

Returns the target value of the animation based on the starting condition of the animation ( i.e. start value and start velocity).

Parameters
float initialValue

The start value of the animation

float initialVelocity

The start velocity of the animation

getValueFromNanos

public float getValueFromNanos(
    long playTimeNanos,
    float initialValue,
    float initialVelocity
)

Returns the value of the animation at the given time.

Parameters
long playTimeNanos

The time elapsed in milliseconds since the start of the animation

float initialValue

The start value of the animation

float initialVelocity

The start velocity of the animation

getVelocityFromNanos

public float getVelocityFromNanos(
    long playTimeNanos,
    float initialValue,
    float initialVelocity
)

Returns the velocity of the animation at the given time.

Parameters
long playTimeNanos

The time elapsed in milliseconds since the start of the animation

float initialValue

The start value of the animation

float initialVelocity

The start velocity of the animation