package com.google.android.material.floatingactionbutton;

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.Bundle;
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 android.widget.ImageView;
import androidx.appcompat.widget.j;
import androidx.appcompat.widget.p;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.s0;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.floatingactionbutton.b;
import com.google.android.material.internal.o;
import com.google.android.material.internal.q;
import com.google.android.material.internal.r;
import java.util.List;
import lj.n;
import s3.i;
import vi.k;
import vi.l;
import wi.f;

/* loaded from: classes3.dex */
public class FloatingActionButton extends r implements fj.a, n, CoordinatorLayout.b {
    private static final int G = k.f39897l;
    boolean A;
    final Rect B;
    private final Rect C;
    private final p D;
    private final fj.b E;
    private com.google.android.material.floatingactionbutton.b F;

    /* renamed from: q, reason: collision with root package name */
    private ColorStateList f13204q;

    /* renamed from: r, reason: collision with root package name */
    private PorterDuff.Mode f13205r;

    /* renamed from: s, reason: collision with root package name */
    private ColorStateList f13206s;

    /* renamed from: t, reason: collision with root package name */
    private PorterDuff.Mode f13207t;

    /* renamed from: u, reason: collision with root package name */
    private ColorStateList f13208u;

    /* renamed from: v, reason: collision with root package name */
    private int f13209v;

    /* renamed from: w, reason: collision with root package name */
    private int f13210w;

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

    /* renamed from: y, reason: collision with root package name */
    private int f13212y;

    /* renamed from: z, reason: collision with root package name */
    private int f13213z;

    /* loaded from: classes3.dex */
    public static class Behavior extends BaseBehavior<FloatingActionButton> {
        public Behavior() {
        }

        @Override // com.google.android.material.floatingactionbutton.FloatingActionButton.BaseBehavior
        /* renamed from: E */
        public /* bridge */ /* synthetic */ boolean b(CoordinatorLayout coordinatorLayout, FloatingActionButton floatingActionButton, Rect rect) {
            return super.b(coordinatorLayout, floatingActionButton, rect);
        }

        @Override // com.google.android.material.floatingactionbutton.FloatingActionButton.BaseBehavior
        /* renamed from: H */
        public /* bridge */ /* synthetic */ boolean h(CoordinatorLayout coordinatorLayout, FloatingActionButton floatingActionButton, View view) {
            return super.h(coordinatorLayout, floatingActionButton, view);
        }

        @Override // com.google.android.material.floatingactionbutton.FloatingActionButton.BaseBehavior
        /* renamed from: I */
        public /* bridge */ /* synthetic */ boolean l(CoordinatorLayout coordinatorLayout, FloatingActionButton floatingActionButton, int i10) {
            return super.l(coordinatorLayout, floatingActionButton, i10);
        }

        @Override // com.google.android.material.floatingactionbutton.FloatingActionButton.BaseBehavior, androidx.coordinatorlayout.widget.CoordinatorLayout.c
        public /* bridge */ /* synthetic */ void g(CoordinatorLayout.f fVar) {
            super.g(fVar);
        }

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

    /* loaded from: classes3.dex */
    public static abstract class a {
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes3.dex */
    public class b implements kj.b {
        b() {
        }

        @Override // kj.b
        public void a(int i10, int i11, int i12, int i13) {
            FloatingActionButton.this.B.set(i10, i11, i12, i13);
            FloatingActionButton floatingActionButton = FloatingActionButton.this;
            floatingActionButton.setPadding(i10 + floatingActionButton.f13212y, i11 + FloatingActionButton.this.f13212y, i12 + FloatingActionButton.this.f13212y, i13 + FloatingActionButton.this.f13212y);
        }

        @Override // kj.b
        public void b(Drawable drawable) {
            if (drawable != null) {
                FloatingActionButton.super.setBackgroundDrawable(drawable);
            }
        }

        @Override // kj.b
        public boolean c() {
            return FloatingActionButton.this.A;
        }
    }

    public FloatingActionButton(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, vi.b.f39741w);
    }

    private com.google.android.material.floatingactionbutton.b e() {
        return new c(this, new b());
    }

    private int g(int i10) {
        int i11 = this.f13211x;
        if (i11 != 0) {
            return i11;
        }
        Resources resources = getResources();
        return i10 != -1 ? i10 != 1 ? resources.getDimensionPixelSize(vi.d.f39774j) : resources.getDimensionPixelSize(vi.d.f39772i) : Math.max(resources.getConfiguration().screenWidthDp, resources.getConfiguration().screenHeightDp) < 470 ? g(1) : g(0);
    }

    private com.google.android.material.floatingactionbutton.b getImpl() {
        if (this.F == null) {
            this.F = e();
        }
        return this.F;
    }

    private void i(Rect rect) {
        int i10 = rect.left;
        Rect rect2 = this.B;
        rect.left = i10 + rect2.left;
        rect.top += rect2.top;
        rect.right -= rect2.right;
        rect.bottom -= rect2.bottom;
    }

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

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

    private b.j m(a aVar) {
        return null;
    }

    @Override // fj.a
    public boolean a() {
        return this.E.c();
    }

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

    public boolean f(Rect rect) {
        if (!s0.Q(this)) {
            return false;
        }
        rect.set(0, 0, getWidth(), getHeight());
        i(rect);
        return true;
    }

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

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

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

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

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

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

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

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

    public int getExpandedComponentIdHint() {
        return this.E.b();
    }

    public f getHideMotionSpec() {
        return getImpl().l();
    }

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

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

    public lj.k getShapeAppearanceModel() {
        return (lj.k) i.g(getImpl().q());
    }

    public f getShowMotionSpec() {
        return getImpl().r();
    }

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

    /* JADX INFO: Access modifiers changed from: package-private */
    public int getSizeDimension() {
        return g(this.f13210w);
    }

    public ColorStateList getSupportBackgroundTintList() {
        return getBackgroundTintList();
    }

    public PorterDuff.Mode getSupportBackgroundTintMode() {
        return getBackgroundTintMode();
    }

    public ColorStateList getSupportImageTintList() {
        return this.f13206s;
    }

    public PorterDuff.Mode getSupportImageTintMode() {
        return this.f13207t;
    }

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

    void h(a aVar, boolean z10) {
        getImpl().s(m(aVar), z10);
    }

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

    void l(a aVar, boolean z10) {
        getImpl().Y(m(aVar), z10);
    }

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

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

    @Override // android.widget.ImageView, android.view.View
    protected void onMeasure(int i10, int i11) {
        int sizeDimension = getSizeDimension();
        this.f13212y = (sizeDimension - this.f13213z) / 2;
        getImpl().b0();
        int min = Math.min(k(sizeDimension, i10), k(sizeDimension, i11));
        Rect rect = this.B;
        setMeasuredDimension(rect.left + min + rect.right, min + rect.top + rect.bottom);
    }

    @Override // android.view.View
    protected void onRestoreInstanceState(Parcelable parcelable) {
        if (!(parcelable instanceof mj.a)) {
            super.onRestoreInstanceState(parcelable);
            return;
        }
        mj.a aVar = (mj.a) parcelable;
        super.onRestoreInstanceState(aVar.a());
        this.E.d((Bundle) i.g(aVar.f29154r.get("expandableWidgetHelper")));
    }

    @Override // android.view.View
    protected Parcelable onSaveInstanceState() {
        Parcelable onSaveInstanceState = super.onSaveInstanceState();
        if (onSaveInstanceState == null) {
            onSaveInstanceState = new Bundle();
        }
        mj.a aVar = new mj.a(onSaveInstanceState);
        aVar.f29154r.put("expandableWidgetHelper", this.E.e());
        return aVar;
    }

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

    @Override // android.view.View
    public void setBackgroundColor(int i10) {
        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 i10) {
        Log.i("FloatingActionButton", "Setting a custom background is not supported.");
    }

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

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

    public void setCompatElevation(float f10) {
        getImpl().J(f10);
    }

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

    public void setCompatHoveredFocusedTranslationZ(float f10) {
        getImpl().M(f10);
    }

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

    public void setCompatPressedTranslationZ(float f10) {
        getImpl().Q(f10);
    }

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

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

    @Override // android.view.View
    public void setElevation(float f10) {
        super.setElevation(f10);
        getImpl().c0(f10);
    }

    public void setEnsureMinTouchTargetSize(boolean z10) {
        if (z10 != getImpl().k()) {
            getImpl().K(z10);
            requestLayout();
        }
    }

    public void setExpandedComponentIdHint(int i10) {
        this.E.f(i10);
    }

    public void setHideMotionSpec(f fVar) {
        getImpl().L(fVar);
    }

    public void setHideMotionSpecResource(int i10) {
        setHideMotionSpec(f.c(getContext(), i10));
    }

    @Override // android.widget.ImageView
    public void setImageDrawable(Drawable drawable) {
        if (getDrawable() != drawable) {
            super.setImageDrawable(drawable);
            getImpl().a0();
            if (this.f13206s != null) {
                j();
            }
        }
    }

    @Override // android.widget.ImageView
    public void setImageResource(int i10) {
        this.D.i(i10);
        j();
    }

    public void setMaxImageSize(int i10) {
        this.f13213z = i10;
        getImpl().O(i10);
    }

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

    @Override // android.view.View
    public void setScaleX(float f10) {
        super.setScaleX(f10);
        getImpl().E();
    }

    @Override // android.view.View
    public void setScaleY(float f10) {
        super.setScaleY(f10);
        getImpl().E();
    }

    public void setShadowPaddingEnabled(boolean z10) {
        getImpl().S(z10);
    }

    @Override // lj.n
    public void setShapeAppearanceModel(lj.k kVar) {
        getImpl().T(kVar);
    }

    public void setShowMotionSpec(f fVar) {
        getImpl().U(fVar);
    }

    public void setShowMotionSpecResource(int i10) {
        setShowMotionSpec(f.c(getContext(), i10));
    }

    public void setSize(int i10) {
        this.f13211x = 0;
        if (i10 != this.f13210w) {
            this.f13210w = i10;
            requestLayout();
        }
    }

    public void setSupportBackgroundTintList(ColorStateList colorStateList) {
        setBackgroundTintList(colorStateList);
    }

    public void setSupportBackgroundTintMode(PorterDuff.Mode mode) {
        setBackgroundTintMode(mode);
    }

    public void setSupportImageTintList(ColorStateList colorStateList) {
        if (this.f13206s != colorStateList) {
            this.f13206s = colorStateList;
            j();
        }
    }

    public void setSupportImageTintMode(PorterDuff.Mode mode) {
        if (this.f13207t != mode) {
            this.f13207t = mode;
            j();
        }
    }

    @Override // android.view.View
    public void setTranslationX(float f10) {
        super.setTranslationX(f10);
        getImpl().F();
    }

    @Override // android.view.View
    public void setTranslationY(float f10) {
        super.setTranslationY(f10);
        getImpl().F();
    }

    @Override // android.view.View
    public void setTranslationZ(float f10) {
        super.setTranslationZ(f10);
        getImpl().F();
    }

    public void setUseCompatPadding(boolean z10) {
        if (this.A != z10) {
            this.A = z10;
            getImpl().y();
        }
    }

    @Override // com.google.android.material.internal.r, android.widget.ImageView, android.view.View
    public void setVisibility(int i10) {
        super.setVisibility(i10);
    }

    /* loaded from: classes3.dex */
    protected static class BaseBehavior<T extends FloatingActionButton> extends CoordinatorLayout.c {

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

        /* renamed from: b, reason: collision with root package name */
        private boolean f13215b;

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

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

        private void G(CoordinatorLayout coordinatorLayout, FloatingActionButton floatingActionButton) {
            Rect rect = floatingActionButton.B;
            if (rect == null || rect.centerX() <= 0 || rect.centerY() <= 0) {
                return;
            }
            CoordinatorLayout.f fVar = (CoordinatorLayout.f) floatingActionButton.getLayoutParams();
            int i10 = 0;
            int i11 = 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) {
                i10 = rect.bottom;
            } else if (floatingActionButton.getTop() <= ((ViewGroup.MarginLayoutParams) fVar).topMargin) {
                i10 = -rect.top;
            }
            if (i10 != 0) {
                s0.X(floatingActionButton, i10);
            }
            if (i11 != 0) {
                s0.W(floatingActionButton, i11);
            }
        }

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

        private boolean K(CoordinatorLayout coordinatorLayout, AppBarLayout appBarLayout, FloatingActionButton floatingActionButton) {
            if (!J(appBarLayout, floatingActionButton)) {
                return false;
            }
            if (this.f13214a == null) {
                this.f13214a = new Rect();
            }
            Rect rect = this.f13214a;
            com.google.android.material.internal.c.a(coordinatorLayout, appBarLayout, rect);
            if (rect.bottom <= appBarLayout.getMinimumHeightForVisibleOverlappingContent()) {
                floatingActionButton.h(null, false);
                return true;
            }
            floatingActionButton.l(null, false);
            return true;
        }

        private boolean L(View view, FloatingActionButton floatingActionButton) {
            if (!J(view, floatingActionButton)) {
                return false;
            }
            if (view.getTop() < (floatingActionButton.getHeight() / 2) + ((ViewGroup.MarginLayoutParams) ((CoordinatorLayout.f) floatingActionButton.getLayoutParams())).topMargin) {
                floatingActionButton.h(null, false);
                return true;
            }
            floatingActionButton.l(null, false);
            return true;
        }

        @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
        /* renamed from: E, reason: merged with bridge method [inline-methods] */
        public boolean b(CoordinatorLayout coordinatorLayout, FloatingActionButton floatingActionButton, Rect rect) {
            Rect rect2 = floatingActionButton.B;
            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
        /* renamed from: H, reason: merged with bridge method [inline-methods] */
        public boolean h(CoordinatorLayout coordinatorLayout, FloatingActionButton floatingActionButton, View view) {
            if (view instanceof AppBarLayout) {
                K(coordinatorLayout, (AppBarLayout) view, floatingActionButton);
                return false;
            }
            if (!F(view)) {
                return false;
            }
            L(view, floatingActionButton);
            return false;
        }

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

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

        public BaseBehavior(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
            TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, l.E2);
            this.f13215b = obtainStyledAttributes.getBoolean(l.F2, true);
            obtainStyledAttributes.recycle();
        }
    }

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public FloatingActionButton(Context context, AttributeSet attributeSet, int i10) {
        super(nj.a.c(context, attributeSet, i10, r6), attributeSet, i10);
        int i11 = G;
        this.B = new Rect();
        this.C = new Rect();
        Context context2 = getContext();
        TypedArray h10 = o.h(context2, attributeSet, l.f40055o2, i10, i11, new int[0]);
        this.f13204q = ij.c.a(context2, h10, l.f40075q2);
        this.f13205r = q.f(h10.getInt(l.f40085r2, -1), null);
        this.f13208u = ij.c.a(context2, h10, l.B2);
        this.f13210w = h10.getInt(l.f40135w2, -1);
        this.f13211x = h10.getDimensionPixelSize(l.f40125v2, 0);
        this.f13209v = h10.getDimensionPixelSize(l.f40095s2, 0);
        float dimension = h10.getDimension(l.f40105t2, BitmapDescriptorFactory.HUE_RED);
        float dimension2 = h10.getDimension(l.f40155y2, BitmapDescriptorFactory.HUE_RED);
        float dimension3 = h10.getDimension(l.A2, BitmapDescriptorFactory.HUE_RED);
        this.A = h10.getBoolean(l.D2, false);
        int dimensionPixelSize = getResources().getDimensionPixelSize(vi.d.f39763d0);
        setMaxImageSize(h10.getDimensionPixelSize(l.f40165z2, 0));
        f b10 = f.b(context2, h10, l.C2);
        f b11 = f.b(context2, h10, l.f40145x2);
        lj.k m10 = lj.k.g(context2, attributeSet, i10, i11, lj.k.f28357m).m();
        boolean z10 = h10.getBoolean(l.f40115u2, false);
        setEnabled(h10.getBoolean(l.f40065p2, true));
        h10.recycle();
        p pVar = new p(this);
        this.D = pVar;
        pVar.g(attributeSet, i10);
        this.E = new fj.b(this);
        getImpl().T(m10);
        getImpl().t(this.f13204q, this.f13205r, this.f13208u, this.f13209v);
        getImpl().P(dimensionPixelSize);
        getImpl().J(dimension);
        getImpl().M(dimension2);
        getImpl().Q(dimension3);
        getImpl().U(b10);
        getImpl().L(b11);
        getImpl().K(z10);
        setScaleType(ImageView.ScaleType.MATRIX);
    }

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