155 lines
4.6 KiB
Java
155 lines
4.6 KiB
Java
package androidx.recyclerview.widget;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.PointF;
|
|
import android.util.DisplayMetrics;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.animation.DecelerateInterpolator;
|
|
import android.view.animation.LinearInterpolator;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import com.thoughtworks.xstream.XStream;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class LinearSmoothScroller extends RecyclerView.SmoothScroller {
|
|
protected PointF k;
|
|
private final float l;
|
|
protected final LinearInterpolator i = new LinearInterpolator();
|
|
protected final DecelerateInterpolator j = new DecelerateInterpolator();
|
|
protected int m = 0;
|
|
protected int n = 0;
|
|
|
|
public LinearSmoothScroller(Context context) {
|
|
this.l = a(context.getResources().getDisplayMetrics());
|
|
}
|
|
|
|
private int b(int i, int i2) {
|
|
int i3 = i - i2;
|
|
if (i * i3 <= 0) {
|
|
return 0;
|
|
}
|
|
return i3;
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.SmoothScroller
|
|
protected void a(View view, RecyclerView.State state, RecyclerView.SmoothScroller.Action action) {
|
|
int a = a(view, i());
|
|
int b = b(view, j());
|
|
int d = d((int) Math.sqrt((a * a) + (b * b)));
|
|
if (d > 0) {
|
|
action.a(-a, -b, d, this.j);
|
|
}
|
|
}
|
|
|
|
public int b(View view, int i) {
|
|
RecyclerView.LayoutManager b = b();
|
|
if (b == null || !b.b()) {
|
|
return 0;
|
|
}
|
|
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams();
|
|
return a(b.j(view) - ((ViewGroup.MarginLayoutParams) layoutParams).topMargin, b.e(view) + ((ViewGroup.MarginLayoutParams) layoutParams).bottomMargin, b.q(), b.h() - b.n(), i);
|
|
}
|
|
|
|
protected int d(int i) {
|
|
return (int) Math.ceil(e(i) / 0.3356d);
|
|
}
|
|
|
|
protected int e(int i) {
|
|
return (int) Math.ceil(Math.abs(i) * this.l);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.SmoothScroller
|
|
protected void f() {
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.SmoothScroller
|
|
protected void g() {
|
|
this.n = 0;
|
|
this.m = 0;
|
|
this.k = null;
|
|
}
|
|
|
|
protected int i() {
|
|
PointF pointF = this.k;
|
|
if (pointF != null) {
|
|
float f = pointF.x;
|
|
if (f != 0.0f) {
|
|
return f > 0.0f ? 1 : -1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
protected int j() {
|
|
PointF pointF = this.k;
|
|
if (pointF != null) {
|
|
float f = pointF.y;
|
|
if (f != 0.0f) {
|
|
return f > 0.0f ? 1 : -1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.SmoothScroller
|
|
protected void a(int i, int i2, RecyclerView.State state, RecyclerView.SmoothScroller.Action action) {
|
|
if (a() == 0) {
|
|
h();
|
|
return;
|
|
}
|
|
this.m = b(this.m, i);
|
|
this.n = b(this.n, i2);
|
|
if (this.m == 0 && this.n == 0) {
|
|
a(action);
|
|
}
|
|
}
|
|
|
|
protected float a(DisplayMetrics displayMetrics) {
|
|
return 25.0f / displayMetrics.densityDpi;
|
|
}
|
|
|
|
protected void a(RecyclerView.SmoothScroller.Action action) {
|
|
PointF a = a(c());
|
|
if (a != null && (a.x != 0.0f || a.y != 0.0f)) {
|
|
a(a);
|
|
this.k = a;
|
|
this.m = (int) (a.x * 10000.0f);
|
|
this.n = (int) (a.y * 10000.0f);
|
|
action.a((int) (this.m * 1.2f), (int) (this.n * 1.2f), (int) (e(XStream.PRIORITY_VERY_HIGH) * 1.2f), this.i);
|
|
return;
|
|
}
|
|
action.a(c());
|
|
h();
|
|
}
|
|
|
|
public int a(int i, int i2, int i3, int i4, int i5) {
|
|
if (i5 == -1) {
|
|
return i3 - i;
|
|
}
|
|
if (i5 != 0) {
|
|
if (i5 == 1) {
|
|
return i4 - i2;
|
|
}
|
|
throw new IllegalArgumentException("snap preference should be one of the constants defined in SmoothScroller, starting with SNAP_");
|
|
}
|
|
int i6 = i3 - i;
|
|
if (i6 > 0) {
|
|
return i6;
|
|
}
|
|
int i7 = i4 - i2;
|
|
if (i7 < 0) {
|
|
return i7;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public int a(View view, int i) {
|
|
RecyclerView.LayoutManager b = b();
|
|
if (b == null || !b.a()) {
|
|
return 0;
|
|
}
|
|
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams();
|
|
return a(b.f(view) - ((ViewGroup.MarginLayoutParams) layoutParams).leftMargin, b.i(view) + ((ViewGroup.MarginLayoutParams) layoutParams).rightMargin, b.o(), b.r() - b.p(), i);
|
|
}
|
|
}
|