StopLogic
public class StopLogic extends MotionInterpolator
| java.lang.Object | ||
| ↳ | androidx.constraintlayout.motion.widget.MotionInterpolator | |
| ↳ | androidx.constraintlayout.motion.utils.StopLogic |
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(Configure the stop logic base on the parameters |
String |
Debugging logic to log the state. |
float |
getInterpolation(float v)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(This configure the stop logic to be a spring. |
Inherited methods |
||
|---|---|---|
|
Public constructors
Public methods
config
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
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
public float getInterpolation(float v)
Gets the interpolated given the original interpolation
| Parameters | |
|---|---|
float v |
| Returns | |
|---|---|
float |
getVelocity
public float getVelocity()
Gets the velocity at the last interpolated point
| Returns | |
|---|---|
float |
getVelocity
public float getVelocity(float x)
Get the velocity at a point in time
| Parameters | |
|---|---|
float x |
| Returns | |
|---|---|
float |
springConfig
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 |