314 lines
9.3 KiB
Java
314 lines
9.3 KiB
Java
package com.ubt.jimu.widgets;
|
|
|
|
import android.content.Context;
|
|
import android.util.AttributeSet;
|
|
import android.view.LayoutInflater;
|
|
import android.view.MotionEvent;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.animation.Animation;
|
|
import android.view.animation.AnimationUtils;
|
|
import android.view.animation.LinearInterpolator;
|
|
import android.widget.AdapterView;
|
|
import android.widget.ImageView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.ScrollView;
|
|
import android.widget.TextView;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import com.ubt.jimu.R;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class PullRefreshLayout extends LinearLayout {
|
|
private View a;
|
|
private View b;
|
|
private TextView c;
|
|
private ImageView d;
|
|
private Context e;
|
|
private int f;
|
|
private int g;
|
|
private int h;
|
|
private int i;
|
|
private int j;
|
|
private int k;
|
|
private Status l;
|
|
private Animation m;
|
|
private ImageView n;
|
|
private boolean o;
|
|
private OnRefreshListener p;
|
|
|
|
public interface OnRefreshListener {
|
|
void a();
|
|
|
|
void b();
|
|
}
|
|
|
|
private enum Status {
|
|
NORMAL,
|
|
TRY_REFRESH,
|
|
REFRESHING,
|
|
TRY_LOADMORE,
|
|
LOADING
|
|
}
|
|
|
|
public PullRefreshLayout(Context context) {
|
|
super(context);
|
|
this.l = Status.NORMAL;
|
|
this.o = false;
|
|
}
|
|
|
|
private void a(Status status) {
|
|
this.l = status;
|
|
}
|
|
|
|
private void b() {
|
|
this.b = LayoutInflater.from(getContext()).inflate(R.layout.pull_footer, (ViewGroup) null, false);
|
|
addView(this.b, new RelativeLayout.LayoutParams(-1, -2));
|
|
this.n = (ImageView) findViewById(R.id.footer_loading);
|
|
}
|
|
|
|
private void c() {
|
|
this.a = LayoutInflater.from(getContext()).inflate(R.layout.pull_header, (ViewGroup) null, false);
|
|
addView(this.a, new RelativeLayout.LayoutParams(-1, -2));
|
|
this.c = (TextView) findViewById(R.id.header_text);
|
|
this.d = (ImageView) findViewById(R.id.header_arrow);
|
|
}
|
|
|
|
private boolean d(View view) {
|
|
if (view instanceof AdapterView) {
|
|
return b(view);
|
|
}
|
|
if (view instanceof ScrollView) {
|
|
return h(view);
|
|
}
|
|
if (view instanceof RecyclerView) {
|
|
return f(view);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private boolean e(View view) {
|
|
RecyclerView recyclerView = (RecyclerView) view;
|
|
return recyclerView.computeVerticalScrollExtent() + recyclerView.computeVerticalScrollOffset() >= recyclerView.computeVerticalScrollRange();
|
|
}
|
|
|
|
private boolean f(View view) {
|
|
return ((RecyclerView) view).computeVerticalScrollOffset() <= 0;
|
|
}
|
|
|
|
private boolean g(View view) {
|
|
ScrollView scrollView = (ScrollView) view;
|
|
return scrollView.getScrollY() >= scrollView.getChildAt(0).getHeight() - scrollView.getHeight();
|
|
}
|
|
|
|
private boolean h(View view) {
|
|
return view.getScrollY() <= 0;
|
|
}
|
|
|
|
private void i(View view) {
|
|
if (this.m == null) {
|
|
this.m = AnimationUtils.loadAnimation(this.e, R.anim.anima_dialog_wait);
|
|
}
|
|
this.m.setInterpolator(new LinearInterpolator());
|
|
view.startAnimation(this.m);
|
|
}
|
|
|
|
public void a() {
|
|
}
|
|
|
|
@Override // android.view.View
|
|
protected void onFinishInflate() {
|
|
super.onFinishInflate();
|
|
this.k = getChildCount() - 1;
|
|
c();
|
|
b();
|
|
}
|
|
|
|
@Override // android.view.ViewGroup
|
|
public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
|
|
int y = (int) motionEvent.getY();
|
|
Status status = this.l;
|
|
boolean z = false;
|
|
if (status != Status.REFRESHING && status != Status.LOADING) {
|
|
int action = motionEvent.getAction();
|
|
if (action == 0) {
|
|
this.i = y;
|
|
} else if (action != 1 && action == 2) {
|
|
int i = this.j;
|
|
if (y > i) {
|
|
z = d(getChildAt(0));
|
|
if (z) {
|
|
a(Status.TRY_REFRESH);
|
|
}
|
|
} else if (y < i && (z = c(getChildAt(this.k)))) {
|
|
a(Status.TRY_LOADMORE);
|
|
}
|
|
}
|
|
this.j = y;
|
|
}
|
|
return z;
|
|
}
|
|
|
|
@Override // android.widget.LinearLayout, android.view.ViewGroup, android.view.View
|
|
protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
|
|
this.f = 0;
|
|
for (int i5 = 0; i5 < getChildCount(); i5++) {
|
|
View childAt = getChildAt(i5);
|
|
if (childAt == this.a) {
|
|
childAt.layout(0, 0 - childAt.getMeasuredHeight(), childAt.getMeasuredWidth(), 0);
|
|
this.g = childAt.getHeight();
|
|
} else if (childAt == this.b) {
|
|
childAt.layout(0, this.f, childAt.getMeasuredWidth(), this.f + childAt.getMeasuredHeight());
|
|
this.h = childAt.getHeight();
|
|
} else {
|
|
childAt.layout(0, this.f, childAt.getMeasuredWidth(), this.f + childAt.getMeasuredHeight());
|
|
if (i5 < getChildCount()) {
|
|
if (childAt instanceof ScrollView) {
|
|
this.f += getMeasuredHeight();
|
|
} else {
|
|
this.f += childAt.getMeasuredHeight();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // android.widget.LinearLayout, android.view.View
|
|
protected void onMeasure(int i, int i2) {
|
|
super.onMeasure(i, i2);
|
|
for (int i3 = 0; i3 < getChildCount(); i3++) {
|
|
measureChild(getChildAt(i3), i, i2);
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public boolean onTouchEvent(MotionEvent motionEvent) {
|
|
int y = (int) motionEvent.getY();
|
|
Status status = this.l;
|
|
if (status == Status.REFRESHING || status == Status.LOADING) {
|
|
return true;
|
|
}
|
|
int action = motionEvent.getAction();
|
|
if (action == 0) {
|
|
this.i = y;
|
|
} else if (action != 1) {
|
|
if (action == 2) {
|
|
int i = this.i - y;
|
|
if (getScrollY() > 0 || i > 0) {
|
|
if (getScrollY() < 0 || i < 0) {
|
|
scrollBy(0, i / 3);
|
|
} else if (this.l == Status.TRY_REFRESH) {
|
|
scrollBy(0, i / 30);
|
|
} else {
|
|
scrollBy(0, i / 3);
|
|
}
|
|
} else if (this.l == Status.TRY_LOADMORE) {
|
|
scrollBy(0, i / 30);
|
|
} else {
|
|
scrollBy(0, i / 3);
|
|
}
|
|
a(i);
|
|
a();
|
|
}
|
|
} else if (getScrollY() <= (-this.g)) {
|
|
e();
|
|
OnRefreshListener onRefreshListener = this.p;
|
|
if (onRefreshListener != null) {
|
|
onRefreshListener.a();
|
|
}
|
|
} else if (getScrollY() >= 10) {
|
|
d();
|
|
OnRefreshListener onRefreshListener2 = this.p;
|
|
if (onRefreshListener2 != null) {
|
|
onRefreshListener2.b();
|
|
}
|
|
} else {
|
|
g();
|
|
f();
|
|
}
|
|
this.i = y;
|
|
return super.onTouchEvent(motionEvent);
|
|
}
|
|
|
|
public void setRefreshListener(OnRefreshListener onRefreshListener) {
|
|
this.p = onRefreshListener;
|
|
}
|
|
|
|
private boolean a(View view) {
|
|
AdapterView adapterView = (AdapterView) view;
|
|
return adapterView.getLastVisiblePosition() == adapterView.getCount() - 1 && adapterView.getChildAt(adapterView.getChildCount() - 1).getBottom() >= getMeasuredHeight();
|
|
}
|
|
|
|
private void f() {
|
|
scrollBy(0, -getScrollY());
|
|
a(Status.NORMAL);
|
|
}
|
|
|
|
public PullRefreshLayout(Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
this.l = Status.NORMAL;
|
|
this.o = false;
|
|
this.e = context;
|
|
}
|
|
|
|
private void e() {
|
|
scrollTo(0, -this.g);
|
|
this.c.setText("正在刷新");
|
|
i(this.d);
|
|
a(Status.REFRESHING);
|
|
}
|
|
|
|
private void g() {
|
|
scrollBy(0, -getScrollY());
|
|
this.c.setText("下拉刷新");
|
|
a(Status.NORMAL);
|
|
}
|
|
|
|
public void a(float f) {
|
|
int abs = Math.abs(getScrollY());
|
|
int i = this.g;
|
|
if (abs > i) {
|
|
abs = i;
|
|
}
|
|
this.d.setRotation((float) (((abs * 1.0d) / this.g) * 180.0d));
|
|
if (getScrollY() <= (-this.g)) {
|
|
this.c.setText("松开刷新");
|
|
} else {
|
|
this.c.setText("下拉刷新");
|
|
}
|
|
}
|
|
|
|
private boolean c(View view) {
|
|
if (view instanceof AdapterView) {
|
|
return a(view);
|
|
}
|
|
if (view instanceof ScrollView) {
|
|
return g(view);
|
|
}
|
|
if (view instanceof RecyclerView) {
|
|
return e(view);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private boolean b(View view) {
|
|
AdapterView adapterView = (AdapterView) view;
|
|
return adapterView.getFirstVisiblePosition() == 0 && adapterView.getChildAt(0).getTop() == 0;
|
|
}
|
|
|
|
private void d() {
|
|
scrollTo(0, this.h);
|
|
if (!this.o) {
|
|
i(this.n);
|
|
}
|
|
a(Status.LOADING);
|
|
}
|
|
|
|
public PullRefreshLayout(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
this.l = Status.NORMAL;
|
|
this.o = false;
|
|
this.e = context;
|
|
}
|
|
}
|