alexandroid/decompiled/jadx/sources/androidx/dynamicanimation/animation/SpringAnimation.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

178 lines
6.3 KiB
Java

package androidx.dynamicanimation.animation;
import android.util.AndroidRuntimeException;
import androidx.annotation.MainThread;
import androidx.dynamicanimation.animation.DynamicAnimation;
import okio.Buffer$$ExternalSyntheticBUOutline0;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes14.dex */
public final class SpringAnimation extends DynamicAnimation<SpringAnimation> {
private static final float UNSET = Float.MAX_VALUE;
private boolean mEndRequested;
private float mPendingPosition;
private SpringForce mSpring;
public SpringAnimation(FloatValueHolder floatValueHolder, float f) {
super(floatValueHolder);
this.mSpring = null;
this.mPendingPosition = Float.MAX_VALUE;
this.mEndRequested = false;
this.mSpring = new SpringForce(f);
}
private void sanityCheck() {
SpringForce springForce = this.mSpring;
if (springForce == null) {
Buffer$$ExternalSyntheticBUOutline0.m$1("Incomplete SpringAnimation: Either final position or a spring force needs to be set.");
return;
}
double finalPosition = springForce.getFinalPosition();
if (finalPosition > this.mMaxValue) {
Buffer$$ExternalSyntheticBUOutline0.m$1("Final position of the spring cannot be greater than the max value.");
} else {
if (finalPosition >= this.mMinValue) {
return;
}
Buffer$$ExternalSyntheticBUOutline0.m$1("Final position of the spring cannot be less than the min value.");
}
}
public void animateToFinalPosition(float f) {
if (isRunning()) {
this.mPendingPosition = f;
return;
}
if (this.mSpring == null) {
this.mSpring = new SpringForce(f);
}
this.mSpring.setFinalPosition(f);
start();
}
public boolean canSkipToEnd() {
return this.mSpring.mDampingRatio > 0.0d;
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
@MainThread
public void cancel() {
super.cancel();
float f = this.mPendingPosition;
if (f != Float.MAX_VALUE) {
SpringForce springForce = this.mSpring;
if (springForce == null) {
this.mSpring = new SpringForce(f);
} else {
springForce.setFinalPosition(f);
}
this.mPendingPosition = Float.MAX_VALUE;
}
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
public float getAcceleration(float f, float f2) {
return this.mSpring.getAcceleration(f, f2);
}
public SpringForce getSpring() {
return this.mSpring;
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
public boolean isAtEquilibrium(float f, float f2) {
return this.mSpring.isAtEquilibrium(f, f2);
}
public SpringAnimation setSpring(SpringForce springForce) {
this.mSpring = springForce;
return this;
}
public void skipToEnd() {
if (!canSkipToEnd()) {
Buffer$$ExternalSyntheticBUOutline0.m$1("Spring animations can only come to an end when there is damping");
} else {
if (!getAnimationHandler().isCurrentThread()) {
throw new AndroidRuntimeException("Animations may only be started on the same thread as the animation handler");
}
if (this.mRunning) {
this.mEndRequested = true;
}
}
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
@MainThread
public void start() {
sanityCheck();
this.mSpring.setValueThreshold(getValueThreshold());
super.start();
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
public boolean updateValueAndVelocity(long j) {
boolean z = this.mEndRequested;
float f = this.mPendingPosition;
if (z) {
if (f != Float.MAX_VALUE) {
this.mSpring.setFinalPosition(f);
this.mPendingPosition = Float.MAX_VALUE;
}
this.mValue = this.mSpring.getFinalPosition();
this.mVelocity = 0.0f;
this.mEndRequested = false;
return true;
}
SpringForce springForce = this.mSpring;
if (f != Float.MAX_VALUE) {
long j2 = j / 2;
DynamicAnimation.MassState updateValues = springForce.updateValues(this.mValue, this.mVelocity, j2);
this.mSpring.setFinalPosition(this.mPendingPosition);
this.mPendingPosition = Float.MAX_VALUE;
DynamicAnimation.MassState updateValues2 = this.mSpring.updateValues(updateValues.mValue, updateValues.mVelocity, j2);
this.mValue = updateValues2.mValue;
this.mVelocity = updateValues2.mVelocity;
} else {
DynamicAnimation.MassState updateValues3 = springForce.updateValues(this.mValue, this.mVelocity, j);
this.mValue = updateValues3.mValue;
this.mVelocity = updateValues3.mVelocity;
}
float max = Math.max(this.mValue, this.mMinValue);
this.mValue = max;
float min = Math.min(max, this.mMaxValue);
this.mValue = min;
if (!isAtEquilibrium(min, this.mVelocity)) {
return false;
}
this.mValue = this.mSpring.getFinalPosition();
this.mVelocity = 0.0f;
return true;
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
public void setValueThreshold(float f) {
}
public SpringAnimation(FloatValueHolder floatValueHolder) {
super(floatValueHolder);
this.mSpring = null;
this.mPendingPosition = Float.MAX_VALUE;
this.mEndRequested = false;
}
public <K> SpringAnimation(K k, FloatPropertyCompat<K> floatPropertyCompat) {
super(k, floatPropertyCompat);
this.mSpring = null;
this.mPendingPosition = Float.MAX_VALUE;
this.mEndRequested = false;
}
public <K> SpringAnimation(K k, FloatPropertyCompat<K> floatPropertyCompat, float f) {
super(k, floatPropertyCompat);
this.mSpring = null;
this.mPendingPosition = Float.MAX_VALUE;
this.mEndRequested = false;
this.mSpring = new SpringForce(f);
}
}