package com.google.android.material.textfield;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.util.Property;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: loaded from: classes2.dex */
public final class s {

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

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

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

    @Nullable
    private Animator captionAnimator;

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

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

    @Nullable
    private CharSequence errorText;

    @Nullable
    private TextView errorView;

    @Nullable
    private CharSequence errorViewContentDescription;

    @Nullable
    private ColorStateList errorViewTextColor;

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

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

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

    @Nullable
    private TextView helperTextView;

    @Nullable
    private ColorStateList helperTextViewTextColor;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public LinearLayout f23456i;

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

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

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

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

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

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

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public int f23463p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public int f23464q;

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

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

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

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

    public s(TextInputLayout textInputLayout) {
        Context context = textInputLayout.getContext();
        this.f23454g = context;
        this.f23455h = textInputLayout;
        this.f23459l = context.getResources().getDimensionPixelSize(x8.e.design_textinput_caption_translate_y);
        int i10 = x8.c.motionDurationShort4;
        this.f23448a = com.bumptech.glide.f.o(context, i10, 217);
        this.f23449b = com.bumptech.glide.f.o(context, x8.c.motionDurationMedium4, 167);
        this.f23450c = com.bumptech.glide.f.o(context, i10, 167);
        int i11 = x8.c.motionEasingEmphasizedDecelerateInterpolator;
        this.f23451d = com.bumptech.glide.f.p(context, i11, y8.a.f36867d);
        LinearInterpolator linearInterpolator = y8.a.f36864a;
        this.f23452e = com.bumptech.glide.f.p(context, i11, linearInterpolator);
        this.f23453f = com.bumptech.glide.f.p(context, x8.c.motionEasingLinearInterpolator, linearInterpolator);
    }

    private void createCaptionAnimators(@NonNull List<Animator> list, boolean z10, @Nullable TextView textView, int i10, int i11, int i12) {
        if (textView == null || !z10) {
            return;
        }
        if (i10 == i12 || i10 == i11) {
            boolean z11 = i12 == i10;
            ObjectAnimator objectAnimatorOfFloat = ObjectAnimator.ofFloat(textView, (Property<TextView, Float>) View.ALPHA, z11 ? 1.0f : 0.0f);
            int i13 = this.f23450c;
            objectAnimatorOfFloat.setDuration(z11 ? this.f23449b : i13);
            objectAnimatorOfFloat.setInterpolator(z11 ? this.f23452e : this.f23453f);
            if (i10 == i12 && i11 != 0) {
                objectAnimatorOfFloat.setStartDelay(i13);
            }
            list.add(objectAnimatorOfFloat);
            if (i12 != i10 || i11 == 0) {
                return;
            }
            ObjectAnimator objectAnimatorOfFloat2 = ObjectAnimator.ofFloat(textView, (Property<TextView, Float>) View.TRANSLATION_Y, -this.f23459l, 0.0f);
            objectAnimatorOfFloat2.setDuration(this.f23448a);
            objectAnimatorOfFloat2.setInterpolator(this.f23451d);
            objectAnimatorOfFloat2.setStartDelay(i13);
            list.add(objectAnimatorOfFloat2);
        }
    }

    @Nullable
    private TextView getCaptionViewFromDisplayState(int i10) {
        if (i10 == 1) {
            return this.errorView;
        }
        if (i10 != 2) {
            return null;
        }
        return this.helperTextView;
    }

    private void setTextViewTypeface(@Nullable TextView textView, Typeface typeface) {
        if (textView != null) {
            textView.setTypeface(typeface);
        }
    }

    private boolean shouldAnimateCaptionView(@Nullable TextView textView, @NonNull CharSequence charSequence) {
        TextInputLayout textInputLayout = this.f23455h;
        return textInputLayout.isLaidOut() && textInputLayout.isEnabled() && !(this.f23461n == this.f23460m && textView != null && TextUtils.equals(textView.getText(), charSequence));
    }

    public final void c(TextView textView, int i10) {
        if (this.f23456i == null && this.f23458k == null) {
            Context context = this.f23454g;
            LinearLayout linearLayout = new LinearLayout(context);
            this.f23456i = linearLayout;
            linearLayout.setOrientation(0);
            LinearLayout linearLayout2 = this.f23456i;
            TextInputLayout textInputLayout = this.f23455h;
            textInputLayout.addView(linearLayout2, -1, -2);
            this.f23458k = new FrameLayout(context);
            this.f23456i.addView(this.f23458k, new LinearLayout.LayoutParams(0, -2, 1.0f));
            if (textInputLayout.getEditText() != null) {
                d();
            }
        }
        if (i10 == 0 || i10 == 1) {
            this.f23458k.setVisibility(0);
            this.f23458k.addView(textView);
        } else {
            this.f23456i.addView(textView, new LinearLayout.LayoutParams(-2, -2));
        }
        this.f23456i.setVisibility(0);
        this.f23457j++;
    }

    public final void d() {
        if (this.f23456i != null) {
            TextInputLayout textInputLayout = this.f23455h;
            if (textInputLayout.getEditText() != null) {
                EditText editText = textInputLayout.getEditText();
                Context context = this.f23454g;
                boolean zC = q9.d.c(context);
                LinearLayout linearLayout = this.f23456i;
                int i10 = x8.e.material_helper_text_font_1_3_padding_horizontal;
                int paddingStart = editText.getPaddingStart();
                if (zC) {
                    paddingStart = context.getResources().getDimensionPixelSize(i10);
                }
                int i11 = x8.e.material_helper_text_font_1_3_padding_top;
                int dimensionPixelSize = context.getResources().getDimensionPixelSize(x8.e.material_helper_text_default_padding_top);
                if (zC) {
                    dimensionPixelSize = context.getResources().getDimensionPixelSize(i11);
                }
                int paddingEnd = editText.getPaddingEnd();
                if (zC) {
                    paddingEnd = context.getResources().getDimensionPixelSize(i10);
                }
                linearLayout.setPaddingRelative(paddingStart, dimensionPixelSize, paddingEnd, 0);
            }
        }
    }

    public final void e() {
        Animator animator = this.captionAnimator;
        if (animator != null) {
            animator.cancel();
        }
    }

    public final boolean f() {
        return (this.f23461n != 1 || this.errorView == null || TextUtils.isEmpty(this.errorText)) ? false : true;
    }

    public final int g() {
        TextView textView = this.errorView;
        if (textView != null) {
            return textView.getCurrentTextColor();
        }
        return -1;
    }

    @Nullable
    public CharSequence getErrorContentDescription() {
        return this.errorViewContentDescription;
    }

    @Nullable
    public CharSequence getErrorText() {
        return this.errorText;
    }

    @Nullable
    public ColorStateList getErrorViewTextColors() {
        TextView textView = this.errorView;
        if (textView != null) {
            return textView.getTextColors();
        }
        return null;
    }

    @Nullable
    public View getHelperTextView() {
        return this.helperTextView;
    }

    @Nullable
    public ColorStateList getHelperTextViewColors() {
        TextView textView = this.helperTextView;
        if (textView != null) {
            return textView.getTextColors();
        }
        return null;
    }

    public final int h() {
        TextView textView = this.helperTextView;
        if (textView != null) {
            return textView.getCurrentTextColor();
        }
        return -1;
    }

    public final void i() {
        this.errorText = null;
        e();
        if (this.f23460m == 1) {
            if (!this.f23466s || TextUtils.isEmpty(this.f23465r)) {
                this.f23461n = 0;
            } else {
                this.f23461n = 2;
            }
        }
        s(this.f23460m, this.f23461n, shouldAnimateCaptionView(this.errorView, ""));
    }

    public final void j(TextView textView, int i10) {
        FrameLayout frameLayout;
        LinearLayout linearLayout = this.f23456i;
        if (linearLayout == null) {
            return;
        }
        if ((i10 == 0 || i10 == 1) && (frameLayout = this.f23458k) != null) {
            frameLayout.removeView(textView);
        } else {
            linearLayout.removeView(textView);
        }
        int i11 = this.f23457j - 1;
        this.f23457j = i11;
        LinearLayout linearLayout2 = this.f23456i;
        if (i11 == 0) {
            linearLayout2.setVisibility(8);
        }
    }

    public final void k(int i10) {
        this.f23463p = i10;
        TextView textView = this.errorView;
        if (textView != null) {
            textView.setAccessibilityLiveRegion(i10);
        }
    }

    public final void l(boolean z10) {
        if (this.f23462o == z10) {
            return;
        }
        e();
        if (z10) {
            AppCompatTextView appCompatTextView = new AppCompatTextView(this.f23454g);
            this.errorView = appCompatTextView;
            appCompatTextView.setId(x8.g.textinput_error);
            this.errorView.setTextAlignment(5);
            Typeface typeface = this.f23468u;
            if (typeface != null) {
                this.errorView.setTypeface(typeface);
            }
            m(this.f23464q);
            setErrorViewTextColor(this.errorViewTextColor);
            setErrorContentDescription(this.errorViewContentDescription);
            k(this.f23463p);
            this.errorView.setVisibility(4);
            c(this.errorView, 0);
        } else {
            i();
            j(this.errorView, 0);
            this.errorView = null;
            TextInputLayout textInputLayout = this.f23455h;
            textInputLayout.s();
            textInputLayout.x();
        }
        this.f23462o = z10;
    }

    public final void m(int i10) {
        this.f23464q = i10;
        TextView textView = this.errorView;
        if (textView != null) {
            this.f23455h.o(textView, i10);
        }
    }

    public final void n(int i10) {
        this.f23467t = i10;
        TextView textView = this.helperTextView;
        if (textView != null) {
            textView.setTextAppearance(i10);
        }
    }

    public final void o(boolean z10) {
        if (this.f23466s == z10) {
            return;
        }
        e();
        int i10 = 1;
        if (z10) {
            AppCompatTextView appCompatTextView = new AppCompatTextView(this.f23454g);
            this.helperTextView = appCompatTextView;
            appCompatTextView.setId(x8.g.textinput_helper_text);
            this.helperTextView.setTextAlignment(5);
            Typeface typeface = this.f23468u;
            if (typeface != null) {
                this.helperTextView.setTypeface(typeface);
            }
            this.helperTextView.setVisibility(4);
            this.helperTextView.setAccessibilityLiveRegion(1);
            n(this.f23467t);
            setHelperTextViewTextColor(this.helperTextViewTextColor);
            c(this.helperTextView, 1);
            this.helperTextView.setAccessibilityDelegate(new l.v(this, i10));
        } else {
            e();
            int i11 = this.f23460m;
            if (i11 == 2) {
                this.f23461n = 0;
            }
            s(i11, this.f23461n, shouldAnimateCaptionView(this.helperTextView, ""));
            j(this.helperTextView, 1);
            this.helperTextView = null;
            TextInputLayout textInputLayout = this.f23455h;
            textInputLayout.s();
            textInputLayout.x();
        }
        this.f23466s = z10;
    }

    public final void p(Typeface typeface) {
        if (typeface != this.f23468u) {
            this.f23468u = typeface;
            setTextViewTypeface(this.errorView, typeface);
            setTextViewTypeface(this.helperTextView, typeface);
        }
    }

    public final void q(CharSequence charSequence) {
        e();
        this.errorText = charSequence;
        this.errorView.setText(charSequence);
        int i10 = this.f23460m;
        if (i10 != 1) {
            this.f23461n = 1;
        }
        s(i10, this.f23461n, shouldAnimateCaptionView(this.errorView, charSequence));
    }

    public final void r(CharSequence charSequence) {
        e();
        this.f23465r = charSequence;
        this.helperTextView.setText(charSequence);
        int i10 = this.f23460m;
        if (i10 != 2) {
            this.f23461n = 2;
        }
        s(i10, this.f23461n, shouldAnimateCaptionView(this.helperTextView, charSequence));
    }

    public final void s(int i10, int i11, boolean z10) {
        TextView captionViewFromDisplayState;
        TextView captionViewFromDisplayState2;
        if (i10 == i11) {
            return;
        }
        if (z10) {
            AnimatorSet animatorSet = new AnimatorSet();
            this.captionAnimator = animatorSet;
            ArrayList arrayList = new ArrayList();
            createCaptionAnimators(arrayList, this.f23466s, this.helperTextView, 2, i10, i11);
            createCaptionAnimators(arrayList, this.f23462o, this.errorView, 1, i10, i11);
            y8.b.a(animatorSet, arrayList);
            animatorSet.addListener(new r(this, i11, getCaptionViewFromDisplayState(i10), i10, getCaptionViewFromDisplayState(i11)));
            animatorSet.start();
        } else if (i10 != i11) {
            if (i11 != 0 && (captionViewFromDisplayState2 = getCaptionViewFromDisplayState(i11)) != null) {
                captionViewFromDisplayState2.setVisibility(0);
                captionViewFromDisplayState2.setAlpha(1.0f);
            }
            if (i10 != 0 && (captionViewFromDisplayState = getCaptionViewFromDisplayState(i10)) != null) {
                captionViewFromDisplayState.setVisibility(4);
                if (i10 == 1) {
                    captionViewFromDisplayState.setText((CharSequence) null);
                }
            }
            this.f23460m = i11;
        }
        TextInputLayout textInputLayout = this.f23455h;
        textInputLayout.s();
        textInputLayout.v(z10, false);
        textInputLayout.x();
    }

    public void setErrorContentDescription(@Nullable CharSequence charSequence) {
        this.errorViewContentDescription = charSequence;
        TextView textView = this.errorView;
        if (textView != null) {
            textView.setContentDescription(charSequence);
        }
    }

    public void setErrorViewTextColor(@Nullable ColorStateList colorStateList) {
        this.errorViewTextColor = colorStateList;
        TextView textView = this.errorView;
        if (textView == null || colorStateList == null) {
            return;
        }
        textView.setTextColor(colorStateList);
    }

    public void setHelperTextViewTextColor(@Nullable ColorStateList colorStateList) {
        this.helperTextViewTextColor = colorStateList;
        TextView textView = this.helperTextView;
        if (textView == null || colorStateList == null) {
            return;
        }
        textView.setTextColor(colorStateList);
    }
}
