package androidx.core.graphics;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Build;
import android.os.CancellationSignal;
import android.os.Handler;
import androidx.core.content.res.e;
import androidx.core.content.res.h;
import androidx.core.provider.g;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static final k f1721a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static final j.e<String, Typeface> f1722b;

    /* JADX INFO: compiled from: TypefaceCompat.java */
    public static class a extends g.c {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private h.f f1723a;

        public a(h.f fVar) {
            this.f1723a = fVar;
        }

        @Override // androidx.core.provider.g.c
        public void a(int i3) {
            h.f fVar = this.f1723a;
            if (fVar != null) {
                fVar.f(i3);
            }
        }

        @Override // androidx.core.provider.g.c
        public void b(Typeface typeface) {
            h.f fVar = this.f1723a;
            if (fVar != null) {
                fVar.g(typeface);
            }
        }
    }

    static {
        int i3 = Build.VERSION.SDK_INT;
        if (i3 >= 29) {
            f1721a = new j();
        } else if (i3 >= 28) {
            f1721a = new i();
        } else if (i3 >= 26) {
            f1721a = new h();
        } else if (i3 >= 24 && g.m()) {
            f1721a = new g();
        } else if (i3 >= 21) {
            f1721a = new f();
        } else {
            f1721a = new k();
        }
        f1722b = new j.e<>(16);
    }

    public static Typeface a(Context context, Typeface typeface, int i3) {
        Typeface typefaceG;
        if (context != null) {
            return (Build.VERSION.SDK_INT >= 21 || (typefaceG = g(context, typeface, i3)) == null) ? Typeface.create(typeface, i3) : typefaceG;
        }
        throw new IllegalArgumentException("Context cannot be null");
    }

    public static Typeface b(Context context, CancellationSignal cancellationSignal, g.b[] bVarArr, int i3) {
        return f1721a.c(context, cancellationSignal, bVarArr, i3);
    }

    public static Typeface c(Context context, e.b bVar, Resources resources, int i3, String str, int i4, int i5, h.f fVar, Handler handler, boolean z2) {
        Typeface typefaceB;
        if (bVar instanceof e.C0012e) {
            e.C0012e c0012e = (e.C0012e) bVar;
            Typeface typefaceH = h(c0012e.c());
            if (typefaceH != null) {
                if (fVar != null) {
                    fVar.d(typefaceH, handler);
                }
                return typefaceH;
            }
            boolean z3 = !z2 ? fVar != null : c0012e.a() != 0;
            int iD = z2 ? c0012e.d() : -1;
            typefaceB = androidx.core.provider.g.c(context, c0012e.b(), i5, z3, iD, h.f.e(handler), new a(fVar));
        } else {
            typefaceB = f1721a.b(context, (e.c) bVar, resources, i5);
            if (fVar != null) {
                if (typefaceB != null) {
                    fVar.d(typefaceB, handler);
                } else {
                    fVar.c(-3, handler);
                }
            }
        }
        if (typefaceB != null) {
            f1722b.d(e(resources, i3, str, i4, i5), typefaceB);
        }
        return typefaceB;
    }

    public static Typeface d(Context context, Resources resources, int i3, String str, int i4, int i5) {
        Typeface typefaceE = f1721a.e(context, resources, i3, str, i5);
        if (typefaceE != null) {
            f1722b.d(e(resources, i3, str, i4, i5), typefaceE);
        }
        return typefaceE;
    }

    private static String e(Resources resources, int i3, String str, int i4, int i5) {
        return resources.getResourcePackageName(i3) + '-' + str + '-' + i4 + '-' + i3 + '-' + i5;
    }

    public static Typeface f(Resources resources, int i3, String str, int i4, int i5) {
        return f1722b.c(e(resources, i3, str, i4, i5));
    }

    private static Typeface g(Context context, Typeface typeface, int i3) {
        k kVar = f1721a;
        e.c cVarI = kVar.i(typeface);
        if (cVarI == null) {
            return null;
        }
        return kVar.b(context, cVarI, context.getResources(), i3);
    }

    private static Typeface h(String str) {
        if (str == null || str.isEmpty()) {
            return null;
        }
        Typeface typefaceCreate = Typeface.create(str, 0);
        Typeface typefaceCreate2 = Typeface.create(Typeface.DEFAULT, 0);
        if (typefaceCreate == null || typefaceCreate.equals(typefaceCreate2)) {
            return null;
        }
        return typefaceCreate;
    }
}
