content: package androidx.dynamicanimation.animation;
  
  import android.os.Looper;
  import android.util.AndroidRuntimeException;
  import androidx.dynamicanimation.animation.DynamicAnimation;
  
  public final class SpringAnimation extends DynamicAnimation<SpringAnimation> {
      private static final float UNSET = Float.MAX_VALUE;
      private boolean mEndRequested = false;
      private float mPendingPosition = Float.MAX_VALUE;
      private SpringForce mSpring = null;
  
      public SpringAnimation(FloatValueHolder floatValueHolder) {
          super(floatValueHolder);
      }
  
      public <K> SpringAnimation(K k, FloatPropertyCompat<K> floatPropertyCompat) {
          super(k, floatPropertyCompat);
      }
  
      public <K> SpringAnimation(K k, FloatPropertyCompat<K> floatPropertyCompat, float finalPosition) {
          super(k, floatPropertyCompat);
          this.mSpring = new SpringForce(finalPosition);
      }
  
      private void sanityCheck() {
          SpringForce springForce = this.mSpring;
          if (springForce != null) {
              double finalPosition = (double) springForce.getFinalPosition();
              if (finalPosition > ((double) this.mMaxValue)) {
                  throw new UnsupportedOperationException("Final position of the spring cannot be greater than the max value.");
              } else if (finalPosition < ((double) this.mMinValue)) {
                  throw new UnsupportedOperationException("Final position of the spring cannot be less than the min value.");
              }
          } else {
              throw new UnsupportedOperationException("Incomplete SpringAnimation: Either final position or a spring force needs to be set.");
          }
      }
  
      public void animateToFinalPosition(float finalPosition) {
          if (isRunning()) {
              this.mPendingPosition = finalPosition;
              return;
          }
          if (this.mSpring == null) {
              this.mSpring = new SpringForce(finalPosition);
          }
          this.mSpring.setFinalPosition(finalPosition);
          start();
      }
  
      public boolean canSkipToEnd() {
          return this.mSpring.mDampingRatio > 0.0d;
      }
  
      /* access modifiers changed from: package-private */
      public float getAcceleration(float value, float velocity) {
          return this.mSpring.getAcceleration(value, velocity);
      }
  
      public SpringForce getSpring() {
          return this.mSpring;
      }
  
      /* access modifiers changed from: package-private */
      public boolean isAtEquilibrium(float value, float velocity) {
          return this.mSpring.isAtEquilibrium(value, velocity);
      }
  
      public SpringAnimation setSpring(SpringForce force) {
          this.mSpring = force;
          return this;
      }
  
      /* access modifiers changed from: package-private */
      public void setValueThreshold(float threshold) {
      }
  
      public void skipToEnd() {
          if (!canSkipToEnd()) {
              throw new UnsupportedOperationException("Spring animations can only come to an end when there is damping");
          } else if (Looper.myLooper() != Looper.getMainLooper()) {
              throw new AndroidRuntimeException("Animations may only be started on the main thread");
          } else if (this.mRunning) {
              this.mEndRequested = true;
          }
      }
  
      public void start() {
          sanityCheck();
          this.mSpring.setValueThreshold((double) getValueThreshold());
          super.start();
      }
  
      /* access modifiers changed from: package-private */
      public boolean updateValueAndVelocity(long deltaT) {
          if (this.mEndRequested) {
              float f = this.mPendingPosition;
              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;
          }
          if (this.mPendingPosition != Float.MAX_VALUE) {
              double finalPosition = (double) this.mSpring.getFinalPosition();
              DynamicAnimation.MassState updateValues = this.mSpring.updateValues((double) this.mValue, (double) this.mVelocity, deltaT / 2);
              this.mSpring.setFinalPosition(this.mPendingPosition);
              this.mPendingPosition = Float.MAX_VALUE;
              DynamicAnimation.MassState updateValues2 = this.mSpring.updateValues((double) updateValues.mValue, (double) updateValues.mVelocity, deltaT / 2);
              this.mValue = updateValues2.mValue;
              this.mVelocity = updateValues2.mVelocity;
          } else {
              DynamicAnimation.MassState updateValues3 = this.mSpring.updateValues((double) this.mValue, (double) this.mVelocity, deltaT);
              this.mValue = updateValues3.mValue;
              this.mVelocity = updateValues3.mVelocity;
          }
          this.mValue = Math.max(this.mValue, this.mMinValue);
          this.mValue = Math.min(this.mValue, this.mMaxValue);
          if (!isAtEquilibrium(this.mValue, this.mVelocity)) {
              return false;
          }
          this.mValue = this.mSpring.getFinalPosition();
          this.mVelocity = 0.0f;
          return true;
      }
  }
  