package androidx.appcompat.graphics.drawable; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; import android.graphics.drawable.Drawable; import androidx.annotation.ColorInt; import androidx.annotation.FloatRange; import androidx.annotation.RestrictTo; import androidx.appcompat.R; import androidx.core.graphics.drawable.DrawableCompat; import b.d.b.a.a; import com.google.android.material.shadow.ShadowDrawableWrapper; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; public class DrawerArrowDrawable extends Drawable { public static final int ARROW_DIRECTION_END = 3; public static final int ARROW_DIRECTION_LEFT = 0; public static final int ARROW_DIRECTION_RIGHT = 1; public static final int ARROW_DIRECTION_START = 2; private static final float ARROW_HEAD_ANGLE = ((float) Math.toRadians(45.0d)); private float mArrowHeadLength; private float mArrowShaftLength; private float mBarGap; private float mBarLength; private int mDirection = 2; private float mMaxCutForBarSize; private final Paint mPaint; private final Path mPath = new Path(); private float mProgress; private final int mSize; private boolean mSpin; private boolean mVerticalMirror = false; @Retention(RetentionPolicy.SOURCE) @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public @interface ArrowDirection { } public DrawerArrowDrawable(Context context) { Paint paint = new Paint(); this.mPaint = paint; paint.setStyle(Paint.Style.STROKE); paint.setStrokeJoin(Paint.Join.MITER); paint.setStrokeCap(Paint.Cap.BUTT); paint.setAntiAlias(true); TypedArray obtainStyledAttributes = context.getTheme().obtainStyledAttributes(null, R.styleable.DrawerArrowToggle, R.attr.drawerArrowStyle, R.style.Base_Widget_AppCompat_DrawerArrowToggle); setColor(obtainStyledAttributes.getColor(R.styleable.DrawerArrowToggle_color, 0)); setBarThickness(obtainStyledAttributes.getDimension(R.styleable.DrawerArrowToggle_thickness, 0.0f)); setSpinEnabled(obtainStyledAttributes.getBoolean(R.styleable.DrawerArrowToggle_spinBars, true)); setGapSize((float) Math.round(obtainStyledAttributes.getDimension(R.styleable.DrawerArrowToggle_gapBetweenBars, 0.0f))); this.mSize = obtainStyledAttributes.getDimensionPixelSize(R.styleable.DrawerArrowToggle_drawableSize, 0); this.mBarLength = (float) Math.round(obtainStyledAttributes.getDimension(R.styleable.DrawerArrowToggle_barLength, 0.0f)); this.mArrowHeadLength = (float) Math.round(obtainStyledAttributes.getDimension(R.styleable.DrawerArrowToggle_arrowHeadLength, 0.0f)); this.mArrowShaftLength = obtainStyledAttributes.getDimension(R.styleable.DrawerArrowToggle_arrowShaftLength, 0.0f); obtainStyledAttributes.recycle(); } private static float lerp(float f, float f2, float f3) { return a.a(f2, f, f3, f); } @Override // android.graphics.drawable.Drawable public void draw(Canvas canvas) { Rect bounds = getBounds(); int i = this.mDirection; boolean z2 = false; if (i != 0 && (i == 1 || (i == 3 ? DrawableCompat.getLayoutDirection(this) == 0 : DrawableCompat.getLayoutDirection(this) == 1))) { z2 = true; } float f = this.mArrowHeadLength; float lerp = lerp(this.mBarLength, (float) Math.sqrt((double) (f * f * 2.0f)), this.mProgress); float lerp2 = lerp(this.mBarLength, this.mArrowShaftLength, this.mProgress); float round = (float) Math.round(lerp(0.0f, this.mMaxCutForBarSize, this.mProgress)); float lerp3 = lerp(0.0f, ARROW_HEAD_ANGLE, this.mProgress); float lerp4 = lerp(z2 ? 0.0f : -180.0f, z2 ? 180.0f : 0.0f, this.mProgress); double d = (double) lerp; double d2 = (double) lerp3; float round2 = (float) Math.round(Math.cos(d2) * d); float round3 = (float) Math.round(Math.sin(d2) * d); this.mPath.rewind(); float lerp5 = lerp(this.mPaint.getStrokeWidth() + this.mBarGap, -this.mMaxCutForBarSize, this.mProgress); float f2 = (-lerp2) / 2.0f; this.mPath.moveTo(f2 + round, 0.0f); this.mPath.rLineTo(lerp2 - (round * 2.0f), 0.0f); this.mPath.moveTo(f2, lerp5); this.mPath.rLineTo(round2, round3); this.mPath.moveTo(f2, -lerp5); this.mPath.rLineTo(round2, -round3); this.mPath.close(); canvas.save(); float strokeWidth = this.mPaint.getStrokeWidth(); float height = ((float) bounds.height()) - (3.0f * strokeWidth); float f3 = this.mBarGap; canvas.translate((float) bounds.centerX(), (strokeWidth * 1.5f) + f3 + ((float) ((((int) (height - (2.0f * f3))) / 4) * 2))); if (this.mSpin) { canvas.rotate(lerp4 * ((float) (this.mVerticalMirror ^ z2 ? -1 : 1))); } else if (z2) { canvas.rotate(180.0f); } canvas.drawPath(this.mPath, this.mPaint); canvas.restore(); } public float getArrowHeadLength() { return this.mArrowHeadLength; } public float getArrowShaftLength() { return this.mArrowShaftLength; } public float getBarLength() { return this.mBarLength; } public float getBarThickness() { return this.mPaint.getStrokeWidth(); } @ColorInt public int getColor() { return this.mPaint.getColor(); } public int getDirection() { return this.mDirection; } public float getGapSize() { return this.mBarGap; } @Override // android.graphics.drawable.Drawable public int getIntrinsicHeight() { return this.mSize; } @Override // android.graphics.drawable.Drawable public int getIntrinsicWidth() { return this.mSize; } @Override // android.graphics.drawable.Drawable public int getOpacity() { return -3; } public final Paint getPaint() { return this.mPaint; } @FloatRange(from = ShadowDrawableWrapper.COS_45, to = 1.0d) public float getProgress() { return this.mProgress; } public boolean isSpinEnabled() { return this.mSpin; } @Override // android.graphics.drawable.Drawable public void setAlpha(int i) { if (i != this.mPaint.getAlpha()) { this.mPaint.setAlpha(i); invalidateSelf(); } } public void setArrowHeadLength(float f) { if (this.mArrowHeadLength != f) { this.mArrowHeadLength = f; invalidateSelf(); } } public void setArrowShaftLength(float f) { if (this.mArrowShaftLength != f) { this.mArrowShaftLength = f; invalidateSelf(); } } public void setBarLength(float f) { if (this.mBarLength != f) { this.mBarLength = f; invalidateSelf(); } } public void setBarThickness(float f) { if (this.mPaint.getStrokeWidth() != f) { this.mPaint.setStrokeWidth(f); this.mMaxCutForBarSize = (float) (Math.cos((double) ARROW_HEAD_ANGLE) * ((double) (f / 2.0f))); invalidateSelf(); } } public void setColor(@ColorInt int i) { if (i != this.mPaint.getColor()) { this.mPaint.setColor(i); invalidateSelf(); } } @Override // android.graphics.drawable.Drawable public void setColorFilter(ColorFilter colorFilter) { this.mPaint.setColorFilter(colorFilter); invalidateSelf(); } public void setDirection(int i) { if (i != this.mDirection) { this.mDirection = i; invalidateSelf(); } } public void setGapSize(float f) { if (f != this.mBarGap) { this.mBarGap = f; invalidateSelf(); } } public void setProgress(@FloatRange(from = 0.0d, to = 1.0d) float f) { if (this.mProgress != f) { this.mProgress = f; invalidateSelf(); } } public void setSpinEnabled(boolean z2) { if (this.mSpin != z2) { this.mSpin = z2; invalidateSelf(); } } public void setVerticalMirror(boolean z2) { if (this.mVerticalMirror != z2) { this.mVerticalMirror = z2; invalidateSelf(); } } }