214 lines
7.8 KiB
Java
214 lines
7.8 KiB
Java
package com.ubt.jimu.picture.pagerecyclerview;
|
|
|
|
import android.animation.Animator;
|
|
import android.animation.AnimatorListenerAdapter;
|
|
import android.animation.ValueAnimator;
|
|
import android.view.MotionEvent;
|
|
import android.view.View;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import com.baidu.cloud.media.player.IMediaPlayer;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class PagerHelper {
|
|
RecyclerView a = null;
|
|
private MyOnScrollListener b = new MyOnScrollListener();
|
|
private MyOnFlingListener c = new MyOnFlingListener();
|
|
private int d = 0;
|
|
private int e = 0;
|
|
int f = 0;
|
|
int g = 0;
|
|
ORIENTATION h = ORIENTATION.HORIZONTAL;
|
|
ValueAnimator i = null;
|
|
private MyOnTouchListener j = new MyOnTouchListener();
|
|
onPageChangeListener k;
|
|
|
|
public class MyOnFlingListener extends RecyclerView.OnFlingListener {
|
|
public MyOnFlingListener() {
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.OnFlingListener
|
|
public boolean a(int i, int i2) {
|
|
int width;
|
|
int i3;
|
|
PagerHelper pagerHelper = PagerHelper.this;
|
|
if (pagerHelper.h == ORIENTATION.NULL) {
|
|
return false;
|
|
}
|
|
int c = pagerHelper.c();
|
|
PagerHelper pagerHelper2 = PagerHelper.this;
|
|
if (pagerHelper2.h == ORIENTATION.VERTICAL) {
|
|
i3 = pagerHelper2.d;
|
|
if (i2 < 0) {
|
|
c--;
|
|
} else if (i2 > 0) {
|
|
c++;
|
|
}
|
|
width = c * PagerHelper.this.a.getHeight();
|
|
} else {
|
|
int i4 = pagerHelper2.e;
|
|
if (i < 0) {
|
|
c--;
|
|
} else if (i > 0) {
|
|
c++;
|
|
}
|
|
width = c * PagerHelper.this.a.getWidth();
|
|
i3 = i4;
|
|
}
|
|
if (width < 0) {
|
|
width = 0;
|
|
}
|
|
PagerHelper pagerHelper3 = PagerHelper.this;
|
|
ValueAnimator valueAnimator = pagerHelper3.i;
|
|
if (valueAnimator == null) {
|
|
new ValueAnimator();
|
|
pagerHelper3.i = ValueAnimator.ofInt(i3, width);
|
|
PagerHelper.this.i.setDuration(300L);
|
|
PagerHelper.this.i.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // from class: com.ubt.jimu.picture.pagerecyclerview.PagerHelper.MyOnFlingListener.1
|
|
@Override // android.animation.ValueAnimator.AnimatorUpdateListener
|
|
public void onAnimationUpdate(ValueAnimator valueAnimator2) {
|
|
int intValue = ((Integer) valueAnimator2.getAnimatedValue()).intValue();
|
|
PagerHelper pagerHelper4 = PagerHelper.this;
|
|
if (pagerHelper4.h == ORIENTATION.VERTICAL) {
|
|
PagerHelper.this.a.scrollBy(0, intValue - pagerHelper4.d);
|
|
} else {
|
|
PagerHelper.this.a.scrollBy(intValue - pagerHelper4.e, 0);
|
|
}
|
|
}
|
|
});
|
|
PagerHelper.this.i.addListener(new AnimatorListenerAdapter() { // from class: com.ubt.jimu.picture.pagerecyclerview.PagerHelper.MyOnFlingListener.2
|
|
@Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
|
|
public void onAnimationEnd(Animator animator) {
|
|
PagerHelper pagerHelper4 = PagerHelper.this;
|
|
onPageChangeListener onpagechangelistener = pagerHelper4.k;
|
|
if (onpagechangelistener != null) {
|
|
onpagechangelistener.a(pagerHelper4.b());
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
valueAnimator.cancel();
|
|
PagerHelper.this.i.setIntValues(i3, width);
|
|
}
|
|
PagerHelper.this.i.start();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public class MyOnTouchListener implements View.OnTouchListener {
|
|
public MyOnTouchListener() {
|
|
}
|
|
|
|
@Override // android.view.View.OnTouchListener
|
|
public boolean onTouch(View view, MotionEvent motionEvent) {
|
|
if (motionEvent.getAction() != 0) {
|
|
return false;
|
|
}
|
|
PagerHelper pagerHelper = PagerHelper.this;
|
|
pagerHelper.f = pagerHelper.d;
|
|
PagerHelper pagerHelper2 = PagerHelper.this;
|
|
pagerHelper2.g = pagerHelper2.e;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
enum ORIENTATION {
|
|
HORIZONTAL,
|
|
VERTICAL,
|
|
NULL
|
|
}
|
|
|
|
public interface onPageChangeListener {
|
|
void a(int i);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public int c() {
|
|
return this.h == ORIENTATION.VERTICAL ? this.f / this.a.getHeight() : this.g / this.a.getWidth();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public int b() {
|
|
if (this.h == ORIENTATION.VERTICAL) {
|
|
return this.d / this.a.getHeight();
|
|
}
|
|
return this.e / this.a.getWidth();
|
|
}
|
|
|
|
public void a(RecyclerView recyclerView) {
|
|
if (recyclerView != null) {
|
|
this.a = recyclerView;
|
|
recyclerView.setOnFlingListener(this.c);
|
|
recyclerView.setOnScrollListener(this.b);
|
|
recyclerView.setOnTouchListener(this.j);
|
|
a();
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("recycleView must be not null");
|
|
}
|
|
|
|
public class MyOnScrollListener extends RecyclerView.OnScrollListener {
|
|
public MyOnScrollListener() {
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.OnScrollListener
|
|
public void a(RecyclerView recyclerView, int i) {
|
|
PagerHelper pagerHelper;
|
|
ORIENTATION orientation;
|
|
if (i != 0 || (orientation = (pagerHelper = PagerHelper.this).h) == ORIENTATION.NULL) {
|
|
return;
|
|
}
|
|
ORIENTATION orientation2 = ORIENTATION.VERTICAL;
|
|
int i2 = IMediaPlayer.MEDIA_ERROR_AUTH_FAILURE;
|
|
int i3 = 0;
|
|
if (orientation == orientation2) {
|
|
if (Math.abs(pagerHelper.d - PagerHelper.this.f) > recyclerView.getHeight() / 2) {
|
|
if (PagerHelper.this.d - PagerHelper.this.f >= 0) {
|
|
i2 = 1000;
|
|
}
|
|
PagerHelper.this.c.a(i3, i2);
|
|
}
|
|
} else {
|
|
if (Math.abs(pagerHelper.e - PagerHelper.this.g) > recyclerView.getWidth() / 2) {
|
|
if (PagerHelper.this.e - PagerHelper.this.g >= 0) {
|
|
i2 = 1000;
|
|
}
|
|
i3 = i2;
|
|
}
|
|
}
|
|
i2 = 0;
|
|
PagerHelper.this.c.a(i3, i2);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.OnScrollListener
|
|
public void a(RecyclerView recyclerView, int i, int i2) {
|
|
PagerHelper.this.d += i2;
|
|
PagerHelper.this.e += i;
|
|
}
|
|
}
|
|
|
|
public void a() {
|
|
RecyclerView.LayoutManager layoutManager = this.a.getLayoutManager();
|
|
if (layoutManager != null) {
|
|
if (layoutManager.b()) {
|
|
this.h = ORIENTATION.VERTICAL;
|
|
} else if (layoutManager.a()) {
|
|
this.h = ORIENTATION.HORIZONTAL;
|
|
} else {
|
|
this.h = ORIENTATION.NULL;
|
|
}
|
|
ValueAnimator valueAnimator = this.i;
|
|
if (valueAnimator != null) {
|
|
valueAnimator.cancel();
|
|
}
|
|
this.g = 0;
|
|
this.f = 0;
|
|
this.e = 0;
|
|
this.d = 0;
|
|
}
|
|
}
|
|
|
|
public void a(onPageChangeListener onpagechangelistener) {
|
|
this.k = onpagechangelistener;
|
|
}
|
|
}
|