package com.google.android.material.bottomappbar;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Rect;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import androidx.appcompat.widget.ActionMenuView;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import c.f.l.t;
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class BottomAppBar extends Toolbar implements CoordinatorLayout.b {
    private final int T;
    private final d.c.a.a.r.b U;
    private final com.google.android.material.bottomappbar.a V;
    private Animator W;
    private Animator a0;
    private Animator b0;
    private int c0;
    private boolean d0;
    private boolean e0;
    AnimatorListenerAdapter f0;

    class a extends AnimatorListenerAdapter {
        a() {
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
            BottomAppBar.this.a0 = null;
        }
    }

    class b implements ValueAnimator.AnimatorUpdateListener {
        b() {
        }

        @Override // android.animation.ValueAnimator.AnimatorUpdateListener
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            BottomAppBar.this.V.j(((Float) valueAnimator.getAnimatedValue()).floatValue());
            BottomAppBar.this.U.invalidateSelf();
        }
    }

    class c extends AnimatorListenerAdapter {
        c() {
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
            BottomAppBar.this.b0 = null;
        }
    }

    class d extends AnimatorListenerAdapter {
        public boolean a;

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

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

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

        d(ActionMenuView actionMenuView, int i2, boolean z) {
            this.f1735b = actionMenuView;
            this.f1736c = i2;
            this.f1737d = z;
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationCancel(Animator animator) {
            this.a = true;
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
            if (this.a) {
                return;
            }
            BottomAppBar.this.l0(this.f1735b, this.f1736c, this.f1737d);
        }
    }

    static class e extends c.h.a.a {
        public static final Parcelable.Creator<e> CREATOR = new a();

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        int f1739g;

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

        static class a implements Parcelable.ClassLoaderCreator<e> {
            a() {
            }

            @Override // android.os.Parcelable.Creator
            /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
            public e createFromParcel(Parcel parcel) {
                return new e(parcel, null);
            }

            @Override // android.os.Parcelable.ClassLoaderCreator
            /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
            public e createFromParcel(Parcel parcel, ClassLoader classLoader) {
                return new e(parcel, classLoader);
            }

            @Override // android.os.Parcelable.Creator
            /* JADX INFO: renamed from: c, reason: merged with bridge method [inline-methods] */
            public e[] newArray(int i2) {
                return new e[i2];
            }
        }

        public e(Parcelable parcelable) {
            super(parcelable);
        }

        @Override // c.h.a.a, android.os.Parcelable
        public void writeToParcel(Parcel parcel, int i2) {
            super.writeToParcel(parcel, i2);
            parcel.writeInt(this.f1739g);
            parcel.writeInt(this.f1740h ? 1 : 0);
        }

        public e(Parcel parcel, ClassLoader classLoader) {
            super(parcel, classLoader);
            this.f1739g = parcel.readInt();
            this.f1740h = parcel.readInt() != 0;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void X(FloatingActionButton floatingActionButton) {
        j0(floatingActionButton);
        floatingActionButton.e(this.f0);
        floatingActionButton.f(this.f0);
    }

    private void Y() {
        Animator animator = this.W;
        if (animator != null) {
            animator.cancel();
        }
        Animator animator2 = this.b0;
        if (animator2 != null) {
            animator2.cancel();
        }
        Animator animator3 = this.a0;
        if (animator3 != null) {
            animator3.cancel();
        }
    }

    private void Z(int i2, List<Animator> list) {
        if (this.e0) {
            ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(this.V.e(), d0(i2));
            valueAnimatorOfFloat.addUpdateListener(new b());
            valueAnimatorOfFloat.setDuration(300L);
            list.add(valueAnimatorOfFloat);
        }
    }

    private void a0(int i2, List<Animator> list) {
        ObjectAnimator objectAnimatorOfFloat = ObjectAnimator.ofFloat(c0(), "translationX", d0(i2));
        objectAnimatorOfFloat.setDuration(300L);
        list.add(objectAnimatorOfFloat);
    }

    private void b0(int i2, boolean z, List<Animator> list) {
        ActionMenuView actionMenuView = getActionMenuView();
        if (actionMenuView == null) {
            return;
        }
        Animator animatorOfFloat = ObjectAnimator.ofFloat(actionMenuView, "alpha", 1.0f);
        if ((!this.e0 && (!z || !g0())) || (this.c0 != 1 && i2 != 1)) {
            if (actionMenuView.getAlpha() < 1.0f) {
                list.add(animatorOfFloat);
            }
        } else {
            ObjectAnimator objectAnimatorOfFloat = ObjectAnimator.ofFloat(actionMenuView, "alpha", 0.0f);
            objectAnimatorOfFloat.addListener(new d(actionMenuView, i2, z));
            AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.setDuration(150L);
            animatorSet.playSequentially(objectAnimatorOfFloat, animatorOfFloat);
            list.add(animatorSet);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public FloatingActionButton c0() {
        if (!(getParent() instanceof CoordinatorLayout)) {
            return null;
        }
        for (View view : ((CoordinatorLayout) getParent()).s(this)) {
            if (view instanceof FloatingActionButton) {
                return (FloatingActionButton) view;
            }
        }
        return null;
    }

    private int d0(int i2) {
        boolean z = t.u(this) == 1;
        if (i2 == 1) {
            return ((getMeasuredWidth() / 2) - this.T) * (z ? -1 : 1);
        }
        return 0;
    }

    private float e0(boolean z) {
        FloatingActionButton floatingActionButtonC0 = c0();
        if (floatingActionButtonC0 == null) {
            return 0.0f;
        }
        Rect rect = new Rect();
        floatingActionButtonC0.h(rect);
        float fHeight = rect.height();
        if (fHeight == 0.0f) {
            fHeight = floatingActionButtonC0.getMeasuredHeight();
        }
        float height = floatingActionButtonC0.getHeight() - rect.bottom;
        float height2 = floatingActionButtonC0.getHeight() - rect.height();
        float f2 = (-getCradleVerticalOffset()) + (fHeight / 2.0f) + height;
        float paddingBottom = height2 - floatingActionButtonC0.getPaddingBottom();
        float f3 = -getMeasuredHeight();
        if (!z) {
            f2 = paddingBottom;
        }
        return f3 + f2;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public boolean f0() {
        Animator animator;
        Animator animator2;
        Animator animator3 = this.W;
        return (animator3 != null && animator3.isRunning()) || ((animator = this.b0) != null && animator.isRunning()) || ((animator2 = this.a0) != null && animator2.isRunning());
    }

    private boolean g0() {
        FloatingActionButton floatingActionButtonC0 = c0();
        return floatingActionButtonC0 != null && floatingActionButtonC0.l();
    }

    private ActionMenuView getActionMenuView() {
        for (int i2 = 0; i2 < getChildCount(); i2++) {
            View childAt = getChildAt(i2);
            if (childAt instanceof ActionMenuView) {
                return (ActionMenuView) childAt;
            }
        }
        return null;
    }

    private float getFabTranslationX() {
        return d0(this.c0);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public float getFabTranslationY() {
        return e0(this.e0);
    }

    private void h0(int i2, boolean z) {
        if (t.H(this)) {
            Animator animator = this.b0;
            if (animator != null) {
                animator.cancel();
            }
            ArrayList arrayList = new ArrayList();
            if (!g0()) {
                i2 = 0;
                z = false;
            }
            b0(i2, z, arrayList);
            AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.playTogether(arrayList);
            this.b0 = animatorSet;
            animatorSet.addListener(new c());
            this.b0.start();
        }
    }

    private void i0(int i2) {
        if (this.c0 == i2 || !t.H(this)) {
            return;
        }
        Animator animator = this.a0;
        if (animator != null) {
            animator.cancel();
        }
        ArrayList arrayList = new ArrayList();
        Z(i2, arrayList);
        a0(i2, arrayList);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(arrayList);
        this.a0 = animatorSet;
        animatorSet.addListener(new a());
        this.a0.start();
    }

    private void j0(FloatingActionButton floatingActionButton) {
        floatingActionButton.o(this.f0);
        floatingActionButton.p(this.f0);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void k0() {
        this.V.j(getFabTranslationX());
        FloatingActionButton floatingActionButtonC0 = c0();
        this.U.b((this.e0 && g0()) ? 1.0f : 0.0f);
        if (floatingActionButtonC0 != null) {
            floatingActionButtonC0.setTranslationY(getFabTranslationY());
            floatingActionButtonC0.setTranslationX(getFabTranslationX());
        }
        ActionMenuView actionMenuView = getActionMenuView();
        if (actionMenuView != null) {
            actionMenuView.setAlpha(1.0f);
            if (g0()) {
                l0(actionMenuView, this.c0, this.e0);
            } else {
                l0(actionMenuView, 0, false);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void l0(ActionMenuView actionMenuView, int i2, boolean z) {
        boolean z2 = t.u(this) == 1;
        int iMax = 0;
        for (int i3 = 0; i3 < getChildCount(); i3++) {
            View childAt = getChildAt(i3);
            if ((childAt.getLayoutParams() instanceof Toolbar.e) && (((Toolbar.e) childAt.getLayoutParams()).a & 8388615) == 8388611) {
                iMax = Math.max(iMax, z2 ? childAt.getLeft() : childAt.getRight());
            }
        }
        actionMenuView.setTranslationX((i2 == 1 && z) ? iMax - (z2 ? actionMenuView.getRight() : actionMenuView.getLeft()) : 0.0f);
    }

    public ColorStateList getBackgroundTint() {
        return this.U.a();
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.b
    public CoordinatorLayout.c<BottomAppBar> getBehavior() {
        return new Behavior();
    }

    public float getCradleVerticalOffset() {
        return this.V.a();
    }

    public int getFabAlignmentMode() {
        return this.c0;
    }

    public float getFabCradleMargin() {
        return this.V.b();
    }

    public float getFabCradleRoundedCornerRadius() {
        return this.V.c();
    }

    public boolean getHideOnScroll() {
        return this.d0;
    }

    @Override // androidx.appcompat.widget.Toolbar, android.view.ViewGroup, android.view.View
    protected void onLayout(boolean z, int i2, int i3, int i4, int i5) {
        super.onLayout(z, i2, i3, i4, i5);
        Y();
        k0();
    }

    @Override // androidx.appcompat.widget.Toolbar, android.view.View
    protected void onRestoreInstanceState(Parcelable parcelable) {
        if (!(parcelable instanceof e)) {
            super.onRestoreInstanceState(parcelable);
            return;
        }
        e eVar = (e) parcelable;
        super.onRestoreInstanceState(eVar.a());
        this.c0 = eVar.f1739g;
        this.e0 = eVar.f1740h;
    }

    @Override // androidx.appcompat.widget.Toolbar, android.view.View
    protected Parcelable onSaveInstanceState() {
        e eVar = new e(super.onSaveInstanceState());
        eVar.f1739g = this.c0;
        eVar.f1740h = this.e0;
        return eVar;
    }

    public void setBackgroundTint(ColorStateList colorStateList) {
        androidx.core.graphics.drawable.a.o(this.U, colorStateList);
    }

    public void setCradleVerticalOffset(float f2) {
        if (f2 != getCradleVerticalOffset()) {
            this.V.f(f2);
            this.U.invalidateSelf();
        }
    }

    public void setFabAlignmentMode(int i2) {
        i0(i2);
        h0(i2, this.e0);
        this.c0 = i2;
    }

    public void setFabCradleMargin(float f2) {
        if (f2 != getFabCradleMargin()) {
            this.V.g(f2);
            this.U.invalidateSelf();
        }
    }

    public void setFabCradleRoundedCornerRadius(float f2) {
        if (f2 != getFabCradleRoundedCornerRadius()) {
            this.V.h(f2);
            this.U.invalidateSelf();
        }
    }

    void setFabDiameter(int i2) {
        float f2 = i2;
        if (f2 != this.V.d()) {
            this.V.i(f2);
            this.U.invalidateSelf();
        }
    }

    public void setHideOnScroll(boolean z) {
        this.d0 = z;
    }

    @Override // androidx.appcompat.widget.Toolbar
    public void setSubtitle(CharSequence charSequence) {
    }

    @Override // androidx.appcompat.widget.Toolbar
    public void setTitle(CharSequence charSequence) {
    }

    public static class Behavior extends HideBottomViewOnScrollBehavior<BottomAppBar> {

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

        public Behavior() {
            this.f1734d = new Rect();
        }

        private boolean L(FloatingActionButton floatingActionButton, BottomAppBar bottomAppBar) {
            ((CoordinatorLayout.f) floatingActionButton.getLayoutParams()).f588d = 17;
            bottomAppBar.X(floatingActionButton);
            return true;
        }

        @Override // com.google.android.material.behavior.HideBottomViewOnScrollBehavior, androidx.coordinatorlayout.widget.CoordinatorLayout.c
        /* JADX INFO: renamed from: H, reason: merged with bridge method [inline-methods] */
        public boolean l(CoordinatorLayout coordinatorLayout, BottomAppBar bottomAppBar, int i2) {
            FloatingActionButton floatingActionButtonC0 = bottomAppBar.c0();
            if (floatingActionButtonC0 != null) {
                L(floatingActionButtonC0, bottomAppBar);
                floatingActionButtonC0.i(this.f1734d);
                bottomAppBar.setFabDiameter(this.f1734d.height());
            }
            if (!bottomAppBar.f0()) {
                bottomAppBar.k0();
            }
            coordinatorLayout.I(bottomAppBar, i2);
            return super.l(coordinatorLayout, bottomAppBar, i2);
        }

        @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
        /* JADX INFO: renamed from: I, reason: merged with bridge method [inline-methods] */
        public boolean z(CoordinatorLayout coordinatorLayout, BottomAppBar bottomAppBar, View view, View view2, int i2, int i3) {
            return bottomAppBar.getHideOnScroll() && super.z(coordinatorLayout, bottomAppBar, view, view2, i2, i3);
        }

        /* JADX INFO: Access modifiers changed from: protected */
        @Override // com.google.android.material.behavior.HideBottomViewOnScrollBehavior
        /* JADX INFO: renamed from: J, reason: merged with bridge method [inline-methods] */
        public void F(BottomAppBar bottomAppBar) {
            super.F(bottomAppBar);
            FloatingActionButton floatingActionButtonC0 = bottomAppBar.c0();
            if (floatingActionButtonC0 != null) {
                floatingActionButtonC0.h(this.f1734d);
                float measuredHeight = floatingActionButtonC0.getMeasuredHeight() - this.f1734d.height();
                floatingActionButtonC0.clearAnimation();
                floatingActionButtonC0.animate().translationY((-floatingActionButtonC0.getPaddingBottom()) + measuredHeight).setInterpolator(d.c.a.a.j.a.f3319b).setDuration(175L);
            }
        }

        /* JADX INFO: Access modifiers changed from: protected */
        @Override // com.google.android.material.behavior.HideBottomViewOnScrollBehavior
        /* JADX INFO: renamed from: K, reason: merged with bridge method [inline-methods] */
        public void G(BottomAppBar bottomAppBar) {
            super.G(bottomAppBar);
            FloatingActionButton floatingActionButtonC0 = bottomAppBar.c0();
            if (floatingActionButtonC0 != null) {
                floatingActionButtonC0.clearAnimation();
                floatingActionButtonC0.animate().translationY(bottomAppBar.getFabTranslationY()).setInterpolator(d.c.a.a.j.a.f3320c).setDuration(225L);
            }
        }

        public Behavior(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
            this.f1734d = new Rect();
        }
    }
}
