package androidx.core.content.res;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.util.SparseArray;
import android.util.TypedValue;
import java.lang.reflect.Method;
import java.util.WeakHashMap;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static final ThreadLocal<TypedValue> f1657a = new ThreadLocal<>();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static final WeakHashMap<e, SparseArray<d>> f1658b = new WeakHashMap<>(0);

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

    /* JADX INFO: compiled from: ResourcesCompat.java */
    static class a {
        static Drawable a(Resources resources, int i3, int i4) {
            return resources.getDrawableForDensity(i3, i4);
        }
    }

    /* JADX INFO: compiled from: ResourcesCompat.java */
    static class b {
        static Drawable a(Resources resources, int i3, Resources.Theme theme) {
            return resources.getDrawable(i3, theme);
        }

        static Drawable b(Resources resources, int i3, int i4, Resources.Theme theme) {
            return resources.getDrawableForDensity(i3, i4, theme);
        }
    }

    /* JADX INFO: compiled from: ResourcesCompat.java */
    static class c {
        static int a(Resources resources, int i3, Resources.Theme theme) {
            return resources.getColor(i3, theme);
        }

        static ColorStateList b(Resources resources, int i3, Resources.Theme theme) {
            return resources.getColorStateList(i3, theme);
        }
    }

    /* JADX INFO: compiled from: ResourcesCompat.java */
    private static class d {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final ColorStateList f1660a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final Configuration f1661b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        final int f1662c;

        d(ColorStateList colorStateList, Configuration configuration, Resources.Theme theme) {
            this.f1660a = colorStateList;
            this.f1661b = configuration;
            this.f1662c = theme == null ? 0 : theme.hashCode();
        }
    }

    /* JADX INFO: compiled from: ResourcesCompat.java */
    private static final class e {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final Resources f1663a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final Resources.Theme f1664b;

        e(Resources resources, Resources.Theme theme) {
            this.f1663a = resources;
            this.f1664b = theme;
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (obj == null || e.class != obj.getClass()) {
                return false;
            }
            e eVar = (e) obj;
            return this.f1663a.equals(eVar.f1663a) && androidx.core.util.c.a(this.f1664b, eVar.f1664b);
        }

        public int hashCode() {
            return androidx.core.util.c.b(this.f1663a, this.f1664b);
        }
    }

    /* JADX INFO: compiled from: ResourcesCompat.java */
    public static abstract class f {
        public static Handler e(Handler handler) {
            return handler == null ? new Handler(Looper.getMainLooper()) : handler;
        }

        public final void c(final int i3, Handler handler) {
            e(handler).post(new Runnable() { // from class: androidx.core.content.res.i
                @Override // java.lang.Runnable
                public final void run() {
                    this.f1668e.f(i3);
                }
            });
        }

        public final void d(final Typeface typeface, Handler handler) {
            e(handler).post(new Runnable() { // from class: androidx.core.content.res.j
                @Override // java.lang.Runnable
                public final void run() {
                    this.f1670e.g(typeface);
                }
            });
        }

        /* JADX INFO: renamed from: h, reason: merged with bridge method [inline-methods] */
        public abstract void f(int i3);

        /* JADX INFO: renamed from: i, reason: merged with bridge method [inline-methods] */
        public abstract void g(Typeface typeface);
    }

    /* JADX INFO: compiled from: ResourcesCompat.java */
    public static final class g {

        /* JADX INFO: compiled from: ResourcesCompat.java */
        static class a {

            /* JADX INFO: renamed from: a, reason: collision with root package name */
            private static final Object f1665a = new Object();

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            private static Method f1666b;

            /* JADX INFO: renamed from: c, reason: collision with root package name */
            private static boolean f1667c;

            /* JADX WARN: Removed duplicated region for block: B:19:0x0038 A[Catch: all -> 0x003a, DONT_GENERATE, TryCatch #2 {, blocks: (B:4:0x0003, B:8:0x0009, B:12:0x0021, B:11:0x001a, B:13:0x0023, B:15:0x0027, B:19:0x0038, B:18:0x002e), top: B:28:0x0003, inners: #0, #1 }] */
            /* JADX WARN: Removed duplicated region for block: B:26:0x0027 A[EXC_TOP_SPLITTER, SYNTHETIC] */
            @android.annotation.SuppressLint({"BanUncheckedReflection"})
            /*
                Code decompiled incorrectly, please refer to instructions dump.
                To view partially-correct add '--show-bad-code' argument
            */
            static void a(android.content.res.Resources.Theme r6) {
                /*
                    java.lang.Object r0 = androidx.core.content.res.h.g.a.f1665a
                    monitor-enter(r0)
                    boolean r1 = androidx.core.content.res.h.g.a.f1667c     // Catch: java.lang.Throwable -> L3a
                    r2 = 0
                    if (r1 != 0) goto L23
                    r1 = 1
                    java.lang.Class<android.content.res.Resources$Theme> r3 = android.content.res.Resources.Theme.class
                    java.lang.String r4 = "rebase"
                    java.lang.Class[] r5 = new java.lang.Class[r2]     // Catch: java.lang.NoSuchMethodException -> L19 java.lang.Throwable -> L3a
                    java.lang.reflect.Method r3 = r3.getDeclaredMethod(r4, r5)     // Catch: java.lang.NoSuchMethodException -> L19 java.lang.Throwable -> L3a
                    androidx.core.content.res.h.g.a.f1666b = r3     // Catch: java.lang.NoSuchMethodException -> L19 java.lang.Throwable -> L3a
                    r3.setAccessible(r1)     // Catch: java.lang.NoSuchMethodException -> L19 java.lang.Throwable -> L3a
                    goto L21
                L19:
                    r3 = move-exception
                    java.lang.String r4 = "ResourcesCompat"
                    java.lang.String r5 = "Failed to retrieve rebase() method"
                    android.util.Log.i(r4, r5, r3)     // Catch: java.lang.Throwable -> L3a
                L21:
                    androidx.core.content.res.h.g.a.f1667c = r1     // Catch: java.lang.Throwable -> L3a
                L23:
                    java.lang.reflect.Method r1 = androidx.core.content.res.h.g.a.f1666b     // Catch: java.lang.Throwable -> L3a
                    if (r1 == 0) goto L38
                    java.lang.Object[] r2 = new java.lang.Object[r2]     // Catch: java.lang.Throwable -> L2d java.lang.Throwable -> L3a
                    r1.invoke(r6, r2)     // Catch: java.lang.Throwable -> L2d java.lang.Throwable -> L3a
                    goto L38
                L2d:
                    r6 = move-exception
                    java.lang.String r1 = "ResourcesCompat"
                    java.lang.String r2 = "Failed to invoke rebase() method via reflection"
                    android.util.Log.i(r1, r2, r6)     // Catch: java.lang.Throwable -> L3a
                    r6 = 0
                    androidx.core.content.res.h.g.a.f1666b = r6     // Catch: java.lang.Throwable -> L3a
                L38:
                    monitor-exit(r0)     // Catch: java.lang.Throwable -> L3a
                    return
                L3a:
                    r6 = move-exception
                    monitor-exit(r0)     // Catch: java.lang.Throwable -> L3a
                    throw r6
                */
                throw new UnsupportedOperationException("Method not decompiled: androidx.core.content.res.h.g.a.a(android.content.res.Resources$Theme):void");
            }
        }

        /* JADX INFO: compiled from: ResourcesCompat.java */
        static class b {
            static void a(Resources.Theme theme) {
                theme.rebase();
            }
        }

        public static void a(Resources.Theme theme) {
            int i3 = Build.VERSION.SDK_INT;
            if (i3 >= 29) {
                b.a(theme);
            } else if (i3 >= 23) {
                a.a(theme);
            }
        }
    }

    private static void a(e eVar, int i3, ColorStateList colorStateList, Resources.Theme theme) {
        synchronized (f1659c) {
            WeakHashMap<e, SparseArray<d>> weakHashMap = f1658b;
            SparseArray<d> sparseArray = weakHashMap.get(eVar);
            if (sparseArray == null) {
                sparseArray = new SparseArray<>();
                weakHashMap.put(eVar, sparseArray);
            }
            sparseArray.append(i3, new d(colorStateList, eVar.f1663a.getConfiguration(), theme));
        }
    }

    private static ColorStateList b(e eVar, int i3) {
        d dVar;
        Resources.Theme theme;
        synchronized (f1659c) {
            SparseArray<d> sparseArray = f1658b.get(eVar);
            if (sparseArray != null && sparseArray.size() > 0 && (dVar = sparseArray.get(i3)) != null) {
                if (dVar.f1661b.equals(eVar.f1663a.getConfiguration()) && (((theme = eVar.f1664b) == null && dVar.f1662c == 0) || (theme != null && dVar.f1662c == theme.hashCode()))) {
                    return dVar.f1660a;
                }
                sparseArray.remove(i3);
            }
            return null;
        }
    }

    public static Typeface c(Context context, int i3) throws Resources.NotFoundException {
        if (context.isRestricted()) {
            return null;
        }
        return m(context, i3, new TypedValue(), 0, null, null, false, true);
    }

    public static ColorStateList d(Resources resources, int i3, Resources.Theme theme) throws Resources.NotFoundException {
        e eVar = new e(resources, theme);
        ColorStateList colorStateListB = b(eVar, i3);
        if (colorStateListB != null) {
            return colorStateListB;
        }
        ColorStateList colorStateListK = k(resources, i3, theme);
        if (colorStateListK == null) {
            return Build.VERSION.SDK_INT >= 23 ? c.b(resources, i3, theme) : resources.getColorStateList(i3);
        }
        a(eVar, i3, colorStateListK, theme);
        return colorStateListK;
    }

    public static Drawable e(Resources resources, int i3, Resources.Theme theme) throws Resources.NotFoundException {
        return Build.VERSION.SDK_INT >= 21 ? b.a(resources, i3, theme) : resources.getDrawable(i3);
    }

    public static Drawable f(Resources resources, int i3, int i4, Resources.Theme theme) throws Resources.NotFoundException {
        int i5 = Build.VERSION.SDK_INT;
        return i5 >= 21 ? b.b(resources, i3, i4, theme) : i5 >= 15 ? a.a(resources, i3, i4) : resources.getDrawable(i3);
    }

    public static Typeface g(Context context, int i3) throws Resources.NotFoundException {
        if (context.isRestricted()) {
            return null;
        }
        return m(context, i3, new TypedValue(), 0, null, null, false, false);
    }

    public static Typeface h(Context context, int i3, TypedValue typedValue, int i4, f fVar) throws Resources.NotFoundException {
        if (context.isRestricted()) {
            return null;
        }
        return m(context, i3, typedValue, i4, fVar, null, true, false);
    }

    public static void i(Context context, int i3, f fVar, Handler handler) throws Resources.NotFoundException {
        androidx.core.util.h.f(fVar);
        if (context.isRestricted()) {
            fVar.c(-4, handler);
        } else {
            m(context, i3, new TypedValue(), 0, fVar, handler, false, false);
        }
    }

    private static TypedValue j() {
        ThreadLocal<TypedValue> threadLocal = f1657a;
        TypedValue typedValue = threadLocal.get();
        if (typedValue != null) {
            return typedValue;
        }
        TypedValue typedValue2 = new TypedValue();
        threadLocal.set(typedValue2);
        return typedValue2;
    }

    private static ColorStateList k(Resources resources, int i3, Resources.Theme theme) {
        if (l(resources, i3)) {
            return null;
        }
        try {
            return androidx.core.content.res.c.a(resources, resources.getXml(i3), theme);
        } catch (Exception e3) {
            Log.w("ResourcesCompat", "Failed to inflate ColorStateList, leaving it to the framework", e3);
            return null;
        }
    }

    private static boolean l(Resources resources, int i3) {
        TypedValue typedValueJ = j();
        resources.getValue(i3, typedValueJ, true);
        int i4 = typedValueJ.type;
        return i4 >= 28 && i4 <= 31;
    }

    private static Typeface m(Context context, int i3, TypedValue typedValue, int i4, f fVar, Handler handler, boolean z2, boolean z3) {
        Resources resources = context.getResources();
        resources.getValue(i3, typedValue, true);
        Typeface typefaceN = n(context, resources, typedValue, i3, i4, fVar, handler, z2, z3);
        if (typefaceN != null || fVar != null || z3) {
            return typefaceN;
        }
        throw new Resources.NotFoundException("Font resource ID #0x" + Integer.toHexString(i3) + " could not be retrieved.");
    }

    /* JADX WARN: Removed duplicated region for block: B:37:0x00b7  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private static android.graphics.Typeface n(android.content.Context r17, android.content.res.Resources r18, android.util.TypedValue r19, int r20, int r21, androidx.core.content.res.h.f r22, android.os.Handler r23, boolean r24, boolean r25) {
        /*
            Method dump skipped, instruction units count: 234
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.core.content.res.h.n(android.content.Context, android.content.res.Resources, android.util.TypedValue, int, int, androidx.core.content.res.h$f, android.os.Handler, boolean, boolean):android.graphics.Typeface");
    }
}
