# 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)

*** ** * ** ***


```
class StopLogic : MotionInterpolator
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.constraintlayout.motion.widget.MotionInterpolator](https://developer.android.com/reference/kotlin/androidx/constraintlayout/motion/widget/MotionInterpolator) ||
|   | ↳ | [androidx.constraintlayout.motion.utils.StopLogic](https://developer.android.com/reference/kotlin/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/kotlin/androidx/constraintlayout/motion/utils/StopLogic#StopLogic()()` |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/constraintlayout/motion/utils/StopLogic#config(float,float,float,float,float,float)( currentPos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, destination: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, currentVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, maxTime: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, maxAcceleration: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, maxVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Configure the stop logic base on the parameters |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/constraintlayout/motion/utils/StopLogic#debug(java.lang.String,float)(desc: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, time: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Debugging logic to log the state. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/constraintlayout/motion/utils/StopLogic#getInterpolation(float)(v: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Gets the interpolated given the original interpolation |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/constraintlayout/motion/utils/StopLogic#getVelocity()()` Gets the velocity at the last interpolated point |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/constraintlayout/motion/utils/StopLogic#getVelocity(float)(x: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Get the velocity at a point in time |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/constraintlayout/motion/utils/StopLogic#isStopped()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/constraintlayout/motion/utils/StopLogic#springConfig(float,float,float,float,float,float,float,int)( currentPos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, destination: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, currentVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, mass: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, stiffness: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, damping: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, stopThreshold: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, boundaryMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` This configure the stop logic to be a spring. |

| ### Inherited functions |
|---|
| From [android.animation.TimeInterpolator](https://developer.android.com/reference/android/animation/TimeInterpolator.html) |---|---| | `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/android/animation/TimeInterpolator.html#getInterpolation(float)(p: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` | |

## Public constructors

### StopLogic

Added in 2.2.2

```
StopLogic()
```

## Public functions

### config

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

```
fun config(
    currentPos: Float,
    destination: Float,
    currentVelocity: Float,
    maxTime: Float,
    maxAcceleration: Float,
    maxVelocity: Float
): Unit
```

Configure the stop logic base on the parameters

| Parameters |
|---|---|
| `currentPos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start position |
| `destination: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the ending position |
| `currentVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the starting velocity |
| `maxTime: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The maximum time to take |
| `maxAcceleration: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the maximum acceleration to use |
| `maxVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the maximum velocity to use |

### debug

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

```
fun debug(desc: String!, time: Float): String!
```

Debugging logic to log the state.

| Parameters |
|---|---|
| `desc: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | Description to pre append |
| `time: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | Time during animation |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.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)

```
fun getInterpolation(v: Float): Float
```

Gets the interpolated given the original interpolation

| Parameters |
|---|---|
| `v: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` |   |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` |   |

### getVelocity

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

```
fun getVelocity(): Float
```

Gets the velocity at the last interpolated point

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` |   |

### getVelocity

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

```
fun getVelocity(x: Float): Float
```

Get the velocity at a point in time

| Parameters |
|---|---|
| `x: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` |   |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` |   |

### isStopped

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

```
fun isStopped(): Boolean
```

### springConfig

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

```
fun springConfig(
    currentPos: Float,
    destination: Float,
    currentVelocity: Float,
    mass: Float,
    stiffness: Float,
    damping: Float,
    stopThreshold: Float,
    boundaryMode: Int
): Unit
```

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 |
|---|---|
| `currentPos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The current position |
| `destination: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The destination position |
| `currentVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the initial velocity |
| `mass: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the mass |
| `stiffness: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the stiffness or spring constant (the force by which the spring pulls) |
| `damping: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the stiffness or spring constant. (the resistance to the motion) |
| `stopThreshold: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | (When the max velocity of the movement is below this it stops) |
| `boundaryMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | This controls if it overshoots or bounces when it hits 0 and 1 |