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 androidx.core.math.MathUtils; import androidx.core.view.ViewCompat; import androidx.customview.view.AbsSavedState; import androidx.customview.widget.ViewDragHelper; import com.google.android.material.R$dimen; import com.google.android.material.R$styleable; import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Map; /* loaded from: classes.dex */ public class BottomSheetBehavior extends CoordinatorLayout.Behavior { private boolean a; private float b; private int c; private boolean d; private int e; private int f; int g; int h; int i; boolean j; private boolean k; int l; ViewDragHelper m; private boolean n; private int o; private boolean p; int q; WeakReference r; WeakReference s; private BottomSheetCallback t; private VelocityTracker u; int v; private int w; boolean x; private Map y; private final ViewDragHelper.Callback z; public static abstract class BottomSheetCallback { public abstract void a(View view, float f); public abstract void a(View view, int i); } protected static class SavedState extends AbsSavedState { public static final Parcelable.Creator CREATOR = new Parcelable.ClassLoaderCreator() { // from class: com.google.android.material.bottomsheet.BottomSheetBehavior.SavedState.1 @Override // android.os.Parcelable.Creator public SavedState[] newArray(int i) { return new SavedState[i]; } /* JADX WARN: Can't rename method to resolve collision */ @Override // android.os.Parcelable.ClassLoaderCreator public SavedState createFromParcel(Parcel parcel, ClassLoader classLoader) { return new SavedState(parcel, classLoader); } @Override // android.os.Parcelable.Creator public SavedState createFromParcel(Parcel parcel) { return new SavedState(parcel, (ClassLoader) null); } }; final int state; public SavedState(Parcel parcel) { this(parcel, (ClassLoader) null); } @Override // androidx.customview.view.AbsSavedState, android.os.Parcelable public void writeToParcel(Parcel parcel, int i) { super.writeToParcel(parcel, i); parcel.writeInt(this.state); } public SavedState(Parcel parcel, ClassLoader classLoader) { super(parcel, classLoader); this.state = parcel.readInt(); } public SavedState(Parcelable parcelable, int i) { super(parcelable); this.state = i; } } private class SettleRunnable implements Runnable { private final View a; private final int b; SettleRunnable(View view, int i) { this.a = view; this.b = i; } @Override // java.lang.Runnable public void run() { ViewDragHelper viewDragHelper = BottomSheetBehavior.this.m; if (viewDragHelper == null || !viewDragHelper.a(true)) { BottomSheetBehavior.this.c(this.b); } else { ViewCompat.a(this.a, this); } } } public BottomSheetBehavior() { this.a = true; this.l = 4; this.z = new ViewDragHelper.Callback() { // from class: com.google.android.material.bottomsheet.BottomSheetBehavior.2 @Override // androidx.customview.widget.ViewDragHelper.Callback public void a(View view, int i, int i2, int i3, int i4) { BottomSheetBehavior.this.a(i2); } @Override // androidx.customview.widget.ViewDragHelper.Callback public boolean b(View view, int i) { WeakReference weakReference; View view2; BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.this; int i2 = bottomSheetBehavior.l; if (i2 == 1 || bottomSheetBehavior.x) { return false; } return ((i2 == 3 && bottomSheetBehavior.v == i && (view2 = bottomSheetBehavior.s.get()) != null && view2.canScrollVertically(-1)) || (weakReference = BottomSheetBehavior.this.r) == null || weakReference.get() != view) ? false : true; } @Override // androidx.customview.widget.ViewDragHelper.Callback public void c(int i) { if (i == 1) { BottomSheetBehavior.this.c(1); } } @Override // androidx.customview.widget.ViewDragHelper.Callback public void a(View view, float f, float f2) { int i; int i2; int i3; int i4 = 4; if (f2 >= 0.0f) { BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.this; if (bottomSheetBehavior.j && bottomSheetBehavior.a(view, f2) && (view.getTop() > BottomSheetBehavior.this.i || Math.abs(f) < Math.abs(f2))) { i3 = BottomSheetBehavior.this.q; i4 = 5; } else if (f2 == 0.0f || Math.abs(f) > Math.abs(f2)) { int top = view.getTop(); if (!BottomSheetBehavior.this.a) { BottomSheetBehavior bottomSheetBehavior2 = BottomSheetBehavior.this; int i5 = bottomSheetBehavior2.h; if (top < i5) { if (top >= Math.abs(top - bottomSheetBehavior2.i)) { i2 = BottomSheetBehavior.this.h; } i3 = 0; i4 = 3; } else if (Math.abs(top - i5) < Math.abs(top - BottomSheetBehavior.this.i)) { i2 = BottomSheetBehavior.this.h; } else { i = BottomSheetBehavior.this.i; } i3 = i2; i4 = 6; } else if (Math.abs(top - BottomSheetBehavior.this.g) < Math.abs(top - BottomSheetBehavior.this.i)) { i3 = BottomSheetBehavior.this.g; i4 = 3; } else { i = BottomSheetBehavior.this.i; } i3 = i; } else { i3 = BottomSheetBehavior.this.i; } } else if (BottomSheetBehavior.this.a) { i3 = BottomSheetBehavior.this.g; i4 = 3; } else { int top2 = view.getTop(); int i6 = BottomSheetBehavior.this.h; if (top2 > i6) { i3 = i6; i4 = 6; } i3 = 0; i4 = 3; } if (!BottomSheetBehavior.this.m.c(view.getLeft(), i3)) { BottomSheetBehavior.this.c(i4); } else { BottomSheetBehavior.this.c(2); ViewCompat.a(view, new SettleRunnable(view, i4)); } } @Override // androidx.customview.widget.ViewDragHelper.Callback public int b(View view, int i, int i2) { int c = BottomSheetBehavior.this.c(); BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.this; return MathUtils.a(i, c, bottomSheetBehavior.j ? bottomSheetBehavior.q : bottomSheetBehavior.i); } @Override // androidx.customview.widget.ViewDragHelper.Callback public int b(View view) { BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.this; if (bottomSheetBehavior.j) { return bottomSheetBehavior.q; } return bottomSheetBehavior.i; } @Override // androidx.customview.widget.ViewDragHelper.Callback public int a(View view, int i, int i2) { return view.getLeft(); } }; } private void e() { this.v = -1; VelocityTracker velocityTracker = this.u; if (velocityTracker != null) { velocityTracker.recycle(); this.u = null; } } public void c(boolean z) { this.k = z; } @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior public Parcelable d(CoordinatorLayout coordinatorLayout, V v) { return new SavedState(super.d(coordinatorLayout, v), this.l); } private float d() { VelocityTracker velocityTracker = this.u; if (velocityTracker == null) { return 0.0f; } velocityTracker.computeCurrentVelocity(1000, this.b); return this.u.getYVelocity(this.v); } @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior public void a(CoordinatorLayout coordinatorLayout, V v, Parcelable parcelable) { SavedState savedState = (SavedState) parcelable; super.a(coordinatorLayout, (CoordinatorLayout) v, savedState.getSuperState()); int i = savedState.state; if (i == 1 || i == 2) { this.l = 4; } else { this.l = i; } } @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior public boolean b(CoordinatorLayout coordinatorLayout, V v, MotionEvent motionEvent) { if (!v.isShown()) { return false; } int actionMasked = motionEvent.getActionMasked(); if (this.l == 1 && actionMasked == 0) { return true; } ViewDragHelper viewDragHelper = this.m; if (viewDragHelper != null) { viewDragHelper.a(motionEvent); } if (actionMasked == 0) { e(); } 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.c()) { this.m.a(v, motionEvent.getPointerId(motionEvent.getActionIndex())); } return !this.n; } void c(int i) { BottomSheetCallback bottomSheetCallback; if (this.l == i) { return; } this.l = i; if (i == 6 || i == 3) { d(true); } else if (i == 5 || i == 4) { d(false); } V v = this.r.get(); if (v == null || (bottomSheetCallback = this.t) == null) { return; } bottomSheetCallback.a((View) v, i); } public BottomSheetBehavior(Context context, AttributeSet attributeSet) { super(context, attributeSet); int i; this.a = true; this.l = 4; this.z = new ViewDragHelper.Callback() { // from class: com.google.android.material.bottomsheet.BottomSheetBehavior.2 @Override // androidx.customview.widget.ViewDragHelper.Callback public void a(View view, int i2, int i22, int i3, int i4) { BottomSheetBehavior.this.a(i22); } @Override // androidx.customview.widget.ViewDragHelper.Callback public boolean b(View view, int i2) { WeakReference weakReference; View view2; BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.this; int i22 = bottomSheetBehavior.l; if (i22 == 1 || bottomSheetBehavior.x) { return false; } return ((i22 == 3 && bottomSheetBehavior.v == i2 && (view2 = bottomSheetBehavior.s.get()) != null && view2.canScrollVertically(-1)) || (weakReference = BottomSheetBehavior.this.r) == null || weakReference.get() != view) ? false : true; } @Override // androidx.customview.widget.ViewDragHelper.Callback public void c(int i2) { if (i2 == 1) { BottomSheetBehavior.this.c(1); } } @Override // androidx.customview.widget.ViewDragHelper.Callback public void a(View view, float f, float f2) { int i2; int i22; int i3; int i4 = 4; if (f2 >= 0.0f) { BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.this; if (bottomSheetBehavior.j && bottomSheetBehavior.a(view, f2) && (view.getTop() > BottomSheetBehavior.this.i || Math.abs(f) < Math.abs(f2))) { i3 = BottomSheetBehavior.this.q; i4 = 5; } else if (f2 == 0.0f || Math.abs(f) > Math.abs(f2)) { int top = view.getTop(); if (!BottomSheetBehavior.this.a) { BottomSheetBehavior bottomSheetBehavior2 = BottomSheetBehavior.this; int i5 = bottomSheetBehavior2.h; if (top < i5) { if (top >= Math.abs(top - bottomSheetBehavior2.i)) { i22 = BottomSheetBehavior.this.h; } i3 = 0; i4 = 3; } else if (Math.abs(top - i5) < Math.abs(top - BottomSheetBehavior.this.i)) { i22 = BottomSheetBehavior.this.h; } else { i2 = BottomSheetBehavior.this.i; } i3 = i22; i4 = 6; } else if (Math.abs(top - BottomSheetBehavior.this.g) < Math.abs(top - BottomSheetBehavior.this.i)) { i3 = BottomSheetBehavior.this.g; i4 = 3; } else { i2 = BottomSheetBehavior.this.i; } i3 = i2; } else { i3 = BottomSheetBehavior.this.i; } } else if (BottomSheetBehavior.this.a) { i3 = BottomSheetBehavior.this.g; i4 = 3; } else { int top2 = view.getTop(); int i6 = BottomSheetBehavior.this.h; if (top2 > i6) { i3 = i6; i4 = 6; } i3 = 0; i4 = 3; } if (!BottomSheetBehavior.this.m.c(view.getLeft(), i3)) { BottomSheetBehavior.this.c(i4); } else { BottomSheetBehavior.this.c(2); ViewCompat.a(view, new SettleRunnable(view, i4)); } } @Override // androidx.customview.widget.ViewDragHelper.Callback public int b(View view, int i2, int i22) { int c = BottomSheetBehavior.this.c(); BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.this; return MathUtils.a(i2, c, bottomSheetBehavior.j ? bottomSheetBehavior.q : bottomSheetBehavior.i); } @Override // androidx.customview.widget.ViewDragHelper.Callback public int b(View view) { BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.this; if (bottomSheetBehavior.j) { return bottomSheetBehavior.q; } return bottomSheetBehavior.i; } @Override // androidx.customview.widget.ViewDragHelper.Callback public int a(View view, int i2, int i22) { return view.getLeft(); } }; TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R$styleable.BottomSheetBehavior_Layout); TypedValue peekValue = obtainStyledAttributes.peekValue(R$styleable.BottomSheetBehavior_Layout_behavior_peekHeight); if (peekValue != null && (i = peekValue.data) == -1) { b(i); } else { b(obtainStyledAttributes.getDimensionPixelSize(R$styleable.BottomSheetBehavior_Layout_behavior_peekHeight, -1)); } b(obtainStyledAttributes.getBoolean(R$styleable.BottomSheetBehavior_Layout_behavior_hideable, false)); a(obtainStyledAttributes.getBoolean(R$styleable.BottomSheetBehavior_Layout_behavior_fitToContents, true)); c(obtainStyledAttributes.getBoolean(R$styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed, false)); obtainStyledAttributes.recycle(); this.b = ViewConfiguration.get(context).getScaledMaximumFlingVelocity(); } private void d(boolean z) { WeakReference 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 i = 0; i < childCount; i++) { View childAt = coordinatorLayout.getChildAt(i); if (childAt != this.r.get()) { if (!z) { Map map = this.y; if (map != null && map.containsKey(childAt)) { ViewCompat.f(childAt, this.y.get(childAt).intValue()); } } else { if (Build.VERSION.SDK_INT >= 16) { this.y.put(childAt, Integer.valueOf(childAt.getImportantForAccessibility())); } ViewCompat.f(childAt, 4); } } } if (z) { return; } this.y = null; } } @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior public boolean a(CoordinatorLayout coordinatorLayout, V v, int i) { if (ViewCompat.h(coordinatorLayout) && !ViewCompat.h(v)) { v.setFitsSystemWindows(true); } int top = v.getTop(); coordinatorLayout.c(v, i); this.q = coordinatorLayout.getHeight(); if (this.d) { if (this.e == 0) { this.e = coordinatorLayout.getResources().getDimensionPixelSize(R$dimen.design_bottom_sheet_peek_height_min); } this.f = Math.max(this.e, this.q - ((coordinatorLayout.getWidth() * 9) / 16)); } else { this.f = this.c; } this.g = Math.max(0, this.q - v.getHeight()); this.h = this.q / 2; b(); int i2 = this.l; if (i2 == 3) { ViewCompat.d((View) v, c()); } else if (i2 == 6) { ViewCompat.d((View) v, this.h); } else if (this.j && i2 == 5) { ViewCompat.d((View) v, this.q); } else { int i3 = this.l; if (i3 == 4) { ViewCompat.d((View) v, this.i); } else if (i3 == 1 || i3 == 2) { ViewCompat.d((View) v, top - v.getTop()); } } if (this.m == null) { this.m = ViewDragHelper.a(coordinatorLayout, this.z); } this.r = new WeakReference<>(v); this.s = new WeakReference<>(a(v)); return true; } /* JADX INFO: Access modifiers changed from: private */ public int c() { if (this.a) { return this.g; } return 0; } @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior public boolean b(CoordinatorLayout coordinatorLayout, V v, View view, View view2, int i, int i2) { this.o = 0; this.p = false; return (i & 2) != 0; } public final void b(int i) { WeakReference weakReference; V v; boolean z = true; if (i == -1) { if (!this.d) { this.d = true; } z = false; } else { if (this.d || this.c != i) { this.d = false; this.c = Math.max(0, i); this.i = this.q - i; } z = false; } if (!z || this.l != 4 || (weakReference = this.r) == null || (v = weakReference.get()) == null) { return; } v.requestLayout(); } public void b(boolean z) { this.j = z; } private void b() { if (this.a) { this.i = Math.max(this.q - this.f, this.g); } else { this.i = this.q - this.f; } } @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior public boolean a(CoordinatorLayout coordinatorLayout, V v, MotionEvent motionEvent) { ViewDragHelper viewDragHelper; if (!v.isShown()) { this.n = true; return false; } int actionMasked = motionEvent.getActionMasked(); if (actionMasked == 0) { e(); } 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 weakReference = this.s; View view = weakReference != null ? weakReference.get() : null; if (view != null && coordinatorLayout.a(view, x, this.w)) { this.v = motionEvent.getPointerId(motionEvent.getActionIndex()); this.x = true; } this.n = this.v == -1 && !coordinatorLayout.a(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 && (viewDragHelper = this.m) != null && viewDragHelper.b(motionEvent)) { return true; } WeakReference weakReference2 = this.s; View view2 = weakReference2 != null ? weakReference2.get() : null; return (actionMasked != 2 || view2 == null || this.n || this.l == 1 || coordinatorLayout.a(view2, (int) motionEvent.getX(), (int) motionEvent.getY()) || this.m == null || Math.abs(((float) this.w) - motionEvent.getY()) <= ((float) this.m.c())) ? false : true; } @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior public void a(CoordinatorLayout coordinatorLayout, V v, View view, int i, int i2, int[] iArr, int i3) { if (i3 != 1 && view == this.s.get()) { int top = v.getTop(); int i4 = top - i2; if (i2 > 0) { if (i4 < c()) { iArr[1] = top - c(); ViewCompat.d((View) v, -iArr[1]); c(3); } else { iArr[1] = i2; ViewCompat.d((View) v, -i2); c(1); } } else if (i2 < 0 && !view.canScrollVertically(-1)) { int i5 = this.i; if (i4 > i5 && !this.j) { iArr[1] = top - i5; ViewCompat.d((View) v, -iArr[1]); c(4); } else { iArr[1] = i2; ViewCompat.d((View) v, -i2); c(1); } } a(v.getTop()); this.o = i2; this.p = true; } } @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior public void a(CoordinatorLayout coordinatorLayout, V v, View view, int i) { int i2; int i3 = 3; if (v.getTop() == c()) { c(3); return; } if (view == this.s.get() && this.p) { if (this.o > 0) { i2 = c(); } else if (this.j && a(v, d())) { i2 = this.q; i3 = 5; } else { if (this.o == 0) { int top = v.getTop(); if (this.a) { if (Math.abs(top - this.g) < Math.abs(top - this.i)) { i2 = this.g; } else { i2 = this.i; } } else { int i4 = this.h; if (top < i4) { if (top < Math.abs(top - this.i)) { i2 = 0; } else { i2 = this.h; } } else if (Math.abs(top - i4) < Math.abs(top - this.i)) { i2 = this.h; } else { i2 = this.i; } i3 = 6; } } else { i2 = this.i; } i3 = 4; } if (this.m.b(v, v.getLeft(), i2)) { c(2); ViewCompat.a(v, new SettleRunnable(v, i3)); } else { c(i3); } this.p = false; } } @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior public boolean a(CoordinatorLayout coordinatorLayout, V v, View view, float f, float f2) { return view == this.s.get() && (this.l != 3 || super.a(coordinatorLayout, (CoordinatorLayout) v, view, f, f2)); } public void a(boolean z) { if (this.a == z) { return; } this.a = z; if (this.r != null) { b(); } c((this.a && this.l == 6) ? 3 : this.l); } boolean a(View view, float f) { if (this.k) { return true; } return view.getTop() >= this.i && Math.abs((((float) view.getTop()) + (f * 0.1f)) - ((float) this.i)) / ((float) this.c) > 0.5f; } View a(View view) { if (ViewCompat.y(view)) { return view; } if (!(view instanceof ViewGroup)) { return null; } ViewGroup viewGroup = (ViewGroup) view; int childCount = viewGroup.getChildCount(); for (int i = 0; i < childCount; i++) { View a = a(viewGroup.getChildAt(i)); if (a != null) { return a; } } return null; } void a(int i) { BottomSheetCallback bottomSheetCallback; V v = this.r.get(); if (v == null || (bottomSheetCallback = this.t) == null) { return; } if (i > this.i) { bottomSheetCallback.a(v, (r2 - i) / (this.q - r2)); } else { bottomSheetCallback.a(v, (r2 - i) / (r2 - c())); } } }