package c.b.g;

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.g.f;
import com.ifpdos.factory.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: loaded from: classes.dex */
public final class c0 {

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public c f4924j;

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

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

    public static class a extends c.d.f<Integer, PorterDuffColorFilter> {
        public a(int i2) {
            super(i2);
        }
    }

    public interface b {
        Drawable a(Context context, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme);
    }

    public interface c {
    }

    public static synchronized c0 c() {
        if (f4916b == null) {
            f4916b = new c0();
        }
        return f4916b;
    }

    public static synchronized PorterDuffColorFilter g(int i2, PorterDuff.Mode mode) {
        PorterDuffColorFilter porterDuffColorFilterA;
        a aVar = f4917c;
        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) {
        boolean z;
        Drawable.ConstantState constantState = drawable.getConstantState();
        if (constantState != null) {
            c.d.e<WeakReference<Drawable.ConstantState>> eVar = this.f4921g.get(context);
            if (eVar == null) {
                eVar = new c.d.e<>();
                this.f4921g.put(context, eVar);
            }
            eVar.e(j2, new WeakReference<>(constantState));
            z = true;
        } else {
            z = false;
        }
        return z;
    }

    public final Drawable b(Context context, int i2) {
        int i3;
        if (this.f4922h == null) {
            this.f4922h = new TypedValue();
        }
        TypedValue typedValue = this.f4922h;
        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.f4924j;
        LayerDrawable layerDrawableC = null;
        if (cVar != null) {
            f.a aVar = (f.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) {
                    i3 = R.dimen.abc_star_big;
                } else if (i2 == R.drawable.abc_ratingbar_indicator_material) {
                    i3 = R.dimen.abc_star_medium;
                } else if (i2 == R.drawable.abc_ratingbar_small_material) {
                    i3 = R.dimen.abc_star_small;
                }
                layerDrawableC = aVar.c(this, context, i3);
            }
        }
        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.f4921g.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.f5121d, eVar.f5123f, j2);
            if (iB >= 0) {
                Object[] objArr = eVar.f5122e;
                Object obj = objArr[iB];
                Object obj2 = c.d.e.f5119b;
                if (obj != obj2) {
                    objArr[iB] = obj2;
                    eVar.f5120c = 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.f4923i     // Catch: java.lang.Throwable -> L49
            if (r0 == 0) goto L6
            goto L2b
        L6:
            r0 = 1
            r4.f4923i = r0     // Catch: java.lang.Throwable -> L49
            r1 = 2131230799(0x7f08004f, float:1.807766E38)
            android.graphics.drawable.Drawable r1 = r4.e(r5, r1)     // Catch: java.lang.Throwable -> L49
            r2 = 0
            if (r1 == 0) goto L4b
            boolean r3 = r1 instanceof c.k.a.a.b     // Catch: java.lang.Throwable -> L49
            if (r3 != 0) goto L29
            java.lang.String r3 = "android.graphics.drawable.VectorDrawable"
            java.lang.Class r1 = r1.getClass()     // Catch: java.lang.Throwable -> L49
            java.lang.String r1 = r1.getName()     // Catch: java.lang.Throwable -> L49
            boolean r1 = r3.equals(r1)     // Catch: java.lang.Throwable -> L49
            if (r1 == 0) goto L28
            goto L29
        L28:
            r0 = r2
        L29:
            if (r0 == 0) goto L4b
        L2b:
            android.graphics.drawable.Drawable r0 = r4.i(r5, r6)     // Catch: java.lang.Throwable -> L49
            if (r0 != 0) goto L35
            android.graphics.drawable.Drawable r0 = r4.b(r5, r6)     // Catch: java.lang.Throwable -> L49
        L35:
            if (r0 != 0) goto L3d
            java.lang.Object r0 = c.e.c.a.f5166a     // Catch: java.lang.Throwable -> L49
            android.graphics.drawable.Drawable r0 = c.e.c.a.b.b(r5, r6)     // Catch: java.lang.Throwable -> L49
        L3d:
            if (r0 == 0) goto L43
            android.graphics.drawable.Drawable r0 = r4.j(r5, r6, r7, r0)     // Catch: java.lang.Throwable -> L49
        L43:
            if (r0 == 0) goto L47
            int[] r5 = c.b.g.t.f5036a     // Catch: java.lang.Throwable -> L49
        L47:
            monitor-exit(r4)
            return r0
        L49:
            r5 = move-exception
            goto L55
        L4b:
            r4.f4923i = r2     // Catch: java.lang.Throwable -> L49
            java.lang.IllegalStateException r5 = new java.lang.IllegalStateException     // Catch: java.lang.Throwable -> L49
            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 -> L49
            throw r5     // Catch: java.lang.Throwable -> L49
        L55:
            monitor-exit(r4)
            throw r5
        */
        throw new UnsupportedOperationException("Method not decompiled: c.b.g.c0.f(android.content.Context, int, boolean):android.graphics.drawable.Drawable");
    }

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

    public final Drawable i(Context context, int i2) {
        int next;
        c.d.h<String, b> hVar = this.f4919e;
        if (hVar == null || hVar.isEmpty()) {
            return null;
        }
        c.d.i<String> iVar = this.f4920f;
        if (iVar != null) {
            String strD = iVar.d(i2, null);
            if ("appcompat_skip_skip".equals(strD) || (strD != null && this.f4919e.getOrDefault(strD, null) == null)) {
                return null;
            }
        } else {
            this.f4920f = new c.d.i<>();
        }
        if (this.f4922h == null) {
            this.f4922h = new TypedValue();
        }
        TypedValue typedValue = this.f4922h;
        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.f4920f.b(i2, name);
                b bVar = this.f4919e.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.f4920f.b(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) {
            if (t.a(drawable)) {
                drawable = drawable.mutate();
            }
            drawable.setTintList(colorStateListH);
            c cVar = this.f4924j;
            if (cVar != null) {
                if (i2 == R.drawable.abc_switch_thumb_material) {
                    mode = PorterDuff.Mode.MULTIPLY;
                }
            }
            if (mode == null) {
                return drawable;
            }
            drawable.setTintMode(mode);
            return drawable;
        }
        c cVar2 = this.f4924j;
        if (cVar2 != null) {
            f.a aVar = (f.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 = h0.c(context, R.attr.colorControlNormal);
                PorterDuff.Mode mode2 = f.f4942a;
                aVar.e(drawableFindDrawableByLayerId, iC, mode2);
                aVar.e(layerDrawable.findDrawableByLayerId(android.R.id.secondaryProgress), h0.c(context, R.attr.colorControlNormal), mode2);
                aVar.e(layerDrawable.findDrawableByLayerId(android.R.id.progress), h0.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 = h0.b(context, R.attr.colorControlNormal);
                PorterDuff.Mode mode3 = f.f4942a;
                aVar.e(drawableFindDrawableByLayerId2, iB, mode3);
                aVar.e(layerDrawable2.findDrawableByLayerId(android.R.id.secondaryProgress), h0.c(context, R.attr.colorControlActivated), mode3);
                aVar.e(layerDrawable2.findDrawableByLayerId(android.R.id.progress), h0.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:36:0x0075  */
    /* JADX WARN: Removed duplicated region for block: B:43:? 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.g.c0$c r0 = r7.f4924j
            r1 = 1
            r2 = 0
            if (r0 == 0) goto L79
            c.b.g.f$a r0 = (c.b.g.f.a) r0
            java.util.Objects.requireNonNull(r0)
            android.graphics.PorterDuff$Mode r3 = c.b.g.f.f4942a
            int[] r4 = r0.f4945a
            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.f4947c
            boolean r4 = r0.a(r4, r9)
            if (r4 == 0) goto L29
            r5 = 2130968675(0x7f040063, float:1.754601E38)
            goto L49
        L29:
            int[] r4 = r0.f4948d
            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 L75
            boolean r4 = c.b.g.t.a(r10)
            if (r4 == 0) goto L5c
            android.graphics.drawable.Drawable r10 = r10.mutate()
        L5c:
            int r8 = c.b.g.h0.c(r8, r9)
            java.lang.Class<c.b.g.f> r9 = c.b.g.f.class
            monitor-enter(r9)
            android.graphics.PorterDuffColorFilter r8 = g(r8, r3)     // Catch: java.lang.Throwable -> L72
            monitor-exit(r9)
            r10.setColorFilter(r8)
            if (r0 == r6) goto L70
            r10.setAlpha(r0)
        L70:
            r8 = r1
            goto L76
        L72:
            r8 = move-exception
            monitor-exit(r9)
            throw r8
        L75:
            r8 = r2
        L76:
            if (r8 == 0) goto L79
            goto L7a
        L79:
            r1 = r2
        L7a:
            return r1
        */
        throw new UnsupportedOperationException("Method not decompiled: c.b.g.c0.k(android.content.Context, int, android.graphics.drawable.Drawable):boolean");
    }
}
