package p9;

import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathMeasure;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.gms.measurement.internal.c2;
import kotlinx.coroutines.y;

/* JADX INFO: loaded from: classes2.dex */
public final class r extends p {

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public Pair f31889o;

    private void drawRoundedBlock(@NonNull Canvas canvas, @NonNull Paint paint, @NonNull o oVar, float f10, float f11, float f12, @Nullable o oVar2, float f13, float f14, float f15, boolean z10) {
        float f16;
        float f17;
        float f18;
        float fMin = Math.min(f11, this.f31881g);
        float f19 = (-f10) / 2.0f;
        float f20 = (-fMin) / 2.0f;
        float f21 = f10 / 2.0f;
        float f22 = fMin / 2.0f;
        RectF rectF = new RectF(f19, f20, f21, f22);
        paint.setStyle(Paint.Style.FILL);
        canvas.save();
        if (oVar2 != null) {
            float fMin2 = Math.min(f14, this.f31881g);
            float fMin3 = Math.min(f13 / 2.0f, (f15 * fMin2) / this.f31881g);
            RectF rectF2 = new RectF();
            float[] fArr = oVar2.f31872a;
            if (z10) {
                float f23 = (fArr[0] - fMin3) - (oVar.f31872a[0] - f12);
                if (f23 > 0.0f) {
                    oVar2.f((-f23) / 2.0f);
                    f18 = f13 + f23;
                } else {
                    f18 = f13;
                }
                rectF2.set(0.0f, f20, f21, f22);
                f16 = 2.0f;
            } else {
                float f24 = (fArr[0] + fMin3) - (oVar.f31872a[0] + f12);
                if (f24 < 0.0f) {
                    f16 = 2.0f;
                    oVar2.f((-f24) / 2.0f);
                    f17 = f13 - f24;
                } else {
                    f16 = 2.0f;
                    f17 = f13;
                }
                rectF2.set(f19, f20, 0.0f, f22);
                f18 = f17;
            }
            RectF rectF3 = new RectF((-f18) / f16, (-fMin2) / f16, f18 / f16, fMin2 / f16);
            canvas.translate(fArr[0], fArr[1]);
            float[] fArr2 = oVar2.f31873b;
            canvas.rotate(p.h(fArr2));
            Path path = new Path();
            path.addRoundRect(rectF3, fMin3, fMin3, Path.Direction.CCW);
            canvas.clipPath(path);
            canvas.rotate(-p.h(fArr2));
            canvas.translate(-fArr[0], -fArr[1]);
            float[] fArr3 = oVar.f31872a;
            canvas.translate(fArr3[0], fArr3[1]);
            canvas.rotate(p.h(oVar.f31873b));
            canvas.drawRect(rectF2, paint);
            canvas.drawRoundRect(rectF, f12, f12, paint);
        } else {
            float[] fArr4 = oVar.f31872a;
            canvas.translate(fArr4[0], fArr4[1]);
            canvas.rotate(p.h(oVar.f31873b));
            canvas.drawRoundRect(rectF, f12, f12, paint);
        }
        canvas.restore();
    }

    @Override // p9.p
    public final void a(Canvas canvas, Rect rect, float f10, boolean z10, boolean z11) {
        if (this.f31880f != rect.width()) {
            this.f31880f = rect.width();
            g();
        }
        float fE = e();
        canvas.translate((rect.width() / 2.0f) + rect.left, Math.max(0.0f, (rect.height() - fE) / 2.0f) + (rect.height() / 2.0f) + rect.top);
        d dVar = this.f31875a;
        if (((v) dVar).f31912q) {
            canvas.scale(-1.0f, 1.0f);
        }
        float f11 = this.f31880f / 2.0f;
        float f12 = fE / 2.0f;
        canvas.clipRect(-f11, -f12, f11, f12);
        this.f31881g = ((v) dVar).f31786a * f10;
        this.f31882h = Math.min(((v) dVar).f31786a / 2, ((v) dVar).a()) * f10;
        this.f31884j = ((v) dVar).f31797l * f10;
        this.f31883i = Math.min(((v) dVar).f31786a / 2.0f, ((v) dVar).e()) * f10;
        if (z10 || z11) {
            if ((z10 && ((v) dVar).f31792g == 2) || (z11 && ((v) dVar).f31793h == 1)) {
                canvas.scale(1.0f, -1.0f);
            }
            if (z10 || (z11 && ((v) dVar).f31793h != 3)) {
                canvas.translate(0.0f, ((1.0f - f10) * ((v) dVar).f31786a) / 2.0f);
            }
        }
        if (z11 && ((v) dVar).f31793h == 3) {
            this.f31888n = f10;
        } else {
            this.f31888n = 1.0f;
        }
    }

    @Override // p9.p
    public final void b(int i10, int i11, Canvas canvas, Paint paint) {
        int iA = h9.a.a(i10, i11);
        this.f31887m = false;
        v vVar = (v) this.f31875a;
        if (vVar.f31913r <= 0 || iA == 0) {
            return;
        }
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(iA);
        Integer num = vVar.trackStopIndicatorPadding;
        o oVar = new o(new float[]{(this.f31880f / 2.0f) - (num != null ? (vVar.f31913r / 2.0f) + num.floatValue() : this.f31881g / 2.0f), 0.0f}, new float[]{1.0f, 0.0f});
        int i12 = vVar.f31913r;
        drawRoundedBlock(canvas, paint, oVar, i12, i12, (this.f31882h * i12) / this.f31881g, null, 0.0f, 0.0f, 0.0f, false);
    }

    @Override // p9.p
    public final void c(Canvas canvas, Paint paint, n nVar, int i10) {
        int iA = h9.a.a(nVar.f31866c, i10);
        this.f31887m = nVar.f31871h;
        float f10 = nVar.f31864a;
        float f11 = nVar.f31865b;
        int i11 = nVar.f31867d;
        i(canvas, paint, f10, f11, iA, i11, i11, nVar.f31868e, nVar.f31869f, true);
    }

    @Override // p9.p
    public final void d(Canvas canvas, Paint paint, float f10, float f11, int i10, int i11, int i12) {
        int iA = h9.a.a(i10, i11);
        this.f31887m = false;
        i(canvas, paint, f10, f11, iA, i12, i12, 0.0f, 0.0f, false);
    }

    @Override // p9.p
    public final int e() {
        d dVar = this.f31875a;
        return (((v) dVar).f31797l * 2) + ((v) dVar).f31786a;
    }

    @Override // p9.p
    public final int f() {
        return -1;
    }

    @Override // p9.p
    public final void g() {
        Path path = this.f31876b;
        path.rewind();
        d dVar = this.f31875a;
        if (((v) dVar).b(this.f31887m)) {
            v vVar = (v) dVar;
            int i10 = this.f31887m ? vVar.f31795j : vVar.f31796k;
            float f10 = this.f31880f;
            int i11 = (int) (f10 / i10);
            this.f31885k = f10 / i11;
            for (int i12 = 0; i12 <= i11; i12++) {
                int i13 = i12 * 2;
                float f11 = i13 + 1;
                path.cubicTo(i13 + 0.48f, 0.0f, f11 - 0.48f, 1.0f, f11, 1.0f);
                float f12 = i13 + 2;
                path.cubicTo(f11 + 0.48f, 1.0f, f12 - 0.48f, 0.0f, f12, 0.0f);
            }
            Matrix matrix = this.f31879e;
            matrix.reset();
            matrix.setScale(this.f31885k / 2.0f, -2.0f);
            matrix.postTranslate(0.0f, 1.0f);
            path.transform(matrix);
        } else {
            path.lineTo(this.f31880f, 0.0f);
        }
        this.f31878d.setPath(path, false);
    }

    public final void i(Canvas canvas, Paint paint, float f10, float f11, int i10, int i11, int i12, float f12, float f13, boolean z10) {
        float f14;
        float fJ;
        float f15;
        Pair pair;
        float f16 = y.f(f10, 0.0f, 1.0f);
        float f17 = y.f(f11, 0.0f, 1.0f);
        float fJ2 = c2.j(1.0f - this.f31888n, 1.0f, f16);
        float fJ3 = c2.j(1.0f - this.f31888n, 1.0f, f17);
        int iF = (int) ((y.f(fJ2, 0.0f, 0.01f) * i11) / 0.01f);
        int iF2 = (int) (((1.0f - y.f(fJ3, 0.99f, 1.0f)) * i12) / 0.01f);
        float f18 = this.f31880f;
        int i13 = (int) ((fJ2 * f18) + iF);
        int i14 = (int) ((fJ3 * f18) - iF2);
        float f19 = this.f31882h;
        float f20 = this.f31883i;
        if (f19 != f20) {
            float fMax = Math.max(f19, f20);
            float f21 = this.f31880f;
            float f22 = fMax / f21;
            float fJ4 = c2.j(this.f31882h, this.f31883i, y.f(i13 / f21, 0.0f, f22) / f22);
            float f23 = this.f31882h;
            float f24 = this.f31883i;
            float f25 = this.f31880f;
            fJ = c2.j(f23, f24, y.f((f25 - i14) / f25, 0.0f, f22) / f22);
            f14 = fJ4;
        } else {
            f14 = f19;
            fJ = f14;
        }
        float f26 = (-this.f31880f) / 2.0f;
        v vVar = (v) this.f31875a;
        boolean z11 = vVar.b(this.f31887m) && z10 && f12 > 0.0f;
        if (i13 <= i14) {
            float f27 = i13 + f14;
            float f28 = i14 - fJ;
            float f29 = f14 * 2.0f;
            float f30 = fJ * 2.0f;
            paint.setColor(i10);
            paint.setAntiAlias(true);
            paint.setStrokeWidth(this.f31881g);
            Pair pair2 = this.f31889o;
            ((o) pair2.first).c();
            ((o) pair2.second).c();
            ((o) pair2.first).f(f27 + f26);
            ((o) pair2.second).f(f28 + f26);
            if (i13 == 0 && f28 + fJ < f27 + f14) {
                o oVar = (o) pair2.first;
                float f31 = this.f31881g;
                drawRoundedBlock(canvas, paint, oVar, f29, f31, f14, (o) pair2.second, f30, f31, fJ, true);
                return;
            }
            if (f27 - f14 > f28 - fJ) {
                o oVar2 = (o) pair2.second;
                float f32 = this.f31881g;
                drawRoundedBlock(canvas, paint, oVar2, f30, f32, fJ, (o) pair2.first, f29, f32, f14, false);
                return;
            }
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeCap(vVar.c() ? Paint.Cap.ROUND : Paint.Cap.BUTT);
            if (z11) {
                PathMeasure pathMeasure = this.f31878d;
                Path path = this.f31877c;
                float f33 = this.f31880f;
                float f34 = f27 / f33;
                float f35 = f28 / f33;
                int i15 = this.f31887m ? vVar.f31795j : vVar.f31796k;
                if (i15 != this.f31886l) {
                    this.f31886l = i15;
                    g();
                }
                path.rewind();
                float f36 = (-this.f31880f) / 2.0f;
                boolean zB = vVar.b(this.f31887m);
                if (zB) {
                    float f37 = this.f31880f;
                    float f38 = this.f31885k;
                    float f39 = f37 / f38;
                    float f40 = f13 / f39;
                    float f41 = f39 / (f39 + 1.0f);
                    f34 = (f34 + f40) * f41;
                    f35 = (f35 + f40) * f41;
                    f36 -= f38 * f13;
                }
                float length = pathMeasure.getLength() * f34;
                float length2 = pathMeasure.getLength() * f35;
                pathMeasure.getSegment(length, length2, path, true);
                o oVar3 = (o) pair2.first;
                oVar3.c();
                f15 = fJ;
                pathMeasure.getPosTan(length, oVar3.f31872a, oVar3.f31873b);
                o oVar4 = (o) pair2.second;
                oVar4.c();
                pathMeasure.getPosTan(length2, oVar4.f31872a, oVar4.f31873b);
                Matrix matrix = this.f31879e;
                matrix.reset();
                matrix.setTranslate(f36, 0.0f);
                oVar3.f(f36);
                oVar4.f(f36);
                if (zB) {
                    float f42 = this.f31884j * f12;
                    matrix.postScale(1.0f, f42);
                    oVar3.e(f42);
                    oVar4.e(f42);
                }
                path.transform(matrix);
                canvas.drawPath(path, paint);
            } else {
                float[] fArr = ((o) pair2.first).f31872a;
                float f43 = fArr[0];
                float f44 = fArr[1];
                float[] fArr2 = ((o) pair2.second).f31872a;
                canvas.drawLine(f43, f44, fArr2[0], fArr2[1], paint);
                f15 = fJ;
            }
            if (vVar.c()) {
                return;
            }
            if (f27 <= 0.0f || f14 <= 0.0f) {
                pair = pair2;
            } else {
                pair = pair2;
                drawRoundedBlock(canvas, paint, (o) pair2.first, f29, this.f31881g, f14, null, 0.0f, 0.0f, 0.0f, false);
            }
            if (f28 >= this.f31880f || f15 <= 0.0f) {
                return;
            }
            drawRoundedBlock(canvas, paint, (o) pair.second, f30, this.f31881g, f15, null, 0.0f, 0.0f, 0.0f, false);
        }
    }
}
