package xyz.stream.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import xyz.stream.view.refresh.layout.util.AutoUtil;

/* JADX INFO: loaded from: classes3.dex */
public class TriangleView extends View {
    public static final int BOTTOM = 1;
    public static final int LEFT = 3;
    public static final int RIGHT = 2;
    public static final int TOP = 0;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f36386b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f36387c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f36388d;

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

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

    public TriangleView(Context context) {
        this(context, null);
    }

    public static float[] b(float f10, float f11, float f12, float f13, float f14) {
        float f15 = f12 - f10;
        float f16 = f13 - f11;
        float fSqrt = (float) Math.sqrt((f16 * f16) + (f15 * f15));
        if (fSqrt == 0.0f) {
            return new float[]{f10, f11};
        }
        float fMin = Math.min(f14, fSqrt);
        return new float[]{((f15 / fSqrt) * fMin) + f10, ((f16 / fSqrt) * fMin) + f11};
    }

    public final void a(float f10, float f11, float f12, float f13, float f14, float f15) {
        float f16 = this.f36390f;
        if (f16 <= 0.0f) {
            this.f36389e.moveTo(f12, f13);
            this.f36389e.lineTo(f14, f15);
            this.f36389e.lineTo(f10, f11);
            this.f36389e.close();
            return;
        }
        float[] fArrB = b(f10, f11, f12, f13, f16);
        float[] fArrB2 = b(f10, f11, f14, f15, f16);
        this.f36389e.moveTo(f12, f13);
        this.f36389e.lineTo(f14, f15);
        this.f36389e.lineTo(fArrB2[0], fArrB2[1]);
        this.f36389e.quadTo(f10, f11, fArrB[0], fArrB[1]);
        this.f36389e.close();
    }

    @Override // android.view.View
    public void onDraw(@NonNull Canvas canvas) {
        super.onDraw(canvas);
        this.f36389e.reset();
        int i10 = this.f36388d;
        if (i10 == 0) {
            int i11 = this.f36386b;
            int i12 = this.f36387c;
            a(i11 / 2.0f, 0.0f, 0.0f, i12, i11, i12);
        } else if (i10 == 1) {
            int i13 = this.f36386b;
            a(i13 / 2.0f, this.f36387c, 0.0f, 0.0f, i13, 0.0f);
        } else if (i10 == 2) {
            float f10 = this.f36386b;
            int i14 = this.f36387c;
            a(f10, i14 / 2.0f, 0.0f, 0.0f, 0.0f, i14);
        } else if (i10 == 3) {
            int i15 = this.f36387c;
            int i16 = this.f36386b;
            a(0.0f, i15 / 2.0f, i16, 0.0f, i16, i15);
        }
        canvas.drawPath(this.f36389e, this.f36385a);
    }

    @Override // android.view.View
    public void onMeasure(int i10, int i11) {
        super.onMeasure(i10, i11);
        this.f36386b = View.MeasureSpec.getSize(i10);
        this.f36387c = View.MeasureSpec.getSize(i11);
        int mode = View.MeasureSpec.getMode(i10);
        int mode2 = View.MeasureSpec.getMode(i11);
        if (this.f36386b == 0 || mode != 1073741824) {
            this.f36386b = AutoUtil.dp2px(10.0f);
        }
        if (this.f36387c == 0 || mode2 != 1073741824) {
            this.f36387c = AutoUtil.dp2px(6.0f);
        }
        setMeasuredDimension(this.f36386b, this.f36387c);
    }

    public void setColor(int i10) {
        this.f36385a.setColor(i10);
        invalidate();
    }

    public void setCornerRadius(float f10) {
        this.f36390f = Math.max(0.0f, f10);
        invalidate();
    }

    public void setDirection(int i10) {
        this.f36388d = i10;
        invalidate();
    }

    public TriangleView(Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public TriangleView(Context context, @Nullable AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        Paint paint = new Paint(1);
        this.f36385a = paint;
        paint.setStyle(Paint.Style.FILL);
        this.f36389e = new Path();
        this.f36388d = 0;
        this.f36390f = AutoUtil.dp2px(5.0f);
        TypedArray typedArrayObtainStyledAttributes = context.getTheme().obtainStyledAttributes(attributeSet, R.styleable.TriangleView, 0, 0);
        int i11 = R.styleable.TriangleView_trv_color;
        Context context2 = getContext();
        Object obj = g0.d.f26125a;
        int color = typedArrayObtainStyledAttributes.getColor(i11, context2.getColor(android.R.color.white));
        this.f36388d = typedArrayObtainStyledAttributes.getInt(R.styleable.TriangleView_trv_direction, 0);
        typedArrayObtainStyledAttributes.recycle();
        this.f36385a.setColor(color);
    }
}
