package y1;

import T.p;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.util.TypedValue;
import java.io.IOException;
import java.util.WeakHashMap;
import n.C2594v;
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 f26164a = new ThreadLocal();

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

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

    public static Typeface a(Context context, int i6) {
        if (context.isRestricted()) {
            return null;
        }
        return b(context, i6, new TypedValue(), null);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:49:0x00db  */
    /* JADX WARN: Removed duplicated region for block: B:51:0x00e0 A[ADDED_TO_REGION] */
    /* JADX WARN: Type inference failed for: r3v1 */
    /* JADX WARN: Type inference failed for: r3v10 */
    /* JADX WARN: Type inference failed for: r3v11 */
    /* JADX WARN: Type inference failed for: r3v12 */
    /* JADX WARN: Type inference failed for: r3v13 */
    /* JADX WARN: Type inference failed for: r3v14, types: [int] */
    /* JADX WARN: Type inference failed for: r3v15 */
    /* JADX WARN: Type inference failed for: r3v19 */
    /* JADX WARN: Type inference failed for: r3v2 */
    /* JADX WARN: Type inference failed for: r3v20 */
    /* JADX WARN: Type inference failed for: r3v21 */
    /* JADX WARN: Type inference failed for: r3v22 */
    /* JADX WARN: Type inference failed for: r3v3 */
    /* JADX WARN: Type inference failed for: r3v4 */
    /* JADX WARN: Type inference failed for: r3v5 */
    /* JADX WARN: Type inference failed for: r3v6 */
    /* JADX WARN: Type inference failed for: r3v7 */
    /* JADX WARN: Type inference failed for: r3v8, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r3v9 */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static Typeface b(Context context, int i6, TypedValue typedValue, p pVar) {
        ?? r32;
        p pVar2;
        XmlPullParserException xmlPullParserException;
        IOException iOException;
        ?? r33;
        ?? r34;
        ?? r35;
        Resources resources = context.getResources();
        resources.getValue(i6, typedValue, true);
        CharSequence charSequence = typedValue.string;
        if (charSequence == null) {
            throw new Resources.NotFoundException("Resource \"" + resources.getResourceName(i6) + "\" (" + Integer.toHexString(i6) + ") is not a Font: " + typedValue);
        }
        String string = charSequence.toString();
        Typeface typefaceA = null;
        if (string.startsWith("res/")) {
            int i7 = typedValue.assetCookie;
            C2594v c2594v = z1.f.f26278b;
            Typeface typeface = (Typeface) c2594v.get(z1.f.b(resources, i6, string, i7));
            if (typeface != null) {
                if (pVar != null) {
                    new Handler(Looper.getMainLooper()).post(new androidx.media3.common.j(17, pVar, typeface));
                }
                r34 = i6;
                pVar2 = pVar;
                typefaceA = typeface;
            } else {
                try {
                    r32 = ".xml";
                    try {
                    } catch (IOException e6) {
                        e = e6;
                        iOException = e;
                        r35 = r32;
                    } catch (XmlPullParserException e7) {
                        e = e7;
                        xmlPullParserException = e;
                        r33 = r32;
                        Log.e("ResourcesCompat", "Failed to parse xml resource ".concat(string), xmlPullParserException);
                        r34 = r33;
                        if (pVar2 != null) {
                        }
                        if (typefaceA == null) {
                        }
                        return typefaceA;
                    }
                } catch (IOException e8) {
                    e = e8;
                    r32 = i6;
                    pVar2 = pVar;
                } catch (XmlPullParserException e9) {
                    e = e9;
                    r32 = i6;
                    pVar2 = pVar;
                }
                if (string.toLowerCase().endsWith(".xml")) {
                    d dVarF = b.f(resources.getXml(i6), resources);
                    if (dVarF == null) {
                        try {
                            Log.e("ResourcesCompat", "Failed to find font-family tag");
                            if (pVar != null) {
                                pVar.k(-3);
                            }
                        } catch (IOException e10) {
                            iOException = e10;
                            r35 = i6;
                            pVar2 = pVar;
                            Log.e("ResourcesCompat", "Failed to read xml resource ".concat(string), iOException);
                            r34 = r35;
                            if (pVar2 != null) {
                            }
                        } catch (XmlPullParserException e11) {
                            xmlPullParserException = e11;
                            r33 = i6;
                            pVar2 = pVar;
                            Log.e("ResourcesCompat", "Failed to parse xml resource ".concat(string), xmlPullParserException);
                            r34 = r33;
                            if (pVar2 != null) {
                            }
                        }
                    } else {
                        r34 = i6;
                        pVar2 = pVar;
                        typefaceA = z1.f.a(context, dVarF, resources, r34 == true ? 1 : 0, string, typedValue.assetCookie, pVar2);
                    }
                    iOException = e;
                    r35 = r32;
                    Log.e("ResourcesCompat", "Failed to read xml resource ".concat(string), iOException);
                    r34 = r35;
                    if (pVar2 != null) {
                        pVar2.k(-3);
                    }
                } else {
                    r34 = i6;
                    pVar2 = pVar;
                    int i8 = typedValue.assetCookie;
                    Typeface typefaceJ = z1.f.f26277a.j(context, resources, r34 == true ? 1 : 0, string);
                    if (typefaceJ != null) {
                        c2594v.put(z1.f.b(resources, r34 == true ? 1 : 0, string, i8), typefaceJ);
                    }
                    if (pVar2 != null) {
                        if (typefaceJ != null) {
                            new Handler(Looper.getMainLooper()).post(new androidx.media3.common.j(17, pVar2, typefaceJ));
                        } else {
                            pVar2.k(-3);
                        }
                    }
                    typefaceA = typefaceJ;
                }
            }
            if (typefaceA == null || pVar2 != null) {
                return typefaceA;
            }
            throw new Resources.NotFoundException("Font resource ID #0x" + Integer.toHexString(r34) + " could not be retrieved.");
        }
        if (pVar != null) {
            pVar.k(-3);
        }
        r34 = i6;
        pVar2 = pVar;
        if (typefaceA == null) {
        }
        return typefaceA;
    }
}
