package o;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Handler;
import android.os.Looper;
import android.util.TypedValue;
import java.io.IOException;
import java.util.WeakHashMap;
import org.xmlpull.v1.XmlPullParserException;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.z20, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public abstract class AbstractC3060z20 {
    public static final ThreadLocal a = new ThreadLocal();
    public static final WeakHashMap b = new WeakHashMap(0);
    public static final Object c = new Object();

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

    public static Typeface b(Context context, int i, TypedValue typedValue, int i2, AbstractC0249Jp abstractC0249Jp, boolean z, boolean z2) throws Resources.NotFoundException {
        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 i3 = typedValue.assetCookie;
            C1283gN c1283gN = AbstractC1977nh0.b;
            Typeface typeface = (Typeface) c1283gN.h(AbstractC1977nh0.b(resources, i, string, i3, i2));
            if (typeface != null) {
                if (abstractC0249Jp != null) {
                    new Handler(Looper.getMainLooper()).post(new O3(19, abstractC0249Jp, typeface));
                }
                typefaceA = typeface;
            } else if (!z2) {
                try {
                    if (string.toLowerCase().endsWith(".xml")) {
                        FA faS = AbstractC2798wI.s(resources.getXml(i), resources);
                        if (faS != null) {
                            typefaceA = AbstractC1977nh0.a(context, faS, resources, i, string, typedValue.assetCookie, i2, abstractC0249Jp, z);
                        } else if (abstractC0249Jp != null) {
                            abstractC0249Jp.r(-3);
                        }
                    } else {
                        int i4 = typedValue.assetCookie;
                        Typeface typefaceI = AbstractC1977nh0.a.i(context, resources, i, string, i2);
                        if (typefaceI != null) {
                            c1283gN.l(AbstractC1977nh0.b(resources, i, string, i4, i2), typefaceI);
                        }
                        if (abstractC0249Jp != null) {
                            if (typefaceI != null) {
                                new Handler(Looper.getMainLooper()).post(new O3(19, abstractC0249Jp, typefaceI));
                            } else {
                                abstractC0249Jp.r(-3);
                            }
                        }
                        typefaceA = typefaceI;
                    }
                } catch (IOException | XmlPullParserException unused) {
                    if (abstractC0249Jp != null) {
                        abstractC0249Jp.r(-3);
                    }
                }
            }
        } else if (abstractC0249Jp != null) {
            abstractC0249Jp.r(-3);
        }
        if (typefaceA != null || abstractC0249Jp != null || z2) {
            return typefaceA;
        }
        throw new Resources.NotFoundException("Font resource ID #0x" + Integer.toHexString(i) + " could not be retrieved.");
    }
}
