discord-jadx/app/src/main/java/androidx/constraintlayout/utils/widget/MotionTelltales.java

124 lines
4.6 KiB
Java
Raw Normal View History

2021-06-27 20:44:35 +00:00
package androidx.constraintlayout.utils.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.ViewParent;
import androidx.constraintlayout.motion.widget.MotionLayout;
import androidx.constraintlayout.widget.R;
public class MotionTelltales extends MockView {
private static final String TAG = "MotionTelltales";
public Matrix mInvertMatrix;
public MotionLayout mMotionLayout;
private Paint mPaintTelltales;
public int mTailColor;
public float mTailScale;
public int mVelocityMode;
public float[] velocity;
public MotionTelltales(Context context) {
super(context);
this.mPaintTelltales = new Paint();
this.velocity = new float[2];
this.mInvertMatrix = new Matrix();
this.mVelocityMode = 0;
this.mTailColor = -65281;
this.mTailScale = 0.25f;
init(context, null);
}
public MotionTelltales(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
this.mPaintTelltales = new Paint();
this.velocity = new float[2];
this.mInvertMatrix = new Matrix();
this.mVelocityMode = 0;
this.mTailColor = -65281;
this.mTailScale = 0.25f;
init(context, attributeSet);
}
public MotionTelltales(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
this.mPaintTelltales = new Paint();
this.velocity = new float[2];
this.mInvertMatrix = new Matrix();
this.mVelocityMode = 0;
this.mTailColor = -65281;
this.mTailScale = 0.25f;
init(context, attributeSet);
}
private void init(Context context, AttributeSet attributeSet) {
if (attributeSet != null) {
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.MotionTelltales);
int indexCount = obtainStyledAttributes.getIndexCount();
for (int i = 0; i < indexCount; i++) {
int index = obtainStyledAttributes.getIndex(i);
if (index == R.styleable.MotionTelltales_telltales_tailColor) {
this.mTailColor = obtainStyledAttributes.getColor(index, this.mTailColor);
} else if (index == R.styleable.MotionTelltales_telltales_velocityMode) {
this.mVelocityMode = obtainStyledAttributes.getInt(index, this.mVelocityMode);
} else if (index == R.styleable.MotionTelltales_telltales_tailScale) {
this.mTailScale = obtainStyledAttributes.getFloat(index, this.mTailScale);
}
}
obtainStyledAttributes.recycle();
}
this.mPaintTelltales.setColor(this.mTailColor);
this.mPaintTelltales.setStrokeWidth(5.0f);
}
@Override // android.view.View
public void onAttachedToWindow() {
super.onAttachedToWindow();
}
@Override // androidx.constraintlayout.utils.widget.MockView, android.view.View
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
getMatrix().invert(this.mInvertMatrix);
if (this.mMotionLayout == null) {
ViewParent parent = getParent();
if (parent instanceof MotionLayout) {
this.mMotionLayout = (MotionLayout) parent;
return;
}
return;
}
int width = getWidth();
int height = getHeight();
float[] fArr = {0.1f, 0.25f, 0.5f, 0.75f, 0.9f};
for (int i = 0; i < 5; i++) {
float f = fArr[i];
for (int i2 = 0; i2 < 5; i2++) {
float f2 = fArr[i2];
this.mMotionLayout.getViewVelocity(this, f2, f, this.velocity, this.mVelocityMode);
this.mInvertMatrix.mapVectors(this.velocity);
float f3 = ((float) width) * f2;
float f4 = ((float) height) * f;
float[] fArr2 = this.velocity;
float f5 = fArr2[0];
float f6 = this.mTailScale;
float f7 = f4 - (fArr2[1] * f6);
this.mInvertMatrix.mapVectors(fArr2);
canvas.drawLine(f3, f4, f3 - (f5 * f6), f7, this.mPaintTelltales);
}
}
}
@Override // android.view.View
public void onLayout(boolean z2, int i, int i2, int i3, int i4) {
super.onLayout(z2, i, i2, i3, i4);
postInvalidate();
}
public void setText(CharSequence charSequence) {
this.mText = charSequence.toString();
requestLayout();
}
}