542 lines
27 KiB
Java
542 lines
27 KiB
Java
package androidx.vectordrawable.graphics.drawable;
|
|
|
|
import android.animation.Animator;
|
|
import android.animation.AnimatorInflater;
|
|
import android.animation.AnimatorSet;
|
|
import android.animation.Keyframe;
|
|
import android.animation.ObjectAnimator;
|
|
import android.animation.PropertyValuesHolder;
|
|
import android.animation.TypeEvaluator;
|
|
import android.animation.ValueAnimator;
|
|
import android.content.Context;
|
|
import android.content.res.Resources;
|
|
import android.content.res.TypedArray;
|
|
import android.content.res.XmlResourceParser;
|
|
import android.graphics.Path;
|
|
import android.graphics.PathMeasure;
|
|
import android.os.Build;
|
|
import android.util.AttributeSet;
|
|
import android.util.Log;
|
|
import android.util.TypedValue;
|
|
import android.util.Xml;
|
|
import android.view.InflateException;
|
|
import androidx.annotation.AnimatorRes;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.core.content.res.TypedArrayUtils;
|
|
import androidx.core.graphics.PathParser;
|
|
import c.d.b.a.a;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import org.xmlpull.v1.XmlPullParser;
|
|
import org.xmlpull.v1.XmlPullParserException;
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public class AnimatorInflaterCompat {
|
|
private static final boolean DBG_ANIMATOR_INFLATER = false;
|
|
private static final int MAX_NUM_POINTS = 100;
|
|
private static final String TAG = "AnimatorInflater";
|
|
private static final int TOGETHER = 0;
|
|
private static final int VALUE_TYPE_COLOR = 3;
|
|
private static final int VALUE_TYPE_FLOAT = 0;
|
|
private static final int VALUE_TYPE_INT = 1;
|
|
private static final int VALUE_TYPE_PATH = 2;
|
|
private static final int VALUE_TYPE_UNDEFINED = 4;
|
|
|
|
public static class PathDataEvaluator implements TypeEvaluator<PathParser.PathDataNode[]> {
|
|
private PathParser.PathDataNode[] mNodeArray;
|
|
|
|
public PathDataEvaluator() {
|
|
}
|
|
|
|
public PathDataEvaluator(PathParser.PathDataNode[] pathDataNodeArr) {
|
|
this.mNodeArray = pathDataNodeArr;
|
|
}
|
|
|
|
public PathParser.PathDataNode[] evaluate(float f, PathParser.PathDataNode[] pathDataNodeArr, PathParser.PathDataNode[] pathDataNodeArr2) {
|
|
if (PathParser.canMorph(pathDataNodeArr, pathDataNodeArr2)) {
|
|
if (!PathParser.canMorph(this.mNodeArray, pathDataNodeArr)) {
|
|
this.mNodeArray = PathParser.deepCopyNodes(pathDataNodeArr);
|
|
}
|
|
for (int i = 0; i < pathDataNodeArr.length; i++) {
|
|
this.mNodeArray[i].interpolatePathDataNode(pathDataNodeArr[i], pathDataNodeArr2[i], f);
|
|
}
|
|
return this.mNodeArray;
|
|
}
|
|
throw new IllegalArgumentException("Can't interpolate between two incompatible pathData");
|
|
}
|
|
}
|
|
|
|
private AnimatorInflaterCompat() {
|
|
}
|
|
|
|
private static Animator createAnimatorFromXml(Context context, Resources resources, Resources.Theme theme, XmlPullParser xmlPullParser, float f) throws XmlPullParserException, IOException {
|
|
return createAnimatorFromXml(context, resources, theme, xmlPullParser, Xml.asAttributeSet(xmlPullParser), null, 0, f);
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r15v0, resolved type: android.animation.AnimatorSet */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
/* JADX WARNING: Removed duplicated region for block: B:30:0x00bb */
|
|
private static Animator createAnimatorFromXml(Context context, Resources resources, Resources.Theme theme, XmlPullParser xmlPullParser, AttributeSet attributeSet, AnimatorSet animatorSet, int i, float f) throws XmlPullParserException, IOException {
|
|
int i2;
|
|
int depth = xmlPullParser.getDepth();
|
|
ValueAnimator valueAnimator = null;
|
|
ArrayList arrayList = null;
|
|
while (true) {
|
|
int next = xmlPullParser.next();
|
|
i2 = 0;
|
|
if ((next != 3 || xmlPullParser.getDepth() > depth) && next != 1) {
|
|
if (next == 2) {
|
|
String name = xmlPullParser.getName();
|
|
if (name.equals("objectAnimator")) {
|
|
valueAnimator = loadObjectAnimator(context, resources, theme, attributeSet, f, xmlPullParser);
|
|
} else if (name.equals("animator")) {
|
|
valueAnimator = loadAnimator(context, resources, theme, attributeSet, null, f, xmlPullParser);
|
|
} else {
|
|
if (name.equals("set")) {
|
|
AnimatorSet animatorSet2 = new AnimatorSet();
|
|
TypedArray obtainAttributes = TypedArrayUtils.obtainAttributes(resources, theme, attributeSet, AndroidResources.STYLEABLE_ANIMATOR_SET);
|
|
createAnimatorFromXml(context, resources, theme, xmlPullParser, attributeSet, animatorSet2, TypedArrayUtils.getNamedInt(obtainAttributes, xmlPullParser, "ordering", 0, 0), f);
|
|
obtainAttributes.recycle();
|
|
valueAnimator = animatorSet2;
|
|
} else if (name.equals("propertyValuesHolder")) {
|
|
PropertyValuesHolder[] loadValues = loadValues(context, resources, theme, xmlPullParser, Xml.asAttributeSet(xmlPullParser));
|
|
if (loadValues != null && (valueAnimator instanceof ValueAnimator)) {
|
|
valueAnimator.setValues(loadValues);
|
|
}
|
|
i2 = 1;
|
|
} else {
|
|
StringBuilder K = a.K("Unknown animator name: ");
|
|
K.append(xmlPullParser.getName());
|
|
throw new RuntimeException(K.toString());
|
|
}
|
|
if (animatorSet != null && i2 == 0) {
|
|
if (arrayList == null) {
|
|
arrayList = new ArrayList();
|
|
}
|
|
arrayList.add(valueAnimator);
|
|
}
|
|
}
|
|
if (arrayList == null) {
|
|
}
|
|
arrayList.add(valueAnimator);
|
|
}
|
|
}
|
|
}
|
|
if (!(animatorSet == null || arrayList == null)) {
|
|
Animator[] animatorArr = new Animator[arrayList.size()];
|
|
Iterator it = arrayList.iterator();
|
|
while (it.hasNext()) {
|
|
animatorArr[i2] = (Animator) it.next();
|
|
i2++;
|
|
}
|
|
if (i == 0) {
|
|
animatorSet.playTogether(animatorArr);
|
|
} else {
|
|
animatorSet.playSequentially(animatorArr);
|
|
}
|
|
}
|
|
return valueAnimator;
|
|
}
|
|
|
|
private static Keyframe createNewKeyframe(Keyframe keyframe, float f) {
|
|
return keyframe.getType() == Float.TYPE ? Keyframe.ofFloat(f) : keyframe.getType() == Integer.TYPE ? Keyframe.ofInt(f) : Keyframe.ofObject(f);
|
|
}
|
|
|
|
private static void distributeKeyframes(Keyframe[] keyframeArr, float f, int i, int i2) {
|
|
float f2 = f / ((float) ((i2 - i) + 2));
|
|
while (i <= i2) {
|
|
keyframeArr[i].setFraction(keyframeArr[i - 1].getFraction() + f2);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
private static void dumpKeyframes(Object[] objArr, String str) {
|
|
if (!(objArr == null || objArr.length == 0)) {
|
|
Log.d("AnimatorInflater", str);
|
|
int length = objArr.length;
|
|
for (int i = 0; i < length; i++) {
|
|
Keyframe keyframe = (Keyframe) objArr[i];
|
|
StringBuilder L = a.L("Keyframe ", i, ": fraction ");
|
|
Object obj = "null";
|
|
L.append(keyframe.getFraction() < 0.0f ? obj : Float.valueOf(keyframe.getFraction()));
|
|
L.append(", , value : ");
|
|
if (keyframe.hasValue()) {
|
|
obj = keyframe.getValue();
|
|
}
|
|
L.append(obj);
|
|
Log.d("AnimatorInflater", L.toString());
|
|
}
|
|
}
|
|
}
|
|
|
|
private static PropertyValuesHolder getPVH(TypedArray typedArray, int i, int i2, int i3, String str) {
|
|
PropertyValuesHolder propertyValuesHolder;
|
|
PropertyValuesHolder propertyValuesHolder2;
|
|
TypedValue peekValue = typedArray.peekValue(i2);
|
|
boolean z2 = peekValue != null;
|
|
int i4 = z2 ? peekValue.type : 0;
|
|
TypedValue peekValue2 = typedArray.peekValue(i3);
|
|
boolean z3 = peekValue2 != null;
|
|
int i5 = z3 ? peekValue2.type : 0;
|
|
if (i == 4) {
|
|
i = ((!z2 || !isColorType(i4)) && (!z3 || !isColorType(i5))) ? 0 : 3;
|
|
}
|
|
boolean z4 = i == 0;
|
|
PropertyValuesHolder propertyValuesHolder3 = null;
|
|
if (i == 2) {
|
|
String string = typedArray.getString(i2);
|
|
String string2 = typedArray.getString(i3);
|
|
PathParser.PathDataNode[] createNodesFromPathData = PathParser.createNodesFromPathData(string);
|
|
PathParser.PathDataNode[] createNodesFromPathData2 = PathParser.createNodesFromPathData(string2);
|
|
if (createNodesFromPathData == null && createNodesFromPathData2 == null) {
|
|
return null;
|
|
}
|
|
if (createNodesFromPathData != null) {
|
|
PathDataEvaluator pathDataEvaluator = new PathDataEvaluator();
|
|
if (createNodesFromPathData2 == null) {
|
|
propertyValuesHolder2 = PropertyValuesHolder.ofObject(str, pathDataEvaluator, createNodesFromPathData);
|
|
} else if (PathParser.canMorph(createNodesFromPathData, createNodesFromPathData2)) {
|
|
propertyValuesHolder2 = PropertyValuesHolder.ofObject(str, pathDataEvaluator, createNodesFromPathData, createNodesFromPathData2);
|
|
} else {
|
|
throw new InflateException(" Can't morph from " + string + " to " + string2);
|
|
}
|
|
return propertyValuesHolder2;
|
|
} else if (createNodesFromPathData2 != null) {
|
|
return PropertyValuesHolder.ofObject(str, new PathDataEvaluator(), createNodesFromPathData2);
|
|
} else {
|
|
return null;
|
|
}
|
|
} else {
|
|
ArgbEvaluator instance = i == 3 ? ArgbEvaluator.getInstance() : null;
|
|
if (z4) {
|
|
if (z2) {
|
|
float dimension = i4 == 5 ? typedArray.getDimension(i2, 0.0f) : typedArray.getFloat(i2, 0.0f);
|
|
if (z3) {
|
|
propertyValuesHolder = PropertyValuesHolder.ofFloat(str, dimension, i5 == 5 ? typedArray.getDimension(i3, 0.0f) : typedArray.getFloat(i3, 0.0f));
|
|
} else {
|
|
propertyValuesHolder = PropertyValuesHolder.ofFloat(str, dimension);
|
|
}
|
|
} else {
|
|
propertyValuesHolder = PropertyValuesHolder.ofFloat(str, i5 == 5 ? typedArray.getDimension(i3, 0.0f) : typedArray.getFloat(i3, 0.0f));
|
|
}
|
|
propertyValuesHolder3 = propertyValuesHolder;
|
|
} else if (z2) {
|
|
int dimension2 = i4 == 5 ? (int) typedArray.getDimension(i2, 0.0f) : isColorType(i4) ? typedArray.getColor(i2, 0) : typedArray.getInt(i2, 0);
|
|
if (z3) {
|
|
propertyValuesHolder3 = PropertyValuesHolder.ofInt(str, dimension2, i5 == 5 ? (int) typedArray.getDimension(i3, 0.0f) : isColorType(i5) ? typedArray.getColor(i3, 0) : typedArray.getInt(i3, 0));
|
|
} else {
|
|
propertyValuesHolder3 = PropertyValuesHolder.ofInt(str, dimension2);
|
|
}
|
|
} else if (z3) {
|
|
propertyValuesHolder3 = PropertyValuesHolder.ofInt(str, i5 == 5 ? (int) typedArray.getDimension(i3, 0.0f) : isColorType(i5) ? typedArray.getColor(i3, 0) : typedArray.getInt(i3, 0));
|
|
}
|
|
if (propertyValuesHolder3 == null || instance == null) {
|
|
return propertyValuesHolder3;
|
|
}
|
|
propertyValuesHolder3.setEvaluator(instance);
|
|
return propertyValuesHolder3;
|
|
}
|
|
}
|
|
|
|
private static int inferValueTypeFromValues(TypedArray typedArray, int i, int i2) {
|
|
TypedValue peekValue = typedArray.peekValue(i);
|
|
boolean z2 = true;
|
|
boolean z3 = peekValue != null;
|
|
int i3 = z3 ? peekValue.type : 0;
|
|
TypedValue peekValue2 = typedArray.peekValue(i2);
|
|
if (peekValue2 == null) {
|
|
z2 = false;
|
|
}
|
|
return ((!z3 || !isColorType(i3)) && (!z2 || !isColorType(z2 ? peekValue2.type : 0))) ? 0 : 3;
|
|
}
|
|
|
|
private static int inferValueTypeOfKeyframe(Resources resources, Resources.Theme theme, AttributeSet attributeSet, XmlPullParser xmlPullParser) {
|
|
TypedArray obtainAttributes = TypedArrayUtils.obtainAttributes(resources, theme, attributeSet, AndroidResources.STYLEABLE_KEYFRAME);
|
|
int i = 0;
|
|
TypedValue peekNamedValue = TypedArrayUtils.peekNamedValue(obtainAttributes, xmlPullParser, "value", 0);
|
|
if ((peekNamedValue != null) && isColorType(peekNamedValue.type)) {
|
|
i = 3;
|
|
}
|
|
obtainAttributes.recycle();
|
|
return i;
|
|
}
|
|
|
|
private static boolean isColorType(int i) {
|
|
return i >= 28 && i <= 31;
|
|
}
|
|
|
|
public static Animator loadAnimator(Context context, @AnimatorRes int i) throws Resources.NotFoundException {
|
|
return Build.VERSION.SDK_INT >= 24 ? AnimatorInflater.loadAnimator(context, i) : loadAnimator(context, context.getResources(), context.getTheme(), i);
|
|
}
|
|
|
|
public static Animator loadAnimator(Context context, Resources resources, Resources.Theme theme, @AnimatorRes int i) throws Resources.NotFoundException {
|
|
return loadAnimator(context, resources, theme, i, 1.0f);
|
|
}
|
|
|
|
public static Animator loadAnimator(Context context, Resources resources, Resources.Theme theme, @AnimatorRes int i, float f) throws Resources.NotFoundException {
|
|
XmlResourceParser xmlResourceParser = null;
|
|
try {
|
|
xmlResourceParser = resources.getAnimation(i);
|
|
Animator createAnimatorFromXml = createAnimatorFromXml(context, resources, theme, xmlResourceParser, f);
|
|
if (xmlResourceParser != null) {
|
|
xmlResourceParser.close();
|
|
}
|
|
return createAnimatorFromXml;
|
|
} catch (XmlPullParserException e) {
|
|
Resources.NotFoundException notFoundException = new Resources.NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(i));
|
|
notFoundException.initCause(e);
|
|
throw notFoundException;
|
|
} catch (IOException e2) {
|
|
Resources.NotFoundException notFoundException2 = new Resources.NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(i));
|
|
notFoundException2.initCause(e2);
|
|
throw notFoundException2;
|
|
} catch (Throwable th) {
|
|
if (xmlResourceParser != null) {
|
|
xmlResourceParser.close();
|
|
}
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
private static ValueAnimator loadAnimator(Context context, Resources resources, Resources.Theme theme, AttributeSet attributeSet, ValueAnimator valueAnimator, float f, XmlPullParser xmlPullParser) throws Resources.NotFoundException {
|
|
TypedArray obtainAttributes = TypedArrayUtils.obtainAttributes(resources, theme, attributeSet, AndroidResources.STYLEABLE_ANIMATOR);
|
|
TypedArray obtainAttributes2 = TypedArrayUtils.obtainAttributes(resources, theme, attributeSet, AndroidResources.STYLEABLE_PROPERTY_ANIMATOR);
|
|
if (valueAnimator == null) {
|
|
valueAnimator = new ValueAnimator();
|
|
}
|
|
parseAnimatorFromTypeArray(valueAnimator, obtainAttributes, obtainAttributes2, f, xmlPullParser);
|
|
int namedResourceId = TypedArrayUtils.getNamedResourceId(obtainAttributes, xmlPullParser, "interpolator", 0, 0);
|
|
if (namedResourceId > 0) {
|
|
valueAnimator.setInterpolator(AnimationUtilsCompat.loadInterpolator(context, namedResourceId));
|
|
}
|
|
obtainAttributes.recycle();
|
|
if (obtainAttributes2 != null) {
|
|
obtainAttributes2.recycle();
|
|
}
|
|
return valueAnimator;
|
|
}
|
|
|
|
private static Keyframe loadKeyframe(Context context, Resources resources, Resources.Theme theme, AttributeSet attributeSet, int i, XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
|
|
TypedArray obtainAttributes = TypedArrayUtils.obtainAttributes(resources, theme, attributeSet, AndroidResources.STYLEABLE_KEYFRAME);
|
|
float namedFloat = TypedArrayUtils.getNamedFloat(obtainAttributes, xmlPullParser, "fraction", 3, -1.0f);
|
|
TypedValue peekNamedValue = TypedArrayUtils.peekNamedValue(obtainAttributes, xmlPullParser, "value", 0);
|
|
boolean z2 = peekNamedValue != null;
|
|
if (i == 4) {
|
|
i = (!z2 || !isColorType(peekNamedValue.type)) ? 0 : 3;
|
|
}
|
|
Keyframe ofInt = z2 ? i != 0 ? (i == 1 || i == 3) ? Keyframe.ofInt(namedFloat, TypedArrayUtils.getNamedInt(obtainAttributes, xmlPullParser, "value", 0, 0)) : null : Keyframe.ofFloat(namedFloat, TypedArrayUtils.getNamedFloat(obtainAttributes, xmlPullParser, "value", 0, 0.0f)) : i == 0 ? Keyframe.ofFloat(namedFloat) : Keyframe.ofInt(namedFloat);
|
|
int namedResourceId = TypedArrayUtils.getNamedResourceId(obtainAttributes, xmlPullParser, "interpolator", 1, 0);
|
|
if (namedResourceId > 0) {
|
|
ofInt.setInterpolator(AnimationUtilsCompat.loadInterpolator(context, namedResourceId));
|
|
}
|
|
obtainAttributes.recycle();
|
|
return ofInt;
|
|
}
|
|
|
|
private static ObjectAnimator loadObjectAnimator(Context context, Resources resources, Resources.Theme theme, AttributeSet attributeSet, float f, XmlPullParser xmlPullParser) throws Resources.NotFoundException {
|
|
ObjectAnimator objectAnimator = new ObjectAnimator();
|
|
loadAnimator(context, resources, theme, attributeSet, objectAnimator, f, xmlPullParser);
|
|
return objectAnimator;
|
|
}
|
|
|
|
private static PropertyValuesHolder loadPvh(Context context, Resources resources, Resources.Theme theme, XmlPullParser xmlPullParser, String str, int i) throws XmlPullParserException, IOException {
|
|
int size;
|
|
PropertyValuesHolder propertyValuesHolder = null;
|
|
ArrayList arrayList = null;
|
|
while (true) {
|
|
int next = xmlPullParser.next();
|
|
if (next == 3 || next == 1) {
|
|
break;
|
|
} else if (xmlPullParser.getName().equals("keyframe")) {
|
|
if (i == 4) {
|
|
i = inferValueTypeOfKeyframe(resources, theme, Xml.asAttributeSet(xmlPullParser), xmlPullParser);
|
|
}
|
|
Keyframe loadKeyframe = loadKeyframe(context, resources, theme, Xml.asAttributeSet(xmlPullParser), i, xmlPullParser);
|
|
if (loadKeyframe != null) {
|
|
if (arrayList == null) {
|
|
arrayList = new ArrayList();
|
|
}
|
|
arrayList.add(loadKeyframe);
|
|
}
|
|
xmlPullParser.next();
|
|
}
|
|
}
|
|
if (arrayList != null && (size = arrayList.size()) > 0) {
|
|
Keyframe keyframe = (Keyframe) arrayList.get(0);
|
|
Keyframe keyframe2 = (Keyframe) arrayList.get(size - 1);
|
|
float fraction = keyframe2.getFraction();
|
|
if (fraction < 1.0f) {
|
|
if (fraction < 0.0f) {
|
|
keyframe2.setFraction(1.0f);
|
|
} else {
|
|
arrayList.add(arrayList.size(), createNewKeyframe(keyframe2, 1.0f));
|
|
size++;
|
|
}
|
|
}
|
|
float fraction2 = keyframe.getFraction();
|
|
if (fraction2 != 0.0f) {
|
|
if (fraction2 < 0.0f) {
|
|
keyframe.setFraction(0.0f);
|
|
} else {
|
|
arrayList.add(0, createNewKeyframe(keyframe, 0.0f));
|
|
size++;
|
|
}
|
|
}
|
|
Keyframe[] keyframeArr = new Keyframe[size];
|
|
arrayList.toArray(keyframeArr);
|
|
for (int i2 = 0; i2 < size; i2++) {
|
|
Keyframe keyframe3 = keyframeArr[i2];
|
|
if (keyframe3.getFraction() < 0.0f) {
|
|
if (i2 == 0) {
|
|
keyframe3.setFraction(0.0f);
|
|
} else {
|
|
int i3 = size - 1;
|
|
if (i2 == i3) {
|
|
keyframe3.setFraction(1.0f);
|
|
} else {
|
|
int i4 = i2 + 1;
|
|
int i5 = i2;
|
|
while (i4 < i3 && keyframeArr[i4].getFraction() < 0.0f) {
|
|
i5 = i4;
|
|
i4++;
|
|
}
|
|
distributeKeyframes(keyframeArr, keyframeArr[i5 + 1].getFraction() - keyframeArr[i2 - 1].getFraction(), i2, i5);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
propertyValuesHolder = PropertyValuesHolder.ofKeyframe(str, keyframeArr);
|
|
if (i == 3) {
|
|
propertyValuesHolder.setEvaluator(ArgbEvaluator.getInstance());
|
|
}
|
|
}
|
|
return propertyValuesHolder;
|
|
}
|
|
|
|
private static PropertyValuesHolder[] loadValues(Context context, Resources resources, Resources.Theme theme, XmlPullParser xmlPullParser, AttributeSet attributeSet) throws XmlPullParserException, IOException {
|
|
int i;
|
|
PropertyValuesHolder[] propertyValuesHolderArr = null;
|
|
ArrayList arrayList = null;
|
|
while (true) {
|
|
int eventType = xmlPullParser.getEventType();
|
|
if (eventType == 3 || eventType == 1) {
|
|
break;
|
|
} else if (eventType != 2) {
|
|
xmlPullParser.next();
|
|
} else {
|
|
if (xmlPullParser.getName().equals("propertyValuesHolder")) {
|
|
TypedArray obtainAttributes = TypedArrayUtils.obtainAttributes(resources, theme, attributeSet, AndroidResources.STYLEABLE_PROPERTY_VALUES_HOLDER);
|
|
String namedString = TypedArrayUtils.getNamedString(obtainAttributes, xmlPullParser, "propertyName", 3);
|
|
int namedInt = TypedArrayUtils.getNamedInt(obtainAttributes, xmlPullParser, "valueType", 2, 4);
|
|
PropertyValuesHolder loadPvh = loadPvh(context, resources, theme, xmlPullParser, namedString, namedInt);
|
|
if (loadPvh == null) {
|
|
loadPvh = getPVH(obtainAttributes, namedInt, 0, 1, namedString);
|
|
}
|
|
if (loadPvh != null) {
|
|
if (arrayList == null) {
|
|
arrayList = new ArrayList();
|
|
}
|
|
arrayList.add(loadPvh);
|
|
}
|
|
obtainAttributes.recycle();
|
|
}
|
|
xmlPullParser.next();
|
|
}
|
|
}
|
|
if (arrayList != null) {
|
|
int size = arrayList.size();
|
|
propertyValuesHolderArr = new PropertyValuesHolder[size];
|
|
for (i = 0; i < size; i++) {
|
|
propertyValuesHolderArr[i] = (PropertyValuesHolder) arrayList.get(i);
|
|
}
|
|
}
|
|
return propertyValuesHolderArr;
|
|
}
|
|
|
|
private static void parseAnimatorFromTypeArray(ValueAnimator valueAnimator, TypedArray typedArray, TypedArray typedArray2, float f, XmlPullParser xmlPullParser) {
|
|
long namedInt = (long) TypedArrayUtils.getNamedInt(typedArray, xmlPullParser, "duration", 1, 300);
|
|
long namedInt2 = (long) TypedArrayUtils.getNamedInt(typedArray, xmlPullParser, "startOffset", 2, 0);
|
|
int namedInt3 = TypedArrayUtils.getNamedInt(typedArray, xmlPullParser, "valueType", 7, 4);
|
|
if (TypedArrayUtils.hasAttribute(xmlPullParser, "valueFrom") && TypedArrayUtils.hasAttribute(xmlPullParser, "valueTo")) {
|
|
if (namedInt3 == 4) {
|
|
namedInt3 = inferValueTypeFromValues(typedArray, 5, 6);
|
|
}
|
|
PropertyValuesHolder pvh = getPVH(typedArray, namedInt3, 5, 6, "");
|
|
if (pvh != null) {
|
|
valueAnimator.setValues(pvh);
|
|
}
|
|
}
|
|
valueAnimator.setDuration(namedInt);
|
|
valueAnimator.setStartDelay(namedInt2);
|
|
valueAnimator.setRepeatCount(TypedArrayUtils.getNamedInt(typedArray, xmlPullParser, "repeatCount", 3, 0));
|
|
valueAnimator.setRepeatMode(TypedArrayUtils.getNamedInt(typedArray, xmlPullParser, "repeatMode", 4, 1));
|
|
if (typedArray2 != null) {
|
|
setupObjectAnimator(valueAnimator, typedArray2, namedInt3, f, xmlPullParser);
|
|
}
|
|
}
|
|
|
|
private static void setupObjectAnimator(ValueAnimator valueAnimator, TypedArray typedArray, int i, float f, XmlPullParser xmlPullParser) {
|
|
ObjectAnimator objectAnimator = (ObjectAnimator) valueAnimator;
|
|
String namedString = TypedArrayUtils.getNamedString(typedArray, xmlPullParser, "pathData", 1);
|
|
if (namedString != null) {
|
|
String namedString2 = TypedArrayUtils.getNamedString(typedArray, xmlPullParser, "propertyXName", 2);
|
|
String namedString3 = TypedArrayUtils.getNamedString(typedArray, xmlPullParser, "propertyYName", 3);
|
|
if (i != 2) {
|
|
}
|
|
if (namedString2 == null && namedString3 == null) {
|
|
throw new InflateException(typedArray.getPositionDescription() + " propertyXName or propertyYName is needed for PathData");
|
|
}
|
|
setupPathMotion(PathParser.createPathFromPathData(namedString), objectAnimator, f * 0.5f, namedString2, namedString3);
|
|
return;
|
|
}
|
|
objectAnimator.setPropertyName(TypedArrayUtils.getNamedString(typedArray, xmlPullParser, "propertyName", 0));
|
|
}
|
|
|
|
private static void setupPathMotion(Path path, ObjectAnimator objectAnimator, float f, String str, String str2) {
|
|
PropertyValuesHolder propertyValuesHolder;
|
|
PathMeasure pathMeasure = new PathMeasure(path, false);
|
|
ArrayList arrayList = new ArrayList();
|
|
float f2 = 0.0f;
|
|
arrayList.add(Float.valueOf(0.0f));
|
|
float f3 = 0.0f;
|
|
do {
|
|
f3 += pathMeasure.getLength();
|
|
arrayList.add(Float.valueOf(f3));
|
|
} while (pathMeasure.nextContour());
|
|
PathMeasure pathMeasure2 = new PathMeasure(path, false);
|
|
int min = Math.min(100, ((int) (f3 / f)) + 1);
|
|
float[] fArr = new float[min];
|
|
float[] fArr2 = new float[min];
|
|
float[] fArr3 = new float[2];
|
|
float f4 = f3 / ((float) (min - 1));
|
|
int i = 0;
|
|
int i2 = 0;
|
|
while (true) {
|
|
propertyValuesHolder = null;
|
|
if (i >= min) {
|
|
break;
|
|
}
|
|
pathMeasure2.getPosTan(f2 - ((Float) arrayList.get(i2)).floatValue(), fArr3, null);
|
|
fArr[i] = fArr3[0];
|
|
fArr2[i] = fArr3[1];
|
|
f2 += f4;
|
|
int i3 = i2 + 1;
|
|
if (i3 < arrayList.size() && f2 > ((Float) arrayList.get(i3)).floatValue()) {
|
|
pathMeasure2.nextContour();
|
|
i2 = i3;
|
|
}
|
|
i++;
|
|
}
|
|
PropertyValuesHolder ofFloat = str != null ? PropertyValuesHolder.ofFloat(str, fArr) : null;
|
|
if (str2 != null) {
|
|
propertyValuesHolder = PropertyValuesHolder.ofFloat(str2, fArr2);
|
|
}
|
|
if (ofFloat == null) {
|
|
objectAnimator.setValues(propertyValuesHolder);
|
|
} else if (propertyValuesHolder == null) {
|
|
objectAnimator.setValues(ofFloat);
|
|
} else {
|
|
objectAnimator.setValues(ofFloat, propertyValuesHolder);
|
|
}
|
|
}
|
|
}
|