discord-jadx/app/src/main/java/androidx/swiperefreshlayout/widget/SwipeRefreshLayout.java

1043 lines
42 KiB
Java

package androidx.swiperefreshlayout.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Transformation;
import android.widget.ListView;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
import androidx.annotation.VisibleForTesting;
import androidx.core.content.ContextCompat;
import androidx.core.view.NestedScrollingChild;
import androidx.core.view.NestedScrollingChild2;
import androidx.core.view.NestedScrollingChild3;
import androidx.core.view.NestedScrollingChildHelper;
import androidx.core.view.NestedScrollingParent;
import androidx.core.view.NestedScrollingParent2;
import androidx.core.view.NestedScrollingParent3;
import androidx.core.view.NestedScrollingParentHelper;
import androidx.core.view.ViewCompat;
import androidx.core.widget.ListViewCompat;
public class SwipeRefreshLayout extends ViewGroup implements NestedScrollingParent3, NestedScrollingParent2, NestedScrollingChild3, NestedScrollingChild2, NestedScrollingParent, NestedScrollingChild {
private static final int ALPHA_ANIMATION_DURATION = 300;
private static final int ANIMATE_TO_START_DURATION = 200;
private static final int ANIMATE_TO_TRIGGER_DURATION = 200;
@VisibleForTesting
public static final int CIRCLE_DIAMETER = 40;
@VisibleForTesting
public static final int CIRCLE_DIAMETER_LARGE = 56;
private static final float DECELERATE_INTERPOLATION_FACTOR = 2.0f;
public static final int DEFAULT = 1;
private static final int DEFAULT_CIRCLE_TARGET = 64;
public static final int DEFAULT_SLINGSHOT_DISTANCE = -1;
private static final float DRAG_RATE = 0.5f;
private static final int INVALID_POINTER = -1;
public static final int LARGE = 0;
private static final int[] LAYOUT_ATTRS = {16842766};
private static final String LOG_TAG = SwipeRefreshLayout.class.getSimpleName();
private static final int MAX_ALPHA = 255;
private static final float MAX_PROGRESS_ANGLE = 0.8f;
private static final int SCALE_DOWN_DURATION = 150;
private static final int STARTING_PROGRESS_ALPHA = 76;
private int mActivePointerId;
private Animation mAlphaMaxAnimation;
private Animation mAlphaStartAnimation;
private final Animation mAnimateToCorrectPosition;
private final Animation mAnimateToStartPosition;
private OnChildScrollUpCallback mChildScrollUpCallback;
private int mCircleDiameter;
public CircleImageView mCircleView;
private int mCircleViewIndex;
public int mCurrentTargetOffsetTop;
public int mCustomSlingshotDistance;
private final DecelerateInterpolator mDecelerateInterpolator;
private boolean mEnableLegacyRequestDisallowInterceptTouch;
public int mFrom;
private float mInitialDownY;
private float mInitialMotionY;
private boolean mIsBeingDragged;
public OnRefreshListener mListener;
private int mMediumAnimationDuration;
private boolean mNestedScrollInProgress;
private final NestedScrollingChildHelper mNestedScrollingChildHelper;
private final NestedScrollingParentHelper mNestedScrollingParentHelper;
private final int[] mNestedScrollingV2ConsumedCompat;
public boolean mNotify;
public int mOriginalOffsetTop;
private final int[] mParentOffsetInWindow;
private final int[] mParentScrollConsumed;
public CircularProgressDrawable mProgress;
private Animation.AnimationListener mRefreshListener;
public boolean mRefreshing;
private boolean mReturningToStart;
public boolean mScale;
private Animation mScaleAnimation;
private Animation mScaleDownAnimation;
private Animation mScaleDownToStartAnimation;
public int mSpinnerOffsetEnd;
public float mStartingScale;
private View mTarget;
private float mTotalDragDistance;
private float mTotalUnconsumed;
private int mTouchSlop;
public boolean mUsingCustomStart;
/* renamed from: androidx.swiperefreshlayout.widget.SwipeRefreshLayout$1 reason: invalid class name */
public class AnonymousClass1 implements Animation.AnimationListener {
public AnonymousClass1() {
}
@Override // android.view.animation.Animation.AnimationListener
public void onAnimationEnd(Animation animation) {
OnRefreshListener onRefreshListener;
SwipeRefreshLayout swipeRefreshLayout = SwipeRefreshLayout.this;
if (swipeRefreshLayout.mRefreshing) {
swipeRefreshLayout.mProgress.setAlpha(255);
SwipeRefreshLayout.this.mProgress.start();
SwipeRefreshLayout swipeRefreshLayout2 = SwipeRefreshLayout.this;
if (swipeRefreshLayout2.mNotify && (onRefreshListener = swipeRefreshLayout2.mListener) != null) {
onRefreshListener.onRefresh();
}
SwipeRefreshLayout swipeRefreshLayout3 = SwipeRefreshLayout.this;
swipeRefreshLayout3.mCurrentTargetOffsetTop = swipeRefreshLayout3.mCircleView.getTop();
return;
}
swipeRefreshLayout.reset();
}
@Override // android.view.animation.Animation.AnimationListener
public void onAnimationRepeat(Animation animation) {
}
@Override // android.view.animation.Animation.AnimationListener
public void onAnimationStart(Animation animation) {
}
}
/* renamed from: androidx.swiperefreshlayout.widget.SwipeRefreshLayout$2 reason: invalid class name */
public class AnonymousClass2 extends Animation {
public AnonymousClass2() {
}
@Override // android.view.animation.Animation
public void applyTransformation(float f, Transformation transformation) {
SwipeRefreshLayout.this.setAnimationProgress(f);
}
}
/* renamed from: androidx.swiperefreshlayout.widget.SwipeRefreshLayout$3 reason: invalid class name */
public class AnonymousClass3 extends Animation {
public AnonymousClass3() {
}
@Override // android.view.animation.Animation
public void applyTransformation(float f, Transformation transformation) {
SwipeRefreshLayout.this.setAnimationProgress(1.0f - f);
}
}
/* renamed from: androidx.swiperefreshlayout.widget.SwipeRefreshLayout$4 reason: invalid class name */
public class AnonymousClass4 extends Animation {
public final /* synthetic */ int val$endingAlpha;
public final /* synthetic */ int val$startingAlpha;
public AnonymousClass4(int i, int i2) {
this.val$startingAlpha = i;
this.val$endingAlpha = i2;
}
@Override // android.view.animation.Animation
public void applyTransformation(float f, Transformation transformation) {
CircularProgressDrawable circularProgressDrawable = SwipeRefreshLayout.this.mProgress;
int i = this.val$startingAlpha;
circularProgressDrawable.setAlpha((int) ((((float) (this.val$endingAlpha - i)) * f) + ((float) i)));
}
}
/* renamed from: androidx.swiperefreshlayout.widget.SwipeRefreshLayout$5 reason: invalid class name */
public class AnonymousClass5 implements Animation.AnimationListener {
public AnonymousClass5() {
}
@Override // android.view.animation.Animation.AnimationListener
public void onAnimationEnd(Animation animation) {
SwipeRefreshLayout swipeRefreshLayout = SwipeRefreshLayout.this;
if (!swipeRefreshLayout.mScale) {
swipeRefreshLayout.startScaleDownAnimation(null);
}
}
@Override // android.view.animation.Animation.AnimationListener
public void onAnimationRepeat(Animation animation) {
}
@Override // android.view.animation.Animation.AnimationListener
public void onAnimationStart(Animation animation) {
}
}
/* renamed from: androidx.swiperefreshlayout.widget.SwipeRefreshLayout$6 reason: invalid class name */
public class AnonymousClass6 extends Animation {
public AnonymousClass6() {
}
@Override // android.view.animation.Animation
public void applyTransformation(float f, Transformation transformation) {
SwipeRefreshLayout swipeRefreshLayout = SwipeRefreshLayout.this;
int abs = !swipeRefreshLayout.mUsingCustomStart ? swipeRefreshLayout.mSpinnerOffsetEnd - Math.abs(swipeRefreshLayout.mOriginalOffsetTop) : swipeRefreshLayout.mSpinnerOffsetEnd;
SwipeRefreshLayout swipeRefreshLayout2 = SwipeRefreshLayout.this;
int i = swipeRefreshLayout2.mFrom;
SwipeRefreshLayout.this.setTargetOffsetTopAndBottom((i + ((int) (((float) (abs - i)) * f))) - swipeRefreshLayout2.mCircleView.getTop());
SwipeRefreshLayout.this.mProgress.setArrowScale(1.0f - f);
}
}
/* renamed from: androidx.swiperefreshlayout.widget.SwipeRefreshLayout$7 reason: invalid class name */
public class AnonymousClass7 extends Animation {
public AnonymousClass7() {
}
@Override // android.view.animation.Animation
public void applyTransformation(float f, Transformation transformation) {
SwipeRefreshLayout.this.moveToStart(f);
}
}
/* renamed from: androidx.swiperefreshlayout.widget.SwipeRefreshLayout$8 reason: invalid class name */
public class AnonymousClass8 extends Animation {
public AnonymousClass8() {
}
@Override // android.view.animation.Animation
public void applyTransformation(float f, Transformation transformation) {
SwipeRefreshLayout swipeRefreshLayout = SwipeRefreshLayout.this;
float f2 = swipeRefreshLayout.mStartingScale;
swipeRefreshLayout.setAnimationProgress(((-f2) * f) + f2);
SwipeRefreshLayout.this.moveToStart(f);
}
}
public interface OnChildScrollUpCallback {
boolean canChildScrollUp(@NonNull SwipeRefreshLayout swipeRefreshLayout, @Nullable View view);
}
public interface OnRefreshListener {
void onRefresh();
}
public static class SavedState extends View.BaseSavedState {
public static final Parcelable.Creator<SavedState> CREATOR = new AnonymousClass1();
public final boolean mRefreshing;
/* renamed from: androidx.swiperefreshlayout.widget.SwipeRefreshLayout$SavedState$1 reason: invalid class name */
public class AnonymousClass1 implements Parcelable.Creator<SavedState> {
@Override // android.os.Parcelable.Creator
public SavedState createFromParcel(Parcel parcel) {
return new SavedState(parcel);
}
@Override // android.os.Parcelable.Creator
public SavedState[] newArray(int i) {
return new SavedState[i];
}
}
public SavedState(Parcel parcel) {
super(parcel);
this.mRefreshing = parcel.readByte() != 0;
}
public SavedState(Parcelable parcelable, boolean z2) {
super(parcelable);
this.mRefreshing = z2;
}
@Override // android.view.View.BaseSavedState, android.os.Parcelable, android.view.AbsSavedState
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeByte(this.mRefreshing ? (byte) 1 : 0);
}
}
public SwipeRefreshLayout(@NonNull Context context) {
this(context, null);
}
public SwipeRefreshLayout(@NonNull Context context, @Nullable AttributeSet attributeSet) {
super(context, attributeSet);
this.mRefreshing = false;
this.mTotalDragDistance = -1.0f;
this.mParentScrollConsumed = new int[2];
this.mParentOffsetInWindow = new int[2];
this.mNestedScrollingV2ConsumedCompat = new int[2];
this.mActivePointerId = -1;
this.mCircleViewIndex = -1;
this.mRefreshListener = new AnonymousClass1();
this.mAnimateToCorrectPosition = new AnonymousClass6();
this.mAnimateToStartPosition = new AnonymousClass7();
this.mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
this.mMediumAnimationDuration = getResources().getInteger(17694721);
setWillNotDraw(false);
this.mDecelerateInterpolator = new DecelerateInterpolator(2.0f);
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
this.mCircleDiameter = (int) (displayMetrics.density * 40.0f);
createProgressView();
setChildrenDrawingOrderEnabled(true);
int i = (int) (displayMetrics.density * 64.0f);
this.mSpinnerOffsetEnd = i;
this.mTotalDragDistance = (float) i;
this.mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);
this.mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
int i2 = -this.mCircleDiameter;
this.mCurrentTargetOffsetTop = i2;
this.mOriginalOffsetTop = i2;
moveToStart(1.0f);
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, LAYOUT_ATTRS);
setEnabled(obtainStyledAttributes.getBoolean(0, true));
obtainStyledAttributes.recycle();
}
private void animateOffsetToCorrectPosition(int i, Animation.AnimationListener animationListener) {
this.mFrom = i;
this.mAnimateToCorrectPosition.reset();
this.mAnimateToCorrectPosition.setDuration(200);
this.mAnimateToCorrectPosition.setInterpolator(this.mDecelerateInterpolator);
if (animationListener != null) {
this.mCircleView.setAnimationListener(animationListener);
}
this.mCircleView.clearAnimation();
this.mCircleView.startAnimation(this.mAnimateToCorrectPosition);
}
private void animateOffsetToStartPosition(int i, Animation.AnimationListener animationListener) {
if (this.mScale) {
startScaleDownReturnToStartAnimation(i, animationListener);
return;
}
this.mFrom = i;
this.mAnimateToStartPosition.reset();
this.mAnimateToStartPosition.setDuration(200);
this.mAnimateToStartPosition.setInterpolator(this.mDecelerateInterpolator);
if (animationListener != null) {
this.mCircleView.setAnimationListener(animationListener);
}
this.mCircleView.clearAnimation();
this.mCircleView.startAnimation(this.mAnimateToStartPosition);
}
private void createProgressView() {
this.mCircleView = new CircleImageView(getContext());
CircularProgressDrawable circularProgressDrawable = new CircularProgressDrawable(getContext());
this.mProgress = circularProgressDrawable;
circularProgressDrawable.setStyle(1);
this.mCircleView.setImageDrawable(this.mProgress);
this.mCircleView.setVisibility(8);
addView(this.mCircleView);
}
private void ensureTarget() {
if (this.mTarget == null) {
for (int i = 0; i < getChildCount(); i++) {
View childAt = getChildAt(i);
if (!childAt.equals(this.mCircleView)) {
this.mTarget = childAt;
return;
}
}
}
}
private void finishSpinner(float f) {
if (f > this.mTotalDragDistance) {
setRefreshing(true, true);
return;
}
this.mRefreshing = false;
this.mProgress.setStartEndTrim(0.0f, 0.0f);
AnonymousClass5 r0 = null;
if (!this.mScale) {
r0 = new AnonymousClass5();
}
animateOffsetToStartPosition(this.mCurrentTargetOffsetTop, r0);
this.mProgress.setArrowEnabled(false);
}
private boolean isAnimationRunning(Animation animation) {
return animation != null && animation.hasStarted() && !animation.hasEnded();
}
private void moveSpinner(float f) {
this.mProgress.setArrowEnabled(true);
float min = Math.min(1.0f, Math.abs(f / this.mTotalDragDistance));
float max = (((float) Math.max(((double) min) - 0.4d, 0.0d)) * 5.0f) / 3.0f;
float abs = Math.abs(f) - this.mTotalDragDistance;
int i = this.mCustomSlingshotDistance;
if (i <= 0) {
i = this.mUsingCustomStart ? this.mSpinnerOffsetEnd - this.mOriginalOffsetTop : this.mSpinnerOffsetEnd;
}
float f2 = (float) i;
double max2 = (double) (Math.max(0.0f, Math.min(abs, f2 * 2.0f) / f2) / 4.0f);
float pow = ((float) (max2 - Math.pow(max2, 2.0d))) * 2.0f;
int i2 = this.mOriginalOffsetTop + ((int) ((f2 * min) + (f2 * pow * 2.0f)));
if (this.mCircleView.getVisibility() != 0) {
this.mCircleView.setVisibility(0);
}
if (!this.mScale) {
this.mCircleView.setScaleX(1.0f);
this.mCircleView.setScaleY(1.0f);
}
if (this.mScale) {
setAnimationProgress(Math.min(1.0f, f / this.mTotalDragDistance));
}
if (f < this.mTotalDragDistance) {
if (this.mProgress.getAlpha() > 76 && !isAnimationRunning(this.mAlphaStartAnimation)) {
startProgressAlphaStartAnimation();
}
} else if (this.mProgress.getAlpha() < 255 && !isAnimationRunning(this.mAlphaMaxAnimation)) {
startProgressAlphaMaxAnimation();
}
this.mProgress.setStartEndTrim(0.0f, Math.min(0.8f, max * 0.8f));
this.mProgress.setArrowScale(Math.min(1.0f, max));
this.mProgress.setProgressRotation(((pow * 2.0f) + ((max * 0.4f) - 16.0f)) * 0.5f);
setTargetOffsetTopAndBottom(i2 - this.mCurrentTargetOffsetTop);
}
private void onSecondaryPointerUp(MotionEvent motionEvent) {
int actionIndex = motionEvent.getActionIndex();
if (motionEvent.getPointerId(actionIndex) == this.mActivePointerId) {
this.mActivePointerId = motionEvent.getPointerId(actionIndex == 0 ? 1 : 0);
}
}
private void setColorViewAlpha(int i) {
this.mCircleView.getBackground().setAlpha(i);
this.mProgress.setAlpha(i);
}
private void setRefreshing(boolean z2, boolean z3) {
if (this.mRefreshing != z2) {
this.mNotify = z3;
ensureTarget();
this.mRefreshing = z2;
if (z2) {
animateOffsetToCorrectPosition(this.mCurrentTargetOffsetTop, this.mRefreshListener);
} else {
startScaleDownAnimation(this.mRefreshListener);
}
}
}
private Animation startAlphaAnimation(int i, int i2) {
AnonymousClass4 r0 = new AnonymousClass4(i, i2);
r0.setDuration(300);
this.mCircleView.setAnimationListener(null);
this.mCircleView.clearAnimation();
this.mCircleView.startAnimation(r0);
return r0;
}
private void startDragging(float f) {
float f2 = this.mInitialDownY;
int i = this.mTouchSlop;
if (f - f2 > ((float) i) && !this.mIsBeingDragged) {
this.mInitialMotionY = f2 + ((float) i);
this.mIsBeingDragged = true;
this.mProgress.setAlpha(76);
}
}
private void startProgressAlphaMaxAnimation() {
this.mAlphaMaxAnimation = startAlphaAnimation(this.mProgress.getAlpha(), 255);
}
private void startProgressAlphaStartAnimation() {
this.mAlphaStartAnimation = startAlphaAnimation(this.mProgress.getAlpha(), 76);
}
private void startScaleDownReturnToStartAnimation(int i, Animation.AnimationListener animationListener) {
this.mFrom = i;
this.mStartingScale = this.mCircleView.getScaleX();
AnonymousClass8 r3 = new AnonymousClass8();
this.mScaleDownToStartAnimation = r3;
r3.setDuration(150);
if (animationListener != null) {
this.mCircleView.setAnimationListener(animationListener);
}
this.mCircleView.clearAnimation();
this.mCircleView.startAnimation(this.mScaleDownToStartAnimation);
}
private void startScaleUpAnimation(Animation.AnimationListener animationListener) {
this.mCircleView.setVisibility(0);
this.mProgress.setAlpha(255);
AnonymousClass2 r0 = new AnonymousClass2();
this.mScaleAnimation = r0;
r0.setDuration((long) this.mMediumAnimationDuration);
if (animationListener != null) {
this.mCircleView.setAnimationListener(animationListener);
}
this.mCircleView.clearAnimation();
this.mCircleView.startAnimation(this.mScaleAnimation);
}
public boolean canChildScrollUp() {
OnChildScrollUpCallback onChildScrollUpCallback = this.mChildScrollUpCallback;
if (onChildScrollUpCallback != null) {
return onChildScrollUpCallback.canChildScrollUp(this, this.mTarget);
}
View view = this.mTarget;
return view instanceof ListView ? ListViewCompat.canScrollList((ListView) view, -1) : view.canScrollVertically(-1);
}
@Override // android.view.View, androidx.core.view.NestedScrollingChild
public boolean dispatchNestedFling(float f, float f2, boolean z2) {
return this.mNestedScrollingChildHelper.dispatchNestedFling(f, f2, z2);
}
@Override // android.view.View, androidx.core.view.NestedScrollingChild
public boolean dispatchNestedPreFling(float f, float f2) {
return this.mNestedScrollingChildHelper.dispatchNestedPreFling(f, f2);
}
@Override // android.view.View, androidx.core.view.NestedScrollingChild
public boolean dispatchNestedPreScroll(int i, int i2, int[] iArr, int[] iArr2) {
return this.mNestedScrollingChildHelper.dispatchNestedPreScroll(i, i2, iArr, iArr2);
}
@Override // androidx.core.view.NestedScrollingChild2
public boolean dispatchNestedPreScroll(int i, int i2, int[] iArr, int[] iArr2, int i3) {
return i3 == 0 && dispatchNestedPreScroll(i, i2, iArr, iArr2);
}
@Override // androidx.core.view.NestedScrollingChild3
public void dispatchNestedScroll(int i, int i2, int i3, int i4, @Nullable int[] iArr, int i5, @NonNull int[] iArr2) {
if (i5 == 0) {
this.mNestedScrollingChildHelper.dispatchNestedScroll(i, i2, i3, i4, iArr, i5, iArr2);
}
}
@Override // android.view.View, androidx.core.view.NestedScrollingChild
public boolean dispatchNestedScroll(int i, int i2, int i3, int i4, int[] iArr) {
return this.mNestedScrollingChildHelper.dispatchNestedScroll(i, i2, i3, i4, iArr);
}
@Override // androidx.core.view.NestedScrollingChild2
public boolean dispatchNestedScroll(int i, int i2, int i3, int i4, int[] iArr, int i5) {
return i5 == 0 && this.mNestedScrollingChildHelper.dispatchNestedScroll(i, i2, i3, i4, iArr, i5);
}
@Override // android.view.ViewGroup
public int getChildDrawingOrder(int i, int i2) {
int i3 = this.mCircleViewIndex;
return i3 < 0 ? i2 : i2 == i + -1 ? i3 : i2 >= i3 ? i2 + 1 : i2;
}
@Override // android.view.ViewGroup, androidx.core.view.NestedScrollingParent
public int getNestedScrollAxes() {
return this.mNestedScrollingParentHelper.getNestedScrollAxes();
}
public int getProgressCircleDiameter() {
return this.mCircleDiameter;
}
public int getProgressViewEndOffset() {
return this.mSpinnerOffsetEnd;
}
public int getProgressViewStartOffset() {
return this.mOriginalOffsetTop;
}
@Override // android.view.View, androidx.core.view.NestedScrollingChild
public boolean hasNestedScrollingParent() {
return this.mNestedScrollingChildHelper.hasNestedScrollingParent();
}
@Override // androidx.core.view.NestedScrollingChild2
public boolean hasNestedScrollingParent(int i) {
return i == 0 && hasNestedScrollingParent();
}
@Override // android.view.View, androidx.core.view.NestedScrollingChild
public boolean isNestedScrollingEnabled() {
return this.mNestedScrollingChildHelper.isNestedScrollingEnabled();
}
public boolean isRefreshing() {
return this.mRefreshing;
}
public void moveToStart(float f) {
int i = this.mFrom;
setTargetOffsetTopAndBottom((i + ((int) (((float) (this.mOriginalOffsetTop - i)) * f))) - this.mCircleView.getTop());
}
@Override // android.view.ViewGroup, android.view.View
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
reset();
}
@Override // android.view.ViewGroup
public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
ensureTarget();
int actionMasked = motionEvent.getActionMasked();
if (this.mReturningToStart && actionMasked == 0) {
this.mReturningToStart = false;
}
if (!isEnabled() || this.mReturningToStart || canChildScrollUp() || this.mRefreshing || this.mNestedScrollInProgress) {
return false;
}
if (actionMasked != 0) {
if (actionMasked != 1) {
if (actionMasked == 2) {
int i = this.mActivePointerId;
if (i == -1) {
Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id.");
return false;
}
int findPointerIndex = motionEvent.findPointerIndex(i);
if (findPointerIndex < 0) {
return false;
}
startDragging(motionEvent.getY(findPointerIndex));
} else if (actionMasked != 3) {
if (actionMasked == 6) {
onSecondaryPointerUp(motionEvent);
}
}
}
this.mIsBeingDragged = false;
this.mActivePointerId = -1;
} else {
setTargetOffsetTopAndBottom(this.mOriginalOffsetTop - this.mCircleView.getTop());
int pointerId = motionEvent.getPointerId(0);
this.mActivePointerId = pointerId;
this.mIsBeingDragged = false;
int findPointerIndex2 = motionEvent.findPointerIndex(pointerId);
if (findPointerIndex2 < 0) {
return false;
}
this.mInitialDownY = motionEvent.getY(findPointerIndex2);
}
return this.mIsBeingDragged;
}
@Override // android.view.ViewGroup, android.view.View
public void onLayout(boolean z2, int i, int i2, int i3, int i4) {
int measuredWidth = getMeasuredWidth();
int measuredHeight = getMeasuredHeight();
if (getChildCount() != 0) {
if (this.mTarget == null) {
ensureTarget();
}
View view = this.mTarget;
if (view != null) {
int paddingLeft = getPaddingLeft();
int paddingTop = getPaddingTop();
view.layout(paddingLeft, paddingTop, ((measuredWidth - getPaddingLeft()) - getPaddingRight()) + paddingLeft, ((measuredHeight - getPaddingTop()) - getPaddingBottom()) + paddingTop);
int measuredWidth2 = this.mCircleView.getMeasuredWidth();
int measuredHeight2 = this.mCircleView.getMeasuredHeight();
int i5 = measuredWidth / 2;
int i6 = measuredWidth2 / 2;
int i7 = this.mCurrentTargetOffsetTop;
this.mCircleView.layout(i5 - i6, i7, i5 + i6, measuredHeight2 + i7);
}
}
}
@Override // android.view.View
public void onMeasure(int i, int i2) {
super.onMeasure(i, i2);
if (this.mTarget == null) {
ensureTarget();
}
View view = this.mTarget;
if (view != null) {
view.measure(View.MeasureSpec.makeMeasureSpec((getMeasuredWidth() - getPaddingLeft()) - getPaddingRight(), 1073741824), View.MeasureSpec.makeMeasureSpec((getMeasuredHeight() - getPaddingTop()) - getPaddingBottom(), 1073741824));
this.mCircleView.measure(View.MeasureSpec.makeMeasureSpec(this.mCircleDiameter, 1073741824), View.MeasureSpec.makeMeasureSpec(this.mCircleDiameter, 1073741824));
this.mCircleViewIndex = -1;
for (int i3 = 0; i3 < getChildCount(); i3++) {
if (getChildAt(i3) == this.mCircleView) {
this.mCircleViewIndex = i3;
return;
}
}
}
}
@Override // android.view.ViewGroup, android.view.ViewParent, androidx.core.view.NestedScrollingParent
public boolean onNestedFling(View view, float f, float f2, boolean z2) {
return dispatchNestedFling(f, f2, z2);
}
@Override // android.view.ViewGroup, android.view.ViewParent, androidx.core.view.NestedScrollingParent
public boolean onNestedPreFling(View view, float f, float f2) {
return dispatchNestedPreFling(f, f2);
}
@Override // android.view.ViewGroup, android.view.ViewParent, androidx.core.view.NestedScrollingParent
public void onNestedPreScroll(View view, int i, int i2, int[] iArr) {
if (i2 > 0) {
float f = this.mTotalUnconsumed;
if (f > 0.0f) {
float f2 = (float) i2;
if (f2 > f) {
iArr[1] = (int) f;
this.mTotalUnconsumed = 0.0f;
} else {
this.mTotalUnconsumed = f - f2;
iArr[1] = i2;
}
moveSpinner(this.mTotalUnconsumed);
}
}
if (this.mUsingCustomStart && i2 > 0 && this.mTotalUnconsumed == 0.0f && Math.abs(i2 - iArr[1]) > 0) {
this.mCircleView.setVisibility(8);
}
int[] iArr2 = this.mParentScrollConsumed;
if (dispatchNestedPreScroll(i - iArr[0], i2 - iArr[1], iArr2, null)) {
iArr[0] = iArr[0] + iArr2[0];
iArr[1] = iArr[1] + iArr2[1];
}
}
@Override // androidx.core.view.NestedScrollingParent2
public void onNestedPreScroll(View view, int i, int i2, int[] iArr, int i3) {
if (i3 == 0) {
onNestedPreScroll(view, i, i2, iArr);
}
}
@Override // android.view.ViewGroup, android.view.ViewParent, androidx.core.view.NestedScrollingParent
public void onNestedScroll(View view, int i, int i2, int i3, int i4) {
onNestedScroll(view, i, i2, i3, i4, 0, this.mNestedScrollingV2ConsumedCompat);
}
@Override // androidx.core.view.NestedScrollingParent2
public void onNestedScroll(View view, int i, int i2, int i3, int i4, int i5) {
onNestedScroll(view, i, i2, i3, i4, i5, this.mNestedScrollingV2ConsumedCompat);
}
@Override // androidx.core.view.NestedScrollingParent3
public void onNestedScroll(@NonNull View view, int i, int i2, int i3, int i4, int i5, @NonNull int[] iArr) {
if (i5 == 0) {
int i6 = iArr[1];
dispatchNestedScroll(i, i2, i3, i4, this.mParentOffsetInWindow, i5, iArr);
int i7 = i4 - (iArr[1] - i6);
int i8 = i7 == 0 ? i4 + this.mParentOffsetInWindow[1] : i7;
if (i8 < 0 && !canChildScrollUp()) {
float abs = this.mTotalUnconsumed + ((float) Math.abs(i8));
this.mTotalUnconsumed = abs;
moveSpinner(abs);
iArr[1] = iArr[1] + i7;
}
}
}
@Override // android.view.ViewGroup, android.view.ViewParent, androidx.core.view.NestedScrollingParent
public void onNestedScrollAccepted(View view, View view2, int i) {
this.mNestedScrollingParentHelper.onNestedScrollAccepted(view, view2, i);
startNestedScroll(i & 2);
this.mTotalUnconsumed = 0.0f;
this.mNestedScrollInProgress = true;
}
@Override // androidx.core.view.NestedScrollingParent2
public void onNestedScrollAccepted(View view, View view2, int i, int i2) {
if (i2 == 0) {
onNestedScrollAccepted(view, view2, i);
}
}
@Override // android.view.View
public void onRestoreInstanceState(Parcelable parcelable) {
SavedState savedState = (SavedState) parcelable;
super.onRestoreInstanceState(savedState.getSuperState());
setRefreshing(savedState.mRefreshing);
}
@Override // android.view.View
public Parcelable onSaveInstanceState() {
return new SavedState(super.onSaveInstanceState(), this.mRefreshing);
}
@Override // android.view.ViewGroup, android.view.ViewParent, androidx.core.view.NestedScrollingParent
public boolean onStartNestedScroll(View view, View view2, int i) {
return isEnabled() && !this.mReturningToStart && !this.mRefreshing && (i & 2) != 0;
}
@Override // androidx.core.view.NestedScrollingParent2
public boolean onStartNestedScroll(View view, View view2, int i, int i2) {
if (i2 == 0) {
return onStartNestedScroll(view, view2, i);
}
return false;
}
@Override // android.view.ViewGroup, android.view.ViewParent, androidx.core.view.NestedScrollingParent
public void onStopNestedScroll(View view) {
this.mNestedScrollingParentHelper.onStopNestedScroll(view);
this.mNestedScrollInProgress = false;
float f = this.mTotalUnconsumed;
if (f > 0.0f) {
finishSpinner(f);
this.mTotalUnconsumed = 0.0f;
}
stopNestedScroll();
}
@Override // androidx.core.view.NestedScrollingParent2
public void onStopNestedScroll(View view, int i) {
if (i == 0) {
onStopNestedScroll(view);
}
}
@Override // android.view.View
public boolean onTouchEvent(MotionEvent motionEvent) {
int actionMasked = motionEvent.getActionMasked();
if (this.mReturningToStart && actionMasked == 0) {
this.mReturningToStart = false;
}
if (!isEnabled() || this.mReturningToStart || canChildScrollUp() || this.mRefreshing || this.mNestedScrollInProgress) {
return false;
}
if (actionMasked == 0) {
this.mActivePointerId = motionEvent.getPointerId(0);
this.mIsBeingDragged = false;
} else if (actionMasked == 1) {
int findPointerIndex = motionEvent.findPointerIndex(this.mActivePointerId);
if (findPointerIndex < 0) {
Log.e(LOG_TAG, "Got ACTION_UP event but don't have an active pointer id.");
return false;
}
if (this.mIsBeingDragged) {
this.mIsBeingDragged = false;
finishSpinner((motionEvent.getY(findPointerIndex) - this.mInitialMotionY) * 0.5f);
}
this.mActivePointerId = -1;
return false;
} else if (actionMasked == 2) {
int findPointerIndex2 = motionEvent.findPointerIndex(this.mActivePointerId);
if (findPointerIndex2 < 0) {
Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id.");
return false;
}
float y2 = motionEvent.getY(findPointerIndex2);
startDragging(y2);
if (this.mIsBeingDragged) {
float f = (y2 - this.mInitialMotionY) * 0.5f;
if (f <= 0.0f) {
return false;
}
getParent().requestDisallowInterceptTouchEvent(true);
moveSpinner(f);
}
} else if (actionMasked == 3) {
return false;
} else {
if (actionMasked == 5) {
int actionIndex = motionEvent.getActionIndex();
if (actionIndex < 0) {
Log.e(LOG_TAG, "Got ACTION_POINTER_DOWN event but have an invalid action index.");
return false;
}
this.mActivePointerId = motionEvent.getPointerId(actionIndex);
} else if (actionMasked == 6) {
onSecondaryPointerUp(motionEvent);
}
}
return true;
}
@Override // android.view.ViewGroup, android.view.ViewParent
public void requestDisallowInterceptTouchEvent(boolean z2) {
ViewParent parent;
View view = this.mTarget;
if (view == null || ViewCompat.isNestedScrollingEnabled(view)) {
super.requestDisallowInterceptTouchEvent(z2);
} else if (!this.mEnableLegacyRequestDisallowInterceptTouch && (parent = getParent()) != null) {
parent.requestDisallowInterceptTouchEvent(z2);
}
}
public void reset() {
this.mCircleView.clearAnimation();
this.mProgress.stop();
this.mCircleView.setVisibility(8);
setColorViewAlpha(255);
if (this.mScale) {
setAnimationProgress(0.0f);
} else {
setTargetOffsetTopAndBottom(this.mOriginalOffsetTop - this.mCurrentTargetOffsetTop);
}
this.mCurrentTargetOffsetTop = this.mCircleView.getTop();
}
public void setAnimationProgress(float f) {
this.mCircleView.setScaleX(f);
this.mCircleView.setScaleY(f);
}
@Deprecated
public void setColorScheme(@ColorRes int... iArr) {
setColorSchemeResources(iArr);
}
public void setColorSchemeColors(@ColorInt int... iArr) {
ensureTarget();
this.mProgress.setColorSchemeColors(iArr);
}
public void setColorSchemeResources(@ColorRes int... iArr) {
Context context = getContext();
int[] iArr2 = new int[iArr.length];
for (int i = 0; i < iArr.length; i++) {
iArr2[i] = ContextCompat.getColor(context, iArr[i]);
}
setColorSchemeColors(iArr2);
}
public void setDistanceToTriggerSync(int i) {
this.mTotalDragDistance = (float) i;
}
@Override // android.view.View
public void setEnabled(boolean z2) {
super.setEnabled(z2);
if (!z2) {
reset();
}
}
@Deprecated
public void setLegacyRequestDisallowInterceptTouchEventEnabled(boolean z2) {
this.mEnableLegacyRequestDisallowInterceptTouch = z2;
}
@Override // android.view.View, androidx.core.view.NestedScrollingChild
public void setNestedScrollingEnabled(boolean z2) {
this.mNestedScrollingChildHelper.setNestedScrollingEnabled(z2);
}
public void setOnChildScrollUpCallback(@Nullable OnChildScrollUpCallback onChildScrollUpCallback) {
this.mChildScrollUpCallback = onChildScrollUpCallback;
}
public void setOnRefreshListener(@Nullable OnRefreshListener onRefreshListener) {
this.mListener = onRefreshListener;
}
@Deprecated
public void setProgressBackgroundColor(int i) {
setProgressBackgroundColorSchemeResource(i);
}
public void setProgressBackgroundColorSchemeColor(@ColorInt int i) {
this.mCircleView.setBackgroundColor(i);
}
public void setProgressBackgroundColorSchemeResource(@ColorRes int i) {
setProgressBackgroundColorSchemeColor(ContextCompat.getColor(getContext(), i));
}
public void setProgressViewEndTarget(boolean z2, int i) {
this.mSpinnerOffsetEnd = i;
this.mScale = z2;
this.mCircleView.invalidate();
}
public void setProgressViewOffset(boolean z2, int i, int i2) {
this.mScale = z2;
this.mOriginalOffsetTop = i;
this.mSpinnerOffsetEnd = i2;
this.mUsingCustomStart = true;
reset();
this.mRefreshing = false;
}
public void setRefreshing(boolean z2) {
if (!z2 || this.mRefreshing == z2) {
setRefreshing(z2, false);
return;
}
this.mRefreshing = z2;
setTargetOffsetTopAndBottom((!this.mUsingCustomStart ? this.mSpinnerOffsetEnd + this.mOriginalOffsetTop : this.mSpinnerOffsetEnd) - this.mCurrentTargetOffsetTop);
this.mNotify = false;
startScaleUpAnimation(this.mRefreshListener);
}
public void setSize(int i) {
if (i == 0 || i == 1) {
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
if (i == 0) {
this.mCircleDiameter = (int) (displayMetrics.density * 56.0f);
} else {
this.mCircleDiameter = (int) (displayMetrics.density * 40.0f);
}
this.mCircleView.setImageDrawable(null);
this.mProgress.setStyle(i);
this.mCircleView.setImageDrawable(this.mProgress);
}
}
public void setSlingshotDistance(@Px int i) {
this.mCustomSlingshotDistance = i;
}
public void setTargetOffsetTopAndBottom(int i) {
this.mCircleView.bringToFront();
ViewCompat.offsetTopAndBottom(this.mCircleView, i);
this.mCurrentTargetOffsetTop = this.mCircleView.getTop();
}
@Override // android.view.View, androidx.core.view.NestedScrollingChild
public boolean startNestedScroll(int i) {
return this.mNestedScrollingChildHelper.startNestedScroll(i);
}
@Override // androidx.core.view.NestedScrollingChild2
public boolean startNestedScroll(int i, int i2) {
return i2 == 0 && startNestedScroll(i);
}
public void startScaleDownAnimation(Animation.AnimationListener animationListener) {
AnonymousClass3 r0 = new AnonymousClass3();
this.mScaleDownAnimation = r0;
r0.setDuration(150);
this.mCircleView.setAnimationListener(animationListener);
this.mCircleView.clearAnimation();
this.mCircleView.startAnimation(this.mScaleDownAnimation);
}
@Override // android.view.View, androidx.core.view.NestedScrollingChild
public void stopNestedScroll() {
this.mNestedScrollingChildHelper.stopNestedScroll();
}
@Override // androidx.core.view.NestedScrollingChild2
public void stopNestedScroll(int i) {
if (i == 0) {
stopNestedScroll();
}
}
}