package n9;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.res.Resources;
import android.graphics.Rect;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.Property;
import android.view.RoundedCorner;
import android.view.View;
import android.view.WindowInsets;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.android.material.internal.ClippableRoundedCornerLayout;
import com.google.android.material.internal.w0;
import r3.r;

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

    @Nullable
    private float[] expandedCornerRadii;

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

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

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

    @Nullable
    private Rect initialHideFromClipBounds;

    @Nullable
    private Rect initialHideToClipBounds;

    public j(ClippableRoundedCornerLayout clippableRoundedCornerLayout) {
        super(clippableRoundedCornerLayout);
        Resources resources = clippableRoundedCornerLayout.getResources();
        this.f31119f = resources.getDimension(x8.e.m3_back_progress_main_container_min_edge_gap);
        this.f31120g = resources.getDimension(x8.e.m3_back_progress_main_container_max_translation_y);
    }

    @NonNull
    private AnimatorSet createResetScaleAndTranslationAnimator(@Nullable View view) {
        AnimatorSet animatorSet = new AnimatorSet();
        View view2 = this.f31109b;
        animatorSet.playTogether(ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.SCALE_X, 1.0f), ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.SCALE_Y, 1.0f), ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.TRANSLATION_X, 0.0f), ObjectAnimator.ofFloat(view2, (Property<View, Float>) View.TRANSLATION_Y, 0.0f));
        animatorSet.addListener(new r(this, view, 1));
        return animatorSet;
    }

    public final void b() {
        this.expandedCornerRadii = null;
    }

    public final float[] c() {
        float[] fArr;
        View view;
        WindowInsets rootWindowInsets;
        RoundedCorner roundedCorner;
        RoundedCorner roundedCorner2;
        RoundedCorner roundedCorner3;
        RoundedCorner roundedCorner4;
        if (this.expandedCornerRadii == null) {
            if (Build.VERSION.SDK_INT < 31 || (rootWindowInsets = (view = this.f31109b).getRootWindowInsets()) == null) {
                fArr = new float[]{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
            } else {
                DisplayMetrics displayMetrics = view.getResources().getDisplayMetrics();
                int i10 = displayMetrics.widthPixels;
                int i11 = displayMetrics.heightPixels;
                int[] iArr = new int[2];
                view.getLocationOnScreen(iArr);
                int i12 = iArr[0];
                int i13 = iArr[1];
                int width = view.getWidth();
                int height = view.getHeight();
                int radius = (i12 == 0 && i13 == 0 && (roundedCorner4 = rootWindowInsets.getRoundedCorner(0)) != null) ? roundedCorner4.getRadius() : 0;
                int i14 = width + i12;
                float f10 = radius;
                float radius2 = (i14 < i10 || i13 != 0 || (roundedCorner3 = rootWindowInsets.getRoundedCorner(1)) == null) ? 0 : roundedCorner3.getRadius();
                float radius3 = (i14 < i10 || i13 + height < i11 || (roundedCorner2 = rootWindowInsets.getRoundedCorner(2)) == null) ? 0 : roundedCorner2.getRadius();
                float radius4 = (i12 != 0 || i13 + height < i11 || (roundedCorner = rootWindowInsets.getRoundedCorner(3)) == null) ? 0 : roundedCorner.getRadius();
                fArr = new float[]{f10, f10, radius2, radius2, radius3, radius3, radius4, radius4};
            }
            this.expandedCornerRadii = fArr;
        }
        return this.expandedCornerRadii;
    }

    public void cancelBackProgress(@Nullable View view) {
        if (super.onCancelBackProgress() == null) {
            return;
        }
        AnimatorSet animatorSetCreateResetScaleAndTranslationAnimator = createResetScaleAndTranslationAnimator(view);
        View view2 = this.f31109b;
        if (view2 instanceof ClippableRoundedCornerLayout) {
            ClippableRoundedCornerLayout clippableRoundedCornerLayout = (ClippableRoundedCornerLayout) view2;
            ValueAnimator valueAnimatorOfObject = ValueAnimator.ofObject(new i(), clippableRoundedCornerLayout.getCornerRadii(), c());
            valueAnimatorOfObject.addUpdateListener(new d9.b(clippableRoundedCornerLayout, 1));
            animatorSetCreateResetScaleAndTranslationAnimator.playTogether(valueAnimatorOfObject);
        }
        animatorSetCreateResetScaleAndTranslationAnimator.setDuration(this.f31112e);
        animatorSetCreateResetScaleAndTranslationAnimator.start();
        this.f31121h = 0.0f;
        this.initialHideToClipBounds = null;
        this.initialHideFromClipBounds = null;
    }

    public void finishBackProgress(long j10, @Nullable View view) {
        AnimatorSet animatorSetCreateResetScaleAndTranslationAnimator = createResetScaleAndTranslationAnimator(view);
        animatorSetCreateResetScaleAndTranslationAnimator.setDuration(j10);
        animatorSetCreateResetScaleAndTranslationAnimator.start();
        this.f31121h = 0.0f;
        this.initialHideToClipBounds = null;
        this.initialHideFromClipBounds = null;
    }

    @Nullable
    public Rect getInitialHideFromClipBounds() {
        return this.initialHideFromClipBounds;
    }

    @Nullable
    public Rect getInitialHideToClipBounds() {
        return this.initialHideToClipBounds;
    }

    public void startBackProgress(@NonNull androidx.activity.b bVar, @Nullable View view) {
        a(bVar);
        startBackProgress(bVar.f467b, view);
    }

    public void updateBackProgress(@NonNull androidx.activity.b bVar, @Nullable View view, float f10) {
        if (super.onUpdateBackProgress(bVar) == null) {
            return;
        }
        if (view != null && view.getVisibility() != 4) {
            view.setVisibility(4);
        }
        boolean z10 = bVar.f469d == 0;
        float interpolation = this.f31108a.getInterpolation(bVar.f468c);
        View view2 = this.f31109b;
        float width = view2.getWidth();
        float height = view2.getHeight();
        if (width <= 0.0f || height <= 0.0f) {
            return;
        }
        float fA = y8.a.a(1.0f, 0.9f, interpolation);
        float f11 = this.f31119f;
        float fA2 = y8.a.a(0.0f, Math.max(0.0f, ((width - (0.9f * width)) / 2.0f) - f11), interpolation) * (z10 ? 1 : -1);
        float fMin = Math.min(Math.max(0.0f, ((height - (fA * height)) / 2.0f) - f11), this.f31120g);
        float f12 = bVar.f467b - this.f31121h;
        float fA3 = y8.a.a(0.0f, fMin, Math.abs(f12) / height) * Math.signum(f12);
        if (Float.isNaN(fA) || Float.isNaN(fA2) || Float.isNaN(fA3)) {
            return;
        }
        view2.setScaleX(fA);
        view2.setScaleY(fA);
        view2.setTranslationX(fA2);
        view2.setTranslationY(fA3);
        if (view2 instanceof ClippableRoundedCornerLayout) {
            float[] fArrC = c();
            ((ClippableRoundedCornerLayout) view2).b(r5.getLeft(), r5.getTop(), r5.getRight(), r5.getBottom(), new float[]{y8.a.a(fArrC[0], f10, interpolation), y8.a.a(fArrC[1], f10, interpolation), y8.a.a(fArrC[2], f10, interpolation), y8.a.a(fArrC[3], f10, interpolation), y8.a.a(fArrC[4], f10, interpolation), y8.a.a(fArrC[5], f10, interpolation), y8.a.a(fArrC[6], f10, interpolation), y8.a.a(fArrC[7], f10, interpolation)});
        }
    }

    @VisibleForTesting
    public void startBackProgress(float f10, @Nullable View view) {
        View view2 = this.f31109b;
        this.initialHideToClipBounds = w0.b(0, view2);
        if (view != null) {
            this.initialHideFromClipBounds = w0.a(view2, view);
        }
        this.f31121h = f10;
    }
}
