package X6FRs_4.IMuAHx_6.X6FRs_4.PGPF6hQ_2;

import X6FRs_4.IMuAHx_6.KNBe_11.FSaI4_7;
import X6FRs_4.IMuAHx_6.X6FRs_4.PGPF6hQ_2.PGPF6hQ_2;
import android.content.Context;
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.TypedValue;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/* compiled from: ResourcesCompat.java */
/* loaded from: classes.dex */
public final class IFxWkV_5 {

    /* compiled from: ResourcesCompat.java */
    /* loaded from: classes.dex */
    public static abstract class KQgRr5e_0 {

        /* compiled from: ResourcesCompat.java */
        /* renamed from: X6FRs_4.IMuAHx_6.X6FRs_4.PGPF6hQ_2.IFxWkV_5$KQgRr5e_0$KQgRr5e_0  reason: collision with other inner class name */
        /* loaded from: classes.dex */
        public class RunnableC0045KQgRr5e_0 implements Runnable {

            /* renamed from: KQgRr5e_0  reason: collision with other field name */
            public final /* synthetic */ Typeface f514KQgRr5e_0;

            public RunnableC0045KQgRr5e_0(Typeface typeface) {
                this.f514KQgRr5e_0 = typeface;
            }

            @Override // java.lang.Runnable
            public void run() {
                KQgRr5e_0.this.onFontRetrieved(this.f514KQgRr5e_0);
            }
        }

        /* compiled from: ResourcesCompat.java */
        /* loaded from: classes.dex */
        public class QxJ9d_1 implements Runnable {
            public final /* synthetic */ int KQgRr5e_0;

            public QxJ9d_1(int i) {
                this.KQgRr5e_0 = i;
            }

            @Override // java.lang.Runnable
            public void run() {
                KQgRr5e_0.this.onFontRetrievalFailed(this.KQgRr5e_0);
            }
        }

        public final void callbackFailAsync(int i, Handler handler) {
            if (handler == null) {
                handler = new Handler(Looper.getMainLooper());
            }
            handler.post(new QxJ9d_1(i));
        }

        public final void callbackSuccessAsync(Typeface typeface, Handler handler) {
            if (handler == null) {
                handler = new Handler(Looper.getMainLooper());
            }
            handler.post(new RunnableC0045KQgRr5e_0(typeface));
        }

        public abstract void onFontRetrievalFailed(int i);

        public abstract void onFontRetrieved(Typeface typeface);
    }

    public static Drawable KQgRr5e_0(Resources resources, int i, Resources.Theme theme) throws Resources.NotFoundException {
        if (Build.VERSION.SDK_INT >= 21) {
            return resources.getDrawable(i, theme);
        }
        return resources.getDrawable(i);
    }

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

    public static void KQgRr5e_0(Context context, int i, KQgRr5e_0 kQgRr5e_0, Handler handler) throws Resources.NotFoundException {
        FSaI4_7.KQgRr5e_0(kQgRr5e_0);
        if (context.isRestricted()) {
            kQgRr5e_0.callbackFailAsync(-4, handler);
        } else {
            KQgRr5e_0(context, i, new TypedValue(), 0, kQgRr5e_0, handler, false);
        }
    }

    public static Typeface KQgRr5e_0(Context context, int i, TypedValue typedValue, int i2, KQgRr5e_0 kQgRr5e_0) throws Resources.NotFoundException {
        if (context.isRestricted()) {
            return null;
        }
        return KQgRr5e_0(context, i, typedValue, i2, kQgRr5e_0, null, true);
    }

    public static Typeface KQgRr5e_0(Context context, int i, TypedValue typedValue, int i2, KQgRr5e_0 kQgRr5e_0, Handler handler, boolean z) {
        Resources resources = context.getResources();
        resources.getValue(i, typedValue, true);
        Typeface KQgRr5e_02 = KQgRr5e_0(context, resources, typedValue, i, i2, kQgRr5e_0, handler, z);
        if (KQgRr5e_02 == null && kQgRr5e_0 == null) {
            throw new Resources.NotFoundException("Font resource ID #0x" + Integer.toHexString(i) + " could not be retrieved.");
        }
        return KQgRr5e_02;
    }

    /* JADX WARN: Removed duplicated region for block: B:35:0x00a3  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static Typeface KQgRr5e_0(Context context, Resources resources, TypedValue typedValue, int i, int i2, KQgRr5e_0 kQgRr5e_0, Handler handler, boolean z) {
        CharSequence charSequence = typedValue.string;
        if (charSequence != null) {
            String charSequence2 = charSequence.toString();
            if (!charSequence2.startsWith("res/")) {
                if (kQgRr5e_0 != null) {
                    kQgRr5e_0.callbackFailAsync(-3, handler);
                }
                return null;
            }
            Typeface KQgRr5e_02 = X6FRs_4.IMuAHx_6.IFxWkV_5.PGPF6hQ_2.KQgRr5e_0(resources, i, i2);
            if (KQgRr5e_02 != null) {
                if (kQgRr5e_0 != null) {
                    kQgRr5e_0.callbackSuccessAsync(KQgRr5e_02, handler);
                }
                return KQgRr5e_02;
            }
            try {
                if (charSequence2.toLowerCase().endsWith(".xml")) {
                    PGPF6hQ_2.KQgRr5e_0 KQgRr5e_03 = PGPF6hQ_2.KQgRr5e_0((XmlPullParser) resources.getXml(i), resources);
                    if (KQgRr5e_03 == null) {
                        Log.e("ResourcesCompat", "Failed to find font-family tag");
                        if (kQgRr5e_0 != null) {
                            kQgRr5e_0.callbackFailAsync(-3, handler);
                        }
                        return null;
                    }
                    return X6FRs_4.IMuAHx_6.IFxWkV_5.PGPF6hQ_2.KQgRr5e_0(context, KQgRr5e_03, resources, i, i2, kQgRr5e_0, handler, z);
                }
                Typeface KQgRr5e_04 = X6FRs_4.IMuAHx_6.IFxWkV_5.PGPF6hQ_2.KQgRr5e_0(context, resources, i, charSequence2, i2);
                if (kQgRr5e_0 != null) {
                    if (KQgRr5e_04 != null) {
                        kQgRr5e_0.callbackSuccessAsync(KQgRr5e_04, handler);
                    } else {
                        kQgRr5e_0.callbackFailAsync(-3, handler);
                    }
                }
                return KQgRr5e_04;
            } catch (IOException e) {
                Log.e("ResourcesCompat", "Failed to read xml resource " + charSequence2, e);
                if (kQgRr5e_0 != null) {
                    kQgRr5e_0.callbackFailAsync(-3, handler);
                }
                return null;
            } catch (XmlPullParserException e2) {
                Log.e("ResourcesCompat", "Failed to parse xml resource " + charSequence2, e2);
                if (kQgRr5e_0 != null) {
                }
                return null;
            }
        }
        throw new Resources.NotFoundException("Resource \"" + resources.getResourceName(i) + "\" (" + Integer.toHexString(i) + ") is not a Font: " + typedValue);
    }
}
