package com.google.android.material.bottomappbar;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
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 android.view.ViewGroup;
import androidx.appcompat.widget.ActionMenuView;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior;
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import d.h.d.k.b;
import d.h.j.y;
import g.e.a.a.f.c;
import g.e.a.a.f.d;
import g.e.a.a.f.f;
import g.e.a.a.f.g;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes.dex */
public class BottomAppBar extends Toolbar implements CoordinatorLayout.b {

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public static final /* synthetic */ int f1019d0 = 0;
    public Animator e0;
    public Animator f0;
    public int g0;
    public int h0;
    public boolean i0;
    public int j0;
    public int k0;
    public boolean l0;
    public Behavior m0;

    public static class Behavior extends HideBottomViewOnScrollBehavior<BottomAppBar> {

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

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public WeakReference<BottomAppBar> f1021f;

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

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        public final View.OnLayoutChangeListener f1023h;

        public class a implements View.OnLayoutChangeListener {
            public a() {
            }

            @Override // android.view.View.OnLayoutChangeListener
            public void onLayoutChange(View view, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9) {
                if (Behavior.this.f1021f.get() == null || !(view instanceof FloatingActionButton)) {
                    view.removeOnLayoutChangeListener(this);
                } else {
                    FloatingActionButton floatingActionButton = (FloatingActionButton) view;
                    Behavior.this.f1020e.set(0, 0, floatingActionButton.getMeasuredWidth(), floatingActionButton.getMeasuredHeight());
                    throw null;
                }
            }
        }

        public Behavior() {
            this.f1023h = new a();
            this.f1020e = new Rect();
        }

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

        @Override // com.google.android.material.behavior.HideBottomViewOnScrollBehavior, androidx.coordinatorlayout.widget.CoordinatorLayout.c
        public boolean k(CoordinatorLayout coordinatorLayout, View view, int i2) {
            BottomAppBar bottomAppBar = (BottomAppBar) view;
            this.f1021f = new WeakReference<>(bottomAppBar);
            int i3 = BottomAppBar.f1019d0;
            View viewY = bottomAppBar.y();
            if (viewY != null) {
                AtomicInteger atomicInteger = y.a;
                if (!y.f.c(viewY)) {
                    CoordinatorLayout.f fVar = (CoordinatorLayout.f) viewY.getLayoutParams();
                    fVar.f640d = 49;
                    this.f1022g = ((ViewGroup.MarginLayoutParams) fVar).bottomMargin;
                    if (viewY instanceof FloatingActionButton) {
                        FloatingActionButton floatingActionButton = (FloatingActionButton) viewY;
                        floatingActionButton.addOnLayoutChangeListener(this.f1023h);
                        floatingActionButton.d(null);
                        floatingActionButton.e(new f(bottomAppBar));
                        floatingActionButton.f(null);
                    }
                    bottomAppBar.C();
                    throw null;
                }
            }
            coordinatorLayout.r(bottomAppBar, i2);
            this.a = bottomAppBar.getMeasuredHeight() + ((ViewGroup.MarginLayoutParams) bottomAppBar.getLayoutParams()).bottomMargin;
            return false;
        }

        @Override // com.google.android.material.behavior.HideBottomViewOnScrollBehavior, androidx.coordinatorlayout.widget.CoordinatorLayout.c
        public boolean x(CoordinatorLayout coordinatorLayout, View view, View view2, View view3, int i2, int i3) {
            if (((BottomAppBar) view).getHideOnScroll()) {
                if (i2 == 2) {
                    return true;
                }
            }
            return false;
        }
    }

    public static class a extends d.j.a.a {
        public static final Parcelable.Creator<a> CREATOR = new C0011a();

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

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

        /* JADX INFO: renamed from: com.google.android.material.bottomappbar.BottomAppBar$a$a, reason: collision with other inner class name */
        public static class C0011a implements Parcelable.ClassLoaderCreator<a> {
            @Override // android.os.Parcelable.Creator
            public Object createFromParcel(Parcel parcel) {
                return new a(parcel, null);
            }

            @Override // android.os.Parcelable.Creator
            public Object[] newArray(int i2) {
                return new a[i2];
            }

            @Override // android.os.Parcelable.ClassLoaderCreator
            public a createFromParcel(Parcel parcel, ClassLoader classLoader) {
                return new a(parcel, classLoader);
            }
        }

        public a(Parcel parcel, ClassLoader classLoader) {
            super(parcel, classLoader);
            this.f1024n = parcel.readInt();
            this.f1025o = parcel.readInt() != 0;
        }

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

        @Override // d.j.a.a, android.os.Parcelable
        public void writeToParcel(Parcel parcel, int i2) {
            parcel.writeParcelable(this.f2846m, i2);
            parcel.writeInt(this.f1024n);
            parcel.writeInt(this.f1025o ? 1 : 0);
        }
    }

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

    private int getBottomInset() {
        return 0;
    }

    private float getFabTranslationX() {
        return A(this.g0);
    }

    private float getFabTranslationY() {
        return -getTopEdgeTreatment().f3616n;
    }

    private int getLeftInset() {
        return 0;
    }

    private int getRightInset() {
        return 0;
    }

    private g getTopEdgeTreatment() {
        throw null;
    }

    public static void w(BottomAppBar bottomAppBar) {
        bottomAppBar.j0--;
    }

    public final float A(int i2) {
        boolean zT = g.e.a.a.a.t(this);
        if (i2 == 1) {
            return ((getMeasuredWidth() / 2) + 0) * (zT ? -1 : 1);
        }
        return 0.0f;
    }

    public final boolean B() {
        FloatingActionButton floatingActionButtonX = x();
        return floatingActionButtonX != null && floatingActionButtonX.k();
    }

    public final void C() {
        getTopEdgeTreatment().f3617o = getFabTranslationX();
        y();
        if (this.l0) {
            B();
        }
        throw null;
    }

    public ColorStateList getBackgroundTint() {
        throw null;
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.b
    public Behavior getBehavior() {
        if (this.m0 == null) {
            this.m0 = new Behavior();
        }
        return this.m0;
    }

    public float getCradleVerticalOffset() {
        return getTopEdgeTreatment().f3616n;
    }

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

    public int getFabAnimationMode() {
        return this.h0;
    }

    public float getFabCradleMargin() {
        return getTopEdgeTreatment().f3615m;
    }

    public float getFabCradleRoundedCornerRadius() {
        return getTopEdgeTreatment().f3614f;
    }

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

    @Override // android.view.ViewGroup, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        g.e.a.a.a.I(this, null);
        throw null;
    }

    @Override // androidx.appcompat.widget.Toolbar, android.view.ViewGroup, android.view.View
    public void onLayout(boolean z2, int i2, int i3, int i4, int i5) {
        super.onLayout(z2, i2, i3, i4, i5);
        if (!z2) {
            ActionMenuView actionMenuView = getActionMenuView();
            if (actionMenuView == null || this.f0 != null) {
                return;
            }
            actionMenuView.setAlpha(1.0f);
            actionMenuView.setTranslationX(!B() ? z(actionMenuView, 0, false) : z(actionMenuView, this.g0, this.l0));
            return;
        }
        Animator animator = this.f0;
        if (animator != null) {
            animator.cancel();
        }
        Animator animator2 = this.e0;
        if (animator2 != null) {
            animator2.cancel();
        }
        C();
        throw null;
    }

    @Override // androidx.appcompat.widget.Toolbar, android.view.View
    public void onRestoreInstanceState(Parcelable parcelable) {
        if (!(parcelable instanceof a)) {
            super.onRestoreInstanceState(parcelable);
            return;
        }
        a aVar = (a) parcelable;
        super.onRestoreInstanceState(aVar.f2846m);
        this.g0 = aVar.f1024n;
        this.l0 = aVar.f1025o;
    }

    @Override // androidx.appcompat.widget.Toolbar, android.view.View
    public Parcelable onSaveInstanceState() {
        a aVar = new a(super.onSaveInstanceState());
        aVar.f1024n = this.g0;
        aVar.f1025o = this.l0;
        return aVar;
    }

    public void setBackgroundTint(ColorStateList colorStateList) {
        b.h(null, colorStateList);
    }

    public void setCradleVerticalOffset(float f2) {
        if (f2 != getCradleVerticalOffset()) {
            g topEdgeTreatment = getTopEdgeTreatment();
            Objects.requireNonNull(topEdgeTreatment);
            if (f2 < 0.0f) {
                throw new IllegalArgumentException("cradleVerticalOffset must be positive.");
            }
            topEdgeTreatment.f3616n = f2;
            throw null;
        }
    }

    @Override // android.view.View
    public void setElevation(float f2) {
        throw null;
    }

    public void setFabAlignmentMode(int i2) {
        int i3;
        this.k0 = 0;
        boolean z2 = this.l0;
        AtomicInteger atomicInteger = y.a;
        if (y.f.c(this)) {
            Animator animator = this.f0;
            if (animator != null) {
                animator.cancel();
            }
            ArrayList arrayList = new ArrayList();
            if (B()) {
                i3 = i2;
            } else {
                z2 = false;
                i3 = 0;
            }
            ActionMenuView actionMenuView = getActionMenuView();
            if (actionMenuView != null) {
                ObjectAnimator objectAnimatorOfFloat = ObjectAnimator.ofFloat(actionMenuView, "alpha", 1.0f);
                if (Math.abs(actionMenuView.getTranslationX() - z(actionMenuView, i3, z2)) > 1.0f) {
                    ObjectAnimator objectAnimatorOfFloat2 = ObjectAnimator.ofFloat(actionMenuView, "alpha", 0.0f);
                    objectAnimatorOfFloat2.addListener(new d(this, actionMenuView, i3, z2));
                    AnimatorSet animatorSet = new AnimatorSet();
                    animatorSet.setDuration(150L);
                    animatorSet.playSequentially(objectAnimatorOfFloat2, objectAnimatorOfFloat);
                    arrayList.add(animatorSet);
                } else if (actionMenuView.getAlpha() < 1.0f) {
                    arrayList.add(objectAnimatorOfFloat);
                }
            }
            AnimatorSet animatorSet2 = new AnimatorSet();
            animatorSet2.playTogether(arrayList);
            this.f0 = animatorSet2;
            animatorSet2.addListener(new c(this));
            this.f0.start();
        } else {
            int i4 = this.k0;
            if (i4 != 0) {
                this.k0 = 0;
                getMenu().clear();
                n(i4);
            }
        }
        if (this.g0 != i2 && y.f.c(this)) {
            Animator animator2 = this.e0;
            if (animator2 != null) {
                animator2.cancel();
            }
            ArrayList arrayList2 = new ArrayList();
            if (this.h0 == 1) {
                ObjectAnimator objectAnimatorOfFloat3 = ObjectAnimator.ofFloat(x(), "translationX", A(i2));
                objectAnimatorOfFloat3.setDuration(300L);
                arrayList2.add(objectAnimatorOfFloat3);
            } else {
                FloatingActionButton floatingActionButtonX = x();
                if (floatingActionButtonX != null && !floatingActionButtonX.j()) {
                    this.j0++;
                    floatingActionButtonX.i(new g.e.a.a.f.b(this, i2), true);
                }
            }
            AnimatorSet animatorSet3 = new AnimatorSet();
            animatorSet3.playTogether(arrayList2);
            this.e0 = animatorSet3;
            animatorSet3.addListener(new g.e.a.a.f.a(this));
            this.e0.start();
        }
        this.g0 = i2;
    }

    public void setFabAnimationMode(int i2) {
        this.h0 = i2;
    }

    public void setFabCornerSize(float f2) {
        if (f2 == getTopEdgeTreatment().f3618p) {
            return;
        }
        getTopEdgeTreatment().f3618p = f2;
        throw null;
    }

    public void setFabCradleMargin(float f2) {
        if (f2 == getFabCradleMargin()) {
            return;
        }
        getTopEdgeTreatment().f3615m = f2;
        throw null;
    }

    public void setFabCradleRoundedCornerRadius(float f2) {
        if (f2 == getFabCradleRoundedCornerRadius()) {
            return;
        }
        getTopEdgeTreatment().f3614f = f2;
        throw null;
    }

    public void setHideOnScroll(boolean z2) {
        this.i0 = z2;
    }

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

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

    public final FloatingActionButton x() {
        View viewY = y();
        if (viewY instanceof FloatingActionButton) {
            return (FloatingActionButton) viewY;
        }
        return null;
    }

    public final View y() {
        if (!(getParent() instanceof CoordinatorLayout)) {
            return null;
        }
        for (View view : ((CoordinatorLayout) getParent()).e(this)) {
            if ((view instanceof FloatingActionButton) || (view instanceof ExtendedFloatingActionButton)) {
                return view;
            }
        }
        return null;
    }

    public int z(ActionMenuView actionMenuView, int i2, boolean z2) {
        if (i2 != 1 || !z2) {
            return 0;
        }
        boolean zT = g.e.a.a.a.t(this);
        int measuredWidth = zT ? getMeasuredWidth() : 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) {
                measuredWidth = zT ? Math.min(measuredWidth, childAt.getLeft()) : Math.max(measuredWidth, childAt.getRight());
            }
        }
        return measuredWidth - ((zT ? actionMenuView.getRight() : actionMenuView.getLeft()) + 0);
    }
}
