package d2;

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;
import com.google.android.gms.internal.measurement.X1;
import java.io.IOException;
import java.util.ArrayList;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

/* JADX INFO: loaded from: classes.dex */
public final class e extends h implements Animatable {

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final Context f11356s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final b f11357t = new b(this);

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final c f11355r = new c();

    public e(Context context) {
        this.f11356s = context;
    }

    @Override // d2.h, android.graphics.drawable.Drawable
    public final void applyTheme(Resources.Theme theme) {
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            drawable.applyTheme(theme);
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final boolean canApplyTheme() {
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            return drawable.canApplyTheme();
        }
        return false;
    }

    @Override // android.graphics.drawable.Drawable
    public final void draw(Canvas canvas) {
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            drawable.draw(canvas);
            return;
        }
        c cVar = this.f11355r;
        cVar.f11350a.draw(canvas);
        if (cVar.f11351b.isStarted()) {
            invalidateSelf();
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final int getAlpha() {
        Drawable drawable = this.f11360q;
        return drawable != null ? drawable.getAlpha() : this.f11355r.f11350a.getAlpha();
    }

    @Override // android.graphics.drawable.Drawable
    public final int getChangingConfigurations() {
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            return drawable.getChangingConfigurations();
        }
        int changingConfigurations = super.getChangingConfigurations();
        this.f11355r.getClass();
        return changingConfigurations;
    }

    @Override // android.graphics.drawable.Drawable
    public final ColorFilter getColorFilter() {
        Drawable drawable = this.f11360q;
        return drawable != null ? drawable.getColorFilter() : this.f11355r.f11350a.getColorFilter();
    }

    @Override // android.graphics.drawable.Drawable
    public final Drawable.ConstantState getConstantState() {
        if (this.f11360q == null || Build.VERSION.SDK_INT < 24) {
            return null;
        }
        return new d(this.f11360q.getConstantState());
    }

    @Override // android.graphics.drawable.Drawable
    public final int getIntrinsicHeight() {
        Drawable drawable = this.f11360q;
        return drawable != null ? drawable.getIntrinsicHeight() : this.f11355r.f11350a.getIntrinsicHeight();
    }

    @Override // android.graphics.drawable.Drawable
    public final int getIntrinsicWidth() {
        Drawable drawable = this.f11360q;
        return drawable != null ? drawable.getIntrinsicWidth() : this.f11355r.f11350a.getIntrinsicWidth();
    }

    @Override // android.graphics.drawable.Drawable
    public final int getOpacity() {
        Drawable drawable = this.f11360q;
        return drawable != null ? drawable.getOpacity() : this.f11355r.f11350a.getOpacity();
    }

    /* JADX WARN: Code restructure failed: missing block: B:82:0x017f, code lost:
    
        if (r8.f11351b != null) goto L84;
     */
    /* JADX WARN: Code restructure failed: missing block: B:83:0x0181, code lost:
    
        r8.f11351b = new android.animation.AnimatorSet();
     */
    /* JADX WARN: Code restructure failed: missing block: B:84:0x0188, code lost:
    
        r8.f11351b.playTogether(r8.f11352c);
     */
    /* JADX WARN: Code restructure failed: missing block: B:85:0x018f, code lost:
    
        return;
     */
    @Override // android.graphics.drawable.Drawable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void inflate(Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) throws Throwable {
        XmlResourceParser animation;
        Animator animatorA;
        q qVar;
        int next;
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            drawable.inflate(resources, xmlPullParser, attributeSet, theme);
            return;
        }
        int eventType = xmlPullParser.getEventType();
        int depth = xmlPullParser.getDepth() + 1;
        while (true) {
            c cVar = this.f11355r;
            if (eventType == 1 || (xmlPullParser.getDepth() < depth && eventType == 3)) {
                break;
            }
            if (eventType == 2) {
                String name = xmlPullParser.getName();
                if ("animated-vector".equals(name)) {
                    TypedArray typedArrayG = E.b.g(resources, theme, attributeSet, a.f11342e);
                    int resourceId = typedArrayG.getResourceId(0, 0);
                    if (resourceId != 0) {
                        PorterDuff.Mode mode = q.f11411z;
                        if (Build.VERSION.SDK_INT >= 24) {
                            qVar = new q();
                            ThreadLocal threadLocal = E.j.f1954a;
                            qVar.f11360q = resources.getDrawable(resourceId, theme);
                            new p(qVar.f11360q.getConstantState());
                        } else {
                            try {
                                XmlResourceParser xml = resources.getXml(resourceId);
                                AttributeSet attributeSetAsAttributeSet = Xml.asAttributeSet(xml);
                                do {
                                    next = xml.next();
                                    if (next == 2) {
                                        break;
                                    }
                                } while (next != 1);
                                if (next != 2) {
                                    throw new XmlPullParserException("No start tag found");
                                }
                                qVar = new q();
                                qVar.inflate(resources, xml, attributeSetAsAttributeSet, theme);
                            } catch (IOException e8) {
                                Log.e("VectorDrawableCompat", "parser error", e8);
                                qVar = null;
                            } catch (XmlPullParserException e9) {
                                Log.e("VectorDrawableCompat", "parser error", e9);
                                qVar = null;
                            }
                        }
                        qVar.f11416v = false;
                        qVar.setCallback(this.f11357t);
                        q qVar2 = cVar.f11350a;
                        if (qVar2 != null) {
                            qVar2.setCallback(null);
                        }
                        cVar.f11350a = qVar;
                    }
                    typedArrayG.recycle();
                } else {
                    XmlResourceParser xmlResourceParser = null;
                    if ("target".equals(name)) {
                        TypedArray typedArrayObtainAttributes = resources.obtainAttributes(attributeSet, a.f11343f);
                        String string = typedArrayObtainAttributes.getString(0);
                        int resourceId2 = typedArrayObtainAttributes.getResourceId(1, 0);
                        if (resourceId2 != 0) {
                            Context context = this.f11356s;
                            if (context == null) {
                                typedArrayObtainAttributes.recycle();
                                throw new IllegalStateException("Context can't be null when inflating animators");
                            }
                            if (Build.VERSION.SDK_INT >= 24) {
                                animatorA = AnimatorInflater.loadAnimator(context, resourceId2);
                            } else {
                                Resources resources2 = context.getResources();
                                Resources.Theme theme2 = context.getTheme();
                                try {
                                    try {
                                        animation = resources2.getAnimation(resourceId2);
                                    } catch (Throwable th) {
                                        th = th;
                                    }
                                } catch (IOException e10) {
                                    e = e10;
                                } catch (XmlPullParserException e11) {
                                    e = e11;
                                }
                                try {
                                    animatorA = a.a(context, resources2, theme2, animation, Xml.asAttributeSet(animation), null, 0);
                                    animation.close();
                                } catch (IOException e12) {
                                    e = e12;
                                    Resources.NotFoundException notFoundException = new Resources.NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(resourceId2));
                                    notFoundException.initCause(e);
                                    throw notFoundException;
                                } catch (XmlPullParserException e13) {
                                    e = e13;
                                    Resources.NotFoundException notFoundException2 = new Resources.NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(resourceId2));
                                    notFoundException2.initCause(e);
                                    throw notFoundException2;
                                } catch (Throwable th2) {
                                    th = th2;
                                    xmlResourceParser = animation;
                                    if (xmlResourceParser != null) {
                                        xmlResourceParser.close();
                                    }
                                    throw th;
                                }
                            }
                            animatorA.setTarget(cVar.f11350a.f11412r.f11400b.f11398o.get(string));
                            if (cVar.f11352c == null) {
                                cVar.f11352c = new ArrayList();
                                cVar.f11353d = new q.e(0);
                            }
                            cVar.f11352c.add(animatorA);
                            cVar.f11353d.put(animatorA, string);
                        }
                        typedArrayObtainAttributes.recycle();
                    } else {
                        continue;
                    }
                }
            }
            eventType = xmlPullParser.next();
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final boolean isAutoMirrored() {
        Drawable drawable = this.f11360q;
        return drawable != null ? drawable.isAutoMirrored() : this.f11355r.f11350a.isAutoMirrored();
    }

    @Override // android.graphics.drawable.Animatable
    public final boolean isRunning() {
        Drawable drawable = this.f11360q;
        return drawable != null ? ((AnimatedVectorDrawable) drawable).isRunning() : this.f11355r.f11351b.isRunning();
    }

    @Override // android.graphics.drawable.Drawable
    public final boolean isStateful() {
        Drawable drawable = this.f11360q;
        return drawable != null ? drawable.isStateful() : this.f11355r.f11350a.isStateful();
    }

    @Override // android.graphics.drawable.Drawable
    public final Drawable mutate() {
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            drawable.mutate();
        }
        return this;
    }

    @Override // android.graphics.drawable.Drawable
    public final void onBoundsChange(Rect rect) {
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            drawable.setBounds(rect);
        } else {
            this.f11355r.f11350a.setBounds(rect);
        }
    }

    @Override // d2.h, android.graphics.drawable.Drawable
    public final boolean onLevelChange(int i) {
        Drawable drawable = this.f11360q;
        return drawable != null ? drawable.setLevel(i) : this.f11355r.f11350a.setLevel(i);
    }

    @Override // android.graphics.drawable.Drawable
    public final boolean onStateChange(int[] iArr) {
        Drawable drawable = this.f11360q;
        return drawable != null ? drawable.setState(iArr) : this.f11355r.f11350a.setState(iArr);
    }

    @Override // android.graphics.drawable.Drawable
    public final void setAlpha(int i) {
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            drawable.setAlpha(i);
        } else {
            this.f11355r.f11350a.setAlpha(i);
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final void setAutoMirrored(boolean z8) {
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            drawable.setAutoMirrored(z8);
        } else {
            this.f11355r.f11350a.setAutoMirrored(z8);
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final void setColorFilter(ColorFilter colorFilter) {
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            drawable.setColorFilter(colorFilter);
        } else {
            this.f11355r.f11350a.setColorFilter(colorFilter);
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final void setTint(int i) {
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            X1.K(drawable, i);
        } else {
            this.f11355r.f11350a.setTint(i);
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final void setTintList(ColorStateList colorStateList) {
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            drawable.setTintList(colorStateList);
        } else {
            this.f11355r.f11350a.setTintList(colorStateList);
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final void setTintMode(PorterDuff.Mode mode) {
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            drawable.setTintMode(mode);
        } else {
            this.f11355r.f11350a.setTintMode(mode);
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final boolean setVisible(boolean z8, boolean z9) {
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            return drawable.setVisible(z8, z9);
        }
        this.f11355r.f11350a.setVisible(z8, z9);
        return super.setVisible(z8, z9);
    }

    @Override // android.graphics.drawable.Animatable
    public final void start() {
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            ((AnimatedVectorDrawable) drawable).start();
            return;
        }
        c cVar = this.f11355r;
        if (cVar.f11351b.isStarted()) {
            return;
        }
        cVar.f11351b.start();
        invalidateSelf();
    }

    @Override // android.graphics.drawable.Animatable
    public final void stop() {
        Drawable drawable = this.f11360q;
        if (drawable != null) {
            ((AnimatedVectorDrawable) drawable).stop();
        } else {
            this.f11355r.f11351b.end();
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final void inflate(Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet) throws Throwable {
        inflate(resources, xmlPullParser, attributeSet, null);
    }
}
