package com.google.android.material.bottomsheet;

import android.R;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.SparseIntArray;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.RoundedCorner;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.WindowInsets;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.annotation.VisibleForTesting;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.s1;
import androidx.media3.exoplayer.source.ProgressiveMediaSource;
import com.google.android.gms.measurement.internal.u1;
import com.google.android.material.internal.w0;
import com.google.android.material.shape.s;
import e.t0;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
import tv.danmaku.ijk.media.player.IjkEventListener;

/* JADX INFO: loaded from: classes2.dex */
public class BottomSheetBehavior<V extends View> extends d0.b implements n9.b {
    public static final int C0 = x8.l.Widget_Design_BottomSheet_Modal;
    public final SparseIntArray A0;
    public final c B0;
    public final boolean Q;
    public final boolean R;
    public final boolean S;
    public final boolean T;
    public final boolean U;
    public final boolean V;
    public final boolean W;
    public int X;
    public int Y;
    public final boolean Z;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final int f22259a;

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    public final s f22260a0;

    @Nullable
    WeakReference<View> accessibilityDelegateViewRef;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public boolean f22261b;

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public boolean f22262b0;

    @Nullable
    private ColorStateList backgroundTint;

    @Nullable
    n9.h bottomContainerBackHelper;

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

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public final i f22264c0;

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

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public final int f22266d0;

    @Nullable
    WeakReference<View> dragHandleViewRef;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f22267e;

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    public int f22268e0;

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

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    public int f22270f0;

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

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

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

    /* JADX INFO: renamed from: h0, reason: collision with root package name */
    public int f22274h0;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final com.google.android.material.shape.k f22275i;

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

    @Nullable
    private Map<View, Integer> importantForAccessibilityMap;

    @Nullable
    private ValueAnimator interpolatorAnimator;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final int f22277j;

    /* JADX INFO: renamed from: j0, reason: collision with root package name */
    public boolean f22278j0;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final int f22279k;

    /* JADX INFO: renamed from: k0, reason: collision with root package name */
    public boolean f22280k0;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public int f22281l;

    /* JADX INFO: renamed from: l0, reason: collision with root package name */
    public final boolean f22282l0;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final boolean f22283m;

    /* JADX INFO: renamed from: m0, reason: collision with root package name */
    public final boolean f22284m0;

    /* JADX INFO: renamed from: n0, reason: collision with root package name */
    public boolean f22285n0;

    @Nullable
    WeakReference<View> nestedScrollingChildRef;

    /* JADX INFO: renamed from: o0, reason: collision with root package name */
    public int f22286o0;

    /* JADX INFO: renamed from: p0, reason: collision with root package name */
    public boolean f22287p0;

    /* JADX INFO: renamed from: q0, reason: collision with root package name */
    public int f22288q0;

    /* JADX INFO: renamed from: r0, reason: collision with root package name */
    public boolean f22289r0;

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

    /* JADX INFO: renamed from: t0, reason: collision with root package name */
    public int f22291t0;

    /* JADX INFO: renamed from: u0, reason: collision with root package name */
    public int f22292u0;

    /* JADX INFO: renamed from: v0, reason: collision with root package name */
    public int f22293v0;

    @Nullable
    private VelocityTracker velocityTracker;

    @Nullable
    y0.h viewDragHelper;

    @Nullable
    WeakReference<V> viewRef;

    /* JADX INFO: renamed from: w0, reason: collision with root package name */
    public final ArrayList f22294w0;

    /* JADX INFO: renamed from: x0, reason: collision with root package name */
    public int f22295x0;

    /* JADX INFO: renamed from: y0, reason: collision with root package name */
    public int f22296y0;
    public boolean z0;

    @Retention(RetentionPolicy.SOURCE)
    @RestrictTo({RestrictTo.Scope.f556b})
    public @interface SaveFlags {
    }

    @Retention(RetentionPolicy.SOURCE)
    @RestrictTo({RestrictTo.Scope.f556b})
    public @interface StableState {
    }

    @Retention(RetentionPolicy.SOURCE)
    @RestrictTo({RestrictTo.Scope.f556b})
    public @interface State {
    }

    public BottomSheetBehavior() {
        this.f22259a = 0;
        this.f22261b = true;
        this.f22277j = -1;
        this.f22279k = -1;
        this.f22264c0 = new i(this);
        this.f22272g0 = 0.5f;
        this.f22276i0 = -1.0f;
        this.f22282l0 = true;
        this.f22284m0 = true;
        this.f22286o0 = 4;
        this.f22290s0 = 0.1f;
        this.f22294w0 = new ArrayList();
        this.f22296y0 = -1;
        this.A0 = new SparseIntArray();
        this.B0 = new c(this);
    }

    public static BottomSheetBehavior B(FrameLayout frameLayout) {
        ViewGroup.LayoutParams layoutParams = frameLayout.getLayoutParams();
        if (!(layoutParams instanceof d0.d)) {
            throw new IllegalArgumentException("The view is not a child of CoordinatorLayout");
        }
        d0.b bVar = ((d0.d) layoutParams).f24884a;
        if (bVar instanceof BottomSheetBehavior) {
            return (BottomSheetBehavior) bVar;
        }
        throw new IllegalArgumentException("The view is not associated with BottomSheetBehavior");
    }

    public static int C(int i10, int i11, int i12, int i13) {
        int childMeasureSpec = ViewGroup.getChildMeasureSpec(i10, i11, i13);
        if (i12 == -1) {
            return childMeasureSpec;
        }
        int mode = View.MeasureSpec.getMode(childMeasureSpec);
        int size = View.MeasureSpec.getSize(childMeasureSpec);
        if (mode == 1073741824) {
            return View.MeasureSpec.makeMeasureSpec(Math.min(size, i12), 1073741824);
        }
        if (size != 0) {
            i12 = Math.min(size, i12);
        }
        return View.MeasureSpec.makeMeasureSpec(i12, Integer.MIN_VALUE);
    }

    @RequiresApi(31)
    private float calculateCornerInterpolation(float f10, @Nullable RoundedCorner roundedCorner) {
        if (roundedCorner != null) {
            float radius = roundedCorner.getRadius();
            if (radius > 0.0f && f10 > 0.0f) {
                return radius / f10;
            }
        }
        return 0.0f;
    }

    public final void A(int i10) {
        V v10 = this.viewRef.get();
        if (v10 != null) {
            ArrayList arrayList = this.f22294w0;
            if (arrayList.isEmpty()) {
                return;
            }
            int i11 = this.f22274h0;
            if (i10 <= i11 && i11 != D()) {
                D();
            }
            for (int i12 = 0; i12 < arrayList.size(); i12++) {
                ((e) arrayList.get(i12)).b(v10);
            }
        }
    }

    public final int D() {
        if (this.f22261b) {
            return this.f22268e0;
        }
        return Math.max(this.f22266d0, this.T ? 0 : this.Y);
    }

    public final int E(int i10) {
        if (i10 == 3) {
            return D();
        }
        if (i10 == 4) {
            return this.f22274h0;
        }
        if (i10 == 5) {
            return this.f22293v0;
        }
        if (i10 == 6) {
            return this.f22270f0;
        }
        throw new IllegalArgumentException(u1.g("Invalid state to get top offset: ", i10));
    }

    public final boolean F() {
        WeakReference<V> weakReference = this.viewRef;
        if (weakReference == null || weakReference.get() == null) {
            return false;
        }
        int[] iArr = new int[2];
        this.viewRef.get().getLocationOnScreen(iArr);
        return iArr[1] == 0;
    }

    public final void G() {
        this.f22295x0 = -1;
        this.f22296y0 = -1;
        VelocityTracker velocityTracker = this.velocityTracker;
        if (velocityTracker != null) {
            velocityTracker.recycle();
            this.velocityTracker = null;
        }
    }

    public final void H(boolean z10) {
        if (this.f22278j0 != z10) {
            this.f22278j0 = z10;
            if (!z10 && this.f22286o0 == 5) {
                J(4);
            }
            O();
        }
    }

    public final void I(int i10) {
        if (i10 == -1) {
            if (this.f22269f) {
                return;
            } else {
                this.f22269f = true;
            }
        } else {
            if (!this.f22269f && this.f22267e == i10) {
                return;
            }
            this.f22269f = false;
            this.f22267e = Math.max(0, i10);
        }
        R();
    }

    public final void J(int i10) {
        if (i10 == 1 || i10 == 2) {
            throw new IllegalArgumentException(defpackage.e.o(new StringBuilder("STATE_"), i10 == 1 ? "DRAGGING" : "SETTLING", " should not be set externally."));
        }
        if (this.f22278j0 || i10 != 5) {
            int i11 = (i10 == 6 && this.f22261b && E(i10) <= this.f22268e0) ? 3 : i10;
            WeakReference<V> weakReference = this.viewRef;
            if (weakReference == null || weakReference.get() == null) {
                K(i10);
                return;
            }
            V v10 = this.viewRef.get();
            androidx.browser.customtabs.f fVar = new androidx.browser.customtabs.f(this, v10, i11, 4);
            ViewParent parent = v10.getParent();
            if (parent != null && parent.isLayoutRequested() && v10.isAttachedToWindow()) {
                v10.post(fVar);
            } else {
                fVar.run();
            }
        }
    }

    public final void K(int i10) {
        V v10;
        if (this.f22286o0 == i10) {
            return;
        }
        this.f22286o0 = i10;
        if (i10 != 4 && i10 != 3 && i10 != 6) {
            boolean z10 = this.f22278j0;
        }
        WeakReference<V> weakReference = this.viewRef;
        if (weakReference == null || (v10 = weakReference.get()) == null) {
            return;
        }
        int i11 = 0;
        if (i10 == 3) {
            Q(true);
        } else if (i10 == 6 || i10 == 5 || i10 == 4) {
            Q(false);
        }
        P(i10, true);
        while (true) {
            ArrayList arrayList = this.f22294w0;
            if (i11 >= arrayList.size()) {
                O();
                return;
            } else {
                ((e) arrayList.get(i11)).c(i10, v10);
                i11++;
            }
        }
    }

    public final boolean L(float f10, View view) {
        if (this.f22280k0) {
            return true;
        }
        if (view.getTop() < this.f22274h0) {
            return false;
        }
        return Math.abs(((f10 * this.f22290s0) + ((float) view.getTop())) - ((float) this.f22274h0)) / ((float) y()) > 0.5f;
    }

    public final void M(View view, int i10, boolean z10) {
        int iE = E(i10);
        y0.h hVar = this.viewDragHelper;
        if (hVar == null || (!z10 ? hVar.s(view, view.getLeft(), iE) : hVar.q(view.getLeft(), iE))) {
            K(i10);
            return;
        }
        K(2);
        P(i10, true);
        this.f22264c0.a(i10);
    }

    public final void N(int i10, View view) {
        int iA;
        if (view == null) {
            return;
        }
        z(i10, view);
        if (!this.f22261b && this.f22286o0 != 6) {
            String string = view.getResources().getString(x8.k.bottomsheet_action_expand_halfway);
            d dVar = new d(this, 6);
            ArrayList arrayListC = s1.c(view);
            int i11 = 0;
            while (true) {
                if (i11 >= arrayListC.size()) {
                    int i12 = -1;
                    for (int i13 = 0; i13 < 32 && i12 == -1; i13++) {
                        int i14 = s1.f1818d[i13];
                        boolean z10 = true;
                        for (int i15 = 0; i15 < arrayListC.size(); i15++) {
                            z10 &= ((q0.c) arrayListC.get(i15)).a() != i14;
                        }
                        if (z10) {
                            i12 = i14;
                        }
                    }
                    iA = i12;
                } else {
                    if (TextUtils.equals(string, ((AccessibilityNodeInfo.AccessibilityAction) ((q0.c) arrayListC.get(i11)).f32070a).getLabel())) {
                        iA = ((q0.c) arrayListC.get(i11)).a();
                        break;
                    }
                    i11++;
                }
            }
            if (iA != -1) {
                q0.c cVar = new q0.c(null, iA, string, dVar, null);
                androidx.core.view.b accessibilityDelegate = s1.getAccessibilityDelegate(view);
                if (accessibilityDelegate == null) {
                    accessibilityDelegate = new androidx.core.view.b();
                }
                s1.setAccessibilityDelegate(view, accessibilityDelegate);
                s1.g(cVar.a(), view);
                s1.c(view).add(cVar);
                s1.e(0, view);
            }
            this.A0.put(i10, iA);
        }
        if (this.f22278j0 && this.f22286o0 != 5) {
            s1.replaceAccessibilityAction(view, q0.c.f32066l, null, new d(this, 5));
        }
        int i16 = this.f22286o0;
        if (i16 == 3) {
            s1.replaceAccessibilityAction(view, q0.c.f32065k, null, new d(this, this.f22261b ? 4 : 6));
            return;
        }
        if (i16 == 4) {
            s1.replaceAccessibilityAction(view, q0.c.f32064j, null, new d(this, this.f22261b ? 3 : 6));
        } else {
            if (i16 != 6) {
                return;
            }
            s1.replaceAccessibilityAction(view, q0.c.f32065k, null, new d(this, 4));
            s1.replaceAccessibilityAction(view, q0.c.f32064j, null, new d(this, 3));
        }
    }

    public final void O() {
        WeakReference<V> weakReference = this.viewRef;
        if (weakReference != null) {
            N(0, weakReference.get());
        }
        WeakReference<View> weakReference2 = this.accessibilityDelegateViewRef;
        if (weakReference2 != null) {
            N(1, weakReference2.get());
        }
    }

    public final void P(int i10, boolean z10) {
        ValueAnimator valueAnimator;
        if (i10 == 2) {
            return;
        }
        boolean z11 = this.f22286o0 == 3 && (this.Z || F());
        if (this.f22262b0 == z11 || this.f22275i == null) {
            return;
        }
        this.f22262b0 = z11;
        if (!z10 || (valueAnimator = this.interpolatorAnimator) == null) {
            ValueAnimator valueAnimator2 = this.interpolatorAnimator;
            if (valueAnimator2 != null && valueAnimator2.isRunning()) {
                this.interpolatorAnimator.cancel();
            }
            this.f22275i.x(this.f22262b0 ? x() : 1.0f);
            return;
        }
        if (valueAnimator.isRunning()) {
            this.interpolatorAnimator.reverse();
        } else {
            this.interpolatorAnimator.setFloatValues(this.f22275i.f23095b.f23070c, z11 ? x() : 1.0f);
            this.interpolatorAnimator.start();
        }
    }

    public final void Q(boolean z10) {
        WeakReference<V> weakReference = this.viewRef;
        if (weakReference == null) {
            return;
        }
        ViewParent parent = weakReference.get().getParent();
        if (parent instanceof CoordinatorLayout) {
            CoordinatorLayout coordinatorLayout = (CoordinatorLayout) parent;
            int childCount = coordinatorLayout.getChildCount();
            if (z10) {
                if (this.importantForAccessibilityMap != null) {
                    return;
                } else {
                    this.importantForAccessibilityMap = new HashMap(childCount);
                }
            }
            for (int i10 = 0; i10 < childCount; i10++) {
                View childAt = coordinatorLayout.getChildAt(i10);
                if (childAt != this.viewRef.get() && z10) {
                    this.importantForAccessibilityMap.put(childAt, Integer.valueOf(childAt.getImportantForAccessibility()));
                }
            }
            if (z10) {
                return;
            }
            this.importantForAccessibilityMap = null;
        }
    }

    public final void R() {
        V v10;
        if (this.viewRef != null) {
            w();
            if (this.f22286o0 != 4 || (v10 = this.viewRef.get()) == null) {
                return;
            }
            v10.requestLayout();
        }
    }

    @Override // n9.b
    public final void a(androidx.activity.b bVar) {
        n9.h hVar = this.bottomContainerBackHelper;
        if (hVar == null) {
            return;
        }
        hVar.a(bVar);
    }

    @Override // n9.b
    public final void b(androidx.activity.b bVar) {
        n9.h hVar = this.bottomContainerBackHelper;
        if (hVar == null) {
            return;
        }
        hVar.e(bVar);
    }

    @Override // n9.b
    public final void c() {
        n9.h hVar = this.bottomContainerBackHelper;
        if (hVar == null) {
            return;
        }
        androidx.activity.b bVarOnHandleBackInvoked = hVar.onHandleBackInvoked();
        if (bVarOnHandleBackInvoked == null || Build.VERSION.SDK_INT < 34) {
            J(this.f22278j0 ? 5 : 4);
        } else if (this.f22278j0) {
            this.bottomContainerBackHelper.finishBackProgressNotPersistent(bVarOnHandleBackInvoked, new a(this));
        } else {
            this.bottomContainerBackHelper.finishBackProgressPersistent(bVarOnHandleBackInvoked, null);
            J(4);
        }
    }

    @Override // n9.b
    public final void d() {
        n9.h hVar = this.bottomContainerBackHelper;
        if (hVar == null) {
            return;
        }
        hVar.b();
    }

    @Nullable
    @VisibleForTesting
    public View findScrollingChild(View view) {
        if (view.getVisibility() != 0) {
            return null;
        }
        if (view.isNestedScrollingEnabled()) {
            return view;
        }
        if (view instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) view;
            int childCount = viewGroup.getChildCount();
            for (int i10 = 0; i10 < childCount; i10++) {
                View viewFindScrollingChild = findScrollingChild(viewGroup.getChildAt(i10));
                if (viewFindScrollingChild != null) {
                    return viewFindScrollingChild;
                }
            }
        }
        return null;
    }

    @Override // d0.b
    public final void g(d0.d dVar) {
        this.viewRef = null;
        this.viewDragHelper = null;
        this.bottomContainerBackHelper = null;
    }

    @Nullable
    @VisibleForTesting
    public n9.h getBackHelper() {
        return this.bottomContainerBackHelper;
    }

    @Override // d0.b
    public final void j() {
        this.viewRef = null;
        this.viewDragHelper = null;
        this.bottomContainerBackHelper = null;
    }

    @Override // d0.b
    public final boolean k(CoordinatorLayout coordinatorLayout, View view, MotionEvent motionEvent) {
        int i10;
        y0.h hVar;
        if (!view.isShown() || !this.f22282l0) {
            this.f22287p0 = true;
            return false;
        }
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 0) {
            G();
        }
        if (this.velocityTracker == null) {
            this.velocityTracker = VelocityTracker.obtain();
        }
        this.velocityTracker.addMovement(motionEvent);
        if (actionMasked == 0) {
            int x10 = (int) motionEvent.getX();
            int y10 = (int) motionEvent.getY();
            this.f22296y0 = y10;
            if (this.f22286o0 != 2) {
                WeakReference<View> weakReference = this.nestedScrollingChildRef;
                View view2 = weakReference != null ? weakReference.get() : null;
                if (view2 != null && coordinatorLayout.m(view2, x10, y10)) {
                    this.f22295x0 = motionEvent.getPointerId(motionEvent.getActionIndex());
                    int i11 = this.f22296y0;
                    WeakReference<View> weakReference2 = this.dragHandleViewRef;
                    View view3 = weakReference2 != null ? weakReference2.get() : null;
                    if (view3 == null || !coordinatorLayout.m(view3, x10, i11)) {
                        this.z0 = true;
                    }
                }
            }
            this.f22287p0 = this.f22295x0 == -1 && !coordinatorLayout.m(view, x10, this.f22296y0);
        } else if (actionMasked == 1 || actionMasked == 3) {
            this.z0 = false;
            this.f22295x0 = -1;
            if (this.f22287p0) {
                this.f22287p0 = false;
                return false;
            }
        }
        if (!this.f22287p0 && (hVar = this.viewDragHelper) != null && hVar.r(motionEvent)) {
            return true;
        }
        WeakReference<View> weakReference3 = this.nestedScrollingChildRef;
        View view4 = weakReference3 != null ? weakReference3.get() : null;
        return (actionMasked != 2 || view4 == null || this.f22287p0 || this.f22286o0 == 1 || coordinatorLayout.m(view4, (int) motionEvent.getX(), (int) motionEvent.getY()) || this.viewDragHelper == null || (i10 = this.f22296y0) == -1 || Math.abs(((float) i10) - motionEvent.getY()) <= ((float) this.viewDragHelper.f36679b)) ? false : true;
    }

    @Override // d0.b
    public final boolean l(CoordinatorLayout coordinatorLayout, View view, int i10) {
        if (coordinatorLayout.getFitsSystemWindows() && !view.getFitsSystemWindows()) {
            view.setFitsSystemWindows(true);
        }
        int i11 = 0;
        if (this.viewRef == null) {
            this.f22271g = coordinatorLayout.getResources().getDimensionPixelSize(x8.e.design_bottom_sheet_peek_height_min);
            boolean z10 = (Build.VERSION.SDK_INT < 29 || this.f22283m || this.f22269f) ? false : true;
            if (this.Q || this.R || this.S || this.U || this.V || this.W || z10) {
                w0.c(view, new t0(this, z10));
            }
            s1.setWindowInsetsAnimationCallback(view, new q(view));
            this.viewRef = new WeakReference<>(view);
            this.bottomContainerBackHelper = new n9.h(view);
            com.google.android.material.shape.k kVar = this.f22275i;
            if (kVar != null) {
                view.setBackground(kVar);
                com.google.android.material.shape.k kVar2 = this.f22275i;
                float elevation = this.f22276i0;
                if (elevation == -1.0f) {
                    elevation = view.getElevation();
                }
                kVar2.w(elevation);
            } else {
                ColorStateList colorStateList = this.backgroundTint;
                if (colorStateList != null) {
                    s1.setBackgroundTintList(view, colorStateList);
                }
            }
            O();
            if (view.getImportantForAccessibility() == 0) {
                view.setImportantForAccessibility(1);
            }
        }
        if (this.viewDragHelper == null) {
            this.viewDragHelper = new y0.h(coordinatorLayout.getContext(), coordinatorLayout, this.B0);
        }
        int top = view.getTop();
        coordinatorLayout.p(i10, view);
        this.f22292u0 = coordinatorLayout.getWidth();
        this.f22293v0 = coordinatorLayout.getHeight();
        int height = view.getHeight();
        this.f22291t0 = height;
        int iMin = this.f22293v0;
        int i12 = iMin - height;
        int i13 = this.Y;
        if (i12 < i13) {
            if (this.T) {
                int i14 = this.f22279k;
                if (i14 != -1) {
                    iMin = Math.min(iMin, i14);
                }
                this.f22291t0 = iMin;
            } else {
                int iMin2 = iMin - i13;
                int i15 = this.f22279k;
                if (i15 != -1) {
                    iMin2 = Math.min(iMin2, i15);
                }
                this.f22291t0 = iMin2;
            }
        }
        this.f22268e0 = Math.max(0, this.f22293v0 - this.f22291t0);
        this.f22270f0 = (int) ((1.0f - this.f22272g0) * this.f22293v0);
        w();
        int i16 = this.f22286o0;
        if (i16 == 3) {
            int iD = D();
            WeakHashMap weakHashMap = s1.f1815a;
            view.offsetTopAndBottom(iD);
        } else if (i16 == 6) {
            int i17 = this.f22270f0;
            WeakHashMap weakHashMap2 = s1.f1815a;
            view.offsetTopAndBottom(i17);
        } else if (this.f22278j0 && i16 == 5) {
            int i18 = this.f22293v0;
            WeakHashMap weakHashMap3 = s1.f1815a;
            view.offsetTopAndBottom(i18);
        } else if (i16 == 4) {
            int i19 = this.f22274h0;
            WeakHashMap weakHashMap4 = s1.f1815a;
            view.offsetTopAndBottom(i19);
        } else if (i16 == 1 || i16 == 2) {
            int top2 = top - view.getTop();
            WeakHashMap weakHashMap5 = s1.f1815a;
            view.offsetTopAndBottom(top2);
        }
        P(this.f22286o0, false);
        this.nestedScrollingChildRef = new WeakReference<>(findScrollingChild(view));
        while (true) {
            ArrayList arrayList = this.f22294w0;
            if (i11 >= arrayList.size()) {
                return true;
            }
            ((e) arrayList.get(i11)).a(view);
            i11++;
        }
    }

    @Override // d0.b
    public final boolean m(CoordinatorLayout coordinatorLayout, View view, int i10, int i11, int i12) {
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        view.measure(C(i10, coordinatorLayout.getPaddingRight() + coordinatorLayout.getPaddingLeft() + marginLayoutParams.leftMargin + marginLayoutParams.rightMargin + i11, this.f22277j, marginLayoutParams.width), C(i12, coordinatorLayout.getPaddingBottom() + coordinatorLayout.getPaddingTop() + marginLayoutParams.topMargin + marginLayoutParams.bottomMargin, this.f22279k, marginLayoutParams.height));
        return true;
    }

    @Override // d0.b
    public final boolean n(View view) {
        WeakReference<View> weakReference = this.nestedScrollingChildRef;
        return (weakReference == null || view != weakReference.get() || this.f22286o0 == 3 || this.f22285n0) ? false : true;
    }

    @Override // d0.b
    public final void o(CoordinatorLayout coordinatorLayout, View view, View view2, int i10, int i11, int[] iArr, int i12) {
        if (i12 == 1) {
            return;
        }
        WeakReference<View> weakReference = this.nestedScrollingChildRef;
        View view3 = weakReference != null ? weakReference.get() : null;
        if (view2 != view3) {
            return;
        }
        int top = view.getTop();
        int i13 = top - i11;
        if (i11 > 0) {
            if (!this.f22289r0 && !this.f22284m0 && view2 == view3 && view2.canScrollVertically(1)) {
                this.f22285n0 = true;
                return;
            }
            if (i13 < D()) {
                int iD = top - D();
                iArr[1] = iD;
                WeakHashMap weakHashMap = s1.f1815a;
                view.offsetTopAndBottom(-iD);
                K(3);
            } else {
                if (!this.f22282l0) {
                    return;
                }
                iArr[1] = i11;
                WeakHashMap weakHashMap2 = s1.f1815a;
                view.offsetTopAndBottom(-i11);
                K(1);
            }
        } else if (i11 < 0) {
            boolean zCanScrollVertically = view2.canScrollVertically(-1);
            if (!this.f22289r0 && !this.f22284m0 && view2 == view3 && zCanScrollVertically) {
                this.f22285n0 = true;
                return;
            }
            if (!zCanScrollVertically) {
                int i14 = this.f22274h0;
                if (i13 > i14 && !this.f22278j0) {
                    int i15 = top - i14;
                    iArr[1] = i15;
                    WeakHashMap weakHashMap3 = s1.f1815a;
                    view.offsetTopAndBottom(-i15);
                    K(4);
                } else {
                    if (!this.f22282l0) {
                        return;
                    }
                    iArr[1] = i11;
                    WeakHashMap weakHashMap4 = s1.f1815a;
                    view.offsetTopAndBottom(-i11);
                    K(1);
                }
            }
        }
        A(view.getTop());
        this.f22288q0 = i11;
        this.f22289r0 = true;
        this.f22285n0 = false;
    }

    @Override // d0.b
    public final void p(CoordinatorLayout coordinatorLayout, View view, int i10, int i11, int i12, int[] iArr) {
    }

    @Override // d0.b
    public final void r(View view, Parcelable parcelable) {
        g gVar = (g) parcelable;
        gVar.getSuperState();
        int i10 = this.f22259a;
        if (i10 != 0) {
            if (i10 == -1 || (i10 & 1) == 1) {
                this.f22267e = gVar.f22311d;
            }
            if (i10 == -1 || (i10 & 2) == 2) {
                this.f22261b = gVar.f22312e;
            }
            if (i10 == -1 || (i10 & 4) == 4) {
                this.f22278j0 = gVar.f22313f;
            }
            if (i10 == -1 || (i10 & 8) == 8) {
                this.f22280k0 = gVar.f22314g;
            }
        }
        int i11 = gVar.f22310c;
        if (i11 == 1 || i11 == 2) {
            this.f22286o0 = 4;
        } else {
            this.f22286o0 = i11;
        }
    }

    @Override // d0.b
    public final Parcelable s(View view) {
        return new g(View.BaseSavedState.EMPTY_STATE, this);
    }

    public void setAccessibilityDelegateView(@Nullable View view) {
        WeakReference<View> weakReference;
        if (view != null || (weakReference = this.accessibilityDelegateViewRef) == null) {
            this.accessibilityDelegateViewRef = new WeakReference<>(view);
            N(1, view);
        } else {
            z(1, weakReference.get());
            this.accessibilityDelegateViewRef = null;
        }
    }

    public void setDragHandleView(@Nullable BottomSheetDragHandleView bottomSheetDragHandleView) {
        this.dragHandleViewRef = bottomSheetDragHandleView != null ? new WeakReference<>(bottomSheetDragHandleView) : null;
    }

    @Override // d0.b
    public final boolean t(CoordinatorLayout coordinatorLayout, View view, View view2, View view3, int i10, int i11) {
        this.f22288q0 = 0;
        this.f22289r0 = false;
        return (i10 & 2) != 0;
    }

    /* JADX WARN: Removed duplicated region for block: B:30:0x0055  */
    /* JADX WARN: Removed duplicated region for block: B:47:0x0097  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x00ae  */
    @Override // d0.b
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void u(CoordinatorLayout coordinatorLayout, View view, View view2, int i10) {
        float yVelocity;
        int i11 = 3;
        if (view.getTop() == D()) {
            K(3);
            return;
        }
        WeakReference<View> weakReference = this.nestedScrollingChildRef;
        if (weakReference != null && view2 == weakReference.get() && this.f22289r0) {
            if (this.f22288q0 > 0) {
                if (!this.f22261b && view.getTop() > this.f22270f0) {
                    i11 = 6;
                }
            } else if (this.f22278j0) {
                VelocityTracker velocityTracker = this.velocityTracker;
                if (velocityTracker == null) {
                    yVelocity = 0.0f;
                } else {
                    velocityTracker.computeCurrentVelocity(1000, this.f22263c);
                    yVelocity = this.velocityTracker.getYVelocity(this.f22295x0);
                }
                if (L(yVelocity, view)) {
                    i11 = 5;
                }
            } else if (this.f22288q0 == 0) {
                int top = view.getTop();
                if (!this.f22261b) {
                    int i12 = this.f22270f0;
                    if (top < i12) {
                        if (top >= Math.abs(top - this.f22274h0)) {
                        }
                    } else if (Math.abs(top - i12) < Math.abs(top - this.f22274h0)) {
                    }
                    i11 = 6;
                } else if (Math.abs(top - this.f22268e0) >= Math.abs(top - this.f22274h0)) {
                    i11 = 4;
                }
            } else {
                if (!this.f22261b) {
                    int top2 = view.getTop();
                    if (Math.abs(top2 - this.f22270f0) < Math.abs(top2 - this.f22274h0)) {
                    }
                }
                i11 = 4;
            }
            M(view, i11, false);
            this.f22289r0 = false;
        }
    }

    @Override // d0.b
    public final boolean v(CoordinatorLayout coordinatorLayout, View view, MotionEvent motionEvent) {
        if (!view.isShown()) {
            return false;
        }
        int actionMasked = motionEvent.getActionMasked();
        int i10 = this.f22286o0;
        if (i10 == 1 && actionMasked == 0) {
            return true;
        }
        y0.h hVar = this.viewDragHelper;
        if (hVar != null && (this.f22282l0 || i10 == 1)) {
            hVar.k(motionEvent);
        }
        if (actionMasked == 0) {
            G();
        }
        if (this.velocityTracker == null) {
            this.velocityTracker = VelocityTracker.obtain();
        }
        this.velocityTracker.addMovement(motionEvent);
        if (this.viewDragHelper != null && ((this.f22282l0 || this.f22286o0 == 1) && actionMasked == 2 && !this.f22287p0)) {
            float fAbs = Math.abs(this.f22296y0 - motionEvent.getY());
            y0.h hVar2 = this.viewDragHelper;
            if (fAbs > hVar2.f36679b) {
                hVar2.c(motionEvent.getPointerId(motionEvent.getActionIndex()), view);
            }
        }
        return !this.f22287p0;
    }

    public final void w() {
        int iY = y();
        if (this.f22261b) {
            this.f22274h0 = Math.max(this.f22293v0 - iY, this.f22268e0);
        } else {
            this.f22274h0 = this.f22293v0 - iY;
        }
    }

    public final float x() {
        WeakReference<V> weakReference;
        WindowInsets rootWindowInsets;
        if (this.f22275i == null || (weakReference = this.viewRef) == null || weakReference.get() == null || Build.VERSION.SDK_INT < 31) {
            return 0.0f;
        }
        V v10 = this.viewRef.get();
        if (!F() || (rootWindowInsets = v10.getRootWindowInsets()) == null) {
            return 0.0f;
        }
        return Math.max(calculateCornerInterpolation(this.f22275i.p(), rootWindowInsets.getRoundedCorner(0)), calculateCornerInterpolation(this.f22275i.q(), rootWindowInsets.getRoundedCorner(1)));
    }

    public final int y() {
        int i10;
        return this.f22269f ? Math.min(Math.max(this.f22271g, this.f22293v0 - ((this.f22292u0 * 9) / 16)), this.f22291t0) + this.X : (this.f22283m || this.Q || (i10 = this.f22281l) <= 0) ? this.f22267e + this.X : Math.max(this.f22267e, i10 + this.f22273h);
    }

    public final void z(int i10, View view) {
        if (view == null) {
            return;
        }
        s1.g(524288, view);
        s1.e(0, view);
        s1.g(262144, view);
        s1.e(0, view);
        s1.g(ProgressiveMediaSource.DEFAULT_LOADING_CHECK_INTERVAL_BYTES, view);
        s1.e(0, view);
        SparseIntArray sparseIntArray = this.A0;
        int i11 = sparseIntArray.get(i10, -1);
        if (i11 != -1) {
            s1.g(i11, view);
            s1.e(0, view);
            sparseIntArray.delete(i10);
        }
    }

    public BottomSheetBehavior(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        int i10;
        this.f22259a = 0;
        this.f22261b = true;
        this.f22277j = -1;
        this.f22279k = -1;
        this.f22264c0 = new i(this);
        this.f22272g0 = 0.5f;
        this.f22276i0 = -1.0f;
        this.f22282l0 = true;
        this.f22284m0 = true;
        this.f22286o0 = 4;
        this.f22290s0 = 0.1f;
        this.f22294w0 = new ArrayList();
        this.f22296y0 = -1;
        this.A0 = new SparseIntArray();
        this.B0 = new c(this);
        this.f22273h = context.getResources().getDimensionPixelSize(x8.e.mtrl_min_touch_target_size);
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, x8.m.BottomSheetBehavior_Layout);
        int i11 = x8.m.BottomSheetBehavior_Layout_backgroundTint;
        if (typedArrayObtainStyledAttributes.hasValue(i11)) {
            this.backgroundTint = q9.d.getColorStateList(context, typedArrayObtainStyledAttributes, i11);
        }
        if (typedArrayObtainStyledAttributes.hasValue(x8.m.BottomSheetBehavior_Layout_shapeAppearance)) {
            this.f22260a0 = s.c(context, attributeSet, x8.c.bottomSheetStyle, C0).a();
        }
        s sVar = this.f22260a0;
        if (sVar != null) {
            com.google.android.material.shape.k kVar = new com.google.android.material.shape.k(sVar);
            this.f22275i = kVar;
            kVar.s(context);
            ColorStateList colorStateList = this.backgroundTint;
            if (colorStateList != null) {
                this.f22275i.setFillColor(colorStateList);
            } else {
                TypedValue typedValue = new TypedValue();
                context.getTheme().resolveAttribute(R.attr.colorBackground, typedValue, true);
                this.f22275i.setTint(typedValue.data);
            }
        }
        ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(x(), 1.0f);
        this.interpolatorAnimator = valueAnimatorOfFloat;
        valueAnimatorOfFloat.setDuration(500L);
        this.interpolatorAnimator.addUpdateListener(new b(this));
        this.f22276i0 = typedArrayObtainStyledAttributes.getDimension(x8.m.BottomSheetBehavior_Layout_android_elevation, -1.0f);
        int i12 = x8.m.BottomSheetBehavior_Layout_android_maxWidth;
        if (typedArrayObtainStyledAttributes.hasValue(i12)) {
            this.f22277j = typedArrayObtainStyledAttributes.getDimensionPixelSize(i12, -1);
        }
        int i13 = x8.m.BottomSheetBehavior_Layout_android_maxHeight;
        if (typedArrayObtainStyledAttributes.hasValue(i13)) {
            this.f22279k = typedArrayObtainStyledAttributes.getDimensionPixelSize(i13, -1);
        }
        int i14 = x8.m.BottomSheetBehavior_Layout_behavior_peekHeight;
        TypedValue typedValuePeekValue = typedArrayObtainStyledAttributes.peekValue(i14);
        if (typedValuePeekValue != null && (i10 = typedValuePeekValue.data) == -1) {
            I(i10);
        } else {
            I(typedArrayObtainStyledAttributes.getDimensionPixelSize(i14, -1));
        }
        H(typedArrayObtainStyledAttributes.getBoolean(x8.m.BottomSheetBehavior_Layout_behavior_hideable, false));
        this.f22283m = typedArrayObtainStyledAttributes.getBoolean(x8.m.BottomSheetBehavior_Layout_gestureInsetBottomIgnored, false);
        boolean z10 = typedArrayObtainStyledAttributes.getBoolean(x8.m.BottomSheetBehavior_Layout_behavior_fitToContents, true);
        if (this.f22261b != z10) {
            this.f22261b = z10;
            if (this.viewRef != null) {
                w();
            }
            K((this.f22261b && this.f22286o0 == 6) ? 3 : this.f22286o0);
            P(this.f22286o0, true);
            O();
        }
        this.f22280k0 = typedArrayObtainStyledAttributes.getBoolean(x8.m.BottomSheetBehavior_Layout_behavior_skipCollapsed, false);
        this.f22282l0 = typedArrayObtainStyledAttributes.getBoolean(x8.m.BottomSheetBehavior_Layout_behavior_draggable, true);
        this.f22284m0 = typedArrayObtainStyledAttributes.getBoolean(x8.m.BottomSheetBehavior_Layout_behavior_draggableOnNestedScroll, true);
        this.f22259a = typedArrayObtainStyledAttributes.getInt(x8.m.BottomSheetBehavior_Layout_behavior_saveFlags, 0);
        float f10 = typedArrayObtainStyledAttributes.getFloat(x8.m.BottomSheetBehavior_Layout_behavior_halfExpandedRatio, 0.5f);
        if (f10 > 0.0f && f10 < 1.0f) {
            this.f22272g0 = f10;
            if (this.viewRef != null) {
                this.f22270f0 = (int) ((1.0f - f10) * this.f22293v0);
            }
            int i15 = x8.m.BottomSheetBehavior_Layout_behavior_expandedOffset;
            TypedValue typedValuePeekValue2 = typedArrayObtainStyledAttributes.peekValue(i15);
            if (typedValuePeekValue2 != null && typedValuePeekValue2.type == 16) {
                int i16 = typedValuePeekValue2.data;
                if (i16 >= 0) {
                    this.f22266d0 = i16;
                    P(this.f22286o0, true);
                } else {
                    throw new IllegalArgumentException("offset must be greater than or equal to 0");
                }
            } else {
                int dimensionPixelOffset = typedArrayObtainStyledAttributes.getDimensionPixelOffset(i15, 0);
                if (dimensionPixelOffset >= 0) {
                    this.f22266d0 = dimensionPixelOffset;
                    P(this.f22286o0, true);
                } else {
                    throw new IllegalArgumentException("offset must be greater than or equal to 0");
                }
            }
            this.f22265d = typedArrayObtainStyledAttributes.getInt(x8.m.BottomSheetBehavior_Layout_behavior_significantVelocityThreshold, IjkEventListener.BUFFERING_START);
            this.Q = typedArrayObtainStyledAttributes.getBoolean(x8.m.BottomSheetBehavior_Layout_paddingBottomSystemWindowInsets, false);
            this.R = typedArrayObtainStyledAttributes.getBoolean(x8.m.BottomSheetBehavior_Layout_paddingLeftSystemWindowInsets, false);
            this.S = typedArrayObtainStyledAttributes.getBoolean(x8.m.BottomSheetBehavior_Layout_paddingRightSystemWindowInsets, false);
            this.T = typedArrayObtainStyledAttributes.getBoolean(x8.m.BottomSheetBehavior_Layout_paddingTopSystemWindowInsets, true);
            this.U = typedArrayObtainStyledAttributes.getBoolean(x8.m.BottomSheetBehavior_Layout_marginLeftSystemWindowInsets, false);
            this.V = typedArrayObtainStyledAttributes.getBoolean(x8.m.BottomSheetBehavior_Layout_marginRightSystemWindowInsets, false);
            this.W = typedArrayObtainStyledAttributes.getBoolean(x8.m.BottomSheetBehavior_Layout_marginTopSystemWindowInsets, false);
            this.Z = typedArrayObtainStyledAttributes.getBoolean(x8.m.BottomSheetBehavior_Layout_shouldRemoveExpandedCorners, true);
            typedArrayObtainStyledAttributes.recycle();
            this.f22263c = ViewConfiguration.get(context).getScaledMaximumFlingVelocity();
            return;
        }
        throw new IllegalArgumentException("ratio must be a float value between 0 and 1");
    }
}
