package com.google.android.material.transformation;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Pair;
import android.util.Property;
import android.view.View;
import android.view.ViewGroup;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.s0;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList;
import java.util.List;
import wi.c;
import wi.f;
import wi.g;
import wi.h;

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

    /* renamed from: c, reason: collision with root package name */
    private final Rect f13791c;

    /* renamed from: d, reason: collision with root package name */
    private final RectF f13792d;

    /* renamed from: e, reason: collision with root package name */
    private final RectF f13793e;

    /* renamed from: f, reason: collision with root package name */
    private final int[] f13794f;

    /* renamed from: g, reason: collision with root package name */
    private float f13795g;

    /* renamed from: h, reason: collision with root package name */
    private float f13796h;

    /* loaded from: classes3.dex */
    class a extends AnimatorListenerAdapter {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ boolean f13797a;

        /* renamed from: b, reason: collision with root package name */
        final /* synthetic */ View f13798b;

        /* renamed from: c, reason: collision with root package name */
        final /* synthetic */ View f13799c;

        a(boolean z10, View view, View view2) {
            this.f13797a = z10;
            this.f13798b = view;
            this.f13799c = view2;
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
            if (this.f13797a) {
                return;
            }
            this.f13798b.setVisibility(4);
            this.f13799c.setAlpha(1.0f);
            this.f13799c.setVisibility(0);
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationStart(Animator animator) {
            if (this.f13797a) {
                this.f13798b.setVisibility(0);
                this.f13799c.setAlpha(BitmapDescriptorFactory.HUE_RED);
                this.f13799c.setVisibility(4);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    /* loaded from: classes3.dex */
    public static class b {

        /* renamed from: a, reason: collision with root package name */
        public f f13801a;

        /* renamed from: b, reason: collision with root package name */
        public h f13802b;
    }

    public FabTransformationBehavior() {
        this.f13791c = new Rect();
        this.f13792d = new RectF();
        this.f13793e = new RectF();
        this.f13794f = new int[2];
    }

    private ViewGroup K(View view) {
        View findViewById = view.findViewById(vi.f.C);
        return findViewById != null ? a0(findViewById) : a0(view);
    }

    private void L(View view, b bVar, g gVar, g gVar2, float f10, float f11, float f12, float f13, RectF rectF) {
        float Q = Q(bVar, gVar, f10, f12);
        float Q2 = Q(bVar, gVar2, f11, f13);
        Rect rect = this.f13791c;
        view.getWindowVisibleDisplayFrame(rect);
        RectF rectF2 = this.f13792d;
        rectF2.set(rect);
        RectF rectF3 = this.f13793e;
        R(view, rectF3);
        rectF3.offset(Q, Q2);
        rectF3.intersect(rectF2);
        rectF.set(rectF3);
    }

    private void M(View view, RectF rectF) {
        R(view, rectF);
        rectF.offset(this.f13795g, this.f13796h);
    }

    private Pair N(float f10, float f11, boolean z10, b bVar) {
        g e10;
        g e11;
        if (f10 == BitmapDescriptorFactory.HUE_RED || f11 == BitmapDescriptorFactory.HUE_RED) {
            e10 = bVar.f13801a.e("translationXLinear");
            e11 = bVar.f13801a.e("translationYLinear");
        } else if ((!z10 || f11 >= BitmapDescriptorFactory.HUE_RED) && (z10 || f11 <= BitmapDescriptorFactory.HUE_RED)) {
            e10 = bVar.f13801a.e("translationXCurveDownwards");
            e11 = bVar.f13801a.e("translationYCurveDownwards");
        } else {
            e10 = bVar.f13801a.e("translationXCurveUpwards");
            e11 = bVar.f13801a.e("translationYCurveUpwards");
        }
        return new Pair(e10, e11);
    }

    private float O(View view, View view2, h hVar) {
        float centerX;
        float centerX2;
        float f10;
        RectF rectF = this.f13792d;
        RectF rectF2 = this.f13793e;
        M(view, rectF);
        R(view2, rectF2);
        int i10 = hVar.f49494a & 7;
        if (i10 == 1) {
            centerX = rectF2.centerX();
            centerX2 = rectF.centerX();
        } else if (i10 == 3) {
            centerX = rectF2.left;
            centerX2 = rectF.left;
        } else {
            if (i10 != 5) {
                f10 = BitmapDescriptorFactory.HUE_RED;
                return f10 + hVar.f49495b;
            }
            centerX = rectF2.right;
            centerX2 = rectF.right;
        }
        f10 = centerX - centerX2;
        return f10 + hVar.f49495b;
    }

    private float P(View view, View view2, h hVar) {
        float centerY;
        float centerY2;
        float f10;
        RectF rectF = this.f13792d;
        RectF rectF2 = this.f13793e;
        M(view, rectF);
        R(view2, rectF2);
        int i10 = hVar.f49494a & 112;
        if (i10 == 16) {
            centerY = rectF2.centerY();
            centerY2 = rectF.centerY();
        } else if (i10 == 48) {
            centerY = rectF2.top;
            centerY2 = rectF.top;
        } else {
            if (i10 != 80) {
                f10 = BitmapDescriptorFactory.HUE_RED;
                return f10 + hVar.f49496c;
            }
            centerY = rectF2.bottom;
            centerY2 = rectF.bottom;
        }
        f10 = centerY - centerY2;
        return f10 + hVar.f49496c;
    }

    private float Q(b bVar, g gVar, float f10, float f11) {
        long c10 = gVar.c();
        long d10 = gVar.d();
        g e10 = bVar.f13801a.e("expansion");
        return wi.a.a(f10, f11, gVar.e().getInterpolation(((float) (((e10.c() + e10.d()) + 17) - c10)) / ((float) d10)));
    }

    private void R(View view, RectF rectF) {
        rectF.set(BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED, view.getWidth(), view.getHeight());
        view.getLocationInWindow(this.f13794f);
        rectF.offsetTo(r3[0], r3[1]);
        rectF.offset((int) (-view.getTranslationX()), (int) (-view.getTranslationY()));
    }

    private void S(View view, View view2, boolean z10, boolean z11, b bVar, List list, List list2) {
        ViewGroup K;
        ObjectAnimator ofFloat;
        if ((view2 instanceof ViewGroup) && (K = K(view2)) != null) {
            if (z10) {
                if (!z11) {
                    c.f49482a.set(K, Float.valueOf(BitmapDescriptorFactory.HUE_RED));
                }
                ofFloat = ObjectAnimator.ofFloat(K, (Property<ViewGroup, Float>) c.f49482a, 1.0f);
            } else {
                ofFloat = ObjectAnimator.ofFloat(K, (Property<ViewGroup, Float>) c.f49482a, BitmapDescriptorFactory.HUE_RED);
            }
            bVar.f13801a.e("contentFade").a(ofFloat);
            list.add(ofFloat);
        }
    }

    private void T(View view, View view2, boolean z10, boolean z11, b bVar, List list, List list2) {
    }

    private void U(View view, View view2, boolean z10, b bVar, List list) {
        float O = O(view, view2, bVar.f13802b);
        float P = P(view, view2, bVar.f13802b);
        Pair N = N(O, P, z10, bVar);
        g gVar = (g) N.first;
        g gVar2 = (g) N.second;
        Property property = View.TRANSLATION_X;
        float[] fArr = new float[1];
        if (!z10) {
            O = this.f13795g;
        }
        fArr[0] = O;
        ObjectAnimator ofFloat = ObjectAnimator.ofFloat(view, (Property<View, Float>) property, fArr);
        Property property2 = View.TRANSLATION_Y;
        float[] fArr2 = new float[1];
        if (!z10) {
            P = this.f13796h;
        }
        fArr2[0] = P;
        ObjectAnimator ofFloat2 = ObjectAnimator.ofFloat(view, (Property<View, Float>) property2, fArr2);
        gVar.a(ofFloat);
        gVar2.a(ofFloat2);
        list.add(ofFloat);
        list.add(ofFloat2);
    }

    private void V(View view, View view2, boolean z10, boolean z11, b bVar, List list, List list2) {
        ObjectAnimator ofFloat;
        float u10 = s0.u(view2) - s0.u(view);
        if (z10) {
            if (!z11) {
                view2.setTranslationZ(-u10);
            }
            ofFloat = ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.TRANSLATION_Z, BitmapDescriptorFactory.HUE_RED);
        } else {
            ofFloat = ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.TRANSLATION_Z, -u10);
        }
        bVar.f13801a.e("elevation").a(ofFloat);
        list.add(ofFloat);
    }

    private void W(View view, View view2, boolean z10, boolean z11, b bVar, float f10, float f11, List list, List list2) {
    }

    private void X(View view, View view2, boolean z10, boolean z11, b bVar, List list, List list2) {
    }

    private void Y(View view, View view2, boolean z10, boolean z11, b bVar, List list, List list2, RectF rectF) {
        ObjectAnimator ofFloat;
        ObjectAnimator ofFloat2;
        float O = O(view, view2, bVar.f13802b);
        float P = P(view, view2, bVar.f13802b);
        Pair N = N(O, P, z10, bVar);
        g gVar = (g) N.first;
        g gVar2 = (g) N.second;
        if (z10) {
            if (!z11) {
                view2.setTranslationX(-O);
                view2.setTranslationY(-P);
            }
            ofFloat = ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.TRANSLATION_X, BitmapDescriptorFactory.HUE_RED);
            ofFloat2 = ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.TRANSLATION_Y, BitmapDescriptorFactory.HUE_RED);
            L(view2, bVar, gVar, gVar2, -O, -P, BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED, rectF);
        } else {
            ofFloat = ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.TRANSLATION_X, -O);
            ofFloat2 = ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.TRANSLATION_Y, -P);
        }
        gVar.a(ofFloat);
        gVar2.a(ofFloat2);
        list.add(ofFloat);
        list.add(ofFloat2);
    }

    private ViewGroup a0(View view) {
        if (view instanceof ViewGroup) {
            return (ViewGroup) view;
        }
        return null;
    }

    @Override // com.google.android.material.transformation.ExpandableTransformationBehavior
    protected AnimatorSet J(View view, View view2, boolean z10, boolean z11) {
        b Z = Z(view2.getContext(), z10);
        if (z10) {
            this.f13795g = view.getTranslationX();
            this.f13796h = view.getTranslationY();
        }
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        V(view, view2, z10, z11, Z, arrayList, arrayList2);
        RectF rectF = this.f13792d;
        Y(view, view2, z10, z11, Z, arrayList, arrayList2, rectF);
        float width = rectF.width();
        float height = rectF.height();
        U(view, view2, z10, Z, arrayList);
        X(view, view2, z10, z11, Z, arrayList, arrayList2);
        W(view, view2, z10, z11, Z, width, height, arrayList, arrayList2);
        T(view, view2, z10, z11, Z, arrayList, arrayList2);
        S(view, view2, z10, z11, Z, arrayList, arrayList2);
        AnimatorSet animatorSet = new AnimatorSet();
        wi.b.a(animatorSet, arrayList);
        animatorSet.addListener(new a(z10, view2, view));
        int size = arrayList2.size();
        for (int i10 = 0; i10 < size; i10++) {
            animatorSet.addListener((Animator.AnimatorListener) arrayList2.get(i10));
        }
        return animatorSet;
    }

    protected abstract b Z(Context context, boolean z10);

    @Override // com.google.android.material.transformation.ExpandableBehavior, androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public boolean e(CoordinatorLayout coordinatorLayout, 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 // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public void g(CoordinatorLayout.f fVar) {
        if (fVar.f3515h == 0) {
            fVar.f3515h = 80;
        }
    }

    public FabTransformationBehavior(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f13791c = new Rect();
        this.f13792d = new RectF();
        this.f13793e = new RectF();
        this.f13794f = new int[2];
    }
}
