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.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.ColorInt;
import androidx.appcompat.widget.AppCompatImageView;

/* JADX INFO: loaded from: classes3.dex */
public class RoundImageView extends AppCompatImageView {
    public final Paint Q;
    public final Path R;
    public final RectF S;

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public boolean f36347k;

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

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

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

    public final void c() {
        Paint paint = this.Q;
        if (paint != null) {
            paint.setColor(this.f36348l);
            this.Q.setStrokeWidth(this.f36349m);
            this.Q.setStyle(Paint.Style.STROKE);
        }
    }

    @Override // android.widget.ImageView, android.view.View
    public void onDraw(Canvas canvas) {
        Paint paint;
        float f10 = this.f36349m / 2.0f;
        float f11 = this.f36342f;
        Path path = this.R;
        if (f11 > 0.0f || this.f36343g > 0.0f || this.f36344h > 0.0f || this.f36345i > 0.0f || this.f36346j > 0.0f) {
            Path path2 = this.f36340d;
            path2.reset();
            path.reset();
            if (this.f36347k) {
                float f12 = this.f36342f;
                path2.addCircle(f12, f12, f12, Path.Direction.CW);
            } else {
                if (this.f36343g == 0.0f) {
                    this.f36343g = this.f36342f;
                }
                if (this.f36344h == 0.0f) {
                    this.f36344h = this.f36342f;
                }
                if (this.f36345i == 0.0f) {
                    this.f36345i = this.f36342f;
                }
                if (this.f36346j == 0.0f) {
                    this.f36346j = this.f36342f;
                }
                float[] fArr = new float[8];
                float f13 = this.f36343g;
                fArr[0] = f13;
                fArr[1] = f13;
                float f14 = this.f36344h;
                fArr[2] = f14;
                fArr[3] = f14;
                float f15 = this.f36346j;
                fArr[4] = f15;
                fArr[5] = f15;
                float f16 = this.f36345i;
                fArr[6] = f16;
                fArr[7] = f16;
                RectF rectF = this.S;
                rectF.set(getPaddingLeft() + f10, getPaddingTop() + f10, (getMeasuredWidth() - getPaddingRight()) - f10, (getMeasuredHeight() - getPaddingBottom()) - f10);
                path.addRoundRect(rectF, fArr, Path.Direction.CW);
                if (f10 > 0.0f) {
                    for (int i10 = 0; i10 < 8; i10++) {
                        float f17 = fArr[i10];
                        if (f17 > 0.0f) {
                            fArr[i10] = f17 + f10;
                        }
                    }
                }
                RectF rectF2 = this.f36341e;
                rectF2.set(getPaddingLeft(), getPaddingTop(), getMeasuredWidth() - getPaddingRight(), getMeasuredHeight() - getPaddingBottom());
                path2.addRoundRect(rectF2, fArr, Path.Direction.CW);
            }
            canvas.clipPath(path2);
        }
        super.onDraw(canvas);
        float f18 = this.f36349m;
        if (f18 <= 0.0f || (paint = this.Q) == null) {
            return;
        }
        if (!this.f36347k) {
            canvas.drawPath(path, paint);
        } else {
            float f19 = this.f36342f;
            canvas.drawCircle(f19, f19, f19 - (f18 / 2.0f), paint);
        }
    }

    @Override // android.widget.ImageView, android.view.View
    public void onMeasure(int i10, int i11) {
        int size = View.MeasureSpec.getSize(i10);
        int size2 = View.MeasureSpec.getSize(i11);
        if (!this.f36347k || size <= 0 || size2 <= 0 || size == size2) {
            super.onMeasure(i10, i11);
        } else {
            int iMin = Math.min(size, size2);
            setMeasuredDimension(iMin, iMin);
        }
    }

    @Override // android.view.View
    public void onSizeChanged(int i10, int i11, int i12, int i13) {
        super.onSizeChanged(i10, i11, i12, i13);
        if (!this.f36347k || this.f36342f > 0.0f) {
            return;
        }
        this.f36342f = Math.min(i10, i11) / 2.0f;
    }

    public void setRadius(float f10) {
        this.f36342f = f10;
        this.f36343g = 0.0f;
        this.f36344h = 0.0f;
        this.f36345i = 0.0f;
        this.f36346j = 0.0f;
        c();
        invalidate();
    }

    public void setRadiusAndBorder(float f10, float f11, @ColorInt int i10, boolean z10) {
        this.f36342f = f10;
        this.f36349m = f11;
        this.f36348l = i10;
        this.f36347k = z10;
        c();
    }

    public RoundImageView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public void setRadiusAndBorder(float f10, float f11, float f12, float f13, float f14, @ColorInt int i10) {
        this.f36343g = f10;
        this.f36344h = f11;
        this.f36345i = f12;
        this.f36346j = f13;
        this.f36349m = f14;
        this.f36348l = i10;
        c();
    }

    public RoundImageView(Context context, AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        this.f36340d = new Path();
        this.f36341e = new RectF();
        this.f36342f = 0.0f;
        this.f36343g = 0.0f;
        this.f36344h = 0.0f;
        this.f36345i = 0.0f;
        this.f36346j = 0.0f;
        this.f36347k = false;
        this.f36348l = 0;
        this.f36349m = 0.0f;
        this.R = new Path();
        this.S = new RectF();
        if (attributeSet != null) {
            TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.RoundImageView);
            this.f36347k = typedArrayObtainStyledAttributes.getBoolean(R.styleable.RoundImageView_riv_roundAsCircle, false);
            this.f36348l = typedArrayObtainStyledAttributes.getColor(R.styleable.RoundImageView_riv_borderColor, 0);
            this.f36349m = typedArrayObtainStyledAttributes.getDimension(R.styleable.RoundImageView_riv_borderWidth, 0.0f);
            this.f36342f = typedArrayObtainStyledAttributes.getDimension(R.styleable.RoundImageView_riv_radius, 0.0f);
            this.f36343g = typedArrayObtainStyledAttributes.getDimension(R.styleable.RoundImageView_riv_topLeft_radius, 0.0f);
            this.f36344h = typedArrayObtainStyledAttributes.getDimension(R.styleable.RoundImageView_riv_topRight_radius, 0.0f);
            this.f36345i = typedArrayObtainStyledAttributes.getDimension(R.styleable.RoundImageView_riv_bottomLeft_radius, 0.0f);
            this.f36346j = typedArrayObtainStyledAttributes.getDimension(R.styleable.RoundImageView_riv_bottomRight_radius, 0.0f);
            typedArrayObtainStyledAttributes.recycle();
        }
        this.Q = new Paint(1);
        c();
    }
}
