2021-06-27 20:44:35 +00:00
|
|
|
package androidx.constraintlayout.motion.utils;
|
|
|
|
|
|
|
|
import android.util.Log;
|
2021-12-21 23:37:30 +00:00
|
|
|
import b.d.b.a.a;
|
2021-10-13 22:40:49 +00:00
|
|
|
import com.discord.analytics.utils.RegistrationSteps;
|
2021-08-09 22:50:01 +00:00
|
|
|
import com.google.android.material.shadow.ShadowDrawableWrapper;
|
2021-06-27 20:44:35 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
public class Easing {
|
|
|
|
private static final String ACCELERATE = "cubic(0.4, 0.05, 0.8, 0.7)";
|
|
|
|
private static final String ACCELERATE_NAME = "accelerate";
|
|
|
|
private static final String DECELERATE = "cubic(0.0, 0.0, 0.2, 0.95)";
|
|
|
|
private static final String DECELERATE_NAME = "decelerate";
|
|
|
|
private static final String LINEAR = "cubic(1, 1, 0, 0)";
|
|
|
|
private static final String LINEAR_NAME = "linear";
|
|
|
|
public static String[] NAMED_EASING = null;
|
|
|
|
private static final String STANDARD = "cubic(0.4, 0.0, 0.2, 1)";
|
|
|
|
private static final String STANDARD_NAME = "standard";
|
|
|
|
public static Easing sDefault = new Easing();
|
2021-10-13 22:40:49 +00:00
|
|
|
public String str = RegistrationSteps.IDENTITY;
|
2021-06-27 20:44:35 +00:00
|
|
|
|
|
|
|
public static class CubicEasing extends Easing {
|
|
|
|
private static double d_error = 1.0E-4d;
|
|
|
|
private static double error = 0.01d;
|
|
|
|
public double x1;
|
|
|
|
public double x2;
|
|
|
|
public double y1;
|
|
|
|
public double y2;
|
|
|
|
|
|
|
|
public CubicEasing(double d, double d2, double d3, double d4) {
|
|
|
|
setup(d, d2, d3, d4);
|
|
|
|
}
|
|
|
|
|
|
|
|
public CubicEasing(String str) {
|
|
|
|
this.str = str;
|
|
|
|
int indexOf = str.indexOf(40);
|
|
|
|
int indexOf2 = str.indexOf(44, indexOf);
|
|
|
|
this.x1 = Double.parseDouble(str.substring(indexOf + 1, indexOf2).trim());
|
|
|
|
int i = indexOf2 + 1;
|
|
|
|
int indexOf3 = str.indexOf(44, i);
|
|
|
|
this.y1 = Double.parseDouble(str.substring(i, indexOf3).trim());
|
|
|
|
int i2 = indexOf3 + 1;
|
|
|
|
int indexOf4 = str.indexOf(44, i2);
|
|
|
|
this.x2 = Double.parseDouble(str.substring(i2, indexOf4).trim());
|
|
|
|
int i3 = indexOf4 + 1;
|
|
|
|
this.y2 = Double.parseDouble(str.substring(i3, str.indexOf(41, i3)).trim());
|
|
|
|
}
|
|
|
|
|
|
|
|
private double getDiffX(double d) {
|
|
|
|
double d2 = 1.0d - d;
|
|
|
|
double d3 = this.x1;
|
|
|
|
double d4 = d2 * 3.0d * d2 * d3;
|
|
|
|
double d5 = this.x2;
|
|
|
|
return ((1.0d - d5) * 3.0d * d * d) + ((d5 - d3) * d2 * 6.0d * d) + d4;
|
|
|
|
}
|
|
|
|
|
|
|
|
private double getDiffY(double d) {
|
|
|
|
double d2 = 1.0d - d;
|
|
|
|
double d3 = this.y1;
|
|
|
|
double d4 = d2 * 3.0d * d2 * d3;
|
|
|
|
double d5 = this.y2;
|
|
|
|
return ((1.0d - d5) * 3.0d * d * d) + ((d5 - d3) * d2 * 6.0d * d) + d4;
|
|
|
|
}
|
|
|
|
|
|
|
|
private double getX(double d) {
|
|
|
|
double d2 = 1.0d - d;
|
|
|
|
double d3 = 3.0d * d2;
|
|
|
|
double d4 = d2 * d3 * d;
|
|
|
|
double d5 = d3 * d * d;
|
|
|
|
return (this.x2 * d5) + (this.x1 * d4) + (d * d * d);
|
|
|
|
}
|
|
|
|
|
|
|
|
private double getY(double d) {
|
|
|
|
double d2 = 1.0d - d;
|
|
|
|
double d3 = 3.0d * d2;
|
|
|
|
double d4 = d2 * d3 * d;
|
|
|
|
double d5 = d3 * d * d;
|
|
|
|
return (this.y2 * d5) + (this.y1 * d4) + (d * d * d);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // androidx.constraintlayout.motion.utils.Easing
|
|
|
|
public double get(double d) {
|
2021-08-09 22:50:01 +00:00
|
|
|
if (d <= ShadowDrawableWrapper.COS_45) {
|
|
|
|
return ShadowDrawableWrapper.COS_45;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
if (d >= 1.0d) {
|
|
|
|
return 1.0d;
|
|
|
|
}
|
|
|
|
double d2 = 0.5d;
|
|
|
|
double d3 = 0.5d;
|
|
|
|
while (d2 > error) {
|
|
|
|
d2 *= 0.5d;
|
|
|
|
d3 = getX(d3) < d ? d3 + d2 : d3 - d2;
|
|
|
|
}
|
|
|
|
double d4 = d3 - d2;
|
|
|
|
double x2 = getX(d4);
|
|
|
|
double d5 = d3 + d2;
|
|
|
|
double x3 = getX(d5);
|
|
|
|
double y2 = getY(d4);
|
|
|
|
return (((d - x2) * (getY(d5) - y2)) / (x3 - x2)) + y2;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // androidx.constraintlayout.motion.utils.Easing
|
|
|
|
public double getDiff(double d) {
|
|
|
|
double d2 = 0.5d;
|
|
|
|
double d3 = 0.5d;
|
|
|
|
while (d2 > d_error) {
|
|
|
|
d2 *= 0.5d;
|
|
|
|
d3 = getX(d3) < d ? d3 + d2 : d3 - d2;
|
|
|
|
}
|
|
|
|
double d4 = d3 - d2;
|
|
|
|
double d5 = d3 + d2;
|
|
|
|
return (getY(d5) - getY(d4)) / (getX(d5) - getX(d4));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setup(double d, double d2, double d3, double d4) {
|
|
|
|
this.x1 = d;
|
|
|
|
this.y1 = d2;
|
|
|
|
this.x2 = d3;
|
|
|
|
this.y2 = d4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static {
|
2021-08-09 22:50:01 +00:00
|
|
|
NAMED_EASING = new String[]{STANDARD_NAME, ACCELERATE_NAME, DECELERATE_NAME, LINEAR_NAME};
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Easing getInterpolator(String str) {
|
|
|
|
if (str == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (str.startsWith("cubic")) {
|
|
|
|
return new CubicEasing(str);
|
|
|
|
}
|
|
|
|
str.hashCode();
|
2021-12-21 23:37:30 +00:00
|
|
|
char c = 65535;
|
2021-06-27 20:44:35 +00:00
|
|
|
switch (str.hashCode()) {
|
|
|
|
case -1354466595:
|
2021-08-09 22:50:01 +00:00
|
|
|
if (str.equals(ACCELERATE_NAME)) {
|
2021-12-21 23:37:30 +00:00
|
|
|
c = 0;
|
2021-06-27 20:44:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case -1263948740:
|
2021-08-09 22:50:01 +00:00
|
|
|
if (str.equals(DECELERATE_NAME)) {
|
2021-12-21 23:37:30 +00:00
|
|
|
c = 1;
|
2021-06-27 20:44:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case -1102672091:
|
2021-08-09 22:50:01 +00:00
|
|
|
if (str.equals(LINEAR_NAME)) {
|
2021-12-21 23:37:30 +00:00
|
|
|
c = 2;
|
2021-06-27 20:44:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1312628413:
|
2021-08-09 22:50:01 +00:00
|
|
|
if (str.equals(STANDARD_NAME)) {
|
2021-12-21 23:37:30 +00:00
|
|
|
c = 3;
|
2021-06-27 20:44:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-12-21 23:37:30 +00:00
|
|
|
switch (c) {
|
2021-06-27 20:44:35 +00:00
|
|
|
case 0:
|
2021-08-09 22:50:01 +00:00
|
|
|
return new CubicEasing(ACCELERATE);
|
2021-06-27 20:44:35 +00:00
|
|
|
case 1:
|
2021-08-09 22:50:01 +00:00
|
|
|
return new CubicEasing(DECELERATE);
|
2021-06-27 20:44:35 +00:00
|
|
|
case 2:
|
2021-08-09 22:50:01 +00:00
|
|
|
return new CubicEasing(LINEAR);
|
2021-06-27 20:44:35 +00:00
|
|
|
case 3:
|
2021-08-09 22:50:01 +00:00
|
|
|
return new CubicEasing(STANDARD);
|
2021-06-27 20:44:35 +00:00
|
|
|
default:
|
2021-11-08 18:25:28 +00:00
|
|
|
StringBuilder R = a.R("transitionEasing syntax error syntax:transitionEasing=\"cubic(1.0,0.5,0.0,0.6)\" or ");
|
|
|
|
R.append(Arrays.toString(NAMED_EASING));
|
|
|
|
Log.e("ConstraintSet", R.toString());
|
2021-06-27 20:44:35 +00:00
|
|
|
return sDefault;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public double get(double d) {
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getDiff(double d) {
|
|
|
|
return 1.0d;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String toString() {
|
|
|
|
return this.str;
|
|
|
|
}
|
|
|
|
}
|