package d2;

import P.Q;
import android.animation.TimeInterpolator;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.os.Build;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.animation.LinearInterpolator;
import com.google.android.material.textfield.TextInputLayout;
import f2.C0592a;
import h0.C0618a;
import java.lang.reflect.Field;

/* JADX INFO: renamed from: d2.b, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0541b {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public CharSequence f6054A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public CharSequence f6055B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public boolean f6056C;

    /* JADX INFO: renamed from: E, reason: collision with root package name */
    public Bitmap f6058E;

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

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

    /* JADX INFO: renamed from: H, reason: collision with root package name */
    public float f6061H;
    public float I;
    public float J;
    public int K;

    /* JADX INFO: renamed from: L, reason: collision with root package name */
    public int[] f6062L;

    /* JADX INFO: renamed from: M, reason: collision with root package name */
    public boolean f6063M;

    /* JADX INFO: renamed from: N, reason: collision with root package name */
    public final TextPaint f6064N;

    /* JADX INFO: renamed from: O, reason: collision with root package name */
    public final TextPaint f6065O;

    /* JADX INFO: renamed from: P, reason: collision with root package name */
    public LinearInterpolator f6066P;

    /* JADX INFO: renamed from: Q, reason: collision with root package name */
    public LinearInterpolator f6067Q;

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

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

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

    /* JADX INFO: renamed from: U, reason: collision with root package name */
    public ColorStateList f6071U;

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

    /* JADX INFO: renamed from: W, reason: collision with root package name */
    public float f6073W;
    public float X;

    /* JADX INFO: renamed from: Y, reason: collision with root package name */
    public StaticLayout f6074Y;

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

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

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

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

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

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

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public CharSequence f6081c0;

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public float f6095o;
    public float p;
    public float q;

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public C0592a f6103y;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f6086f = 16;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public int f6088g = 16;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public float f6089h = 15.0f;
    public float i = 15.0f;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final TextUtils.TruncateAt f6104z = TextUtils.TruncateAt.END;

    /* JADX INFO: renamed from: D, reason: collision with root package name */
    public final boolean f6057D = true;

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public final int f6083d0 = 1;

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    public final float f6085e0 = 1.0f;

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    public final int f6087f0 = 1;

    public C0541b(TextInputLayout textInputLayout) {
        this.f6076a = textInputLayout;
        TextPaint textPaint = new TextPaint(129);
        this.f6064N = textPaint;
        this.f6065O = new TextPaint(textPaint);
        this.f6082d = new Rect();
        this.f6080c = new Rect();
        this.f6084e = new RectF();
        g(textInputLayout.getContext().getResources().getConfiguration());
    }

    public static int a(int i, int i5, float f6) {
        float f7 = 1.0f - f6;
        return Color.argb(Math.round((Color.alpha(i5) * f6) + (Color.alpha(i) * f7)), Math.round((Color.red(i5) * f6) + (Color.red(i) * f7)), Math.round((Color.green(i5) * f6) + (Color.green(i) * f7)), Math.round((Color.blue(i5) * f6) + (Color.blue(i) * f7)));
    }

    public static float f(float f6, float f7, float f8, TimeInterpolator timeInterpolator) {
        if (timeInterpolator != null) {
            f8 = timeInterpolator.getInterpolation(f8);
        }
        return R1.a.a(f6, f7, f8);
    }

    public final boolean b(CharSequence charSequence) {
        Field field = Q.f2392a;
        boolean z5 = this.f6076a.getLayoutDirection() == 1;
        if (this.f6057D) {
            return (z5 ? N.g.f2167d : N.g.f2166c).i(charSequence, charSequence.length());
        }
        return z5;
    }

    public final void c(float f6, boolean z5) {
        float f7;
        float f8;
        Typeface typeface;
        boolean z6;
        Layout.Alignment alignment;
        if (this.f6054A == null) {
            return;
        }
        float fWidth = this.f6082d.width();
        float fWidth2 = this.f6080c.width();
        if (Math.abs(f6 - 1.0f) < 1.0E-5f) {
            f7 = this.i;
            f8 = this.f6072V;
            this.f6059F = 1.0f;
            typeface = this.f6096r;
        } else {
            float f9 = this.f6089h;
            float f10 = this.f6073W;
            Typeface typeface2 = this.f6099u;
            if (Math.abs(f6 - 0.0f) < 1.0E-5f) {
                this.f6059F = 1.0f;
            } else {
                this.f6059F = f(this.f6089h, this.i, f6, this.f6067Q) / this.f6089h;
            }
            float f11 = this.i / this.f6089h;
            fWidth = (!z5 && fWidth2 * f11 > fWidth) ? Math.min(fWidth / f11, fWidth2) : fWidth2;
            f7 = f9;
            f8 = f10;
            typeface = typeface2;
        }
        TextPaint textPaint = this.f6064N;
        if (fWidth > 0.0f) {
            boolean z7 = this.f6060G != f7;
            boolean z8 = this.X != f8;
            boolean z9 = this.f6102x != typeface;
            StaticLayout staticLayout = this.f6074Y;
            boolean z10 = z7 || z8 || (staticLayout != null && (fWidth > ((float) staticLayout.getWidth()) ? 1 : (fWidth == ((float) staticLayout.getWidth()) ? 0 : -1)) != 0) || z9 || this.f6063M;
            this.f6060G = f7;
            this.X = f8;
            this.f6102x = typeface;
            this.f6063M = false;
            textPaint.setLinearText(this.f6059F != 1.0f);
            z6 = z10;
        } else {
            z6 = false;
        }
        if (this.f6055B == null || z6) {
            textPaint.setTextSize(this.f6060G);
            textPaint.setTypeface(this.f6102x);
            textPaint.setLetterSpacing(this.X);
            boolean zB = b(this.f6054A);
            this.f6056C = zB;
            int i = this.f6083d0;
            if (i <= 1 || zB) {
                i = 1;
            }
            if (i == 1) {
                alignment = Layout.Alignment.ALIGN_NORMAL;
            } else {
                int absoluteGravity = Gravity.getAbsoluteGravity(this.f6086f, zB ? 1 : 0) & 7;
                alignment = absoluteGravity != 1 ? absoluteGravity != 5 ? this.f6056C ? Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_NORMAL : this.f6056C ? Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_CENTER;
            }
            g gVar = new g(this.f6054A, textPaint, (int) fWidth);
            gVar.f6122k = this.f6104z;
            gVar.f6121j = zB;
            gVar.f6117e = alignment;
            gVar.i = false;
            gVar.f6118f = i;
            gVar.f6119g = this.f6085e0;
            gVar.f6120h = this.f6087f0;
            StaticLayout staticLayoutA = gVar.a();
            staticLayoutA.getClass();
            this.f6074Y = staticLayoutA;
            this.f6055B = staticLayoutA.getText();
        }
    }

    public final float d() {
        TextPaint textPaint = this.f6065O;
        textPaint.setTextSize(this.i);
        textPaint.setTypeface(this.f6096r);
        textPaint.setLetterSpacing(this.f6072V);
        return -textPaint.ascent();
    }

    public final int e(ColorStateList colorStateList) {
        if (colorStateList == null) {
            return 0;
        }
        int[] iArr = this.f6062L;
        return iArr != null ? colorStateList.getColorForState(iArr, 0) : colorStateList.getDefaultColor();
    }

    public final void g(Configuration configuration) {
        if (Build.VERSION.SDK_INT >= 31) {
            Typeface typeface = this.f6098t;
            if (typeface != null) {
                this.f6097s = android.support.v4.media.session.b.m(configuration, typeface);
            }
            Typeface typeface2 = this.f6101w;
            if (typeface2 != null) {
                this.f6100v = android.support.v4.media.session.b.m(configuration, typeface2);
            }
            Typeface typeface3 = this.f6097s;
            if (typeface3 == null) {
                typeface3 = this.f6098t;
            }
            this.f6096r = typeface3;
            Typeface typeface4 = this.f6100v;
            if (typeface4 == null) {
                typeface4 = this.f6101w;
            }
            this.f6099u = typeface4;
            h(true);
        }
    }

    public final void h(boolean z5) {
        float fMeasureText;
        StaticLayout staticLayout;
        TextInputLayout textInputLayout = this.f6076a;
        if ((textInputLayout.getHeight() <= 0 || textInputLayout.getWidth() <= 0) && !z5) {
            return;
        }
        c(1.0f, z5);
        CharSequence charSequence = this.f6055B;
        TextPaint textPaint = this.f6064N;
        if (charSequence != null && (staticLayout = this.f6074Y) != null) {
            this.f6081c0 = TextUtils.ellipsize(charSequence, textPaint, staticLayout.getWidth(), this.f6104z);
        }
        CharSequence charSequence2 = this.f6081c0;
        if (charSequence2 != null) {
            this.f6075Z = textPaint.measureText(charSequence2, 0, charSequence2.length());
        } else {
            this.f6075Z = 0.0f;
        }
        int absoluteGravity = Gravity.getAbsoluteGravity(this.f6088g, this.f6056C ? 1 : 0);
        int i = absoluteGravity & 112;
        Rect rect = this.f6082d;
        if (i == 48) {
            this.f6093m = rect.top;
        } else if (i != 80) {
            this.f6093m = rect.centerY() - ((textPaint.descent() - textPaint.ascent()) / 2.0f);
        } else {
            this.f6093m = textPaint.ascent() + rect.bottom;
        }
        int i5 = absoluteGravity & 8388615;
        if (i5 == 1) {
            this.f6095o = rect.centerX() - (this.f6075Z / 2.0f);
        } else if (i5 != 5) {
            this.f6095o = rect.left;
        } else {
            this.f6095o = rect.right - this.f6075Z;
        }
        c(0.0f, z5);
        float height = this.f6074Y != null ? r1.getHeight() : 0.0f;
        StaticLayout staticLayout2 = this.f6074Y;
        if (staticLayout2 == null || this.f6083d0 <= 1) {
            CharSequence charSequence3 = this.f6055B;
            fMeasureText = charSequence3 != null ? textPaint.measureText(charSequence3, 0, charSequence3.length()) : 0.0f;
        } else {
            fMeasureText = staticLayout2.getWidth();
        }
        StaticLayout staticLayout3 = this.f6074Y;
        if (staticLayout3 != null) {
            staticLayout3.getLineCount();
        }
        int absoluteGravity2 = Gravity.getAbsoluteGravity(this.f6086f, this.f6056C ? 1 : 0);
        int i6 = absoluteGravity2 & 112;
        Rect rect2 = this.f6080c;
        if (i6 == 48) {
            this.f6092l = rect2.top;
        } else if (i6 != 80) {
            this.f6092l = rect2.centerY() - (height / 2.0f);
        } else {
            this.f6092l = textPaint.descent() + (rect2.bottom - height);
        }
        int i7 = absoluteGravity2 & 8388615;
        if (i7 == 1) {
            this.f6094n = rect2.centerX() - (fMeasureText / 2.0f);
        } else if (i7 != 5) {
            this.f6094n = rect2.left;
        } else {
            this.f6094n = rect2.right - fMeasureText;
        }
        Bitmap bitmap = this.f6058E;
        if (bitmap != null) {
            bitmap.recycle();
            this.f6058E = null;
        }
        l(this.f6078b);
        float f6 = this.f6078b;
        float f7 = f(rect2.left, rect.left, f6, this.f6066P);
        RectF rectF = this.f6084e;
        rectF.left = f7;
        rectF.top = f(this.f6092l, this.f6093m, f6, this.f6066P);
        rectF.right = f(rect2.right, rect.right, f6, this.f6066P);
        rectF.bottom = f(rect2.bottom, rect.bottom, f6, this.f6066P);
        this.p = f(this.f6094n, this.f6095o, f6, this.f6066P);
        this.q = f(this.f6092l, this.f6093m, f6, this.f6066P);
        l(f6);
        C0618a c0618a = R1.a.f2624b;
        this.f6077a0 = 1.0f - f(0.0f, 1.0f, 1.0f - f6, c0618a);
        Field field = Q.f2392a;
        textInputLayout.postInvalidateOnAnimation();
        this.f6079b0 = f(1.0f, 0.0f, f6, c0618a);
        textInputLayout.postInvalidateOnAnimation();
        ColorStateList colorStateList = this.f6091k;
        ColorStateList colorStateList2 = this.f6090j;
        if (colorStateList != colorStateList2) {
            textPaint.setColor(a(e(colorStateList2), e(this.f6091k), f6));
        } else {
            textPaint.setColor(e(colorStateList));
        }
        float f8 = this.f6072V;
        float f9 = this.f6073W;
        if (f8 != f9) {
            textPaint.setLetterSpacing(f(f9, f8, f6, c0618a));
        } else {
            textPaint.setLetterSpacing(f8);
        }
        this.f6061H = R1.a.a(0.0f, this.f6068R, f6);
        this.I = R1.a.a(0.0f, this.f6069S, f6);
        this.J = R1.a.a(0.0f, this.f6070T, f6);
        int iA = a(0, e(this.f6071U), f6);
        this.K = iA;
        textPaint.setShadowLayer(this.f6061H, this.I, this.J, iA);
        textInputLayout.postInvalidateOnAnimation();
    }

    public final void i(ColorStateList colorStateList) {
        if (this.f6091k == colorStateList && this.f6090j == colorStateList) {
            return;
        }
        this.f6091k = colorStateList;
        this.f6090j = colorStateList;
        h(false);
    }

    public final boolean j(Typeface typeface) {
        C0592a c0592a = this.f6103y;
        if (c0592a != null) {
            c0592a.f6346f = true;
        }
        if (this.f6098t == typeface) {
            return false;
        }
        this.f6098t = typeface;
        Typeface typefaceM = android.support.v4.media.session.b.m(this.f6076a.getContext().getResources().getConfiguration(), typeface);
        this.f6097s = typefaceM;
        if (typefaceM == null) {
            typefaceM = this.f6098t;
        }
        this.f6096r = typefaceM;
        return true;
    }

    public final void k(float f6) {
        if (f6 < 0.0f) {
            f6 = 0.0f;
        } else if (f6 > 1.0f) {
            f6 = 1.0f;
        }
        if (f6 != this.f6078b) {
            this.f6078b = f6;
            float f7 = this.f6080c.left;
            Rect rect = this.f6082d;
            float f8 = f(f7, rect.left, f6, this.f6066P);
            RectF rectF = this.f6084e;
            rectF.left = f8;
            rectF.top = f(this.f6092l, this.f6093m, f6, this.f6066P);
            rectF.right = f(r1.right, rect.right, f6, this.f6066P);
            rectF.bottom = f(r1.bottom, rect.bottom, f6, this.f6066P);
            this.p = f(this.f6094n, this.f6095o, f6, this.f6066P);
            this.q = f(this.f6092l, this.f6093m, f6, this.f6066P);
            l(f6);
            C0618a c0618a = R1.a.f2624b;
            this.f6077a0 = 1.0f - f(0.0f, 1.0f, 1.0f - f6, c0618a);
            Field field = Q.f2392a;
            TextInputLayout textInputLayout = this.f6076a;
            textInputLayout.postInvalidateOnAnimation();
            this.f6079b0 = f(1.0f, 0.0f, f6, c0618a);
            textInputLayout.postInvalidateOnAnimation();
            ColorStateList colorStateList = this.f6091k;
            ColorStateList colorStateList2 = this.f6090j;
            TextPaint textPaint = this.f6064N;
            if (colorStateList != colorStateList2) {
                textPaint.setColor(a(e(colorStateList2), e(this.f6091k), f6));
            } else {
                textPaint.setColor(e(colorStateList));
            }
            float f9 = this.f6072V;
            float f10 = this.f6073W;
            if (f9 != f10) {
                textPaint.setLetterSpacing(f(f10, f9, f6, c0618a));
            } else {
                textPaint.setLetterSpacing(f9);
            }
            this.f6061H = R1.a.a(0.0f, this.f6068R, f6);
            this.I = R1.a.a(0.0f, this.f6069S, f6);
            this.J = R1.a.a(0.0f, this.f6070T, f6);
            int iA = a(0, e(this.f6071U), f6);
            this.K = iA;
            textPaint.setShadowLayer(this.f6061H, this.I, this.J, iA);
            textInputLayout.postInvalidateOnAnimation();
        }
    }

    public final void l(float f6) {
        c(f6, false);
        Field field = Q.f2392a;
        this.f6076a.postInvalidateOnAnimation();
    }

    public final void m(Typeface typeface) {
        boolean z5;
        boolean zJ = j(typeface);
        if (this.f6101w != typeface) {
            this.f6101w = typeface;
            Typeface typefaceM = android.support.v4.media.session.b.m(this.f6076a.getContext().getResources().getConfiguration(), typeface);
            this.f6100v = typefaceM;
            if (typefaceM == null) {
                typefaceM = this.f6101w;
            }
            this.f6099u = typefaceM;
            z5 = true;
        } else {
            z5 = false;
        }
        if (zJ || z5) {
            h(false);
        }
    }
}
