package androidx.swiperefreshlayout.widget; import android.R; import android.content.Context; import android.content.res.TypedArray; 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.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.NestedScrollingChildHelper; import androidx.core.view.NestedScrollingParent; import androidx.core.view.NestedScrollingParentHelper; import androidx.core.view.ViewCompat; import androidx.core.widget.ListViewCompat; /* loaded from: classes.dex */ public class SwipeRefreshLayout extends ViewGroup implements 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; private static final int CIRCLE_BG_LIGHT = -328966; @VisibleForTesting static final int CIRCLE_DIAMETER = 40; @VisibleForTesting 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 = {R.attr.enabled}; private static final String LOG_TAG = "SwipeRefreshLayout"; 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; CircleImageView mCircleView; private int mCircleViewIndex; int mCurrentTargetOffsetTop; int mCustomSlingshotDistance; private final DecelerateInterpolator mDecelerateInterpolator; protected int mFrom; private float mInitialDownY; private float mInitialMotionY; private boolean mIsBeingDragged; OnRefreshListener mListener; private int mMediumAnimationDuration; private boolean mNestedScrollInProgress; private final NestedScrollingChildHelper mNestedScrollingChildHelper; private final NestedScrollingParentHelper mNestedScrollingParentHelper; boolean mNotify; protected int mOriginalOffsetTop; private final int[] mParentOffsetInWindow; private final int[] mParentScrollConsumed; CircularProgressDrawable mProgress; private Animation.AnimationListener mRefreshListener; boolean mRefreshing; private boolean mReturningToStart; boolean mScale; private Animation mScaleAnimation; private Animation mScaleDownAnimation; private Animation mScaleDownToStartAnimation; int mSpinnerOffsetEnd; float mStartingScale; private View mTarget; private float mTotalDragDistance; private float mTotalUnconsumed; private int mTouchSlop; boolean mUsingCustomStart; public interface OnChildScrollUpCallback { boolean canChildScrollUp(@NonNull SwipeRefreshLayout swipeRefreshLayout, @Nullable View view); } public interface OnRefreshListener { void onRefresh(); } @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; } public int getProgressCircleDiameter() { return this.mCircleDiameter; } public int getProgressViewEndOffset() { return this.mSpinnerOffsetEnd; } public int getProgressViewStartOffset() { return this.mOriginalOffsetTop; } public boolean isRefreshing() { return this.mRefreshing; } public void setDistanceToTriggerSync(int i) { this.mTotalDragDistance = i; } public void setOnChildScrollUpCallback(@Nullable OnChildScrollUpCallback onChildScrollUpCallback) { this.mChildScrollUpCallback = onChildScrollUpCallback; } public void setOnRefreshListener(@Nullable OnRefreshListener onRefreshListener) { this.mListener = onRefreshListener; } public void setSlingshotDistance(@Px int i) { this.mCustomSlingshotDistance = i; } 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(); } @Override // android.view.View public void setEnabled(boolean z) { super.setEnabled(z); if (z) { return; } reset(); } @Override // android.view.ViewGroup, android.view.View public void onDetachedFromWindow() { super.onDetachedFromWindow(); reset(); } private void setColorViewAlpha(int i) { this.mCircleView.getBackground().setAlpha(i); this.mProgress.setAlpha(i); } public void setProgressViewOffset(boolean z, int i, int i2) { this.mScale = z; this.mOriginalOffsetTop = i; this.mSpinnerOffsetEnd = i2; this.mUsingCustomStart = true; reset(); this.mRefreshing = false; } public void setProgressViewEndTarget(boolean z, int i) { this.mSpinnerOffsetEnd = i; this.mScale = z; this.mCircleView.invalidate(); } 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 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.mActivePointerId = -1; this.mCircleViewIndex = -1; this.mRefreshListener = new Animation.AnimationListener() { // from class: androidx.swiperefreshlayout.widget.SwipeRefreshLayout.1 @Override // android.view.animation.Animation.AnimationListener public void onAnimationRepeat(Animation animation) { } @Override // android.view.animation.Animation.AnimationListener public void onAnimationStart(Animation animation) { } @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(); } }; this.mAnimateToCorrectPosition = new Animation() { // from class: androidx.swiperefreshlayout.widget.SwipeRefreshLayout.6 @Override // android.view.animation.Animation public void applyTransformation(float f, Transformation transformation) { int i; SwipeRefreshLayout swipeRefreshLayout = SwipeRefreshLayout.this; if (!swipeRefreshLayout.mUsingCustomStart) { i = swipeRefreshLayout.mSpinnerOffsetEnd - Math.abs(swipeRefreshLayout.mOriginalOffsetTop); } else { i = swipeRefreshLayout.mSpinnerOffsetEnd; } SwipeRefreshLayout swipeRefreshLayout2 = SwipeRefreshLayout.this; SwipeRefreshLayout.this.setTargetOffsetTopAndBottom((swipeRefreshLayout2.mFrom + ((int) ((i - r1) * f))) - swipeRefreshLayout2.mCircleView.getTop()); SwipeRefreshLayout.this.mProgress.setArrowScale(1.0f - f); } }; this.mAnimateToStartPosition = new Animation() { // from class: androidx.swiperefreshlayout.widget.SwipeRefreshLayout.7 @Override // android.view.animation.Animation public void applyTransformation(float f, Transformation transformation) { SwipeRefreshLayout.this.moveToStart(f); } }; this.mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); this.mMediumAnimationDuration = getResources().getInteger(R.integer.config_mediumAnimTime); 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 = 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 createProgressView() { this.mCircleView = new CircleImageView(getContext(), CIRCLE_BG_LIGHT); CircularProgressDrawable circularProgressDrawable = new CircularProgressDrawable(getContext()); this.mProgress = circularProgressDrawable; circularProgressDrawable.setStyle(1); this.mCircleView.setImageDrawable(this.mProgress); this.mCircleView.setVisibility(8); addView(this.mCircleView); } public void setRefreshing(boolean z) { if (z && this.mRefreshing != z) { this.mRefreshing = z; setTargetOffsetTopAndBottom((!this.mUsingCustomStart ? this.mSpinnerOffsetEnd + this.mOriginalOffsetTop : this.mSpinnerOffsetEnd) - this.mCurrentTargetOffsetTop); this.mNotify = false; startScaleUpAnimation(this.mRefreshListener); return; } setRefreshing(z, false); } private void startScaleUpAnimation(Animation.AnimationListener animationListener) { this.mCircleView.setVisibility(0); this.mProgress.setAlpha(255); Animation animation = new Animation() { // from class: androidx.swiperefreshlayout.widget.SwipeRefreshLayout.2 @Override // android.view.animation.Animation public void applyTransformation(float f, Transformation transformation) { SwipeRefreshLayout.this.setAnimationProgress(f); } }; this.mScaleAnimation = animation; animation.setDuration(this.mMediumAnimationDuration); if (animationListener != null) { this.mCircleView.setAnimationListener(animationListener); } this.mCircleView.clearAnimation(); this.mCircleView.startAnimation(this.mScaleAnimation); } public void setAnimationProgress(float f) { this.mCircleView.setScaleX(f); this.mCircleView.setScaleY(f); } private void setRefreshing(boolean z, boolean z2) { if (this.mRefreshing != z) { this.mNotify = z2; ensureTarget(); this.mRefreshing = z; if (z) { animateOffsetToCorrectPosition(this.mCurrentTargetOffsetTop, this.mRefreshListener); } else { startScaleDownAnimation(this.mRefreshListener); } } } public void startScaleDownAnimation(Animation.AnimationListener animationListener) { Animation animation = new Animation() { // from class: androidx.swiperefreshlayout.widget.SwipeRefreshLayout.3 @Override // android.view.animation.Animation public void applyTransformation(float f, Transformation transformation) { SwipeRefreshLayout.this.setAnimationProgress(1.0f - f); } }; this.mScaleDownAnimation = animation; animation.setDuration(150L); this.mCircleView.setAnimationListener(animationListener); this.mCircleView.clearAnimation(); this.mCircleView.startAnimation(this.mScaleDownAnimation); } private void startProgressAlphaStartAnimation() { this.mAlphaStartAnimation = startAlphaAnimation(this.mProgress.getAlpha(), STARTING_PROGRESS_ALPHA); } private void startProgressAlphaMaxAnimation() { this.mAlphaMaxAnimation = startAlphaAnimation(this.mProgress.getAlpha(), 255); } private Animation startAlphaAnimation(final int i, final int i2) { Animation animation = new Animation() { // from class: androidx.swiperefreshlayout.widget.SwipeRefreshLayout.4 @Override // android.view.animation.Animation public void applyTransformation(float f, Transformation transformation) { SwipeRefreshLayout.this.mProgress.setAlpha((int) (i + ((i2 - r0) * f))); } }; animation.setDuration(300L); this.mCircleView.setAnimationListener(null); this.mCircleView.clearAnimation(); this.mCircleView.startAnimation(animation); return animation; } @Deprecated public void setProgressBackgroundColor(int i) { setProgressBackgroundColorSchemeResource(i); } public void setProgressBackgroundColorSchemeResource(@ColorRes int i) { setProgressBackgroundColorSchemeColor(ContextCompat.getColor(getContext(), i)); } public void setProgressBackgroundColorSchemeColor(@ColorInt int i) { this.mCircleView.setBackgroundColor(i); } @Deprecated public void setColorScheme(@ColorRes int... iArr) { setColorSchemeResources(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 setColorSchemeColors(@ColorInt int... iArr) { ensureTarget(); this.mProgress.setColorSchemeColors(iArr); } 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; } } } } @Override // android.view.ViewGroup, android.view.View public void onLayout(boolean z, int i, int i2, int i3, int i4) { int measuredWidth = getMeasuredWidth(); int measuredHeight = getMeasuredHeight(); if (getChildCount() == 0) { return; } if (this.mTarget == null) { ensureTarget(); } View view = this.mTarget; if (view == null) { return; } 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) { return; } 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; } } } public boolean canChildScrollUp() { OnChildScrollUpCallback onChildScrollUpCallback = this.mChildScrollUpCallback; if (onChildScrollUpCallback != null) { return onChildScrollUpCallback.canChildScrollUp(this, this.mTarget); } View view = this.mTarget; if (view instanceof ListView) { return ListViewCompat.canScrollList((ListView) view, -1); } return view.canScrollVertically(-1); } @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.ViewParent public void requestDisallowInterceptTouchEvent(boolean z) { View view = this.mTarget; if (view == null || ViewCompat.isNestedScrollingEnabled(view)) { super.requestDisallowInterceptTouchEvent(z); } } @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) ? false : true; } @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 // 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 = i2; if (f2 > f) { iArr[1] = i2 - ((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 // android.view.ViewGroup, androidx.core.view.NestedScrollingParent public int getNestedScrollAxes() { return this.mNestedScrollingParentHelper.getNestedScrollAxes(); } @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 // android.view.ViewGroup, android.view.ViewParent, androidx.core.view.NestedScrollingParent public void onNestedScroll(View view, int i, int i2, int i3, int i4) { dispatchNestedScroll(i, i2, i3, i4, this.mParentOffsetInWindow); if (i4 + this.mParentOffsetInWindow[1] >= 0 || canChildScrollUp()) { return; } float abs = this.mTotalUnconsumed + Math.abs(r11); this.mTotalUnconsumed = abs; moveSpinner(abs); } @Override // android.view.View, androidx.core.view.NestedScrollingChild public void setNestedScrollingEnabled(boolean z) { this.mNestedScrollingChildHelper.setNestedScrollingEnabled(z); } @Override // android.view.View, androidx.core.view.NestedScrollingChild public boolean isNestedScrollingEnabled() { return this.mNestedScrollingChildHelper.isNestedScrollingEnabled(); } @Override // android.view.View, androidx.core.view.NestedScrollingChild public boolean startNestedScroll(int i) { return this.mNestedScrollingChildHelper.startNestedScroll(i); } @Override // android.view.View, androidx.core.view.NestedScrollingChild public void stopNestedScroll() { this.mNestedScrollingChildHelper.stopNestedScroll(); } @Override // android.view.View, androidx.core.view.NestedScrollingChild public boolean hasNestedScrollingParent() { return this.mNestedScrollingChildHelper.hasNestedScrollingParent(); } @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 // 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 // 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 boolean onNestedFling(View view, float f, float f2, boolean z) { return dispatchNestedFling(f, f2, z); } @Override // android.view.View, androidx.core.view.NestedScrollingChild public boolean dispatchNestedFling(float f, float f2, boolean z) { return this.mNestedScrollingChildHelper.dispatchNestedFling(f, f2, z); } @Override // android.view.View, androidx.core.view.NestedScrollingChild public boolean dispatchNestedPreFling(float f, float f2) { return this.mNestedScrollingChildHelper.dispatchNestedPreFling(f, f2); } private boolean isAnimationRunning(Animation animation) { return (animation == null || !animation.hasStarted() || animation.hasEnded()) ? false : true; } 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(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 = i; double max2 = 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() > STARTING_PROGRESS_ALPHA && !isAnimationRunning(this.mAlphaStartAnimation)) { startProgressAlphaStartAnimation(); } } else if (this.mProgress.getAlpha() < 255 && !isAnimationRunning(this.mAlphaMaxAnimation)) { startProgressAlphaMaxAnimation(); } this.mProgress.setStartEndTrim(0.0f, Math.min(MAX_PROGRESS_ANGLE, max * MAX_PROGRESS_ANGLE)); this.mProgress.setArrowScale(Math.min(1.0f, max)); this.mProgress.setProgressRotation((((max * 0.4f) - 0.25f) + (pow * 2.0f)) * DRAG_RATE); setTargetOffsetTopAndBottom(i2 - this.mCurrentTargetOffsetTop); } private void finishSpinner(float f) { if (f > this.mTotalDragDistance) { setRefreshing(true, true); return; } this.mRefreshing = false; this.mProgress.setStartEndTrim(0.0f, 0.0f); animateOffsetToStartPosition(this.mCurrentTargetOffsetTop, !this.mScale ? new Animation.AnimationListener() { // from class: androidx.swiperefreshlayout.widget.SwipeRefreshLayout.5 @Override // android.view.animation.Animation.AnimationListener public void onAnimationRepeat(Animation animation) { } @Override // android.view.animation.Animation.AnimationListener public void onAnimationStart(Animation animation) { } @Override // android.view.animation.Animation.AnimationListener public void onAnimationEnd(Animation animation) { SwipeRefreshLayout swipeRefreshLayout = SwipeRefreshLayout.this; if (swipeRefreshLayout.mScale) { return; } swipeRefreshLayout.startScaleDownAnimation(null); } } : null); this.mProgress.setArrowEnabled(false); } @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) { float y = (motionEvent.getY(findPointerIndex) - this.mInitialMotionY) * DRAG_RATE; this.mIsBeingDragged = false; finishSpinner(y); } this.mActivePointerId = -1; return false; } 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) * DRAG_RATE; if (f <= 0.0f) { return false; } moveSpinner(f); } } else { if (actionMasked == 3) { return false; } 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; } private void startDragging(float f) { float f2 = this.mInitialDownY; float f3 = f - f2; int i = this.mTouchSlop; if (f3 <= i || this.mIsBeingDragged) { return; } this.mInitialMotionY = f2 + i; this.mIsBeingDragged = true; this.mProgress.setAlpha(STARTING_PROGRESS_ALPHA); } private void animateOffsetToCorrectPosition(int i, Animation.AnimationListener animationListener) { this.mFrom = i; this.mAnimateToCorrectPosition.reset(); this.mAnimateToCorrectPosition.setDuration(200L); 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(200L); this.mAnimateToStartPosition.setInterpolator(this.mDecelerateInterpolator); if (animationListener != null) { this.mCircleView.setAnimationListener(animationListener); } this.mCircleView.clearAnimation(); this.mCircleView.startAnimation(this.mAnimateToStartPosition); } public void moveToStart(float f) { setTargetOffsetTopAndBottom((this.mFrom + ((int) ((this.mOriginalOffsetTop - r0) * f))) - this.mCircleView.getTop()); } private void startScaleDownReturnToStartAnimation(int i, Animation.AnimationListener animationListener) { this.mFrom = i; this.mStartingScale = this.mCircleView.getScaleX(); Animation animation = new Animation() { // from class: androidx.swiperefreshlayout.widget.SwipeRefreshLayout.8 @Override // android.view.animation.Animation public void applyTransformation(float f, Transformation transformation) { SwipeRefreshLayout swipeRefreshLayout = SwipeRefreshLayout.this; float f2 = swipeRefreshLayout.mStartingScale; swipeRefreshLayout.setAnimationProgress(f2 + ((-f2) * f)); SwipeRefreshLayout.this.moveToStart(f); } }; this.mScaleDownToStartAnimation = animation; animation.setDuration(150L); if (animationListener != null) { this.mCircleView.setAnimationListener(animationListener); } this.mCircleView.clearAnimation(); this.mCircleView.startAnimation(this.mScaleDownToStartAnimation); } public void setTargetOffsetTopAndBottom(int i) { this.mCircleView.bringToFront(); ViewCompat.offsetTopAndBottom(this.mCircleView, i); this.mCurrentTargetOffsetTop = this.mCircleView.getTop(); } private void onSecondaryPointerUp(MotionEvent motionEvent) { int actionIndex = motionEvent.getActionIndex(); if (motionEvent.getPointerId(actionIndex) == this.mActivePointerId) { this.mActivePointerId = motionEvent.getPointerId(actionIndex == 0 ? 1 : 0); } } }