package com.google.android.material.textfield;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Typeface;
import android.os.Build;
import android.text.TextUtils;
import android.util.Property;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.widget.d0;
import androidx.core.view.y;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: compiled from: IndicatorViewController.java */
/* JADX INFO: loaded from: classes.dex */
final class g {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final TextInputLayout f4302b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private LinearLayout f4303c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private int f4304d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private FrameLayout f4305e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private Animator f4306f;

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private int f4308h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private int f4309i;

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

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private TextView f4312l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private CharSequence f4313m;

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

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

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    private CharSequence f4316p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    private boolean f4317q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    private TextView f4318r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    private int f4319s;

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

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

    /* JADX INFO: compiled from: IndicatorViewController.java */
    class a extends AnimatorListenerAdapter {

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

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

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

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        final /* synthetic */ TextView f4325d;

        a(int i3, TextView textView, int i4, TextView textView2) {
            this.f4322a = i3;
            this.f4323b = textView;
            this.f4324c = i4;
            this.f4325d = textView2;
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
            g.this.f4308h = this.f4322a;
            g.this.f4306f = null;
            TextView textView = this.f4323b;
            if (textView != null) {
                textView.setVisibility(4);
                if (this.f4324c == 1 && g.this.f4312l != null) {
                    g.this.f4312l.setText((CharSequence) null);
                }
            }
            TextView textView2 = this.f4325d;
            if (textView2 != null) {
                textView2.setTranslationY(0.0f);
                this.f4325d.setAlpha(1.0f);
            }
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationStart(Animator animator) {
            TextView textView = this.f4325d;
            if (textView != null) {
                textView.setVisibility(0);
            }
        }
    }

    /* JADX INFO: compiled from: IndicatorViewController.java */
    class b extends View.AccessibilityDelegate {
        b() {
        }

        @Override // android.view.View.AccessibilityDelegate
        public void onInitializeAccessibilityNodeInfo(View view, AccessibilityNodeInfo accessibilityNodeInfo) {
            super.onInitializeAccessibilityNodeInfo(view, accessibilityNodeInfo);
            EditText editText = g.this.f4302b.getEditText();
            if (editText != null) {
                accessibilityNodeInfo.setLabeledBy(editText);
            }
        }
    }

    public g(TextInputLayout textInputLayout) {
        this.f4301a = textInputLayout.getContext();
        this.f4302b = textInputLayout;
        this.f4307g = r0.getResources().getDimensionPixelSize(l0.d.f5357h);
    }

    private void C(int i3, int i4) {
        TextView textViewM;
        TextView textViewM2;
        if (i3 == i4) {
            return;
        }
        if (i4 != 0 && (textViewM2 = m(i4)) != null) {
            textViewM2.setVisibility(0);
            textViewM2.setAlpha(1.0f);
        }
        if (i3 != 0 && (textViewM = m(i3)) != null) {
            textViewM.setVisibility(4);
            if (i3 == 1) {
                textViewM.setText((CharSequence) null);
            }
        }
        this.f4308h = i4;
    }

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

    private void M(ViewGroup viewGroup, int i3) {
        if (i3 == 0) {
            viewGroup.setVisibility(8);
        }
    }

    private boolean N(TextView textView, CharSequence charSequence) {
        return y.V(this.f4302b) && this.f4302b.isEnabled() && !(this.f4309i == this.f4308h && textView != null && TextUtils.equals(textView.getText(), charSequence));
    }

    private void Q(int i3, int i4, boolean z2) {
        if (i3 == i4) {
            return;
        }
        if (z2) {
            AnimatorSet animatorSet = new AnimatorSet();
            this.f4306f = animatorSet;
            ArrayList arrayList = new ArrayList();
            i(arrayList, this.f4317q, this.f4318r, 2, i3, i4);
            i(arrayList, this.f4311k, this.f4312l, 1, i3, i4);
            m0.b.a(animatorSet, arrayList);
            animatorSet.addListener(new a(i4, m(i3), i3, m(i4)));
            animatorSet.start();
        } else {
            C(i3, i4);
        }
        this.f4302b.r0();
        this.f4302b.w0(z2);
        this.f4302b.E0();
    }

    private boolean g() {
        return (this.f4303c == null || this.f4302b.getEditText() == null) ? false : true;
    }

    private void i(List<Animator> list, boolean z2, TextView textView, int i3, int i4, int i5) {
        if (textView == null || !z2) {
            return;
        }
        if (i3 == i5 || i3 == i4) {
            list.add(j(textView, i5 == i3));
            if (i5 == i3) {
                list.add(k(textView));
            }
        }
    }

    private ObjectAnimator j(TextView textView, boolean z2) {
        ObjectAnimator objectAnimatorOfFloat = ObjectAnimator.ofFloat(textView, (Property<TextView, Float>) View.ALPHA, z2 ? 1.0f : 0.0f);
        objectAnimatorOfFloat.setDuration(167L);
        objectAnimatorOfFloat.setInterpolator(m0.a.f5553a);
        return objectAnimatorOfFloat;
    }

    private ObjectAnimator k(TextView textView) {
        ObjectAnimator objectAnimatorOfFloat = ObjectAnimator.ofFloat(textView, (Property<TextView, Float>) View.TRANSLATION_Y, -this.f4307g, 0.0f);
        objectAnimatorOfFloat.setDuration(217L);
        objectAnimatorOfFloat.setInterpolator(m0.a.f5556d);
        return objectAnimatorOfFloat;
    }

    private TextView m(int i3) {
        if (i3 == 1) {
            return this.f4312l;
        }
        if (i3 != 2) {
            return null;
        }
        return this.f4318r;
    }

    private int u(boolean z2, int i3, int i4) {
        return z2 ? this.f4301a.getResources().getDimensionPixelSize(i3) : i4;
    }

    private boolean x(int i3) {
        return (i3 != 1 || this.f4312l == null || TextUtils.isEmpty(this.f4310j)) ? false : true;
    }

    boolean A() {
        return this.f4317q;
    }

    void B(TextView textView, int i3) {
        FrameLayout frameLayout;
        if (this.f4303c == null) {
            return;
        }
        if (!y(i3) || (frameLayout = this.f4305e) == null) {
            this.f4303c.removeView(textView);
        } else {
            frameLayout.removeView(textView);
        }
        int i4 = this.f4304d - 1;
        this.f4304d = i4;
        M(this.f4303c, i4);
    }

    void D(CharSequence charSequence) {
        this.f4313m = charSequence;
        TextView textView = this.f4312l;
        if (textView != null) {
            textView.setContentDescription(charSequence);
        }
    }

    void E(boolean z2) {
        if (this.f4311k == z2) {
            return;
        }
        h();
        if (z2) {
            d0 d0Var = new d0(this.f4301a);
            this.f4312l = d0Var;
            d0Var.setId(l0.f.L);
            if (Build.VERSION.SDK_INT >= 17) {
                this.f4312l.setTextAlignment(5);
            }
            Typeface typeface = this.f4321u;
            if (typeface != null) {
                this.f4312l.setTypeface(typeface);
            }
            F(this.f4314n);
            G(this.f4315o);
            D(this.f4313m);
            this.f4312l.setVisibility(4);
            y.t0(this.f4312l, 1);
            e(this.f4312l, 0);
        } else {
            v();
            B(this.f4312l, 0);
            this.f4312l = null;
            this.f4302b.r0();
            this.f4302b.E0();
        }
        this.f4311k = z2;
    }

    void F(int i3) {
        this.f4314n = i3;
        TextView textView = this.f4312l;
        if (textView != null) {
            this.f4302b.d0(textView, i3);
        }
    }

    void G(ColorStateList colorStateList) {
        this.f4315o = colorStateList;
        TextView textView = this.f4312l;
        if (textView == null || colorStateList == null) {
            return;
        }
        textView.setTextColor(colorStateList);
    }

    void H(int i3) {
        this.f4319s = i3;
        TextView textView = this.f4318r;
        if (textView != null) {
            androidx.core.widget.j.n(textView, i3);
        }
    }

    void I(boolean z2) {
        if (this.f4317q == z2) {
            return;
        }
        h();
        if (z2) {
            d0 d0Var = new d0(this.f4301a);
            this.f4318r = d0Var;
            d0Var.setId(l0.f.M);
            int i3 = Build.VERSION.SDK_INT;
            if (i3 >= 17) {
                this.f4318r.setTextAlignment(5);
            }
            Typeface typeface = this.f4321u;
            if (typeface != null) {
                this.f4318r.setTypeface(typeface);
            }
            this.f4318r.setVisibility(4);
            y.t0(this.f4318r, 1);
            H(this.f4319s);
            J(this.f4320t);
            e(this.f4318r, 1);
            if (i3 >= 17) {
                this.f4318r.setAccessibilityDelegate(new b());
            }
        } else {
            w();
            B(this.f4318r, 1);
            this.f4318r = null;
            this.f4302b.r0();
            this.f4302b.E0();
        }
        this.f4317q = z2;
    }

    void J(ColorStateList colorStateList) {
        this.f4320t = colorStateList;
        TextView textView = this.f4318r;
        if (textView == null || colorStateList == null) {
            return;
        }
        textView.setTextColor(colorStateList);
    }

    void L(Typeface typeface) {
        if (typeface != this.f4321u) {
            this.f4321u = typeface;
            K(this.f4312l, typeface);
            K(this.f4318r, typeface);
        }
    }

    void O(CharSequence charSequence) {
        h();
        this.f4310j = charSequence;
        this.f4312l.setText(charSequence);
        int i3 = this.f4308h;
        if (i3 != 1) {
            this.f4309i = 1;
        }
        Q(i3, this.f4309i, N(this.f4312l, charSequence));
    }

    void P(CharSequence charSequence) {
        h();
        this.f4316p = charSequence;
        this.f4318r.setText(charSequence);
        int i3 = this.f4308h;
        if (i3 != 2) {
            this.f4309i = 2;
        }
        Q(i3, this.f4309i, N(this.f4318r, charSequence));
    }

    void e(TextView textView, int i3) {
        if (this.f4303c == null && this.f4305e == null) {
            LinearLayout linearLayout = new LinearLayout(this.f4301a);
            this.f4303c = linearLayout;
            linearLayout.setOrientation(0);
            this.f4302b.addView(this.f4303c, -1, -2);
            this.f4305e = new FrameLayout(this.f4301a);
            this.f4303c.addView(this.f4305e, new LinearLayout.LayoutParams(0, -2, 1.0f));
            if (this.f4302b.getEditText() != null) {
                f();
            }
        }
        if (y(i3)) {
            this.f4305e.setVisibility(0);
            this.f4305e.addView(textView);
        } else {
            this.f4303c.addView(textView, new LinearLayout.LayoutParams(-2, -2));
        }
        this.f4303c.setVisibility(0);
        this.f4304d++;
    }

    void f() {
        if (g()) {
            EditText editText = this.f4302b.getEditText();
            boolean zG = z0.c.g(this.f4301a);
            LinearLayout linearLayout = this.f4303c;
            int i3 = l0.d.f5369t;
            y.E0(linearLayout, u(zG, i3, y.J(editText)), u(zG, l0.d.f5370u, this.f4301a.getResources().getDimensionPixelSize(l0.d.f5368s)), u(zG, i3, y.I(editText)), 0);
        }
    }

    void h() {
        Animator animator = this.f4306f;
        if (animator != null) {
            animator.cancel();
        }
    }

    boolean l() {
        return x(this.f4309i);
    }

    CharSequence n() {
        return this.f4313m;
    }

    CharSequence o() {
        return this.f4310j;
    }

    int p() {
        TextView textView = this.f4312l;
        if (textView != null) {
            return textView.getCurrentTextColor();
        }
        return -1;
    }

    ColorStateList q() {
        TextView textView = this.f4312l;
        if (textView != null) {
            return textView.getTextColors();
        }
        return null;
    }

    CharSequence r() {
        return this.f4316p;
    }

    View s() {
        return this.f4318r;
    }

    int t() {
        TextView textView = this.f4318r;
        if (textView != null) {
            return textView.getCurrentTextColor();
        }
        return -1;
    }

    void v() {
        this.f4310j = null;
        h();
        if (this.f4308h == 1) {
            if (!this.f4317q || TextUtils.isEmpty(this.f4316p)) {
                this.f4309i = 0;
            } else {
                this.f4309i = 2;
            }
        }
        Q(this.f4308h, this.f4309i, N(this.f4312l, ""));
    }

    void w() {
        h();
        int i3 = this.f4308h;
        if (i3 == 2) {
            this.f4309i = 0;
        }
        Q(i3, this.f4309i, N(this.f4318r, ""));
    }

    boolean y(int i3) {
        return i3 == 0 || i3 == 1;
    }

    boolean z() {
        return this.f4311k;
    }
}
