126 lines
4.6 KiB
Java
126 lines
4.6 KiB
Java
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;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class MotionTelltales extends MockView {
|
|
private static final String TAG = "MotionTelltales";
|
|
Matrix mInvertMatrix;
|
|
MotionLayout mMotionLayout;
|
|
private Paint mPaintTelltales;
|
|
int mTailColor;
|
|
float mTailScale;
|
|
int mVelocityMode;
|
|
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 attrs) {
|
|
super(context, attrs);
|
|
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, attrs);
|
|
}
|
|
|
|
public MotionTelltales(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
super(context, attrs, defStyleAttr);
|
|
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, attrs);
|
|
}
|
|
|
|
private void init(Context context, AttributeSet attrs) {
|
|
if (attrs != null) {
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attrs, 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
|
|
protected void onAttachedToWindow() {
|
|
super.onAttachedToWindow();
|
|
}
|
|
|
|
public void setText(CharSequence text) {
|
|
this.mText = text.toString();
|
|
requestLayout();
|
|
}
|
|
|
|
@Override // android.view.View
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
super.onLayout(changed, left, top, right, bottom);
|
|
postInvalidate();
|
|
}
|
|
|
|
@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 = width * f2;
|
|
float f4 = 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);
|
|
}
|
|
}
|
|
}
|
|
}
|