337 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			337 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package androidx.constraintlayout.motion.utils;
 | |
| 
 | |
| import android.util.Log;
 | |
| import android.util.SparseArray;
 | |
| import android.view.View;
 | |
| import androidx.constraintlayout.core.motion.utils.CurveFit;
 | |
| import androidx.constraintlayout.core.motion.utils.KeyCache;
 | |
| import androidx.constraintlayout.core.motion.utils.TimeCycleSplineSet;
 | |
| import androidx.constraintlayout.motion.widget.MotionLayout;
 | |
| import androidx.constraintlayout.widget.ConstraintAttribute;
 | |
| import java.lang.reflect.Array;
 | |
| import java.lang.reflect.InvocationTargetException;
 | |
| import java.lang.reflect.Method;
 | |
| 
 | |
| /* loaded from: classes.dex */
 | |
| public abstract class ViewTimeCycle extends TimeCycleSplineSet {
 | |
|     private static final String TAG = "ViewTimeCycle";
 | |
| 
 | |
|     public abstract boolean setProperty(View view, float t, long time, KeyCache cache);
 | |
| 
 | |
|     public float get(float pos, long time, View view, KeyCache cache) {
 | |
|         this.mCurveFit.getPos(pos, this.mCache);
 | |
|         boolean z = true;
 | |
|         float f = this.mCache[1];
 | |
|         if (f == 0.0f) {
 | |
|             this.mContinue = false;
 | |
|             return this.mCache[2];
 | |
|         }
 | |
|         if (Float.isNaN(this.last_cycle)) {
 | |
|             this.last_cycle = cache.getFloatValue(view, this.mType, 0);
 | |
|             if (Float.isNaN(this.last_cycle)) {
 | |
|                 this.last_cycle = 0.0f;
 | |
|             }
 | |
|         }
 | |
|         this.last_cycle = (float) ((this.last_cycle + (((time - this.last_time) * 1.0E-9d) * f)) % 1.0d);
 | |
|         cache.setFloatValue(view, this.mType, 0, this.last_cycle);
 | |
|         this.last_time = time;
 | |
|         float f2 = this.mCache[0];
 | |
|         float calcWave = (calcWave(this.last_cycle) * f2) + this.mCache[2];
 | |
|         if (f2 == 0.0f && f == 0.0f) {
 | |
|             z = false;
 | |
|         }
 | |
|         this.mContinue = z;
 | |
|         return calcWave;
 | |
|     }
 | |
| 
 | |
|     public static ViewTimeCycle makeCustomSpline(String str, SparseArray<ConstraintAttribute> attrList) {
 | |
|         return new CustomSet(str, attrList);
 | |
|     }
 | |
| 
 | |
|     public static ViewTimeCycle makeSpline(String str, long currentTime) {
 | |
|         ViewTimeCycle rotationXset;
 | |
|         str.hashCode();
 | |
|         switch (str) {
 | |
|             case "rotationX":
 | |
|                 rotationXset = new RotationXset();
 | |
|                 break;
 | |
|             case "rotationY":
 | |
|                 rotationXset = new RotationYset();
 | |
|                 break;
 | |
|             case "translationX":
 | |
|                 rotationXset = new TranslationXset();
 | |
|                 break;
 | |
|             case "translationY":
 | |
|                 rotationXset = new TranslationYset();
 | |
|                 break;
 | |
|             case "translationZ":
 | |
|                 rotationXset = new TranslationZset();
 | |
|                 break;
 | |
|             case "progress":
 | |
|                 rotationXset = new ProgressSet();
 | |
|                 break;
 | |
|             case "scaleX":
 | |
|                 rotationXset = new ScaleXset();
 | |
|                 break;
 | |
|             case "scaleY":
 | |
|                 rotationXset = new ScaleYset();
 | |
|                 break;
 | |
|             case "rotation":
 | |
|                 rotationXset = new RotationSet();
 | |
|                 break;
 | |
|             case "elevation":
 | |
|                 rotationXset = new ElevationSet();
 | |
|                 break;
 | |
|             case "transitionPathRotate":
 | |
|                 rotationXset = new PathRotate();
 | |
|                 break;
 | |
|             case "alpha":
 | |
|                 rotationXset = new AlphaSet();
 | |
|                 break;
 | |
|             default:
 | |
|                 return null;
 | |
|         }
 | |
|         rotationXset.setStartTime(currentTime);
 | |
|         return rotationXset;
 | |
|     }
 | |
| 
 | |
|     static class ElevationSet extends ViewTimeCycle {
 | |
|         ElevationSet() {
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.constraintlayout.motion.utils.ViewTimeCycle
 | |
|         public boolean setProperty(View view, float t, long time, KeyCache cache) {
 | |
|             view.setElevation(get(t, time, view, cache));
 | |
|             return this.mContinue;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     static class AlphaSet extends ViewTimeCycle {
 | |
|         AlphaSet() {
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.constraintlayout.motion.utils.ViewTimeCycle
 | |
|         public boolean setProperty(View view, float t, long time, KeyCache cache) {
 | |
|             view.setAlpha(get(t, time, view, cache));
 | |
|             return this.mContinue;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     static class RotationSet extends ViewTimeCycle {
 | |
|         RotationSet() {
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.constraintlayout.motion.utils.ViewTimeCycle
 | |
|         public boolean setProperty(View view, float t, long time, KeyCache cache) {
 | |
|             view.setRotation(get(t, time, view, cache));
 | |
|             return this.mContinue;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     static class RotationXset extends ViewTimeCycle {
 | |
|         RotationXset() {
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.constraintlayout.motion.utils.ViewTimeCycle
 | |
|         public boolean setProperty(View view, float t, long time, KeyCache cache) {
 | |
|             view.setRotationX(get(t, time, view, cache));
 | |
|             return this.mContinue;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     static class RotationYset extends ViewTimeCycle {
 | |
|         RotationYset() {
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.constraintlayout.motion.utils.ViewTimeCycle
 | |
|         public boolean setProperty(View view, float t, long time, KeyCache cache) {
 | |
|             view.setRotationY(get(t, time, view, cache));
 | |
|             return this.mContinue;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public static class PathRotate extends ViewTimeCycle {
 | |
|         @Override // androidx.constraintlayout.motion.utils.ViewTimeCycle
 | |
|         public boolean setProperty(View view, float t, long time, KeyCache cache) {
 | |
|             return this.mContinue;
 | |
|         }
 | |
| 
 | |
|         public boolean setPathRotate(View view, KeyCache cache, float t, long time, double dx, double dy) {
 | |
|             view.setRotation(get(t, time, view, cache) + ((float) Math.toDegrees(Math.atan2(dy, dx))));
 | |
|             return this.mContinue;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     static class ScaleXset extends ViewTimeCycle {
 | |
|         ScaleXset() {
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.constraintlayout.motion.utils.ViewTimeCycle
 | |
|         public boolean setProperty(View view, float t, long time, KeyCache cache) {
 | |
|             view.setScaleX(get(t, time, view, cache));
 | |
|             return this.mContinue;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     static class ScaleYset extends ViewTimeCycle {
 | |
|         ScaleYset() {
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.constraintlayout.motion.utils.ViewTimeCycle
 | |
|         public boolean setProperty(View view, float t, long time, KeyCache cache) {
 | |
|             view.setScaleY(get(t, time, view, cache));
 | |
|             return this.mContinue;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     static class TranslationXset extends ViewTimeCycle {
 | |
|         TranslationXset() {
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.constraintlayout.motion.utils.ViewTimeCycle
 | |
|         public boolean setProperty(View view, float t, long time, KeyCache cache) {
 | |
|             view.setTranslationX(get(t, time, view, cache));
 | |
|             return this.mContinue;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     static class TranslationYset extends ViewTimeCycle {
 | |
|         TranslationYset() {
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.constraintlayout.motion.utils.ViewTimeCycle
 | |
|         public boolean setProperty(View view, float t, long time, KeyCache cache) {
 | |
|             view.setTranslationY(get(t, time, view, cache));
 | |
|             return this.mContinue;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     static class TranslationZset extends ViewTimeCycle {
 | |
|         TranslationZset() {
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.constraintlayout.motion.utils.ViewTimeCycle
 | |
|         public boolean setProperty(View view, float t, long time, KeyCache cache) {
 | |
|             view.setTranslationZ(get(t, time, view, cache));
 | |
|             return this.mContinue;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public static class CustomSet extends ViewTimeCycle {
 | |
|         String mAttributeName;
 | |
|         float[] mCache;
 | |
|         SparseArray<ConstraintAttribute> mConstraintAttributeList;
 | |
|         float[] mTempValues;
 | |
|         SparseArray<float[]> mWaveProperties = new SparseArray<>();
 | |
| 
 | |
|         public CustomSet(String attribute, SparseArray<ConstraintAttribute> attrList) {
 | |
|             this.mAttributeName = attribute.split(",")[1];
 | |
|             this.mConstraintAttributeList = attrList;
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.constraintlayout.core.motion.utils.TimeCycleSplineSet
 | |
|         public void setup(int curveType) {
 | |
|             int size = this.mConstraintAttributeList.size();
 | |
|             int numberOfInterpolatedValues = this.mConstraintAttributeList.valueAt(0).numberOfInterpolatedValues();
 | |
|             double[] dArr = new double[size];
 | |
|             int i = numberOfInterpolatedValues + 2;
 | |
|             this.mTempValues = new float[i];
 | |
|             this.mCache = new float[numberOfInterpolatedValues];
 | |
|             double[][] dArr2 = (double[][]) Array.newInstance((Class<?>) Double.TYPE, size, i);
 | |
|             for (int i2 = 0; i2 < size; i2++) {
 | |
|                 int keyAt = this.mConstraintAttributeList.keyAt(i2);
 | |
|                 ConstraintAttribute valueAt = this.mConstraintAttributeList.valueAt(i2);
 | |
|                 float[] valueAt2 = this.mWaveProperties.valueAt(i2);
 | |
|                 dArr[i2] = keyAt * 0.01d;
 | |
|                 valueAt.getValuesToInterpolate(this.mTempValues);
 | |
|                 int i3 = 0;
 | |
|                 while (true) {
 | |
|                     if (i3 < this.mTempValues.length) {
 | |
|                         dArr2[i2][i3] = r7[i3];
 | |
|                         i3++;
 | |
|                     }
 | |
|                 }
 | |
|                 double[] dArr3 = dArr2[i2];
 | |
|                 dArr3[numberOfInterpolatedValues] = valueAt2[0];
 | |
|                 dArr3[numberOfInterpolatedValues + 1] = valueAt2[1];
 | |
|             }
 | |
|             this.mCurveFit = CurveFit.get(curveType, dArr, dArr2);
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.constraintlayout.core.motion.utils.TimeCycleSplineSet
 | |
|         public void setPoint(int position, float value, float period, int shape, float offset) {
 | |
|             throw new RuntimeException("don't call for custom attribute call setPoint(pos, ConstraintAttribute,...)");
 | |
|         }
 | |
| 
 | |
|         public void setPoint(int position, ConstraintAttribute value, float period, int shape, float offset) {
 | |
|             this.mConstraintAttributeList.append(position, value);
 | |
|             this.mWaveProperties.append(position, new float[]{period, offset});
 | |
|             this.mWaveShape = Math.max(this.mWaveShape, shape);
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.constraintlayout.motion.utils.ViewTimeCycle
 | |
|         public boolean setProperty(View view, float t, long time, KeyCache cache) {
 | |
|             this.mCurveFit.getPos(t, this.mTempValues);
 | |
|             float[] fArr = this.mTempValues;
 | |
|             float f = fArr[fArr.length - 2];
 | |
|             float f2 = fArr[fArr.length - 1];
 | |
|             long j = time - this.last_time;
 | |
|             if (Float.isNaN(this.last_cycle)) {
 | |
|                 this.last_cycle = cache.getFloatValue(view, this.mAttributeName, 0);
 | |
|                 if (Float.isNaN(this.last_cycle)) {
 | |
|                     this.last_cycle = 0.0f;
 | |
|                 }
 | |
|             }
 | |
|             this.last_cycle = (float) ((this.last_cycle + ((j * 1.0E-9d) * f)) % 1.0d);
 | |
|             this.last_time = time;
 | |
|             float calcWave = calcWave(this.last_cycle);
 | |
|             this.mContinue = false;
 | |
|             for (int i = 0; i < this.mCache.length; i++) {
 | |
|                 this.mContinue |= ((double) this.mTempValues[i]) != 0.0d;
 | |
|                 this.mCache[i] = (this.mTempValues[i] * calcWave) + f2;
 | |
|             }
 | |
|             CustomSupport.setInterpolatedValue(this.mConstraintAttributeList.valueAt(0), view, this.mCache);
 | |
|             if (f != 0.0f) {
 | |
|                 this.mContinue = true;
 | |
|             }
 | |
|             return this.mContinue;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     static class ProgressSet extends ViewTimeCycle {
 | |
|         boolean mNoMethod = false;
 | |
| 
 | |
|         ProgressSet() {
 | |
|         }
 | |
| 
 | |
|         @Override // androidx.constraintlayout.motion.utils.ViewTimeCycle
 | |
|         public boolean setProperty(View view, float t, long time, KeyCache cache) {
 | |
|             Method method;
 | |
|             if (view instanceof MotionLayout) {
 | |
|                 ((MotionLayout) view).setProgress(get(t, time, view, cache));
 | |
|             } else {
 | |
|                 if (this.mNoMethod) {
 | |
|                     return false;
 | |
|                 }
 | |
|                 try {
 | |
|                     method = view.getClass().getMethod("setProgress", Float.TYPE);
 | |
|                 } catch (NoSuchMethodException unused) {
 | |
|                     this.mNoMethod = true;
 | |
|                     method = null;
 | |
|                 }
 | |
|                 Method method2 = method;
 | |
|                 if (method2 != null) {
 | |
|                     try {
 | |
|                         method2.invoke(view, Float.valueOf(get(t, time, view, cache)));
 | |
|                     } catch (IllegalAccessException e) {
 | |
|                         Log.e(ViewTimeCycle.TAG, "unable to setProgress", e);
 | |
|                     } catch (InvocationTargetException e2) {
 | |
|                         Log.e(ViewTimeCycle.TAG, "unable to setProgress", e2);
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|             return this.mContinue;
 | |
|         }
 | |
|     }
 | |
| }
 |