Initial commit
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package com.google.android.material.behavior;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.TimeInterpolator;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewPropertyAnimator;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import com.google.android.material.animation.AnimationUtils;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class HideBottomViewOnScrollBehavior<V extends View> extends CoordinatorLayout.Behavior<V> {
|
||||
private int a;
|
||||
private int b;
|
||||
private ViewPropertyAnimator c;
|
||||
|
||||
public HideBottomViewOnScrollBehavior() {
|
||||
this.a = 0;
|
||||
this.b = 2;
|
||||
}
|
||||
|
||||
protected void b(V v) {
|
||||
ViewPropertyAnimator viewPropertyAnimator = this.c;
|
||||
if (viewPropertyAnimator != null) {
|
||||
viewPropertyAnimator.cancel();
|
||||
v.clearAnimation();
|
||||
}
|
||||
this.b = 2;
|
||||
a((HideBottomViewOnScrollBehavior<V>) v, 0, 225L, AnimationUtils.d);
|
||||
}
|
||||
|
||||
@Override // androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior
|
||||
public boolean b(CoordinatorLayout coordinatorLayout, V v, View view, View view2, int i) {
|
||||
return i == 2;
|
||||
}
|
||||
|
||||
@Override // androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior
|
||||
public boolean a(CoordinatorLayout coordinatorLayout, V v, int i) {
|
||||
this.a = v.getMeasuredHeight();
|
||||
return super.a(coordinatorLayout, (CoordinatorLayout) v, i);
|
||||
}
|
||||
|
||||
public HideBottomViewOnScrollBehavior(Context context, AttributeSet attributeSet) {
|
||||
super(context, attributeSet);
|
||||
this.a = 0;
|
||||
this.b = 2;
|
||||
}
|
||||
|
||||
@Override // androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior
|
||||
public void a(CoordinatorLayout coordinatorLayout, V v, View view, int i, int i2, int i3, int i4) {
|
||||
if (this.b != 1 && i2 > 0) {
|
||||
a((HideBottomViewOnScrollBehavior<V>) v);
|
||||
} else {
|
||||
if (this.b == 2 || i2 >= 0) {
|
||||
return;
|
||||
}
|
||||
b(v);
|
||||
}
|
||||
}
|
||||
|
||||
protected void a(V v) {
|
||||
ViewPropertyAnimator viewPropertyAnimator = this.c;
|
||||
if (viewPropertyAnimator != null) {
|
||||
viewPropertyAnimator.cancel();
|
||||
v.clearAnimation();
|
||||
}
|
||||
this.b = 1;
|
||||
a((HideBottomViewOnScrollBehavior<V>) v, this.a, 175L, AnimationUtils.c);
|
||||
}
|
||||
|
||||
private void a(V v, int i, long j, TimeInterpolator timeInterpolator) {
|
||||
this.c = v.animate().translationY(i).setInterpolator(timeInterpolator).setDuration(j).setListener(new AnimatorListenerAdapter() { // from class: com.google.android.material.behavior.HideBottomViewOnScrollBehavior.1
|
||||
@Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
|
||||
public void onAnimationEnd(Animator animator) {
|
||||
HideBottomViewOnScrollBehavior.this.c = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,262 @@
|
||||
package com.google.android.material.behavior;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.customview.widget.ViewDragHelper;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class SwipeDismissBehavior<V extends View> extends CoordinatorLayout.Behavior<V> {
|
||||
ViewDragHelper a;
|
||||
OnDismissListener b;
|
||||
private boolean c;
|
||||
private boolean e;
|
||||
private float d = 0.0f;
|
||||
int f = 2;
|
||||
float g = 0.5f;
|
||||
float h = 0.0f;
|
||||
float i = 0.5f;
|
||||
private final ViewDragHelper.Callback j = new ViewDragHelper.Callback() { // from class: com.google.android.material.behavior.SwipeDismissBehavior.1
|
||||
private int a;
|
||||
private int b = -1;
|
||||
|
||||
@Override // androidx.customview.widget.ViewDragHelper.Callback
|
||||
public void a(View view, int i) {
|
||||
this.b = i;
|
||||
this.a = view.getLeft();
|
||||
ViewParent parent = view.getParent();
|
||||
if (parent != null) {
|
||||
parent.requestDisallowInterceptTouchEvent(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // androidx.customview.widget.ViewDragHelper.Callback
|
||||
public boolean b(View view, int i) {
|
||||
return this.b == -1 && SwipeDismissBehavior.this.a(view);
|
||||
}
|
||||
|
||||
@Override // androidx.customview.widget.ViewDragHelper.Callback
|
||||
public void c(int i) {
|
||||
OnDismissListener onDismissListener = SwipeDismissBehavior.this.b;
|
||||
if (onDismissListener != null) {
|
||||
onDismissListener.a(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // androidx.customview.widget.ViewDragHelper.Callback
|
||||
public int b(View view, int i, int i2) {
|
||||
return view.getTop();
|
||||
}
|
||||
|
||||
@Override // androidx.customview.widget.ViewDragHelper.Callback
|
||||
public void a(View view, float f, float f2) {
|
||||
int i;
|
||||
boolean z;
|
||||
OnDismissListener onDismissListener;
|
||||
this.b = -1;
|
||||
int width = view.getWidth();
|
||||
if (a(view, f)) {
|
||||
int left = view.getLeft();
|
||||
int i2 = this.a;
|
||||
i = left < i2 ? i2 - width : i2 + width;
|
||||
z = true;
|
||||
} else {
|
||||
i = this.a;
|
||||
z = false;
|
||||
}
|
||||
if (SwipeDismissBehavior.this.a.c(i, view.getTop())) {
|
||||
ViewCompat.a(view, new SettleRunnable(view, z));
|
||||
} else {
|
||||
if (!z || (onDismissListener = SwipeDismissBehavior.this.b) == null) {
|
||||
return;
|
||||
}
|
||||
onDismissListener.a(view);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean a(View view, float f) {
|
||||
if (f == 0.0f) {
|
||||
return Math.abs(view.getLeft() - this.a) >= Math.round(((float) view.getWidth()) * SwipeDismissBehavior.this.g);
|
||||
}
|
||||
boolean z = ViewCompat.k(view) == 1;
|
||||
int i = SwipeDismissBehavior.this.f;
|
||||
if (i == 2) {
|
||||
return true;
|
||||
}
|
||||
if (i == 0) {
|
||||
if (z) {
|
||||
if (f >= 0.0f) {
|
||||
return false;
|
||||
}
|
||||
} else if (f <= 0.0f) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (i != 1) {
|
||||
return false;
|
||||
}
|
||||
if (z) {
|
||||
if (f <= 0.0f) {
|
||||
return false;
|
||||
}
|
||||
} else if (f >= 0.0f) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override // androidx.customview.widget.ViewDragHelper.Callback
|
||||
public int a(View view) {
|
||||
return view.getWidth();
|
||||
}
|
||||
|
||||
@Override // androidx.customview.widget.ViewDragHelper.Callback
|
||||
public int a(View view, int i, int i2) {
|
||||
int width;
|
||||
int width2;
|
||||
int width3;
|
||||
boolean z = ViewCompat.k(view) == 1;
|
||||
int i3 = SwipeDismissBehavior.this.f;
|
||||
if (i3 == 0) {
|
||||
if (z) {
|
||||
width = this.a - view.getWidth();
|
||||
width2 = this.a;
|
||||
} else {
|
||||
width = this.a;
|
||||
width3 = view.getWidth();
|
||||
width2 = width3 + width;
|
||||
}
|
||||
} else if (i3 != 1) {
|
||||
width = this.a - view.getWidth();
|
||||
width2 = view.getWidth() + this.a;
|
||||
} else if (z) {
|
||||
width = this.a;
|
||||
width3 = view.getWidth();
|
||||
width2 = width3 + width;
|
||||
} else {
|
||||
width = this.a - view.getWidth();
|
||||
width2 = this.a;
|
||||
}
|
||||
return SwipeDismissBehavior.a(width, i, width2);
|
||||
}
|
||||
|
||||
@Override // androidx.customview.widget.ViewDragHelper.Callback
|
||||
public void a(View view, int i, int i2, int i3, int i4) {
|
||||
float width = this.a + (view.getWidth() * SwipeDismissBehavior.this.h);
|
||||
float width2 = this.a + (view.getWidth() * SwipeDismissBehavior.this.i);
|
||||
float f = i;
|
||||
if (f <= width) {
|
||||
view.setAlpha(1.0f);
|
||||
} else if (f >= width2) {
|
||||
view.setAlpha(0.0f);
|
||||
} else {
|
||||
view.setAlpha(SwipeDismissBehavior.a(0.0f, 1.0f - SwipeDismissBehavior.b(width, width2, f), 1.0f));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public interface OnDismissListener {
|
||||
void a(int i);
|
||||
|
||||
void a(View view);
|
||||
}
|
||||
|
||||
private class SettleRunnable implements Runnable {
|
||||
private final View a;
|
||||
private final boolean b;
|
||||
|
||||
SettleRunnable(View view, boolean z) {
|
||||
this.a = view;
|
||||
this.b = z;
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
OnDismissListener onDismissListener;
|
||||
ViewDragHelper viewDragHelper = SwipeDismissBehavior.this.a;
|
||||
if (viewDragHelper != null && viewDragHelper.a(true)) {
|
||||
ViewCompat.a(this.a, this);
|
||||
} else {
|
||||
if (!this.b || (onDismissListener = SwipeDismissBehavior.this.b) == null) {
|
||||
return;
|
||||
}
|
||||
onDismissListener.a(this.a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static float b(float f, float f2, float f3) {
|
||||
return (f3 - f) / (f2 - f);
|
||||
}
|
||||
|
||||
public void a(OnDismissListener onDismissListener) {
|
||||
this.b = onDismissListener;
|
||||
}
|
||||
|
||||
public boolean a(View view) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void b(float f) {
|
||||
this.h = a(0.0f, f, 1.0f);
|
||||
}
|
||||
|
||||
public void a(int i) {
|
||||
this.f = i;
|
||||
}
|
||||
|
||||
@Override // androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior
|
||||
public boolean b(CoordinatorLayout coordinatorLayout, V v, MotionEvent motionEvent) {
|
||||
ViewDragHelper viewDragHelper = this.a;
|
||||
if (viewDragHelper == null) {
|
||||
return false;
|
||||
}
|
||||
viewDragHelper.a(motionEvent);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void a(float f) {
|
||||
this.i = a(0.0f, f, 1.0f);
|
||||
}
|
||||
|
||||
@Override // androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior
|
||||
public boolean a(CoordinatorLayout coordinatorLayout, V v, MotionEvent motionEvent) {
|
||||
boolean z = this.c;
|
||||
int actionMasked = motionEvent.getActionMasked();
|
||||
if (actionMasked == 0) {
|
||||
this.c = coordinatorLayout.a(v, (int) motionEvent.getX(), (int) motionEvent.getY());
|
||||
z = this.c;
|
||||
} else if (actionMasked == 1 || actionMasked == 3) {
|
||||
this.c = false;
|
||||
}
|
||||
if (!z) {
|
||||
return false;
|
||||
}
|
||||
a((ViewGroup) coordinatorLayout);
|
||||
return this.a.b(motionEvent);
|
||||
}
|
||||
|
||||
private void a(ViewGroup viewGroup) {
|
||||
ViewDragHelper a;
|
||||
if (this.a == null) {
|
||||
if (this.e) {
|
||||
a = ViewDragHelper.a(viewGroup, this.d, this.j);
|
||||
} else {
|
||||
a = ViewDragHelper.a(viewGroup, this.j);
|
||||
}
|
||||
this.a = a;
|
||||
}
|
||||
}
|
||||
|
||||
static float a(float f, float f2, float f3) {
|
||||
return Math.min(Math.max(f, f2), f3);
|
||||
}
|
||||
|
||||
static int a(int i, int i2, int i3) {
|
||||
return Math.min(Math.max(i, i2), i3);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user