package z0;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.os.Build;
import android.text.TextPaint;
import android.util.Log;
import androidx.core.content.res.h;
import l0.k;

/* JADX INFO: compiled from: TextAppearance.java */
/* JADX INFO: loaded from: classes.dex */
public class d {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final ColorStateList f5979a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final String f5980b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final int f5981c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final int f5982d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final float f5983e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final float f5984f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final float f5985g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final boolean f5986h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final float f5987i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private ColorStateList f5988j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private float f5989k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private final int f5990l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private boolean f5991m = false;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    private Typeface f5992n;

    /* JADX INFO: compiled from: TextAppearance.java */
    class a extends h.f {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final /* synthetic */ f f5993a;

        a(f fVar) {
            this.f5993a = fVar;
        }

        @Override // androidx.core.content.res.h.f
        /* JADX INFO: renamed from: h */
        public void f(int i3) {
            d.this.f5991m = true;
            this.f5993a.a(i3);
        }

        @Override // androidx.core.content.res.h.f
        /* JADX INFO: renamed from: i */
        public void g(Typeface typeface) {
            d dVar = d.this;
            dVar.f5992n = Typeface.create(typeface, dVar.f5981c);
            d.this.f5991m = true;
            this.f5993a.b(d.this.f5992n, false);
        }
    }

    /* JADX INFO: compiled from: TextAppearance.java */
    class b extends f {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final /* synthetic */ Context f5995a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ TextPaint f5996b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        final /* synthetic */ f f5997c;

        b(Context context, TextPaint textPaint, f fVar) {
            this.f5995a = context;
            this.f5996b = textPaint;
            this.f5997c = fVar;
        }

        @Override // z0.f
        public void a(int i3) {
            this.f5997c.a(i3);
        }

        @Override // z0.f
        public void b(Typeface typeface, boolean z2) {
            d.this.p(this.f5995a, this.f5996b, typeface);
            this.f5997c.b(typeface, z2);
        }
    }

    public d(Context context, int i3) {
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(i3, k.J2);
        l(typedArrayObtainStyledAttributes.getDimension(k.K2, 0.0f));
        k(c.a(context, typedArrayObtainStyledAttributes, k.N2));
        c.a(context, typedArrayObtainStyledAttributes, k.O2);
        c.a(context, typedArrayObtainStyledAttributes, k.P2);
        this.f5981c = typedArrayObtainStyledAttributes.getInt(k.M2, 0);
        this.f5982d = typedArrayObtainStyledAttributes.getInt(k.L2, 1);
        int iE = c.e(typedArrayObtainStyledAttributes, k.V2, k.U2);
        this.f5990l = typedArrayObtainStyledAttributes.getResourceId(iE, 0);
        this.f5980b = typedArrayObtainStyledAttributes.getString(iE);
        typedArrayObtainStyledAttributes.getBoolean(k.W2, false);
        this.f5979a = c.a(context, typedArrayObtainStyledAttributes, k.Q2);
        this.f5983e = typedArrayObtainStyledAttributes.getFloat(k.R2, 0.0f);
        this.f5984f = typedArrayObtainStyledAttributes.getFloat(k.S2, 0.0f);
        this.f5985g = typedArrayObtainStyledAttributes.getFloat(k.T2, 0.0f);
        typedArrayObtainStyledAttributes.recycle();
        if (Build.VERSION.SDK_INT < 21) {
            this.f5986h = false;
            this.f5987i = 0.0f;
            return;
        }
        TypedArray typedArrayObtainStyledAttributes2 = context.obtainStyledAttributes(i3, k.X1);
        int i4 = k.Y1;
        this.f5986h = typedArrayObtainStyledAttributes2.hasValue(i4);
        this.f5987i = typedArrayObtainStyledAttributes2.getFloat(i4, 0.0f);
        typedArrayObtainStyledAttributes2.recycle();
    }

    private void d() {
        String str;
        if (this.f5992n == null && (str = this.f5980b) != null) {
            this.f5992n = Typeface.create(str, this.f5981c);
        }
        if (this.f5992n == null) {
            int i3 = this.f5982d;
            if (i3 == 1) {
                this.f5992n = Typeface.SANS_SERIF;
            } else if (i3 == 2) {
                this.f5992n = Typeface.SERIF;
            } else if (i3 != 3) {
                this.f5992n = Typeface.DEFAULT;
            } else {
                this.f5992n = Typeface.MONOSPACE;
            }
            this.f5992n = Typeface.create(this.f5992n, this.f5981c);
        }
    }

    private boolean m(Context context) {
        if (e.a()) {
            return true;
        }
        int i3 = this.f5990l;
        return (i3 != 0 ? h.c(context, i3) : null) != null;
    }

    public Typeface e() {
        d();
        return this.f5992n;
    }

    public Typeface f(Context context) {
        if (this.f5991m) {
            return this.f5992n;
        }
        if (!context.isRestricted()) {
            try {
                Typeface typefaceG = h.g(context, this.f5990l);
                this.f5992n = typefaceG;
                if (typefaceG != null) {
                    this.f5992n = Typeface.create(typefaceG, this.f5981c);
                }
            } catch (Resources.NotFoundException | UnsupportedOperationException unused) {
            } catch (Exception e3) {
                Log.d("TextAppearance", "Error loading font " + this.f5980b, e3);
            }
        }
        d();
        this.f5991m = true;
        return this.f5992n;
    }

    public void g(Context context, TextPaint textPaint, f fVar) {
        p(context, textPaint, e());
        h(context, new b(context, textPaint, fVar));
    }

    public void h(Context context, f fVar) {
        if (m(context)) {
            f(context);
        } else {
            d();
        }
        int i3 = this.f5990l;
        if (i3 == 0) {
            this.f5991m = true;
        }
        if (this.f5991m) {
            fVar.b(this.f5992n, true);
            return;
        }
        try {
            h.i(context, i3, new a(fVar), null);
        } catch (Resources.NotFoundException unused) {
            this.f5991m = true;
            fVar.a(1);
        } catch (Exception e3) {
            Log.d("TextAppearance", "Error loading font " + this.f5980b, e3);
            this.f5991m = true;
            fVar.a(-3);
        }
    }

    public ColorStateList i() {
        return this.f5988j;
    }

    public float j() {
        return this.f5989k;
    }

    public void k(ColorStateList colorStateList) {
        this.f5988j = colorStateList;
    }

    public void l(float f3) {
        this.f5989k = f3;
    }

    public void n(Context context, TextPaint textPaint, f fVar) {
        o(context, textPaint, fVar);
        ColorStateList colorStateList = this.f5988j;
        textPaint.setColor(colorStateList != null ? colorStateList.getColorForState(textPaint.drawableState, colorStateList.getDefaultColor()) : -16777216);
        float f3 = this.f5985g;
        float f4 = this.f5983e;
        float f5 = this.f5984f;
        ColorStateList colorStateList2 = this.f5979a;
        textPaint.setShadowLayer(f3, f4, f5, colorStateList2 != null ? colorStateList2.getColorForState(textPaint.drawableState, colorStateList2.getDefaultColor()) : 0);
    }

    public void o(Context context, TextPaint textPaint, f fVar) {
        if (m(context)) {
            p(context, textPaint, f(context));
        } else {
            g(context, textPaint, fVar);
        }
    }

    public void p(Context context, TextPaint textPaint, Typeface typeface) {
        Typeface typefaceA = g.a(context, typeface);
        if (typefaceA != null) {
            typeface = typefaceA;
        }
        textPaint.setTypeface(typeface);
        int i3 = this.f5981c & (~typeface.getStyle());
        textPaint.setFakeBoldText((i3 & 1) != 0);
        textPaint.setTextSkewX((i3 & 2) != 0 ? -0.25f : 0.0f);
        textPaint.setTextSize(this.f5989k);
        if (Build.VERSION.SDK_INT < 21 || !this.f5986h) {
            return;
        }
        textPaint.setLetterSpacing(this.f5987i);
    }
}
