# Draw: Android's Squiggly Media Progress Bar

> Recreating Android 13's squiggly media-notification seek bar, a looping wavy line trimmed to an exact rounded tip with Canvas and Path.

**Date:** 2026-10-24T00:00:00.000Z
**Tags:** Draw, Canvas, Animation

## What we're building

Android 13 redrew the media-notification seek bar: the played portion of
the track draws as a squiggly sine wave instead of a straight line, the
unplayed remainder stays flat, and the whole thing settles back to a
straight line as soon as playback pauses. Any app that posts a
`MediaStyle` notification, Spotify and YouTube Music included, gets the
same look for free from the system.

![A real Android media notification showing a song playing, with the seek bar drawn as a squiggly wave instead of a straight line.](/posts/draw-android-squiggly-progress-bar/android-notification-4.webp)

*The real thing: Android's media-notification seek bar drawn as a squiggly wave while a track plays.*

There's no stock Composable for any of that. `LinearProgressIndicator`
draws one straight track. This needs a wave-shaped stroke that loops
seamlessly and trims to an exact position as playback advances. It also
has to flatten on demand and keep a cleanly rounded tip instead of a
clipped edge.

Full source: [`WavyLoaderScreen.kt`](https://github.com/rifqimfahmi/recomposed.blog-demo/blob/main/app/src/main/java/blog/recomposed/demosrecomposed/ui/screens/WavyLoaderScreen.kt).

## The intuition

* The wave doesn't need `sin()`. Each half-period is one quadratic
  Bézier in a
  `Path` (A Compose UI graphics object representing a sequence of line/curve segments, built point by point with moveTo/lineTo/quadraticTo.),
  with both endpoints on the center line and one control point pulling
  it up or down. All four steps below reuse that same two-curve bump.
* Trimming the wave to an exact tip and splitting it into
  played/unplayed both reduce to the same question: "where does this
  Bézier curve actually end, right now?" Step 3 answers it once with a
  curve-splitting formula. Step 4 reuses that answer with a moving
  playback position as the end instead of a fixed one.
* `StrokeCap.Round` only rounds a path's real endpoint. Clipping a wave
  to a window crops pixels and leaves a flat cut behind; trimming the
  curve itself is what gives the rounded cap an actual curve end to
  round off.

- [Traveling Wave Phase: Turning Position and Time Into One Angle](/traveling-wave-phase) — The phase math (position + time → one angle) the shift-as-phase trick in Step 2 is built on, generalized beyond a single scrolling line.

- [Quadratic vs Cubic Bezier vs Arc: Picking the Right Path Curve](/quadratic-cubic-bezier-and-arc) — Why quadraticTo is the right curve type for a wave's dip-then-rise shape, and when a cubic or arc would be the better call instead.

- [animate\*AsState vs Animatable: Animation Is Just an Interpolated Value](/compose-value-based-animation) — Why this post calls Animatable.animateTo directly inside a coroutine instead of animate\*AsState, letting amplitude, shift, and progress stage and cancel independently.

## Step 1: Sampling the wave as paired quadratic Béziers

```kotlin
// crop the drawing to exactly WAVE_COUNT waves wide
clipRect(
    left = 0f,
    top = center.y - (amplitude * 2),
    right = (waveLength * WAVE_COUNT),
    bottom = center.y + (amplitude * 2)
) {
    val path = Path().apply {
        moveTo(0f, center.y)

        repeat(WAVE_COUNT + 1) { idx ->
            val quarterWaveLength = waveLength / 4
            val startX = (waveLength * idx)
            val endX = waveLength * (idx + 1)
            val midPointX = startX + (endX - startX) / 2
            val controlPoint1 = Offset(
                x = startX + quarterWaveLength,
                y = center.y - (amplitude * 2)
            )
            val controlPoint2 = Offset(
                x = midPointX + quarterWaveLength,
                y = center.y + (amplitude * 2)
            )
            quadraticTo(x1 = controlPoint1.x, y1 = controlPoint1.y, x2 = midPointX, y2 = center.y)
            quadraticTo(x1 = controlPoint2.x, y1 = controlPoint2.y, x2 = endX, y2 = center.y)
        }
    }

    drawPath(
        path = path,
        color = theme.primary,
        style = Stroke(width = WAVE_WIDTH.toPx(), cap = StrokeCap.Round)
    )
}
```

![A single row of dip-rise wave bumps drawn inside a square box, no motion, no trimming.](/posts/draw-android-squiggly-progress-bar/step1-static-wave.webp)

*WaveStatic: one Path, two quadraticTo calls per bump, nothing animated yet.*

Every wave is two `quadraticTo` calls. Both curves start and end on
`center.y`, only the control point differs:

* The first curve's control point sits at `center.y - amplitude * 2`.
  Screen `y` grows downward, so this half bulges up.
* The second curve's control point sits at `center.y + amplitude * 2`,
  so it bulges down and lands back on `center.y` at `endX`.

The control point's `y` offset is `amplitude * 2`, not `amplitude`. A
quadratic Bézier's midpoint sits at *half* the control point's offset
from its endpoints, so doubling the control offset is what makes the
curve's actual visual peak equal `amplitude`.

`WAVE_COUNT + 1` waves get built, one more than fits inside the
`clipRect`. That spare wave hangs off the right edge, cropped away for
now, so there's always a full wave ready to slide in once Step 2 starts
scrolling this path.

## Step 2: Looping the wave with an animated phase shift

```kotlin
val shiftAnimatable = remember { Animatable(0f) }

LaunchedEffect(Unit) {
    shiftAnimatable.animateTo(
        targetValue = waveLength,
        animationSpec = infiniteRepeatable(
            animation = tween(durationMillis = 1000, easing = LinearEasing),
            repeatMode = RepeatMode.Restart
        )
    )
}

// same clipRect and path-building loop as Step 1, now offset by the animated shift
val path = Path().apply {
    moveTo(0f - shiftAnimatable.value, center.y)
    repeat(WAVE_COUNT + 1) { idx ->
        val startX = (waveLength * idx) - shiftAnimatable.value
        val endX = waveLength * (idx + 1) - shiftAnimatable.value
        // ...same control points and quadraticTo calls as Step 1
    }
}
```

[Video](/posts/draw-android-squiggly-progress-bar/step2-loop.mp4)

*The wave scrolling continuously. The phase loop is seamless, there's no visible jump at the wrap point.*

Subtracting an animated `shift` value from every sampled `x` slides the
whole wave pattern left. Animating `shift` from `0` to one `waveLength`
with `infiniteRepeatable`/`RepeatMode.Restart` makes it jump back to `0`
every 1000ms.

The wave repeats every `waveLength`, so inside the `clipRect` window,
`shift = 0` and `shift = waveLength` draw pixel-identical curves. The
jump is invisible because it's a jump between two frames that look the
same. Outside the window the path's ends do move, which is exactly what
the clip is there to hide.

## Step 3: Trimming the tip exactly, without clipping

```kotlin
// blends a and b by fraction t: t=0 returns a, t=1 returns b
private fun lerp(a: Offset, b: Offset, t: Float): Offset =
    Offset(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t)

// De Casteljau split: returns the control points of quadratic Bézier (p0, c, p2)
// restricted to the parameter range [t0, t1], reparameterized back to [0, 1].
private fun trimQuadratic(
    p0: Offset, c: Offset, p2: Offset,
    t0: Float, t1: Float,
): Triple<Offset, Offset, Offset> {
    val q0 = lerp(p0, c, t0)
    val q1 = lerp(c, p2, t0)
    val tailP0 = lerp(q0, q1, t0)
    if (t1 >= 1f) return Triple(tailP0, q1, p2)

    val t1Prime = (t1 - t0) / (1f - t0)
    val s0 = lerp(tailP0, q1, t1Prime)
    val s1 = lerp(q1, p2, t1Prime)
    val headP2 = lerp(s0, s1, t1Prime)
    return Triple(tailP0, s0, headP2)
}
```

Steps 1 and 2 end the wave with `clipRect`, and a clip only crops
pixels. The path itself keeps going past the window, so
`StrokeCap.Round` never sees an endpoint to round. The stroke just stops
dead at the window's straight edge, mid-curve, with a flat cut.

Getting an actual rounded tip means the curve itself has to end exactly
at the boundary, which means it has to be a *different*, shorter curve,
not a cropped one. Repeatedly lerping (Linear interpolation: blending two points by a fraction t, t=0 returns the first point, t=1 returns the second.)
between a Bézier's own points at a parameter `t` is De Casteljau's
algorithm (Evaluating or splitting a Bezier curve at a parameter t by recursively lerping its control points toward each other.), and it's how you split a curve into two curves
that are each still valid Béziers, with an exact shared point at `t`.

`trimQuadratic` applies that split twice: once at `t0` to drop the part
before it, once at `t1` to drop the part after it.

The second split can't reuse `t1` as-is, though. `t1` was a fraction of
the *original* curve, but by the time the second split runs, the first
split has already shortened it down to `(tailP0, q1, p2)`. `t1Prime`
rescales `t1` against that shorter remainder before the second split
runs on it, and the function returns that remainder's three points.

*\[Interactive demo: DeCasteljauTrimDemo — view this post in a browser for the live version.]*

`P0`, `C`, and `P2` in the demo are the same-named parameters
`trimQuadratic` takes in: the curve's fixed start, control, and end
points. Drag either handle along the curve to pick `t0` or `t1`.

The thin line that lights up while dragging is `Q0`-`Q1`, the segment
the second lerp runs along. The handle itself is where that lerp lands,
`tailP0` or `headP2` depending on which handle moved. The solid middle
segment is `trimQuadratic`'s actual return value, not a cropped copy of
the original curve.

```kotlin
repeat(WAVE_COUNT + 1) { idx ->
    val segmentStart = (waveLength * idx) - shiftAnimatable.value

    // each full wave is two quadratic halves: dip down, then rise back up
    for (half in 0..1) {
        val halfStart = segmentStart + half * halfWaveLength
        val halfEnd = halfStart + halfWaveLength
        if (halfEnd <= leftBound || halfStart >= rightBound) continue

        val controlYOffset = if (half == 0) -amplitude * 2 else amplitude * 2
        val p0 = Offset(halfStart, center.y)
        val c = Offset(halfStart + quarterWaveLength, center.y + controlYOffset)
        val p2 = Offset(halfEnd, center.y)

        val t0 = if (halfStart < leftBound) (leftBound - halfStart) / halfWaveLength else 0f
        val t1 = if (halfEnd > rightBound) (rightBound - halfStart) / halfWaveLength else 1f

        val (trimmedP0, trimmedC, trimmedP2) = trimQuadratic(p0, c, p2, t0, t1)

        if (!started) {
            path.moveTo(trimmedP0.x, trimmedP0.y)
            started = true
        }
        path.quadraticTo(trimmedC.x, trimmedC.y, trimmedP2.x, trimmedP2.y)
    }
}
```

The draw loop walks each half-wave and computes `t0`/`t1` as the
fraction of *that half* that actually falls inside `[leftBound,
rightBound]`. A half entirely inside the window gets `t0 = 0`, `t1 = 1`,
meaning "use the whole half, trim nothing." Only the one or two halves a
boundary actually cuts through get a real trim.

*\[Interactive demo: WaveTrimLoopDemo — view this post in a browser for the live version.]*

[Video](/posts/draw-android-squiggly-progress-bar/step3-trim-loop.mp4)

*The looping wave with the exact trim applied. Both ends stay rounded at every phase of the loop, where Step 2's clipRect left a flat cut.*

This version drops the `clipRect` entirely. The path now really ends at
`leftBound` and `rightBound`, so `StrokeCap.Round` rounds both ends
exactly, at any phase of the loop.

## How De Casteljau's algorithm actually splits a curve

For a quadratic Bézier, evaluating the curve at any `t` comes down to
three lerps, run in this order:

* `lerp(p0, c, t)`, call the result `q0`
* `lerp(c, p2, t)`, call the result `q1`
* `lerp(q0, q1, t)`, the curve's actual position at `t`

The first two don't depend on each other; they both just blend between
the original three points. The third one is what actually uses them,
blending `q0` and `q1` together.

`trimQuadratic` runs those exact same first two lerps, naming the
results `q0` and `q1`. The draggable demo above already shows them:
`Q0`-`Q1` is the thin segment that lights up while dragging.

The difference is what happens next. Evaluating the curve collapses
`q0` and `q1` into one final point and throws them away. Splitting it
stops one lerp early and keeps them, because `q0`, `q1`, and that final
blended point, `tailP0`, are themselves the three control points of a
new, shorter Bézier.

Two such triples exist for every split: `(p0, q0, tailP0)` covers the
curve from `0` to `t`, and `(tailP0, q1, p2)` covers `t` to `1`. They
meet exactly at `tailP0` because that point was built by blending both
halves together in the first place, not by picking a point on the
original curve and hoping it lines up. `trimQuadratic` only ever keeps
the second triple, since every call is trimming away everything
*before* some `t`, whether that's the real `t0` or the rescaled
`t1Prime`.

## Step 4: Splitting played/unplayed and flattening on pause

```kotlin
var isPlaying by remember { mutableStateOf(true) }
val shiftAnimatable = remember { Animatable(0f) }
val amplitudeAnimatable = remember { Animatable(fullAmplitude) }
val progressAnimatable = remember { Animatable(0f) }

LaunchedEffect(isPlaying) {
    if (isPlaying) {
        amplitudeAnimatable.animateTo(fullAmplitude, animationSpec = tween(300))

        launch {
            shiftAnimatable.animateTo(
                targetValue = shiftAnimatable.value + waveLength,
                animationSpec = infiniteRepeatable(
                    animation = tween(durationMillis = 1000, easing = LinearEasing),
                    repeatMode = RepeatMode.Restart
                )
            )
        }

        val remainingMillis = ((1f - progressAnimatable.value) * PLAYBACK_DURATION_MILLIS).toInt()
        progressAnimatable.animateTo(
            targetValue = 1f,
            animationSpec = tween(durationMillis = remainingMillis.coerceAtLeast(1), easing = LinearEasing)
        )
    } else {
        amplitudeAnimatable.animateTo(0f, animationSpec = tween(300))
    }
}
```

This reuses Step 3's exact trim unchanged. The only swap is the trim
bound: the loop's fixed `rightBound` becomes a moving `progressX`,
driven by its own `Animatable`. The same rounded-tip math now produces a
tip that visibly grows as playback advances, not just a static loop
edge.

```kotlin
val progressX = leftBound + progressAnimatable.value * (rightBound - leftBound)

// ...same trimQuadratic loop as Step 3, culled and trimmed against
// progressX instead of rightBound...

drawPath(path = wavyPath, color = theme.primary, style = Stroke(WAVE_WIDTH.toPx(), cap = StrokeCap.Round))

// Skipped once progress reaches the end: a zero-length line still
// renders its StrokeCap.Round as a filled dot, pinned at rightBound
// forever while the wavy portion keeps animating past it.
if (progressX < rightBound) {
    drawLine(
        color = theme.primary.copy(alpha = 0.3f),
        start = Offset(progressX, center.y),
        end = Offset(rightBound, center.y),
        strokeWidth = WAVE_WIDTH.toPx(),
        cap = StrokeCap.Round
    )
}
```

The unplayed remainder is just a flat `drawLine` from `progressX` to
`rightBound` at a lower alpha. It's skipped once `progressX` reaches
`rightBound`, because a zero-length line still renders its
`StrokeCap.Round` as a filled dot. That dot stays pinned at one screen
position while the wavy portion keeps looping past it, which reads as
the stroke snapping in place.

[Video](/posts/draw-android-squiggly-progress-bar/demo.mp4)

*Playback advances the wavy tip and the dim remainder shrinks; pausing flattens the whole bar; resuming grows it back and the loop continues from the same phase.*

Pausing tears down the shift loop (`LaunchedEffect(isPlaying)` cancels
its old coroutine the instant the key changes) and eases `amplitude`
toward `0` over a short tween. Every curve's anchor points already sit
on `center.y`, only the control points move, so shrinking `amplitude`
to `0` degenerates the whole wavy portion into the same flat line the
unplayed remainder already was. No separate flatten path needed.

> **Resuming an infiniteRepeatable**
>
> `animateTo(targetValue, infiniteRepeatable(...))` locks in whatever
> initial/target pair is active the moment it's called, and
> `RepeatMode.Restart` replays that exact pair forever, jumping back to
> the call's *initial* value, not to `0`. A literal `waveLength` target
> works the first time, since the shift starts at `0`. Every resume after
> a pause starts from wherever the shift was frozen instead, so the
> target has to track `shiftAnimatable.value + waveLength`, not a fixed
> literal, or every resumed loop snaps to whatever arbitrary phase it
> happened to pause at.

## Variations and tradeoffs

* **Clipping vs. trimming.** Step 2's `clipRect` is one call and costs
  nothing extra per curve. It's a fine choice when the wave's ends are
  hidden anyway, under a thumb or flush with a container edge. It can
  never produce a rounded tip, though, which is why Steps 3 and 4 trim
  the curve instead.
* **Sampling resolution is fixed at wave level, not pixel level.**
  Because each half-wave is one quadratic curve, not a run of line
  segments, `WAVE_COUNT` controls how many bumps fit, not how smooth
  any one bump is. Each extra wave costs two more `trimQuadratic` calls
  per frame (one per half), not hundreds of extra sample points the way
  a `lineTo`-based approach would.
* **`PLAYBACK_DURATION_MILLIS` and the shift loop's speed are
  independent knobs.** The 1000ms-per-wavelength ripple tween never
  reads `PLAYBACK_DURATION_MILLIS`. Playback speed and the wave's own
  travel speed can be tuned separately without touching each other's
  math.
* **Resume regrows the wave before it moves.** `LaunchedEffect(isPlaying)`
  awaits the 300ms amplitude tween before launching the shift loop and
  the progress tween. So on resume the wave grows back frozen in place,
  then starts scrolling. Launch the amplitude tween in its own `launch`
  block too if all three should start together.
* **The zero-length-line dot only shows up at full progress.** That
  makes it easy to ship and easy to miss in a quick check, since most
  manual testing happens mid-playback. Worth deliberately checking both
  progress endpoints, `0` and `1`, not just the middle, whenever a bar
  like this splits a stroke into two differently styled segments.


---

Canonical page: https://recomposed.blog/draw-android-squiggly-progress-bar