package com.google.android.material.transformation;

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.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Pair;
import android.util.Property;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.collection.s;
import androidx.core.view.y1;
import com.google.android.gms.measurement.internal.c2;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import d0.d;
import g9.f;
import java.util.ArrayList;
import r3.r;
import x8.g;
import y8.a;
import y8.c;
import y8.e;
import y8.h;
import y8.i;
import z9.b;

/* JADX INFO: loaded from: classes2.dex */
@Deprecated
public abstract class FabTransformationBehavior extends ExpandableTransformationBehavior {

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final RectF f23528c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final RectF f23529d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final int[] f23530e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public float f23531f;

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

    public FabTransformationBehavior() {
        this.f23527b = new Rect();
        this.f23528c = new RectF();
        this.f23529d = new RectF();
        this.f23530e = new int[2];
    }

    public static float C(b bVar, h hVar, float f10) {
        long j10 = hVar.f36876a;
        h hVarD = bVar.timings.d("expansion");
        return a.a(f10, 0.0f, hVar.getInterpolator().getInterpolation((((hVarD.f36876a + hVarD.f36877b) + 17) - j10) / hVar.f36877b));
    }

    @Nullable
    private ViewGroup calculateChildContentContainer(@NonNull View view) {
        View viewFindViewById = view.findViewById(g.mtrl_child_content_container);
        return viewFindViewById != null ? toViewGroupOrNull(viewFindViewById) : ((view instanceof TransformationChildLayout) || (view instanceof TransformationChildCard)) ? toViewGroupOrNull(((ViewGroup) view).getChildAt(0)) : toViewGroupOrNull(view);
    }

    @Nullable
    private ViewGroup toViewGroupOrNull(View view) {
        if (view instanceof ViewGroup) {
            return (ViewGroup) view;
        }
        return null;
    }

    public static Pair z(float f10, float f11, boolean z10, b bVar) {
        h hVarD;
        h hVarD2;
        if (f10 == 0.0f || f11 == 0.0f) {
            hVarD = bVar.timings.d("translationXLinear");
            hVarD2 = bVar.timings.d("translationYLinear");
        } else if ((!z10 || f11 >= 0.0f) && (z10 || f11 <= 0.0f)) {
            hVarD = bVar.timings.d("translationXCurveDownwards");
            hVarD2 = bVar.timings.d("translationYCurveDownwards");
        } else {
            hVarD = bVar.timings.d("translationXCurveUpwards");
            hVarD2 = bVar.timings.d("translationYCurveUpwards");
        }
        return new Pair(hVarD, hVarD2);
    }

    public final float A(View view, View view2, i iVar) {
        float fCenterX;
        float fCenterX2;
        float f10;
        RectF rectF = this.f23528c;
        RectF rectF2 = this.f23529d;
        D(view, rectF);
        rectF.offset(this.f23531f, this.f23532g);
        D(view2, rectF2);
        int i10 = iVar.f36880a & 7;
        if (i10 == 1) {
            fCenterX = rectF2.centerX();
            fCenterX2 = rectF.centerX();
        } else if (i10 == 3) {
            fCenterX = rectF2.left;
            fCenterX2 = rectF.left;
        } else {
            if (i10 != 5) {
                f10 = 0.0f;
                return f10 + iVar.f36881b;
            }
            fCenterX = rectF2.right;
            fCenterX2 = rectF.right;
        }
        f10 = fCenterX - fCenterX2;
        return f10 + iVar.f36881b;
    }

    public final float B(View view, View view2, i iVar) {
        float fCenterY;
        float fCenterY2;
        float f10;
        RectF rectF = this.f23528c;
        RectF rectF2 = this.f23529d;
        D(view, rectF);
        rectF.offset(this.f23531f, this.f23532g);
        D(view2, rectF2);
        int i10 = iVar.f36880a & 112;
        if (i10 == 16) {
            fCenterY = rectF2.centerY();
            fCenterY2 = rectF.centerY();
        } else if (i10 == 48) {
            fCenterY = rectF2.top;
            fCenterY2 = rectF.top;
        } else {
            if (i10 != 80) {
                f10 = 0.0f;
                return f10 + iVar.f36882c;
            }
            fCenterY = rectF2.bottom;
            fCenterY2 = rectF.bottom;
        }
        f10 = fCenterY - fCenterY2;
        return f10 + iVar.f36882c;
    }

    public final void D(View view, RectF rectF) {
        rectF.set(0.0f, 0.0f, view.getWidth(), view.getHeight());
        view.getLocationInWindow(this.f23530e);
        rectF.offsetTo(r0[0], r0[1]);
        rectF.offset((int) (-view.getTranslationX()), (int) (-view.getTranslationY()));
    }

    public abstract b E(Context context, boolean z10);

    @Override // com.google.android.material.transformation.ExpandableBehavior, d0.b
    public final boolean f(View view, View view2) {
        if (view.getVisibility() == 8) {
            throw new IllegalStateException("This behavior cannot be attached to a GONE view. Set the view to INVISIBLE instead.");
        }
        if (!(view2 instanceof FloatingActionButton)) {
            return false;
        }
        int expandedComponentIdHint = ((FloatingActionButton) view2).getExpandedComponentIdHint();
        return expandedComponentIdHint == 0 || expandedComponentIdHint == view.getId();
    }

    @Override // d0.b
    public final void g(d dVar) {
        if (dVar.f24891h == 0) {
            dVar.f24891h = 80;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:33:0x0159  */
    @Override // com.google.android.material.transformation.ExpandableTransformationBehavior
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final AnimatorSet y(View view, View view2, boolean z10, boolean z11) {
        ObjectAnimator objectAnimatorOfFloat;
        ArrayList arrayList;
        ObjectAnimator objectAnimatorOfFloat2;
        ObjectAnimator objectAnimatorOfFloat3;
        ArrayList arrayList2;
        boolean z12;
        b bVar;
        g9.g gVar;
        AnimatorSet animatorSetA;
        boolean z13;
        ObjectAnimator objectAnimatorOfInt;
        b bVar2;
        ViewGroup viewGroupCalculateChildContentContainer;
        int i10;
        ObjectAnimator objectAnimatorOfFloat4;
        ObjectAnimator objectAnimatorOfInt2;
        b bVarE = E(view2.getContext(), z10);
        if (z10) {
            this.f23531f = view.getTranslationX();
            this.f23532g = view.getTranslationY();
        }
        ArrayList arrayList3 = new ArrayList();
        ArrayList arrayList4 = new ArrayList();
        float elevation = view2.getElevation() - view.getElevation();
        if (z10) {
            if (!z11) {
                view2.setTranslationZ(-elevation);
            }
            objectAnimatorOfFloat = ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.TRANSLATION_Z, 0.0f);
        } else {
            objectAnimatorOfFloat = ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.TRANSLATION_Z, -elevation);
        }
        bVarE.timings.d("elevation").a(objectAnimatorOfFloat);
        arrayList3.add(objectAnimatorOfFloat);
        RectF rectF = this.f23528c;
        float fA = A(view, view2, bVarE.f37120a);
        float fB = B(view, view2, bVarE.f37120a);
        Pair pairZ = z(fA, fB, z10, bVarE);
        h hVar = (h) pairZ.first;
        h hVar2 = (h) pairZ.second;
        RectF rectF2 = this.f23529d;
        Rect rect = this.f23527b;
        if (z10) {
            if (!z11) {
                view2.setTranslationX(-fA);
                view2.setTranslationY(-fB);
            }
            arrayList = arrayList4;
            ObjectAnimator objectAnimatorOfFloat5 = ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.TRANSLATION_X, 0.0f);
            ObjectAnimator objectAnimatorOfFloat6 = ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.TRANSLATION_Y, 0.0f);
            float fC = C(bVarE, hVar, -fA);
            float fC2 = C(bVarE, hVar2, -fB);
            view2.getWindowVisibleDisplayFrame(rect);
            rectF.set(rect);
            D(view2, rectF2);
            rectF2.offset(fC, fC2);
            rectF2.intersect(rectF);
            rectF.set(rectF2);
            objectAnimatorOfFloat3 = objectAnimatorOfFloat6;
            objectAnimatorOfFloat2 = objectAnimatorOfFloat5;
        } else {
            arrayList = arrayList4;
            objectAnimatorOfFloat2 = ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.TRANSLATION_X, -fA);
            objectAnimatorOfFloat3 = ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.TRANSLATION_Y, -fB);
        }
        hVar.a(objectAnimatorOfFloat2);
        hVar2.a(objectAnimatorOfFloat3);
        arrayList3.add(objectAnimatorOfFloat2);
        arrayList3.add(objectAnimatorOfFloat3);
        float fWidth = rectF.width();
        float fHeight = rectF.height();
        float fA2 = A(view, view2, bVarE.f37120a);
        float fB2 = B(view, view2, bVarE.f37120a);
        Pair pairZ2 = z(fA2, fB2, z10, bVarE);
        h hVar3 = (h) pairZ2.first;
        h hVar4 = (h) pairZ2.second;
        Property property = View.TRANSLATION_X;
        float[] fArr = new float[1];
        fArr[0] = z10 ? fA2 : this.f23531f;
        ObjectAnimator objectAnimatorOfFloat7 = ObjectAnimator.ofFloat(view, (Property<View, Float>) property, fArr);
        Property property2 = View.TRANSLATION_Y;
        float[] fArr2 = new float[1];
        fArr2[0] = z10 ? fB2 : this.f23532g;
        ObjectAnimator objectAnimatorOfFloat8 = ObjectAnimator.ofFloat(view, (Property<View, Float>) property2, fArr2);
        hVar3.a(objectAnimatorOfFloat7);
        hVar4.a(objectAnimatorOfFloat8);
        arrayList3.add(objectAnimatorOfFloat7);
        arrayList3.add(objectAnimatorOfFloat8);
        boolean z14 = view2 instanceof g9.g;
        if (z14 && (view instanceof ImageView)) {
            g9.g gVar2 = (g9.g) view2;
            Drawable drawable = ((ImageView) view).getDrawable();
            if (drawable != null) {
                drawable.mutate();
                if (z10) {
                    if (!z11) {
                        drawable.setAlpha(255);
                    }
                    objectAnimatorOfInt2 = ObjectAnimator.ofInt(drawable, e.f36871a, 0);
                } else {
                    objectAnimatorOfInt2 = ObjectAnimator.ofInt(drawable, e.f36871a, 255);
                }
                objectAnimatorOfInt2.addUpdateListener(new androidx.swiperefreshlayout.widget.b(this, view2, 2));
                bVarE.timings.d("iconFade").a(objectAnimatorOfInt2);
                arrayList3.add(objectAnimatorOfInt2);
                y1 y1Var = new y1(this, gVar2, drawable, 2);
                arrayList2 = arrayList;
                arrayList2.add(y1Var);
            }
        } else {
            arrayList2 = arrayList;
        }
        if (z14) {
            g9.g gVar3 = (g9.g) view2;
            i iVar = bVarE.f37120a;
            D(view, rectF);
            rectF.offset(this.f23531f, this.f23532g);
            D(view2, rectF2);
            rectF2.offset(-A(view, view2, iVar), 0.0f);
            float fCenterX = rectF.centerX() - rectF2.left;
            i iVar2 = bVarE.f37120a;
            D(view, rectF);
            z12 = z14;
            rectF.offset(this.f23531f, this.f23532g);
            D(view2, rectF2);
            rectF2.offset(0.0f, -B(view, view2, iVar2));
            float fCenterY = rectF.centerY() - rectF2.top;
            ((FloatingActionButton) view).f(rect);
            float fWidth2 = rect.width() / 2.0f;
            h hVarD = bVarE.timings.d("expansion");
            if (z10) {
                if (!z11) {
                    gVar3.setRevealInfo(new f(fCenterX, fCenterY, fWidth2));
                }
                if (z11) {
                    fWidth2 = gVar3.getRevealInfo().f26333c;
                }
                animatorSetA = com.bumptech.glide.f.a(gVar3, fCenterX, fCenterY, c2.h(fCenterX, fCenterY, fWidth, fHeight));
                animatorSetA.addListener(new r(this, gVar3, 3));
                long j10 = hVarD.f36876a;
                int i11 = (int) fCenterX;
                int i12 = (int) fCenterY;
                if (j10 > 0) {
                    Animator animatorCreateCircularReveal = ViewAnimationUtils.createCircularReveal(view2, i11, i12, fWidth2, fWidth2);
                    animatorCreateCircularReveal.setStartDelay(0L);
                    animatorCreateCircularReveal.setDuration(j10);
                    arrayList3.add(animatorCreateCircularReveal);
                }
                bVar = bVarE;
                gVar = gVar3;
            } else {
                float f10 = gVar3.getRevealInfo().f26333c;
                AnimatorSet animatorSetA2 = com.bumptech.glide.f.a(gVar3, fCenterX, fCenterY, fWidth2);
                long j11 = hVarD.f36876a;
                int i13 = (int) fCenterX;
                int i14 = (int) fCenterY;
                g9.g gVar4 = gVar3;
                long jMax = 0;
                if (j11 > 0) {
                    Animator animatorCreateCircularReveal2 = ViewAnimationUtils.createCircularReveal(view2, i13, i14, f10, f10);
                    animatorCreateCircularReveal2.setStartDelay(0L);
                    animatorCreateCircularReveal2.setDuration(j11);
                    arrayList3.add(animatorCreateCircularReveal2);
                }
                s sVar = bVarE.timings.f36874a;
                int i15 = sVar.f968c;
                int i16 = 0;
                while (i16 < i15) {
                    s sVar2 = sVar;
                    h hVar5 = (h) sVar.m(i16);
                    jMax = Math.max(jMax, hVar5.f36876a + hVar5.f36877b);
                    i16++;
                    gVar4 = gVar4;
                    sVar = sVar2;
                    i15 = i15;
                    bVarE = bVarE;
                }
                bVar = bVarE;
                gVar = gVar4;
                long j12 = hVarD.f36876a + hVarD.f36877b;
                if (j12 < jMax) {
                    Animator animatorCreateCircularReveal3 = ViewAnimationUtils.createCircularReveal(view2, i13, i14, fWidth2, fWidth2);
                    animatorCreateCircularReveal3.setStartDelay(j12);
                    animatorCreateCircularReveal3.setDuration(jMax - j12);
                    arrayList3.add(animatorCreateCircularReveal3);
                }
                animatorSetA = animatorSetA2;
            }
            hVarD.a(animatorSetA);
            arrayList3.add(animatorSetA);
            arrayList2.add(new l.e(gVar, 6));
        } else {
            bVar = bVarE;
            z12 = z14;
        }
        if (z12) {
            g9.g gVar5 = (g9.g) view2;
            ColorStateList backgroundTintList = view.getBackgroundTintList();
            int colorForState = backgroundTintList != null ? backgroundTintList.getColorForState(view.getDrawableState(), backgroundTintList.getDefaultColor()) : 0;
            int i17 = 16777215 & colorForState;
            z13 = z10;
            if (z13) {
                if (!z11) {
                    gVar5.setCircularRevealScrimColor(colorForState);
                }
                objectAnimatorOfInt = ObjectAnimator.ofInt(gVar5, g9.e.f26330a, i17);
            } else {
                objectAnimatorOfInt = ObjectAnimator.ofInt(gVar5, g9.e.f26330a, colorForState);
            }
            objectAnimatorOfInt.setEvaluator(c.f36869a);
            bVar2 = bVar;
            bVar2.timings.d("color").a(objectAnimatorOfInt);
            arrayList3.add(objectAnimatorOfInt);
        } else {
            z13 = z10;
            bVar2 = bVar;
        }
        if ((view2 instanceof ViewGroup) && (viewGroupCalculateChildContentContainer = calculateChildContentContainer(view2)) != null) {
            if (z13) {
                if (!z11) {
                    y8.d.f36870a.set(viewGroupCalculateChildContentContainer, Float.valueOf(0.0f));
                }
                i10 = 0;
                objectAnimatorOfFloat4 = ObjectAnimator.ofFloat(viewGroupCalculateChildContentContainer, y8.d.f36870a, 1.0f);
            } else {
                i10 = 0;
                objectAnimatorOfFloat4 = ObjectAnimator.ofFloat(viewGroupCalculateChildContentContainer, y8.d.f36870a, 0.0f);
            }
            bVar2.timings.d("contentFade").a(objectAnimatorOfFloat4);
            arrayList3.add(objectAnimatorOfFloat4);
        } else {
            i10 = 0;
        }
        AnimatorSet animatorSet = new AnimatorSet();
        y8.b.a(animatorSet, arrayList3);
        animatorSet.addListener(new com.google.android.material.floatingactionbutton.d(z13, view2, view));
        int size = arrayList2.size();
        while (i10 < size) {
            animatorSet.addListener((Animator.AnimatorListener) arrayList2.get(i10));
            i10++;
        }
        return animatorSet;
    }

    public FabTransformationBehavior(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f23527b = new Rect();
        this.f23528c = new RectF();
        this.f23529d = new RectF();
        this.f23530e = new int[2];
    }
}
