package u3;

import E.j;
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.text.TextPaint;
import android.util.Log;
import android.util.TypedValue;
import h3.AbstractC1031a;
import s7.l;

/* JADX INFO: renamed from: u3.d, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1599d {

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

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

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

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

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

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

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

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

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

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

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

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

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

    public C1599d(Context context, int i) {
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(i, AbstractC1031a.f13417x);
        this.f17482k = typedArrayObtainStyledAttributes.getDimension(0, 0.0f);
        this.f17473a = s7.d.q(context, typedArrayObtainStyledAttributes, 3);
        s7.d.q(context, typedArrayObtainStyledAttributes, 4);
        s7.d.q(context, typedArrayObtainStyledAttributes, 5);
        this.f17476d = typedArrayObtainStyledAttributes.getInt(2, 0);
        this.f17477e = typedArrayObtainStyledAttributes.getInt(1, 1);
        int i5 = typedArrayObtainStyledAttributes.hasValue(12) ? 12 : 10;
        this.f17483l = typedArrayObtainStyledAttributes.getResourceId(i5, 0);
        this.f17475c = typedArrayObtainStyledAttributes.getString(i5);
        typedArrayObtainStyledAttributes.getBoolean(14, false);
        this.f17474b = s7.d.q(context, typedArrayObtainStyledAttributes, 6);
        this.f17478f = typedArrayObtainStyledAttributes.getFloat(7, 0.0f);
        this.f17479g = typedArrayObtainStyledAttributes.getFloat(8, 0.0f);
        this.f17480h = typedArrayObtainStyledAttributes.getFloat(9, 0.0f);
        typedArrayObtainStyledAttributes.recycle();
        TypedArray typedArrayObtainStyledAttributes2 = context.obtainStyledAttributes(i, AbstractC1031a.f13410q);
        this.i = typedArrayObtainStyledAttributes2.hasValue(0);
        this.f17481j = typedArrayObtainStyledAttributes2.getFloat(0, 0.0f);
        typedArrayObtainStyledAttributes2.recycle();
    }

    public final void a() {
        String str;
        Typeface typeface = this.f17485n;
        int i = this.f17476d;
        if (typeface == null && (str = this.f17475c) != null) {
            this.f17485n = Typeface.create(str, i);
        }
        if (this.f17485n == null) {
            int i5 = this.f17477e;
            if (i5 == 1) {
                this.f17485n = Typeface.SANS_SERIF;
            } else if (i5 == 2) {
                this.f17485n = Typeface.SERIF;
            } else if (i5 != 3) {
                this.f17485n = Typeface.DEFAULT;
            } else {
                this.f17485n = Typeface.MONOSPACE;
            }
            this.f17485n = Typeface.create(this.f17485n, i);
        }
    }

    public final Typeface b(Context context) {
        if (this.f17484m) {
            return this.f17485n;
        }
        if (!context.isRestricted()) {
            try {
                int i = this.f17483l;
                ThreadLocal threadLocal = j.f1954a;
                Typeface typefaceB = context.isRestricted() ? null : j.b(context, i, new TypedValue(), 0, null, false, false);
                this.f17485n = typefaceB;
                if (typefaceB != null) {
                    this.f17485n = Typeface.create(typefaceB, this.f17476d);
                }
            } catch (Resources.NotFoundException | UnsupportedOperationException unused) {
            } catch (Exception e8) {
                Log.d("TextAppearance", "Error loading font " + this.f17475c, e8);
            }
        }
        a();
        this.f17484m = true;
        return this.f17485n;
    }

    public final void c(Context context, l lVar) {
        if (d(context)) {
            b(context);
        } else {
            a();
        }
        int i = this.f17483l;
        if (i == 0) {
            this.f17484m = true;
        }
        if (this.f17484m) {
            lVar.u(this.f17485n, true);
            return;
        }
        try {
            C1597b c1597b = new C1597b(this, lVar);
            ThreadLocal threadLocal = j.f1954a;
            if (context.isRestricted()) {
                c1597b.a(-4);
            } else {
                j.b(context, i, new TypedValue(), 0, c1597b, false, false);
            }
        } catch (Resources.NotFoundException unused) {
            this.f17484m = true;
            lVar.t(1);
        } catch (Exception e8) {
            Log.d("TextAppearance", "Error loading font " + this.f17475c, e8);
            this.f17484m = true;
            lVar.t(-3);
        }
    }

    public final boolean d(Context context) {
        Typeface typefaceB = null;
        int i = this.f17483l;
        if (i != 0) {
            ThreadLocal threadLocal = j.f1954a;
            if (!context.isRestricted()) {
                typefaceB = j.b(context, i, new TypedValue(), 0, null, false, true);
            }
        }
        return typefaceB != null;
    }

    public final void e(Context context, TextPaint textPaint, l lVar) {
        f(context, textPaint, lVar);
        ColorStateList colorStateList = this.f17473a;
        textPaint.setColor(colorStateList != null ? colorStateList.getColorForState(textPaint.drawableState, colorStateList.getDefaultColor()) : -16777216);
        ColorStateList colorStateList2 = this.f17474b;
        textPaint.setShadowLayer(this.f17480h, this.f17478f, this.f17479g, colorStateList2 != null ? colorStateList2.getColorForState(textPaint.drawableState, colorStateList2.getDefaultColor()) : 0);
    }

    public final void f(Context context, TextPaint textPaint, l lVar) {
        if (d(context)) {
            g(textPaint, b(context));
            return;
        }
        a();
        g(textPaint, this.f17485n);
        c(context, new C1598c(this, textPaint, lVar));
    }

    public final void g(TextPaint textPaint, Typeface typeface) {
        textPaint.setTypeface(typeface);
        int i = (~typeface.getStyle()) & this.f17476d;
        textPaint.setFakeBoldText((i & 1) != 0);
        textPaint.setTextSkewX((i & 2) != 0 ? -0.25f : 0.0f);
        textPaint.setTextSize(this.f17482k);
        if (this.i) {
            textPaint.setLetterSpacing(this.f17481j);
        }
    }
}
