ADD week 5

This commit is contained in:
2025-03-31 16:33:42 +02:00
parent 86f265f22d
commit bf645048e6
4927 changed files with 544053 additions and 0 deletions

View File

@ -0,0 +1,178 @@
package androidx.dynamicanimation.animation;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.view.Choreographer;
import androidx.collection.SimpleArrayMap;
import java.util.ArrayList;
/* loaded from: classes.dex */
class AnimationHandler {
private static final long FRAME_DELAY_MS = 10;
public static final ThreadLocal<AnimationHandler> sAnimatorHandler = new ThreadLocal<>();
private AnimationFrameCallbackProvider mProvider;
private final SimpleArrayMap<AnimationFrameCallback, Long> mDelayedCallbackStartTime = new SimpleArrayMap<>();
final ArrayList<AnimationFrameCallback> mAnimationCallbacks = new ArrayList<>();
private final AnimationCallbackDispatcher mCallbackDispatcher = new AnimationCallbackDispatcher();
long mCurrentFrameTime = 0;
private boolean mListDirty = false;
interface AnimationFrameCallback {
boolean doAnimationFrame(long j);
}
public void setProvider(AnimationFrameCallbackProvider animationFrameCallbackProvider) {
this.mProvider = animationFrameCallbackProvider;
}
AnimationHandler() {
}
class AnimationCallbackDispatcher {
AnimationCallbackDispatcher() {
}
void dispatchAnimationFrame() {
AnimationHandler.this.mCurrentFrameTime = SystemClock.uptimeMillis();
AnimationHandler animationHandler = AnimationHandler.this;
animationHandler.doAnimationFrame(animationHandler.mCurrentFrameTime);
if (AnimationHandler.this.mAnimationCallbacks.size() > 0) {
AnimationHandler.this.getProvider().postFrameCallback();
}
}
}
public static AnimationHandler getInstance() {
ThreadLocal<AnimationHandler> threadLocal = sAnimatorHandler;
if (threadLocal.get() == null) {
threadLocal.set(new AnimationHandler());
}
return threadLocal.get();
}
public static long getFrameTime() {
ThreadLocal<AnimationHandler> threadLocal = sAnimatorHandler;
if (threadLocal.get() == null) {
return 0L;
}
return threadLocal.get().mCurrentFrameTime;
}
AnimationFrameCallbackProvider getProvider() {
if (this.mProvider == null) {
this.mProvider = new FrameCallbackProvider16(this.mCallbackDispatcher);
}
return this.mProvider;
}
public void addAnimationFrameCallback(AnimationFrameCallback animationFrameCallback, long j) {
if (this.mAnimationCallbacks.size() == 0) {
getProvider().postFrameCallback();
}
if (!this.mAnimationCallbacks.contains(animationFrameCallback)) {
this.mAnimationCallbacks.add(animationFrameCallback);
}
if (j > 0) {
this.mDelayedCallbackStartTime.put(animationFrameCallback, Long.valueOf(SystemClock.uptimeMillis() + j));
}
}
public void removeCallback(AnimationFrameCallback animationFrameCallback) {
this.mDelayedCallbackStartTime.remove(animationFrameCallback);
int indexOf = this.mAnimationCallbacks.indexOf(animationFrameCallback);
if (indexOf >= 0) {
this.mAnimationCallbacks.set(indexOf, null);
this.mListDirty = true;
}
}
void doAnimationFrame(long j) {
long uptimeMillis = SystemClock.uptimeMillis();
for (int i = 0; i < this.mAnimationCallbacks.size(); i++) {
AnimationFrameCallback animationFrameCallback = this.mAnimationCallbacks.get(i);
if (animationFrameCallback != null && isCallbackDue(animationFrameCallback, uptimeMillis)) {
animationFrameCallback.doAnimationFrame(j);
}
}
cleanUpList();
}
private boolean isCallbackDue(AnimationFrameCallback animationFrameCallback, long j) {
Long l = this.mDelayedCallbackStartTime.get(animationFrameCallback);
if (l == null) {
return true;
}
if (l.longValue() >= j) {
return false;
}
this.mDelayedCallbackStartTime.remove(animationFrameCallback);
return true;
}
private void cleanUpList() {
if (this.mListDirty) {
for (int size = this.mAnimationCallbacks.size() - 1; size >= 0; size--) {
if (this.mAnimationCallbacks.get(size) == null) {
this.mAnimationCallbacks.remove(size);
}
}
this.mListDirty = false;
}
}
private static class FrameCallbackProvider16 extends AnimationFrameCallbackProvider {
private final Choreographer mChoreographer;
private final Choreographer.FrameCallback mChoreographerCallback;
FrameCallbackProvider16(AnimationCallbackDispatcher animationCallbackDispatcher) {
super(animationCallbackDispatcher);
this.mChoreographer = Choreographer.getInstance();
this.mChoreographerCallback = new Choreographer.FrameCallback() { // from class: androidx.dynamicanimation.animation.AnimationHandler.FrameCallbackProvider16.1
@Override // android.view.Choreographer.FrameCallback
public void doFrame(long j) {
FrameCallbackProvider16.this.mDispatcher.dispatchAnimationFrame();
}
};
}
@Override // androidx.dynamicanimation.animation.AnimationHandler.AnimationFrameCallbackProvider
void postFrameCallback() {
this.mChoreographer.postFrameCallback(this.mChoreographerCallback);
}
}
private static class FrameCallbackProvider14 extends AnimationFrameCallbackProvider {
private final Handler mHandler;
long mLastFrameTime;
private final Runnable mRunnable;
FrameCallbackProvider14(AnimationCallbackDispatcher animationCallbackDispatcher) {
super(animationCallbackDispatcher);
this.mLastFrameTime = -1L;
this.mRunnable = new Runnable() { // from class: androidx.dynamicanimation.animation.AnimationHandler.FrameCallbackProvider14.1
@Override // java.lang.Runnable
public void run() {
FrameCallbackProvider14.this.mLastFrameTime = SystemClock.uptimeMillis();
FrameCallbackProvider14.this.mDispatcher.dispatchAnimationFrame();
}
};
this.mHandler = new Handler(Looper.myLooper());
}
@Override // androidx.dynamicanimation.animation.AnimationHandler.AnimationFrameCallbackProvider
void postFrameCallback() {
this.mHandler.postDelayed(this.mRunnable, Math.max(AnimationHandler.FRAME_DELAY_MS - (SystemClock.uptimeMillis() - this.mLastFrameTime), 0L));
}
}
static abstract class AnimationFrameCallbackProvider {
final AnimationCallbackDispatcher mDispatcher;
abstract void postFrameCallback();
AnimationFrameCallbackProvider(AnimationCallbackDispatcher animationCallbackDispatcher) {
this.mDispatcher = animationCallbackDispatcher;
}
}
}

View File

@ -0,0 +1,430 @@
package androidx.dynamicanimation.animation;
import android.os.Looper;
import android.util.AndroidRuntimeException;
import android.view.View;
import androidx.constraintlayout.motion.widget.Key;
import androidx.core.view.ViewCompat;
import androidx.dynamicanimation.animation.AnimationHandler;
import androidx.dynamicanimation.animation.DynamicAnimation;
import java.util.ArrayList;
/* loaded from: classes.dex */
public abstract class DynamicAnimation<T extends DynamicAnimation<T>> implements AnimationHandler.AnimationFrameCallback {
public static final float MIN_VISIBLE_CHANGE_ALPHA = 0.00390625f;
public static final float MIN_VISIBLE_CHANGE_PIXELS = 1.0f;
public static final float MIN_VISIBLE_CHANGE_ROTATION_DEGREES = 0.1f;
public static final float MIN_VISIBLE_CHANGE_SCALE = 0.002f;
private static final float THRESHOLD_MULTIPLIER = 0.75f;
private static final float UNSET = Float.MAX_VALUE;
private final ArrayList<OnAnimationEndListener> mEndListeners;
private long mLastFrameTime;
float mMaxValue;
float mMinValue;
private float mMinVisibleChange;
final FloatPropertyCompat mProperty;
boolean mRunning;
boolean mStartValueIsSet;
final Object mTarget;
private final ArrayList<OnAnimationUpdateListener> mUpdateListeners;
float mValue;
float mVelocity;
public static final ViewProperty TRANSLATION_X = new ViewProperty("translationX") { // from class: androidx.dynamicanimation.animation.DynamicAnimation.1
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(View view, float f) {
view.setTranslationX(f);
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(View view) {
return view.getTranslationX();
}
};
public static final ViewProperty TRANSLATION_Y = new ViewProperty("translationY") { // from class: androidx.dynamicanimation.animation.DynamicAnimation.2
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(View view, float f) {
view.setTranslationY(f);
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(View view) {
return view.getTranslationY();
}
};
public static final ViewProperty TRANSLATION_Z = new ViewProperty("translationZ") { // from class: androidx.dynamicanimation.animation.DynamicAnimation.3
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(View view, float f) {
ViewCompat.setTranslationZ(view, f);
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(View view) {
return ViewCompat.getTranslationZ(view);
}
};
public static final ViewProperty SCALE_X = new ViewProperty("scaleX") { // from class: androidx.dynamicanimation.animation.DynamicAnimation.4
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(View view, float f) {
view.setScaleX(f);
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(View view) {
return view.getScaleX();
}
};
public static final ViewProperty SCALE_Y = new ViewProperty("scaleY") { // from class: androidx.dynamicanimation.animation.DynamicAnimation.5
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(View view, float f) {
view.setScaleY(f);
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(View view) {
return view.getScaleY();
}
};
public static final ViewProperty ROTATION = new ViewProperty(Key.ROTATION) { // from class: androidx.dynamicanimation.animation.DynamicAnimation.6
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(View view, float f) {
view.setRotation(f);
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(View view) {
return view.getRotation();
}
};
public static final ViewProperty ROTATION_X = new ViewProperty("rotationX") { // from class: androidx.dynamicanimation.animation.DynamicAnimation.7
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(View view, float f) {
view.setRotationX(f);
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(View view) {
return view.getRotationX();
}
};
public static final ViewProperty ROTATION_Y = new ViewProperty("rotationY") { // from class: androidx.dynamicanimation.animation.DynamicAnimation.8
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(View view, float f) {
view.setRotationY(f);
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(View view) {
return view.getRotationY();
}
};
public static final ViewProperty X = new ViewProperty("x") { // from class: androidx.dynamicanimation.animation.DynamicAnimation.9
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(View view, float f) {
view.setX(f);
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(View view) {
return view.getX();
}
};
public static final ViewProperty Y = new ViewProperty("y") { // from class: androidx.dynamicanimation.animation.DynamicAnimation.10
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(View view, float f) {
view.setY(f);
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(View view) {
return view.getY();
}
};
public static final ViewProperty Z = new ViewProperty("z") { // from class: androidx.dynamicanimation.animation.DynamicAnimation.11
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(View view, float f) {
ViewCompat.setZ(view, f);
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(View view) {
return ViewCompat.getZ(view);
}
};
public static final ViewProperty ALPHA = new ViewProperty("alpha") { // from class: androidx.dynamicanimation.animation.DynamicAnimation.12
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(View view, float f) {
view.setAlpha(f);
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(View view) {
return view.getAlpha();
}
};
public static final ViewProperty SCROLL_X = new ViewProperty("scrollX") { // from class: androidx.dynamicanimation.animation.DynamicAnimation.13
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(View view, float f) {
view.setScrollX((int) f);
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(View view) {
return view.getScrollX();
}
};
public static final ViewProperty SCROLL_Y = new ViewProperty("scrollY") { // from class: androidx.dynamicanimation.animation.DynamicAnimation.14
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(View view, float f) {
view.setScrollY((int) f);
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(View view) {
return view.getScrollY();
}
};
public interface OnAnimationEndListener {
void onAnimationEnd(DynamicAnimation dynamicAnimation, boolean z, float f, float f2);
}
public interface OnAnimationUpdateListener {
void onAnimationUpdate(DynamicAnimation dynamicAnimation, float f, float f2);
}
abstract float getAcceleration(float f, float f2);
public float getMinimumVisibleChange() {
return this.mMinVisibleChange;
}
float getValueThreshold() {
return this.mMinVisibleChange * 0.75f;
}
abstract boolean isAtEquilibrium(float f, float f2);
public boolean isRunning() {
return this.mRunning;
}
public T setMaxValue(float f) {
this.mMaxValue = f;
return this;
}
public T setMinValue(float f) {
this.mMinValue = f;
return this;
}
public T setStartValue(float f) {
this.mValue = f;
this.mStartValueIsSet = true;
return this;
}
public T setStartVelocity(float f) {
this.mVelocity = f;
return this;
}
abstract void setValueThreshold(float f);
abstract boolean updateValueAndVelocity(long j);
public static abstract class ViewProperty extends FloatPropertyCompat<View> {
private ViewProperty(String str) {
super(str);
}
}
static class MassState {
float mValue;
float mVelocity;
MassState() {
}
}
DynamicAnimation(final FloatValueHolder floatValueHolder) {
this.mVelocity = 0.0f;
this.mValue = Float.MAX_VALUE;
this.mStartValueIsSet = false;
this.mRunning = false;
this.mMaxValue = Float.MAX_VALUE;
this.mMinValue = -Float.MAX_VALUE;
this.mLastFrameTime = 0L;
this.mEndListeners = new ArrayList<>();
this.mUpdateListeners = new ArrayList<>();
this.mTarget = null;
this.mProperty = new FloatPropertyCompat("FloatValueHolder") { // from class: androidx.dynamicanimation.animation.DynamicAnimation.15
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(Object obj) {
return floatValueHolder.getValue();
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(Object obj, float f) {
floatValueHolder.setValue(f);
}
};
this.mMinVisibleChange = 1.0f;
}
<K> DynamicAnimation(K k, FloatPropertyCompat<K> floatPropertyCompat) {
this.mVelocity = 0.0f;
this.mValue = Float.MAX_VALUE;
this.mStartValueIsSet = false;
this.mRunning = false;
this.mMaxValue = Float.MAX_VALUE;
this.mMinValue = -Float.MAX_VALUE;
this.mLastFrameTime = 0L;
this.mEndListeners = new ArrayList<>();
this.mUpdateListeners = new ArrayList<>();
this.mTarget = k;
this.mProperty = floatPropertyCompat;
if (floatPropertyCompat == ROTATION || floatPropertyCompat == ROTATION_X || floatPropertyCompat == ROTATION_Y) {
this.mMinVisibleChange = 0.1f;
return;
}
if (floatPropertyCompat == ALPHA) {
this.mMinVisibleChange = 0.00390625f;
} else if (floatPropertyCompat == SCALE_X || floatPropertyCompat == SCALE_Y) {
this.mMinVisibleChange = 0.00390625f;
} else {
this.mMinVisibleChange = 1.0f;
}
}
public T addEndListener(OnAnimationEndListener onAnimationEndListener) {
if (!this.mEndListeners.contains(onAnimationEndListener)) {
this.mEndListeners.add(onAnimationEndListener);
}
return this;
}
public void removeEndListener(OnAnimationEndListener onAnimationEndListener) {
removeEntry(this.mEndListeners, onAnimationEndListener);
}
public T addUpdateListener(OnAnimationUpdateListener onAnimationUpdateListener) {
if (isRunning()) {
throw new UnsupportedOperationException("Error: Update listeners must be added beforethe animation.");
}
if (!this.mUpdateListeners.contains(onAnimationUpdateListener)) {
this.mUpdateListeners.add(onAnimationUpdateListener);
}
return this;
}
public void removeUpdateListener(OnAnimationUpdateListener onAnimationUpdateListener) {
removeEntry(this.mUpdateListeners, onAnimationUpdateListener);
}
public T setMinimumVisibleChange(float f) {
if (f <= 0.0f) {
throw new IllegalArgumentException("Minimum visible change must be positive.");
}
this.mMinVisibleChange = f;
setValueThreshold(f * 0.75f);
return this;
}
private static <T> void removeNullEntries(ArrayList<T> arrayList) {
for (int size = arrayList.size() - 1; size >= 0; size--) {
if (arrayList.get(size) == null) {
arrayList.remove(size);
}
}
}
private static <T> void removeEntry(ArrayList<T> arrayList, T t) {
int indexOf = arrayList.indexOf(t);
if (indexOf >= 0) {
arrayList.set(indexOf, null);
}
}
public void start() {
if (Looper.myLooper() != Looper.getMainLooper()) {
throw new AndroidRuntimeException("Animations may only be started on the main thread");
}
if (this.mRunning) {
return;
}
startAnimationInternal();
}
public void cancel() {
if (Looper.myLooper() != Looper.getMainLooper()) {
throw new AndroidRuntimeException("Animations may only be canceled on the main thread");
}
if (this.mRunning) {
endAnimationInternal(true);
}
}
private void startAnimationInternal() {
if (this.mRunning) {
return;
}
this.mRunning = true;
if (!this.mStartValueIsSet) {
this.mValue = getPropertyValue();
}
float f = this.mValue;
if (f > this.mMaxValue || f < this.mMinValue) {
throw new IllegalArgumentException("Starting value need to be in between min value and max value");
}
AnimationHandler.getInstance().addAnimationFrameCallback(this, 0L);
}
@Override // androidx.dynamicanimation.animation.AnimationHandler.AnimationFrameCallback
public boolean doAnimationFrame(long j) {
long j2 = this.mLastFrameTime;
if (j2 == 0) {
this.mLastFrameTime = j;
setPropertyValue(this.mValue);
return false;
}
this.mLastFrameTime = j;
boolean updateValueAndVelocity = updateValueAndVelocity(j - j2);
float min = Math.min(this.mValue, this.mMaxValue);
this.mValue = min;
float max = Math.max(min, this.mMinValue);
this.mValue = max;
setPropertyValue(max);
if (updateValueAndVelocity) {
endAnimationInternal(false);
}
return updateValueAndVelocity;
}
private void endAnimationInternal(boolean z) {
this.mRunning = false;
AnimationHandler.getInstance().removeCallback(this);
this.mLastFrameTime = 0L;
this.mStartValueIsSet = false;
for (int i = 0; i < this.mEndListeners.size(); i++) {
if (this.mEndListeners.get(i) != null) {
this.mEndListeners.get(i).onAnimationEnd(this, z, this.mValue, this.mVelocity);
}
}
removeNullEntries(this.mEndListeners);
}
void setPropertyValue(float f) {
this.mProperty.setValue(this.mTarget, f);
for (int i = 0; i < this.mUpdateListeners.size(); i++) {
if (this.mUpdateListeners.get(i) != null) {
this.mUpdateListeners.get(i).onAnimationUpdate(this, this.mValue, this.mVelocity);
}
}
removeNullEntries(this.mUpdateListeners);
}
private float getPropertyValue() {
return this.mProperty.getValue(this.mTarget);
}
}

View File

@ -0,0 +1,128 @@
package androidx.dynamicanimation.animation;
import androidx.dynamicanimation.animation.DynamicAnimation;
/* loaded from: classes.dex */
public final class FlingAnimation extends DynamicAnimation<FlingAnimation> {
private final DragForce mFlingForce;
public FlingAnimation(FloatValueHolder floatValueHolder) {
super(floatValueHolder);
DragForce dragForce = new DragForce();
this.mFlingForce = dragForce;
dragForce.setValueThreshold(getValueThreshold());
}
public <K> FlingAnimation(K k, FloatPropertyCompat<K> floatPropertyCompat) {
super(k, floatPropertyCompat);
DragForce dragForce = new DragForce();
this.mFlingForce = dragForce;
dragForce.setValueThreshold(getValueThreshold());
}
public FlingAnimation setFriction(float f) {
if (f <= 0.0f) {
throw new IllegalArgumentException("Friction must be positive");
}
this.mFlingForce.setFrictionScalar(f);
return this;
}
public float getFriction() {
return this.mFlingForce.getFrictionScalar();
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
public FlingAnimation setMinValue(float f) {
super.setMinValue(f);
return this;
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
public FlingAnimation setMaxValue(float f) {
super.setMaxValue(f);
return this;
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
public FlingAnimation setStartVelocity(float f) {
super.setStartVelocity(f);
return this;
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
boolean updateValueAndVelocity(long j) {
DynamicAnimation.MassState updateValueAndVelocity = this.mFlingForce.updateValueAndVelocity(this.mValue, this.mVelocity, j);
this.mValue = updateValueAndVelocity.mValue;
this.mVelocity = updateValueAndVelocity.mVelocity;
if (this.mValue < this.mMinValue) {
this.mValue = this.mMinValue;
return true;
}
if (this.mValue <= this.mMaxValue) {
return isAtEquilibrium(this.mValue, this.mVelocity);
}
this.mValue = this.mMaxValue;
return true;
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
float getAcceleration(float f, float f2) {
return this.mFlingForce.getAcceleration(f, f2);
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
boolean isAtEquilibrium(float f, float f2) {
return f >= this.mMaxValue || f <= this.mMinValue || this.mFlingForce.isAtEquilibrium(f, f2);
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
void setValueThreshold(float f) {
this.mFlingForce.setValueThreshold(f);
}
static final class DragForce implements Force {
private static final float DEFAULT_FRICTION = -4.2f;
private static final float VELOCITY_THRESHOLD_MULTIPLIER = 62.5f;
private float mFriction = DEFAULT_FRICTION;
private final DynamicAnimation.MassState mMassState = new DynamicAnimation.MassState();
private float mVelocityThreshold;
@Override // androidx.dynamicanimation.animation.Force
public float getAcceleration(float f, float f2) {
return f2 * this.mFriction;
}
float getFrictionScalar() {
return this.mFriction / DEFAULT_FRICTION;
}
void setFrictionScalar(float f) {
this.mFriction = f * DEFAULT_FRICTION;
}
void setValueThreshold(float f) {
this.mVelocityThreshold = f * VELOCITY_THRESHOLD_MULTIPLIER;
}
DragForce() {
}
DynamicAnimation.MassState updateValueAndVelocity(float f, float f2, long j) {
float f3 = j;
this.mMassState.mVelocity = (float) (f2 * Math.exp((f3 / 1000.0f) * this.mFriction));
DynamicAnimation.MassState massState = this.mMassState;
float f4 = this.mFriction;
massState.mValue = (float) ((f - (f2 / f4)) + ((f2 / f4) * Math.exp((f4 * f3) / 1000.0f)));
if (isAtEquilibrium(this.mMassState.mValue, this.mMassState.mVelocity)) {
this.mMassState.mVelocity = 0.0f;
}
return this.mMassState;
}
@Override // androidx.dynamicanimation.animation.Force
public boolean isAtEquilibrium(float f, float f2) {
return Math.abs(f2) < this.mVelocityThreshold;
}
}
}

View File

@ -0,0 +1,34 @@
package androidx.dynamicanimation.animation;
import android.util.FloatProperty;
/* loaded from: classes.dex */
public abstract class FloatPropertyCompat<T> {
final String mPropertyName;
public abstract float getValue(T t);
public abstract void setValue(T t, float f);
public FloatPropertyCompat(String str) {
this.mPropertyName = str;
}
public static <T> FloatPropertyCompat<T> createFloatPropertyCompat(final FloatProperty<T> floatProperty) {
String name;
name = floatProperty.getName();
return new FloatPropertyCompat<T>(name) { // from class: androidx.dynamicanimation.animation.FloatPropertyCompat.1
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public float getValue(T t) {
Object obj;
obj = floatProperty.get(t);
return ((Float) obj).floatValue();
}
@Override // androidx.dynamicanimation.animation.FloatPropertyCompat
public void setValue(T t, float f) {
floatProperty.setValue(t, f);
}
};
}
}

View File

@ -0,0 +1,21 @@
package androidx.dynamicanimation.animation;
/* loaded from: classes.dex */
public final class FloatValueHolder {
private float mValue = 0.0f;
public float getValue() {
return this.mValue;
}
public void setValue(float f) {
this.mValue = f;
}
public FloatValueHolder() {
}
public FloatValueHolder(float f) {
setValue(f);
}
}

View File

@ -0,0 +1,8 @@
package androidx.dynamicanimation.animation;
/* loaded from: classes.dex */
interface Force {
float getAcceleration(float f, float f2);
boolean isAtEquilibrium(float f, float f2);
}

View File

@ -0,0 +1,144 @@
package androidx.dynamicanimation.animation;
import android.os.Looper;
import android.util.AndroidRuntimeException;
import androidx.dynamicanimation.animation.DynamicAnimation;
/* loaded from: classes.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 SpringForce getSpring() {
return this.mSpring;
}
public SpringAnimation setSpring(SpringForce springForce) {
this.mSpring = springForce;
return this;
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
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);
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
public void start() {
sanityCheck();
this.mSpring.setValueThreshold(getValueThreshold());
super.start();
}
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 void skipToEnd() {
if (!canSkipToEnd()) {
throw new UnsupportedOperationException("Spring animations can only come to an end when there is damping");
}
if (Looper.myLooper() != Looper.getMainLooper()) {
throw new AndroidRuntimeException("Animations may only be started on the main thread");
}
if (this.mRunning) {
this.mEndRequested = true;
}
}
public boolean canSkipToEnd() {
return this.mSpring.mDampingRatio > 0.0d;
}
private void sanityCheck() {
SpringForce springForce = this.mSpring;
if (springForce == null) {
throw new UnsupportedOperationException("Incomplete SpringAnimation: Either final position or a spring force needs to be set.");
}
double finalPosition = springForce.getFinalPosition();
if (finalPosition > this.mMaxValue) {
throw new UnsupportedOperationException("Final position of the spring cannot be greater than the max value.");
}
if (finalPosition < this.mMinValue) {
throw new UnsupportedOperationException("Final position of the spring cannot be less than the min value.");
}
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
boolean updateValueAndVelocity(long j) {
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) {
this.mSpring.getFinalPosition();
long j2 = j / 2;
DynamicAnimation.MassState updateValues = this.mSpring.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 = this.mSpring.updateValues(this.mValue, this.mVelocity, j);
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;
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
float getAcceleration(float f, float f2) {
return this.mSpring.getAcceleration(f, f2);
}
@Override // androidx.dynamicanimation.animation.DynamicAnimation
boolean isAtEquilibrium(float f, float f2) {
return this.mSpring.isAtEquilibrium(f, f2);
}
}

View File

@ -0,0 +1,163 @@
package androidx.dynamicanimation.animation;
import androidx.dynamicanimation.animation.DynamicAnimation;
/* loaded from: classes.dex */
public final class SpringForce implements Force {
public static final float DAMPING_RATIO_HIGH_BOUNCY = 0.2f;
public static final float DAMPING_RATIO_LOW_BOUNCY = 0.75f;
public static final float DAMPING_RATIO_MEDIUM_BOUNCY = 0.5f;
public static final float DAMPING_RATIO_NO_BOUNCY = 1.0f;
public static final float STIFFNESS_HIGH = 10000.0f;
public static final float STIFFNESS_LOW = 200.0f;
public static final float STIFFNESS_MEDIUM = 1500.0f;
public static final float STIFFNESS_VERY_LOW = 50.0f;
private static final double UNSET = Double.MAX_VALUE;
private static final double VELOCITY_THRESHOLD_MULTIPLIER = 62.5d;
private double mDampedFreq;
double mDampingRatio;
private double mFinalPosition;
private double mGammaMinus;
private double mGammaPlus;
private boolean mInitialized;
private final DynamicAnimation.MassState mMassState;
double mNaturalFreq;
private double mValueThreshold;
private double mVelocityThreshold;
public float getDampingRatio() {
return (float) this.mDampingRatio;
}
public float getFinalPosition() {
return (float) this.mFinalPosition;
}
public float getStiffness() {
double d = this.mNaturalFreq;
return (float) (d * d);
}
public SpringForce setFinalPosition(float f) {
this.mFinalPosition = f;
return this;
}
public SpringForce() {
this.mNaturalFreq = Math.sqrt(1500.0d);
this.mDampingRatio = 0.5d;
this.mInitialized = false;
this.mFinalPosition = Double.MAX_VALUE;
this.mMassState = new DynamicAnimation.MassState();
}
public SpringForce(float f) {
this.mNaturalFreq = Math.sqrt(1500.0d);
this.mDampingRatio = 0.5d;
this.mInitialized = false;
this.mFinalPosition = Double.MAX_VALUE;
this.mMassState = new DynamicAnimation.MassState();
this.mFinalPosition = f;
}
public SpringForce setStiffness(float f) {
if (f <= 0.0f) {
throw new IllegalArgumentException("Spring stiffness constant must be positive.");
}
this.mNaturalFreq = Math.sqrt(f);
this.mInitialized = false;
return this;
}
public SpringForce setDampingRatio(float f) {
if (f < 0.0f) {
throw new IllegalArgumentException("Damping ratio must be non-negative");
}
this.mDampingRatio = f;
this.mInitialized = false;
return this;
}
@Override // androidx.dynamicanimation.animation.Force
public float getAcceleration(float f, float f2) {
float finalPosition = f - getFinalPosition();
double d = this.mNaturalFreq;
return (float) (((-(d * d)) * finalPosition) - (((d * 2.0d) * this.mDampingRatio) * f2));
}
@Override // androidx.dynamicanimation.animation.Force
public boolean isAtEquilibrium(float f, float f2) {
return ((double) Math.abs(f2)) < this.mVelocityThreshold && ((double) Math.abs(f - getFinalPosition())) < this.mValueThreshold;
}
private void init() {
if (this.mInitialized) {
return;
}
if (this.mFinalPosition == Double.MAX_VALUE) {
throw new IllegalStateException("Error: Final position of the spring must be set before the animation starts");
}
double d = this.mDampingRatio;
if (d > 1.0d) {
double d2 = this.mNaturalFreq;
this.mGammaPlus = ((-d) * d2) + (d2 * Math.sqrt((d * d) - 1.0d));
double d3 = this.mDampingRatio;
double d4 = this.mNaturalFreq;
this.mGammaMinus = ((-d3) * d4) - (d4 * Math.sqrt((d3 * d3) - 1.0d));
} else if (d >= 0.0d && d < 1.0d) {
this.mDampedFreq = this.mNaturalFreq * Math.sqrt(1.0d - (d * d));
}
this.mInitialized = true;
}
DynamicAnimation.MassState updateValues(double d, double d2, long j) {
double cos;
double d3;
init();
double d4 = j / 1000.0d;
double d5 = d - this.mFinalPosition;
double d6 = this.mDampingRatio;
if (d6 > 1.0d) {
double d7 = this.mGammaMinus;
double d8 = this.mGammaPlus;
double d9 = d5 - (((d7 * d5) - d2) / (d7 - d8));
double d10 = ((d5 * d7) - d2) / (d7 - d8);
d3 = (Math.pow(2.718281828459045d, d7 * d4) * d9) + (Math.pow(2.718281828459045d, this.mGammaPlus * d4) * d10);
double d11 = this.mGammaMinus;
double pow = d9 * d11 * Math.pow(2.718281828459045d, d11 * d4);
double d12 = this.mGammaPlus;
cos = pow + (d10 * d12 * Math.pow(2.718281828459045d, d12 * d4));
} else if (d6 == 1.0d) {
double d13 = this.mNaturalFreq;
double d14 = d2 + (d13 * d5);
double d15 = d5 + (d14 * d4);
d3 = Math.pow(2.718281828459045d, (-d13) * d4) * d15;
double pow2 = d15 * Math.pow(2.718281828459045d, (-this.mNaturalFreq) * d4);
double d16 = this.mNaturalFreq;
cos = (d14 * Math.pow(2.718281828459045d, (-d16) * d4)) + (pow2 * (-d16));
} else {
double d17 = 1.0d / this.mDampedFreq;
double d18 = this.mNaturalFreq;
double d19 = d17 * ((d6 * d18 * d5) + d2);
double pow3 = Math.pow(2.718281828459045d, (-d6) * d18 * d4) * ((Math.cos(this.mDampedFreq * d4) * d5) + (Math.sin(this.mDampedFreq * d4) * d19));
double d20 = this.mNaturalFreq;
double d21 = this.mDampingRatio;
double d22 = (-d20) * pow3 * d21;
double pow4 = Math.pow(2.718281828459045d, (-d21) * d20 * d4);
double d23 = this.mDampedFreq;
double sin = (-d23) * d5 * Math.sin(d23 * d4);
double d24 = this.mDampedFreq;
cos = d22 + (pow4 * (sin + (d19 * d24 * Math.cos(d24 * d4))));
d3 = pow3;
}
this.mMassState.mValue = (float) (d3 + this.mFinalPosition);
this.mMassState.mVelocity = (float) cos;
return this.mMassState;
}
void setValueThreshold(double d) {
double abs = Math.abs(d);
this.mValueThreshold = abs;
this.mVelocityThreshold = abs * VELOCITY_THRESHOLD_MULTIPLIER;
}
}