package androidx.vectordrawable.graphics.drawable; import android.animation.Animator; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.ColorFilter; import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.drawable.AnimatedVectorDrawable; import android.graphics.drawable.Drawable; import android.os.Build; import android.util.AttributeSet; import androidx.collection.ArrayMap; import androidx.core.content.res.TypedArrayUtils; import androidx.core.graphics.drawable.DrawableCompat; import java.io.IOException; import java.util.ArrayList; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; /* loaded from: classes.dex */ public class AnimatedVectorDrawableCompat extends VectorDrawableCommon implements Animatable2Compat { private AnimatedVectorDrawableCompatState b; private Context c; private android.animation.ArgbEvaluator d; final Drawable.Callback e; private static class AnimatedVectorDrawableCompatState extends Drawable.ConstantState { int a; VectorDrawableCompat b; AnimatorSet c; ArrayList d; ArrayMap e; public AnimatedVectorDrawableCompatState(Context context, AnimatedVectorDrawableCompatState animatedVectorDrawableCompatState, Drawable.Callback callback, Resources resources) { if (animatedVectorDrawableCompatState != null) { this.a = animatedVectorDrawableCompatState.a; VectorDrawableCompat vectorDrawableCompat = animatedVectorDrawableCompatState.b; if (vectorDrawableCompat != null) { Drawable.ConstantState constantState = vectorDrawableCompat.getConstantState(); if (resources != null) { this.b = (VectorDrawableCompat) constantState.newDrawable(resources); } else { this.b = (VectorDrawableCompat) constantState.newDrawable(); } VectorDrawableCompat vectorDrawableCompat2 = this.b; vectorDrawableCompat2.mutate(); this.b = vectorDrawableCompat2; this.b.setCallback(callback); this.b.setBounds(animatedVectorDrawableCompatState.b.getBounds()); this.b.a(false); } ArrayList arrayList = animatedVectorDrawableCompatState.d; if (arrayList != null) { int size = arrayList.size(); this.d = new ArrayList<>(size); this.e = new ArrayMap<>(size); for (int i = 0; i < size; i++) { Animator animator = animatedVectorDrawableCompatState.d.get(i); Animator clone = animator.clone(); String str = animatedVectorDrawableCompatState.e.get(animator); clone.setTarget(this.b.a(str)); this.d.add(clone); this.e.put(clone, str); } a(); } } } public void a() { if (this.c == null) { this.c = new AnimatorSet(); } this.c.playTogether(this.d); } @Override // android.graphics.drawable.Drawable.ConstantState public int getChangingConfigurations() { return this.a; } @Override // android.graphics.drawable.Drawable.ConstantState public Drawable newDrawable() { throw new IllegalStateException("No constant state support for SDK < 24."); } @Override // android.graphics.drawable.Drawable.ConstantState public Drawable newDrawable(Resources resources) { throw new IllegalStateException("No constant state support for SDK < 24."); } } AnimatedVectorDrawableCompat() { this(null, null, null); } public static AnimatedVectorDrawableCompat a(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) throws XmlPullParserException, IOException { AnimatedVectorDrawableCompat animatedVectorDrawableCompat = new AnimatedVectorDrawableCompat(context); animatedVectorDrawableCompat.inflate(resources, xmlPullParser, attributeSet, theme); return animatedVectorDrawableCompat; } @Override // androidx.vectordrawable.graphics.drawable.VectorDrawableCommon, android.graphics.drawable.Drawable public void applyTheme(Resources.Theme theme) { Drawable drawable = this.a; if (drawable != null) { DrawableCompat.a(drawable, theme); } } @Override // android.graphics.drawable.Drawable public boolean canApplyTheme() { Drawable drawable = this.a; if (drawable != null) { return DrawableCompat.a(drawable); } return false; } @Override // android.graphics.drawable.Drawable public void draw(Canvas canvas) { Drawable drawable = this.a; if (drawable != null) { drawable.draw(canvas); return; } this.b.b.draw(canvas); if (this.b.c.isStarted()) { invalidateSelf(); } } @Override // android.graphics.drawable.Drawable public int getAlpha() { Drawable drawable = this.a; return drawable != null ? DrawableCompat.c(drawable) : this.b.b.getAlpha(); } @Override // android.graphics.drawable.Drawable public int getChangingConfigurations() { Drawable drawable = this.a; return drawable != null ? drawable.getChangingConfigurations() : super.getChangingConfigurations() | this.b.a; } @Override // android.graphics.drawable.Drawable public Drawable.ConstantState getConstantState() { Drawable drawable = this.a; if (drawable == null || Build.VERSION.SDK_INT < 24) { return null; } return new AnimatedVectorDrawableDelegateState(drawable.getConstantState()); } @Override // android.graphics.drawable.Drawable public int getIntrinsicHeight() { Drawable drawable = this.a; return drawable != null ? drawable.getIntrinsicHeight() : this.b.b.getIntrinsicHeight(); } @Override // android.graphics.drawable.Drawable public int getIntrinsicWidth() { Drawable drawable = this.a; return drawable != null ? drawable.getIntrinsicWidth() : this.b.b.getIntrinsicWidth(); } @Override // android.graphics.drawable.Drawable public int getOpacity() { Drawable drawable = this.a; return drawable != null ? drawable.getOpacity() : this.b.b.getOpacity(); } @Override // android.graphics.drawable.Drawable public void inflate(Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) throws XmlPullParserException, IOException { Drawable drawable = this.a; if (drawable != null) { DrawableCompat.a(drawable, resources, xmlPullParser, attributeSet, theme); return; } int eventType = xmlPullParser.getEventType(); int depth = xmlPullParser.getDepth() + 1; while (eventType != 1 && (xmlPullParser.getDepth() >= depth || eventType != 3)) { if (eventType == 2) { String name = xmlPullParser.getName(); if ("animated-vector".equals(name)) { TypedArray a = TypedArrayUtils.a(resources, theme, attributeSet, AndroidResources.e); int resourceId = a.getResourceId(0, 0); if (resourceId != 0) { VectorDrawableCompat a2 = VectorDrawableCompat.a(resources, resourceId, theme); a2.a(false); a2.setCallback(this.e); VectorDrawableCompat vectorDrawableCompat = this.b.b; if (vectorDrawableCompat != null) { vectorDrawableCompat.setCallback(null); } this.b.b = a2; } a.recycle(); } else if ("target".equals(name)) { TypedArray obtainAttributes = resources.obtainAttributes(attributeSet, AndroidResources.f); String string = obtainAttributes.getString(0); int resourceId2 = obtainAttributes.getResourceId(1, 0); if (resourceId2 != 0) { Context context = this.c; if (context == null) { obtainAttributes.recycle(); throw new IllegalStateException("Context can't be null when inflating animators"); } a(string, AnimatorInflaterCompat.a(context, resourceId2)); } obtainAttributes.recycle(); } else { continue; } } eventType = xmlPullParser.next(); } this.b.a(); } @Override // android.graphics.drawable.Drawable public boolean isAutoMirrored() { Drawable drawable = this.a; return drawable != null ? DrawableCompat.f(drawable) : this.b.b.isAutoMirrored(); } @Override // android.graphics.drawable.Animatable public boolean isRunning() { Drawable drawable = this.a; return drawable != null ? ((AnimatedVectorDrawable) drawable).isRunning() : this.b.c.isRunning(); } @Override // android.graphics.drawable.Drawable public boolean isStateful() { Drawable drawable = this.a; return drawable != null ? drawable.isStateful() : this.b.b.isStateful(); } @Override // android.graphics.drawable.Drawable public Drawable mutate() { Drawable drawable = this.a; if (drawable != null) { drawable.mutate(); } return this; } @Override // android.graphics.drawable.Drawable protected void onBoundsChange(Rect rect) { Drawable drawable = this.a; if (drawable != null) { drawable.setBounds(rect); } else { this.b.b.setBounds(rect); } } @Override // androidx.vectordrawable.graphics.drawable.VectorDrawableCommon, android.graphics.drawable.Drawable protected boolean onLevelChange(int i) { Drawable drawable = this.a; return drawable != null ? drawable.setLevel(i) : this.b.b.setLevel(i); } @Override // android.graphics.drawable.Drawable protected boolean onStateChange(int[] iArr) { Drawable drawable = this.a; return drawable != null ? drawable.setState(iArr) : this.b.b.setState(iArr); } @Override // android.graphics.drawable.Drawable public void setAlpha(int i) { Drawable drawable = this.a; if (drawable != null) { drawable.setAlpha(i); } else { this.b.b.setAlpha(i); } } @Override // android.graphics.drawable.Drawable public void setAutoMirrored(boolean z) { Drawable drawable = this.a; if (drawable != null) { DrawableCompat.a(drawable, z); } else { this.b.b.setAutoMirrored(z); } } @Override // android.graphics.drawable.Drawable, androidx.core.graphics.drawable.TintAwareDrawable public void setTint(int i) { Drawable drawable = this.a; if (drawable != null) { DrawableCompat.b(drawable, i); } else { this.b.b.setTint(i); } } @Override // android.graphics.drawable.Drawable, androidx.core.graphics.drawable.TintAwareDrawable public void setTintList(ColorStateList colorStateList) { Drawable drawable = this.a; if (drawable != null) { DrawableCompat.a(drawable, colorStateList); } else { this.b.b.setTintList(colorStateList); } } @Override // android.graphics.drawable.Drawable, androidx.core.graphics.drawable.TintAwareDrawable public void setTintMode(PorterDuff.Mode mode) { Drawable drawable = this.a; if (drawable != null) { DrawableCompat.a(drawable, mode); } else { this.b.b.setTintMode(mode); } } @Override // android.graphics.drawable.Drawable public boolean setVisible(boolean z, boolean z2) { Drawable drawable = this.a; if (drawable != null) { return drawable.setVisible(z, z2); } this.b.b.setVisible(z, z2); return super.setVisible(z, z2); } @Override // android.graphics.drawable.Animatable public void start() { Drawable drawable = this.a; if (drawable != null) { ((AnimatedVectorDrawable) drawable).start(); } else { if (this.b.c.isStarted()) { return; } this.b.c.start(); invalidateSelf(); } } @Override // android.graphics.drawable.Animatable public void stop() { Drawable drawable = this.a; if (drawable != null) { ((AnimatedVectorDrawable) drawable).stop(); } else { this.b.c.end(); } } private AnimatedVectorDrawableCompat(Context context) { this(context, null, null); } @Override // android.graphics.drawable.Drawable public void setColorFilter(ColorFilter colorFilter) { Drawable drawable = this.a; if (drawable != null) { drawable.setColorFilter(colorFilter); } else { this.b.b.setColorFilter(colorFilter); } } private static class AnimatedVectorDrawableDelegateState extends Drawable.ConstantState { private final Drawable.ConstantState a; public AnimatedVectorDrawableDelegateState(Drawable.ConstantState constantState) { this.a = constantState; } @Override // android.graphics.drawable.Drawable.ConstantState public boolean canApplyTheme() { return this.a.canApplyTheme(); } @Override // android.graphics.drawable.Drawable.ConstantState public int getChangingConfigurations() { return this.a.getChangingConfigurations(); } @Override // android.graphics.drawable.Drawable.ConstantState public Drawable newDrawable() { AnimatedVectorDrawableCompat animatedVectorDrawableCompat = new AnimatedVectorDrawableCompat(); animatedVectorDrawableCompat.a = this.a.newDrawable(); animatedVectorDrawableCompat.a.setCallback(animatedVectorDrawableCompat.e); return animatedVectorDrawableCompat; } @Override // android.graphics.drawable.Drawable.ConstantState public Drawable newDrawable(Resources resources) { AnimatedVectorDrawableCompat animatedVectorDrawableCompat = new AnimatedVectorDrawableCompat(); animatedVectorDrawableCompat.a = this.a.newDrawable(resources); animatedVectorDrawableCompat.a.setCallback(animatedVectorDrawableCompat.e); return animatedVectorDrawableCompat; } @Override // android.graphics.drawable.Drawable.ConstantState public Drawable newDrawable(Resources resources, Resources.Theme theme) { AnimatedVectorDrawableCompat animatedVectorDrawableCompat = new AnimatedVectorDrawableCompat(); animatedVectorDrawableCompat.a = this.a.newDrawable(resources, theme); animatedVectorDrawableCompat.a.setCallback(animatedVectorDrawableCompat.e); return animatedVectorDrawableCompat; } } private AnimatedVectorDrawableCompat(Context context, AnimatedVectorDrawableCompatState animatedVectorDrawableCompatState, Resources resources) { this.d = null; this.e = new Drawable.Callback() { // from class: androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat.1 @Override // android.graphics.drawable.Drawable.Callback public void invalidateDrawable(Drawable drawable) { AnimatedVectorDrawableCompat.this.invalidateSelf(); } @Override // android.graphics.drawable.Drawable.Callback public void scheduleDrawable(Drawable drawable, Runnable runnable, long j) { AnimatedVectorDrawableCompat.this.scheduleSelf(runnable, j); } @Override // android.graphics.drawable.Drawable.Callback public void unscheduleDrawable(Drawable drawable, Runnable runnable) { AnimatedVectorDrawableCompat.this.unscheduleSelf(runnable); } }; this.c = context; if (animatedVectorDrawableCompatState != null) { this.b = animatedVectorDrawableCompatState; } else { this.b = new AnimatedVectorDrawableCompatState(context, animatedVectorDrawableCompatState, this.e, resources); } } private void a(Animator animator) { ArrayList childAnimations; if ((animator instanceof AnimatorSet) && (childAnimations = ((AnimatorSet) animator).getChildAnimations()) != null) { for (int i = 0; i < childAnimations.size(); i++) { a(childAnimations.get(i)); } } if (animator instanceof ObjectAnimator) { ObjectAnimator objectAnimator = (ObjectAnimator) animator; String propertyName = objectAnimator.getPropertyName(); if ("fillColor".equals(propertyName) || "strokeColor".equals(propertyName)) { if (this.d == null) { this.d = new android.animation.ArgbEvaluator(); } objectAnimator.setEvaluator(this.d); } } } private void a(String str, Animator animator) { animator.setTarget(this.b.b.a(str)); if (Build.VERSION.SDK_INT < 21) { a(animator); } AnimatedVectorDrawableCompatState animatedVectorDrawableCompatState = this.b; if (animatedVectorDrawableCompatState.d == null) { animatedVectorDrawableCompatState.d = new ArrayList<>(); this.b.e = new ArrayMap<>(); } this.b.d.add(animator); this.b.e.put(animator, str); } @Override // android.graphics.drawable.Drawable public void inflate(Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet) throws XmlPullParserException, IOException { inflate(resources, xmlPullParser, attributeSet, null); } }