package com.google.android.material.bottomsheet;

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import c.f.l.t;
import c.h.b.a;
import com.cvte.vman.impl.FwUpgradeManager;
import d.c.a.a.i;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;

/* JADX INFO: loaded from: classes.dex */
public class BottomSheetBehavior<V extends View> extends CoordinatorLayout.c<V> {
    private boolean a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private float f1741b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private int f1742c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private boolean f1743d;

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private int f1745f;

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

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    int f1748i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    boolean f1749j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private boolean f1750k;
    int l;
    c.h.b.a m;
    private boolean n;
    private int o;
    private boolean p;
    int q;
    WeakReference<V> r;
    WeakReference<View> s;
    private b t;
    private VelocityTracker u;
    int v;
    private int w;
    boolean x;
    private Map<View, Integer> y;
    private final a.c z;

    class a extends a.c {
        a() {
        }

        @Override // c.h.b.a.c
        public int a(View view, int i2, int i3) {
            return view.getLeft();
        }

        @Override // c.h.b.a.c
        public int b(View view, int i2, int i3) {
            int I = BottomSheetBehavior.this.I();
            BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.this;
            return c.f.g.a.a(i2, I, bottomSheetBehavior.f1749j ? bottomSheetBehavior.q : bottomSheetBehavior.f1748i);
        }

        @Override // c.h.b.a.c
        public int e(View view) {
            BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.this;
            return bottomSheetBehavior.f1749j ? bottomSheetBehavior.q : bottomSheetBehavior.f1748i;
        }

        @Override // c.h.b.a.c
        public void j(int i2) {
            if (i2 == 1) {
                BottomSheetBehavior.this.P(1);
            }
        }

        @Override // c.h.b.a.c
        public void k(View view, int i2, int i3, int i4, int i5) {
            BottomSheetBehavior.this.G(i3);
        }

        /* JADX WARN: Removed duplicated region for block: B:46:0x00d5  */
        /* JADX WARN: Removed duplicated region for block: B:47:0x00e6  */
        @Override // c.h.b.a.c
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        public void l(android.view.View r8, float r9, float r10) {
            /*
                Method dump skipped, instruction units count: 236
                To view this dump add '--comments-level debug' option
            */
            throw new UnsupportedOperationException("Method not decompiled: com.google.android.material.bottomsheet.BottomSheetBehavior.a.l(android.view.View, float, float):void");
        }

        @Override // c.h.b.a.c
        public boolean m(View view, int i2) {
            View view2;
            BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.this;
            int i3 = bottomSheetBehavior.l;
            if (i3 == 1 || bottomSheetBehavior.x) {
                return false;
            }
            if (i3 == 3 && bottomSheetBehavior.v == i2 && (view2 = bottomSheetBehavior.s.get()) != null && view2.canScrollVertically(-1)) {
                return false;
            }
            WeakReference<V> weakReference = BottomSheetBehavior.this.r;
            return weakReference != null && weakReference.get() == view;
        }
    }

    public static abstract class b {
        public abstract void a(View view, float f2);

        public abstract void b(View view, int i2);
    }

    private class d implements Runnable {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private final View f1752b;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        private final int f1753f;

        d(View view, int i2) {
            this.f1752b = view;
            this.f1753f = i2;
        }

        @Override // java.lang.Runnable
        public void run() {
            c.h.b.a aVar = BottomSheetBehavior.this.m;
            if (aVar == null || !aVar.k(true)) {
                BottomSheetBehavior.this.P(this.f1753f);
            } else {
                t.R(this.f1752b, this);
            }
        }
    }

    public BottomSheetBehavior() {
        this.a = true;
        this.l = 4;
        this.z = new a();
    }

    private void F() {
        if (this.a) {
            this.f1748i = Math.max(this.q - this.f1745f, this.f1746g);
        } else {
            this.f1748i = this.q - this.f1745f;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public int I() {
        if (this.a) {
            return this.f1746g;
        }
        return 0;
    }

    private float J() {
        VelocityTracker velocityTracker = this.u;
        if (velocityTracker == null) {
            return 0.0f;
        }
        velocityTracker.computeCurrentVelocity(FwUpgradeManager.TYPE_FW_CVTE_CAMERA, this.f1741b);
        return this.u.getYVelocity(this.v);
    }

    private void K() {
        this.v = -1;
        VelocityTracker velocityTracker = this.u;
        if (velocityTracker != null) {
            velocityTracker.recycle();
            this.u = null;
        }
    }

    private void R(boolean z) {
        WeakReference<V> weakReference = this.r;
        if (weakReference == null) {
            return;
        }
        ViewParent parent = weakReference.get().getParent();
        if (parent instanceof CoordinatorLayout) {
            CoordinatorLayout coordinatorLayout = (CoordinatorLayout) parent;
            int childCount = coordinatorLayout.getChildCount();
            if (Build.VERSION.SDK_INT >= 16 && z) {
                if (this.y != null) {
                    return;
                } else {
                    this.y = new HashMap(childCount);
                }
            }
            for (int i2 = 0; i2 < childCount; i2++) {
                View childAt = coordinatorLayout.getChildAt(i2);
                if (childAt != this.r.get()) {
                    if (z) {
                        if (Build.VERSION.SDK_INT >= 16) {
                            this.y.put(childAt, Integer.valueOf(childAt.getImportantForAccessibility()));
                        }
                        t.e0(childAt, 4);
                    } else {
                        Map<View, Integer> map = this.y;
                        if (map != null && map.containsKey(childAt)) {
                            t.e0(childAt, this.y.get(childAt).intValue());
                        }
                    }
                }
            }
            if (z) {
                return;
            }
            this.y = null;
        }
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public void B(CoordinatorLayout coordinatorLayout, V v, View view, int i2) {
        int I;
        int i3 = 3;
        if (v.getTop() == I()) {
            P(3);
            return;
        }
        if (view == this.s.get() && this.p) {
            if (this.o > 0) {
                I = I();
            } else if (this.f1749j && Q(v, J())) {
                I = this.q;
                i3 = 5;
            } else {
                if (this.o == 0) {
                    int top = v.getTop();
                    if (!this.a) {
                        int i4 = this.f1747h;
                        if (top < i4) {
                            if (top < Math.abs(top - this.f1748i)) {
                                I = 0;
                            } else {
                                I = this.f1747h;
                            }
                        } else if (Math.abs(top - i4) < Math.abs(top - this.f1748i)) {
                            I = this.f1747h;
                        } else {
                            I = this.f1748i;
                        }
                        i3 = 6;
                    } else if (Math.abs(top - this.f1746g) < Math.abs(top - this.f1748i)) {
                        I = this.f1746g;
                    } else {
                        I = this.f1748i;
                    }
                } else {
                    I = this.f1748i;
                }
                i3 = 4;
            }
            if (this.m.H(v, v.getLeft(), I)) {
                P(2);
                t.R(v, new d(v, i3));
            } else {
                P(i3);
            }
            this.p = false;
        }
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public boolean C(CoordinatorLayout coordinatorLayout, V v, MotionEvent motionEvent) {
        if (!v.isShown()) {
            return false;
        }
        int actionMasked = motionEvent.getActionMasked();
        if (this.l == 1 && actionMasked == 0) {
            return true;
        }
        c.h.b.a aVar = this.m;
        if (aVar != null) {
            aVar.z(motionEvent);
        }
        if (actionMasked == 0) {
            K();
        }
        if (this.u == null) {
            this.u = VelocityTracker.obtain();
        }
        this.u.addMovement(motionEvent);
        if (actionMasked == 2 && !this.n && Math.abs(this.w - motionEvent.getY()) > this.m.u()) {
            this.m.b(v, motionEvent.getPointerId(motionEvent.getActionIndex()));
        }
        return !this.n;
    }

    void G(int i2) {
        b bVar;
        V v = this.r.get();
        if (v == null || (bVar = this.t) == null) {
            return;
        }
        if (i2 > this.f1748i) {
            bVar.a(v, (r2 - i2) / (this.q - r2));
        } else {
            bVar.a(v, (r2 - i2) / (r2 - I()));
        }
    }

    View H(View view) {
        if (t.I(view)) {
            return view;
        }
        if (!(view instanceof ViewGroup)) {
            return null;
        }
        ViewGroup viewGroup = (ViewGroup) view;
        int childCount = viewGroup.getChildCount();
        for (int i2 = 0; i2 < childCount; i2++) {
            View viewH = H(viewGroup.getChildAt(i2));
            if (viewH != null) {
                return viewH;
            }
        }
        return null;
    }

    public void L(boolean z) {
        if (this.a == z) {
            return;
        }
        this.a = z;
        if (this.r != null) {
            F();
        }
        P((this.a && this.l == 6) ? 3 : this.l);
    }

    public void M(boolean z) {
        this.f1749j = z;
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x0015  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void N(int r4) {
        /*
            r3 = this;
            r0 = 1
            r1 = 0
            r2 = -1
            if (r4 != r2) goto Lc
            boolean r4 = r3.f1743d
            if (r4 != 0) goto L15
            r3.f1743d = r0
            goto L24
        Lc:
            boolean r2 = r3.f1743d
            if (r2 != 0) goto L17
            int r2 = r3.f1742c
            if (r2 == r4) goto L15
            goto L17
        L15:
            r0 = r1
            goto L24
        L17:
            r3.f1743d = r1
            int r1 = java.lang.Math.max(r1, r4)
            r3.f1742c = r1
            int r1 = r3.q
            int r1 = r1 - r4
            r3.f1748i = r1
        L24:
            if (r0 == 0) goto L3a
            int r4 = r3.l
            r0 = 4
            if (r4 != r0) goto L3a
            java.lang.ref.WeakReference<V extends android.view.View> r4 = r3.r
            if (r4 == 0) goto L3a
            java.lang.Object r4 = r4.get()
            android.view.View r4 = (android.view.View) r4
            if (r4 == 0) goto L3a
            r4.requestLayout()
        L3a:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.android.material.bottomsheet.BottomSheetBehavior.N(int):void");
    }

    public void O(boolean z) {
        this.f1750k = z;
    }

    void P(int i2) {
        b bVar;
        if (this.l == i2) {
            return;
        }
        this.l = i2;
        if (i2 == 6 || i2 == 3) {
            R(true);
        } else if (i2 == 5 || i2 == 4) {
            R(false);
        }
        V v = this.r.get();
        if (v == null || (bVar = this.t) == null) {
            return;
        }
        bVar.b(v, i2);
    }

    boolean Q(View view, float f2) {
        if (this.f1750k) {
            return true;
        }
        return view.getTop() >= this.f1748i && Math.abs((((float) view.getTop()) + (f2 * 0.1f)) - ((float) this.f1748i)) / ((float) this.f1742c) > 0.5f;
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public boolean k(CoordinatorLayout coordinatorLayout, V v, MotionEvent motionEvent) {
        c.h.b.a aVar;
        if (!v.isShown()) {
            this.n = true;
            return false;
        }
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 0) {
            K();
        }
        if (this.u == null) {
            this.u = VelocityTracker.obtain();
        }
        this.u.addMovement(motionEvent);
        if (actionMasked == 0) {
            int x = (int) motionEvent.getX();
            this.w = (int) motionEvent.getY();
            WeakReference<View> weakReference = this.s;
            View view = weakReference != null ? weakReference.get() : null;
            if (view != null && coordinatorLayout.B(view, x, this.w)) {
                this.v = motionEvent.getPointerId(motionEvent.getActionIndex());
                this.x = true;
            }
            this.n = this.v == -1 && !coordinatorLayout.B(v, x, this.w);
        } else if (actionMasked == 1 || actionMasked == 3) {
            this.x = false;
            this.v = -1;
            if (this.n) {
                this.n = false;
                return false;
            }
        }
        if (!this.n && (aVar = this.m) != null && aVar.G(motionEvent)) {
            return true;
        }
        WeakReference<View> weakReference2 = this.s;
        View view2 = weakReference2 != null ? weakReference2.get() : null;
        return (actionMasked != 2 || view2 == null || this.n || this.l == 1 || coordinatorLayout.B(view2, (int) motionEvent.getX(), (int) motionEvent.getY()) || this.m == null || Math.abs(((float) this.w) - motionEvent.getY()) <= ((float) this.m.u())) ? false : true;
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public boolean l(CoordinatorLayout coordinatorLayout, V v, int i2) {
        if (t.r(coordinatorLayout) && !t.r(v)) {
            v.setFitsSystemWindows(true);
        }
        int top = v.getTop();
        coordinatorLayout.I(v, i2);
        this.q = coordinatorLayout.getHeight();
        if (this.f1743d) {
            if (this.f1744e == 0) {
                this.f1744e = coordinatorLayout.getResources().getDimensionPixelSize(d.c.a.a.c.design_bottom_sheet_peek_height_min);
            }
            this.f1745f = Math.max(this.f1744e, this.q - ((coordinatorLayout.getWidth() * 9) / 16));
        } else {
            this.f1745f = this.f1742c;
        }
        this.f1746g = Math.max(0, this.q - v.getHeight());
        this.f1747h = this.q / 2;
        F();
        int i3 = this.l;
        if (i3 == 3) {
            t.N(v, I());
        } else if (i3 == 6) {
            t.N(v, this.f1747h);
        } else if (this.f1749j && i3 == 5) {
            t.N(v, this.q);
        } else {
            int i4 = this.l;
            if (i4 == 4) {
                t.N(v, this.f1748i);
            } else if (i4 == 1 || i4 == 2) {
                t.N(v, top - v.getTop());
            }
        }
        if (this.m == null) {
            this.m = c.h.b.a.m(coordinatorLayout, this.z);
        }
        this.r = new WeakReference<>(v);
        this.s = new WeakReference<>(H(v));
        return true;
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public boolean o(CoordinatorLayout coordinatorLayout, V v, View view, float f2, float f3) {
        return view == this.s.get() && (this.l != 3 || super.o(coordinatorLayout, v, view, f2, f3));
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public void q(CoordinatorLayout coordinatorLayout, V v, View view, int i2, int i3, int[] iArr, int i4) {
        if (i4 != 1 && view == this.s.get()) {
            int top = v.getTop();
            int i5 = top - i3;
            if (i3 > 0) {
                if (i5 < I()) {
                    iArr[1] = top - I();
                    t.N(v, -iArr[1]);
                    P(3);
                } else {
                    iArr[1] = i3;
                    t.N(v, -i3);
                    P(1);
                }
            } else if (i3 < 0 && !view.canScrollVertically(-1)) {
                int i6 = this.f1748i;
                if (i5 <= i6 || this.f1749j) {
                    iArr[1] = i3;
                    t.N(v, -i3);
                    P(1);
                } else {
                    iArr[1] = top - i6;
                    t.N(v, -iArr[1]);
                    P(4);
                }
            }
            G(v.getTop());
            this.o = i3;
            this.p = true;
        }
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public void w(CoordinatorLayout coordinatorLayout, V v, Parcelable parcelable) {
        c cVar = (c) parcelable;
        super.w(coordinatorLayout, v, cVar.a());
        int i2 = cVar.f1751g;
        if (i2 == 1 || i2 == 2) {
            this.l = 4;
        } else {
            this.l = i2;
        }
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public Parcelable x(CoordinatorLayout coordinatorLayout, V v) {
        return new c(super.x(coordinatorLayout, v), this.l);
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public boolean z(CoordinatorLayout coordinatorLayout, V v, View view, View view2, int i2, int i3) {
        this.o = 0;
        this.p = false;
        return (i2 & 2) != 0;
    }

    protected static class c extends c.h.a.a {
        public static final Parcelable.Creator<c> CREATOR = new a();

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

        static class a implements Parcelable.ClassLoaderCreator<c> {
            a() {
            }

            @Override // android.os.Parcelable.Creator
            /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
            public c createFromParcel(Parcel parcel) {
                return new c(parcel, (ClassLoader) null);
            }

            @Override // android.os.Parcelable.ClassLoaderCreator
            /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
            public c createFromParcel(Parcel parcel, ClassLoader classLoader) {
                return new c(parcel, classLoader);
            }

            @Override // android.os.Parcelable.Creator
            /* JADX INFO: renamed from: c, reason: merged with bridge method [inline-methods] */
            public c[] newArray(int i2) {
                return new c[i2];
            }
        }

        public c(Parcel parcel, ClassLoader classLoader) {
            super(parcel, classLoader);
            this.f1751g = parcel.readInt();
        }

        @Override // c.h.a.a, android.os.Parcelable
        public void writeToParcel(Parcel parcel, int i2) {
            super.writeToParcel(parcel, i2);
            parcel.writeInt(this.f1751g);
        }

        public c(Parcelable parcelable, int i2) {
            super(parcelable);
            this.f1751g = i2;
        }
    }

    public BottomSheetBehavior(Context context, AttributeSet attributeSet) {
        int i2;
        super(context, attributeSet);
        this.a = true;
        this.l = 4;
        this.z = new a();
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, i.BottomSheetBehavior_Layout);
        TypedValue typedValuePeekValue = typedArrayObtainStyledAttributes.peekValue(i.BottomSheetBehavior_Layout_behavior_peekHeight);
        if (typedValuePeekValue != null && (i2 = typedValuePeekValue.data) == -1) {
            N(i2);
        } else {
            N(typedArrayObtainStyledAttributes.getDimensionPixelSize(i.BottomSheetBehavior_Layout_behavior_peekHeight, -1));
        }
        M(typedArrayObtainStyledAttributes.getBoolean(i.BottomSheetBehavior_Layout_behavior_hideable, false));
        L(typedArrayObtainStyledAttributes.getBoolean(i.BottomSheetBehavior_Layout_behavior_fitToContents, true));
        O(typedArrayObtainStyledAttributes.getBoolean(i.BottomSheetBehavior_Layout_behavior_skipCollapsed, false));
        typedArrayObtainStyledAttributes.recycle();
        this.f1741b = ViewConfiguration.get(context).getScaledMaximumFlingVelocity();
    }
}
