jimu-decompiled/sources/androidx/recyclerview/widget/FastScroller.java
2025-05-13 19:24:51 +02:00

446 lines
13 KiB
Java

package androidx.recyclerview.widget;
import android.R;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.view.MotionEvent;
import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.gms.common.ConnectionResult;
import com.ubt.jimu.base.mvp.SingleClickListener;
/* loaded from: classes.dex */
class FastScroller extends RecyclerView.ItemDecoration implements RecyclerView.OnItemTouchListener {
private static final int[] D = {R.attr.state_pressed};
private static final int[] E = new int[0];
private final int a;
private final int b;
final StateListDrawable c;
final Drawable d;
private final int e;
private final int f;
private final StateListDrawable g;
private final Drawable h;
private final int i;
private final int j;
int k;
int l;
float m;
int n;
int o;
float p;
private RecyclerView s;
private int q = 0;
private int r = 0;
private boolean t = false;
private boolean u = false;
private int v = 0;
private int w = 0;
private final int[] x = new int[2];
private final int[] y = new int[2];
final ValueAnimator z = ValueAnimator.ofFloat(0.0f, 1.0f);
int A = 0;
private final Runnable B = new Runnable() { // from class: androidx.recyclerview.widget.FastScroller.1
@Override // java.lang.Runnable
public void run() {
FastScroller.this.a(SingleClickListener.FAST_CLICK_DELAY_TIME);
}
};
private final RecyclerView.OnScrollListener C = new RecyclerView.OnScrollListener() { // from class: androidx.recyclerview.widget.FastScroller.2
@Override // androidx.recyclerview.widget.RecyclerView.OnScrollListener
public void a(RecyclerView recyclerView, int i, int i2) {
FastScroller.this.a(recyclerView.computeHorizontalScrollOffset(), recyclerView.computeVerticalScrollOffset());
}
};
private class AnimatorListener extends AnimatorListenerAdapter {
private boolean a = false;
AnimatorListener() {
}
@Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
public void onAnimationCancel(Animator animator) {
this.a = true;
}
@Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
public void onAnimationEnd(Animator animator) {
if (this.a) {
this.a = false;
return;
}
if (((Float) FastScroller.this.z.getAnimatedValue()).floatValue() == 0.0f) {
FastScroller fastScroller = FastScroller.this;
fastScroller.A = 0;
fastScroller.b(0);
} else {
FastScroller fastScroller2 = FastScroller.this;
fastScroller2.A = 2;
fastScroller2.a();
}
}
}
private class AnimatorUpdater implements ValueAnimator.AnimatorUpdateListener {
AnimatorUpdater() {
}
@Override // android.animation.ValueAnimator.AnimatorUpdateListener
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int floatValue = (int) (((Float) valueAnimator.getAnimatedValue()).floatValue() * 255.0f);
FastScroller.this.c.setAlpha(floatValue);
FastScroller.this.d.setAlpha(floatValue);
FastScroller.this.a();
}
}
FastScroller(RecyclerView recyclerView, StateListDrawable stateListDrawable, Drawable drawable, StateListDrawable stateListDrawable2, Drawable drawable2, int i, int i2, int i3) {
this.c = stateListDrawable;
this.d = drawable;
this.g = stateListDrawable2;
this.h = drawable2;
this.e = Math.max(i, stateListDrawable.getIntrinsicWidth());
this.f = Math.max(i, drawable.getIntrinsicWidth());
this.i = Math.max(i, stateListDrawable2.getIntrinsicWidth());
this.j = Math.max(i, drawable2.getIntrinsicWidth());
this.a = i2;
this.b = i3;
this.c.setAlpha(255);
this.d.setAlpha(255);
this.z.addListener(new AnimatorListener());
this.z.addUpdateListener(new AnimatorUpdater());
a(recyclerView);
}
private void c() {
this.s.removeCallbacks(this.B);
}
private void d() {
this.s.b((RecyclerView.ItemDecoration) this);
this.s.b((RecyclerView.OnItemTouchListener) this);
this.s.b(this.C);
c();
}
private int[] e() {
int[] iArr = this.y;
int i = this.b;
iArr[0] = i;
iArr[1] = this.q - i;
return iArr;
}
private int[] f() {
int[] iArr = this.x;
int i = this.b;
iArr[0] = i;
iArr[1] = this.r - i;
return iArr;
}
private boolean g() {
return ViewCompat.k(this.s) == 1;
}
private void h() {
this.s.a((RecyclerView.ItemDecoration) this);
this.s.a((RecyclerView.OnItemTouchListener) this);
this.s.a(this.C);
}
public void a(RecyclerView recyclerView) {
RecyclerView recyclerView2 = this.s;
if (recyclerView2 == recyclerView) {
return;
}
if (recyclerView2 != null) {
d();
}
this.s = recyclerView;
if (this.s != null) {
h();
}
}
void b(int i) {
if (i == 2 && this.v != 2) {
this.c.setState(D);
c();
}
if (i == 0) {
a();
} else {
b();
}
if (this.v == 2 && i != 2) {
this.c.setState(E);
c(1200);
} else if (i == 1) {
c(ConnectionResult.DRIVE_EXTERNAL_STORAGE_REQUIRED);
}
this.v = i;
}
@Override // androidx.recyclerview.widget.RecyclerView.ItemDecoration
public void onDrawOver(Canvas canvas, RecyclerView recyclerView, RecyclerView.State state) {
if (this.q != this.s.getWidth() || this.r != this.s.getHeight()) {
this.q = this.s.getWidth();
this.r = this.s.getHeight();
b(0);
} else if (this.A != 0) {
if (this.t) {
b(canvas);
}
if (this.u) {
a(canvas);
}
}
}
@Override // androidx.recyclerview.widget.RecyclerView.OnItemTouchListener
public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
int i = this.v;
if (i == 1) {
boolean b = b(motionEvent.getX(), motionEvent.getY());
boolean a = a(motionEvent.getX(), motionEvent.getY());
if (motionEvent.getAction() != 0) {
return false;
}
if (!b && !a) {
return false;
}
if (a) {
this.w = 1;
this.p = (int) motionEvent.getX();
} else if (b) {
this.w = 2;
this.m = (int) motionEvent.getY();
}
b(2);
} else if (i != 2) {
return false;
}
return true;
}
@Override // androidx.recyclerview.widget.RecyclerView.OnItemTouchListener
public void onRequestDisallowInterceptTouchEvent(boolean z) {
}
@Override // androidx.recyclerview.widget.RecyclerView.OnItemTouchListener
public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
if (this.v == 0) {
return;
}
if (motionEvent.getAction() == 0) {
boolean b = b(motionEvent.getX(), motionEvent.getY());
boolean a = a(motionEvent.getX(), motionEvent.getY());
if (b || a) {
if (a) {
this.w = 1;
this.p = (int) motionEvent.getX();
} else if (b) {
this.w = 2;
this.m = (int) motionEvent.getY();
}
b(2);
return;
}
return;
}
if (motionEvent.getAction() == 1 && this.v == 2) {
this.m = 0.0f;
this.p = 0.0f;
b(1);
this.w = 0;
return;
}
if (motionEvent.getAction() == 2 && this.v == 2) {
b();
if (this.w == 1) {
a(motionEvent.getX());
}
if (this.w == 2) {
b(motionEvent.getY());
}
}
}
private void c(int i) {
c();
this.s.postDelayed(this.B, i);
}
void a() {
this.s.invalidate();
}
void a(int i) {
int i2 = this.A;
if (i2 == 1) {
this.z.cancel();
} else if (i2 != 2) {
return;
}
this.A = 3;
ValueAnimator valueAnimator = this.z;
valueAnimator.setFloatValues(((Float) valueAnimator.getAnimatedValue()).floatValue(), 0.0f);
this.z.setDuration(i);
this.z.start();
}
public void b() {
int i = this.A;
if (i != 0) {
if (i != 3) {
return;
} else {
this.z.cancel();
}
}
this.A = 1;
ValueAnimator valueAnimator = this.z;
valueAnimator.setFloatValues(((Float) valueAnimator.getAnimatedValue()).floatValue(), 1.0f);
this.z.setDuration(500L);
this.z.setStartDelay(0L);
this.z.start();
}
private void a(Canvas canvas) {
int i = this.r;
int i2 = this.i;
int i3 = this.o;
int i4 = this.n;
this.g.setBounds(0, 0, i4, i2);
this.h.setBounds(0, 0, this.q, this.j);
canvas.translate(0.0f, i - i2);
this.h.draw(canvas);
canvas.translate(i3 - (i4 / 2), 0.0f);
this.g.draw(canvas);
canvas.translate(-r2, -r0);
}
private void b(Canvas canvas) {
int i = this.q;
int i2 = this.e;
int i3 = i - i2;
int i4 = this.l;
int i5 = this.k;
int i6 = i4 - (i5 / 2);
this.c.setBounds(0, 0, i2, i5);
this.d.setBounds(0, 0, this.f, this.r);
if (g()) {
this.d.draw(canvas);
canvas.translate(this.e, i6);
canvas.scale(-1.0f, 1.0f);
this.c.draw(canvas);
canvas.scale(1.0f, 1.0f);
canvas.translate(-this.e, -i6);
return;
}
canvas.translate(i3, 0.0f);
this.d.draw(canvas);
canvas.translate(0.0f, i6);
this.c.draw(canvas);
canvas.translate(-i3, -i6);
}
void a(int i, int i2) {
int computeVerticalScrollRange = this.s.computeVerticalScrollRange();
int i3 = this.r;
this.t = computeVerticalScrollRange - i3 > 0 && i3 >= this.a;
int computeHorizontalScrollRange = this.s.computeHorizontalScrollRange();
int i4 = this.q;
this.u = computeHorizontalScrollRange - i4 > 0 && i4 >= this.a;
if (!this.t && !this.u) {
if (this.v != 0) {
b(0);
return;
}
return;
}
if (this.t) {
float f = i3;
this.l = (int) ((f * (i2 + (f / 2.0f))) / computeVerticalScrollRange);
this.k = Math.min(i3, (i3 * i3) / computeVerticalScrollRange);
}
if (this.u) {
float f2 = i4;
this.o = (int) ((f2 * (i + (f2 / 2.0f))) / computeHorizontalScrollRange);
this.n = Math.min(i4, (i4 * i4) / computeHorizontalScrollRange);
}
int i5 = this.v;
if (i5 == 0 || i5 == 1) {
b(1);
}
}
private void b(float f) {
int[] f2 = f();
float max = Math.max(f2[0], Math.min(f2[1], f));
if (Math.abs(this.l - max) < 2.0f) {
return;
}
int a = a(this.m, max, f2, this.s.computeVerticalScrollRange(), this.s.computeVerticalScrollOffset(), this.r);
if (a != 0) {
this.s.scrollBy(0, a);
}
this.m = max;
}
private void a(float f) {
int[] e = e();
float max = Math.max(e[0], Math.min(e[1], f));
if (Math.abs(this.o - max) < 2.0f) {
return;
}
int a = a(this.p, max, e, this.s.computeHorizontalScrollRange(), this.s.computeHorizontalScrollOffset(), this.q);
if (a != 0) {
this.s.scrollBy(a, 0);
}
this.p = max;
}
boolean b(float f, float f2) {
if (!g() ? f >= this.q - this.e : f <= this.e / 2) {
int i = this.l;
int i2 = this.k;
if (f2 >= i - (i2 / 2) && f2 <= i + (i2 / 2)) {
return true;
}
}
return false;
}
private int a(float f, float f2, int[] iArr, int i, int i2, int i3) {
int i4 = iArr[1] - iArr[0];
if (i4 == 0) {
return 0;
}
int i5 = i - i3;
int i6 = (int) (((f2 - f) / i4) * i5);
int i7 = i2 + i6;
if (i7 >= i5 || i7 < 0) {
return 0;
}
return i6;
}
boolean a(float f, float f2) {
if (f2 >= this.r - this.i) {
int i = this.o;
int i2 = this.n;
if (f >= i - (i2 / 2) && f <= i + (i2 / 2)) {
return true;
}
}
return false;
}
}