432 lines
16 KiB
Java
432 lines
16 KiB
Java
|
package com.asksira.loopingviewpager;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.content.res.TypedArray;
|
||
|
import android.os.Handler;
|
||
|
import android.util.AttributeSet;
|
||
|
import android.view.View;
|
||
|
import androidx.viewpager.widget.ViewPager;
|
||
|
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
||
|
import java.util.List;
|
||
|
import o.BjL;
|
||
|
import o.Joe;
|
||
|
import o.WYJ;
|
||
|
|
||
|
/* loaded from: classes.dex */
|
||
|
public class LoopingViewPager extends ViewPager {
|
||
|
public Handler a;
|
||
|
public int b;
|
||
|
public Runnable c;
|
||
|
protected boolean d;
|
||
|
protected boolean e;
|
||
|
private float f;
|
||
|
private boolean g;
|
||
|
private boolean h;
|
||
|
private IeS i;
|
||
|
private int j;
|
||
|
private int l;
|
||
|
private int m;
|
||
|
private boolean n;
|
||
|
|
||
|
/* renamed from: o, reason: collision with root package name */
|
||
|
private int f6399o;
|
||
|
|
||
|
/* loaded from: classes.dex */
|
||
|
public interface IeS {
|
||
|
}
|
||
|
|
||
|
static /* synthetic */ int c(LoopingViewPager loopingViewPager) {
|
||
|
int i = loopingViewPager.j;
|
||
|
loopingViewPager.j = i + 1;
|
||
|
return i;
|
||
|
}
|
||
|
|
||
|
public LoopingViewPager(Context context) {
|
||
|
super(context);
|
||
|
this.d = true;
|
||
|
this.e = false;
|
||
|
this.n = true;
|
||
|
this.b = 5000;
|
||
|
this.f6399o = 0;
|
||
|
this.j = 0;
|
||
|
this.a = new Handler();
|
||
|
this.c = new Runnable(this) { // from class: com.asksira.loopingviewpager.LoopingViewPager.5
|
||
|
private LoopingViewPager d;
|
||
|
|
||
|
{
|
||
|
this.d = this;
|
||
|
}
|
||
|
|
||
|
@Override // java.lang.Runnable
|
||
|
public final void run() {
|
||
|
if (this.d.getAdapter() == null || !this.d.e || this.d.getAdapter().getCount() < 2) {
|
||
|
return;
|
||
|
}
|
||
|
if (!this.d.d && this.d.getAdapter().getCount() - 1 == this.d.j) {
|
||
|
this.d.j = 0;
|
||
|
} else {
|
||
|
LoopingViewPager.c(this.d);
|
||
|
}
|
||
|
LoopingViewPager loopingViewPager = this.d;
|
||
|
loopingViewPager.setCurrentItem(loopingViewPager.j, true);
|
||
|
}
|
||
|
};
|
||
|
this.m = 0;
|
||
|
this.l = 0;
|
||
|
this.h = true;
|
||
|
this.g = false;
|
||
|
addOnPageChangeListener(new ViewPager.ojQ(this) { // from class: com.asksira.loopingviewpager.LoopingViewPager.4
|
||
|
private LoopingViewPager a;
|
||
|
private float c;
|
||
|
|
||
|
{
|
||
|
this.a = this;
|
||
|
}
|
||
|
|
||
|
@Override // androidx.viewpager.widget.ViewPager.ojQ
|
||
|
public final void onPageScrolled(int i, float f, int i2) {
|
||
|
float f2;
|
||
|
float f3;
|
||
|
if (this.a.i == null) {
|
||
|
return;
|
||
|
}
|
||
|
float f4 = i;
|
||
|
if (f4 + f >= this.c) {
|
||
|
this.a.h = true;
|
||
|
} else {
|
||
|
this.a.h = false;
|
||
|
}
|
||
|
if (f == BitmapDescriptorFactory.HUE_RED) {
|
||
|
this.c = f4;
|
||
|
}
|
||
|
LoopingViewPager loopingViewPager = this.a;
|
||
|
int d = loopingViewPager.d(loopingViewPager.h);
|
||
|
if (this.a.l != 2 || Math.abs(this.a.j - this.a.f6399o) <= 1) {
|
||
|
if (!this.a.h) {
|
||
|
f = 1.0f - f;
|
||
|
}
|
||
|
} else {
|
||
|
int abs = Math.abs(this.a.j - this.a.f6399o);
|
||
|
if (this.a.h) {
|
||
|
f2 = abs;
|
||
|
f3 = (i - this.a.f6399o) / f2;
|
||
|
} else {
|
||
|
f2 = abs;
|
||
|
f3 = (this.a.f6399o - (i + 1)) / f2;
|
||
|
f = 1.0f - f;
|
||
|
}
|
||
|
f = (f / f2) + f3;
|
||
|
}
|
||
|
if (f == BitmapDescriptorFactory.HUE_RED || f > 1.0f) {
|
||
|
return;
|
||
|
}
|
||
|
if (this.a.g) {
|
||
|
if (this.a.l != 1) {
|
||
|
return;
|
||
|
}
|
||
|
IeS unused = this.a.i;
|
||
|
return;
|
||
|
}
|
||
|
if (this.a.l == 1) {
|
||
|
if (this.a.h && Math.abs(d - this.a.j) == 2) {
|
||
|
return;
|
||
|
}
|
||
|
if (!this.a.h && d == this.a.j) {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
IeS unused2 = this.a.i;
|
||
|
}
|
||
|
|
||
|
@Override // androidx.viewpager.widget.ViewPager.ojQ
|
||
|
public final void onPageSelected(int i) {
|
||
|
LoopingViewPager loopingViewPager = this.a;
|
||
|
loopingViewPager.f6399o = loopingViewPager.j;
|
||
|
this.a.j = i;
|
||
|
if (this.a.i != null) {
|
||
|
IeS unused = this.a.i;
|
||
|
this.a.e();
|
||
|
}
|
||
|
this.a.a.removeCallbacks(this.a.c);
|
||
|
this.a.a.postDelayed(this.a.c, this.a.b);
|
||
|
}
|
||
|
|
||
|
@Override // androidx.viewpager.widget.ViewPager.ojQ
|
||
|
public final void onPageScrollStateChanged(int i) {
|
||
|
int count;
|
||
|
if (!this.a.g && this.a.l == 2 && i == 1 && this.a.i != null) {
|
||
|
IeS unused = this.a.i;
|
||
|
LoopingViewPager loopingViewPager = this.a;
|
||
|
loopingViewPager.d(loopingViewPager.h);
|
||
|
}
|
||
|
LoopingViewPager loopingViewPager2 = this.a;
|
||
|
loopingViewPager2.m = loopingViewPager2.l;
|
||
|
this.a.l = i;
|
||
|
if (i == 0) {
|
||
|
if (this.a.d) {
|
||
|
if (this.a.getAdapter() == null || (count = this.a.getAdapter().getCount()) < 2) {
|
||
|
return;
|
||
|
}
|
||
|
int currentItem = this.a.getCurrentItem();
|
||
|
if (currentItem == 0) {
|
||
|
this.a.setCurrentItem(count - 2, false);
|
||
|
} else if (currentItem == count - 1) {
|
||
|
this.a.setCurrentItem(1, false);
|
||
|
}
|
||
|
}
|
||
|
if (this.a.i != null) {
|
||
|
IeS unused2 = this.a.i;
|
||
|
this.a.e();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
if (this.d) {
|
||
|
setCurrentItem(1, false);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public LoopingViewPager(Context context, AttributeSet attributeSet) {
|
||
|
super(context, attributeSet);
|
||
|
this.d = true;
|
||
|
this.e = false;
|
||
|
this.n = true;
|
||
|
this.b = 5000;
|
||
|
this.f6399o = 0;
|
||
|
this.j = 0;
|
||
|
this.a = new Handler();
|
||
|
this.c = new Runnable(this) { // from class: com.asksira.loopingviewpager.LoopingViewPager.5
|
||
|
private LoopingViewPager d;
|
||
|
|
||
|
{
|
||
|
this.d = this;
|
||
|
}
|
||
|
|
||
|
@Override // java.lang.Runnable
|
||
|
public final void run() {
|
||
|
if (this.d.getAdapter() == null || !this.d.e || this.d.getAdapter().getCount() < 2) {
|
||
|
return;
|
||
|
}
|
||
|
if (!this.d.d && this.d.getAdapter().getCount() - 1 == this.d.j) {
|
||
|
this.d.j = 0;
|
||
|
} else {
|
||
|
LoopingViewPager.c(this.d);
|
||
|
}
|
||
|
LoopingViewPager loopingViewPager = this.d;
|
||
|
loopingViewPager.setCurrentItem(loopingViewPager.j, true);
|
||
|
}
|
||
|
};
|
||
|
this.m = 0;
|
||
|
this.l = 0;
|
||
|
this.h = true;
|
||
|
this.g = false;
|
||
|
TypedArray obtainStyledAttributes = context.getTheme().obtainStyledAttributes(attributeSet, Joe.RVV.LoopingViewPager, 0, 0);
|
||
|
try {
|
||
|
this.d = obtainStyledAttributes.getBoolean(Joe.RVV.LoopingViewPager_isInfinite, false);
|
||
|
this.e = obtainStyledAttributes.getBoolean(Joe.RVV.LoopingViewPager_autoScroll, false);
|
||
|
this.n = obtainStyledAttributes.getBoolean(Joe.RVV.LoopingViewPager_wrap_content, true);
|
||
|
this.b = obtainStyledAttributes.getInt(Joe.RVV.LoopingViewPager_scrollInterval, 5000);
|
||
|
this.f = obtainStyledAttributes.getFloat(Joe.RVV.LoopingViewPager_viewpagerAspectRatio, BitmapDescriptorFactory.HUE_RED);
|
||
|
obtainStyledAttributes.recycle();
|
||
|
addOnPageChangeListener(new ViewPager.ojQ(this) { // from class: com.asksira.loopingviewpager.LoopingViewPager.4
|
||
|
private LoopingViewPager a;
|
||
|
private float c;
|
||
|
|
||
|
{
|
||
|
this.a = this;
|
||
|
}
|
||
|
|
||
|
@Override // androidx.viewpager.widget.ViewPager.ojQ
|
||
|
public final void onPageScrolled(int i, float f, int i2) {
|
||
|
float f2;
|
||
|
float f3;
|
||
|
if (this.a.i == null) {
|
||
|
return;
|
||
|
}
|
||
|
float f4 = i;
|
||
|
if (f4 + f >= this.c) {
|
||
|
this.a.h = true;
|
||
|
} else {
|
||
|
this.a.h = false;
|
||
|
}
|
||
|
if (f == BitmapDescriptorFactory.HUE_RED) {
|
||
|
this.c = f4;
|
||
|
}
|
||
|
LoopingViewPager loopingViewPager = this.a;
|
||
|
int d = loopingViewPager.d(loopingViewPager.h);
|
||
|
if (this.a.l != 2 || Math.abs(this.a.j - this.a.f6399o) <= 1) {
|
||
|
if (!this.a.h) {
|
||
|
f = 1.0f - f;
|
||
|
}
|
||
|
} else {
|
||
|
int abs = Math.abs(this.a.j - this.a.f6399o);
|
||
|
if (this.a.h) {
|
||
|
f2 = abs;
|
||
|
f3 = (i - this.a.f6399o) / f2;
|
||
|
} else {
|
||
|
f2 = abs;
|
||
|
f3 = (this.a.f6399o - (i + 1)) / f2;
|
||
|
f = 1.0f - f;
|
||
|
}
|
||
|
f = (f / f2) + f3;
|
||
|
}
|
||
|
if (f == BitmapDescriptorFactory.HUE_RED || f > 1.0f) {
|
||
|
return;
|
||
|
}
|
||
|
if (this.a.g) {
|
||
|
if (this.a.l != 1) {
|
||
|
return;
|
||
|
}
|
||
|
IeS unused = this.a.i;
|
||
|
return;
|
||
|
}
|
||
|
if (this.a.l == 1) {
|
||
|
if (this.a.h && Math.abs(d - this.a.j) == 2) {
|
||
|
return;
|
||
|
}
|
||
|
if (!this.a.h && d == this.a.j) {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
IeS unused2 = this.a.i;
|
||
|
}
|
||
|
|
||
|
@Override // androidx.viewpager.widget.ViewPager.ojQ
|
||
|
public final void onPageSelected(int i) {
|
||
|
LoopingViewPager loopingViewPager = this.a;
|
||
|
loopingViewPager.f6399o = loopingViewPager.j;
|
||
|
this.a.j = i;
|
||
|
if (this.a.i != null) {
|
||
|
IeS unused = this.a.i;
|
||
|
this.a.e();
|
||
|
}
|
||
|
this.a.a.removeCallbacks(this.a.c);
|
||
|
this.a.a.postDelayed(this.a.c, this.a.b);
|
||
|
}
|
||
|
|
||
|
@Override // androidx.viewpager.widget.ViewPager.ojQ
|
||
|
public final void onPageScrollStateChanged(int i) {
|
||
|
int count;
|
||
|
if (!this.a.g && this.a.l == 2 && i == 1 && this.a.i != null) {
|
||
|
IeS unused = this.a.i;
|
||
|
LoopingViewPager loopingViewPager = this.a;
|
||
|
loopingViewPager.d(loopingViewPager.h);
|
||
|
}
|
||
|
LoopingViewPager loopingViewPager2 = this.a;
|
||
|
loopingViewPager2.m = loopingViewPager2.l;
|
||
|
this.a.l = i;
|
||
|
if (i == 0) {
|
||
|
if (this.a.d) {
|
||
|
if (this.a.getAdapter() == null || (count = this.a.getAdapter().getCount()) < 2) {
|
||
|
return;
|
||
|
}
|
||
|
int currentItem = this.a.getCurrentItem();
|
||
|
if (currentItem == 0) {
|
||
|
this.a.setCurrentItem(count - 2, false);
|
||
|
} else if (currentItem == count - 1) {
|
||
|
this.a.setCurrentItem(1, false);
|
||
|
}
|
||
|
}
|
||
|
if (this.a.i != null) {
|
||
|
IeS unused2 = this.a.i;
|
||
|
this.a.e();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
if (this.d) {
|
||
|
setCurrentItem(1, false);
|
||
|
}
|
||
|
} catch (Throwable th) {
|
||
|
obtainStyledAttributes.recycle();
|
||
|
throw th;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // androidx.viewpager.widget.ViewPager, android.view.View
|
||
|
public void onMeasure(int i, int i2) {
|
||
|
int mode;
|
||
|
int size = View.MeasureSpec.getSize(i);
|
||
|
if (this.f > BitmapDescriptorFactory.HUE_RED) {
|
||
|
super.onMeasure(View.MeasureSpec.makeMeasureSpec(size, 1073741824), View.MeasureSpec.makeMeasureSpec(Math.round(View.MeasureSpec.getSize(i) / this.f), 1073741824));
|
||
|
return;
|
||
|
}
|
||
|
if (this.n && ((mode = View.MeasureSpec.getMode(i2)) == 0 || mode == Integer.MIN_VALUE)) {
|
||
|
super.onMeasure(i, i2);
|
||
|
int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec((size - getPaddingLeft()) - getPaddingRight(), 1073741824);
|
||
|
int i3 = 0;
|
||
|
for (int i4 = 0; i4 < getChildCount(); i4++) {
|
||
|
View childAt = getChildAt(i4);
|
||
|
childAt.measure(makeMeasureSpec, View.MeasureSpec.makeMeasureSpec(0, 0));
|
||
|
int measuredHeight = childAt.getMeasuredHeight();
|
||
|
if (measuredHeight > i3) {
|
||
|
i3 = measuredHeight;
|
||
|
}
|
||
|
}
|
||
|
i2 = View.MeasureSpec.makeMeasureSpec(i3 + getPaddingTop() + getPaddingBottom(), 1073741824);
|
||
|
}
|
||
|
super.onMeasure(i, i2);
|
||
|
}
|
||
|
|
||
|
@Override // androidx.viewpager.widget.ViewPager
|
||
|
public void setAdapter(WYJ wyj) {
|
||
|
super.setAdapter(wyj);
|
||
|
if (this.d) {
|
||
|
setCurrentItem(1, false);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final int e() {
|
||
|
if (this.d && (getAdapter() instanceof BjL)) {
|
||
|
int i = this.j;
|
||
|
int i2 = 0;
|
||
|
if (i == 0) {
|
||
|
List<T> list = ((BjL) getAdapter()).a;
|
||
|
if (list != 0) {
|
||
|
i2 = list.size();
|
||
|
}
|
||
|
} else {
|
||
|
if (i == ((BjL) getAdapter()).c() + 1) {
|
||
|
return 0;
|
||
|
}
|
||
|
i2 = this.j;
|
||
|
}
|
||
|
return i2 - 1;
|
||
|
}
|
||
|
return this.j;
|
||
|
}
|
||
|
|
||
|
public final int d(boolean z) {
|
||
|
int i = this.l;
|
||
|
if (i == 2 || i == 0 || (this.m == 2 && i == 1)) {
|
||
|
return e();
|
||
|
}
|
||
|
int i2 = z ? 1 : -1;
|
||
|
if (this.d && (getAdapter() instanceof BjL)) {
|
||
|
int i3 = this.j;
|
||
|
if (i3 == 1 && !z) {
|
||
|
return ((BjL) getAdapter()).c() - 1;
|
||
|
}
|
||
|
if (i3 == ((BjL) getAdapter()).c() && z) {
|
||
|
return 0;
|
||
|
}
|
||
|
return (this.j + i2) - 1;
|
||
|
}
|
||
|
return this.j + i2;
|
||
|
}
|
||
|
|
||
|
public void setInterval(int i) {
|
||
|
this.b = i;
|
||
|
this.a.removeCallbacks(this.c);
|
||
|
this.a.postDelayed(this.c, this.b);
|
||
|
}
|
||
|
|
||
|
public void setIndicatorSmart(boolean z) {
|
||
|
this.g = z;
|
||
|
}
|
||
|
|
||
|
public void setIndicatorPageChangeListener(IeS ieS) {
|
||
|
this.i = ieS;
|
||
|
}
|
||
|
}
|