package com.google.android.material.floatingactionbutton;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Property;
import android.view.View;
import android.view.ViewGroup;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.y;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.button.MaterialButton;
import java.util.Iterator;
import java.util.List;
import l0.k;
import m0.h;

/* JADX INFO: loaded from: classes.dex */
public class ExtendedFloatingActionButton extends MaterialButton implements CoordinatorLayout.b {
    private final com.google.android.material.floatingactionbutton.c A;
    private final com.google.android.material.floatingactionbutton.c B;
    private final int C;
    private final CoordinatorLayout.c<ExtendedFloatingActionButton> D;
    private boolean E;
    private boolean F;
    private boolean G;

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

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    private final com.google.android.material.floatingactionbutton.c f3928y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    private final com.google.android.material.floatingactionbutton.c f3929z;

    class a extends AnimatorListenerAdapter {

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

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ com.google.android.material.floatingactionbutton.c f3936b;

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

        a(ExtendedFloatingActionButton extendedFloatingActionButton, com.google.android.material.floatingactionbutton.c cVar, f fVar) {
            this.f3936b = cVar;
        }

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

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
            this.f3936b.c();
            if (this.f3935a) {
                return;
            }
            this.f3936b.f(this.f3937c);
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationStart(Animator animator) {
            this.f3936b.onAnimationStart(animator);
            this.f3935a = false;
        }
    }

    class b extends Property<View, Float> {
        b(Class cls, String str) {
            super(cls, str);
        }

        @Override // android.util.Property
        /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
        public Float get(View view) {
            return Float.valueOf(view.getLayoutParams().width);
        }

        @Override // android.util.Property
        /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
        public void set(View view, Float f3) {
            view.getLayoutParams().width = f3.intValue();
            view.requestLayout();
        }
    }

    class c extends Property<View, Float> {
        c(Class cls, String str) {
            super(cls, str);
        }

        @Override // android.util.Property
        /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
        public Float get(View view) {
            return Float.valueOf(view.getLayoutParams().height);
        }

        @Override // android.util.Property
        /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
        public void set(View view, Float f3) {
            view.getLayoutParams().height = f3.intValue();
            view.requestLayout();
        }
    }

    class d extends Property<View, Float> {
        d(Class cls, String str) {
            super(cls, str);
        }

        @Override // android.util.Property
        /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
        public Float get(View view) {
            return Float.valueOf(y.J(view));
        }

        @Override // android.util.Property
        /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
        public void set(View view, Float f3) {
            y.E0(view, f3.intValue(), view.getPaddingTop(), y.I(view), view.getPaddingBottom());
        }
    }

    class e extends Property<View, Float> {
        e(Class cls, String str) {
            super(cls, str);
        }

        @Override // android.util.Property
        /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
        public Float get(View view) {
            return Float.valueOf(y.I(view));
        }

        @Override // android.util.Property
        /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
        public void set(View view, Float f3) {
            y.E0(view, y.J(view), view.getPaddingTop(), f3.intValue(), view.getPaddingBottom());
        }
    }

    public static abstract class f {
    }

    static {
        new b(Float.class, "width");
        new c(Float.class, "height");
        new d(Float.class, "paddingStart");
        new e(Float.class, "paddingEnd");
    }

    private boolean o() {
        return getVisibility() != 0 ? this.f3927x == 2 : this.f3927x != 1;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void p(com.google.android.material.floatingactionbutton.c cVar, f fVar) {
        if (cVar.g()) {
            return;
        }
        if (!r()) {
            cVar.i();
            cVar.f(fVar);
            return;
        }
        measure(0, 0);
        AnimatorSet animatorSetB = cVar.b();
        animatorSetB.addListener(new a(this, cVar, fVar));
        Iterator<Animator.AnimatorListener> it = cVar.e().iterator();
        while (it.hasNext()) {
            animatorSetB.addListener(it.next());
        }
        animatorSetB.start();
    }

    private void q() {
        getTextColors();
    }

    private boolean r() {
        return (y.V(this) || (!o() && this.G)) && !isInEditMode();
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.b
    public CoordinatorLayout.c<ExtendedFloatingActionButton> getBehavior() {
        return this.D;
    }

    int getCollapsedPadding() {
        return (getCollapsedSize() - getIconSize()) / 2;
    }

    int getCollapsedSize() {
        int i3 = this.C;
        return i3 < 0 ? (Math.min(y.J(this), y.I(this)) * 2) + getIconSize() : i3;
    }

    public h getExtendMotionSpec() {
        return this.f3929z.a();
    }

    public h getHideMotionSpec() {
        return this.B.a();
    }

    public h getShowMotionSpec() {
        return this.A.a();
    }

    public h getShrinkMotionSpec() {
        return this.f3928y.a();
    }

    @Override // com.google.android.material.button.MaterialButton, android.widget.TextView, android.view.View
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (this.E && TextUtils.isEmpty(getText()) && getIcon() != null) {
            this.E = false;
            this.f3928y.i();
        }
    }

    public void setAnimateShowBeforeLayout(boolean z2) {
        this.G = z2;
    }

    public void setExtendMotionSpec(h hVar) {
        this.f3929z.h(hVar);
    }

    public void setExtendMotionSpecResource(int i3) {
        setExtendMotionSpec(h.c(getContext(), i3));
    }

    public void setExtended(boolean z2) {
        if (this.E == z2) {
            return;
        }
        com.google.android.material.floatingactionbutton.c cVar = z2 ? this.f3929z : this.f3928y;
        if (cVar.g()) {
            return;
        }
        cVar.i();
    }

    public void setHideMotionSpec(h hVar) {
        this.B.h(hVar);
    }

    public void setHideMotionSpecResource(int i3) {
        setHideMotionSpec(h.c(getContext(), i3));
    }

    @Override // android.widget.TextView, android.view.View
    public void setPadding(int i3, int i4, int i5, int i6) {
        super.setPadding(i3, i4, i5, i6);
        if (!this.E || this.F) {
            return;
        }
        y.J(this);
        y.I(this);
    }

    @Override // android.widget.TextView, android.view.View
    public void setPaddingRelative(int i3, int i4, int i5, int i6) {
        super.setPaddingRelative(i3, i4, i5, i6);
    }

    public void setShowMotionSpec(h hVar) {
        this.A.h(hVar);
    }

    public void setShowMotionSpecResource(int i3) {
        setShowMotionSpec(h.c(getContext(), i3));
    }

    public void setShrinkMotionSpec(h hVar) {
        this.f3928y.h(hVar);
    }

    public void setShrinkMotionSpecResource(int i3) {
        setShrinkMotionSpec(h.c(getContext(), i3));
    }

    @Override // android.widget.TextView
    public void setTextColor(int i3) {
        super.setTextColor(i3);
        q();
    }

    protected static class ExtendedFloatingActionButtonBehavior<T extends ExtendedFloatingActionButton> extends CoordinatorLayout.c<T> {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private Rect f3930a;

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

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

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

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

        public ExtendedFloatingActionButtonBehavior() {
            this.f3933d = false;
            this.f3934e = true;
        }

        private static boolean G(View view) {
            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
            if (layoutParams instanceof CoordinatorLayout.f) {
                return ((CoordinatorLayout.f) layoutParams).f() instanceof BottomSheetBehavior;
            }
            return false;
        }

        private boolean J(View view, ExtendedFloatingActionButton extendedFloatingActionButton) {
            return (this.f3933d || this.f3934e) && ((CoordinatorLayout.f) extendedFloatingActionButton.getLayoutParams()).e() == view.getId();
        }

        private boolean L(CoordinatorLayout coordinatorLayout, AppBarLayout appBarLayout, ExtendedFloatingActionButton extendedFloatingActionButton) {
            if (!J(appBarLayout, extendedFloatingActionButton)) {
                return false;
            }
            if (this.f3930a == null) {
                this.f3930a = new Rect();
            }
            Rect rect = this.f3930a;
            com.google.android.material.internal.c.a(coordinatorLayout, appBarLayout, rect);
            if (rect.bottom <= appBarLayout.getMinimumHeightForVisibleOverlappingContent()) {
                K(extendedFloatingActionButton);
                return true;
            }
            E(extendedFloatingActionButton);
            return true;
        }

        private boolean M(View view, ExtendedFloatingActionButton extendedFloatingActionButton) {
            if (!J(view, extendedFloatingActionButton)) {
                return false;
            }
            if (view.getTop() < (extendedFloatingActionButton.getHeight() / 2) + ((ViewGroup.MarginLayoutParams) ((CoordinatorLayout.f) extendedFloatingActionButton.getLayoutParams())).topMargin) {
                K(extendedFloatingActionButton);
                return true;
            }
            E(extendedFloatingActionButton);
            return true;
        }

        protected void E(ExtendedFloatingActionButton extendedFloatingActionButton) {
            boolean z2 = this.f3934e;
            extendedFloatingActionButton.p(z2 ? extendedFloatingActionButton.f3929z : extendedFloatingActionButton.A, z2 ? this.f3932c : this.f3931b);
        }

        @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
        /* JADX INFO: renamed from: F, reason: merged with bridge method [inline-methods] */
        public boolean b(CoordinatorLayout coordinatorLayout, ExtendedFloatingActionButton extendedFloatingActionButton, Rect rect) {
            return super.b(coordinatorLayout, extendedFloatingActionButton, rect);
        }

        @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
        /* JADX INFO: renamed from: H, reason: merged with bridge method [inline-methods] */
        public boolean h(CoordinatorLayout coordinatorLayout, ExtendedFloatingActionButton extendedFloatingActionButton, View view) {
            if (view instanceof AppBarLayout) {
                L(coordinatorLayout, (AppBarLayout) view, extendedFloatingActionButton);
                return false;
            }
            if (!G(view)) {
                return false;
            }
            M(view, extendedFloatingActionButton);
            return false;
        }

        @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
        /* JADX INFO: renamed from: I, reason: merged with bridge method [inline-methods] */
        public boolean l(CoordinatorLayout coordinatorLayout, ExtendedFloatingActionButton extendedFloatingActionButton, int i3) {
            List<View> listR = coordinatorLayout.r(extendedFloatingActionButton);
            int size = listR.size();
            for (int i4 = 0; i4 < size; i4++) {
                View view = listR.get(i4);
                if (!(view instanceof AppBarLayout)) {
                    if (G(view) && M(view, extendedFloatingActionButton)) {
                        break;
                    }
                } else {
                    if (L(coordinatorLayout, (AppBarLayout) view, extendedFloatingActionButton)) {
                        break;
                    }
                }
            }
            coordinatorLayout.I(extendedFloatingActionButton, i3);
            return true;
        }

        protected void K(ExtendedFloatingActionButton extendedFloatingActionButton) {
            boolean z2 = this.f3934e;
            extendedFloatingActionButton.p(z2 ? extendedFloatingActionButton.f3928y : extendedFloatingActionButton.B, z2 ? this.f3932c : this.f3931b);
        }

        @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
        public void g(CoordinatorLayout.f fVar) {
            if (fVar.f1581h == 0) {
                fVar.f1581h = 80;
            }
        }

        public ExtendedFloatingActionButtonBehavior(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
            TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, k.F0);
            this.f3933d = typedArrayObtainStyledAttributes.getBoolean(k.G0, false);
            this.f3934e = typedArrayObtainStyledAttributes.getBoolean(k.H0, true);
            typedArrayObtainStyledAttributes.recycle();
        }
    }

    @Override // android.widget.TextView
    public void setTextColor(ColorStateList colorStateList) {
        super.setTextColor(colorStateList);
        q();
    }
}
