# StopLogic

Artifact: [androidx.constraintlayout:constraintlayout](https://developer.android.com/jetpack/androidx/releases/constraintlayout) [View Source](https://cs.android.com/search?q=file:androidx/constraintlayout/motion/utils/StopLogic.java+class:androidx.constraintlayout.motion.utils.StopLogic) Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

*** ** * ** ***


```
public class StopLogic extends MotionInterpolator
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.constraintlayout.motion.widget.MotionInterpolator](https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionInterpolator) ||
|   | ↳ | [androidx.constraintlayout.motion.utils.StopLogic](https://developer.android.com/reference/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 |
|---|
| `https://developer.android.com/reference/androidx/constraintlayout/motion/utils/StopLogic#StopLogic()()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/utils/StopLogic#config(float,float,float,float,float,float)( float currentPos, float destination, float currentVelocity, float maxTime, float maxAcceleration, float maxVelocity )` Configure the stop logic base on the parameters |
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/constraintlayout/motion/utils/StopLogic#debug(java.lang.String,float)(https://developer.android.com/reference/java/lang/String.html desc, float time)` Debugging logic to log the state. |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/motion/utils/StopLogic#getInterpolation(float)(float v)` Gets the interpolated given the original interpolation |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/motion/utils/StopLogic#getVelocity()()` Gets the velocity at the last interpolated point |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/motion/utils/StopLogic#getVelocity(float)(float x)` Get the velocity at a point in time |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/motion/utils/StopLogic#isStopped()()` |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/motion/utils/StopLogic#springConfig(float,float,float,float,float,float,float,int)( 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](https://developer.android.com/reference/android/animation/TimeInterpolator.html) |---|---| | `abstract float` | `https://developer.android.com/reference/android/animation/TimeInterpolator.html#getInterpolation(float)(float p)` | |

## Public constructors

### StopLogic

Added in 2.2.2

```
public StopLogic()
```

## Public methods

### config

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
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.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public String debug(String desc, float time)
```

Debugging logic to log the state.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html desc` | Description to pre append |
| `float time` | Time during animation |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` | string useful for debugging the state of the StopLogic |

### getInterpolation

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public float getInterpolation(float v)
```

Gets the interpolated given the original interpolation

| Parameters |
|---|---|
| `float v` |   |

| Returns |
|---|---|
| `float` |   |

### getVelocity

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public float getVelocity()
```

Gets the velocity at the last interpolated point

| Returns |
|---|---|
| `float` |   |

### getVelocity

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public float getVelocity(float x)
```

Get the velocity at a point in time

| Parameters |
|---|---|
| `float x` |   |

| Returns |
|---|---|
| `float` |   |

### isStopped

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
public boolean isStopped()
```

### springConfig

Added in [2.2.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#2.2.2)

```
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 |