package E;

import B0.A;
import N1.B0;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.util.SparseArray;
import android.util.TypedValue;
import java.io.IOException;
import java.util.WeakHashMap;
import org.xmlpull.v1.XmlPullParserException;

/* JADX INFO: loaded from: classes.dex */
public abstract class j {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final WeakHashMap f1955b = new WeakHashMap(0);

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

    public static void a(i iVar, int i, ColorStateList colorStateList, Resources.Theme theme) {
        synchronized (f1956c) {
            try {
                WeakHashMap weakHashMap = f1955b;
                SparseArray sparseArray = (SparseArray) weakHashMap.get(iVar);
                if (sparseArray == null) {
                    sparseArray = new SparseArray();
                    weakHashMap.put(iVar, sparseArray);
                }
                sparseArray.append(i, new h(colorStateList, iVar.f1952a.getConfiguration(), theme));
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:39:0x00cb  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static Typeface b(Context context, int i, TypedValue typedValue, int i5, b bVar, boolean z8, boolean z9) {
        Resources resources = context.getResources();
        resources.getValue(i, typedValue, true);
        CharSequence charSequence = typedValue.string;
        if (charSequence == null) {
            throw new Resources.NotFoundException("Resource \"" + resources.getResourceName(i) + "\" (" + Integer.toHexString(i) + ") is not a Font: " + typedValue);
        }
        String string = charSequence.toString();
        Typeface typefaceA = null;
        if (string.startsWith("res/")) {
            int i8 = typedValue.assetCookie;
            B0 b02 = F.e.f2237b;
            Typeface typeface = (Typeface) b02.h(F.e.b(resources, i, string, i8, i5));
            if (typeface != null) {
                if (bVar != null) {
                    new Handler(Looper.getMainLooper()).post(new A(bVar, 10, typeface));
                }
                typefaceA = typeface;
            } else if (!z9) {
                try {
                    if (string.toLowerCase().endsWith(".xml")) {
                        d dVarJ = b.j(resources.getXml(i), resources);
                        if (dVarJ == null) {
                            Log.e("ResourcesCompat", "Failed to find font-family tag");
                            if (bVar != null) {
                                bVar.a(-3);
                            }
                        } else {
                            typefaceA = F.e.a(context, dVarJ, resources, i, string, typedValue.assetCookie, i5, bVar, z8);
                        }
                    } else {
                        int i9 = typedValue.assetCookie;
                        Typeface typefaceL = F.e.f2236a.l(context, resources, i, string, i5);
                        if (typefaceL != null) {
                            b02.m(F.e.b(resources, i, string, i9, i5), typefaceL);
                        }
                        if (bVar != null) {
                            if (typefaceL != null) {
                                new Handler(Looper.getMainLooper()).post(new A(bVar, 10, typefaceL));
                            } else {
                                bVar.a(-3);
                            }
                        }
                        typefaceA = typefaceL;
                    }
                } catch (IOException e8) {
                    Log.e("ResourcesCompat", "Failed to read xml resource ".concat(string), e8);
                    if (bVar != null) {
                        bVar.a(-3);
                    }
                } catch (XmlPullParserException e9) {
                    Log.e("ResourcesCompat", "Failed to parse xml resource ".concat(string), e9);
                    if (bVar != null) {
                    }
                }
            }
        } else if (bVar != null) {
            bVar.a(-3);
        }
        if (typefaceA != null || bVar != null || z9) {
            return typefaceA;
        }
        throw new Resources.NotFoundException("Font resource ID #0x" + Integer.toHexString(i) + " could not be retrieved.");
    }
}
