76 lines
4 KiB
Java
76 lines
4 KiB
Java
package androidx.vectordrawable.graphics.drawable;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.Resources;
|
|
import android.util.AttributeSet;
|
|
import android.util.Xml;
|
|
import android.view.animation.AccelerateDecelerateInterpolator;
|
|
import android.view.animation.AccelerateInterpolator;
|
|
import android.view.animation.AnimationUtils;
|
|
import android.view.animation.AnticipateInterpolator;
|
|
import android.view.animation.AnticipateOvershootInterpolator;
|
|
import android.view.animation.BounceInterpolator;
|
|
import android.view.animation.CycleInterpolator;
|
|
import android.view.animation.DecelerateInterpolator;
|
|
import android.view.animation.Interpolator;
|
|
import android.view.animation.LinearInterpolator;
|
|
import android.view.animation.OvershootInterpolator;
|
|
import androidx.annotation.RestrictTo;
|
|
import b.d.b.a.a;
|
|
import java.io.IOException;
|
|
import org.xmlpull.v1.XmlPullParser;
|
|
import org.xmlpull.v1.XmlPullParserException;
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public class AnimationUtilsCompat {
|
|
private AnimationUtilsCompat() {
|
|
}
|
|
|
|
private static Interpolator createInterpolatorFromXml(Context context, Resources resources, Resources.Theme theme, XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
|
|
Interpolator accelerateInterpolator;
|
|
int depth = xmlPullParser.getDepth();
|
|
Interpolator interpolator = null;
|
|
while (true) {
|
|
int next = xmlPullParser.next();
|
|
if ((next != 3 || xmlPullParser.getDepth() > depth) && next != 1) {
|
|
if (next == 2) {
|
|
AttributeSet asAttributeSet = Xml.asAttributeSet(xmlPullParser);
|
|
String name = xmlPullParser.getName();
|
|
if (name.equals("linearInterpolator")) {
|
|
interpolator = new LinearInterpolator();
|
|
} else {
|
|
if (name.equals("accelerateInterpolator")) {
|
|
accelerateInterpolator = new AccelerateInterpolator(context, asAttributeSet);
|
|
} else if (name.equals("decelerateInterpolator")) {
|
|
accelerateInterpolator = new DecelerateInterpolator(context, asAttributeSet);
|
|
} else if (name.equals("accelerateDecelerateInterpolator")) {
|
|
interpolator = new AccelerateDecelerateInterpolator();
|
|
} else if (name.equals("cycleInterpolator")) {
|
|
accelerateInterpolator = new CycleInterpolator(context, asAttributeSet);
|
|
} else if (name.equals("anticipateInterpolator")) {
|
|
accelerateInterpolator = new AnticipateInterpolator(context, asAttributeSet);
|
|
} else if (name.equals("overshootInterpolator")) {
|
|
accelerateInterpolator = new OvershootInterpolator(context, asAttributeSet);
|
|
} else if (name.equals("anticipateOvershootInterpolator")) {
|
|
accelerateInterpolator = new AnticipateOvershootInterpolator(context, asAttributeSet);
|
|
} else if (name.equals("bounceInterpolator")) {
|
|
interpolator = new BounceInterpolator();
|
|
} else if (name.equals("pathInterpolator")) {
|
|
accelerateInterpolator = new PathInterpolatorCompat(context, asAttributeSet, xmlPullParser);
|
|
} else {
|
|
StringBuilder R = a.R("Unknown interpolator name: ");
|
|
R.append(xmlPullParser.getName());
|
|
throw new RuntimeException(R.toString());
|
|
}
|
|
interpolator = accelerateInterpolator;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return interpolator;
|
|
}
|
|
|
|
public static Interpolator loadInterpolator(Context context, int i) throws Resources.NotFoundException {
|
|
return AnimationUtils.loadInterpolator(context, i);
|
|
}
|
|
}
|