package c.e.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: loaded from: classes.dex */
public class d extends i {

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

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

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

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

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

    public static boolean e(Object obj, String str, int i2, boolean z) throws NoSuchMethodException {
        f();
        try {
            return ((Boolean) f5196d.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 (f5198f) {
            return;
        }
        f5198f = 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;
        }
        f5195c = constructor;
        f5194b = cls;
        f5196d = method2;
        f5197e = method;
    }

    @Override // c.e.d.i
    public Typeface a(Context context, c.e.c.b.b bVar, Resources resources, int i2) throws NoSuchMethodException {
        f();
        try {
            Object objNewInstance = f5195c.newInstance(new Object[0]);
            for (c.e.c.b.c cVar : bVar.f5167a) {
                File fileJ = c.e.b.a.j(context);
                if (fileJ == null) {
                    return null;
                }
                try {
                    if (!c.e.b.a.e(fileJ, resources, cVar.f5173f)) {
                        return null;
                    }
                    if (!e(objNewInstance, fileJ.getPath(), cVar.f5169b, cVar.f5170c)) {
                        return null;
                    }
                } catch (RuntimeException unused) {
                    return null;
                } finally {
                    fileJ.delete();
                }
            }
            f();
            try {
                Object objNewInstance2 = Array.newInstance(f5194b, 1);
                Array.set(objNewInstance2, 0, objNewInstance);
                return (Typeface) f5197e.invoke(null, objNewInstance2);
            } catch (IllegalAccessException | InvocationTargetException e2) {
                throw new RuntimeException(e2);
            }
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException e3) {
            throw new RuntimeException(e3);
        }
    }
}
