package c.b.f;

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.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.util.Xml;
import c.b.f.m;
import com.ifpdos.debugmenu.R;
import java.lang.ref.WeakReference;
import java.util.Objects;
import java.util.WeakHashMap;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static t0 f954b;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public WeakHashMap<Context, c.d.i<ColorStateList>> f956d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public c.d.h<String, b> f957e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public c.d.i<String> f958f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final WeakHashMap<Context, c.d.e<WeakReference<Drawable.ConstantState>>> f959g = new WeakHashMap<>(0);

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public TypedValue f960h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public boolean f961i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public c f962j;
    public static final PorterDuff.Mode a = PorterDuff.Mode.SRC_IN;

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

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

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

    /* JADX INFO: compiled from: ResourceManagerInternal.java */
    public interface c {
    }

    public static synchronized t0 c() {
        if (f954b == null) {
            f954b = new t0();
        }
        return f954b;
    }

    public static synchronized PorterDuffColorFilter g(int i2, PorterDuff.Mode mode) {
        PorterDuffColorFilter porterDuffColorFilterA;
        a aVar = f955c;
        Objects.requireNonNull(aVar);
        int i3 = (i2 + 31) * 31;
        porterDuffColorFilterA = aVar.a(Integer.valueOf(mode.hashCode() + i3));
        if (porterDuffColorFilterA == null) {
            porterDuffColorFilterA = new PorterDuffColorFilter(i2, mode);
            Objects.requireNonNull(aVar);
            aVar.b(Integer.valueOf(mode.hashCode() + i3), porterDuffColorFilterA);
        }
        return porterDuffColorFilterA;
    }

    public final synchronized boolean a(Context context, long j2, Drawable drawable) {
        Drawable.ConstantState constantState = drawable.getConstantState();
        if (constantState == null) {
            return false;
        }
        c.d.e<WeakReference<Drawable.ConstantState>> eVar = this.f959g.get(context);
        if (eVar == null) {
            eVar = new c.d.e<>();
            this.f959g.put(context, eVar);
        }
        eVar.e(j2, new WeakReference<>(constantState));
        return true;
    }

    public final Drawable b(Context context, int i2) {
        if (this.f960h == null) {
            this.f960h = new TypedValue();
        }
        TypedValue typedValue = this.f960h;
        context.getResources().getValue(i2, typedValue, true);
        long j2 = (((long) typedValue.assetCookie) << 32) | ((long) typedValue.data);
        Drawable drawableD = d(context, j2);
        if (drawableD != null) {
            return drawableD;
        }
        c cVar = this.f962j;
        LayerDrawable layerDrawableC = null;
        if (cVar != null) {
            m.a aVar = (m.a) cVar;
            if (i2 == R.drawable.abc_cab_background_top_material) {
                layerDrawableC = new LayerDrawable(new Drawable[]{e(context, R.drawable.abc_cab_background_internal_bg), e(context, R.drawable.abc_cab_background_top_mtrl_alpha)});
            } else if (i2 == R.drawable.abc_ratingbar_material) {
                layerDrawableC = aVar.c(this, context, R.dimen.abc_star_big);
            } else if (i2 == R.drawable.abc_ratingbar_indicator_material) {
                layerDrawableC = aVar.c(this, context, R.dimen.abc_star_medium);
            } else if (i2 == R.drawable.abc_ratingbar_small_material) {
                layerDrawableC = aVar.c(this, context, R.dimen.abc_star_small);
            }
        }
        if (layerDrawableC != null) {
            layerDrawableC.setChangingConfigurations(typedValue.changingConfigurations);
            a(context, j2, layerDrawableC);
        }
        return layerDrawableC;
    }

    public final synchronized Drawable d(Context context, long j2) {
        c.d.e<WeakReference<Drawable.ConstantState>> eVar = this.f959g.get(context);
        if (eVar == null) {
            return null;
        }
        WeakReference<Drawable.ConstantState> weakReferenceD = eVar.d(j2, null);
        if (weakReferenceD != null) {
            Drawable.ConstantState constantState = weakReferenceD.get();
            if (constantState != null) {
                return constantState.newDrawable(context.getResources());
            }
            int iB = c.d.d.b(eVar.f1028f, eVar.f1030h, j2);
            if (iB >= 0) {
                Object[] objArr = eVar.f1029g;
                Object obj = objArr[iB];
                Object obj2 = c.d.e.f1026b;
                if (obj != obj2) {
                    objArr[iB] = obj2;
                    eVar.f1027e = true;
                }
            }
        }
        return null;
    }

    public synchronized Drawable e(Context context, int i2) {
        return f(context, i2, false);
    }

    /* JADX WARN: Code restructure failed: missing block: B:14:0x0029, code lost:
    
        if (r0 != false) goto L15;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public synchronized android.graphics.drawable.Drawable f(android.content.Context r5, int r6, boolean r7) {
        /*
            r4 = this;
            monitor-enter(r4)
            boolean r0 = r4.f961i     // Catch: java.lang.Throwable -> L4a
            if (r0 == 0) goto L6
            goto L2b
        L6:
            r0 = 1
            r4.f961i = r0     // Catch: java.lang.Throwable -> L4a
            r1 = 2131230799(0x7f08004f, float:1.807766E38)
            android.graphics.drawable.Drawable r1 = r4.e(r5, r1)     // Catch: java.lang.Throwable -> L4a
            r2 = 0
            if (r1 == 0) goto L4c
            boolean r3 = r1 instanceof c.q.a.a.b     // Catch: java.lang.Throwable -> L4a
            if (r3 != 0) goto L29
            java.lang.String r3 = "android.graphics.drawable.VectorDrawable"
            java.lang.Class r1 = r1.getClass()     // Catch: java.lang.Throwable -> L4a
            java.lang.String r1 = r1.getName()     // Catch: java.lang.Throwable -> L4a
            boolean r1 = r3.equals(r1)     // Catch: java.lang.Throwable -> L4a
            if (r1 == 0) goto L28
            goto L29
        L28:
            r0 = r2
        L29:
            if (r0 == 0) goto L4c
        L2b:
            android.graphics.drawable.Drawable r0 = r4.i(r5, r6)     // Catch: java.lang.Throwable -> L4a
            if (r0 != 0) goto L35
            android.graphics.drawable.Drawable r0 = r4.b(r5, r6)     // Catch: java.lang.Throwable -> L4a
        L35:
            if (r0 != 0) goto L3d
            java.lang.Object r0 = c.f.c.a.a     // Catch: java.lang.Throwable -> L4a
            android.graphics.drawable.Drawable r0 = c.f.c.a.b.b(r5, r6)     // Catch: java.lang.Throwable -> L4a
        L3d:
            if (r0 == 0) goto L43
            android.graphics.drawable.Drawable r0 = r4.j(r5, r6, r7, r0)     // Catch: java.lang.Throwable -> L4a
        L43:
            if (r0 == 0) goto L48
            c.b.f.k0.a(r0)     // Catch: java.lang.Throwable -> L4a
        L48:
            monitor-exit(r4)
            return r0
        L4a:
            r5 = move-exception
            goto L56
        L4c:
            r4.f961i = r2     // Catch: java.lang.Throwable -> L4a
            java.lang.IllegalStateException r5 = new java.lang.IllegalStateException     // Catch: java.lang.Throwable -> L4a
            java.lang.String r6 = "This app has been built with an incorrect configuration. Please configure your build for VectorDrawableCompat."
            r5.<init>(r6)     // Catch: java.lang.Throwable -> L4a
            throw r5     // Catch: java.lang.Throwable -> L4a
        L56:
            monitor-exit(r4)
            throw r5
        */
        throw new UnsupportedOperationException("Method not decompiled: c.b.f.t0.f(android.content.Context, int, boolean):android.graphics.drawable.Drawable");
    }

    public synchronized ColorStateList h(Context context, int i2) {
        ColorStateList colorStateListC;
        c.d.i<ColorStateList> iVar;
        WeakHashMap<Context, c.d.i<ColorStateList>> weakHashMap = this.f956d;
        ColorStateList colorStateListD = null;
        colorStateListC = (weakHashMap == null || (iVar = weakHashMap.get(context)) == null) ? null : iVar.c(i2, null);
        if (colorStateListC == null) {
            c cVar = this.f962j;
            if (cVar != null) {
                colorStateListD = ((m.a) cVar).d(context, i2);
            }
            if (colorStateListD != null) {
                if (this.f956d == null) {
                    this.f956d = new WeakHashMap<>();
                }
                c.d.i<ColorStateList> iVar2 = this.f956d.get(context);
                if (iVar2 == null) {
                    iVar2 = new c.d.i<>();
                    this.f956d.put(context, iVar2);
                }
                iVar2.a(i2, colorStateListD);
            }
            colorStateListC = colorStateListD;
        }
        return colorStateListC;
    }

    public final Drawable i(Context context, int i2) {
        int next;
        c.d.h<String, b> hVar = this.f957e;
        if (hVar == null || hVar.isEmpty()) {
            return null;
        }
        c.d.i<String> iVar = this.f958f;
        if (iVar != null) {
            String strC = iVar.c(i2, null);
            if ("appcompat_skip_skip".equals(strC) || (strC != null && this.f957e.getOrDefault(strC, null) == null)) {
                return null;
            }
        } else {
            this.f958f = new c.d.i<>();
        }
        if (this.f960h == null) {
            this.f960h = new TypedValue();
        }
        TypedValue typedValue = this.f960h;
        Resources resources = context.getResources();
        resources.getValue(i2, typedValue, true);
        long j2 = (((long) typedValue.assetCookie) << 32) | ((long) typedValue.data);
        Drawable drawableD = d(context, j2);
        if (drawableD != null) {
            return drawableD;
        }
        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.f958f.a(i2, name);
                b bVar = this.f957e.get(name);
                if (bVar != null) {
                    drawableD = bVar.a(context, xml, attributeSetAsAttributeSet, context.getTheme());
                }
                if (drawableD != null) {
                    drawableD.setChangingConfigurations(typedValue.changingConfigurations);
                    a(context, j2, drawableD);
                }
            } catch (Exception e2) {
                Log.e("ResourceManagerInternal", "Exception while inflating drawable", e2);
            }
        }
        if (drawableD == null) {
            this.f958f.a(i2, "appcompat_skip_skip");
        }
        return drawableD;
    }

    public final Drawable j(Context context, int i2, boolean z, Drawable drawable) {
        ColorStateList colorStateListH = h(context, i2);
        PorterDuff.Mode mode = null;
        if (colorStateListH != null) {
            int[] iArr = k0.a;
            Drawable drawableMutate = drawable.mutate();
            c.f.d.l.b.h(drawableMutate, colorStateListH);
            c cVar = this.f962j;
            if (cVar != null) {
                if (i2 == R.drawable.abc_switch_thumb_material) {
                    mode = PorterDuff.Mode.MULTIPLY;
                }
            }
            if (mode == null) {
                return drawableMutate;
            }
            c.f.d.l.b.i(drawableMutate, mode);
            return drawableMutate;
        }
        c cVar2 = this.f962j;
        if (cVar2 != null) {
            m.a aVar = (m.a) cVar2;
            boolean z2 = true;
            if (i2 == R.drawable.abc_seekbar_track_material) {
                LayerDrawable layerDrawable = (LayerDrawable) drawable;
                Drawable drawableFindDrawableByLayerId = layerDrawable.findDrawableByLayerId(android.R.id.background);
                int iC = y0.c(context, R.attr.colorControlNormal);
                PorterDuff.Mode mode2 = m.a;
                aVar.e(drawableFindDrawableByLayerId, iC, mode2);
                aVar.e(layerDrawable.findDrawableByLayerId(android.R.id.secondaryProgress), y0.c(context, R.attr.colorControlNormal), mode2);
                aVar.e(layerDrawable.findDrawableByLayerId(android.R.id.progress), y0.c(context, R.attr.colorControlActivated), mode2);
            } else if (i2 == R.drawable.abc_ratingbar_material || i2 == R.drawable.abc_ratingbar_indicator_material || i2 == R.drawable.abc_ratingbar_small_material) {
                LayerDrawable layerDrawable2 = (LayerDrawable) drawable;
                Drawable drawableFindDrawableByLayerId2 = layerDrawable2.findDrawableByLayerId(android.R.id.background);
                int iB = y0.b(context, R.attr.colorControlNormal);
                PorterDuff.Mode mode3 = m.a;
                aVar.e(drawableFindDrawableByLayerId2, iB, mode3);
                aVar.e(layerDrawable2.findDrawableByLayerId(android.R.id.secondaryProgress), y0.c(context, R.attr.colorControlActivated), mode3);
                aVar.e(layerDrawable2.findDrawableByLayerId(android.R.id.progress), y0.c(context, R.attr.colorControlActivated), mode3);
            } else {
                z2 = false;
            }
            if (z2) {
                return drawable;
            }
        }
        if (k(context, i2, drawable) || !z) {
            return drawable;
        }
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:22:0x0052  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x0071  */
    /* JADX WARN: Removed duplicated region for block: B:40:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public boolean k(android.content.Context r8, int r9, android.graphics.drawable.Drawable r10) {
        /*
            r7 = this;
            c.b.f.t0$c r0 = r7.f962j
            r1 = 1
            r2 = 0
            if (r0 == 0) goto L75
            c.b.f.m$a r0 = (c.b.f.m.a) r0
            java.util.Objects.requireNonNull(r0)
            android.graphics.PorterDuff$Mode r3 = c.b.f.m.a
            int[] r4 = r0.a
            boolean r4 = r0.a(r4, r9)
            r5 = 16842801(0x1010031, float:2.3693695E-38)
            r6 = -1
            if (r4 == 0) goto L1d
            r5 = 2130968677(0x7f040065, float:1.7546014E38)
            goto L49
        L1d:
            int[] r4 = r0.f897c
            boolean r4 = r0.a(r4, r9)
            if (r4 == 0) goto L29
            r5 = 2130968675(0x7f040063, float:1.754601E38)
            goto L49
        L29:
            int[] r4 = r0.f898d
            boolean r0 = r0.a(r4, r9)
            if (r0 == 0) goto L34
            android.graphics.PorterDuff$Mode r3 = android.graphics.PorterDuff.Mode.MULTIPLY
            goto L49
        L34:
            r0 = 2131230758(0x7f080026, float:1.8077578E38)
            if (r9 != r0) goto L44
            r9 = 16842800(0x1010030, float:2.3693693E-38)
            r0 = 1109603123(0x42233333, float:40.8)
            int r0 = java.lang.Math.round(r0)
            goto L4b
        L44:
            r0 = 2131230740(0x7f080014, float:1.8077541E38)
            if (r9 != r0) goto L4d
        L49:
            r9 = r5
            r0 = r6
        L4b:
            r4 = r1
            goto L50
        L4d:
            r9 = r2
            r4 = r9
            r0 = r6
        L50:
            if (r4 == 0) goto L71
            int[] r4 = c.b.f.k0.a
            android.graphics.drawable.Drawable r10 = r10.mutate()
            int r8 = c.b.f.y0.c(r8, r9)
            java.lang.Class<c.b.f.m> r9 = c.b.f.m.class
            monitor-enter(r9)
            android.graphics.PorterDuffColorFilter r8 = g(r8, r3)     // Catch: java.lang.Throwable -> L6e
            monitor-exit(r9)
            r10.setColorFilter(r8)
            if (r0 == r6) goto L6c
            r10.setAlpha(r0)
        L6c:
            r8 = r1
            goto L72
        L6e:
            r8 = move-exception
            monitor-exit(r9)
            throw r8
        L71:
            r8 = r2
        L72:
            if (r8 == 0) goto L75
            goto L76
        L75:
            r1 = r2
        L76:
            return r1
        */
        throw new UnsupportedOperationException("Method not decompiled: c.b.f.t0.k(android.content.Context, int, android.graphics.drawable.Drawable):boolean");
    }
}
