diff options
author | 2020-02-07 18:29:03 +0000 | |
---|---|---|
committer | 2020-02-07 18:29:03 +0000 | |
commit | e339549209dd8ac0dbfd858cc3ec25a54f242bcc (patch) | |
tree | 793a126f72bb08e3f444b13fc0d078c73337376b | |
parent | 688689eb58b4a3409dd9a5ff308bb7c2b1c27a28 (diff) | |
parent | 5b139c32464b56c30cd8d7c2304acf044a65282a (diff) |
Merge "Adds estimateFlingEndValue to PhysicsAnimator."
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/util/animation/PhysicsAnimator.kt | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/util/animation/PhysicsAnimator.kt b/packages/SystemUI/src/com/android/systemui/util/animation/PhysicsAnimator.kt index cfd77be9303d..f4157f21e158 100644 --- a/packages/SystemUI/src/com/android/systemui/util/animation/PhysicsAnimator.kt +++ b/packages/SystemUI/src/com/android/systemui/util/animation/PhysicsAnimator.kt @@ -901,6 +901,23 @@ class PhysicsAnimator<T> private constructor (val target: T) { verboseLogging = debug } + /** + * Estimates the end value of a fling that starts at the given value using the provided + * start velocity and fling configuration. + * + * This is only an estimate. Fling animations use a timing-based physics simulation that is + * non-deterministic, so this exact value may not be reached. + */ + @JvmStatic + fun estimateFlingEndValue( + startValue: Float, + startVelocity: Float, + flingConfig: FlingConfig + ): Float { + val distance = startVelocity / (flingConfig.friction * FLING_FRICTION_SCALAR_MULTIPLIER) + return Math.min(flingConfig.max, Math.max(flingConfig.min, startValue + distance)) + } + @JvmStatic fun getReadablePropertyName(property: FloatPropertyCompat<*>): String { return when (property) { |