package n9;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.res.Resources;
import android.util.Property;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.GravityInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import l.t2;

/* JADX INFO: loaded from: classes2.dex */
public final class k extends a {

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

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final float f31124h;

    public k(View view) {
        super(view);
        Resources resources = view.getResources();
        this.f31122f = resources.getDimension(x8.e.m3_back_progress_side_container_max_scale_x_distance_shrink);
        this.f31123g = resources.getDimension(x8.e.m3_back_progress_side_container_max_scale_x_distance_grow);
        this.f31124h = resources.getDimension(x8.e.m3_back_progress_side_container_max_scale_y_distance);
    }

    public final void b() {
        if (super.onCancelBackProgress() == null) {
            return;
        }
        AnimatorSet animatorSet = new AnimatorSet();
        View view = this.f31109b;
        animatorSet.playTogether(ObjectAnimator.ofFloat(view, (Property<View, Float>) View.SCALE_X, 1.0f), ObjectAnimator.ofFloat(view, (Property<View, Float>) View.SCALE_Y, 1.0f));
        if (view instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) view;
            for (int i10 = 0; i10 < viewGroup.getChildCount(); i10++) {
                animatorSet.playTogether(ObjectAnimator.ofFloat(viewGroup.getChildAt(i10), (Property<View, Float>) View.SCALE_Y, 1.0f));
            }
        }
        animatorSet.setDuration(this.f31112e);
        animatorSet.start();
    }

    public final void c(int i10, float f10, boolean z10) {
        float interpolation = this.f31108a.getInterpolation(f10);
        View view = this.f31109b;
        boolean z11 = (Gravity.getAbsoluteGravity(i10, view.getLayoutDirection()) & 3) == 3;
        boolean z12 = z10 == z11;
        int width = view.getWidth();
        int height = view.getHeight();
        float f11 = width;
        if (f11 > 0.0f) {
            float f12 = height;
            if (f12 <= 0.0f) {
                return;
            }
            float f13 = this.f31122f / f11;
            float f14 = this.f31123g / f11;
            float f15 = this.f31124h / f12;
            if (z11) {
                f11 = 0.0f;
            }
            view.setPivotX(f11);
            if (!z12) {
                f14 = -f13;
            }
            float fA = y8.a.a(0.0f, f14, interpolation);
            float f16 = fA + 1.0f;
            float fA2 = 1.0f - y8.a.a(0.0f, f15, interpolation);
            if (Float.isNaN(f16) || Float.isNaN(fA2)) {
                return;
            }
            view.setScaleX(f16);
            view.setScaleY(fA2);
            if (view instanceof ViewGroup) {
                ViewGroup viewGroup = (ViewGroup) view;
                for (int i11 = 0; i11 < viewGroup.getChildCount(); i11++) {
                    View childAt = viewGroup.getChildAt(i11);
                    childAt.setPivotX(z11 ? childAt.getWidth() + (width - childAt.getRight()) : -childAt.getLeft());
                    childAt.setPivotY(-childAt.getTop());
                    float f17 = z12 ? 1.0f - fA : 1.0f;
                    float f18 = fA2 != 0.0f ? (f16 / fA2) * f17 : 1.0f;
                    if (!Float.isNaN(f17) && !Float.isNaN(f18)) {
                        childAt.setScaleX(f17);
                        childAt.setScaleY(f18);
                    }
                }
            }
        }
    }

    public final void d(androidx.activity.b bVar, int i10) {
        if (super.onUpdateBackProgress(bVar) == null) {
            return;
        }
        c(i10, bVar.f468c, bVar.f469d == 0);
    }

    public void finishBackProgress(@NonNull androidx.activity.b bVar, @GravityInt int i10, @Nullable Animator.AnimatorListener animatorListener, @Nullable ValueAnimator.AnimatorUpdateListener animatorUpdateListener) {
        int i11;
        boolean z10 = bVar.f469d == 0;
        View view = this.f31109b;
        boolean z11 = (Gravity.getAbsoluteGravity(i10, view.getLayoutDirection()) & 3) == 3;
        float scaleX = view.getScaleX() * view.getWidth();
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
            i11 = z11 ? marginLayoutParams.leftMargin : marginLayoutParams.rightMargin;
        } else {
            i11 = 0;
        }
        float f10 = scaleX + i11;
        Property property = View.TRANSLATION_X;
        float[] fArr = new float[1];
        if (z11) {
            f10 = -f10;
        }
        fArr[0] = f10;
        ObjectAnimator objectAnimatorOfFloat = ObjectAnimator.ofFloat(view, (Property<View, Float>) property, fArr);
        if (animatorUpdateListener != null) {
            objectAnimatorOfFloat.addUpdateListener(animatorUpdateListener);
        }
        objectAnimatorOfFloat.setInterpolator(new l1.b());
        objectAnimatorOfFloat.setDuration(y8.a.c(bVar.f468c, this.f31110c, this.f31111d));
        objectAnimatorOfFloat.addListener(new t2(this, z10, i10));
        if (animatorListener != null) {
            objectAnimatorOfFloat.addListener(animatorListener);
        }
        objectAnimatorOfFloat.start();
    }
}
