package androidx.appcompat.widget;

import android.R;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.util.Xml;
import java.lang.ref.WeakReference;
import java.util.WeakHashMap;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

/* JADX INFO: compiled from: AppCompatDrawableManager.java */
/* JADX INFO: loaded from: classes.dex */
public final class f {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static f f586b;
    private WeakHashMap<Context, a.b.g<ColorStateList>> j;
    private a.b.a<String, d> k;
    private a.b.g<String> l;
    private final WeakHashMap<Context, a.b.c<WeakReference<Drawable.ConstantState>>> m = new WeakHashMap<>(0);
    private TypedValue n;
    private boolean o;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static final PorterDuff.Mode f585a = PorterDuff.Mode.SRC_IN;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static final c f587c = new c(6);

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static final int[] f588d = {a.a.e.Q, a.a.e.O, a.a.e.f21a};

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private static final int[] f589e = {a.a.e.m, a.a.e.z, a.a.e.r, a.a.e.n, a.a.e.o, a.a.e.q, a.a.e.p};

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private static final int[] f590f = {a.a.e.N, a.a.e.P, a.a.e.i, a.a.e.G, a.a.e.H, a.a.e.J, a.a.e.L, a.a.e.I, a.a.e.K, a.a.e.M};

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private static final int[] f591g = {a.a.e.u, a.a.e.f27g, a.a.e.t};
    private static final int[] h = {a.a.e.F, a.a.e.R};
    private static final int[] i = {a.a.e.f23c, a.a.e.f26f};

    /* JADX INFO: compiled from: AppCompatDrawableManager.java */
    static class a implements d {
        a() {
        }

        @Override // androidx.appcompat.widget.f.d
        public Drawable a(Context context, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) {
            try {
                return a.a.l.a.a.m(context, context.getResources(), xmlPullParser, attributeSet, theme);
            } catch (Exception e2) {
                Log.e("AsldcInflateDelegate", "Exception while inflating <animated-selector>", e2);
                return null;
            }
        }
    }

    /* JADX INFO: compiled from: AppCompatDrawableManager.java */
    private static class b implements d {
        b() {
        }

        @Override // androidx.appcompat.widget.f.d
        public Drawable a(Context context, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) {
            try {
                return a.h.a.a.b.a(context, context.getResources(), xmlPullParser, attributeSet, theme);
            } catch (Exception e2) {
                Log.e("AvdcInflateDelegate", "Exception while inflating <animated-vector>", e2);
                return null;
            }
        }
    }

    /* JADX INFO: compiled from: AppCompatDrawableManager.java */
    private static class c extends a.b.d<Integer, PorterDuffColorFilter> {
        public c(int i) {
            super(i);
        }

        private static int h(int i, PorterDuff.Mode mode) {
            return ((i + 31) * 31) + mode.hashCode();
        }

        PorterDuffColorFilter i(int i, PorterDuff.Mode mode) {
            return c(Integer.valueOf(h(i, mode)));
        }

        PorterDuffColorFilter j(int i, PorterDuff.Mode mode, PorterDuffColorFilter porterDuffColorFilter) {
            return d(Integer.valueOf(h(i, mode)), porterDuffColorFilter);
        }
    }

    /* JADX INFO: compiled from: AppCompatDrawableManager.java */
    private interface d {
        Drawable a(Context context, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme);
    }

    /* JADX INFO: compiled from: AppCompatDrawableManager.java */
    private static class e implements d {
        e() {
        }

        @Override // androidx.appcompat.widget.f.d
        public Drawable a(Context context, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) {
            try {
                return a.h.a.a.h.c(context.getResources(), xmlPullParser, attributeSet, theme);
            } catch (Exception e2) {
                Log.e("VdcInflateDelegate", "Exception while inflating <vector>", e2);
                return null;
            }
        }
    }

    private Drawable A(Context context, int i2, boolean z, Drawable drawable) {
        ColorStateList colorStateListS = s(context, i2);
        if (colorStateListS != null) {
            if (r.a(drawable)) {
                drawable = drawable.mutate();
            }
            Drawable drawableO = androidx.core.graphics.drawable.a.o(drawable);
            androidx.core.graphics.drawable.a.m(drawableO, colorStateListS);
            PorterDuff.Mode modeU = u(i2);
            if (modeU == null) {
                return drawableO;
            }
            androidx.core.graphics.drawable.a.n(drawableO, modeU);
            return drawableO;
        }
        if (i2 == a.a.e.A) {
            LayerDrawable layerDrawable = (LayerDrawable) drawable;
            Drawable drawableFindDrawableByLayerId = layerDrawable.findDrawableByLayerId(R.id.background);
            int i3 = a.a.a.o;
            int iB = d0.b(context, i3);
            PorterDuff.Mode mode = f585a;
            z(drawableFindDrawableByLayerId, iB, mode);
            z(layerDrawable.findDrawableByLayerId(R.id.secondaryProgress), d0.b(context, i3), mode);
            z(layerDrawable.findDrawableByLayerId(R.id.progress), d0.b(context, a.a.a.m), mode);
            return drawable;
        }
        if (i2 != a.a.e.w && i2 != a.a.e.v && i2 != a.a.e.x) {
            if (C(context, i2, drawable) || !z) {
                return drawable;
            }
            return null;
        }
        LayerDrawable layerDrawable2 = (LayerDrawable) drawable;
        Drawable drawableFindDrawableByLayerId2 = layerDrawable2.findDrawableByLayerId(R.id.background);
        int iA = d0.a(context, a.a.a.o);
        PorterDuff.Mode mode2 = f585a;
        z(drawableFindDrawableByLayerId2, iA, mode2);
        Drawable drawableFindDrawableByLayerId3 = layerDrawable2.findDrawableByLayerId(R.id.secondaryProgress);
        int i4 = a.a.a.m;
        z(drawableFindDrawableByLayerId3, d0.b(context, i4), mode2);
        z(layerDrawable2.findDrawableByLayerId(R.id.progress), d0.b(context, i4), mode2);
        return drawable;
    }

    static void B(Drawable drawable, g0 g0Var, int[] iArr) {
        if (r.a(drawable) && drawable.mutate() != drawable) {
            Log.d("AppCompatDrawableManag", "Mutated drawable is not the same instance as the input.");
            return;
        }
        boolean z = g0Var.f601d;
        if (z || g0Var.f600c) {
            drawable.setColorFilter(m(z ? g0Var.f598a : null, g0Var.f600c ? g0Var.f599b : f585a, iArr));
        } else {
            drawable.clearColorFilter();
        }
        if (Build.VERSION.SDK_INT <= 23) {
            drawable.invalidateSelf();
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:21:0x0044  */
    /* JADX WARN: Removed duplicated region for block: B:28:0x005f A[RETURN] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    static boolean C(android.content.Context r6, int r7, android.graphics.drawable.Drawable r8) {
        /*
            android.graphics.PorterDuff$Mode r0 = androidx.appcompat.widget.f.f585a
            int[] r1 = androidx.appcompat.widget.f.f588d
            boolean r1 = d(r1, r7)
            r2 = 16842801(0x1010031, float:2.3693695E-38)
            r3 = -1
            r4 = 0
            r5 = 1
            if (r1 == 0) goto L15
            int r2 = a.a.a.o
        L12:
            r7 = r3
        L13:
            r1 = r5
            goto L42
        L15:
            int[] r1 = androidx.appcompat.widget.f.f590f
            boolean r1 = d(r1, r7)
            if (r1 == 0) goto L20
            int r2 = a.a.a.m
            goto L12
        L20:
            int[] r1 = androidx.appcompat.widget.f.f591g
            boolean r1 = d(r1, r7)
            if (r1 == 0) goto L2b
            android.graphics.PorterDuff$Mode r0 = android.graphics.PorterDuff.Mode.MULTIPLY
            goto L12
        L2b:
            int r1 = a.a.e.s
            if (r7 != r1) goto L3a
            r2 = 16842800(0x1010030, float:2.3693693E-38)
            r7 = 1109603123(0x42233333, float:40.8)
            int r7 = java.lang.Math.round(r7)
            goto L13
        L3a:
            int r1 = a.a.e.j
            if (r7 != r1) goto L3f
            goto L12
        L3f:
            r7 = r3
            r1 = r4
            r2 = r1
        L42:
            if (r1 == 0) goto L5f
            boolean r1 = androidx.appcompat.widget.r.a(r8)
            if (r1 == 0) goto L4e
            android.graphics.drawable.Drawable r8 = r8.mutate()
        L4e:
            int r6 = androidx.appcompat.widget.d0.b(r6, r2)
            android.graphics.PorterDuffColorFilter r6 = r(r6, r0)
            r8.setColorFilter(r6)
            if (r7 == r3) goto L5e
            r8.setAlpha(r7)
        L5e:
            return r5
        L5f:
            return r4
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.appcompat.widget.f.C(android.content.Context, int, android.graphics.drawable.Drawable):boolean");
    }

    private void a(String str, d dVar) {
        if (this.k == null) {
            this.k = new a.b.a<>();
        }
        this.k.put(str, dVar);
    }

    private synchronized boolean b(Context context, long j, Drawable drawable) {
        Drawable.ConstantState constantState = drawable.getConstantState();
        if (constantState == null) {
            return false;
        }
        a.b.c<WeakReference<Drawable.ConstantState>> cVar = this.m.get(context);
        if (cVar == null) {
            cVar = new a.b.c<>();
            this.m.put(context, cVar);
        }
        cVar.h(j, new WeakReference<>(constantState));
        return true;
    }

    private void c(Context context, int i2, ColorStateList colorStateList) {
        if (this.j == null) {
            this.j = new WeakHashMap<>();
        }
        a.b.g<ColorStateList> gVar = this.j.get(context);
        if (gVar == null) {
            gVar = new a.b.g<>();
            this.j.put(context, gVar);
        }
        gVar.a(i2, colorStateList);
    }

    private static boolean d(int[] iArr, int i2) {
        for (int i3 : iArr) {
            if (i3 == i2) {
                return true;
            }
        }
        return false;
    }

    private void e(Context context) {
        if (this.o) {
            return;
        }
        this.o = true;
        Drawable drawableP = p(context, a.a.e.S);
        if (drawableP == null || !w(drawableP)) {
            this.o = false;
            throw new IllegalStateException("This app has been built with an incorrect configuration. Please configure your build for VectorDrawableCompat.");
        }
    }

    private ColorStateList f(Context context) {
        return g(context, 0);
    }

    private ColorStateList g(Context context, int i2) {
        int iB = d0.b(context, a.a.a.n);
        return new ColorStateList(new int[][]{d0.f573b, d0.f576e, d0.f574c, d0.i}, new int[]{d0.a(context, a.a.a.l), a.c.d.a.b(iB, i2), a.c.d.a.b(iB, i2), i2});
    }

    private static long h(TypedValue typedValue) {
        return (((long) typedValue.assetCookie) << 32) | ((long) typedValue.data);
    }

    private ColorStateList i(Context context) {
        return g(context, d0.b(context, a.a.a.k));
    }

    private ColorStateList j(Context context) {
        return g(context, d0.b(context, a.a.a.l));
    }

    private Drawable k(Context context, int i2) {
        if (this.n == null) {
            this.n = new TypedValue();
        }
        TypedValue typedValue = this.n;
        context.getResources().getValue(i2, typedValue, true);
        long jH = h(typedValue);
        Drawable drawableO = o(context, jH);
        if (drawableO != null) {
            return drawableO;
        }
        if (i2 == a.a.e.h) {
            drawableO = new LayerDrawable(new Drawable[]{p(context, a.a.e.f27g), p(context, a.a.e.i)});
        }
        if (drawableO != null) {
            drawableO.setChangingConfigurations(typedValue.changingConfigurations);
            b(context, jH, drawableO);
        }
        return drawableO;
    }

    private ColorStateList l(Context context) {
        int[][] iArr = new int[3][];
        int[] iArr2 = new int[3];
        int i2 = a.a.a.p;
        ColorStateList colorStateListD = d0.d(context, i2);
        if (colorStateListD == null || !colorStateListD.isStateful()) {
            iArr[0] = d0.f573b;
            iArr2[0] = d0.a(context, i2);
            iArr[1] = d0.f577f;
            iArr2[1] = d0.b(context, a.a.a.m);
            iArr[2] = d0.i;
            iArr2[2] = d0.b(context, i2);
        } else {
            iArr[0] = d0.f573b;
            iArr2[0] = colorStateListD.getColorForState(iArr[0], 0);
            iArr[1] = d0.f577f;
            iArr2[1] = d0.b(context, a.a.a.m);
            iArr[2] = d0.i;
            iArr2[2] = colorStateListD.getDefaultColor();
        }
        return new ColorStateList(iArr, iArr2);
    }

    private static PorterDuffColorFilter m(ColorStateList colorStateList, PorterDuff.Mode mode, int[] iArr) {
        if (colorStateList == null || mode == null) {
            return null;
        }
        return r(colorStateList.getColorForState(iArr, 0), mode);
    }

    public static synchronized f n() {
        if (f586b == null) {
            f fVar = new f();
            f586b = fVar;
            v(fVar);
        }
        return f586b;
    }

    private synchronized Drawable o(Context context, long j) {
        a.b.c<WeakReference<Drawable.ConstantState>> cVar = this.m.get(context);
        if (cVar == null) {
            return null;
        }
        WeakReference<Drawable.ConstantState> weakReferenceE = cVar.e(j);
        if (weakReferenceE != null) {
            Drawable.ConstantState constantState = weakReferenceE.get();
            if (constantState != null) {
                return constantState.newDrawable(context.getResources());
            }
            cVar.c(j);
        }
        return null;
    }

    public static synchronized PorterDuffColorFilter r(int i2, PorterDuff.Mode mode) {
        PorterDuffColorFilter porterDuffColorFilterI;
        c cVar = f587c;
        porterDuffColorFilterI = cVar.i(i2, mode);
        if (porterDuffColorFilterI == null) {
            porterDuffColorFilterI = new PorterDuffColorFilter(i2, mode);
            cVar.j(i2, mode, porterDuffColorFilterI);
        }
        return porterDuffColorFilterI;
    }

    private ColorStateList t(Context context, int i2) {
        a.b.g<ColorStateList> gVar;
        WeakHashMap<Context, a.b.g<ColorStateList>> weakHashMap = this.j;
        if (weakHashMap == null || (gVar = weakHashMap.get(context)) == null) {
            return null;
        }
        return gVar.d(i2);
    }

    static PorterDuff.Mode u(int i2) {
        if (i2 == a.a.e.D) {
            return PorterDuff.Mode.MULTIPLY;
        }
        return null;
    }

    private static void v(f fVar) {
        if (Build.VERSION.SDK_INT < 24) {
            fVar.a("vector", new e());
            fVar.a("animated-vector", new b());
            fVar.a("animated-selector", new a());
        }
    }

    private static boolean w(Drawable drawable) {
        return (drawable instanceof a.h.a.a.h) || "android.graphics.drawable.VectorDrawable".equals(drawable.getClass().getName());
    }

    private Drawable x(Context context, int i2) {
        int next;
        a.b.a<String, d> aVar = this.k;
        if (aVar == null || aVar.isEmpty()) {
            return null;
        }
        a.b.g<String> gVar = this.l;
        if (gVar != null) {
            String strD = gVar.d(i2);
            if ("appcompat_skip_skip".equals(strD) || (strD != null && this.k.get(strD) == null)) {
                return null;
            }
        } else {
            this.l = new a.b.g<>();
        }
        if (this.n == null) {
            this.n = new TypedValue();
        }
        TypedValue typedValue = this.n;
        Resources resources = context.getResources();
        resources.getValue(i2, typedValue, true);
        long jH = h(typedValue);
        Drawable drawableO = o(context, jH);
        if (drawableO != null) {
            return drawableO;
        }
        CharSequence charSequence = typedValue.string;
        if (charSequence != null && charSequence.toString().endsWith(".xml")) {
            try {
                XmlResourceParser xml = resources.getXml(i2);
                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");
                }
                String name = xml.getName();
                this.l.a(i2, name);
                d dVar = this.k.get(name);
                if (dVar != null) {
                    drawableO = dVar.a(context, xml, attributeSetAsAttributeSet, context.getTheme());
                }
                if (drawableO != null) {
                    drawableO.setChangingConfigurations(typedValue.changingConfigurations);
                    b(context, jH, drawableO);
                }
            } catch (Exception e2) {
                Log.e("AppCompatDrawableManag", "Exception while inflating drawable", e2);
            }
        }
        if (drawableO == null) {
            this.l.a(i2, "appcompat_skip_skip");
        }
        return drawableO;
    }

    private static void z(Drawable drawable, int i2, PorterDuff.Mode mode) {
        if (r.a(drawable)) {
            drawable = drawable.mutate();
        }
        if (mode == null) {
            mode = f585a;
        }
        drawable.setColorFilter(r(i2, mode));
    }

    public synchronized Drawable p(Context context, int i2) {
        return q(context, i2, false);
    }

    synchronized Drawable q(Context context, int i2, boolean z) {
        Drawable drawableX;
        e(context);
        drawableX = x(context, i2);
        if (drawableX == null) {
            drawableX = k(context, i2);
        }
        if (drawableX == null) {
            drawableX = a.c.c.a.b(context, i2);
        }
        if (drawableX != null) {
            drawableX = A(context, i2, z, drawableX);
        }
        if (drawableX != null) {
            r.b(drawableX);
        }
        return drawableX;
    }

    synchronized ColorStateList s(Context context, int i2) {
        ColorStateList colorStateListT;
        colorStateListT = t(context, i2);
        if (colorStateListT == null) {
            if (i2 == a.a.e.k) {
                colorStateListT = a.a.k.a.a.c(context, a.a.c.f10c);
            } else if (i2 == a.a.e.E) {
                colorStateListT = a.a.k.a.a.c(context, a.a.c.f13f);
            } else if (i2 == a.a.e.D) {
                colorStateListT = l(context);
            } else if (i2 == a.a.e.f25e) {
                colorStateListT = j(context);
            } else if (i2 == a.a.e.f22b) {
                colorStateListT = f(context);
            } else if (i2 == a.a.e.f24d) {
                colorStateListT = i(context);
            } else if (i2 == a.a.e.B || i2 == a.a.e.C) {
                colorStateListT = a.a.k.a.a.c(context, a.a.c.f12e);
            } else if (d(f589e, i2)) {
                colorStateListT = d0.d(context, a.a.a.o);
            } else if (d(h, i2)) {
                colorStateListT = a.a.k.a.a.c(context, a.a.c.f9b);
            } else if (d(i, i2)) {
                colorStateListT = a.a.k.a.a.c(context, a.a.c.f8a);
            } else if (i2 == a.a.e.y) {
                colorStateListT = a.a.k.a.a.c(context, a.a.c.f11d);
            }
            if (colorStateListT != null) {
                c(context, i2, colorStateListT);
            }
        }
        return colorStateListT;
    }

    synchronized Drawable y(Context context, n0 n0Var, int i2) {
        Drawable drawableX = x(context, i2);
        if (drawableX == null) {
            drawableX = n0Var.c(i2);
        }
        if (drawableX == null) {
            return null;
        }
        return A(context, i2, false, drawableX);
    }
}
