package com.google.android.material.floatingactionbutton;

import android.animation.Animator;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import androidx.appcompat.widget.j;
import androidx.appcompat.widget.n;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.widget.k;
import c.f.l.s;
import c.f.l.t;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.floatingactionbutton.a;
import com.google.android.material.internal.g;
import d.c.a.a.i;
import d.c.a.a.j.h;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
@CoordinatorLayout.d(Behavior.class)
public class FloatingActionButton extends g implements s, k, d.c.a.a.m.a {

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private PorterDuff.Mode f1756g;

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private PorterDuff.Mode f1758i;

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private int f1760k;
    private int l;
    private int m;
    private int n;
    boolean o;
    final Rect p;
    private final Rect q;
    private final n r;
    private final d.c.a.a.m.b s;
    private com.google.android.material.floatingactionbutton.a t;

    public static class Behavior extends BaseBehavior<FloatingActionButton> {
        public Behavior() {
        }

        public Behavior(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
        }
    }

    class a implements a.g {
        final /* synthetic */ b a;

        a(b bVar) {
            this.a = bVar;
        }

        @Override // com.google.android.material.floatingactionbutton.a.g
        public void a() {
            this.a.b(FloatingActionButton.this);
        }

        @Override // com.google.android.material.floatingactionbutton.a.g
        public void b() {
            this.a.a(FloatingActionButton.this);
        }
    }

    public static abstract class b {
        public abstract void a(FloatingActionButton floatingActionButton);

        public abstract void b(FloatingActionButton floatingActionButton);
    }

    private class c implements d.c.a.a.q.b {
        c() {
        }

        @Override // d.c.a.a.q.b
        public void a(int i2, int i3, int i4, int i5) {
            FloatingActionButton.this.p.set(i2, i3, i4, i5);
            FloatingActionButton floatingActionButton = FloatingActionButton.this;
            floatingActionButton.setPadding(i2 + floatingActionButton.m, i3 + FloatingActionButton.this.m, i4 + FloatingActionButton.this.m, i5 + FloatingActionButton.this.m);
        }

        @Override // d.c.a.a.q.b
        public void b(Drawable drawable) {
            FloatingActionButton.super.setBackgroundDrawable(drawable);
        }

        @Override // d.c.a.a.q.b
        public boolean c() {
            return FloatingActionButton.this.o;
        }

        @Override // d.c.a.a.q.b
        public float d() {
            return FloatingActionButton.this.getSizeDimension() / 2.0f;
        }
    }

    private com.google.android.material.floatingactionbutton.a g() {
        return Build.VERSION.SDK_INT >= 21 ? new com.google.android.material.floatingactionbutton.b(this, new c()) : new com.google.android.material.floatingactionbutton.a(this, new c());
    }

    private com.google.android.material.floatingactionbutton.a getImpl() {
        if (this.t == null) {
            this.t = g();
        }
        return this.t;
    }

    private int j(int i2) {
        int i3 = this.l;
        if (i3 != 0) {
            return i3;
        }
        Resources resources = getResources();
        return i2 != -1 ? i2 != 1 ? resources.getDimensionPixelSize(d.c.a.a.c.design_fab_size_normal) : resources.getDimensionPixelSize(d.c.a.a.c.design_fab_size_mini) : Math.max(resources.getConfiguration().screenWidthDp, resources.getConfiguration().screenHeightDp) < 470 ? j(1) : j(0);
    }

    private void m(Rect rect) {
        int i2 = rect.left;
        Rect rect2 = this.p;
        rect.left = i2 + rect2.left;
        rect.top += rect2.top;
        rect.right -= rect2.right;
        rect.bottom -= rect2.bottom;
    }

    private void n() {
        Drawable drawable = getDrawable();
        if (drawable == null) {
            return;
        }
        ColorStateList colorStateList = this.f1757h;
        if (colorStateList == null) {
            androidx.core.graphics.drawable.a.c(drawable);
            return;
        }
        int colorForState = colorStateList.getColorForState(getDrawableState(), 0);
        PorterDuff.Mode mode = this.f1758i;
        if (mode == null) {
            mode = PorterDuff.Mode.SRC_IN;
        }
        drawable.mutate().setColorFilter(j.r(colorForState, mode));
    }

    private static int q(int i2, int i3) {
        int mode = View.MeasureSpec.getMode(i3);
        int size = View.MeasureSpec.getSize(i3);
        if (mode == Integer.MIN_VALUE) {
            return Math.min(i2, size);
        }
        if (mode == 0) {
            return i2;
        }
        if (mode == 1073741824) {
            return size;
        }
        throw new IllegalArgumentException();
    }

    private a.g s(b bVar) {
        if (bVar == null) {
            return null;
        }
        return new a(bVar);
    }

    @Override // d.c.a.a.m.a
    public boolean a() {
        return this.s.b();
    }

    @Override // android.widget.ImageView, android.view.View
    protected void drawableStateChanged() {
        super.drawableStateChanged();
        getImpl().w(getDrawableState());
    }

    public void e(Animator.AnimatorListener animatorListener) {
        getImpl().a(animatorListener);
    }

    public void f(Animator.AnimatorListener animatorListener) {
        getImpl().b(animatorListener);
    }

    @Override // android.view.View
    public ColorStateList getBackgroundTintList() {
        return this.f1755f;
    }

    @Override // android.view.View
    public PorterDuff.Mode getBackgroundTintMode() {
        return this.f1756g;
    }

    public float getCompatElevation() {
        return getImpl().j();
    }

    public float getCompatHoveredFocusedTranslationZ() {
        return getImpl().l();
    }

    public float getCompatPressedTranslationZ() {
        return getImpl().n();
    }

    public Drawable getContentBackground() {
        return getImpl().g();
    }

    public int getCustomSize() {
        return this.l;
    }

    public int getExpandedComponentIdHint() {
        return this.s.a();
    }

    public h getHideMotionSpec() {
        return getImpl().k();
    }

    @Deprecated
    public int getRippleColor() {
        ColorStateList colorStateList = this.f1759j;
        if (colorStateList != null) {
            return colorStateList.getDefaultColor();
        }
        return 0;
    }

    public ColorStateList getRippleColorStateList() {
        return this.f1759j;
    }

    public h getShowMotionSpec() {
        return getImpl().o();
    }

    public int getSize() {
        return this.f1760k;
    }

    int getSizeDimension() {
        return j(this.f1760k);
    }

    @Override // c.f.l.s
    public ColorStateList getSupportBackgroundTintList() {
        return getBackgroundTintList();
    }

    @Override // c.f.l.s
    public PorterDuff.Mode getSupportBackgroundTintMode() {
        return getBackgroundTintMode();
    }

    @Override // androidx.core.widget.k
    public ColorStateList getSupportImageTintList() {
        return this.f1757h;
    }

    @Override // androidx.core.widget.k
    public PorterDuff.Mode getSupportImageTintMode() {
        return this.f1758i;
    }

    public boolean getUseCompatPadding() {
        return this.o;
    }

    @Deprecated
    public boolean h(Rect rect) {
        if (!t.H(this)) {
            return false;
        }
        rect.set(0, 0, getWidth(), getHeight());
        m(rect);
        return true;
    }

    public void i(Rect rect) {
        rect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
        m(rect);
    }

    @Override // android.widget.ImageView, android.view.View
    public void jumpDrawablesToCurrentState() {
        super.jumpDrawablesToCurrentState();
        getImpl().s();
    }

    void k(b bVar, boolean z) {
        getImpl().p(s(bVar), z);
    }

    public boolean l() {
        return getImpl().r();
    }

    public void o(Animator.AnimatorListener animatorListener) {
        getImpl().A(animatorListener);
    }

    @Override // android.widget.ImageView, android.view.View
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        getImpl().t();
    }

    @Override // android.widget.ImageView, android.view.View
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        getImpl().v();
    }

    @Override // android.widget.ImageView, android.view.View
    protected void onMeasure(int i2, int i3) {
        int sizeDimension = getSizeDimension();
        this.m = (sizeDimension - this.n) / 2;
        getImpl().Q();
        int iMin = Math.min(q(sizeDimension, i2), q(sizeDimension, i3));
        Rect rect = this.p;
        setMeasuredDimension(rect.left + iMin + rect.right, iMin + rect.top + rect.bottom);
    }

    @Override // android.view.View
    protected void onRestoreInstanceState(Parcelable parcelable) {
        if (!(parcelable instanceof d.c.a.a.s.a)) {
            super.onRestoreInstanceState(parcelable);
            return;
        }
        d.c.a.a.s.a aVar = (d.c.a.a.s.a) parcelable;
        super.onRestoreInstanceState(aVar.a());
        this.s.c(aVar.f3361g.get("expandableWidgetHelper"));
    }

    @Override // android.view.View
    protected Parcelable onSaveInstanceState() {
        d.c.a.a.s.a aVar = new d.c.a.a.s.a(super.onSaveInstanceState());
        aVar.f3361g.put("expandableWidgetHelper", this.s.d());
        return aVar;
    }

    @Override // android.view.View
    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (motionEvent.getAction() == 0 && h(this.q) && !this.q.contains((int) motionEvent.getX(), (int) motionEvent.getY())) {
            return false;
        }
        return super.onTouchEvent(motionEvent);
    }

    public void p(Animator.AnimatorListener animatorListener) {
        getImpl().B(animatorListener);
    }

    void r(b bVar, boolean z) {
        getImpl().N(s(bVar), z);
    }

    @Override // android.view.View
    public void setBackgroundColor(int i2) {
        Log.i("FloatingActionButton", "Setting a custom background is not supported.");
    }

    @Override // android.view.View
    public void setBackgroundDrawable(Drawable drawable) {
        Log.i("FloatingActionButton", "Setting a custom background is not supported.");
    }

    @Override // android.view.View
    public void setBackgroundResource(int i2) {
        Log.i("FloatingActionButton", "Setting a custom background is not supported.");
    }

    @Override // android.view.View
    public void setBackgroundTintList(ColorStateList colorStateList) {
        if (this.f1755f != colorStateList) {
            this.f1755f = colorStateList;
            getImpl().D(colorStateList);
        }
    }

    @Override // android.view.View
    public void setBackgroundTintMode(PorterDuff.Mode mode) {
        if (this.f1756g != mode) {
            this.f1756g = mode;
            getImpl().E(mode);
        }
    }

    public void setCompatElevation(float f2) {
        getImpl().F(f2);
    }

    public void setCompatElevationResource(int i2) {
        setCompatElevation(getResources().getDimension(i2));
    }

    public void setCompatHoveredFocusedTranslationZ(float f2) {
        getImpl().H(f2);
    }

    public void setCompatHoveredFocusedTranslationZResource(int i2) {
        setCompatHoveredFocusedTranslationZ(getResources().getDimension(i2));
    }

    public void setCompatPressedTranslationZ(float f2) {
        getImpl().J(f2);
    }

    public void setCompatPressedTranslationZResource(int i2) {
        setCompatPressedTranslationZ(getResources().getDimension(i2));
    }

    public void setCustomSize(int i2) {
        if (i2 < 0) {
            throw new IllegalArgumentException("Custom size must be non-negative");
        }
        this.l = i2;
    }

    public void setExpandedComponentIdHint(int i2) {
        this.s.e(i2);
    }

    public void setHideMotionSpec(h hVar) {
        getImpl().G(hVar);
    }

    public void setHideMotionSpecResource(int i2) {
        setHideMotionSpec(h.b(getContext(), i2));
    }

    @Override // android.widget.ImageView
    public void setImageDrawable(Drawable drawable) {
        super.setImageDrawable(drawable);
        getImpl().P();
    }

    @Override // android.widget.ImageView
    public void setImageResource(int i2) {
        this.r.g(i2);
    }

    public void setRippleColor(int i2) {
        setRippleColor(ColorStateList.valueOf(i2));
    }

    public void setShowMotionSpec(h hVar) {
        getImpl().L(hVar);
    }

    public void setShowMotionSpecResource(int i2) {
        setShowMotionSpec(h.b(getContext(), i2));
    }

    public void setSize(int i2) {
        this.l = 0;
        if (i2 != this.f1760k) {
            this.f1760k = i2;
            requestLayout();
        }
    }

    @Override // c.f.l.s
    public void setSupportBackgroundTintList(ColorStateList colorStateList) {
        setBackgroundTintList(colorStateList);
    }

    @Override // c.f.l.s
    public void setSupportBackgroundTintMode(PorterDuff.Mode mode) {
        setBackgroundTintMode(mode);
    }

    @Override // androidx.core.widget.k
    public void setSupportImageTintList(ColorStateList colorStateList) {
        if (this.f1757h != colorStateList) {
            this.f1757h = colorStateList;
            n();
        }
    }

    @Override // androidx.core.widget.k
    public void setSupportImageTintMode(PorterDuff.Mode mode) {
        if (this.f1758i != mode) {
            this.f1758i = mode;
            n();
        }
    }

    public void setUseCompatPadding(boolean z) {
        if (this.o != z) {
            this.o = z;
            getImpl().u();
        }
    }

    protected static class BaseBehavior<T extends FloatingActionButton> extends CoordinatorLayout.c<T> {
        private Rect a;

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

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

        public BaseBehavior() {
            this.f1762c = true;
        }

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

        private void F(CoordinatorLayout coordinatorLayout, FloatingActionButton floatingActionButton) {
            Rect rect = floatingActionButton.p;
            if (rect == null || rect.centerX() <= 0 || rect.centerY() <= 0) {
                return;
            }
            CoordinatorLayout.f fVar = (CoordinatorLayout.f) floatingActionButton.getLayoutParams();
            int i2 = 0;
            int i3 = floatingActionButton.getRight() >= coordinatorLayout.getWidth() - ((ViewGroup.MarginLayoutParams) fVar).rightMargin ? rect.right : floatingActionButton.getLeft() <= ((ViewGroup.MarginLayoutParams) fVar).leftMargin ? -rect.left : 0;
            if (floatingActionButton.getBottom() >= coordinatorLayout.getHeight() - ((ViewGroup.MarginLayoutParams) fVar).bottomMargin) {
                i2 = rect.bottom;
            } else if (floatingActionButton.getTop() <= ((ViewGroup.MarginLayoutParams) fVar).topMargin) {
                i2 = -rect.top;
            }
            if (i2 != 0) {
                t.N(floatingActionButton, i2);
            }
            if (i3 != 0) {
                t.M(floatingActionButton, i3);
            }
        }

        private boolean I(View view, FloatingActionButton floatingActionButton) {
            return this.f1762c && ((CoordinatorLayout.f) floatingActionButton.getLayoutParams()).e() == view.getId() && floatingActionButton.getUserSetVisibility() == 0;
        }

        private boolean J(CoordinatorLayout coordinatorLayout, AppBarLayout appBarLayout, FloatingActionButton floatingActionButton) {
            if (!I(appBarLayout, floatingActionButton)) {
                return false;
            }
            if (this.a == null) {
                this.a = new Rect();
            }
            Rect rect = this.a;
            com.google.android.material.internal.b.a(coordinatorLayout, appBarLayout, rect);
            if (rect.bottom <= appBarLayout.getMinimumHeightForVisibleOverlappingContent()) {
                floatingActionButton.k(this.f1761b, false);
                return true;
            }
            floatingActionButton.r(this.f1761b, false);
            return true;
        }

        private boolean K(View view, FloatingActionButton floatingActionButton) {
            if (!I(view, floatingActionButton)) {
                return false;
            }
            if (view.getTop() < (floatingActionButton.getHeight() / 2) + ((ViewGroup.MarginLayoutParams) ((CoordinatorLayout.f) floatingActionButton.getLayoutParams())).topMargin) {
                floatingActionButton.k(this.f1761b, false);
                return true;
            }
            floatingActionButton.r(this.f1761b, false);
            return true;
        }

        @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
        /* JADX INFO: renamed from: D, reason: merged with bridge method [inline-methods] */
        public boolean b(CoordinatorLayout coordinatorLayout, FloatingActionButton floatingActionButton, Rect rect) {
            Rect rect2 = floatingActionButton.p;
            rect.set(floatingActionButton.getLeft() + rect2.left, floatingActionButton.getTop() + rect2.top, floatingActionButton.getRight() - rect2.right, floatingActionButton.getBottom() - rect2.bottom);
            return true;
        }

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

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

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

        public BaseBehavior(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
            TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, i.FloatingActionButton_Behavior_Layout);
            this.f1762c = typedArrayObtainStyledAttributes.getBoolean(i.FloatingActionButton_Behavior_Layout_behavior_autoHide, true);
            typedArrayObtainStyledAttributes.recycle();
        }
    }

    public void setRippleColor(ColorStateList colorStateList) {
        if (this.f1759j != colorStateList) {
            this.f1759j = colorStateList;
            getImpl().K(this.f1759j);
        }
    }
}
