package c.f.d;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.util.Log;
import java.io.File;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/* JADX INFO: compiled from: TypefaceCompatApi21Impl.java */
/* JADX INFO: loaded from: classes.dex */
public class e extends j {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static Class<?> f1337b = null;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static Constructor<?> f1338c = null;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static Method f1339d = null;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static Method f1340e = null;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static boolean f1341f = false;

    public static boolean e(Object obj, String str, int i2, boolean z) throws NoSuchMethodException {
        f();
        try {
            return ((Boolean) f1339d.invoke(obj, str, Integer.valueOf(i2), Boolean.valueOf(z))).booleanValue();
        } catch (IllegalAccessException | InvocationTargetException e2) {
            throw new RuntimeException(e2);
        }
    }

    public static void f() throws NoSuchMethodException {
        Method method;
        Class<?> cls;
        Method method2;
        if (f1341f) {
            return;
        }
        f1341f = true;
        Constructor<?> constructor = null;
        try {
            cls = Class.forName("android.graphics.FontFamily");
            Constructor<?> constructor2 = cls.getConstructor(new Class[0]);
            method2 = cls.getMethod("addFontWeightStyle", String.class, Integer.TYPE, Boolean.TYPE);
            method = Typeface.class.getMethod("createFromFamiliesWithDefault", Array.newInstance(cls, 1).getClass());
            constructor = constructor2;
        } catch (ClassNotFoundException | NoSuchMethodException e2) {
            Log.e("TypefaceCompatApi21Impl", e2.getClass().getName(), e2);
            method = null;
            cls = null;
            method2 = null;
        }
        f1338c = constructor;
        f1337b = cls;
        f1339d = method2;
        f1340e = method;
    }

    @Override // c.f.d.j
    public Typeface a(Context context, c.f.c.b.h hVar, Resources resources, int i2) throws NoSuchMethodException {
        f();
        try {
            Object objNewInstance = f1338c.newInstance(new Object[0]);
            for (c.f.c.b.i iVar : hVar.a) {
                File fileQ = c.f.b.h.q(context);
                if (fileQ == null) {
                    return null;
                }
                try {
                    if (!c.f.b.h.i(fileQ, resources, iVar.f1311f)) {
                        return null;
                    }
                    if (!e(objNewInstance, fileQ.getPath(), iVar.f1307b, iVar.f1308c)) {
                        return null;
                    }
                    fileQ.delete();
                } catch (RuntimeException unused) {
                    return null;
                } finally {
                    fileQ.delete();
                }
            }
            f();
            try {
                Object objNewInstance2 = Array.newInstance(f1337b, 1);
                Array.set(objNewInstance2, 0, objNewInstance);
                return (Typeface) f1340e.invoke(null, objNewInstance2);
            } catch (IllegalAccessException | InvocationTargetException e2) {
                throw new RuntimeException(e2);
            }
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException e3) {
            throw new RuntimeException(e3);
        }
    }
}
