discord-jadx/app/src/main/java/androidx/core/widget/AutoScrollHelper.java

401 lines
14 KiB
Java

package androidx.core.widget;
import android.content.res.Resources;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import androidx.annotation.NonNull;
import androidx.core.view.ViewCompat;
public abstract class AutoScrollHelper implements View.OnTouchListener {
private static final int DEFAULT_ACTIVATION_DELAY = ViewConfiguration.getTapTimeout();
private static final int DEFAULT_EDGE_TYPE = 1;
private static final float DEFAULT_MAXIMUM_EDGE = Float.MAX_VALUE;
private static final int DEFAULT_MAXIMUM_VELOCITY_DIPS = 1575;
private static final int DEFAULT_MINIMUM_VELOCITY_DIPS = 315;
private static final int DEFAULT_RAMP_DOWN_DURATION = 500;
private static final int DEFAULT_RAMP_UP_DURATION = 500;
private static final float DEFAULT_RELATIVE_EDGE = 0.2f;
private static final float DEFAULT_RELATIVE_VELOCITY = 1.0f;
public static final int EDGE_TYPE_INSIDE = 0;
public static final int EDGE_TYPE_INSIDE_EXTEND = 1;
public static final int EDGE_TYPE_OUTSIDE = 2;
private static final int HORIZONTAL = 0;
public static final float NO_MAX = Float.MAX_VALUE;
public static final float NO_MIN = 0.0f;
public static final float RELATIVE_UNSPECIFIED = 0.0f;
private static final int VERTICAL = 1;
private int mActivationDelay;
private boolean mAlreadyDelayed;
public boolean mAnimating;
private final Interpolator mEdgeInterpolator = new AccelerateInterpolator();
private int mEdgeType;
private boolean mEnabled;
private boolean mExclusive;
private float[] mMaximumEdges = {Float.MAX_VALUE, Float.MAX_VALUE};
private float[] mMaximumVelocity = {Float.MAX_VALUE, Float.MAX_VALUE};
private float[] mMinimumVelocity = {0.0f, 0.0f};
public boolean mNeedsCancel;
public boolean mNeedsReset;
private float[] mRelativeEdges = {0.0f, 0.0f};
private float[] mRelativeVelocity = {0.0f, 0.0f};
private Runnable mRunnable;
public final ClampedScroller mScroller = new ClampedScroller();
public final View mTarget;
public static class ClampedScroller {
private long mDeltaTime = 0;
private int mDeltaX = 0;
private int mDeltaY = 0;
private int mEffectiveRampDown;
private int mRampDownDuration;
private int mRampUpDuration;
private long mStartTime = Long.MIN_VALUE;
private long mStopTime = -1;
private float mStopValue;
private float mTargetVelocityX;
private float mTargetVelocityY;
private float getValueAt(long j) {
long j2 = this.mStartTime;
if (j < j2) {
return 0.0f;
}
long j3 = this.mStopTime;
if (j3 < 0 || j < j3) {
return AutoScrollHelper.constrain(((float) (j - j2)) / ((float) this.mRampUpDuration), 0.0f, 1.0f) * 0.5f;
}
float f = this.mStopValue;
return (AutoScrollHelper.constrain(((float) (j - j3)) / ((float) this.mEffectiveRampDown), 0.0f, 1.0f) * f) + (1.0f - f);
}
private float interpolateValue(float f) {
return (f * 4.0f) + (-4.0f * f * f);
}
public void computeScrollDelta() {
if (this.mDeltaTime != 0) {
long currentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
float interpolateValue = interpolateValue(getValueAt(currentAnimationTimeMillis));
this.mDeltaTime = currentAnimationTimeMillis;
float f = ((float) (currentAnimationTimeMillis - this.mDeltaTime)) * interpolateValue;
this.mDeltaX = (int) (this.mTargetVelocityX * f);
this.mDeltaY = (int) (f * this.mTargetVelocityY);
return;
}
throw new RuntimeException("Cannot compute scroll delta before calling start()");
}
public int getDeltaX() {
return this.mDeltaX;
}
public int getDeltaY() {
return this.mDeltaY;
}
public int getHorizontalDirection() {
float f = this.mTargetVelocityX;
return (int) (f / Math.abs(f));
}
public int getVerticalDirection() {
float f = this.mTargetVelocityY;
return (int) (f / Math.abs(f));
}
public boolean isFinished() {
return this.mStopTime > 0 && AnimationUtils.currentAnimationTimeMillis() > this.mStopTime + ((long) this.mEffectiveRampDown);
}
public void requestStop() {
long currentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
this.mEffectiveRampDown = AutoScrollHelper.constrain((int) (currentAnimationTimeMillis - this.mStartTime), 0, this.mRampDownDuration);
this.mStopValue = getValueAt(currentAnimationTimeMillis);
this.mStopTime = currentAnimationTimeMillis;
}
public void setRampDownDuration(int i) {
this.mRampDownDuration = i;
}
public void setRampUpDuration(int i) {
this.mRampUpDuration = i;
}
public void setTargetVelocity(float f, float f2) {
this.mTargetVelocityX = f;
this.mTargetVelocityY = f2;
}
public void start() {
long currentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
this.mStartTime = currentAnimationTimeMillis;
this.mStopTime = -1;
this.mDeltaTime = currentAnimationTimeMillis;
this.mStopValue = 0.5f;
this.mDeltaX = 0;
this.mDeltaY = 0;
}
}
public class ScrollAnimationRunnable implements Runnable {
public ScrollAnimationRunnable() {
}
@Override // java.lang.Runnable
public void run() {
AutoScrollHelper autoScrollHelper = AutoScrollHelper.this;
if (autoScrollHelper.mAnimating) {
if (autoScrollHelper.mNeedsReset) {
autoScrollHelper.mNeedsReset = false;
autoScrollHelper.mScroller.start();
}
ClampedScroller clampedScroller = AutoScrollHelper.this.mScroller;
if (clampedScroller.isFinished() || !AutoScrollHelper.this.shouldAnimate()) {
AutoScrollHelper.this.mAnimating = false;
return;
}
AutoScrollHelper autoScrollHelper2 = AutoScrollHelper.this;
if (autoScrollHelper2.mNeedsCancel) {
autoScrollHelper2.mNeedsCancel = false;
autoScrollHelper2.cancelTargetTouch();
}
clampedScroller.computeScrollDelta();
AutoScrollHelper.this.scrollTargetBy(clampedScroller.getDeltaX(), clampedScroller.getDeltaY());
ViewCompat.postOnAnimation(AutoScrollHelper.this.mTarget, this);
}
}
}
public AutoScrollHelper(@NonNull View view) {
this.mTarget = view;
float f = Resources.getSystem().getDisplayMetrics().density;
float f2 = (float) ((int) ((1575.0f * f) + 0.5f));
setMaximumVelocity(f2, f2);
float f3 = (float) ((int) ((f * 315.0f) + 0.5f));
setMinimumVelocity(f3, f3);
setEdgeType(1);
setMaximumEdges(Float.MAX_VALUE, Float.MAX_VALUE);
setRelativeEdges(0.2f, 0.2f);
setRelativeVelocity(1.0f, 1.0f);
setActivationDelay(DEFAULT_ACTIVATION_DELAY);
setRampUpDuration(500);
setRampDownDuration(500);
}
private float computeTargetVelocity(int i, float f, float f2, float f3) {
float edgeValue = getEdgeValue(this.mRelativeEdges[i], f2, this.mMaximumEdges[i], f);
int i2 = (edgeValue > 0.0f ? 1 : (edgeValue == 0.0f ? 0 : -1));
if (i2 == 0) {
return 0.0f;
}
float f4 = this.mRelativeVelocity[i];
float f5 = this.mMinimumVelocity[i];
float f6 = this.mMaximumVelocity[i];
float f7 = f4 * f3;
return i2 > 0 ? constrain(edgeValue * f7, f5, f6) : -constrain((-edgeValue) * f7, f5, f6);
}
public static float constrain(float f, float f2, float f3) {
return f > f3 ? f3 : f < f2 ? f2 : f;
}
public static int constrain(int i, int i2, int i3) {
return i > i3 ? i3 : i < i2 ? i2 : i;
}
private float constrainEdgeValue(float f, float f2) {
if (f2 == 0.0f) {
return 0.0f;
}
int i = this.mEdgeType;
if (i == 0 || i == 1) {
if (f < f2) {
if (f >= 0.0f) {
return 1.0f - (f / f2);
}
if (this.mAnimating && i == 1) {
return 1.0f;
}
}
} else if (i == 2 && f < 0.0f) {
return f / (-f2);
}
return 0.0f;
}
private float getEdgeValue(float f, float f2, float f3, float f4) {
float f5;
float constrain = constrain(f * f2, 0.0f, f3);
float constrainEdgeValue = constrainEdgeValue(f2 - f4, constrain) - constrainEdgeValue(f4, constrain);
if (constrainEdgeValue < 0.0f) {
f5 = -this.mEdgeInterpolator.getInterpolation(-constrainEdgeValue);
} else if (constrainEdgeValue <= 0.0f) {
return 0.0f;
} else {
f5 = this.mEdgeInterpolator.getInterpolation(constrainEdgeValue);
}
return constrain(f5, -1.0f, 1.0f);
}
private void requestStop() {
if (this.mNeedsReset) {
this.mAnimating = false;
} else {
this.mScroller.requestStop();
}
}
private void startAnimating() {
int i;
if (this.mRunnable == null) {
this.mRunnable = new ScrollAnimationRunnable();
}
this.mAnimating = true;
this.mNeedsReset = true;
if (this.mAlreadyDelayed || (i = this.mActivationDelay) <= 0) {
this.mRunnable.run();
} else {
ViewCompat.postOnAnimationDelayed(this.mTarget, this.mRunnable, (long) i);
}
this.mAlreadyDelayed = true;
}
public abstract boolean canTargetScrollHorizontally(int i);
public abstract boolean canTargetScrollVertically(int i);
public void cancelTargetTouch() {
long uptimeMillis = SystemClock.uptimeMillis();
MotionEvent obtain = MotionEvent.obtain(uptimeMillis, uptimeMillis, 3, 0.0f, 0.0f, 0);
this.mTarget.onTouchEvent(obtain);
obtain.recycle();
}
public boolean isEnabled() {
return this.mEnabled;
}
public boolean isExclusive() {
return this.mExclusive;
}
/* JADX WARNING: Code restructure failed: missing block: B:9:0x0013, code lost:
if (r0 != 3) goto L_0x0058;
*/
@Override // android.view.View.OnTouchListener
public boolean onTouch(View view, MotionEvent motionEvent) {
if (!this.mEnabled) {
return false;
}
int actionMasked = motionEvent.getActionMasked();
if (actionMasked != 0) {
if (actionMasked != 1) {
if (actionMasked != 2) {
}
}
requestStop();
return this.mExclusive && this.mAnimating;
}
this.mNeedsCancel = true;
this.mAlreadyDelayed = false;
this.mScroller.setTargetVelocity(computeTargetVelocity(0, motionEvent.getX(), (float) view.getWidth(), (float) this.mTarget.getWidth()), computeTargetVelocity(1, motionEvent.getY(), (float) view.getHeight(), (float) this.mTarget.getHeight()));
if (!this.mAnimating && shouldAnimate()) {
startAnimating();
}
if (this.mExclusive) {
return false;
}
}
public abstract void scrollTargetBy(int i, int i2);
@NonNull
public AutoScrollHelper setActivationDelay(int i) {
this.mActivationDelay = i;
return this;
}
@NonNull
public AutoScrollHelper setEdgeType(int i) {
this.mEdgeType = i;
return this;
}
public AutoScrollHelper setEnabled(boolean z2) {
if (this.mEnabled && !z2) {
requestStop();
}
this.mEnabled = z2;
return this;
}
public AutoScrollHelper setExclusive(boolean z2) {
this.mExclusive = z2;
return this;
}
@NonNull
public AutoScrollHelper setMaximumEdges(float f, float f2) {
float[] fArr = this.mMaximumEdges;
fArr[0] = f;
fArr[1] = f2;
return this;
}
@NonNull
public AutoScrollHelper setMaximumVelocity(float f, float f2) {
float[] fArr = this.mMaximumVelocity;
fArr[0] = f / 1000.0f;
fArr[1] = f2 / 1000.0f;
return this;
}
@NonNull
public AutoScrollHelper setMinimumVelocity(float f, float f2) {
float[] fArr = this.mMinimumVelocity;
fArr[0] = f / 1000.0f;
fArr[1] = f2 / 1000.0f;
return this;
}
@NonNull
public AutoScrollHelper setRampDownDuration(int i) {
this.mScroller.setRampDownDuration(i);
return this;
}
@NonNull
public AutoScrollHelper setRampUpDuration(int i) {
this.mScroller.setRampUpDuration(i);
return this;
}
@NonNull
public AutoScrollHelper setRelativeEdges(float f, float f2) {
float[] fArr = this.mRelativeEdges;
fArr[0] = f;
fArr[1] = f2;
return this;
}
@NonNull
public AutoScrollHelper setRelativeVelocity(float f, float f2) {
float[] fArr = this.mRelativeVelocity;
fArr[0] = f / 1000.0f;
fArr[1] = f2 / 1000.0f;
return this;
}
public boolean shouldAnimate() {
ClampedScroller clampedScroller = this.mScroller;
int verticalDirection = clampedScroller.getVerticalDirection();
int horizontalDirection = clampedScroller.getHorizontalDirection();
return (verticalDirection != 0 && canTargetScrollVertically(verticalDirection)) || (horizontalDirection != 0 && canTargetScrollHorizontally(horizontalDirection));
}
}