FloatExponentialDecaySpec


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(
    frictionMultiplier: @FloatRange(from = 0.0, fromInclusive = false) Float,
    absVelocityThreshold: @FloatRange(from = 0.0, fromInclusive = false) Float
)
Cmn

Public functions

open Long
getDurationNanos(initialValue: Float, initialVelocity: Float)

Returns the duration of the decay animation, in nanoseconds.

Cmn
open Float
getTargetValue(initialValue: Float, initialVelocity: Float)

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

Cmn
open Float
getValueFromNanos(
    playTimeNanos: Long,
    initialValue: Float,
    initialVelocity: Float
)

Returns the value of the animation at the given time.

Cmn
open Float
getVelocityFromNanos(
    playTimeNanos: Long,
    initialValue: Float,
    initialVelocity: Float
)

Returns the velocity of the animation at the given time.

Cmn

Public properties

open Float

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

Cmn

Public constructors

FloatExponentialDecaySpec

FloatExponentialDecaySpec(
    frictionMultiplier: @FloatRange(from = 0.0, fromInclusive = false) Float = 1.0f,
    absVelocityThreshold: @FloatRange(from = 0.0, fromInclusive = false) Float = 0.1f
)
Parameters
frictionMultiplier: @FloatRange(from = 0.0, fromInclusive = false) Float = 1.0f

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

absVelocityThreshold: @FloatRange(from = 0.0, fromInclusive = false) Float = 0.1f

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

Public functions

getDurationNanos

open fun getDurationNanos(initialValue: Float, initialVelocity: Float): Long

Returns the duration of the decay animation, in nanoseconds.

Parameters
initialValue: Float

start value of the animation

initialVelocity: Float

start velocity of the animation

getTargetValue

open fun getTargetValue(initialValue: Float, initialVelocity: Float): Float

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

Parameters
initialValue: Float

The start value of the animation

initialVelocity: Float

The start velocity of the animation

getValueFromNanos

open fun getValueFromNanos(
    playTimeNanos: Long,
    initialValue: Float,
    initialVelocity: Float
): Float

Returns the value of the animation at the given time.

Parameters
playTimeNanos: Long

The time elapsed in milliseconds since the start of the animation

initialValue: Float

The start value of the animation

initialVelocity: Float

The start velocity of the animation

getVelocityFromNanos

open fun getVelocityFromNanos(
    playTimeNanos: Long,
    initialValue: Float,
    initialVelocity: Float
): Float

Returns the velocity of the animation at the given time.

Parameters
playTimeNanos: Long

The time elapsed in milliseconds since the start of the animation

initialValue: Float

The start value of the animation

initialVelocity: Float

The start velocity of the animation

Public properties

absVelocityThreshold

open val absVelocityThresholdFloat

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