package g;

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 com.google.android.gms.measurement.internal.u1;
import d.i;
import d.j;

/* JADX INFO: loaded from: classes.dex */
public final class d extends Drawable {

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public static final float f26113l = (float) Math.toRadians(45.0d);

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Paint f26114a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final float f26115b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final float f26116c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final float f26117d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final float f26118e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final boolean f26119f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final Path f26120g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final int f26121h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public float f26122i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final float f26123j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final int f26124k;

    public d(Context context) {
        Paint paint = new Paint();
        this.f26114a = paint;
        this.f26120g = new Path();
        this.f26124k = 2;
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeJoin(Paint.Join.MITER);
        paint.setStrokeCap(Paint.Cap.BUTT);
        paint.setAntiAlias(true);
        TypedArray typedArrayObtainStyledAttributes = context.getTheme().obtainStyledAttributes(null, j.DrawerArrowToggle, d.a.drawerArrowStyle, i.Base_Widget_AppCompat_DrawerArrowToggle);
        int color = typedArrayObtainStyledAttributes.getColor(j.DrawerArrowToggle_color, 0);
        if (color != paint.getColor()) {
            paint.setColor(color);
            invalidateSelf();
        }
        float dimension = typedArrayObtainStyledAttributes.getDimension(j.DrawerArrowToggle_thickness, 0.0f);
        if (paint.getStrokeWidth() != dimension) {
            paint.setStrokeWidth(dimension);
            this.f26123j = (float) (Math.cos(f26113l) * ((double) (dimension / 2.0f)));
            invalidateSelf();
        }
        boolean z10 = typedArrayObtainStyledAttributes.getBoolean(j.DrawerArrowToggle_spinBars, true);
        if (this.f26119f != z10) {
            this.f26119f = z10;
            invalidateSelf();
        }
        float fRound = Math.round(typedArrayObtainStyledAttributes.getDimension(j.DrawerArrowToggle_gapBetweenBars, 0.0f));
        if (fRound != this.f26118e) {
            this.f26118e = fRound;
            invalidateSelf();
        }
        this.f26121h = typedArrayObtainStyledAttributes.getDimensionPixelSize(j.DrawerArrowToggle_drawableSize, 0);
        this.f26116c = Math.round(typedArrayObtainStyledAttributes.getDimension(j.DrawerArrowToggle_barLength, 0.0f));
        this.f26115b = Math.round(typedArrayObtainStyledAttributes.getDimension(j.DrawerArrowToggle_arrowHeadLength, 0.0f));
        this.f26117d = typedArrayObtainStyledAttributes.getDimension(j.DrawerArrowToggle_arrowShaftLength, 0.0f);
        typedArrayObtainStyledAttributes.recycle();
    }

    public static float a(float f10, float f11, float f12) {
        return u1.a(f11, f10, f12, f10);
    }

    @Override // android.graphics.drawable.Drawable
    public final void draw(Canvas canvas) {
        Rect bounds = getBounds();
        boolean z10 = false;
        int i10 = this.f26124k;
        if (i10 != 0 && (i10 == 1 || (i10 == 3 ? getLayoutDirection() == 0 : getLayoutDirection() == 1))) {
            z10 = true;
        }
        float f10 = this.f26115b;
        float fSqrt = (float) Math.sqrt(f10 * f10 * 2.0f);
        float f11 = this.f26122i;
        float f12 = this.f26116c;
        float fA = a(f12, fSqrt, f11);
        float fA2 = a(f12, this.f26117d, this.f26122i);
        float fRound = Math.round(a(0.0f, this.f26123j, this.f26122i));
        float fA3 = a(0.0f, f26113l, this.f26122i);
        float fA4 = a(z10 ? 0.0f : -180.0f, z10 ? 180.0f : 0.0f, this.f26122i);
        double d10 = fA;
        double d11 = fA3;
        float fRound2 = Math.round(Math.cos(d11) * d10);
        float fRound3 = Math.round(Math.sin(d11) * d10);
        Path path = this.f26120g;
        path.rewind();
        float f13 = this.f26118e;
        Paint paint = this.f26114a;
        float fA5 = a(paint.getStrokeWidth() + f13, -this.f26123j, this.f26122i);
        float f14 = (-fA2) / 2.0f;
        path.moveTo(f14 + fRound, 0.0f);
        path.rLineTo(fA2 - (fRound * 2.0f), 0.0f);
        path.moveTo(f14, fA5);
        path.rLineTo(fRound2, fRound3);
        path.moveTo(f14, -fA5);
        path.rLineTo(fRound2, -fRound3);
        path.close();
        canvas.save();
        float strokeWidth = paint.getStrokeWidth();
        float fHeight = bounds.height() - (3.0f * strokeWidth);
        canvas.translate(bounds.centerX(), (strokeWidth * 1.5f) + this.f26118e + ((((int) (fHeight - (2.0f * r8))) / 4) * 2));
        if (this.f26119f) {
            canvas.rotate(fA4 * (z10 ? -1 : 1));
        } else if (z10) {
            canvas.rotate(180.0f);
        }
        canvas.drawPath(path, paint);
        canvas.restore();
    }

    @Override // android.graphics.drawable.Drawable
    public final int getIntrinsicHeight() {
        return this.f26121h;
    }

    @Override // android.graphics.drawable.Drawable
    public final int getIntrinsicWidth() {
        return this.f26121h;
    }

    @Override // android.graphics.drawable.Drawable
    public final int getOpacity() {
        return -3;
    }

    @Override // android.graphics.drawable.Drawable
    public final void setAlpha(int i10) {
        Paint paint = this.f26114a;
        if (i10 != paint.getAlpha()) {
            paint.setAlpha(i10);
            invalidateSelf();
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final void setColorFilter(ColorFilter colorFilter) {
        this.f26114a.setColorFilter(colorFilter);
        invalidateSelf();
    }
}
