public class StopLogic extends MotionInterpolator


This contains the class to provide the logic for an animation to come to a stop. The setup defines a series of velocity gradients that gets to the desired position ending at 0 velocity. The path is computed such that the velocities are continuous

Summary

Public constructors

Public methods

void
config(
    float currentPos,
    float destination,
    float currentVelocity,
    float maxTime,
    float maxAcceleration,
    float maxVelocity
)

Configure the stop logic base on the parameters

String
debug(String desc, float time)

Debugging logic to log the state.

float

Gets the interpolated given the original interpolation

float

Gets the velocity at the last interpolated point

float
getVelocity(float x)

Get the velocity at a point in time

boolean
void
springConfig(
    float currentPos,
    float destination,
    float currentVelocity,
    float mass,
    float stiffness,
    float damping,
    float stopThreshold,
    int boundaryMode
)

This configure the stop logic to be a spring.

Inherited methods

From android.animation.TimeInterpolator
abstract float

Public constructors

StopLogic

Added in 2.2.0-alpha13
public StopLogic()

Public methods

config

Added in 2.2.0-alpha13
public void config(
    float currentPos,
    float destination,
    float currentVelocity,
    float maxTime,
    float maxAcceleration,
    float maxVelocity
)

Configure the stop logic base on the parameters

Parameters
float currentPos

start position

float destination

the ending position

float currentVelocity

the starting velocity

float maxTime

The maximum time to take

float maxAcceleration

the maximum acceleration to use

float maxVelocity

the maximum velocity to use

debug

Added in 2.2.0-alpha13
public String debug(String desc, float time)

Debugging logic to log the state.

Parameters
String desc

Description to pre append

float time

Time during animation

Returns
String

string useful for debugging the state of the StopLogic

getInterpolation

Added in 2.2.0-alpha13
public float getInterpolation(float v)

Gets the interpolated given the original interpolation

Parameters
float v
Returns
float

getVelocity

Added in 2.2.0-alpha13
public float getVelocity()

Gets the velocity at the last interpolated point

Returns
float

getVelocity

Added in 2.2.0-alpha13
public float getVelocity(float x)

Get the velocity at a point in time

Parameters
float x
Returns
float

isStopped

Added in 2.2.0-alpha13
public boolean isStopped()

springConfig

Added in 2.2.0-alpha13
public void springConfig(
    float currentPos,
    float destination,
    float currentVelocity,
    float mass,
    float stiffness,
    float damping,
    float stopThreshold,
    int boundaryMode
)

This configure the stop logic to be a spring. Moving from currentPosition(P0) to destination with an initial velocity of currentVelocity (V0) moving as if it has a mass (m) with spring constant stiffness(k), and friction(c) It moves with the equation acceleration a = (-k.x-c.v)/m. x = current position - destination v is velocity

Parameters
float currentPos

The current position

float destination

The destination position

float currentVelocity

the initial velocity

float mass

the mass

float stiffness

the stiffness or spring constant (the force by which the spring pulls)

float damping

the stiffness or spring constant. (the resistance to the motion)

float stopThreshold

(When the max velocity of the movement is below this it stops)

int boundaryMode

This controls if it overshoots or bounces when it hits 0 and 1