18 Commits
Author SHA1 Message Date
nilsandClaude Sonnet 5.5 bf6038fd37 App 2.49.0: the Caterpillar style
A cut-paper collage after a picture book about a hungry caterpillar:
the caterpillar is the speed and power, the sun the battery, the story's
fruit the range. The music light bounces the sun and the segments. A
butterfly or a ladybird tows the song on tissue paper.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-07 10:07:02 +01:00
nilsandClaude Sonnet 5.5 5cbd6699aa SPECS: app 2.48.0 published
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-07 09:13:22 +01:00
nilsandClaude Sonnet 5.5 ff204caa52 App 2.48.0: the Christmas style
A tree with a bauble for the speed, fairy lights for the power, a mug of
cocoa for the battery, a wreath clock and candy canes for the range. Its
lights flare on the beat with the music light, now "Light follows the
music" for Halloween and Christmas. A sleigh or an angel tows the song.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-07 09:13:08 +01:00
nilsandClaude Sonnet 5.5 69ccf0d5fd SPECS: app 2.47.0 published
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-02 22:20:17 +01:00
nilsandClaude Sonnet 5.5 d80221db15 App 2.47.0: now playing in Quest, Empire, Terminal and Sci-fi
Quest: a dragon tows a scroll. Empire: an eagle flies one. Terminal: a
PLAYING row. Sci-fi: the song in black on the top bar.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-02 22:20:11 +01:00
nilsandClaude Sonnet 5.5 83dc8b231d SPECS: app 2.46.0 published
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-02 17:48:49 +01:00
nilsandClaude Sonnet 5.5 cdf78c6d32 App 2.46.0: Día de Muertos shows what plays
A strip of papel picado with the song waves across the sky, towed by a
monarch butterfly and, on the next pass, an alebrije. One flag colour per
song. The banner moved into the shared SongBanner; Halloween is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-02 17:48:35 +01:00
nilsandClaude Opus 5.5 a445fef407 SPECS: app 2.45.2 published
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-02 14:45:41 +01:00
nilsandClaude Opus 5.5 f9813c2afd App 2.45.2: Halloween's song banner waves
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-02 14:45:35 +01:00
nilsandClaude Opus 5.5 3a532cd498 SPECS: app 2.45.1 published
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-02 14:33:20 +01:00
nilsandClaude Opus 5.5 06a61282a6 App 2.45.1: Halloween's song flies across the sky on a bat's banner
Instead of a line at the foot of the hill, a bat tows a parchment
banner with the title and artist through the sky above the sign.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-02 14:33:14 +01:00
nilsandClaude Opus 5.5 ed32fbbc1f SPECS: app 2.45.0 published
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-02 14:03:44 +01:00
nilsandClaude Opus 5.5 91283093f5 App 2.45.0: now playing on the Overview
NowPlayingWatcher follows the head unit's media sessions (listening
only, never connecting to a player); NowPlaying picks what plays and
cleans the text. Tiles shows source, title, artist, cover and progress
under the battery; Halloween carves title and artist into the hill.
Settings: "Show what's playing", on by default. Nothing is logged or
sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-02 14:03:26 +01:00
nilsandClaude Opus 5.5 bdb3f5e765 SPECS: app 2.44.0 published
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-02 13:15:41 +01:00
nilsandClaude Opus 5.5 9d84dc6d15 App 2.44.0: the pumpkin light follows the kick drum, behind a switch
MusicPulse reads 40-120 Hz and lights only on jumps of the bass, so
held notes and bass lines stay dark. Settings gets "Pumpkin light
follows the music" (Halloween only, off by default); off, the audio
analyser never starts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-02 13:15:25 +01:00
nilsandClaude Opus 5.5 418883beb0 SPECS: app 2.43.5 published
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-01 10:21:26 +01:00
nilsandClaude Opus 5.5 e52d7f01fc App 2.43.5: update checks log what happens
Each check writes down the networks Android sees, the server's name lookup,
how a failure happened and how many reports wait, and on a failure whether
the internet answers at all, to tell a SIM without data from a server that is
down. The report goes to a USB stick and, once online, the server. No address
or token is written. Tried on the emulator. Not tried on the car.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-01 10:21:15 +01:00
nilsandClaude Opus 5.5 6b55bec419 SPECS: app 2.43.4 published
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
2026-11-01 10:08:03 +01:00
45 changed files with 2952 additions and 46 deletions
+9 -1
View File
@@ -79,9 +79,17 @@ analyser's peak, bass, mid, treble and rms, and a result line. Levels only, no s
to move for music to count as heard. Ask what was playing when the check ran, and whether the to move for music to count as heard. Ask what was playing when the check ran, and whether the
music kept playing and any prompt came up. music kept playing and any prompt came up.
## Update checks
`fetch-logs` also brings `update-check-YYYYMMDD-HHMMSS.txt` (each Settings → Check for updates,
`UpdateHook`, 2.43.5 on): the networks Android sees, whether the server's name resolves, the
result and, on a failure, whether `www.gstatic.com/generate_204` answers (204: the internet
works, so look at the server). A report written offline arrives once the car is back online, or
is on a USB stick that was plugged in.
## Rules ## Rules
- Recordings and checks are the car's data: `logs/`, `/signal-recording-*.txt` and - Recordings and checks are the car's data: `logs/`, `/signal-recording-*.txt` and
`/media-probe-*.txt`, `/sound-probe-*.txt` are gitignored. Never `/media-probe-*.txt`, `/sound-probe-*.txt`, `/update-check-*.txt` are gitignored. Never
commit, publish or upload them anywhere. commit, publish or upload them anywhere.
- Findings that change what the project knows go into a `SPECS.md` done-log entry, as usual. - Findings that change what the project knows go into a `SPECS.md` done-log entry, as usual.
+1
View File
@@ -47,3 +47,4 @@ mise.local.toml
/signal-recording-*.txt /signal-recording-*.txt
/media-probe-*.txt /media-probe-*.txt
/sound-probe-*.txt /sound-probe-*.txt
/update-check-*.txt
+2 -2
View File
@@ -77,12 +77,12 @@ Repository: `ssh://git@git.stinnesbeck.com:2222/nils/mg4.git` (remote `origin`),
| Tab | Contents | | Tab | Contents |
|---|---| |---|---|
| Overview | value tiles (battery, range, range/usage/energy since start, 5-min averages of range, usage, power, speed), vehicle info (odometer, lease allowance and the odometer against it), tyre pressures; read every 0.2 s on a background thread. Styles (Settings → Overview style): Tiles, Gauges (`GaugeView` needles), Cockpit (`RingView` rings, `TraceView` power trace), Retro (`RetroView`, seven-segment VFD), Futuristic (`FlowView`, animated energy flow), Sci-fi (`SciFiView`, starship console), Cartoon (`CartoonView`), MG (`OctagonView`, octagonal dials after the classic MG dashboards), and on `ClusterCanvasView`: Minimal, Terminal, Nixie tubes, Chronograph, Grid (`GridView`, neon lines over a moving grid floor, power as a light-cycle trail from `ClusterValues.powerTrail`), Grid with map (the same `GridView` over the roads round the car, top-down: GPS while it is shown, tiles from the server's `/v1/map/roads` through `MapRoads`, cached in `files/map`; `RoadTile`, `MapGeometry`; the map is `MapLayerView`, a hardware layer drawn once and moved and turned by the GPU every display frame), Time circuits (`TimeCircuitsView`, the time machine's LED rows with `Segments14` letters and a flux capacitor), Quest (`QuestView`, a fantasy game interface), Visor (`VisorView`, a helmet display with a motion tracker of the power trail), Empire (`EmpireView`, a strategy game with an isometric world and ages by odometer, `EmpireAge`), Día de Muertos (`MuertosView`, an ofrenda: papel picado, candles, a calavera in a ring of marigolds), Halloween (`HalloweenView`, a jack-o'-lantern, a potion flask, a tombstone on a graveyard hill), both counting with `Tally`, the pumpkin's light following the music on screen (`MusicTap`, `MusicPulse`: Android's audio analyser, levels only; Bluetooth and CarPlay, not the radio); the drawn styles share `ClusterValues`. A style shown in its own palette (Sci-fi, Cartoon, Nixie, Time circuits, Quest, Empire, Día de Muertos, Halloween; Retro, Terminal, Grid and Visor with "Original") gives the whole app its colours (`StylePalette`, `res/values/style_palettes.xml`) instead of the accent colour. A button in the navigation's header hides the navigation for a full-width Overview (`PREF_OVERVIEW_FULLSCREEN`); a swipe in from the left edge (`EdgeSwipe`) brings it back; without the app's own full screen the car's sidebar takes that edge, so a tab at the left edge (`edge_tab`) is tapped or swiped instead. Pages change only by the navigation (the pager's own swiping is off) | | Overview | value tiles (battery, range, range/usage/energy since start, 5-min averages of range, usage, power, speed, and under the battery what plays: `NowPlaying` picks from the media sessions `NowPlayingWatcher` follows — listened to only, never connected to, nothing logged or sent; Tiles, Terminal, Sci-fi, Quest, Empire, Día de Muertos, Halloween, Christmas and Caterpillar, Settings → "Show what's playing", `PREF_NOW_PLAYING`, on by default), vehicle info (odometer, lease allowance and the odometer against it), tyre pressures; read every 0.2 s on a background thread. Styles (Settings → Overview style): Tiles, Gauges (`GaugeView` needles), Cockpit (`RingView` rings, `TraceView` power trace), Retro (`RetroView`, seven-segment VFD), Futuristic (`FlowView`, animated energy flow), Sci-fi (`SciFiView`, starship console), Cartoon (`CartoonView`), MG (`OctagonView`, octagonal dials after the classic MG dashboards), and on `ClusterCanvasView`: Minimal, Terminal, Nixie tubes, Chronograph, Grid (`GridView`, neon lines over a moving grid floor, power as a light-cycle trail from `ClusterValues.powerTrail`), Grid with map (the same `GridView` over the roads round the car, top-down: GPS while it is shown, tiles from the server's `/v1/map/roads` through `MapRoads`, cached in `files/map`; `RoadTile`, `MapGeometry`; the map is `MapLayerView`, a hardware layer drawn once and moved and turned by the GPU every display frame), Time circuits (`TimeCircuitsView`, the time machine's LED rows with `Segments14` letters and a flux capacitor), Quest (`QuestView`, a fantasy game interface), Visor (`VisorView`, a helmet display with a motion tracker of the power trail), Empire (`EmpireView`, a strategy game with an isometric world and ages by odometer, `EmpireAge`), Día de Muertos (`MuertosView`, an ofrenda: papel picado, candles, a calavera in a ring of marigolds), Halloween (`HalloweenView`, a jack-o'-lantern, a potion flask, a tombstone on a graveyard hill), Christmas (`ChristmasView`, a tree with a bauble, fairy lights, a mug of cocoa, a wreath clock and candy canes in the snow), Caterpillar (`CaterpillarView`, cut-paper collage after a picture book: the caterpillar is speed and power, the sun the battery, fruit the range), all counting with `Tally`, the pumpkin's light, Christmas's tree lights and the Caterpillar's sun flaring on the kick drum while on screen, when "Light follows the music" is on (off by default, `PREF_MUSIC_LIGHT`; `MusicTap`, `MusicPulse`: Android's audio analyser, 40–120 Hz, jumps not levels; Bluetooth and CarPlay, not the radio); the drawn styles share `ClusterValues`. A style shown in its own palette (Sci-fi, Cartoon, Nixie, Time circuits, Quest, Empire, Día de Muertos, Halloween, Christmas, Caterpillar; Retro, Terminal, Grid and Visor with "Original") gives the whole app its colours (`StylePalette`, `res/values/style_palettes.xml`) instead of the accent colour. A button in the navigation's header hides the navigation for a full-width Overview (`PREF_OVERVIEW_FULLSCREEN`); a swipe in from the left edge (`EdgeSwipe`) brings it back; without the app's own full screen the car's sidebar takes that edge, so a tab at the left edge (`edge_tab`) is tapped or swiped instead. Pages change only by the navigation (the pager's own swiping is off) |
| Consumption / Charging | period totals, daily log, charging sessions and curve | | Consumption / Charging | period totals, daily log, charging sessions and curve |
| Live data | on/off, ABRP API key and user token, upload frequency | | Live data | on/off, ABRP API key and user token, upload frequency |
| Server | URL, pairing by QR, ingest token, installation ID (read-only), config import | | Server | URL, pairing by QR, ingest token, installation ID (read-only), config import |
| Settings | drive mode (Eco, Normal, Sport, Snow, Custom; the lit one is what the car reports; changes only in P at a standstill, `DriveModeWrite`; "Set at start" sets the last confirmed choice again when the service starts with the head unit), full screen, voice key, Overview style with the accent colour beside it (offered only for styles drawn in it, `OverviewStyle.usesAccent`; Retro, Terminal, Grid (and Grid with map, sharing Grid's choice) and Visor add "Original" for their own palette, `hasOriginal`), tyre unit, battery and charging price (one card on wide screens), version, update check, install from USB, About | | Settings | drive mode (Eco, Normal, Sport, Snow, Custom; the lit one is what the car reports; changes only in P at a standstill, `DriveModeWrite`; "Set at start" sets the last confirmed choice again when the service starts with the head unit), full screen, voice key, Overview style with the accent colour beside it (offered only for styles drawn in it, `OverviewStyle.usesAccent`; Retro, Terminal, Grid (and Grid with map, sharing Grid's choice) and Visor add "Original" for their own palette, `hasOriginal`), tyre unit, battery and charging price (one card on wide screens), version, update check, install from USB, About |
| Logs | signal recorder (`SignalRecorder`/`SignalRecording`: every property and vendor getter via `VendorSurfaceProbe.capture`, again and again for 3 minutes, plus change events of the driver-assistance block it subscribes to, `EVHardware.listenToProperties` with `AssistBlock`, and steering-wheel key broadcasts; lists what changed, rarest first; saved to the app, a USB stick and the server, through `LogOutbox`, which sends it again later when the car is offline; how to find where the car publishes something), music-sources check (`MediaProbe`: audio players and the active media sessions, CarPlay's and Bluetooth's among them, with their song, and the media browser services by name — never connected to: binding them stopped the music in 2.42.0; saved and sent like a recording), sound check (`SoundProbe`, `SoundLevels`: on a tap, 10 seconds of levels from Android's audio analyser, to learn whether it hears what plays; saved and sent like a recording), update log (every install step, with the platform's words), upload log | | Logs | signal recorder (`SignalRecorder`/`SignalRecording`: every property and vendor getter via `VendorSurfaceProbe.capture`, again and again for 3 minutes, plus change events of the driver-assistance block it subscribes to, `EVHardware.listenToProperties` with `AssistBlock`, and steering-wheel key broadcasts; lists what changed, rarest first; saved to the app, a USB stick and the server, through `LogOutbox`, which sends it again later when the car is offline; how to find where the car publishes something), music-sources check (`MediaProbe`: audio players and the active media sessions, CarPlay's and Bluetooth's among them, with their song, and the media browser services by name — never connected to: binding them stopped the music in 2.42.0; saved and sent like a recording), sound check (`SoundProbe`, `SoundLevels`: on a tap, 10 seconds of levels from Android's audio analyser, to learn whether it hears what plays; saved and sent like a recording), update log (every check and install step, with the platform's words; a check also writes down the networks, the server's name lookup and, when it fails, an internet test, `UpdateNetworkCheck`, `UpdateDiagnosis`, and saves a report like a recording), upload log |
Key classes (`app/src/main/java/com/evsuite/abrp/`): `AbrpUploadService` (foreground service, Key classes (`app/src/main/java/com/evsuite/abrp/`): `AbrpUploadService` (foreground service,
15 s tick), `TelemetryUploader` (+ `TelemetryQueue`, persisted), `TelemetryPayload` (server 15 s tick), `TelemetryUploader` (+ `TelemetryQueue`, persisted), `TelemetryPayload` (server
+5 -1
View File
@@ -89,7 +89,11 @@ platform's own words, is on the Logs tab under "Updates".
| `Installation failed: INSTALL_FAILED_… The APK is in Downloads.` | The package manager's own words. A signature error means the APK was not signed by `build-car`. | | `Installation failed: INSTALL_FAILED_… The APK is in Downloads.` | The package manager's own words. A signature error means the APK was not signed by `build-car`. |
| `… is in Downloads — tap the file to install` | A session could not start; install from Downloads by hand. | | `… is in Downloads — tap the file to install` | A session could not start; install from Downloads by hand. |
On the car's Logs tab, or with a cable: `adb logcat -s EVABRP.Update OtaUpdater`. On the car's Logs tab, or with a cable: `adb logcat -s EVABRP.Update OtaUpdater`. Each check
writes down the networks Android sees, whether the server's name resolves, its result and, when
it fails, whether `www.gstatic.com/generate_204` answers, which tells a SIM without data from a
server that is down. That report also goes to a USB stick and, once online, to the server
(`update-check-*.txt`, read with `fetch-logs`). No address or token is written.
## Why a PackageInstaller session, not `pm install` ## Why a PackageInstaller session, not `pm install`
+1 -1
View File
@@ -89,7 +89,7 @@ with the server using a token of its own, obtained by pairing with a phone (belo
| Tab | What it shows | | Tab | What it shows |
|---|---| |---|---|
| **Overview** | Battery, range, power and speed; range, usage and energy since start; 5-minute averages of range, usage, power and speed; vehicle info (odometer, lease allowance, climate setpoint) and tyre pressures. Read five times a second. Looks to choose from in Settings → Overview style: Tiles, Gauges, Cockpit, Retro, Futuristic, Sci-fi, Cartoon, MG, Minimal, Terminal, Nixie tubes, Chronograph, Grid, Grid with map, Time circuits, Quest, Visor and Empire ([THEMES.md](THEMES.md) shows them all). A style with its own colours (Sci-fi, Cartoon, Nixie tubes, Time circuits, Quest, Empire, and Retro, Terminal, Grid and Visor with "Original") colours the whole app to match, e.g. turquoise for Retro. Grid with map lays the roads round the car on the Grid's floor: the app asks the car's server for the map tile it is in (not its position), the server fetches only that tile from OpenFreeMap's OpenStreetMap vector tiles and keeps it, and the GPS runs for it only while that style is on screen. The small button next to the MG4 logo in the navigation hides the navigation for a full-width Overview; swipe in from the left edge (a faint handle marks it) to bring it back; with Settings → Full screen off, the car's own sidebar sits at that edge, so tap the small tab at the left edge (›) instead. Pages change only by the navigation, not by swiping sideways | | **Overview** | Battery, range, power and speed; range, usage and energy since start; 5-minute averages of range, usage, power and speed; vehicle info (odometer, lease allowance, climate setpoint) and tyre pressures. While music plays (Bluetooth, CarPlay or the radio), the title and artist; they stay on the screen and are never sent. Read five times a second. Looks to choose from in Settings → Overview style: Tiles, Gauges, Cockpit, Retro, Futuristic, Sci-fi, Cartoon, MG, Minimal, Terminal, Nixie tubes, Chronograph, Grid, Grid with map, Time circuits, Quest, Visor and Empire ([THEMES.md](THEMES.md) shows them all). A style with its own colours (Sci-fi, Cartoon, Nixie tubes, Time circuits, Quest, Empire, and Retro, Terminal, Grid and Visor with "Original") colours the whole app to match, e.g. turquoise for Retro. Grid with map lays the roads round the car on the Grid's floor: the app asks the car's server for the map tile it is in (not its position), the server fetches only that tile from OpenFreeMap's OpenStreetMap vector tiles and keeps it, and the GPS runs for it only while that style is on screen. The small button next to the MG4 logo in the navigation hides the navigation for a full-width Overview; swipe in from the left edge (a faint handle marks it) to bring it back; with Settings → Full screen off, the car's own sidebar sits at that edge, so tap the small tab at the left edge (›) instead. Pages change only by the navigation, not by swiping sideways |
| **Consumption** | Lifetime, last 7 and 30 days, Trip A and B (distance, energy, average consumption and speed, SOC change), and a daily log of the last four months | | **Consumption** | Lifetime, last 7 and 30 days, Trip A and B (distance, energy, average consumption and speed, SOC change), and a daily log of the last four months |
| **Charging** | The current session (SOC, voltage, current, power, energy into the battery and from the grid, time, cost) and its SOC/power curve | | **Charging** | The current session (SOC, voltage, current, power, energy into the battery and from the grid, time, cost) and its SOC/power curve |
| **Live data** | Live data on/off, ABRP credentials for sending directly from the car, upload frequency | | **Live data** | Live data on/off, ABRP credentials for sending directly from the car, upload frequency |
+18
View File
@@ -140,6 +140,24 @@ tyre pressures, GPS (lat, lon, elevation, heading) and the is_* flags. It does *
confirmed car facts, app structure, UI conventions, build/test/ship, documents. It replaces confirmed car facts, app structure, UI conventions, build/test/ship, documents. It replaces
upstream's EVABRPUploader text. The test emulator is now in the flake: `nix run .#car-emulator` upstream's EVABRPUploader text. The test emulator is now in the flake: `nix run .#car-emulator`
(Android 9 AOSP at 1920×720, 160 dpi; the car build installs as the system user — checked). (Android 9 AOSP at 1920×720, 160 dpi; the car build installs as the system user — checked).
- 2026-11-07 — App 2.49.0: **the Caterpillar style** (owner: "a theme based on The Very Hungry Caterpillar"; design agreed first, defaults taken: dark night page, named "Caterpillar" not the book's title, fruit as range). `CaterpillarView`, an original cut-paper collage, not the book's illustrations: the caterpillar's red head is the speed and its ten segments the power (blue while regenerating, wiggling while driving); the sun is the battery (a grey moon below 20 %); a leaf holds trip, usage, climate and odometer; a clock in a paper circle; fruit in the story's order (1 apple, 2 pears, 3 plums, 4 strawberries, 5 oranges) is the range, one per 50 km, used ones with a bite out; P R N D are an egg, the caterpillar, a cocoon and a butterfly; hills are the last two minutes of power. The music light (now also for this style) bounces the sun's rays and the segments on the kick drum. What plays: a butterfly and, on the next pass, a ladybird tow a strip of tissue paper (colour fixed by the song); both in `SongCarriers`. Own palette (green). Two screenshots in THEMES.md. Tested: unit tests, lint, emulator with sample values and with the throwaway fake song. Not tried on the car.
- 2026-11-07 — App 2.48.0 published (`car-2.48.0`).
- 2026-11-07 — App 2.48.0: **the Christmas style** (owner: "let's also do a christmas based theme", with music and something that pulsates; design agreed first). `ChristmasView`: a tree with a big red bauble (speed), fairy lights arching over it (power: gold left to right while drawing, ice blue and right to left while regenerating), a glass mug of cocoa filling with the charge (cold blue and "BATTERY LOW" below 20 %), gift tags (trip, usage, climate, odometer), a wreath clock, a signboard (range) with a candy cane per 50 km, P R N D as baubles, and a snow drift of the last two minutes of power; snow falls and the lights twinkle while driving. Own palette (red); always in the drop-down; English only. The music light is now **"Light follows the music"** for Halloween and Christmas (same `PREF_MUSIC_LIGHT`, off by default): the tree's lights and the arch flare on the kick drum. What plays: Santa's sleigh with a reindeer and, on the next pass, an angel with a trumpet tow a strip of wrapping paper (colour fixed by the song); both in `SongCarriers`. Two screenshots in THEMES.md. Tested: unit tests, lint, emulator with sample values (panel and full screen, and with no data), with the throwaway fake song (both carriers), and the music-tap thread runs only with the switch on. Not tried on the emulator: the pulse itself with real sound (the code path is Halloween's `MusicTap`). Not tried on the car.
- 2026-11-02 — App 2.47.0 published (`car-2.47.0`).
- 2026-11-02 — App 2.47.0: **now playing in four more styles** (owner: "let's implement Now playing in more styles"; Spanish labels declined). Quest: a red dragon tows a waving scroll across the top of the sky, behind the frames. Empire: an eagle flies a scroll across the top of the world, behind the speed. Terminal: a PLAYING row above the prompt. Sci-fi: the song in black on the top bar. The creatures are in the new `SongCarriers` (dragon, eagle) beside `SongBanner`. Same switch as before (Settings → "Show what's playing"). Not yet in the rest: Gauges, Cockpit, Retro, Futuristic, MG, Minimal, Nixie, Chronograph, Grid, Grid with map, Time circuits, Visor, Cartoon. Tested: unit tests, lint, emulator with the throwaway fake session. Not tried on the car.
- 2026-11-02 — App 2.46.0 published (`car-2.46.0`).
- 2026-11-02 — App 2.46.0: **Día de Muertos shows what plays** (owner: "Can we also put that into the dia de muertos theme?", then "switch between monarch and alebrije", "one color per song"). A strip of papel picado (zigzag-cut edges) with "♪ title — artist" waves across the sky between the flags and the ring, behind the ring and the clock; a monarch butterfly and an alebrije (a painted horned creature with feathered wings and a curled tail) tow it on alternate passes. The paper's colour is one of the flags', fixed by the song (hash of title and artist, never logged). The banner moved out of `HalloweenView` into the shared `SongBanner`; Halloween looks as before. Same switch as Tiles and Halloween (Settings → "Show what's playing"). Tested: unit tests, lint, emulator with the throwaway fake session. Not tried on the car.
- 2026-11-02 — App 2.45.2 published (`car-2.45.2`).
- 2026-11-02 — App 2.45.2: Halloween's song banner **waves** (owner: "Can it also be a bit wavy?"): waves run from the bat to the tail, still where the bat holds it and up to 7 units at the tail, and the text follows them (`drawTextOnPath`). Tested: emulator with the throwaway fake session, unit tests, lint. Not tried on the car.
- 2026-11-02 — App 2.45.1 published (`car-2.45.1`).
- 2026-11-02 — App 2.45.1: **Halloween's song flies through the sky** (owner: "Instead of taking up screen space on the bottom, can we somehow include the title in the theme itself? ... have text fly through the air"). A bat tows a parchment banner with "♪ title — artist" from left to right across the strip of sky above the sign, behind the moon, one pass about every half minute, again and again while something plays (the title is cut first so the artist stays); the line at the foot of the hill is gone. While a banner flies the view draws about 30 frames a second, as it does while driving. Tested: emulator with the throwaway fake session (banner clear of the sign along the whole pass), unit tests, lint. Not tried on the car.
- 2026-11-02 — App 2.45.0 published (`car-2.45.0`).
- 2026-11-02 — App 2.45.0: **now playing on the Overview** (owner: "can we also implement music titles etc in our app?"; display only, Tiles and Halloween first). `NowPlayingWatcher` follows the active media sessions as the music-sources check reads them (`MediaSessionManager`, MEDIA_CONTENT_CONTROL as the system user), with a change listener and a callback per session, so reading costs no call into another app; it never connects to a media browser service (2.42.0) and sends no command. It runs only while the Overview is on screen in Tiles or Halloween with Settings → "Show what's playing" on (**on by default**, `PREF_NOW_PLAYING`). `NowPlaying` (pure, unit-tested) picks the session that plays, the one updated last of several, else the one paused last, passing over sessions without text (Bluetooth's empty one); CarPlay's YouTube titles lose their `[videoID]`; the radio shows its text (the artist field, e.g. "BLIND MELON - NO RAIN") with the station below. Tiles: the empty slot under the battery shows source ("· paused" when paused), title, artist, a cover (the session's picture, or Bluetooth's `ALBUM_ART_URI` file, read small off the main thread) and how far the song is; invisible when nothing plays; the narrow layout has no room and shows none. Halloween: "♪ title — artist" along the foot of the hill, the title cut first. Titles stay on screen: not logged, not sent. Tested: unit tests, lint, emulator with a throwaway build publishing a fake session (CarPlay-like title with ID removed, cover, bar; Halloween line; the switch hides and brings back both). With Halloween chosen the Settings card has two switches more and scrolls further. Not tried on the car: whether the car's sessions, Bluetooth's cover file and the radio text show as in the music-sources checks.
- 2026-11-02 — App 2.44.0 published (`car-2.44.0`).
- 2026-11-02 — App 2.44.0: **the pumpkin light follows the bass, and only when switched on** (owner: "more focussed on the bass", "optional via a settings flag"). `MusicPulse` now reads the kick drum's band (40–120 Hz, was 20–250 Hz) and lights only on a jump since the last reading, against the biggest jumps of the last 4 s; a jump under a fifth of that, or under half the bass's average level, lights nothing. So kicks flash, and a held note, a wobbling bass line or a swelling note stay dark (unit tests with made-up patterns). It flares at once and falls in 0.2 s. New switch under the Overview style, shown only for Halloween: "Pumpkin light follows the music" (`PREF_MUSIC_LIGHT`), **off by default**; off, the analyser never starts. Tuned on made-up signals only: no Bluetooth or CarPlay sound report from the car has arrived yet. Next: now playing (title, artist, source) from the media sessions, in its own version. Tested: unit tests, lint, emulator (switch off by default and the analyser thread absent; on, it runs only on the Overview; a throwaway build playing a pulsing test tone: the glow flares with the switch on, and stays exactly still with it off). With Halloween chosen, the Settings card now scrolls a little to reach the tyre unit. Not tried on the car.
- 2026-11-01 — App 2.43.5 published (`car-2.43.5`).
- 2026-11-01 — App 2.43.5: **update checks log what happens** (`UpdateNetworkCheck`, `UpdateDiagnosis`; owner: updating from the car fails, "Can we log what happens? Maybe my SIM card has no data left"). Each check on Settings writes to the Logs tab: the networks Android sees (type, in use, internet, validated, roaming), whether the server's name resolves, how a failure happened, in words from its type or status only, and how many reports wait. On a failure it also asks `https://www.gstatic.com/generate_204`, the one request to anyone but the car server, to tell no data from a server that is down. A report goes to a USB stick and, when online, the server (`update-check-*.txt`; only the newest waits, so it cannot push out a recording). A check at start logs only a failure. The update log keeps 40 lines, not 10. An out-of-data SIM would also explain why the Bluetooth and CarPlay sound reports did not arrive; not confirmed. Tested: unit tests, lint, emulator with a fake server (online: the name fails, the internet test says it works; airplane mode: both fail, "none in use"; the real build installs and starts, its check not run there, having no server). Not tried on the car.
- 2026-11-01 — App 2.43.4 published (`car-2.43.4`).
- 2026-11-01 — App 2.43.4: **the Halloween pumpkin's light follows the music** (`MusicTap`, `MusicPulse`; owner: "make the light in the pumpkin react to the equalizer/sound of the music"). The bass, 25 times a second off the main thread, drives the glow and brightens the carving on the beat; yellow and green still mean drawing and regenerating, the embers still the power, and no signal leaves the light as it was. It listens only with the app in front, on the Overview, in Halloween. The owner reports the sound check worked with Bluetooth and CarPlay; those two reports never reached the server (why not is unexplained), so their levels are unseen and the pulse's feel is untuned for the car. Tested: unit tests, lint, emulator (a tone already playing when the analyser starts: the carving and glow move with it; no sound: unchanged; the analyser is released on another tab and when the app leaves the front; no crash). Not tried on the car; how it looks there, and its effect on the head unit over a long drive, are unknown. - 2026-11-01 — App 2.43.4: **the Halloween pumpkin's light follows the music** (`MusicTap`, `MusicPulse`; owner: "make the light in the pumpkin react to the equalizer/sound of the music"). The bass, 25 times a second off the main thread, drives the glow and brightens the carving on the beat; yellow and green still mean drawing and regenerating, the embers still the power, and no signal leaves the light as it was. It listens only with the app in front, on the Overview, in Halloween. The owner reports the sound check worked with Bluetooth and CarPlay; those two reports never reached the server (why not is unexplained), so their levels are unseen and the pulse's feel is untuned for the car. Tested: unit tests, lint, emulator (a tone already playing when the analyser starts: the carving and glow move with it; no sound: unchanged; the analyser is released on another tab and when the app leaves the front; no crash). Not tried on the car; how it looks there, and its effect on the head unit over a long drive, are unknown.
- 2026-10-31 — Sound check on the car (2.43.3), radio: `com.saicmotor.radio` playing, `isMusicActive` false, analyser enabled without error and silent for all 10 seconds (peak 0.00, -9600 mB). The audio analyser does not hear the radio. The owner ran Bluetooth and CarPlay too; those reports have not reached the server yet (the outbox sends oldest first and stops at the first failure, retrying while the service runs). - 2026-10-31 — Sound check on the car (2.43.3), radio: `com.saicmotor.radio` playing, `isMusicActive` false, analyser enabled without error and silent for all 10 seconds (peak 0.00, -9600 mB). The audio analyser does not hear the radio. The owner ran Bluetooth and CarPlay too; those reports have not reached the server yet (the outbox sends oldest first and stops at the first failure, retrying while the service runs).
- 2026-10-31 — App 2.43.3 published (`car-2.43.3`). - 2026-10-31 — App 2.43.3 published (`car-2.43.3`).
+61 -5
View File
@@ -11,7 +11,7 @@ emulator has no car; on the car the values are live.
**Colours.** Most styles are drawn in the accent colour you pick from the MG4 paints (Settings → **Colours.** Most styles are drawn in the accent colour you pick from the MG4 paints (Settings →
Accent colour; shown here in Dynamic Red). Retro, Terminal, Grid (with or without the map) and Visor can also show their original Accent colour; shown here in Dynamic Red). Retro, Terminal, Grid (with or without the map) and Visor can also show their original
colours, and Sci-fi, Cartoon, Nixie tubes, Time circuits, Quest, Empire, Día de Muertos and Halloween always do; while one of those is shown, the whole app colours, and Sci-fi, Cartoon, Nixie tubes, Time circuits, Quest, Empire, Día de Muertos, Halloween, Christmas and Caterpillar always do; while one of those is shown, the whole app
(navigation, buttons, switches) takes on its colours too. (navigation, buttons, switches) takes on its colours too.
| Style | Look | Colours | | Style | Look | Colours |
@@ -36,13 +36,17 @@ colours, and Sci-fi, Cartoon, Nixie tubes, Time circuits, Quest, Empire, Día de
| [Empire](#empire) | a strategy game's interface | own | | [Empire](#empire) | a strategy game's interface | own |
| [Día de Muertos](#día-de-muertos) | an ofrenda with papel picado and a calavera | own | | [Día de Muertos](#día-de-muertos) | an ofrenda with papel picado and a calavera | own |
| [Halloween](#halloween) | a jack-o'-lantern on a graveyard hill | own | | [Halloween](#halloween) | a jack-o'-lantern on a graveyard hill | own |
| [Christmas](#christmas) | a Christmas tree in a snowy village | own |
| [Caterpillar](#caterpillar) | a hungry caterpillar in cut-paper collage | own |
## Tiles ## Tiles
The app's original look, from the design it was forked from: glass cards on OLED black, one tile The app's original look, from the design it was forked from: glass cards on OLED black, one tile
per value, with the averages over the last five minutes and since the start, vehicle info (with per value, with the averages over the last five minutes and since the start, vehicle info (with
the lease allowance) and the tyre pressures on a little top view of the car. The most the lease allowance) and the tyre pressures on a little top view of the car. The most
information on one screen. information on one screen. While something plays over Bluetooth, CarPlay or the radio, the slot
under the battery shows it: the source, title, artist, a cover when Bluetooth sends one, and how
far the song is (Settings → "Show what's playing", on by default).
![Tiles with the navigation](screenshots/themes/tiles-panel.png) ![Tiles with the navigation](screenshots/themes/tiles-panel.png)
![Tiles, full screen](screenshots/themes/tiles.png) ![Tiles, full screen](screenshots/themes/tiles.png)
@@ -92,6 +96,7 @@ A starship console, after the look of the computer screens in 90s science-fictio
"elbow" frames in orange and lilac, pill-shaped labels, condensed capitals and blocky bar graphs "elbow" frames in orange and lilac, pill-shaped labels, condensed capitals and blocky bar graphs
on black. Below 20 % charge the frames turn red: red alert. The app takes on the lilac of the on black. Below 20 % charge the frames turn red: red alert. The app takes on the lilac of the
lower frame. lower frame.
What plays (Bluetooth, CarPlay or the radio) is written in black on the top bar, cut to its length.
![Sci-fi with the navigation](screenshots/themes/scifi-panel.png) ![Sci-fi with the navigation](screenshots/themes/scifi-panel.png)
![Sci-fi, full screen](screenshots/themes/scifi.png) ![Sci-fi, full screen](screenshots/themes/scifi.png)
@@ -129,6 +134,7 @@ driving.
As if a shell printed the car's state: `watch -n 0.2 vehicle-status` on a green-phosphor screen As if a shell printed the car's state: `watch -n 0.2 vehicle-status` on a green-phosphor screen
with faint scan lines, each value on a row with an ASCII bar, the gear as `[D]`, and a prompt with with faint scan lines, each value on a row with an ASCII bar, the gear as `[D]`, and a prompt with
a blinking cursor. A low battery turns its row amber. In green (shown) or in the accent colour. a blinking cursor. A low battery turns its row amber. In green (shown) or in the accent colour.
What plays (Bluetooth, CarPlay or the radio) shows as a PLAYING row above the prompt, cut to the width.
![Terminal with the navigation](screenshots/themes/terminal-panel.png) ![Terminal with the navigation](screenshots/themes/terminal-panel.png)
![Terminal, full screen](screenshots/themes/terminal.png) ![Terminal, full screen](screenshots/themes/terminal.png)
@@ -204,6 +210,7 @@ energy bar; a minimap with the clock; the speed in large gold numbers over a cas
are the trip, the usage and the climate; a chat window with system lines; P R N D as action are the trip, the usage and the climate; a chat window with system lines; P R N D as action
buttons, and the odometer as the experience bar, a level per 1000 km. Below 20 % a raid warning buttons, and the odometer as the experience bar, a level per 1000 km. Below 20 % a raid warning
flashes "Low battery!". The app turns gold with it. flashes "Low battery!". The app turns gold with it.
What plays (Bluetooth, CarPlay or the radio) crosses the top of the sky on a waving scroll towed by a red dragon, behind the frames, again and again while it plays.
![Quest with the navigation](screenshots/themes/quest-panel.png) ![Quest with the navigation](screenshots/themes/quest-panel.png)
![Quest, full screen](screenshots/themes/quest.png) ![Quest, full screen](screenshots/themes/quest.png)
@@ -232,6 +239,7 @@ while the ground and trees move past as fast as you drive and the speed stands l
land. The carved panel at the bottom has P R N D as command buttons, the unit's portrait and land. The carved panel at the bottom has P R N D as command buttons, the unit's portrait and
stats, and a diamond minimap with the odometer and the way to the next age. Below 20 % it warns stats, and a diamond minimap with the odometer and the way to the next age. Below 20 % it warns
"Your battery is running low!". The app turns the player's blue with it. "Your battery is running low!". The app turns the player's blue with it.
What plays (Bluetooth, CarPlay or the radio) crosses the top of the world on a waving scroll flown by an eagle, behind the speed, again and again while it plays.
![Empire with the navigation](screenshots/themes/empire-panel.png) ![Empire with the navigation](screenshots/themes/empire-panel.png)
![Empire, full screen](screenshots/themes/empire.png) ![Empire, full screen](screenshots/themes/empire.png)
@@ -247,7 +255,10 @@ drawing, turquoise and anticlockwise while regenerating. The altar's candles are
per 50 km. The path of marigold petals along the bottom, which in the tradition leads the visitors per 50 km. The path of marigold petals along the bottom, which in the tradition leads the visitors
home, is the last two minutes of power. On the right the clock in a tin frame, P R N D as small home, is the last two minutes of power. On the right the clock in a tin frame, P R N D as small
marigolds, and trip, usage, climate and odometer on the altar cloth. While you drive the flags marigolds, and trip, usage, climate and odometer on the altar cloth. While you drive the flags
sway and the flames flicker. The app turns the papel picado's pink with it. sway and the flames flicker. What plays (Bluetooth, CarPlay or the radio) crosses the sky between
the flags and the ring on a waving strip of cut paper, towed by a monarch butterfly and, on the next
pass, an alebrije; the paper takes one of the flags' colours, fixed by the song. The app turns the
papel picado's pink with it.
![Día de Muertos with the navigation](screenshots/themes/muertos-panel.png) ![Día de Muertos with the navigation](screenshots/themes/muertos-panel.png)
![Día de Muertos, full screen](screenshots/themes/muertos.png) ![Día de Muertos, full screen](screenshots/themes/muertos.png)
@@ -262,9 +273,54 @@ the range ("here lies … km"), and the bats are the range too, one per 50 km; P
gravestones, the one engaged lit. The moon holds the clock, a sign hanging from a cobweb has trip, gravestones, the one engaged lit. The moon holds the clock, a sign hanging from a cobweb has trip,
usage, climate and odometer, and the hill along the bottom is the last two minutes of power. While usage, climate and odometer, and the hill along the bottom is the last two minutes of power. While
you drive the bats fly, the potion bubbles and the ghost floats (where there is room for it, as on you drive the bats fly, the potion bubbles and the ghost floats (where there is room for it, as on
this screen). With Bluetooth or CarPlay music playing, the pumpkin's glow swells and its carving this screen). With "Pumpkin light follows the music" on (Settings, shown with this style; off by
brightens on the beat; the radio cannot be heard, so it burns as usual then. The app turns the default) and Bluetooth or CarPlay music playing, the pumpkin's glow flares and its carving
brightens on each kick drum; the radio cannot be heard, so it burns as usual then. What plays
(Bluetooth, CarPlay or the radio) flies across the top of the sky on a waving parchment banner that a
bat tows, behind the moon, again and again while it plays (`SongBanner` draws the banner for both
this style and Día de Muertos). The app turns the
pumpkin's orange with it. pumpkin's orange with it.
![Halloween with the navigation](screenshots/themes/halloween-panel.png) ![Halloween with the navigation](screenshots/themes/halloween-panel.png)
![Halloween, full screen](screenshots/themes/halloween.png) ![Halloween, full screen](screenshots/themes/halloween.png)
## Christmas
A snowy village at night, warm and festive. In the middle a Christmas tree with a big red bauble
in front of it: the speed. Fairy lights arch over the tree: the power, left to right in warm gold
while drawing, ice blue and right to left while regenerating. On the left a glass mug of hot cocoa
fills with the charge, with marshmallows floating on it and steam rising; it turns cold blue with
"BATTERY LOW" blinking below 20 %. Above it, gift tags hang from a garland with trip, usage,
climate and odometer. On the right a wreath holds the clock, and a snowy signboard reads the range
with a candy cane for every 50 km in the snow below; P R N D are four baubles, the one engaged lit.
The snow drift along the bottom is the last two minutes of power, rising with it. While you drive the
snow falls and the tree's lights twinkle. With "Light follows the music" on (Settings, shown with
this style and Halloween; off by default) and Bluetooth or CarPlay music playing, the lights on the
tree and the fairy lights flare on each kick drum; the radio cannot be heard, so they twinkle as
usual then. What plays (Bluetooth, CarPlay or the radio) crosses the sky above the tree on a waving
strip of wrapping paper towed by Santa's sleigh and, on the next pass, a small angel with a
trumpet; the paper's colour is fixed by the song. The app turns red with it.
![Christmas with the navigation](screenshots/themes/christmas-panel.png)
![Christmas, full screen](screenshots/themes/christmas.png)
## Caterpillar
After a picture book about a very hungry caterpillar, drawn anew in cut-paper shapes and bright
tissue colours on the book's night page. The caterpillar crosses the middle: its red head carries
the speed, and its ten green segments are the power, lit from the head backwards while drawing and
blue while regenerating; it wiggles along while you drive. On the left the sun is the battery,
filling with the charge; below 20 % it turns into a grey moon and "BATTERY LOW" blinks. A big leaf
above it holds trip, usage, climate and odometer on paper labels. On the right a clock in a paper
circle, and the story's fruit, one apple, two pears, three plums, four strawberries and five
oranges: a fruit per 50 km of range, those used up with a bite taken out. P R N D are the stages of
its life, an egg, the caterpillar, a cocoon and a butterfly, the one engaged lit. The hills along
the bottom are the last two minutes of power, rising with it. With "Light follows the music" on
(Settings, shown with this style, Halloween and Christmas; off by default) and Bluetooth or CarPlay
music playing, the sun's rays and the caterpillar's segments bounce on each kick drum; the radio
cannot be heard. What plays (Bluetooth, CarPlay or the radio) crosses the sky on a waving strip of
tissue paper towed by a butterfly and, on the next pass, a ladybird; the paper's colour is fixed by
the song. The app turns green with it.
![Caterpillar with the navigation](screenshots/themes/caterpillar-panel.png)
![Caterpillar, full screen](screenshots/themes/caterpillar.png)
+2 -2
View File
@@ -34,8 +34,8 @@ android {
applicationId "com.stinnesbeck.nilsmg4" applicationId "com.stinnesbeck.nilsmg4"
minSdk 27 minSdk 27
targetSdk 36 targetSdk 36
versionCode 157 versionCode 166
versionName "2.43.4" versionName "2.49.0"
// Nothing about the server ships in the APK: its URL and ingest token are entered in // Nothing about the server ships in the APK: its URL and ingest token are entered in
// the app's Server tab (ServerConfig), and the database is only reachable by the server. // the app's Server tab (ServerConfig), and the database is only reachable by the server.
@@ -0,0 +1,528 @@
package com.evsuite.abrp;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.Typeface;
import android.os.SystemClock;
import java.util.Locale;
/**
* The Caterpillar Overview style, after the picture book about a very hungry caterpillar (drawn
* anew, not copied from it): cut-paper shapes in bright tissue colours on the book's night page.
*
* In the middle the caterpillar: its red head carries the speed, and its ten green segments are the
* power, lit from the head backwards while drawing, blue while regenerating; it wiggles along while
* the car moves. On the left the sun is the battery, filling with the charge, and turning into a
* grey moon with "BATTERY LOW" blinking below 20 %; above it a big leaf holds trip, usage, climate
* and odometer on paper labels. On the right the clock in a paper circle, and the
* story's fruit: one apple, two pears, three plums, four strawberries and five oranges, a fruit
* per 50 km of range, those used up with a bite taken out. P R N D are the four stages of its life,
* an egg, the caterpillar, a cocoon and a butterfly, the one engaged lit. The hills along the bottom
* are the last two minutes of power, rising with it. Unread values show "—" and light nothing.
* With music playing, the sun's rays and the caterpillar's segments bounce on the beat
* ({@link MusicTap}). What plays crosses the sky on a banner of tissue paper towed by a butterfly
* and, on the next pass, a ladybird ({@link NowPlaying}).
*
* The night, the stars and the far hills are drawn once into a bitmap per size. The caterpillar
* wiggles (about 30 frames a second) only while the car moves and the view is on screen; the
* pulse and the song keep it drawing while there are any.
*/
final class CaterpillarView extends ClusterCanvasView {
private static final int SEGMENTS = 10, RAYS = 14, FRUIT = 15;
private static final int NIGHT_TOP = 0xFF050B22, NIGHT_LOW = 0xFF12305A, NIGHT_END = 0xFF1D4A5E;
private static final int GREEN = 0xFF7ED957, GREEN_DARK = 0xFF2E8B3A, LEAF = 0xFF3FA34D, HEAD = 0xFFE53935;
private static final int SUN = 0xFFFFA726, SUN_LIGHT = 0xFFFFD54F, MOON = 0xFFB8BCC8, ICE = 0xFF5CC8FF;
private static final int PAPER = 0xFFFBF1DA, INK = 0xFF1B1530, BONE = 0xFFF6F0E4, YELLOW = 0xFFFFE066;
private static final int[] TISSUE = { 0xFFE53935, 0xFF2B7BE0, 0xFF2EA84F, 0xFFFFC928, 0xFF8E4DD6, 0xFFFF8A1F };
private final Paint fill = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint line = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint text = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint image = new Paint(Paint.FILTER_BITMAP_FLAG);
private final Path path = new Path();
private final Path bite = new Path();
private final SongBanner banner = new SongBanner();
private final RectF r = new RectF();
private final Typeface serif = Typeface.create("serif", Typeface.BOLD);
private final Typeface face = Typeface.create("sans-serif-condensed", Typeface.BOLD);
private final Typeface thin = Typeface.create("sans-serif-condensed", Typeface.NORMAL);
private Bitmap sky;
private int skyW, skyH;
private float time;
private long lastFrame;
private MusicTap music;
CaterpillarView(Context context) {
super(context);
line.setStyle(Paint.Style.STROKE);
line.setStrokeCap(Paint.Cap.ROUND);
}
/** Where the sun and the caterpillar hear the music; without it, they do not follow any. */
void setMusic(MusicTap tap) {
music = tap;
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
sky = null;
skyW = 0;
}
@Override
protected void onDraw(Canvas c) {
super.onDraw(c);
int w = getWidth(), h = getHeight();
if (w <= 0 || h <= 0) return;
float u = Math.min(h / 640f, w / 1100f);
boolean moving = v.speedKmh != null && v.speedKmh > 0.5f;
if (moving) {
long now = SystemClock.uptimeMillis();
time += lastFrame == 0 ? 0f : Math.min(0.2f, (now - lastFrame) / 1000f);
lastFrame = now;
} else {
lastFrame = 0;
}
if (sky == null || skyW != w || skyH != h) buildSky(w, h, u);
c.drawBitmap(sky, 0, 0, image);
boolean song = drawSong(c, w, u);
drawHills(c, w, h, u);
float pulse = music == null ? 0f : music.pulse();
drawSun(c, u, pulse);
drawLeaf(c, u);
drawClock(c, w, u);
drawFruit(c, w, u);
drawGears(c, w, u);
drawCaterpillar(c, w, u, pulse);
keepAnimating(moving || pulse > 0f || song, 33);
}
private void label(Canvas c, String s, float x, float y, float size, int colour, Typeface tf, Paint.Align a) {
text.setTypeface(tf);
text.setTextSize(size);
text.setTextAlign(a);
text.setColor(colour);
c.drawText(s, x, y, text);
}
/** Text with a dark outline, to read over whatever is behind it. */
private void outlined(Canvas c, String s, float x, float y, float size, int colour, Typeface tf, Paint.Align a, float u) {
text.setStyle(Paint.Style.STROKE);
text.setStrokeWidth(Math.max(3f * u, size * 0.12f));
text.setStrokeJoin(Paint.Join.ROUND);
label(c, s, x, y, size, 0xDD0A0608, tf, a);
text.setStyle(Paint.Style.FILL);
label(c, s, x, y, size, colour, tf, a);
}
private boolean regen() {
return v.powerKw != null && v.powerKw < -0.05f;
}
// ---------- The night page ----------
private void buildSky(int w, int h, float u) {
sky = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
skyW = w;
skyH = h;
Canvas c = new Canvas(sky);
Paint p = new Paint();
p.setShader(new LinearGradient(0, 0, 0, h, new int[] { NIGHT_TOP, NIGHT_LOW, NIGHT_END },
new float[] { 0f, 0.7f, 1f }, Shader.TileMode.CLAMP));
c.drawRect(0, 0, w, h, p);
Paint star = new Paint(Paint.ANTI_ALIAS_FLAG);
star.setColor(0xB0FFF6C8);
for (int i = 0; i < 80; i++) {
float x = ((i * 191 + 17) % 1009) / 1009f * w, y = ((i * 83 + 5) % 421) * u;
c.drawCircle(x, y, (i % 4 == 0 ? 2.2f : 1.2f) * u, star);
}
// A crescent moon, as on the book's first night.
Path moon = new Path(), cut = new Path();
float mx = w * 0.3f, my = 150f * u;
moon.addCircle(mx, my, 30f * u, Path.Direction.CW);
cut.addCircle(mx + 13f * u, my - 6f * u, 27f * u, Path.Direction.CW);
moon.op(cut, Path.Op.DIFFERENCE);
Paint paper = new Paint(Paint.ANTI_ALIAS_FLAG);
paper.setColor(0xFFFFF3B0);
c.drawPath(moon, paper);
hills(c, w, h, h - 150f * u, 0xFF124A3A, 0.8f, u);
hills(c, w, h, h - 100f * u, 0xFF1A5E45, 1.5f, u);
}
private void hills(Canvas c, int w, int h, float base, int colour, float wave, float u) {
Path hill = new Path();
hill.moveTo(0, h);
for (int i = 0; i <= 24; i++) {
float x = w * i / 24f;
hill.lineTo(x, base - (float) (Math.sin(i * wave) * 0.5 + Math.sin(i * wave * 0.37 + 1) * 0.5) * 22f * u);
}
hill.lineTo(w, h);
hill.close();
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setColor(colour);
c.drawPath(hill, p);
}
// ---------- The hills in front: the last two minutes of power ----------
private void drawHills(Canvas c, int w, int h, float u) {
float base = h - 44f * u, amp = 36f * u;
float[] trail = v.powerTrail;
path.reset();
path.moveTo(0, h);
int n = trail == null ? 0 : trail.length;
if (n == 0) {
path.lineTo(0, base);
path.lineTo(w, base);
} else {
for (int i = 0; i < n; i++) {
float p = trail[i];
float height = Float.isNaN(p) ? 0f : Math.min(1f, Math.abs(p) / (p < 0 ? 40f : 60f));
path.lineTo(i / (n - 1f) * w, base - height * amp);
}
}
path.lineTo(w, h);
path.close();
fill.setColor(0xFF2E9A4E);
c.drawPath(path, fill);
if (n > 1) {
line.setStrokeWidth(3f * u);
for (int i = 1; i < n; i++) {
float a = trail[i - 1], b = trail[i];
if (Float.isNaN(a) || Float.isNaN(b)) continue;
float ha = Math.min(1f, Math.abs(a) / (a < 0 ? 40f : 60f));
float hb = Math.min(1f, Math.abs(b) / (b < 0 ? 40f : 60f));
line.setColor(b < 0 ? ICE : YELLOW);
c.drawLine((i - 1f) / (n - 1f) * w, base - ha * amp, i / (n - 1f) * w, base - hb * amp, line);
}
}
}
// ---------- The sun (or the moon): the battery ----------
private void drawSun(Canvas c, float u, float pulse) {
float cx = 178f * u, cy = 452f * u, rad = 100f * u;
boolean low = v.socPercent != null && v.socPercent < 20f;
boolean blinkOn = (SystemClock.uptimeMillis() / 500) % 2 == 0;
float share = v.socPercent == null ? 0f : Math.max(0f, Math.min(1f, v.socPercent / 100f));
// The rays, longer and stronger with the music; none for the moon.
if (!low) {
for (int i = 0; i < RAYS; i++) {
double a = Math.PI * 2 * i / RAYS;
float cos = (float) Math.cos(a), sin = (float) Math.sin(a);
float tip = rad + (22f + pulse * 16f + (i % 2) * 8f) * u;
float nx = -sin * 8f * u, ny = cos * 8f * u;
path.reset();
path.moveTo(cx + cos * (rad - 2f * u) + nx, cy + sin * (rad - 2f * u) + ny);
path.lineTo(cx + cos * tip, cy + sin * tip);
path.lineTo(cx + cos * (rad - 2f * u) - nx, cy + sin * (rad - 2f * u) - ny);
path.close();
fill.setColor(AccentColor.withAlpha(SUN_LIGHT, 0x60 + (int) (share * 0x9F)));
c.drawPath(path, fill);
}
}
// The disc: dark where the charge is gone, the sun's colour as high as it is full.
fill.setColor(0xFF1E2748);
c.drawCircle(cx, cy, rad, fill);
if (v.socPercent != null) {
float level = cy + rad - share * 2f * rad;
c.save();
c.clipRect(cx - rad, level, cx + rad, cy + rad + 1f);
fill.setColor(low ? MOON : SUN);
c.drawCircle(cx, cy, rad, fill);
c.restore();
}
if (low) {
fill.setColor(0x33000000);
c.drawCircle(cx - 36f * u, cy - 30f * u, 13f * u, fill);
c.drawCircle(cx + 34f * u, cy + 40f * u, 17f * u, fill);
c.drawCircle(cx + 40f * u, cy - 36f * u, 8f * u, fill);
}
line.setColor(low ? MOON : SUN_LIGHT);
line.setStrokeWidth(4f * u);
c.drawCircle(cx, cy, rad, line);
String number = fmt(v.socPercent, "%.0f %%", "—");
outlined(c, number, cx, cy + 20f * u, 58f * u, BONE, serif, Paint.Align.CENTER, u);
if (low && blinkOn) outlined(c, "BATTERY LOW", cx, cy + 56f * u, 21f * u, BONE, face, Paint.Align.CENTER, u);
else if (!low) outlined(c, "BATTERY", cx, cy + 56f * u, 19f * u, YELLOW, face, Paint.Align.CENTER, u);
}
// ---------- The leaf: trip, usage, climate, odometer ----------
private void drawLeaf(Canvas c, float u) {
float l = 20f * u, rr = 336f * u, t = 34f * u, b = 246f * u;
// A stem, then the leaf: a rounded sheet with a pointed tip and veins.
line.setColor(GREEN_DARK);
line.setStrokeWidth(7f * u);
c.drawLine(l + 6f * u, b - 4f * u, l - 12f * u, b + 20f * u, line);
path.reset();
path.moveTo(l + 30f * u, t);
path.lineTo(rr - 50f * u, t);
path.quadTo(rr, t + 4f * u, rr + 10f * u, (t + b) / 2f);
path.quadTo(rr, b - 4f * u, rr - 50f * u, b);
path.lineTo(l + 30f * u, b);
path.quadTo(l, b, l, b - 30f * u);
path.lineTo(l, t + 30f * u);
path.quadTo(l, t, l + 30f * u, t);
path.close();
fill.setColor(LEAF);
c.drawPath(path, fill);
line.setColor(0xFF2E8B3A);
line.setStrokeWidth(3f * u);
c.drawPath(path, line);
line.setColor(0x55B6F0A8);
line.setStrokeWidth(2.5f * u);
c.drawLine(l + 8f * u, (t + b) / 2f, rr + 6f * u, (t + b) / 2f, line);
for (int i = 1; i < 6; i++) {
float x = l + i * 50f * u;
c.drawLine(x, (t + b) / 2f, x + 26f * u, t + 8f * u, line);
c.drawLine(x, (t + b) / 2f, x + 26f * u, b - 8f * u, line);
}
String[][] rows = {
{ "TRIP", fmt(v.tripKm, "%.1f km", "—") },
{ "5 MIN", fmt(v.usage5Min, "%.1f kWh/100", "—") },
{ "SINCE START", fmt(v.usageTrip, "%.1f kWh/100", "—") },
{ "CLIMATE", fmt(v.climateCelsius, "%.0f °C", "—") },
{ "ODOMETER", fmt(v.odometerKm, "%,.0f km", "—") },
};
for (int i = 0; i < rows.length; i++) {
float top = t + 12f * u + i * 38f * u;
c.save();
c.rotate((i % 2 == 0 ? -0.6f : 0.6f), (l + rr) / 2f, top + 16f * u);
r.set(l + 14f * u, top, rr - 14f * u, top + 32f * u);
fill.setColor(PAPER);
c.drawRect(r, fill);
label(c, rows[i][0], l + 24f * u, top + 22f * u, 16f * u, 0xFF6B4A8A, thin, Paint.Align.LEFT);
label(c, rows[i][1], rr - 24f * u, top + 24f * u, 21f * u, INK, face, Paint.Align.RIGHT);
c.restore();
}
}
// ---------- The clock ----------
private void drawClock(Canvas c, int w, float u) {
float cx = w - 115f * u, cy = 96f * u, rad = 62f * u;
// Two leaves on top.
fill.setColor(LEAF);
for (int side = -1; side <= 1; side += 2) {
c.save();
c.rotate(side * 40f, cx, cy);
r.set(cx - 12f * u, cy - rad - 34f * u, cx + 12f * u, cy - rad + 8f * u);
c.drawOval(r, fill);
c.restore();
}
fill.setColor(PAPER);
c.drawCircle(cx, cy, rad, fill);
line.setColor(GREEN_DARK);
line.setStrokeWidth(6f * u);
c.drawCircle(cx, cy, rad, line);
label(c, v.clock.isEmpty() ? "—" : v.clock, cx, cy + 14f * u, 40f * u, INK, serif, Paint.Align.CENTER);
}
// ---------- The fruit: the range ----------
private void drawFruit(Canvas c, int w, float u) {
float rr = w - 40f * u, l = rr - 250f * u;
label(c, fmt(v.rangeKm, "%.0f km", "— km"), (l + rr) / 2f, 220f * u, 36f * u, BONE, serif, Paint.Align.CENTER);
int whole = Tally.lit(v.rangeKm, 50f, FRUIT);
int index = 0;
for (int row = 0; row < 5; row++) {
for (int k = 0; k <= row; k++, index++) {
fruit(c, row, l + 24f * u + k * 46f * u, 256f * u + row * 50f * u, 19f * u, index < whole, u);
}
}
}
/** One fruit of kind {@code kind} (apple, pear, plum, strawberry, orange); used up ones have a bite out. */
private void fruit(Canvas c, int kind, float x, float y, float s, boolean whole, float u) {
final int[] colours = { 0xFFE53935, 0xFFA8D83F, 0xFF7E3FBF, 0xFFE8263E, 0xFFFF8F1F };
path.reset();
switch (kind) {
case 1: r.set(x - s * 0.8f, y - s, x + s * 0.8f, y + s); path.addOval(r, Path.Direction.CW); break;
case 3:
path.moveTo(x - s, y - s * 0.6f);
path.lineTo(x + s, y - s * 0.6f);
path.lineTo(x, y + s);
path.close();
break;
default: path.addCircle(x, y, s, Path.Direction.CW);
}
if (!whole) {
bite.reset();
bite.addCircle(x + s * 0.85f, y - s * 0.55f, s * 0.5f, Path.Direction.CW);
path.op(bite, Path.Op.DIFFERENCE);
}
fill.setColor(whole ? colours[kind] : AccentColor.withAlpha(colours[kind], 0x78));
c.drawPath(path, fill);
if (!whole) return;
// A stem and a leaf, seeds on the strawberry.
line.setColor(kind == 3 ? GREEN_DARK : 0xFF6B4226);
line.setStrokeWidth(2.5f * u);
c.drawLine(x, y - s * (kind == 3 ? 0.6f : 0.95f), x + 3f * u, y - s * 1.3f, line);
fill.setColor(GREEN);
r.set(x + 1f * u, y - s * 1.35f, x + 11f * u, y - s * 1.05f);
c.drawOval(r, fill);
if (kind == 3) {
fill.setColor(YELLOW);
for (int i = 0; i < 3; i++) c.drawCircle(x + (i - 1) * 7f * u, y + (i % 2) * 7f * u - 2f * u, 1.6f * u, fill);
}
}
// ---------- The stages of its life: the gears ----------
private void drawGears(Canvas c, int w, float u) {
float rr = w - 40f * u, l = rr - 250f * u, cy = 520f * u, rad = 26f * u;
String[] gears = { "P", "R", "N", "D" };
String now = Gear.label(v.gear);
float step = (rr - l) / 4f;
for (int i = 0; i < gears.length; i++) {
float mid = l + (i + 0.5f) * step;
boolean on = gears[i].equals(now);
if (on) {
fill.setColor(0x55FFE066);
c.drawCircle(mid, cy, 40f * u, fill);
}
fill.setColor(0xFF1B2A4A);
c.drawCircle(mid, cy, rad, fill);
line.setColor(on ? YELLOW : 0xFF3A5080);
line.setStrokeWidth(2.5f * u);
c.drawCircle(mid, cy, rad, line);
stage(c, i, mid, cy, u, on);
label(c, gears[i], mid, cy + rad + 22f * u, 22f * u, on ? YELLOW : 0xB0FFFFFF, serif, Paint.Align.CENTER);
}
}
/** The life stage for gear {@code i}: an egg, the caterpillar, a cocoon, a butterfly. */
private void stage(Canvas c, int i, float x, float y, float u, boolean on) {
int alpha = on ? 0xFF : 0x90;
switch (i) {
case 0:
r.set(x - 9f * u, y - 13f * u, x + 9f * u, y + 13f * u);
fill.setColor(AccentColor.withAlpha(0xFFF6F0E4, alpha));
c.drawOval(r, fill);
break;
case 1:
for (int k = 0; k < 3; k++) {
fill.setColor(AccentColor.withAlpha(k == 2 ? HEAD : GREEN, alpha));
c.drawCircle(x + (k - 1) * 10f * u, y + 2f * u, 7f * u, fill);
}
break;
case 2:
r.set(x - 8f * u, y - 16f * u, x + 8f * u, y + 16f * u);
fill.setColor(AccentColor.withAlpha(0xFFB08A5A, alpha));
c.drawOval(r, fill);
line.setColor(AccentColor.withAlpha(0xFF6B4226, alpha));
line.setStrokeWidth(1.5f * u);
c.drawLine(x - 7f * u, y - 4f * u, x + 7f * u, y - 4f * u, line);
c.drawLine(x - 7f * u, y + 5f * u, x + 7f * u, y + 5f * u, line);
break;
default:
fill.setColor(AccentColor.withAlpha(0xFF7E57E0, alpha));
r.set(x - 16f * u, y - 14f * u, x, y + 2f * u);
c.drawOval(r, fill);
r.set(x, y - 14f * u, x + 16f * u, y + 2f * u);
c.drawOval(r, fill);
fill.setColor(AccentColor.withAlpha(0xFFFF5FA2, alpha));
r.set(x - 14f * u, y - 2f * u, x, y + 12f * u);
c.drawOval(r, fill);
r.set(x, y - 2f * u, x + 14f * u, y + 12f * u);
c.drawOval(r, fill);
}
}
// ---------- The caterpillar: speed and power ----------
private void drawCaterpillar(Canvas c, int w, float u, float pulse) {
float hx = w / 2f + 250f * u, hy = 400f * u, hr = 76f * u;
int lit = Tally.ofPower(v.powerKw, 150f, 50f, SEGMENTS);
int colour = regen() ? ICE : GREEN;
// The segments from the tail towards the head, the legs behind them.
for (int i = SEGMENTS - 1; i >= 0; i--) {
float x = hx - 100f * u - i * 54f * u;
float y = hy + 10f * u + (float) Math.sin(time * 3.5f - i * 0.75f) * 12f * u;
boolean on = i < lit;
float rad = 32f * u * (1f + (on ? pulse * (i % 2 == 0 ? 0.18f : 0.12f) : 0f));
line.setColor(HEAD);
line.setStrokeWidth(4f * u);
float foot = (i % 2 == 0 ? 6f : -6f) * u;
c.drawLine(x, y + rad - 4f * u, x + foot, y + rad + 14f * u, line);
fill.setColor(on ? colour : 0xFF3B7A4A);
c.drawCircle(x, y, rad, fill);
line.setColor(on ? GREEN_DARK : 0xFF2A5A36);
line.setStrokeWidth(3f * u);
c.drawCircle(x, y, rad, line);
if (on) {
fill.setColor(0x44FFFFFF);
c.drawCircle(x - rad * 0.3f, y - rad * 0.35f, rad * 0.28f, fill);
}
}
// The head, with antennae and eyes, and the speed.
line.setColor(HEAD);
line.setStrokeWidth(4f * u);
c.drawLine(hx - 22f * u, hy - hr + 8f * u, hx - 40f * u, hy - hr - 30f * u, line);
c.drawLine(hx + 22f * u, hy - hr + 8f * u, hx + 40f * u, hy - hr - 30f * u, line);
fill.setColor(0xFFFFA726);
c.drawCircle(hx - 40f * u, hy - hr - 32f * u, 7f * u, fill);
c.drawCircle(hx + 40f * u, hy - hr - 32f * u, 7f * u, fill);
fill.setColor(HEAD);
c.drawCircle(hx, hy, hr * (1f + pulse * 0.04f), fill);
fill.setColor(0x33FFFFFF);
c.drawCircle(hx - hr * 0.35f, hy - hr * 0.4f, hr * 0.2f, fill);
for (int side = -1; side <= 1; side += 2) {
fill.setColor(0xFFFFFFFF);
c.drawCircle(hx + side * 24f * u, hy - 34f * u, 14f * u, fill);
fill.setColor(INK);
c.drawCircle(hx + side * 24f * u + 3f * u, hy - 33f * u, 6f * u, fill);
}
label(c, fmt(v.speedKmh, "%.0f", "—"), hx, hy + 38f * u, 58f * u, 0xFFFFFFFF, serif, Paint.Align.CENTER);
label(c, "KM/H", hx, hy + 58f * u, 14f * u, 0xCCFFE9EA, face, Paint.Align.CENTER);
boolean regen = regen();
String power = v.powerKw == null ? "— kW" : String.format(Locale.US, regen ? "+%.1f kW" : "%.1f kW",
Math.abs(v.powerKw));
outlined(c, power, hx - 100f * u - 4.5f * 54f * u, 556f * u, 34f * u, regen ? ICE : BONE, face, Paint.Align.CENTER, u);
}
// ---------- What plays: a butterfly or a ladybird tows it on tissue paper ----------
/**
* A butterfly and a ladybird take turns towing a waving strip of tissue paper with the song across
* the sky, behind the clock and the leaf, again and again while something plays. The paper's
* colour is fixed by the song. Returns whether it is drawn, so the view keeps animating for it.
*/
private boolean drawSong(Canvas c, int w, float u) {
if (v.songTitle == null) return false;
text.setTypeface(face);
text.setTextSize(19f * u);
text.setStyle(Paint.Style.FILL);
String s = SongBanner.line(text, v.songTitle, v.songArtist, Math.min(560f * u, w * 0.45f));
float t = SystemClock.uptimeMillis() / 1000f;
float bw = text.measureText(s) + 40f * u, bh = 28f * u, tow = 76f * u;
float bx = SongBanner.left(t, w, bw, tow, u);
float yc = 66f * u + (float) Math.sin(t * 1.3f) * 3f * u;
int paper = TISSUE[Math.floorMod((v.songTitle + "\n" + v.songArtist).hashCode(), TISSUE.length)];
boolean darkInk = paper == TISSUE[3] || paper == TISSUE[5];
banner.draw(c, fill, line, text, s, bx, yc, bw, bh, t, u, 9f * u, paper, 0x66FFFFFF, darkInk ? INK : 0xFFFFFFFF);
boolean butterfly = SongBanner.pass(t, w, bw, tow, u) % 2 == 0;
float right = bx + bw, cx = right + tow, cy = yc - 4f * u, size = (butterfly ? 60f : 44f) * u;
float[] tail = butterfly ? SongCarriers.butterflyTail : SongCarriers.ladybirdTail;
float ax = cx + tail[0] * size, ay = cy + tail[1] * size;
line.setColor(0xCCFFFFFF);
line.setStrokeWidth(1.5f * u);
c.drawLine(right, yc - bh / 2f + 3f * u, ax, ay, line);
c.drawLine(right, yc + bh / 2f - 3f * u, ax, ay, line);
float flap = (float) Math.sin(t * (butterfly ? 7f : 18f));
if (butterfly) SongCarriers.butterfly(c, fill, line, path, r, cx, cy, size, flap, u);
else SongCarriers.ladybird(c, fill, line, path, r, cx, cy, size, flap, u);
return true;
}
}
@@ -0,0 +1,616 @@
package com.evsuite.abrp;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.DashPathEffect;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RadialGradient;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.Typeface;
import android.os.SystemClock;
import java.util.Locale;
/**
* The Christmas Overview style: a snowy village night, warm and festive.
*
* In the middle a Christmas tree with a big red bauble in front of it: the speed. Fairy lights
* arch over the tree: the power, left to right in warm gold while drawing, ice blue and right to
* left while regenerating. On the left a glass mug of hot cocoa filling with the charge, cold blue
* with "BATTERY LOW" blinking below 20 %, under gift tags with trip, usage, climate and odometer.
* On the right a wreath holds the clock, and a snowy signboard reads the range, with a candy cane
* per 50 km; P R N D are four baubles, the one engaged lit. The snow drift along the bottom is the
* last two minutes of power, rising with it, in gold or, where it regenerated, ice blue. Unread
* values show "—" and light nothing. With music playing, the tree's lights and the fairy lights
* flare on the beat ({@link MusicTap}); with no music they twinkle as before. What plays crosses
* the sky on a banner of wrapping paper, towed by Santa's sleigh and, on the next pass, an angel
* ({@link NowPlaying}).
*
* The night, the hills and the stars are drawn once into a bitmap per size; only the rest goes over
* it. Snow falls and the lights twinkle (about 30 frames a second) only while the car moves and the
* view is on screen; the lights' pulse and the song keep it drawing while there are any.
*/
final class ChristmasView extends ClusterCanvasView {
private static final int BULBS = 25, FLAKES = 70, CANES = 8;
private static final int SKY_TOP = 0xFF06142B, SKY_LOW = 0xFF173A5E, SKY_END = 0xFF2A5A7A;
private static final int SNOW = 0xFFE9F2FF, PINE = 0xFF1F7A3C, PINE_DARK = 0xFF0F4A24;
private static final int RED = 0xFFE53946, GOLD = 0xFFFFD04A, BONE = 0xFFF6F0E4, INK = 0xFF1B0F12;
private static final int COCOA = 0xFF7B3F22, COLD = 0xFF4A8AD0, ICE = 0xFF8FD8FF, WOOD = 0xFF4A2E1A;
private static final int[] LIGHTS = { RED, GOLD, ICE, 0xFFFFFFFF, 0xFF5CE08A };
private static final int[] PAPER = { 0xFFC62828, 0xFF1E7B3C, 0xFF2B5FA8, 0xFFD9A62E, 0xFFF1F1F1 };
private final Paint fill = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint line = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint text = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint image = new Paint(Paint.FILTER_BITMAP_FLAG);
private final Paint glow = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Path path = new Path();
private final SongBanner banner = new SongBanner();
private final RectF r = new RectF();
private final Typeface serif = Typeface.create("serif", Typeface.BOLD);
private final Typeface face = Typeface.create("sans-serif-condensed", Typeface.BOLD);
private final Typeface thin = Typeface.create("sans-serif-condensed", Typeface.NORMAL);
private Bitmap sky;
private int skyW, skyH;
private float time;
private long lastFrame;
private MusicTap music;
ChristmasView(Context context) {
super(context);
line.setStyle(Paint.Style.STROKE);
line.setStrokeCap(Paint.Cap.ROUND);
}
/** Where the lights hear the music; without it, they do not follow any. */
void setMusic(MusicTap tap) {
music = tap;
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
sky = null;
skyW = 0;
}
@Override
protected void onDraw(Canvas c) {
super.onDraw(c);
int w = getWidth(), h = getHeight();
if (w <= 0 || h <= 0) return;
float u = Math.min(h / 640f, w / 1100f);
boolean moving = v.speedKmh != null && v.speedKmh > 0.5f;
if (moving) {
long now = SystemClock.uptimeMillis();
time += lastFrame == 0 ? 0f : Math.min(0.2f, (now - lastFrame) / 1000f);
lastFrame = now;
} else {
lastFrame = 0;
}
if (sky == null || skyW != w || skyH != h) buildSky(w, h, u);
c.drawBitmap(sky, 0, 0, image);
boolean song = drawSong(c, w, u);
drawSnow(c, w, h, u);
drawDrift(c, w, h, u);
float pulse = music == null ? 0f : music.pulse();
drawTree(c, w, u, pulse);
drawArch(c, w, u, pulse);
drawBauble(c, w, u, pulse);
drawWreath(c, w, u);
drawTags(c, u);
drawMug(c, u);
drawBoard(c, w, u);
drawGears(c, w, u);
keepAnimating(moving || pulse > 0f || song, 33);
}
private void label(Canvas c, String s, float x, float y, float size, int colour, Typeface tf, Paint.Align a) {
text.setTypeface(tf);
text.setTextSize(size);
text.setTextAlign(a);
text.setColor(colour);
c.drawText(s, x, y, text);
}
/** Text with a dark outline, to read over whatever is behind it. */
private void outlined(Canvas c, String s, float x, float y, float size, int colour, Typeface tf, Paint.Align a, float u) {
text.setStyle(Paint.Style.STROKE);
text.setStrokeWidth(Math.max(3f * u, size * 0.12f));
text.setStrokeJoin(Paint.Join.ROUND);
label(c, s, x, y, size, 0xDD0A0608, tf, a);
text.setStyle(Paint.Style.FILL);
label(c, s, x, y, size, colour, tf, a);
}
private boolean regen() {
return v.powerKw != null && v.powerKw < -0.05f;
}
// ---------- Night sky and hills ----------
private void buildSky(int w, int h, float u) {
sky = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
skyW = w;
skyH = h;
Canvas c = new Canvas(sky);
Paint p = new Paint();
p.setShader(new LinearGradient(0, 0, 0, h, new int[] { SKY_TOP, SKY_LOW, SKY_END },
new float[] { 0f, 0.7f, 1f }, Shader.TileMode.CLAMP));
c.drawRect(0, 0, w, h, p);
Paint star = new Paint(Paint.ANTI_ALIAS_FLAG);
star.setColor(0x99FFFFFF);
for (int i = 0; i < 90; i++) {
float x = ((i * 191 + 17) % 1009) / 1009f * w, y = ((i * 83 + 5) % 421) * u;
c.drawCircle(x, y, (i % 4 == 0 ? 1.7f : 0.9f) * u, star);
}
// Two ranges of snowy hills, with pines on the far one.
hills(c, w, h, h - 150f * u, 0xFF28496B, 0.8f, u);
Paint pine = new Paint(Paint.ANTI_ALIAS_FLAG);
pine.setColor(0xFF0F3A2A);
for (int i = 0; i < 14; i++) {
float x = ((i * 233 + 41) % 997) / 997f * w, tall = (36f + (i * 17) % 30) * u;
float base = h - 150f * u + 8f * u;
Path tri = new Path();
tri.moveTo(x, base - tall);
tri.lineTo(x + tall * 0.32f, base);
tri.lineTo(x - tall * 0.32f, base);
tri.close();
c.drawPath(tri, pine);
}
hills(c, w, h, h - 100f * u, 0xFF3C6286, 1.5f, u);
}
private void hills(Canvas c, int w, int h, float base, int colour, float wave, float u) {
Path hill = new Path();
hill.moveTo(0, h);
for (int i = 0; i <= 24; i++) {
float x = w * i / 24f;
hill.lineTo(x, base - (float) (Math.sin(i * wave) * 0.5 + Math.sin(i * wave * 0.37 + 1) * 0.5) * 22f * u);
}
hill.lineTo(w, h);
hill.close();
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setColor(colour);
c.drawPath(hill, p);
}
private void drawSnow(Canvas c, int w, int h, float u) {
for (int i = 0; i < FLAKES; i++) {
float fall = (30f + (i % 5) * 12f) * u;
float y = (((i * 53) % 600) * u + time * fall) % h;
float x = ((i * 97 + 13) % 1000) / 1000f * w + (float) Math.sin(time * 0.8f + i) * 12f * u;
fill.setColor(i % 3 == 0 ? 0xE0FFFFFF : 0x90FFFFFF);
c.drawCircle(x, y, (1f + (i % 3) * 0.8f) * u, fill);
}
}
// ---------- The drift: the last two minutes of power ----------
private void drawDrift(Canvas c, int w, int h, float u) {
float base = h - 44f * u, amp = 36f * u;
float[] trail = v.powerTrail;
path.reset();
path.moveTo(0, h);
int n = trail == null ? 0 : trail.length;
if (n == 0) {
path.lineTo(0, base);
path.lineTo(w, base);
} else {
for (int i = 0; i < n; i++) {
float p = trail[i];
float height = Float.isNaN(p) ? 0f : Math.min(1f, Math.abs(p) / (p < 0 ? 40f : 60f));
path.lineTo(i / (n - 1f) * w, base - height * amp);
}
}
path.lineTo(w, h);
path.close();
fill.setColor(SNOW);
c.drawPath(path, fill);
if (n > 1) {
line.setStrokeWidth(3f * u);
for (int i = 1; i < n; i++) {
float a = trail[i - 1], b = trail[i];
if (Float.isNaN(a) || Float.isNaN(b)) continue;
float ha = Math.min(1f, Math.abs(a) / (a < 0 ? 40f : 60f));
float hb = Math.min(1f, Math.abs(b) / (b < 0 ? 40f : 60f));
line.setColor(b < 0 ? ICE : GOLD);
c.drawLine((i - 1f) / (n - 1f) * w, base - ha * amp, i / (n - 1f) * w, base - hb * amp, line);
}
}
}
// ---------- The tree ----------
private void drawTree(Canvas c, int w, float u, float pulse) {
float cx = w / 2f;
// The trunk, then three tiers, each with a darker underside.
r.set(cx - 22f * u, 480f * u, cx + 22f * u, 526f * u);
fill.setColor(WOOD);
c.drawRect(r, fill);
tier(c, cx, 118f * u, 238f * u, 96f * u, u);
tier(c, cx, 190f * u, 358f * u, 136f * u, u);
tier(c, cx, 270f * u, 492f * u, 182f * u, u);
// The star on top, flaring with the music.
float sy = 104f * u, flare = 1f + pulse * 0.5f;
glow.setShader(new RadialGradient(cx, sy, 60f * u * flare,
new int[] { AccentColor.withAlpha(GOLD, 0x55 + (int) (pulse * 0x80)), AccentColor.withAlpha(GOLD, 0) }, null,
Shader.TileMode.CLAMP));
c.drawCircle(cx, sy, 60f * u * flare, glow);
path.reset();
for (int i = 0; i < 10; i++) {
double a = -Math.PI / 2 + Math.PI * i / 5;
float rad = (i % 2 == 0 ? 24f : 10f) * u;
float x = cx + (float) Math.cos(a) * rad, y = sy + (float) Math.sin(a) * rad;
if (i == 0) path.moveTo(x, y);
else path.lineTo(x, y);
}
path.close();
fill.setColor(GOLD);
c.drawPath(path, fill);
// The lights: strung along each tier's lower edge, steady, twinkling a little while driving,
// flaring together on the beat.
float[][] strings = { { 238f, 96f, 5 }, { 358f, 136f, 7 }, { 492f, 182f, 10 } };
int i = 0;
for (float[] st : strings) {
int n = (int) st[2];
for (int k = 0; k < n; k++, i++) {
float x = cx - st[1] * 0.85f * u + k * (1.7f * st[1] * u) / (n - 1);
float y = (st[0] - 16f + (k % 2) * 9f) * u;
int colour = LIGHTS[i % LIGHTS.length];
float twinkle = 0.5f + 0.5f * (float) Math.sin(time * 3f + i * 1.7f);
int alpha = Math.min(0xFF, 0x58 + (int) (twinkle * 0x38) + (int) (pulse * 0x90));
fill.setColor(AccentColor.withAlpha(colour, alpha));
c.drawCircle(x, y, (11f + pulse * 9f) * u, fill);
fill.setColor(brighter(colour, pulse * 0.4f));
c.drawCircle(x, y, 4.8f * u * (1f + pulse * 0.35f), fill);
}
}
}
private void tier(Canvas c, float cx, float apex, float base, float half, float u) {
for (int pass = 0; pass < 2; pass++) {
float dy = pass == 0 ? 7f * u : 0f;
path.reset();
path.moveTo(cx, apex + dy);
path.lineTo(cx + half, base - 6f * u + dy);
int scallops = 5;
float sw = half * 2f / scallops;
for (int i = scallops; i > 0; i--) {
float x = cx - half + i * sw;
path.quadTo(x - sw / 2f, base + 12f * u + dy, x - sw, base - 6f * u + dy);
}
path.close();
fill.setColor(pass == 0 ? PINE_DARK : PINE);
c.drawPath(path, fill);
}
}
/** The colour moved {@code share} of the way to white. */
private static int brighter(int colour, float share) {
int r = (colour >> 16) & 0xFF, g = (colour >> 8) & 0xFF, b = colour & 0xFF;
return 0xFF000000 | (r + (int) ((255 - r) * share)) << 16 | (g + (int) ((255 - g) * share)) << 8
| (b + (int) ((255 - b) * share));
}
// ---------- The fairy lights over the tree: the power ----------
private void drawArch(Canvas c, int w, float u, float pulse) {
float cx = w / 2f, cy = 348f * u, radX = 272f * u, radY = 244f * u;
int lit = Tally.ofPower(v.powerKw, 150f, 50f, BULBS);
boolean regen = regen();
// The wire.
line.setColor(PINE_DARK);
line.setStrokeWidth(3f * u);
path.reset();
for (int i = 0; i <= 48; i++) {
double a = Math.PI + Math.PI * i / 48.0;
float x = cx + (float) Math.cos(a) * radX, y = cy + (float) Math.sin(a) * radY;
if (i == 0) path.moveTo(x, y);
else path.lineTo(x, y);
}
c.drawPath(path, line);
for (int i = 0; i < BULBS; i++) {
// Left to right over the top; regeneration comes back from the right.
int k = regen ? BULBS - 1 - i : i;
double a = Math.PI + Math.PI * k / (BULBS - 1);
float x = cx + (float) Math.cos(a) * radX, y = cy + (float) Math.sin(a) * radY;
boolean on = i < lit;
if (on) {
fill.setColor(AccentColor.withAlpha(regen ? ICE : GOLD, 0x44 + (int) (pulse * 0x50)));
c.drawCircle(x, y, (15f + pulse * 6f) * u, fill);
}
fill.setColor(on ? brighter(regen ? ICE : GOLD, pulse * 0.4f) : 0x38FFFFFF);
c.drawCircle(x, y, 7.5f * u, fill);
}
}
// ---------- The big bauble: the speed ----------
private void drawBauble(Canvas c, int w, float u, float pulse) {
float cx = w / 2f, cy = 372f * u, rad = 88f * u;
glow.setShader(new RadialGradient(cx, cy, rad * (1.6f + pulse * 0.2f),
new int[] { AccentColor.withAlpha(RED, 0x40 + (int) (pulse * 0x50)), AccentColor.withAlpha(RED, 0) }, null,
Shader.TileMode.CLAMP));
c.drawCircle(cx, cy, rad * (1.6f + pulse * 0.2f), glow);
// The cap and its loop.
line.setColor(GOLD);
line.setStrokeWidth(3f * u);
r.set(cx - 12f * u, cy - rad - 30f * u, cx + 12f * u, cy - rad - 6f * u);
c.drawOval(r, line);
glow.setShader(new RadialGradient(cx - rad * 0.3f, cy - rad * 0.35f, rad * 1.3f,
new int[] { 0xFFFF7A82, RED, 0xFF8E1623 }, new float[] { 0f, 0.5f, 1f }, Shader.TileMode.CLAMP));
c.drawCircle(cx, cy, rad, glow);
r.set(cx - 16f * u, cy - rad - 12f * u, cx + 16f * u, cy - rad + 8f * u);
fill.setColor(GOLD);
c.drawRect(r, fill);
// A gold band round the middle's lower half, and a highlight.
line.setColor(0x88FFD04A);
line.setStrokeWidth(3f * u);
r.set(cx - rad + 6f * u, cy + 34f * u, cx + rad - 6f * u, cy + rad - 4f * u);
c.drawArc(r, 20f, 140f, false, line);
fill.setColor(0x55FFFFFF);
r.set(cx - rad * 0.62f, cy - rad * 0.72f, cx - rad * 0.2f, cy - rad * 0.42f);
c.drawOval(r, fill);
label(c, fmt(v.speedKmh, "%.0f", "—"), cx, cy + 20f * u, 84f * u, BONE, serif, Paint.Align.CENTER);
label(c, "KM/H", cx, cy + 50f * u, 16f * u, 0xCCFFE9EA, face, Paint.Align.CENTER);
// The power under the tree, above the drift.
boolean regen = regen();
String power = v.powerKw == null ? "— kW" : String.format(Locale.US, regen ? "+%.1f kW" : "%.1f kW",
Math.abs(v.powerKw));
outlined(c, power, cx, 556f * u, 34f * u, regen ? ICE : BONE, face, Paint.Align.CENTER, u);
}
// ---------- The wreath: the clock ----------
private void drawWreath(Canvas c, int w, float u) {
float rad = 74f * u, cx = w - 100f * u - rad * 0.2f, cy = 96f * u;
line.setColor(PINE);
line.setStrokeWidth(24f * u);
c.drawCircle(cx, cy, rad, line);
line.setColor(PINE_DARK);
line.setStrokeWidth(5f * u);
c.drawCircle(cx, cy, rad - 8f * u, line);
fill.setColor(0xFF2E9C52);
for (int i = 0; i < 16; i++) {
double a = Math.PI * 2 * i / 16;
c.drawCircle(cx + (float) Math.cos(a) * rad, cy + (float) Math.sin(a) * rad, 8f * u, fill);
}
fill.setColor(RED);
for (int i = 0; i < 9; i++) {
double a = Math.PI * 2 * i / 9 + 0.3;
c.drawCircle(cx + (float) Math.cos(a) * rad, cy + (float) Math.sin(a) * rad, 4.5f * u, fill);
}
// The bow at the foot.
path.reset();
float bx = cx, by = cy + rad;
path.moveTo(bx, by);
path.lineTo(bx - 28f * u, by - 14f * u);
path.lineTo(bx - 28f * u, by + 14f * u);
path.close();
path.moveTo(bx, by);
path.lineTo(bx + 28f * u, by - 14f * u);
path.lineTo(bx + 28f * u, by + 14f * u);
path.close();
fill.setColor(RED);
c.drawPath(path, fill);
c.drawCircle(bx, by, 7f * u, fill);
// The clock face inside.
fill.setColor(0xFFFFF6E0);
c.drawCircle(cx, cy, rad - 18f * u, fill);
line.setColor(GOLD);
line.setStrokeWidth(3f * u);
c.drawCircle(cx, cy, rad - 18f * u, line);
label(c, v.clock.isEmpty() ? "—" : v.clock, cx, cy + 14f * u, 40f * u, INK, serif, Paint.Align.CENTER);
}
// ---------- Gift tags: trip, usage, climate, odometer ----------
private void drawTags(Canvas c, float u) {
float l = 28f * u, rr = l + 300f * u, t = 44f * u, tag = 34f * u, step = 38f * u;
// The garland they hang from.
line.setColor(PINE);
line.setStrokeWidth(8f * u);
c.drawLine(l + 10f * u, 20f * u, rr - 10f * u, 20f * u, line);
fill.setColor(RED);
for (int i = 0; i < 7; i++) c.drawCircle(l + 24f * u + i * 44f * u, 20f * u, 4f * u, fill);
String[][] rows = {
{ "TRIP", fmt(v.tripKm, "%.1f km", "—") },
{ "5 MIN", fmt(v.usage5Min, "%.1f kWh/100", "—") },
{ "SINCE START", fmt(v.usageTrip, "%.1f kWh/100", "—") },
{ "CLIMATE", fmt(v.climateCelsius, "%.0f °C", "—") },
{ "ODOMETER", fmt(v.odometerKm, "%,.0f km", "—") },
};
for (int i = 0; i < rows.length; i++) {
float top = t + i * step;
// A tag with a clipped corner and a hole, hung on a thread from the one above.
path.reset();
path.moveTo(l + 18f * u, top);
path.lineTo(rr, top);
path.lineTo(rr, top + tag);
path.lineTo(l + 18f * u, top + tag);
path.lineTo(l, top + tag / 2f);
path.close();
fill.setColor(i % 2 == 0 ? 0xFFF6EBD0 : 0xFFEAD9B6);
c.drawPath(path, fill);
line.setColor(RED);
line.setStrokeWidth(2f * u);
c.drawPath(path, line);
line.setColor(0xCCFFFFFF);
line.setStrokeWidth(1.5f * u);
c.drawLine(l + 12f * u, top - (i == 0 ? 20f * u - 0f : step - tag), l + 12f * u, top + tag / 2f, line);
fill.setColor(0xFF2A1A10);
c.drawCircle(l + 12f * u, top + tag / 2f, 3f * u, fill);
label(c, rows[i][0], l + 28f * u, top + 23f * u, 17f * u, 0xFF8E1623, thin, Paint.Align.LEFT);
label(c, rows[i][1], rr - 12f * u, top + 25f * u, 22f * u, INK, face, Paint.Align.RIGHT);
}
}
// ---------- The mug of cocoa: the battery ----------
private void drawMug(Canvas c, float u) {
float cx = 178f * u, l = cx - 92f * u, rr = cx + 92f * u, top = 330f * u, bottom = 560f * u;
boolean low = v.socPercent != null && v.socPercent < 20f;
boolean blinkOn = (SystemClock.uptimeMillis() / 500) % 2 == 0;
float corner = 22f * u, inner = 6f * u;
// The handle.
line.setColor(0xFFCFE6F0);
line.setStrokeWidth(14f * u);
r.set(rr - 26f * u, top + 50f * u, rr + 40f * u, top + 170f * u);
c.drawArc(r, -90f, 180f, false, line);
// The glass.
r.set(l, top, rr, bottom);
fill.setColor(0x30CFE6F0);
c.drawRoundRect(r, corner, corner, fill);
if (v.socPercent != null) {
float share = Math.max(0f, Math.min(1f, v.socPercent / 100f));
float level = bottom - inner - share * (bottom - top - 2f * inner);
c.save();
r.set(l + inner, top + inner, rr - inner, bottom - inner);
path.reset();
path.addRoundRect(r, corner - inner, corner - inner, Path.Direction.CW);
c.clipPath(path);
fill.setColor(low ? COLD : COCOA);
c.drawRect(l, level, rr, bottom, fill);
fill.setColor(0x33FFFFFF);
c.drawRect(l, level, rr, level + 4f * u, fill);
c.restore();
// Marshmallows float on top, bobbing while driving.
for (int i = 0; i < 3; i++) {
float mx = cx + (i - 1) * 50f * u, my = level - 8f * u + (float) Math.sin(time * 2f + i * 2f) * 2f * u;
r.set(mx - 14f * u, my - 12f * u, mx + 14f * u, my + 8f * u);
fill.setColor(BONE);
c.drawRoundRect(r, 6f * u, 6f * u, fill);
}
// Steam.
line.setColor(0x66FFFFFF);
line.setStrokeWidth(4f * u);
for (int i = 0; i < 3; i++) {
float sx = cx + (i - 1) * 44f * u;
path.reset();
path.moveTo(sx, level - 24f * u);
for (int k = 1; k <= 6; k++) {
path.lineTo(sx + (float) Math.sin(time * 2.5f + i + k * 0.9f) * 9f * u, level - 24f * u - k * 11f * u);
}
c.drawPath(path, line);
}
}
line.setColor(0xFFCFE6F0);
line.setStrokeWidth(4f * u);
r.set(l, top, rr, bottom);
c.drawRoundRect(r, corner, corner, line);
String number = fmt(v.socPercent, "%.0f %%", "—");
outlined(c, number, cx, 470f * u, 58f * u, low ? 0xFFFF9AA3 : BONE, serif, Paint.Align.CENTER, u);
if (low && blinkOn) outlined(c, "BATTERY LOW", cx, 508f * u, 21f * u, BONE, face, Paint.Align.CENTER, u);
else if (!low) outlined(c, "BATTERY", cx, 508f * u, 19f * u, GOLD, face, Paint.Align.CENTER, u);
}
// ---------- The signboard and candy canes: the range; baubles: the gears ----------
private void drawBoard(Canvas c, int w, float u) {
float rr = w - 40f * u, l = rr - 250f * u, t = 214f * u, b = 394f * u, mid = (l + rr) / 2f;
r.set(l, t, rr, b);
fill.setColor(WOOD);
c.drawRoundRect(r, 10f * u, 10f * u, fill);
line.setColor(0xFF8A5A33);
line.setStrokeWidth(3f * u);
c.drawRoundRect(r, 10f * u, 10f * u, line);
// Snow on top.
path.reset();
path.moveTo(l - 4f * u, t + 4f * u);
path.quadTo(l + 40f * u, t - 24f * u, l + 90f * u, t - 4f * u);
path.quadTo(l + 140f * u, t - 28f * u, l + 190f * u, t - 6f * u);
path.quadTo(l + 230f * u, t - 16f * u, rr + 4f * u, t + 4f * u);
path.lineTo(rr + 4f * u, t + 12f * u);
path.lineTo(l - 4f * u, t + 12f * u);
path.close();
fill.setColor(SNOW);
c.drawPath(path, fill);
label(c, "RANGE", mid, t + 52f * u, 20f * u, GOLD, face, Paint.Align.CENTER);
label(c, fmt(v.rangeKm, "%.0f", "—"), mid, t + 128f * u, 80f * u, BONE, serif, Paint.Align.CENTER);
label(c, "KM", mid, t + 160f * u, 20f * u, GOLD, face, Paint.Align.CENTER);
// A candy cane per 50 km in the snow below.
int lit = Tally.lit(v.rangeKm, 50f, CANES);
for (int i = 0; i < CANES; i++) {
cane(c, l + 18f * u + i * 30f * u, 488f * u, u, i < lit);
}
}
private void cane(Canvas c, float x, float foot, float u, boolean on) {
path.reset();
path.moveTo(x, foot);
path.lineTo(x, foot - 58f * u);
path.cubicTo(x, foot - 78f * u, x + 18f * u, foot - 78f * u, x + 18f * u, foot - 62f * u);
line.setStrokeWidth(9f * u);
line.setColor(on ? 0xFFFFFFFF : 0x40FFFFFF);
c.drawPath(path, line);
line.setColor(on ? RED : 0x40E53946);
line.setPathEffect(new DashPathEffect(new float[] { 7f * u, 7f * u }, 0f));
c.drawPath(path, line);
line.setPathEffect(null);
}
private void drawGears(Canvas c, int w, float u) {
float rr = w - 40f * u, l = rr - 250f * u, cy = 540f * u, rad = 25f * u;
String[] gears = { "P", "R", "N", "D" };
String now = Gear.label(v.gear);
float step = (rr - l) / 4f;
for (int i = 0; i < gears.length; i++) {
float mid = l + (i + 0.5f) * step;
boolean on = gears[i].equals(now);
if (on) {
fill.setColor(0x55FFD04A);
c.drawCircle(mid, cy, 42f * u, fill);
}
fill.setColor(GOLD);
r.set(mid - 7f * u, cy - rad - 9f * u, mid + 7f * u, cy - rad + 3f * u);
c.drawRect(r, fill);
fill.setColor(on ? GOLD : 0xFF7A1F2A);
c.drawCircle(mid, cy, rad, fill);
line.setColor(on ? 0xFFFFF0B0 : 0xFFB03A48);
line.setStrokeWidth(2f * u);
c.drawCircle(mid, cy, rad, line);
label(c, gears[i], mid, cy + 11f * u, 30f * u, on ? INK : 0xB0FFFFFF, serif, Paint.Align.CENTER);
}
}
// ---------- What plays: a sleigh or an angel tows it on wrapping paper ----------
/**
* Santa's sleigh and an angel take turns towing a waving strip of wrapping paper with the song
* across the sky above the tree, behind the wreath and the tags, again and again while
* something plays. The paper's colour is fixed by the song. Returns whether it is drawn, so the
* view keeps animating for it.
*/
private boolean drawSong(Canvas c, int w, float u) {
if (v.songTitle == null) return false;
text.setTypeface(face);
text.setTextSize(19f * u);
text.setStyle(Paint.Style.FILL);
String s = SongBanner.line(text, v.songTitle, v.songArtist, Math.min(560f * u, w * 0.45f));
float t = SystemClock.uptimeMillis() / 1000f;
float bw = text.measureText(s) + 40f * u, bh = 28f * u, tow = 80f * u;
float bx = SongBanner.left(t, w, bw, tow, u);
float yc = 66f * u + (float) Math.sin(t * 1.3f) * 3f * u;
int paper = PAPER[Math.floorMod((v.songTitle + "\n" + v.songArtist).hashCode(), PAPER.length)];
boolean darkInk = paper == PAPER[3] || paper == PAPER[4];
banner.draw(c, fill, line, text, s, bx, yc, bw, bh, t, u, 0f, paper, 0xCCFFFFFF, darkInk ? INK : 0xFFFFFFFF);
boolean sleigh = SongBanner.pass(t, w, bw, tow, u) % 2 == 0;
float right = bx + bw, cx = right + tow, cy = yc - 6f * u, size = (sleigh ? 70f : 56f) * u;
float[] tail = sleigh ? SongCarriers.sleighTail : SongCarriers.angelTail;
float ax = cx + tail[0] * size, ay = cy + tail[1] * size;
line.setColor(0xCCFFFFFF);
line.setStrokeWidth(1.5f * u);
c.drawLine(right, yc - bh / 2f + 3f * u, ax, ay, line);
c.drawLine(right, yc + bh / 2f - 3f * u, ax, ay, line);
if (sleigh) SongCarriers.sleigh(c, fill, line, path, r, cx, cy, size, t, u);
else SongCarriers.angel(c, fill, line, path, r, cx, cy, size, (float) Math.sin(t * 7f), u);
return true;
}
}
@@ -23,4 +23,6 @@ final class ClusterValues {
String tyreFl = "—", tyreFr = "—", tyreRl = "—", tyreRr = "—"; String tyreFl = "—", tyreFr = "—", tyreRl = "—", tyreRr = "—";
/** Battery power over the last two minutes, oldest first, NaN where unread; null before any. */ /** Battery power over the last two minutes, oldest first, NaN where unread; null before any. */
float[] powerTrail; float[] powerTrail;
/** What plays ({@link NowPlaying}): the title, null when nothing does or it is off, and the artist or null. */
String songTitle, songArtist;
} }
@@ -38,6 +38,7 @@ final class EmpireView extends ClusterCanvasView {
private final Paint fill = new Paint(Paint.ANTI_ALIAS_FLAG); private final Paint fill = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint text = new Paint(Paint.ANTI_ALIAS_FLAG); private final Paint text = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Path path = new Path(); private final Path path = new Path();
private final SongBanner banner = new SongBanner();
private final RectF r = new RectF(); private final RectF r = new RectF();
private final Typeface serif = Typeface.create(Typeface.SERIF, Typeface.BOLD); private final Typeface serif = Typeface.create(Typeface.SERIF, Typeface.BOLD);
private final Typeface sans = Typeface.create("sans-serif-condensed", Typeface.BOLD); private final Typeface sans = Typeface.create("sans-serif-condensed", Typeface.BOLD);
@@ -61,10 +62,38 @@ final class EmpireView extends ClusterCanvasView {
advance(moving); advance(moving);
float top = 46f * u, bottom = h - 186f * u; float top = 46f * u, bottom = h - 186f * u;
drawWorld(c, w, top, bottom, u); drawWorld(c, w, top, bottom, u);
boolean song = drawSong(c, w, top, u);
drawSpeed(c, w, top, u); drawSpeed(c, w, top, u);
drawResources(c, w, top, u); drawResources(c, w, top, u);
drawPanel(c, w, h, bottom, u); drawPanel(c, w, h, bottom, u);
keepAnimating(moving, 33); keepAnimating(moving || song, 33);
}
// ---------- What plays: an eagle brings it on a scroll ----------
/**
* An eagle flies a waving scroll with the song across the top of the world, behind the speed,
* again and again while something plays. Returns whether it is drawn, so the view keeps animating.
*/
private boolean drawSong(Canvas c, float w, float top, float u) {
if (v.songTitle == null) return false;
text.setTypeface(serif);
text.setTextSize(19f * u);
text.setStyle(Paint.Style.FILL);
String s = SongBanner.line(text, v.songTitle, v.songArtist, Math.min(560f * u, w * 0.45f));
float t = SystemClock.uptimeMillis() / 1000f;
float bw = text.measureText(s) + 40f * u, bh = 28f * u, size = 58f * u, tow = size * 1.0f;
float bx = SongBanner.left(t, Math.round(w), bw, tow, u);
float yc = top + 30f * u + (float) Math.sin(t * 1.3f) * 3f * u;
banner.draw(c, fill, line, text, s, bx, yc, bw, bh, t, u, 0f, 0xFFEFE0B8, WOOD_DARK, 0xFF2A1A08);
float right = bx + bw, cx = right + tow, cy = yc - 10f * u;
line.setColor(0xCCFFFFFF);
line.setStrokeWidth(1.5f * u);
float ax = cx + SongCarriers.eagleTail[0] * size, ay = cy + SongCarriers.eagleTail[1] * size;
c.drawLine(right, yc - bh / 2f + 3f * u, ax, ay, line);
c.drawLine(right, yc + bh / 2f - 3f * u, ax, ay, line);
SongCarriers.eagle(c, fill, line, path, r, cx, cy, size, (float) Math.sin(t * 7f), t, u);
return true;
} }
private void advance(boolean moving) { private void advance(boolean moving) {
@@ -27,7 +27,7 @@ import java.util.Locale;
* of power, rising with it, in orange or, where it regenerated, green. Unread values show "—" and * of power, rising with it, in orange or, where it regenerated, green. Unread values show "—" and
* light nothing. With music playing, the pumpkin's glow swells and its carving brightens on the * light nothing. With music playing, the pumpkin's glow swells and its carving brightens on the
* beat ({@link MusicTap}); colours and the embers keep their meaning, and with no music it burns as * beat ({@link MusicTap}); colours and the embers keep their meaning, and with no music it burns as
* before. * before. What plays flies across the sky on a banner a bat tows ({@link NowPlaying}).
* *
* The night sky is drawn once into a bitmap per size; only the rest goes over it. Bats, bubbles and * The night sky is drawn once into a bitmap per size; only the rest goes over it. Bats, bubbles and
* the ghost move (about 30 frames a second) only while the car moves and the view is on screen; * the ghost move (about 30 frames a second) only while the car moves and the view is on screen;
@@ -50,6 +50,7 @@ final class HalloweenView extends ClusterCanvasView {
private final Paint image = new Paint(Paint.FILTER_BITMAP_FLAG); private final Paint image = new Paint(Paint.FILTER_BITMAP_FLAG);
private final Paint glow = new Paint(Paint.ANTI_ALIAS_FLAG); private final Paint glow = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Path path = new Path(); private final Path path = new Path();
private final SongBanner banner = new SongBanner();
private final RectF r = new RectF(); private final RectF r = new RectF();
private final Typeface serif = Typeface.create("serif", Typeface.BOLD); private final Typeface serif = Typeface.create("serif", Typeface.BOLD);
private final Typeface face = Typeface.create("sans-serif-condensed", Typeface.BOLD); private final Typeface face = Typeface.create("sans-serif-condensed", Typeface.BOLD);
@@ -96,6 +97,7 @@ final class HalloweenView extends ClusterCanvasView {
if (sky == null || skyW != w || skyH != h) buildSky(w, h, u); if (sky == null || skyW != w || skyH != h) buildSky(w, h, u);
c.drawBitmap(sky, 0, 0, image); c.drawBitmap(sky, 0, 0, image);
drawBats(c, w, u); drawBats(c, w, u);
boolean song = drawSong(c, w, u);
drawMoon(c, w, u); drawMoon(c, w, u);
drawGhost(c, w, u); drawGhost(c, w, u);
drawHill(c, w, h, u); drawHill(c, w, h, u);
@@ -106,7 +108,7 @@ final class HalloweenView extends ClusterCanvasView {
drawFlask(c, u); drawFlask(c, u);
drawTombstone(c, w, u); drawTombstone(c, w, u);
drawGears(c, w, u); drawGears(c, w, u);
keepAnimating(moving || pulse > 0f, 33); keepAnimating(moving || pulse > 0f || song, 33);
} }
private void label(Canvas c, String s, float x, float y, float size, int colour, Typeface tf, Paint.Align a) { private void label(Canvas c, String s, float x, float y, float size, int colour, Typeface tf, Paint.Align a) {
@@ -276,6 +278,34 @@ final class HalloweenView extends ClusterCanvasView {
} }
} }
// ---------- What plays: a bat tows it across the sky on a banner ----------
/**
* A bat pulls a waving parchment banner with the song from left to right, high in the sky, behind the
* sign and the moon, again and again while something plays. Returns whether it is drawn, so
* the view keeps animating for it.
*/
private boolean drawSong(Canvas c, int w, float u) {
if (v.songTitle == null) return false;
text.setTypeface(face);
text.setTextSize(19f * u);
String s = SongBanner.line(text, v.songTitle, v.songArtist, Math.min(560f * u, w * 0.45f));
float t = SystemClock.uptimeMillis() / 1000f;
float bw = text.measureText(s) + 40f * u, bh = 30f * u, tow = 56f * u;
float bx = SongBanner.left(t, w, bw, tow, u);
// In the strip of sky above the sign, clear of it.
float yc = 34f * u + (float) Math.sin(t * 1.3f) * 4f * u;
banner.draw(c, fill, line, text, s, bx, yc, bw, bh, t, u, 0f, BONE, 0xFF8A6A3A, INK);
// The tow lines, and the bat at their end.
float right = bx + bw, batX = right + tow, batY = yc - 10f * u;
line.setColor(BAT_EDGE);
line.setStrokeWidth(1.5f * u);
c.drawLine(right, yc - bh / 2f + 3f * u, batX, batY + 6f * u, line);
c.drawLine(right, yc + bh / 2f - 3f * u, batX, batY + 6f * u, line);
bat(c, batX, batY, 26f * u, (float) Math.sin(t * 12f), u);
return true;
}
// ---------- The arch of embers: the power ---------- // ---------- The arch of embers: the power ----------
private void drawEmbers(Canvas c, int w, float u) { private void drawEmbers(Canvas c, int w, float u) {
@@ -85,6 +85,12 @@ final class LogOutbox {
return true; return true;
} }
/** Removes what waits under names starting with [prefix]. */
static synchronized void dropWaiting(Context context, String prefix) {
File dir = new File(context.getFilesDir(), DIR);
for (String name : waiting(dir)) if (name.startsWith(prefix)) new File(dir, name).delete();
}
/** Sends what waits, unless the last attempt failed less than {@link #RETRY_MS} ago. Blocking: /** Sends what waits, unless the last attempt failed less than {@link #RETRY_MS} ago. Blocking:
* call it off the main thread. */ * call it off the main thread. */
static void sendIfDue(Context context) { static void sendIfDue(Context context) {
@@ -78,6 +78,7 @@ public class MainActivity extends AppCompatActivity {
/** The pane of each Overview style, by its {@link OverviewStyle} ordinal. */ /** The pane of each Overview style, by its {@link OverviewStyle} ordinal. */
private View[] stylePanes; private View[] stylePanes;
private MusicTap musicTap; private MusicTap musicTap;
private NowPlayingWatcher nowPlaying;
private View consumptionPane; private View consumptionPane;
private View chargingPane; private View chargingPane;
/** Display, battery, charging price and Wi-Fi. */ /** Display, battery, charging price and Wi-Fi. */
@@ -197,6 +198,7 @@ public class MainActivity extends AppCompatActivity {
markCurrentPage(position); markCurrentPage(position);
applyOverviewFullScreen(position); applyOverviewFullScreen(position);
updateMusicTap(); updateMusicTap();
updateNowPlaying();
} }
}); });
findViewById(R.id.edge_tab).setOnClickListener(v -> leaveOverviewFullScreen()); findViewById(R.id.edge_tab).setOnClickListener(v -> leaveOverviewFullScreen());
@@ -215,6 +217,10 @@ public class MainActivity extends AppCompatActivity {
/** Whether the Overview hides the navigation (the button in the navigation's header). */ /** Whether the Overview hides the navigation (the button in the navigation's header). */
static final String PREF_OVERVIEW_FULLSCREEN = "overview_fullscreen"; static final String PREF_OVERVIEW_FULLSCREEN = "overview_fullscreen";
/** The Overview shows what plays (the styles that have a place for it); on by default. */
static final String PREF_NOW_PLAYING = "now_playing";
/** The Halloween pumpkin's and the Christmas tree's and the Caterpillar's light follows the music; off by default, so the analyser stays off. */
static final String PREF_MUSIC_LIGHT = "music_light";
/** True while the Overview is full screen: the navigation hidden, the edge swipe armed. */ /** True while the Overview is full screen: the navigation hidden, the edge swipe armed. */
private boolean overviewFull; private boolean overviewFull;
@@ -357,10 +363,16 @@ public class MainActivity extends AppCompatActivity {
visorView = new VisorView(this); visorView = new VisorView(this);
HalloweenView halloweenView = new HalloweenView(this); HalloweenView halloweenView = new HalloweenView(this);
musicTap = new MusicTap(this); musicTap = new MusicTap(this);
nowPlaying = new NowPlayingWatcher(this);
ChristmasView christmasView = new ChristmasView(this);
halloweenView.setMusic(musicTap); halloweenView.setMusic(musicTap);
CaterpillarView caterpillarView = new CaterpillarView(this);
christmasView.setMusic(musicTap);
caterpillarView.setMusic(musicTap);
java.util.Collections.addAll(canvasStyles, new MinimalView(this), terminalView, java.util.Collections.addAll(canvasStyles, new MinimalView(this), terminalView,
new NixieView(this), new ChronographView(this), gridView, gridMapView, new TimeCircuitsView(this), new NixieView(this), new ChronographView(this), gridView, gridMapView, new TimeCircuitsView(this),
new QuestView(this), visorView, new EmpireView(this), new MuertosView(this), halloweenView); new QuestView(this), visorView, new EmpireView(this), new MuertosView(this), halloweenView,
christmasView, caterpillarView);
View[] canvasPanes = new View[canvasStyles.size()]; View[] canvasPanes = new View[canvasStyles.size()];
for (int i = 0; i < canvasPanes.length; i++) canvasPanes[i] = drawnPane(canvasStyles.get(i)); for (int i = 0; i < canvasPanes.length; i++) canvasPanes[i] = drawnPane(canvasStyles.get(i));
// Grid with map: its map layer goes under it, in the same pane. // Grid with map: its map layer goes under it, in the same pane.
@@ -512,6 +524,7 @@ public class MainActivity extends AppCompatActivity {
inFront = true; inFront = true;
updateMapLocation(); updateMapLocation();
updateMusicTap(); updateMusicTap();
updateNowPlaying();
} }
@Override @Override
@@ -562,6 +575,7 @@ public class MainActivity extends AppCompatActivity {
inFront = false; inFront = false;
updateMapLocation(); updateMapLocation();
updateMusicTap(); updateMusicTap();
updateNowPlaying();
} }
@Override @Override
@@ -1223,6 +1237,18 @@ public class MainActivity extends AppCompatActivity {
bindDriveMode(); bindDriveMode();
bindOverviewStyle(); bindOverviewStyle();
bindAccentColor(); bindAccentColor();
SwitchMaterial showPlaying = settingsPane.findViewById(R.id.now_playing_switch);
showPlaying.setChecked(prefs.getBoolean(PREF_NOW_PLAYING, true));
showPlaying.setOnCheckedChangeListener((btn, checked) -> {
prefs.edit().putBoolean(PREF_NOW_PLAYING, checked).apply();
updateNowPlaying();
});
SwitchMaterial musicLight = settingsPane.findViewById(R.id.music_light_switch);
musicLight.setChecked(prefs.getBoolean(PREF_MUSIC_LIGHT, false));
musicLight.setOnCheckedChangeListener((btn, checked) -> {
prefs.edit().putBoolean(PREF_MUSIC_LIGHT, checked).apply();
updateMusicTap();
});
fullScreenSwitch = settingsPane.findViewById(R.id.full_screen_switch); fullScreenSwitch = settingsPane.findViewById(R.id.full_screen_switch);
fullScreenSwitch.setChecked(UploadSettings.fullScreen(prefs)); fullScreenSwitch.setChecked(UploadSettings.fullScreen(prefs));
fullScreenSwitch.setOnCheckedChangeListener((btn, checked) -> { fullScreenSwitch.setOnCheckedChangeListener((btn, checked) -> {
@@ -1759,12 +1785,76 @@ public class MainActivity extends AppCompatActivity {
if (settingsPane != null) bindAccentColor(); if (settingsPane != null) bindAccentColor();
updateMapLocation(); updateMapLocation();
updateMusicTap(); updateMusicTap();
updateNowPlaying();
} }
/** The pumpkin listens only while it can be seen: the app in front, on the Overview, in Halloween. */ /** The styles that show what plays. */
private static boolean showsNowPlaying(OverviewStyle style) {
return style == OverviewStyle.TILES || style == OverviewStyle.HALLOWEEN
|| style == OverviewStyle.MUERTOS || style == OverviewStyle.QUEST || style == OverviewStyle.EMPIRE
|| style == OverviewStyle.TERMINAL || style == OverviewStyle.SCIFI
|| style == OverviewStyle.CHRISTMAS || style == OverviewStyle.CATERPILLAR;
}
/** The media sessions are watched only while what plays can be seen, and the switch is on. */
private void updateNowPlaying() {
ViewPager2 pager = findViewById(R.id.content);
nowPlaying.setRunning(inFront && showsNowPlaying(overviewStyle())
&& prefs.getBoolean(PREF_NOW_PLAYING, true)
&& pager != null && pager.getCurrentItem() == 0);
if (!nowPlaying.isRunning()) showNowPlaying(null);
}
/** The Tiles tile: source, title, artist, a cover when there is one, and how far the song is. */
private void showNowPlaying(NowPlaying.Track t) {
if (vehiclePane == null) return;
View tile = vehiclePane.findViewById(R.id.now_playing_tile);
if (tile == null) return; // the narrow layout has no room for it
if (t == null) {
tile.setVisibility(View.INVISIBLE);
return;
}
tile.setVisibility(View.VISIBLE);
String source = getString(t.source == NowPlaying.Source.BLUETOOTH ? R.string.now_playing_bluetooth
: t.source == NowPlaying.Source.CARPLAY ? R.string.now_playing_carplay
: t.source == NowPlaying.Source.RADIO ? R.string.now_playing_radio : R.string.now_playing_other);
setIfChanged(vehiclePane.findViewById(R.id.now_playing_source),
t.playing ? source : getString(R.string.now_playing_paused, source));
setIfChanged(vehiclePane.findViewById(R.id.now_playing_title), t.title);
TextView artist = vehiclePane.findViewById(R.id.now_playing_artist);
setIfChanged(artist, t.subtitle == null ? "" : t.subtitle);
artist.setVisibility(t.subtitle == null ? View.GONE : View.VISIBLE);
android.widget.ImageView cover = vehiclePane.findViewById(R.id.now_playing_cover);
android.graphics.Bitmap art = nowPlaying.cover(t);
if (cover.getTag() != art) {
cover.setTag(art);
cover.setImageBitmap(art);
cover.setVisibility(art == null ? View.GONE : View.VISIBLE);
}
android.widget.ProgressBar bar = vehiclePane.findViewById(R.id.now_playing_progress);
float progress = t.progressAt(android.os.SystemClock.elapsedRealtime());
bar.setVisibility(progress < 0f ? View.INVISIBLE : View.VISIBLE);
if (progress >= 0f) bar.setProgress(Math.round(progress * bar.getMax()));
}
private static void setIfChanged(TextView view, CharSequence text) {
if (!android.text.TextUtils.equals(view.getText(), text)) view.setText(text);
}
/** The styles with a light that can follow the music: Halloween's pumpkin, Christmas's tree and the Caterpillar's sun. */
private static boolean hasMusicLight(OverviewStyle style) {
return style == OverviewStyle.HALLOWEEN || style == OverviewStyle.CHRISTMAS
|| style == OverviewStyle.CATERPILLAR;
}
/**
* The light listens only while it can be seen (the app in front, on the Overview, in
* Halloween, Christmas or Caterpillar) and only when "Light follows the music" is on.
*/
private void updateMusicTap() { private void updateMusicTap() {
ViewPager2 pager = findViewById(R.id.content); ViewPager2 pager = findViewById(R.id.content);
musicTap.setRunning(inFront && overviewStyle() == OverviewStyle.HALLOWEEN musicTap.setRunning(inFront && hasMusicLight(overviewStyle())
&& prefs.getBoolean(PREF_MUSIC_LIGHT, false)
&& pager != null && pager.getCurrentItem() == 0); && pager != null && pager.getCurrentItem() == 0);
} }
@@ -1828,6 +1918,12 @@ public class MainActivity extends AppCompatActivity {
TextView note = settingsPane.findViewById(R.id.accent_note); TextView note = settingsPane.findViewById(R.id.accent_note);
note.setVisibility(style.usesAccent ? View.GONE : View.VISIBLE); note.setVisibility(style.usesAccent ? View.GONE : View.VISIBLE);
note.setText(getString(R.string.accent_not_used, styleLabels()[style.ordinal()])); note.setText(getString(R.string.accent_not_used, styleLabels()[style.ordinal()]));
int playing = showsNowPlaying(style) ? View.VISIBLE : View.GONE;
settingsPane.findViewById(R.id.now_playing_switch).setVisibility(playing);
settingsPane.findViewById(R.id.now_playing_hint).setVisibility(playing);
int music = hasMusicLight(style) ? View.VISIBLE : View.GONE;
settingsPane.findViewById(R.id.music_light_switch).setVisibility(music);
settingsPane.findViewById(R.id.music_light_hint).setVisibility(music);
} }
/** The drop-down's labels, by {@link OverviewStyle} ordinal. */ /** The drop-down's labels, by {@link OverviewStyle} ordinal. */
@@ -1843,7 +1939,8 @@ public class MainActivity extends AppCompatActivity {
getString(R.string.overview_style_grid_map), getString(R.string.overview_style_grid_map),
getString(R.string.overview_style_time_circuits), getString(R.string.overview_style_quest), getString(R.string.overview_style_time_circuits), getString(R.string.overview_style_quest),
getString(R.string.overview_style_visor), getString(R.string.overview_style_empire), getString(R.string.overview_style_visor), getString(R.string.overview_style_empire),
getString(R.string.overview_style_muertos), getString(R.string.overview_style_halloween) }; getString(R.string.overview_style_muertos), getString(R.string.overview_style_halloween),
getString(R.string.overview_style_christmas), getString(R.string.overview_style_caterpillar) };
} }
/** The style drop-down; every style is fed on every reading, only the chosen one is shown. */ /** The style drop-down; every style is fed on every reading, only the chosen one is shown. */
@@ -1910,6 +2007,10 @@ public class MainActivity extends AppCompatActivity {
v.tyreRl = unit.format(s.getTirePressures().getRearLeftKpa()); v.tyreRl = unit.format(s.getTirePressures().getRearLeftKpa());
v.tyreRr = unit.format(s.getTirePressures().getRearRightKpa()); v.tyreRr = unit.format(s.getTirePressures().getRearRightKpa());
v.powerTrail = cockpitTrace.snapshot(); v.powerTrail = cockpitTrace.snapshot();
NowPlaying.Track track = nowPlaying.isRunning() ? nowPlaying.current() : null;
v.songTitle = track == null ? null : track.title;
v.songArtist = track == null ? null : track.subtitle;
showNowPlaying(track);
retroView.setValues(v); retroView.setValues(v);
flowView.setValues(v); flowView.setValues(v);
sciFiView.setValues(v); sciFiView.setValues(v);
@@ -44,6 +44,7 @@ final class MuertosView extends ClusterCanvasView {
private final Paint image = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); private final Paint image = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
private final Path path = new Path(); private final Path path = new Path();
private final Path flag = new Path(); private final Path flag = new Path();
private final SongBanner banner = new SongBanner();
private final RectF r = new RectF(); private final RectF r = new RectF();
private final Typeface serif = Typeface.create("serif", Typeface.BOLD); private final Typeface serif = Typeface.create("serif", Typeface.BOLD);
private final Typeface face = Typeface.create("sans-serif-condensed", Typeface.BOLD); private final Typeface face = Typeface.create("sans-serif-condensed", Typeface.BOLD);
@@ -87,6 +88,7 @@ final class MuertosView extends ClusterCanvasView {
c.drawBitmap(scene, 0, 0, image); c.drawBitmap(scene, 0, 0, image);
float cx = w / 2f, cy = 345f * u; float cx = w / 2f, cy = 345f * u;
drawFlags(c, w, u); drawFlags(c, w, u);
boolean song = drawSong(c, w, u);
drawRing(c, cx, cy, u); drawRing(c, cx, cy, u);
drawSpeed(c, cx, cy, u); drawSpeed(c, cx, cy, u);
drawBattery(c, u); drawBattery(c, u);
@@ -95,7 +97,7 @@ final class MuertosView extends ClusterCanvasView {
drawClock(c, w, u); drawClock(c, w, u);
drawGears(c, w, u); drawGears(c, w, u);
drawRows(c, w, h, u); drawRows(c, w, h, u);
keepAnimating(moving, 33); keepAnimating(moving || song, 33);
} }
private void label(Canvas c, String s, float x, float y, float size, int colour, Typeface tf, Paint.Align a) { private void label(Canvas c, String s, float x, float y, float size, int colour, Typeface tf, Paint.Align a) {
@@ -330,6 +332,165 @@ final class MuertosView extends ClusterCanvasView {
} }
} }
// ---------- What plays: a monarch or an alebrije tows it on a strip of papel picado ----------
/**
* A monarch butterfly (the souls' messengers) and an alebrije (Oaxaca's painted spirit creature)
* take turns towing a waving strip of cut paper with the song across the sky between the flags
* and the ring, behind the ring and the clock, again and again while something plays. The paper's
* colour is one of the flags', fixed by the song. Returns whether it is drawn, so the view keeps
* animating for it.
*/
private boolean drawSong(Canvas c, int w, float u) {
if (v.songTitle == null) return false;
text.setTypeface(face);
text.setTextSize(19f * u);
String s = SongBanner.line(text, v.songTitle, v.songArtist, Math.min(560f * u, w * 0.45f));
float t = SystemClock.uptimeMillis() / 1000f;
float bw = text.measureText(s) + 40f * u, bh = 28f * u, tow = 64f * u;
float bx = SongBanner.left(t, w, bw, tow, u);
float yc = 106f * u + (float) Math.sin(t * 1.3f) * 2f * u;
int paper = PAPER[Math.floorMod((v.songTitle + "\n" + v.songArtist).hashCode(), PAPER.length)];
fill.setStyle(Paint.Style.FILL);
banner.draw(c, fill, line, text, s, bx, yc, bw, bh, t, u, 14f * u, paper, 0xCC2A0E36,
paper == PAPER[4] ? BONE : INK);
boolean butterfly = SongBanner.pass(t, w, bw, tow, u) % 2 == 0;
float right = bx + bw, cx = right + tow, cy = yc - 6f * u, size = (butterfly ? 40f : 36f) * u;
// The tow lines run to the tail.
float ax = cx - (butterfly ? 0.4f : 0.6f) * size, ay = cy - (butterfly ? 0f : 0.35f * size);
line.setColor(0x99FFFFFF);
line.setStrokeWidth(1.5f * u);
c.drawLine(right, yc - bh / 2f + 3f * u, ax, ay, line);
c.drawLine(right, yc + bh / 2f - 3f * u, ax, ay, line);
float flap = (float) Math.sin(t * (butterfly ? 9f : 7f));
if (butterfly) monarch(c, cx, cy, size, flap, u);
else alebrije(c, cx, cy, size, flap, u);
return true;
}
/** A monarch seen from above, flying right: orange wings veined and edged in black, white dots. */
private void monarch(Canvas c, float x, float y, float s, float flap, float u) {
float k = 0.3f + 0.7f * Math.abs(flap);
c.save();
c.translate(x, y);
for (int side = 0; side < 2; side++) {
c.save();
if (side == 1) c.scale(1f, -1f);
path.reset();
path.moveTo(0.3f * s, 0);
path.quadTo(0.3f * s, -0.75f * s * k, -0.02f * s, -0.95f * s * k);
path.quadTo(-0.45f * s, -0.7f * s * k, -0.1f * s, 0);
path.close();
path.moveTo(-0.05f * s, 0);
path.quadTo(-0.4f * s, -0.55f * s * k, -0.7f * s, -0.4f * s * k);
path.quadTo(-0.7f * s, -0.1f * s * k, -0.3f * s, 0);
path.close();
fill.setColor(0xFFFF8A1F);
c.drawPath(path, fill);
line.setColor(0xFF1A0A10);
line.setStrokeWidth(2.2f * u);
line.setStrokeJoin(Paint.Join.ROUND);
c.drawPath(path, line);
line.setStrokeWidth(1.2f * u);
c.drawLine(0.1f * s, 0, -0.02f * s, -0.88f * s * k, line);
c.drawLine(0.05f * s, 0, -0.3f * s, -0.62f * s * k, line);
c.drawLine(-0.1f * s, 0, -0.62f * s, -0.36f * s * k, line);
fill.setColor(0xFFFFFFFF);
for (float[] d : new float[][] { { 0.14f, -0.74f }, { -0.1f, -0.88f }, { -0.3f, -0.72f }, { -0.62f, -0.36f } }) {
c.drawCircle(d[0] * s, d[1] * s * k, 1.6f * u, fill);
}
c.restore();
}
fill.setColor(0xFF1A0A10);
r.set(-0.4f * s, -0.07f * s, 0.35f * s, 0.07f * s);
c.drawOval(r, fill);
c.drawCircle(0.38f * s, 0, 0.08f * s, fill);
line.setColor(0xFF1A0A10);
line.setStrokeWidth(1.5f * u);
c.drawLine(0.42f * s, -0.04f * s, 0.62f * s, -0.2f * s, line);
c.drawLine(0.42f * s, 0.04f * s, 0.62f * s, 0.2f * s, line);
c.restore();
}
/** An alebrije flying right: a painted horned creature with feathered wings and a curled tail. */
private void alebrije(Canvas c, float x, float y, float s, float flap, float u) {
int[] feathers = { TURQUOISE, GOLD, PINK, MARIGOLD, PAPER[4] };
c.save();
c.translate(x, y);
// The wing, behind the body: feathers fanned from the shoulder, lifted and dropped by the flap.
for (int i = 0; i < feathers.length; i++) {
c.save();
c.translate(-0.05f * s, -0.2f * s);
c.rotate(-125f + flap * 30f + i * 15f);
r.set(0, -0.07f * s, 0.8f * s, 0.07f * s);
fill.setColor(feathers[i]);
c.drawOval(r, fill);
line.setColor(INK);
line.setStrokeWidth(1.5f * u);
c.drawOval(r, line);
c.restore();
}
// The curled tail.
path.reset();
path.moveTo(-0.4f * s, 0.05f * s);
path.cubicTo(-0.8f * s, 0.1f * s, -0.85f * s, -0.3f * s, -0.6f * s, -0.35f * s);
line.setColor(PINK);
line.setStrokeWidth(0.1f * s);
c.drawPath(path, line);
fill.setColor(GOLD);
c.drawCircle(-0.6f * s, -0.35f * s, 0.07f * s, fill);
// Legs.
line.setColor(INK);
line.setStrokeWidth(3f * u);
c.drawLine(-0.25f * s, 0.15f * s, -0.3f * s, 0.42f * s, line);
c.drawLine(0.15f * s, 0.15f * s, 0.2f * s, 0.42f * s, line);
fill.setColor(GOLD);
c.drawCircle(-0.3f * s, 0.43f * s, 0.05f * s, fill);
c.drawCircle(0.2f * s, 0.43f * s, 0.05f * s, fill);
// The body, painted with stripes and dots.
r.set(-0.45f * s, -0.2f * s, 0.35f * s, 0.2f * s);
fill.setColor(PINK);
c.drawOval(r, fill);
line.setColor(INK);
line.setStrokeWidth(2f * u);
c.drawOval(r, line);
line.setColor(TURQUOISE);
line.setStrokeWidth(0.05f * s);
path.reset();
path.moveTo(-0.35f * s, 0f);
for (int i = 1; i <= 6; i++) path.lineTo((-0.35f + 0.1f * i) * s, (i % 2 == 0 ? 0f : -0.07f) * s);
c.drawPath(path, line);
fill.setColor(GOLD);
for (float[] d : new float[][] { { -0.3f, 0.1f }, { -0.1f, 0.12f }, { 0.1f, 0.1f }, { 0.25f, 0.05f } }) {
c.drawCircle(d[0] * s, d[1] * s, 0.035f * s, fill);
}
// Horns, the head, snout, eye.
line.setColor(GOLD);
line.setStrokeWidth(3.5f * u);
path.reset();
path.moveTo(0.35f * s, -0.38f * s);
path.quadTo(0.2f * s, -0.55f * s, 0.3f * s, -0.78f * s);
path.moveTo(0.5f * s, -0.38f * s);
path.quadTo(0.65f * s, -0.52f * s, 0.55f * s, -0.78f * s);
c.drawPath(path, line);
fill.setColor(MARIGOLD);
c.drawCircle(0.42f * s, -0.22f * s, 0.2f * s, fill);
line.setColor(INK);
line.setStrokeWidth(2f * u);
c.drawCircle(0.42f * s, -0.22f * s, 0.2f * s, line);
r.set(0.5f * s, -0.22f * s, 0.85f * s, -0.06f * s);
fill.setColor(GOLD);
c.drawOval(r, fill);
c.drawOval(r, line);
fill.setColor(PINK);
c.drawCircle(0.8f * s, -0.15f * s, 0.035f * s, fill);
fill.setColor(BONE);
c.drawCircle(0.45f * s, -0.28f * s, 0.07f * s, fill);
fill.setColor(INK);
c.drawCircle(0.47f * s, -0.28f * s, 0.035f * s, fill);
c.restore();
}
private void drawBattery(Canvas c, float u) { private void drawBattery(Canvas c, float u) {
boolean low = v.socPercent != null && v.socPercent < 20f; boolean low = v.socPercent != null && v.socPercent < 20f;
float x = 36f * u; float x = 36f * u;
@@ -2,32 +2,45 @@ package com.evsuite.abrp;
/** /**
* How strongly the Halloween pumpkin's light answers the music at this moment, from 0 to 1, out of * How strongly the Halloween pumpkin's light answers the music at this moment, from 0 to 1, out of
* the bass the audio analyser reports. What counts is the beat, not the loudness: each reading is * the kick drum's band the audio analyser reports. What counts is the hit, not the loudness: only
* placed between the bass's recent average and its recent peak, so quiet and loud songs both * a jump of the bass since the last reading lights it, measured against the biggest jumps of the
* pulse and a steady hum settles at nothing. It rises fast and falls slowly, as a flame does. No * last seconds, so quiet and loud songs both flash, and a held bass note or a steady hum does not.
* reading or silence falls back to 0, so without music the light stays as it is. Android-free and * Jumps that are small against the bass's own level (a swelling note, noise) are ignored. It
* unit-tested. * flares at once and dies down within a beat, as a flame does. No reading or silence falls back to
* 0, so without music the light stays as it is. Android-free and unit-tested.
*/ */
final class MusicPulse { final class MusicPulse {
/** Below this the bass counts as silence. */ /** Below this the bass counts as silence. */
static final float SILENT = 0.005f; static final float SILENT = 0.005f;
private static final float RISE_S = 0.03f, FALL_S = 0.25f, AVERAGE_S = 2f, PEAK_S = 4f; /** The kick drum's band, in Hz, that {@link MusicTap} reads. */
static final float FROM_HZ = 40f, TO_HZ = 120f;
private static final float FALL_S = 0.2f, AVERAGE_S = 2f, PEAK_S = 4f;
/** A jump below this share of the recent biggest one lights nothing. */
private static final float THRESHOLD = 0.2f;
/** A jump has to be at least this share of the bass's average level to count at all. */
private static final float LEVEL_SHARE = 0.5f;
private float average, peak, pulse; private float last, average, peakJump, pulse;
/** One reading, {@code seconds} after the last; null when it failed. Returns the new pulse. */ /** One reading, {@code seconds} after the last; null when it failed. Returns the new pulse. */
float update(Float bass, float seconds) { float update(Float bass, float seconds) {
float target = 0f; float target = 0f;
if (bass == null || bass.isNaN() || bass < SILENT) { if (bass == null || bass.isNaN() || bass < SILENT) {
last = 0f;
average = 0f; average = 0f;
peak = 0f; peakJump = 0f;
} else { } else {
float jump = Math.max(0f, bass - last);
last = bass;
average = average == 0f ? bass : average + (bass - average) * share(seconds, AVERAGE_S); average = average == 0f ? bass : average + (bass - average) * share(seconds, AVERAGE_S);
peak = Math.max(bass, peak - peak * share(seconds, PEAK_S)); peakJump = Math.max(jump, peakJump - peakJump * share(seconds, PEAK_S));
if (peak > average) target = Math.max(0f, Math.min(1f, (bass - average) / (peak - average))); float reference = Math.max(peakJump, average * LEVEL_SHARE);
if (reference > 0f) {
target = Math.max(0f, Math.min(1f, (jump / reference - THRESHOLD) / (1f - THRESHOLD)));
} }
pulse += (target - pulse) * share(seconds, target > pulse ? RISE_S : FALL_S); }
pulse = target > pulse ? target : pulse + (target - pulse) * share(seconds, FALL_S);
if (pulse < 0.005f) pulse = 0f; if (pulse < 0.005f) pulse = 0f;
return pulse; return pulse;
} }
@@ -7,9 +7,9 @@ import android.media.audiofx.Visualizer;
/** /**
* Listens to what the head unit plays for the Halloween pumpkin's light: Android's audio analyser * Listens to what the head unit plays for the Halloween pumpkin's light: Android's audio analyser
* on the output mix, its bass read 25 times a second on a thread of its own, made into a * on the output mix, its kick-drum band read 25 times a second on a thread of its own, made into a
* {@link MusicPulse}. Runs only while MainActivity says so (the style on screen, the app in * {@link MusicPulse}. Runs only while MainActivity says so (the style on screen, the app in
* front). Levels only: no sound is kept and no microphone used. Where the analyser hears nothing * front, and "Pumpkin light follows the music" on). Levels only: no sound is kept and no microphone used. Where the analyser hears nothing
* (the radio) or is not available, the pulse stays 0 and the pumpkin burns as usual. * (the radio) or is not available, the pulse stays 0 and the pumpkin burns as usual.
*/ */
final class MusicTap { final class MusicTap {
@@ -64,7 +64,7 @@ final class MusicTap {
boolean read = analyser.getFft(fft) == Visualizer.SUCCESS; boolean read = analyser.getFft(fft) == Visualizer.SUCCESS;
failures = read ? 0 : failures + 1; failures = read ? 0 : failures + 1;
long now = System.nanoTime(); long now = System.nanoTime();
float value = music.update(read ? SoundLevels.band(fft, rateHz, 20f, 250f) : null, (now - last) / 1e9f); float value = music.update(read ? SoundLevels.band(fft, rateHz, MusicPulse.FROM_HZ, MusicPulse.TO_HZ) : null, (now - last) / 1e9f);
last = now; last = now;
if (worker == me) pulse = value; if (worker == me) pulse = value;
} }
@@ -0,0 +1,136 @@
package com.evsuite.abrp;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
/**
* What the Overview shows as playing, out of the media sessions the head unit publishes
* ({@link NowPlayingWatcher}): the session that plays, the one updated last when several do, and
* when none plays the one paused last. Sessions without any text are passed over (Bluetooth leaves
* an empty one behind when the phone stops). The text is cleaned: CarPlay's YouTube titles lose
* their trailing video ID, and the radio, whose title is the station and whose artist field is the
* station's own text, shows that text with the station below. Shown on screen only; nothing here
* is logged or sent. Android-free and unit-tested.
*/
final class NowPlaying {
enum Source { BLUETOOTH, CARPLAY, RADIO, OTHER }
/** android.media.session.PlaybackState's codes, mirrored to stay Android-free. */
static final int STATE_PAUSED = 2, STATE_PLAYING = 3, STATE_FAST_FORWARDING = 4, STATE_REWINDING = 5,
STATE_BUFFERING = 6, STATE_SKIPPING_TO_PREVIOUS = 9, STATE_SKIPPING_TO_NEXT = 10,
STATE_SKIPPING_TO_QUEUE_ITEM = 11;
private static final int MAX_TEXT = 200;
/** A YouTube video ID in brackets at the end of a title, as CarPlay passes them on. */
private static final Pattern VIDEO_ID = Pattern.compile("\\s*\\[[A-Za-z0-9_-]{11}\\]$");
private static final Pattern SPACES = Pattern.compile("\\s+");
private NowPlaying() {}
/** One media session as last seen. Times in the platform's elapsed-realtime milliseconds. */
static final class Session {
String packageName;
int state;
String title, artist;
/** -1 when the session says no position. */
long positionMs = -1;
long positionUpdatedAt;
float speed = 1f;
/** 0 when unknown (the radio). */
long durationMs;
/** A file or content URI for the cover, when the session names one (Bluetooth does). */
String artUri;
}
/** What to show. {@code subtitle} may be null; {@code session} is where it came from. */
static final class Track {
final Source source;
final String title, subtitle;
final boolean playing;
final Session session;
Track(Source source, String title, String subtitle, boolean playing, Session session) {
this.source = source;
this.title = title;
this.subtitle = subtitle;
this.playing = playing;
this.session = session;
}
/** Where the song is at {@code now}, or -1 when the session gives no position. */
long positionAt(long now) {
if (session.positionMs < 0) return -1;
long at = session.positionMs;
if (playing && session.positionUpdatedAt > 0 && now > session.positionUpdatedAt) {
at += (long) ((now - session.positionUpdatedAt) * session.speed);
}
if (session.durationMs > 0) at = Math.min(at, session.durationMs);
return Math.max(0, at);
}
/** How far through the song, from 0 to 1, or -1 without a length or position (the radio). */
float progressAt(long now) {
long at = positionAt(now);
if (at < 0 || session.durationMs <= 0) return -1f;
return Math.min(1f, at / (float) session.durationMs);
}
}
static Track pick(List<Session> sessions) {
Session best = null;
boolean bestPlaying = false;
if (sessions != null) {
for (Session s : sessions) {
if (s == null || (!playing(s.state) && s.state != STATE_PAUSED)) continue;
if (clean(s.title) == null && clean(s.artist) == null) continue;
boolean p = playing(s.state);
if (best == null || (p && !bestPlaying)
|| (p == bestPlaying && s.positionUpdatedAt > best.positionUpdatedAt)) {
best = s;
bestPlaying = p;
}
}
}
if (best == null) return null;
Source source = source(best.packageName);
String title = clean(best.title), artist = clean(best.artist);
if (source == Source.RADIO) {
// The station is the title; its own text (song, programme) comes as the artist.
if (artist != null) return new Track(source, artist, title, bestPlaying, best);
return new Track(source, title, null, bestPlaying, best);
}
if (title == null) return new Track(source, artist, null, bestPlaying, best);
return new Track(source, title, artist, bestPlaying, best);
}
static boolean playing(int state) {
switch (state) {
case STATE_PLAYING: case STATE_FAST_FORWARDING: case STATE_REWINDING: case STATE_BUFFERING:
case STATE_SKIPPING_TO_PREVIOUS: case STATE_SKIPPING_TO_NEXT: case STATE_SKIPPING_TO_QUEUE_ITEM:
return true;
default:
return false;
}
}
/** Which source a session's app is: the ones seen on the owner's car, the rest as "other". */
static Source source(String packageName) {
if (packageName == null) return Source.OTHER;
String p = packageName.toLowerCase(Locale.ROOT);
if (p.equals("com.android.bluetooth")) return Source.BLUETOOTH;
if (p.contains("allgo") || p.contains("carplay")) return Source.CARPLAY;
if (p.contains("radio")) return Source.RADIO;
return Source.OTHER;
}
/** Trimmed, one line, without a trailing video ID, at most 200 characters; null when empty. */
static String clean(String text) {
if (text == null) return null;
String s = SPACES.matcher(text).replaceAll(" ").trim();
s = VIDEO_ID.matcher(s).replaceAll("").trim();
if (s.isEmpty()) return null;
return s.length() > MAX_TEXT ? s.substring(0, MAX_TEXT - 1) + "…" : s;
}
}
@@ -0,0 +1,215 @@
package com.evsuite.abrp;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaMetadata;
import android.media.session.MediaController;
import android.media.session.MediaSessionManager;
import android.media.session.PlaybackState;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Watches the media sessions the head unit publishes (Bluetooth's, CarPlay's, the radio's) for the
* Overview's "now playing", the way the Logs tab's music-sources check reads them: through
* {@code MediaSessionManager}, which needs MEDIA_CONTENT_CONTROL (the car build has it as the
* system user). It only listens: no media browser service is connected to (that stopped the music
* in 2.42.0) and no command is sent. Each session's state and song are kept as the session reports
* changes, so reading {@link #current()} costs no call into another app. Runs only while
* MainActivity says so, on the main thread. Without the permission, or on any failure, there is
* simply nothing playing. Nothing it sees is logged.
*/
final class NowPlayingWatcher {
private static final int COVER_PX = 160;
private final Context app;
private final Handler main = new Handler(Looper.getMainLooper());
private final List<Watched> watched = new ArrayList<>();
private final ExecutorService coverLoader = Executors.newSingleThreadExecutor(r -> {
Thread t = new Thread(r, "now-playing-cover");
t.setDaemon(true);
return t;
});
private MediaSessionManager sessions;
private boolean running;
private Bitmap sessionCover;
/** The file cover asked for last and what came of it, from the loader thread. */
private volatile String coverUri;
private volatile Bitmap fileCover;
private final MediaSessionManager.OnActiveSessionsChangedListener changed = this::watch;
NowPlayingWatcher(Context context) {
app = context.getApplicationContext();
}
void setRunning(boolean run) {
if (run == running) return;
running = run;
if (!run) {
try {
if (sessions != null) sessions.removeOnActiveSessionsChangedListener(changed);
} catch (RuntimeException ignored) {
// Gone with the listener either way.
}
watch(null);
return;
}
try {
sessions = (MediaSessionManager) app.getSystemService(Context.MEDIA_SESSION_SERVICE);
if (sessions == null) return;
sessions.addOnActiveSessionsChangedListener(changed, null, main);
watch(sessions.getActiveSessions(null));
} catch (RuntimeException e) {
// No permission (the stable build) or no session service: nothing plays.
android.util.Log.w("NowPlaying", "Media sessions not readable: " + e.getClass().getSimpleName());
}
}
boolean isRunning() {
return running;
}
/** What plays now, or null. */
NowPlaying.Track current() {
List<NowPlaying.Session> seen = new ArrayList<>(watched.size());
for (Watched w : watched) seen.add(w.seen);
return NowPlaying.pick(seen);
}
/** The current track's cover, or null: the picture the session carries, else its file, once loaded. */
Bitmap cover(NowPlaying.Track track) {
if (track == null) return null;
for (Watched w : watched) {
if (w.seen == track.session && w.cover != null) return w.cover;
}
String uri = track.session.artUri;
if (uri == null) return null;
if (!uri.equals(coverUri)) {
coverUri = uri;
fileCover = null;
coverLoader.execute(() -> {
Bitmap b = load(uri);
if (uri.equals(coverUri)) fileCover = b;
});
}
return fileCover;
}
private void watch(List<MediaController> controllers) {
for (Watched w : watched) w.release();
watched.clear();
if (controllers == null || !running) return;
for (MediaController c : controllers) {
try {
watched.add(new Watched(c));
} catch (RuntimeException ignored) {
// A session that went away while being read.
}
}
}
/** One session: its last state and song, kept up to date by its callback. */
private final class Watched extends MediaController.Callback {
final MediaController controller;
final NowPlaying.Session seen = new NowPlaying.Session();
Bitmap cover;
Watched(MediaController c) {
controller = c;
seen.packageName = c.getPackageName();
onPlaybackStateChanged(c.getPlaybackState());
onMetadataChanged(c.getMetadata());
c.registerCallback(this, main);
}
void release() {
try {
controller.unregisterCallback(this);
} catch (RuntimeException ignored) {
// Already gone.
}
}
@Override
public void onPlaybackStateChanged(PlaybackState state) {
seen.state = state == null ? 0 : state.getState();
seen.positionMs = state == null ? -1 : state.getPosition();
seen.positionUpdatedAt = state == null ? 0 : state.getLastPositionUpdateTime();
seen.speed = state == null ? 1f : state.getPlaybackSpeed();
}
@Override
public void onMetadataChanged(MediaMetadata m) {
seen.title = text(m, MediaMetadata.METADATA_KEY_TITLE);
if (seen.title == null) seen.title = text(m, MediaMetadata.METADATA_KEY_DISPLAY_TITLE);
seen.artist = text(m, MediaMetadata.METADATA_KEY_ARTIST);
if (seen.artist == null) seen.artist = text(m, MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE);
seen.durationMs = m == null ? 0 : Math.max(0, m.getLong(MediaMetadata.METADATA_KEY_DURATION));
cover = picture(m);
seen.artUri = text(m, MediaMetadata.METADATA_KEY_ALBUM_ART_URI);
if (seen.artUri == null) seen.artUri = text(m, MediaMetadata.METADATA_KEY_ART_URI);
}
@Override
public void onSessionDestroyed() {
seen.state = 0;
}
}
private static String text(MediaMetadata m, String key) {
if (m == null) return null;
try {
CharSequence s = m.getText(key);
return s == null ? null : s.toString();
} catch (RuntimeException e) {
return null;
}
}
private static Bitmap picture(MediaMetadata m) {
if (m == null) return null;
for (String key : new String[] { MediaMetadata.METADATA_KEY_ALBUM_ART, MediaMetadata.METADATA_KEY_ART,
MediaMetadata.METADATA_KEY_DISPLAY_ICON }) {
try {
Bitmap b = m.getBitmap(key);
if (b != null && b.getWidth() > 1 && b.getHeight() > 1) return b;
} catch (RuntimeException ignored) {
// Try the next.
}
}
return null;
}
/** A cover file, made small; null when it cannot be read. Off the main thread. */
private Bitmap load(String uri) {
try {
Uri u = uri.startsWith("/") ? Uri.fromFile(new java.io.File(uri)) : Uri.parse(uri);
String scheme = u.getScheme();
if (!"file".equals(scheme) && !"content".equals(scheme)) return null;
BitmapFactory.Options size = new BitmapFactory.Options();
size.inJustDecodeBounds = true;
try (InputStream in = app.getContentResolver().openInputStream(u)) {
BitmapFactory.decodeStream(in, null, size);
}
if (size.outWidth <= 0 || size.outHeight <= 0) return null;
BitmapFactory.Options small = new BitmapFactory.Options();
small.inSampleSize = 1;
while (Math.max(size.outWidth, size.outHeight) / (small.inSampleSize * 2) >= COVER_PX) small.inSampleSize *= 2;
try (InputStream in = app.getContentResolver().openInputStream(u)) {
return BitmapFactory.decodeStream(in, null, small);
}
} catch (Exception | OutOfMemoryError e) {
return null;
}
}
}
@@ -33,7 +33,9 @@ enum OverviewStyle {
VISOR(true, true), VISOR(true, true),
EMPIRE(false, false), EMPIRE(false, false),
MUERTOS(false, false), MUERTOS(false, false),
HALLOWEEN(false, false); HALLOWEEN(false, false),
CHRISTMAS(false, false),
CATERPILLAR(false, false);
static final String PREF_KEY = "overview_style"; static final String PREF_KEY = "overview_style";
@@ -37,6 +37,7 @@ final class QuestView extends ClusterCanvasView {
private final Paint text = new Paint(Paint.ANTI_ALIAS_FLAG); private final Paint text = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint skyPaint = new Paint(); private final Paint skyPaint = new Paint();
private final Path path = new Path(); private final Path path = new Path();
private final SongBanner banner = new SongBanner();
private final RectF r = new RectF(); private final RectF r = new RectF();
private final Typeface serif = Typeface.create(Typeface.SERIF, Typeface.BOLD); private final Typeface serif = Typeface.create(Typeface.SERIF, Typeface.BOLD);
private final Typeface sans = Typeface.create("sans-serif-condensed", Typeface.BOLD); private final Typeface sans = Typeface.create("sans-serif-condensed", Typeface.BOLD);
@@ -54,6 +55,7 @@ final class QuestView extends ClusterCanvasView {
if (w <= 0 || h <= 0) return; if (w <= 0 || h <= 0) return;
float u = Math.min(h / 640f, w / 1100f); float u = Math.min(h / 640f, w / 1100f);
drawLandscape(c, w, h); drawLandscape(c, w, h);
boolean song = drawSong(c, w, u);
drawPlayer(c, u); drawPlayer(c, u);
drawMinimap(c, w, u); drawMinimap(c, w, u);
drawSpeed(c, w, u); drawSpeed(c, w, u);
@@ -62,6 +64,35 @@ final class QuestView extends ClusterCanvasView {
drawChat(c, u); drawChat(c, u);
drawActionBar(c, w, h, u); drawActionBar(c, w, h, u);
drawXp(c, w, h, u); drawXp(c, w, h, u);
keepAnimating(song, 33);
}
// ---------- What plays: a dragon tows it on a scroll ----------
/**
* A dragon tows a waving scroll with the song across the top of the sky, behind the frames, again
* and again while something plays. Returns whether it is drawn, so the view keeps animating.
*/
private boolean drawSong(Canvas c, float w, float u) {
if (v.songTitle == null) return false;
text.setTypeface(serif);
text.setTextSize(19f * u);
text.setStyle(Paint.Style.FILL);
String s = SongBanner.line(text, v.songTitle, v.songArtist, Math.min(560f * u, w * 0.45f));
float t = SystemClock.uptimeMillis() / 1000f;
float bw = text.measureText(s) + 40f * u, bh = 28f * u, size = 58f * u, tow = size * 1.3f;
int wi = Math.round(w);
float bx = SongBanner.left(t, wi, bw, tow, u);
float yc = 72f * u + (float) Math.sin(t * 1.3f) * 3f * u;
banner.draw(c, fill, line, text, s, bx, yc, bw, bh, t, u, 0f, 0xFFE8D5A8, GOLD_DARK, 0xFF2A1A08);
float right = bx + bw, cx = right + tow, cy = yc - 8f * u;
line.setColor(0xCCFFFFFF);
line.setStrokeWidth(1.5f * u);
float ax = cx + SongCarriers.dragonTail[0] * size, ay = cy + SongCarriers.dragonTail[1] * size;
c.drawLine(right, yc - bh / 2f + 3f * u, ax, ay, line);
c.drawLine(right, yc + bh / 2f - 3f * u, ax, ay, line);
SongCarriers.dragon(c, fill, line, path, r, cx, cy, size, (float) Math.sin(t * 6f), t, u);
return true;
} }
// ---------- World ---------- // ---------- World ----------
@@ -67,6 +67,13 @@ public final class SciFiView extends View {
label(c, redAlert ? "RED ALERT · LOW RESERVES" : "PROPULSION STATUS", w * 0.61f + 10f * d, label(c, redAlert ? "RED ALERT · LOW RESERVES" : "PROPULSION STATUS", w * 0.61f + 10f * d,
bar * 0.86f, bar * 1.05f, redAlert ? alert : orange, Paint.Align.LEFT); bar * 0.86f, bar * 1.05f, redAlert ? alert : orange, Paint.Align.LEFT);
pill(c, w * 0.94f, 0, w, bar, frame2); pill(c, w * 0.94f, 0, w, bar, frame2);
if (v.songTitle != null) {
// What plays, in black on the top bar, cut to its length.
float x = side + 16f * d, size = bar * 0.8f;
text.setTextSize(size);
String s = SongBanner.line(text, v.songTitle, v.songArtist, w * 0.60f - x - 16f * d);
label(c, s, x, bar * 0.78f, size, 0xFF000000, Paint.Align.LEFT);
}
// The bottom bar's end: odometer and time. // The bottom bar's end: odometer and time.
String odo = v.odometerKm == null ? "—" : String.format(Locale.US, "%06.0f", v.odometerKm); String odo = v.odometerKm == null ? "—" : String.format(Locale.US, "%06.0f", v.odometerKm);
label(c, "ODO " + odo + " · " + (v.clock.isEmpty() ? "—" : v.clock), label(c, "ODO " + odo + " · " + (v.clock.isEmpty() ? "—" : v.clock),
@@ -0,0 +1,97 @@
package com.evsuite.abrp;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathMeasure;
/**
* The strip of paper a creature tows across a style's sky with the song on it, shared by the styles
* that show what plays (Halloween's parchment, Día de Muertos's papel picado). The ribbon waves in
* the wind: still where the creature holds it, rippling more towards its tail, which is cut as a
* swallowtail, and the text follows the waves. The style draws the creature and the tow lines. Keeps
* only the paths it reuses between frames.
*/
final class SongBanner {
private static final float SPEED = 70f;
private final Path path = new Path();
private final Path baseline = new Path();
private final PathMeasure measure = new PathMeasure();
/** One pass takes about half a minute; then the creature comes round again from the left. */
static float travel(int w, float bw, float tow, float u) {
return w + bw + tow + 80f * u;
}
/** Where the banner's left end is at {@code t} seconds. */
static float left(float t, int w, float bw, float tow, float u) {
return (t * SPEED * u) % travel(w, bw, tow, u) - bw - tow - 40f * u;
}
/** How many times it has crossed by {@code t}, to let two creatures take turns. */
static int pass(float t, int w, float bw, float tow, float u) {
return (int) (t * SPEED * u / travel(w, bw, tow, u));
}
/**
* Draws the banner from {@code bx} to {@code bx + bw}, centred on {@code yc}. {@code tooth} above
* zero cuts both long edges in zigzags of that width (cut paper). The text paint is set up by the
* caller (typeface and size); its colour and alignment are set here.
*/
void draw(Canvas c, Paint fill, Paint line, Paint text, String s, float bx, float yc, float bw, float bh,
float t, float u, float tooth, int paper, int edge, int ink) {
float top = yc - bh / 2f, bottom = yc + bh / 2f, right = bx + bw, notch = 12f * u;
float cut = tooth > 0f ? 3.5f * u : 0f;
int steps = Math.max(8, Math.round(bw / (tooth > 0f ? tooth / 2f : 12f * u)));
path.reset();
for (int i = 0; i <= steps; i++) {
float x = right - bw * i / steps;
float y = top + wave(x, right, bw, t, u) - (i % 2 == 1 ? cut : 0f);
if (i == 0) path.moveTo(x, y);
else path.lineTo(x, y);
}
path.lineTo(bx + notch, yc + wave(bx + notch, right, bw, t, u));
for (int i = steps; i >= 0; i--) {
float x = right - bw * i / steps;
path.lineTo(x, bottom + wave(x, right, bw, t, u) + (i % 2 == 1 ? cut : 0f));
}
path.close();
fill.setColor(paper);
c.drawPath(path, fill);
line.setColor(edge);
line.setStrokeWidth(2f * u);
c.drawPath(path, line);
baseline.reset();
for (int i = 0; i <= steps; i++) {
float x = bx + notch + (bw - notch) * i / steps;
if (i == 0) baseline.moveTo(x, yc + wave(x, right, bw, t, u));
else baseline.lineTo(x, yc + wave(x, right, bw, t, u));
}
measure.setPath(baseline, false);
text.setColor(ink);
text.setTextAlign(Paint.Align.LEFT);
c.drawTextOnPath(s, baseline, Math.max(0f, (measure.getLength() - text.measureText(s)) / 2f), 7f * u, text);
}
/**
* How far the banner bends at {@code x}: nothing at the creature's end ({@code right}), up to 7
* units at the tail, in waves that run from the creature to the tail.
*/
private static float wave(float x, float right, float bw, float t, float u) {
float along = right - x;
return 7f * u * (along / bw) * (float) Math.sin(along / (170f * u) * 2f * Math.PI - t * 5f);
}
/** "♪ title — artist" in the text paint as set, cut with "…" to fit {@code room}; the title gives way first. */
static String line(Paint text, String title, String artist, float room) {
String a = artist == null ? "" : " — " + cut(text, artist, room / 2.5f);
return "♪ " + cut(text, title, room - text.measureText("♪ " + a)) + a;
}
private static String cut(Paint text, String s, float room) {
if (text.measureText(s) <= room) return s;
int fits = text.breakText(s, true, Math.max(0f, room - text.measureText("…")), null);
return s.substring(0, Math.max(0, fits)).trim() + "…";
}
}
@@ -0,0 +1,338 @@
package com.evsuite.abrp;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
/**
* The creatures that tow a {@link SongBanner} in the styles with a sky for it, drawn flying right
* with their centre at (x, y) and about {@code s} wide: a dragon (Quest), an eagle (Empire), Santa's
* sleigh with a reindeer and an angel (Christmas), a butterfly and a ladybird (Caterpillar).
* {@code flap} runs from −1 to 1 with the wing beat, {@code t} is the time in seconds. The caller
* passes its own paints and scratch objects; the paints' colour and width are set here. Where the
* tow lines tie on is {@link #dragonTail}, {@link #eagleTail}, {@link #sleighTail}, {@link #angelTail}, {@link #butterflyTail} and {@link #ladybirdTail}, as offsets in units of {@code s}.
*/
final class SongCarriers {
static final float[] dragonTail = { -1.0f, -0.25f }, eagleTail = { -0.55f, 0.05f },
sleighTail = { -0.62f, 0f }, angelTail = { -0.45f, 0.1f }, butterflyTail = { -0.3f, 0f },
ladybirdTail = { -0.4f, 0f };
private SongCarriers() {}
static void dragon(Canvas c, Paint fill, Paint line, Path path, RectF r, float x, float y, float s,
float flap, float t, float u) {
final int red = 0xFFB3262E, dark = 0xFF6E1219, belly = 0xFFE8B84A;
c.save();
c.translate(x, y);
// The wing behind the body: a membrane between three fingers, lifted and dropped by the flap.
c.save();
c.translate(-0.05f * s, -0.2f * s);
c.rotate(-120f + flap * 30f);
path.reset();
path.moveTo(0, 0);
path.lineTo(0.95f * s, -0.05f * s);
path.quadTo(0.8f * s, 0.15f * s, 0.62f * s, 0.12f * s);
path.quadTo(0.5f * s, 0.3f * s, 0.3f * s, 0.22f * s);
path.quadTo(0.2f * s, 0.35f * s, 0, 0.15f * s);
path.close();
fill.setColor(dark);
c.drawPath(path, fill);
line.setColor(0xFF2A0508);
line.setStrokeWidth(2f * u);
c.drawPath(path, line);
c.drawLine(0, 0.05f * s, 0.62f * s, 0.12f * s, line);
c.restore();
// The tail, ending in a spade.
path.reset();
path.moveTo(-0.4f * s, 0f);
path.cubicTo(-0.9f * s, 0.1f * s, -0.8f * s, -0.3f * s, -1.0f * s, -0.25f * s);
line.setColor(red);
line.setStrokeWidth(0.13f * s);
line.setStrokeCap(Paint.Cap.ROUND);
c.drawPath(path, line);
line.setStrokeCap(Paint.Cap.BUTT);
// Legs.
line.setColor(dark);
line.setStrokeWidth(3f * u);
c.drawLine(-0.25f * s, 0.12f * s, -0.3f * s, 0.34f * s, line);
c.drawLine(0.1f * s, 0.12f * s, 0.18f * s, 0.34f * s, line);
// Body with a pale belly.
r.set(-0.45f * s, -0.17f * s, 0.3f * s, 0.17f * s);
fill.setColor(red);
c.drawOval(r, fill);
r.set(-0.4f * s, 0.0f, 0.25f * s, 0.15f * s);
fill.setColor(belly);
c.drawOval(r, fill);
// Neck and head, a horn, an eye, and a small flame at the mouth.
path.reset();
path.moveTo(0.2f * s, -0.05f * s);
path.quadTo(0.4f * s, -0.05f * s, 0.5f * s, -0.3f * s);
line.setColor(red);
line.setStrokeWidth(0.15f * s);
c.drawPath(path, line);
r.set(0.46f * s, -0.45f * s, 0.86f * s, -0.24f * s);
fill.setColor(red);
c.drawOval(r, fill);
line.setColor(belly);
line.setStrokeWidth(3f * u);
c.drawLine(0.5f * s, -0.44f * s, 0.38f * s, -0.62f * s, line);
fill.setColor(0xFFFFE04A);
c.drawCircle(0.62f * s, -0.37f * s, 0.035f * s, fill);
fill.setColor(0xFF2A0508);
c.drawCircle(0.63f * s, -0.37f * s, 0.016f * s, fill);
float flick = 0.8f + 0.2f * (float) Math.sin(t * 25f);
fill.setColor(0xFFFF8A1F);
c.drawCircle(0.93f * s, -0.33f * s, 0.07f * s * flick, fill);
fill.setColor(0xFFFFE04A);
c.drawCircle(0.95f * s, -0.33f * s, 0.035f * s * flick, fill);
c.restore();
}
static void eagle(Canvas c, Paint fill, Paint line, Path path, RectF r, float x, float y, float s,
float flap, float t, float u) {
final int brown = 0xFF6B4423, dark = 0xFF3E2610, white = 0xFFF4EAD2, beak = 0xFFF2B21B;
c.save();
c.translate(x, y);
// The tail, a short fan.
path.reset();
path.moveTo(-0.3f * s, 0f);
path.lineTo(-0.58f * s, -0.1f * s);
path.lineTo(-0.6f * s, 0.02f * s);
path.lineTo(-0.55f * s, 0.14f * s);
path.close();
fill.setColor(dark);
c.drawPath(path, fill);
// The far wing, then the near one: feathers fanned from the shoulder, lifted by the flap.
for (int wing = 0; wing < 2; wing++) {
for (int i = 0; i < 5; i++) {
c.save();
c.translate(0.02f * s, -0.08f * s);
c.rotate(-130f + flap * 32f + i * 13f + (wing == 0 ? 8f : 0f));
r.set(0, -0.05f * s, (0.95f - 0.08f * Math.abs(i - 2)) * s, 0.05f * s);
fill.setColor(wing == 0 ? dark : (i % 2 == 0 ? brown : 0xFF84552E));
c.drawOval(r, fill);
c.restore();
}
}
// Body, white head, hooked beak, eye, talons.
r.set(-0.35f * s, -0.14f * s, 0.3f * s, 0.14f * s);
fill.setColor(brown);
c.drawOval(r, fill);
fill.setColor(white);
c.drawCircle(0.34f * s, -0.12f * s, 0.12f * s, fill);
path.reset();
path.moveTo(0.42f * s, -0.16f * s);
path.quadTo(0.6f * s, -0.15f * s, 0.55f * s, -0.04f * s);
path.lineTo(0.43f * s, -0.08f * s);
path.close();
fill.setColor(beak);
c.drawPath(path, fill);
fill.setColor(0xFF1A1008);
c.drawCircle(0.38f * s, -0.15f * s, 0.022f * s, fill);
line.setColor(beak);
line.setStrokeWidth(2.5f * u);
c.drawLine(-0.1f * s, 0.13f * s, -0.14f * s, 0.26f * s, line);
c.drawLine(0.05f * s, 0.13f * s, 0.02f * s, 0.26f * s, line);
c.restore();
}
/** A reindeer with a glowing nose pulling Santa's sleigh, drawn about 1.7 s wide. */
static void sleigh(Canvas c, Paint fill, Paint line, Path path, RectF r, float x, float y, float s,
float t, float u) {
final int brown = 0xFF8A5A33, red = 0xFFC62828, gold = 0xFFFFD04A;
c.save();
c.translate(x, y);
// The reindeer: four legs trotting, a body, a neck, a head with antlers and a red nose.
float swing = (float) Math.sin(t * 8f) * 0.18f;
line.setColor(brown);
line.setStrokeWidth(3f * u);
c.drawLine(0.72f * s, 0.05f * s, (0.72f + swing) * s, 0.3f * s, line);
c.drawLine(0.66f * s, 0.05f * s, (0.66f - swing) * s, 0.3f * s, line);
c.drawLine(0.44f * s, 0.05f * s, (0.44f - swing) * s, 0.3f * s, line);
c.drawLine(0.38f * s, 0.05f * s, (0.38f + swing) * s, 0.3f * s, line);
r.set(0.32f * s, -0.15f * s, 0.8f * s, 0.1f * s);
fill.setColor(brown);
c.drawOval(r, fill);
line.setStrokeWidth(0.1f * s);
c.drawLine(0.76f * s, -0.08f * s, 0.86f * s, -0.2f * s, line);
c.drawCircle(0.88f * s, -0.22f * s, 0.075f * s, fill);
line.setColor(0xFFD9C08A);
line.setStrokeWidth(2f * u);
c.drawLine(0.85f * s, -0.28f * s, 0.78f * s, -0.46f * s, line);
c.drawLine(0.82f * s, -0.37f * s, 0.9f * s, -0.4f * s, line);
c.drawLine(0.9f * s, -0.28f * s, 0.97f * s, -0.46f * s, line);
c.drawLine(0.94f * s, -0.37f * s, 0.86f * s, -0.42f * s, line);
float glow = 0.75f + 0.25f * (float) Math.sin(t * 6f);
fill.setColor(0x55FF3B30);
c.drawCircle(0.97f * s, -0.2f * s, 0.1f * s * glow, fill);
fill.setColor(0xFFFF3B30);
c.drawCircle(0.96f * s, -0.2f * s, 0.04f * s, fill);
// The harness, and the sleigh: a red body with a curled front on a gold runner.
line.setColor(gold);
line.setStrokeWidth(1.5f * u);
c.drawLine(0.36f * s, -0.02f * s, 0.12f * s, -0.02f * s, line);
path.reset();
path.moveTo(-0.55f * s, -0.12f * s);
path.lineTo(0.05f * s, -0.12f * s);
path.quadTo(0.22f * s, -0.12f * s, 0.2f * s, -0.28f * s);
path.lineTo(0.12f * s, 0.1f * s);
path.lineTo(-0.5f * s, 0.1f * s);
path.quadTo(-0.64f * s, 0.08f * s, -0.6f * s, -0.12f * s);
path.close();
fill.setColor(red);
c.drawPath(path, fill);
line.setColor(gold);
line.setStrokeWidth(2f * u);
c.drawPath(path, line);
path.reset();
path.moveTo(-0.62f * s, 0.19f * s);
path.lineTo(0.18f * s, 0.19f * s);
path.quadTo(0.32f * s, 0.19f * s, 0.3f * s, 0.07f * s);
line.setStrokeWidth(3f * u);
c.drawPath(path, line);
c.drawLine(-0.4f * s, 0.1f * s, -0.4f * s, 0.19f * s, line);
c.drawLine(0.0f, 0.1f * s, 0.0f, 0.19f * s, line);
// Santa with his sack.
fill.setColor(0xFF7A4A22);
c.drawCircle(-0.5f * s, -0.18f * s, 0.11f * s, fill);
fill.setColor(red);
c.drawCircle(-0.25f * s, -0.2f * s, 0.12f * s, fill);
fill.setColor(0xFFF2CFA0);
c.drawCircle(-0.22f * s, -0.36f * s, 0.07f * s, fill);
fill.setColor(0xFFFFFFFF);
r.set(-0.28f * s, -0.37f * s, -0.15f * s, -0.28f * s);
c.drawOval(r, fill);
path.reset();
path.moveTo(-0.29f * s, -0.4f * s);
path.lineTo(-0.14f * s, -0.4f * s);
path.lineTo(-0.3f * s, -0.56f * s);
path.close();
fill.setColor(red);
c.drawPath(path, fill);
fill.setColor(0xFFFFFFFF);
c.drawCircle(-0.3f * s, -0.57f * s, 0.035f * s, fill);
c.restore();
}
/** A small angel flying right with a trumpet, wings beating. */
static void angel(Canvas c, Paint fill, Paint line, Path path, RectF r, float x, float y, float s,
float flap, float u) {
final int white = 0xFFF4F8FF, gold = 0xFFFFD04A;
c.save();
c.translate(x, y);
for (int i = 0; i < 4; i++) {
c.save();
c.translate(-0.05f * s, -0.12f * s);
c.rotate(-125f + flap * 28f + i * 14f);
r.set(0, -0.06f * s, (0.85f - 0.07f * i) * s, 0.06f * s);
fill.setColor(white);
c.drawOval(r, fill);
line.setColor(0xFFB9C6DC);
line.setStrokeWidth(1.5f * u);
c.drawOval(r, line);
c.restore();
}
// The robe trails behind, with a gold sash.
path.reset();
path.moveTo(0.2f * s, -0.14f * s);
path.quadTo(0.28f * s, 0.05f * s, 0.05f * s, 0.12f * s);
path.lineTo(-0.5f * s, 0.22f * s);
path.quadTo(-0.35f * s, -0.02f * s, -0.1f * s, -0.14f * s);
path.close();
fill.setColor(white);
c.drawPath(path, fill);
line.setColor(0xFFB9C6DC);
line.setStrokeWidth(1.5f * u);
c.drawPath(path, line);
line.setColor(gold);
line.setStrokeWidth(3f * u);
c.drawLine(0.02f * s, -0.12f * s, 0.12f * s, 0.06f * s, line);
// The head with a halo, and the trumpet held out in front.
fill.setColor(0xFFF2CFA0);
c.drawCircle(0.3f * s, -0.2f * s, 0.1f * s, fill);
fill.setColor(gold);
r.set(0.2f * s, -0.4f * s, 0.4f * s, -0.33f * s);
c.drawOval(r, line);
line.setStrokeWidth(2.5f * u);
c.drawLine(0.3f * s, -0.04f * s, 0.7f * s, -0.1f * s, line);
path.reset();
path.moveTo(0.66f * s, -0.1f * s);
path.lineTo(0.9f * s, -0.22f * s);
path.lineTo(0.9f * s, 0.02f * s);
path.close();
c.drawPath(path, fill);
c.restore();
}
/** A big tissue-paper butterfly seen from above, flying right, wings beating. */
static void butterfly(Canvas c, Paint fill, Paint line, Path path, RectF r, float x, float y, float s,
float flap, float u) {
final int purple = 0xFF7E57E0, pink = 0xFFFF5FA2, yellow = 0xFFFFE066, dark = 0xFF1B1530;
float k = 0.3f + 0.7f * Math.abs(flap);
c.save();
c.translate(x, y);
for (int side = 0; side < 2; side++) {
c.save();
if (side == 1) c.scale(1f, -1f);
path.reset();
path.moveTo(0.25f * s, 0);
path.quadTo(0.3f * s, -0.8f * s * k, -0.1f * s, -0.95f * s * k);
path.quadTo(-0.4f * s, -0.6f * s * k, -0.05f * s, 0);
path.close();
fill.setColor(purple);
c.drawPath(path, fill);
path.reset();
path.moveTo(-0.05f * s, 0);
path.quadTo(-0.45f * s, -0.6f * s * k, -0.7f * s, -0.35f * s * k);
path.quadTo(-0.6f * s, -0.05f * s * k, -0.2f * s, 0);
path.close();
fill.setColor(pink);
c.drawPath(path, fill);
fill.setColor(yellow);
c.drawCircle(0.02f * s, -0.58f * s * k, 0.08f * s, fill);
c.drawCircle(-0.4f * s, -0.33f * s * k, 0.06f * s, fill);
c.restore();
}
fill.setColor(dark);
r.set(-0.4f * s, -0.06f * s, 0.3f * s, 0.06f * s);
c.drawOval(r, fill);
c.drawCircle(0.34f * s, 0, 0.07f * s, fill);
line.setColor(dark);
line.setStrokeWidth(1.5f * u);
c.drawLine(0.38f * s, -0.03f * s, 0.55f * s, -0.18f * s, line);
c.drawLine(0.38f * s, 0.03f * s, 0.55f * s, 0.18f * s, line);
c.restore();
}
/** A ladybird seen from above, flying right, with its wings out. */
static void ladybird(Canvas c, Paint fill, Paint line, Path path, RectF r, float x, float y, float s,
float flap, float u) {
final int red = 0xFFE53935, dark = 0xFF1B1530;
c.save();
c.translate(x, y);
float out = (0.3f + 0.25f * Math.abs(flap)) * s;
fill.setColor(0xAAFFFFFF);
r.set(-0.45f * s, -out - 0.12f * s, 0.15f * s, -out + 0.12f * s);
c.drawOval(r, fill);
r.set(-0.45f * s, out - 0.12f * s, 0.15f * s, out + 0.12f * s);
c.drawOval(r, fill);
fill.setColor(red);
r.set(-0.4f * s, -0.26f * s, 0.26f * s, 0.26f * s);
c.drawOval(r, fill);
line.setColor(dark);
line.setStrokeWidth(2f * u);
c.drawLine(-0.4f * s, 0, 0.26f * s, 0, line);
fill.setColor(dark);
c.drawCircle(-0.2f * s, -0.12f * s, 0.045f * s, fill);
c.drawCircle(-0.2f * s, 0.12f * s, 0.045f * s, fill);
c.drawCircle(0.05f * s, -0.14f * s, 0.045f * s, fill);
c.drawCircle(0.05f * s, 0.14f * s, 0.045f * s, fill);
c.drawCircle(0.34f * s, 0, 0.12f * s, fill);
line.setStrokeWidth(1.5f * u);
c.drawLine(0.42f * s, -0.06f * s, 0.58f * s, -0.18f * s, line);
c.drawLine(0.42f * s, 0.06f * s, 0.58f * s, 0.18f * s, line);
c.restore();
}
}
@@ -26,6 +26,8 @@ final class StylePalette {
case EMPIRE: return R.style.ThemeOverlay_EV_Style_Empire; case EMPIRE: return R.style.ThemeOverlay_EV_Style_Empire;
case MUERTOS: return R.style.ThemeOverlay_EV_Style_Muertos; case MUERTOS: return R.style.ThemeOverlay_EV_Style_Muertos;
case HALLOWEEN: return R.style.ThemeOverlay_EV_Style_Halloween; case HALLOWEEN: return R.style.ThemeOverlay_EV_Style_Halloween;
case CHRISTMAS: return R.style.ThemeOverlay_EV_Style_Christmas;
case CATERPILLAR: return R.style.ThemeOverlay_EV_Style_Caterpillar;
default: return 0; default: return 0;
} }
} }
@@ -84,6 +84,14 @@ final class TerminalView extends ClusterCanvasView {
y += line; y += line;
print(c, row("TYRES", "FL " + v.tyreFl + " FR " + v.tyreFr + " RL " + v.tyreRl + " RR " + v.tyreRr), x, y, green); print(c, row("TYRES", "FL " + v.tyreFl + " FR " + v.tyreFr + " RL " + v.tyreRl + " RR " + v.tyreRr), x, y, green);
y += line * 1.4f; y += line * 1.4f;
if (v.songTitle != null) {
// What plays, cut to the row's width.
String label = String.format(Locale.US, "%-9s", "PLAYING");
String s = v.songTitle + (v.songArtist == null ? "" : " — " + v.songArtist);
int fits = text.breakText(s, true, Math.max(0f, getWidth() - x - text.measureText(label)), null);
print(c, label + (fits < s.length() ? s.substring(0, Math.max(0, fits - 1)).trim() + "…" : s), x, y, green);
y += line;
}
boolean cursor = (SystemClock.uptimeMillis() / 500) % 2 == 0; boolean cursor = (SystemClock.uptimeMillis() / 500) % 2 == 0;
print(c, "[" + (v.clock.isEmpty() ? "--:--" : v.clock) + "] nils@mg4:~$ " + (cursor ? "█" : ""), x, y, green); print(c, "[" + (v.clock.isEmpty() ? "--:--" : v.clock) + "] nils@mg4:~$ " + (cursor ? "█" : ""), x, y, green);
@@ -0,0 +1,69 @@
package com.evsuite.abrp;
import java.io.IOException;
import java.net.ConnectException;
import java.net.NoRouteToHostException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.SSLException;
/**
* Why an update check failed, in words for the update log, and what the car's networks look
* like. Built from an error's type and an HTTP status only, because an error's own text can carry
* the server's address: nothing here holds a URL or a credential. Android-free and unit-tested.
*/
final class UpdateDiagnosis {
private static final Pattern STATUS = Pattern.compile("^Release API returned (\\d{3})$");
private UpdateDiagnosis() {}
/** One line about a failed step. */
static String failure(Throwable t) {
if (t == null) return "unknown failure";
String type = " (" + t.getClass().getSimpleName() + ")";
if (t instanceof UnknownHostException) return "the name could not be looked up: no data connection, or no name service" + type;
if (t instanceof SocketTimeoutException) return "no answer in time: a very slow or blocked connection" + type;
if (t instanceof ConnectException || t instanceof NoRouteToHostException) return "no connection could be made" + type;
if (t instanceof SSLException) return "the secure connection failed: something in between may have answered, or the head unit's clock is wrong" + type;
if (t instanceof SocketException) return "the connection broke off" + type;
if (t instanceof IOException && t.getMessage() != null) {
Matcher status = STATUS.matcher(t.getMessage());
if (status.matches()) return status(Integer.parseInt(status.group(1)));
if (t.getMessage().equals("Invalid release response")) return "the answer was not a list of releases";
}
return "failed" + type;
}
/** What a status from the car server means here. */
static String status(int code) {
String what;
if (code >= 300 && code < 400) what = "something in between redirected it, as a SIM without data may";
else if (code == 401 || code == 403) what = "the server refuses the car's token";
else if (code == 404) what = "the server does not know this address";
else if (code >= 500) what = "the server or the forge behind it has a problem";
else what = "not what was expected";
return "the server answered HTTP " + code + ": " + what;
}
/** The outside-world test: a 204 is the internet working; anything else stands in between. */
static String internet(int code) {
if (code == 204) return "the internet works (HTTP 204)";
return "something in between answered HTTP " + code + " instead, as a SIM without data may";
}
/** One network as Android sees it. */
static String network(List<String> transports, boolean internet, boolean validated,
boolean active, boolean roaming) {
return (transports.isEmpty() ? "unknown type" : String.join("+", transports))
+ (active ? ", in use" : "")
+ (internet ? ", offers internet" : ", no internet")
+ (validated ? ", confirmed by Android" : ", not confirmed by Android")
+ (roaming ? ", roaming" : "");
}
}
@@ -21,7 +21,7 @@ import java.util.Locale;
*/ */
final class UpdateLog { final class UpdateLog {
static final int MAX_LINES = 10; static final int MAX_LINES = 40;
private static final String PREFS = "update_log"; private static final String PREFS = "update_log";
private static final String KEY = "lines"; private static final String KEY = "lines";
private static final String KEY_VERSION = "version"; private static final String KEY_VERSION = "version";
@@ -26,6 +26,12 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<TextView android:id="@+id/accent_note" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:textAppearance="@style/Text.EV.Secondary" android:visibility="gone" /> <TextView android:id="@+id/accent_note" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:textAppearance="@style/Text.EV.Secondary" android:visibility="gone" />
<!-- Only the styles that show what plays (the styles with a place for it). -->
<com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/now_playing_switch" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:text="@string/label_now_playing" android:textAppearance="@style/Text.EV.Body" android:paddingTop="8dp" android:paddingBottom="8dp" app:useMaterialThemeColors="true" app:thumbTint="@color/switch_thumb" app:trackTint="@color/switch_track" android:textColor="@color/ev_text_primary" android:visibility="gone" />
<TextView android:id="@+id/now_playing_hint" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/hint_now_playing" android:textAppearance="@style/Text.EV.Secondary" android:visibility="gone" />
<!-- Only Halloween, Christmas and Caterpillar listen to the music. -->
<com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/music_light_switch" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:text="@string/label_music_light" android:textAppearance="@style/Text.EV.Body" android:paddingTop="8dp" android:paddingBottom="8dp" app:useMaterialThemeColors="true" app:thumbTint="@color/switch_thumb" app:trackTint="@color/switch_track" android:textColor="@color/ev_text_primary" android:visibility="gone" />
<TextView android:id="@+id/music_light_hint" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/hint_music_light" android:textAppearance="@style/Text.EV.Secondary" android:visibility="gone" />
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:baselineAligned="false"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:baselineAligned="false">
<LinearLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_marginEnd="12dp" android:orientation="vertical"> <LinearLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_marginEnd="12dp" android:orientation="vertical">
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/label_tire_unit" android:textAppearance="@style/Text.EV.Body" android:layout_marginTop="8dp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/label_tire_unit" android:textAppearance="@style/Text.EV.Body" android:layout_marginTop="8dp" />
@@ -31,7 +31,18 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:orientation="horizontal" android:baselineAligned="false"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:orientation="horizontal" android:baselineAligned="false">
<Space android:layout_width="0dp" android:layout_height="1dp" android:layout_weight="1" android:layout_marginEnd="10dp" /> <!-- What plays (NowPlaying), in the slot under the battery; invisible when nothing does. -->
<LinearLayout android:id="@+id/now_playing_tile" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginEnd="10dp" android:orientation="vertical" android:minHeight="112dp" android:padding="16dp" android:background="@drawable/bg_glass" android:visibility="invisible">
<TextView android:id="@+id/now_playing_source" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="@style/Text.EV.Secondary" android:maxLines="1" android:ellipsize="end" />
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:orientation="horizontal" android:gravity="center_vertical" android:baselineAligned="false">
<ImageView android:id="@+id/now_playing_cover" android:layout_width="44dp" android:layout_height="44dp" android:layout_marginEnd="10dp" android:scaleType="centerCrop" android:importantForAccessibility="no" android:visibility="gone" />
<LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical">
<TextView android:id="@+id/now_playing_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="@style/Text.EV.Body" android:textSize="17sp" android:maxLines="1" android:ellipsize="end" />
<TextView android:id="@+id/now_playing_artist" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="@style/Text.EV.Secondary" android:textColor="?attr/evAccentLight" android:textSize="16sp" android:maxLines="1" android:ellipsize="end" />
</LinearLayout>
</LinearLayout>
<ProgressBar android:id="@+id/now_playing_progress" style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="4dp" android:layout_marginTop="6dp" android:max="1000" android:progressTint="?attr/evAccent" android:progressBackgroundTint="?attr/evAccentTrack" android:visibility="invisible" />
</LinearLayout>
<LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginEnd="10dp" android:orientation="vertical" android:minHeight="112dp" android:padding="16dp" android:background="@drawable/bg_glass"> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginEnd="10dp" android:orientation="vertical" android:minHeight="112dp" android:padding="16dp" android:background="@drawable/bg_glass">
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/vehicle_row_energy_trip" android:textAppearance="@style/Text.EV.Secondary" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/vehicle_row_energy_trip" android:textAppearance="@style/Text.EV.Secondary" />
<TextView android:id="@+id/vehicle_energy_trip" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/no_value" android:layout_marginTop="6dp" android:textAppearance="@style/Text.EV.Metric.Compact" android:gravity="end" android:fontFeatureSettings="tnum" android:maxLines="1" android:autoSizeTextType="uniform" android:autoSizeMinTextSize="18sp" android:autoSizeMaxTextSize="28sp" android:autoSizeStepGranularity="1sp" /> <TextView android:id="@+id/vehicle_energy_trip" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/no_value" android:layout_marginTop="6dp" android:textAppearance="@style/Text.EV.Metric.Compact" android:gravity="end" android:fontFeatureSettings="tnum" android:maxLines="1" android:autoSizeTextType="uniform" android:autoSizeMinTextSize="18sp" android:autoSizeMaxTextSize="28sp" android:autoSizeStepGranularity="1sp" />
@@ -17,6 +17,12 @@
<com.google.android.material.textfield.MaterialAutoCompleteTextView android:id="@+id/accent_choices" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:inputType="none" android:textSize="20sp" app:simpleItemLayout="@layout/dropdown_item" /> <com.google.android.material.textfield.MaterialAutoCompleteTextView android:id="@+id/accent_choices" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:inputType="none" android:textSize="20sp" app:simpleItemLayout="@layout/dropdown_item" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<TextView android:id="@+id/accent_note" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:textAppearance="@style/Text.EV.Secondary" android:visibility="gone" /> <TextView android:id="@+id/accent_note" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:textAppearance="@style/Text.EV.Secondary" android:visibility="gone" />
<!-- Only the styles that show what plays (the styles with a place for it). -->
<com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/now_playing_switch" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:text="@string/label_now_playing" android:textAppearance="@style/Text.EV.Body" android:paddingTop="8dp" android:paddingBottom="8dp" app:useMaterialThemeColors="true" app:thumbTint="@color/switch_thumb" app:trackTint="@color/switch_track" android:textColor="@color/ev_text_primary" android:visibility="gone" />
<TextView android:id="@+id/now_playing_hint" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/hint_now_playing" android:textAppearance="@style/Text.EV.Secondary" android:visibility="gone" />
<!-- Only Halloween, Christmas and Caterpillar listen to the music. -->
<com.google.android.material.switchmaterial.SwitchMaterial android:id="@+id/music_light_switch" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:text="@string/label_music_light" android:textAppearance="@style/Text.EV.Body" android:paddingTop="8dp" android:paddingBottom="8dp" app:useMaterialThemeColors="true" app:thumbTint="@color/switch_thumb" app:trackTint="@color/switch_track" android:textColor="@color/ev_text_primary" android:visibility="gone" />
<TextView android:id="@+id/music_light_hint" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/hint_music_light" android:textAppearance="@style/Text.EV.Secondary" android:visibility="gone" />
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/label_tire_unit" android:textAppearance="@style/Text.EV.Body" android:layout_marginTop="20dp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/label_tire_unit" android:textAppearance="@style/Text.EV.Body" android:layout_marginTop="20dp" />
<com.google.android.material.textfield.TextInputLayout style="@style/Widget.EV.Dropdown" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="12dp"> <com.google.android.material.textfield.TextInputLayout style="@style/Widget.EV.Dropdown" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="12dp">
<com.google.android.material.textfield.MaterialAutoCompleteTextView android:id="@+id/tire_unit_choices" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:inputType="none" android:textSize="20sp" app:simpleItemLayout="@layout/dropdown_item" /> <com.google.android.material.textfield.MaterialAutoCompleteTextView android:id="@+id/tire_unit_choices" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="72dp" android:inputType="none" android:textSize="20sp" app:simpleItemLayout="@layout/dropdown_item" />
+11
View File
@@ -129,6 +129,15 @@
<string name="overview_style_scifi">Sci-fi</string> <string name="overview_style_scifi">Sci-fi</string>
<string name="overview_style_cartoon">Cartoon</string> <string name="overview_style_cartoon">Cartoon</string>
<string name="overview_style_mg">MG</string> <string name="overview_style_mg">MG</string>
<string name="label_now_playing">Show what\'s playing</string>
<string name="hint_now_playing">Title and artist from Bluetooth, CarPlay or the radio. Shown here only, never sent.</string>
<string name="now_playing_bluetooth">Bluetooth</string>
<string name="now_playing_carplay">CarPlay</string>
<string name="now_playing_radio">Radio</string>
<string name="now_playing_other">Media</string>
<string name="now_playing_paused">%1$s · paused</string>
<string name="label_music_light">Light follows the music</string>
<string name="hint_music_light">Flares on the kick drum over Bluetooth or CarPlay, not the radio. Levels only, no sound kept.</string>
<string name="accent_not_used">%1$s has its own colours, and the app takes them on. To change the accent colour, pick a style that uses it.</string> <string name="accent_not_used">%1$s has its own colours, and the app takes them on. To change the accent colour, pick a style that uses it.</string>
<string name="overview_fullscreen_enter">Overview full screen: hide the navigation</string> <string name="overview_fullscreen_enter">Overview full screen: hide the navigation</string>
<string name="overview_fullscreen_exit">Show the navigation again</string> <string name="overview_fullscreen_exit">Show the navigation again</string>
@@ -143,6 +152,8 @@
<string name="overview_style_empire">Empire</string> <string name="overview_style_empire">Empire</string>
<string name="overview_style_muertos">Día de Muertos</string> <string name="overview_style_muertos">Día de Muertos</string>
<string name="overview_style_halloween">Halloween</string> <string name="overview_style_halloween">Halloween</string>
<string name="overview_style_christmas">Christmas</string>
<string name="overview_style_caterpillar">Caterpillar</string>
<string name="overview_style_nixie">Nixie tubes</string> <string name="overview_style_nixie">Nixie tubes</string>
<string name="overview_style_chronograph">Chronograph</string> <string name="overview_style_chronograph">Chronograph</string>
<string name="cockpit_battery">BATTERY</string> <string name="cockpit_battery">BATTERY</string>
@@ -124,4 +124,24 @@
<item name="evAccentStroke">#80804A1E</item> <item name="evAccentStroke">#80804A1E</item>
<item name="evAccentTrack">#6A3F18</item> <item name="evAccentTrack">#6A3F18</item>
</style> </style>
<!-- Christmas: the red of the big bauble. -->
<style name="ThemeOverlay.EV.Style.Christmas" parent="">
<item name="evAccent">#E53946</item>
<item name="evOnAccent">#1F0306</item>
<item name="evAccentLight">#FF9AA3</item>
<item name="evAccentDeep">#3D0C12</item>
<item name="evAccentSurface">#10243A</item>
<item name="evAccentStroke">#80B08A3A</item>
<item name="evAccentTrack">#7A2630</item>
</style>
<!-- Caterpillar: the green of its body. -->
<style name="ThemeOverlay.EV.Style.Caterpillar" parent="">
<item name="evAccent">#5CC15A</item>
<item name="evOnAccent">#07210B</item>
<item name="evAccentLight">#B6F0A8</item>
<item name="evAccentDeep">#123A1A</item>
<item name="evAccentSurface">#10243A</item>
<item name="evAccentStroke">#8057A04A</item>
<item name="evAccentTrack">#2E6B35</item>
</style>
</resources> </resources>
@@ -36,6 +36,45 @@ public class MusicPulseTest {
assertEquals(0f, last, 0f); assertEquals(0f, last, 0f);
} }
@Test
public void aHeldBassNoteLightsOnlyItsStart() {
MusicPulse p = new MusicPulse();
for (int i = 0; i < 50; i++) p.update(0.05f, STEP);
assertTrue(p.update(0.4f, STEP) > 0.8f);
float last = 1f;
for (int i = 0; i < 25; i++) last = p.update(0.4f, STEP);
assertEquals(0f, last, 0f);
}
@Test
public void aWobblingBassLineStaysDark() {
MusicPulse p = new MusicPulse();
for (int i = 0; i < 50; i++) p.update(0.3f, STEP);
float top = 0f;
for (int i = 0; i < 200; i++) top = Math.max(top, p.update(i % 3 == 0 ? 0.33f : 0.3f, STEP));
assertEquals(0f, top, 0f);
}
@Test
public void aSwellingNoteStaysDark() {
MusicPulse p = new MusicPulse();
for (int i = 0; i < 50; i++) p.update(0.1f, STEP);
float top = 0f;
for (int i = 0; i < 100; i++) top = Math.max(top, p.update(0.1f + i * 0.004f, STEP));
assertEquals(0f, top, 0f);
}
@Test
public void aKickOverABassLineLights() {
MusicPulse p = new MusicPulse();
float top = 0f;
for (int i = 0; i < 300; i++) {
float v = p.update(i % 12 == 0 ? 0.6f : (i % 3 == 0 ? 0.33f : 0.3f), STEP);
if (i > 100) top = Math.max(top, v);
}
assertTrue("a kick lights it, got " + top, top > 0.8f);
}
@Test @Test
public void quietAndLoudSongsPulseAlike() { public void quietAndLoudSongsPulseAlike() {
assertEquals(beatOf(0.5f), beatOf(0.05f), 0.02f); assertEquals(beatOf(0.5f), beatOf(0.05f), 0.02f);
@@ -0,0 +1,138 @@
package com.evsuite.abrp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
public class NowPlayingTest {
private static NowPlaying.Session session(String pkg, int state, String title, String artist, long updatedAt) {
NowPlaying.Session s = new NowPlaying.Session();
s.packageName = pkg;
s.state = state;
s.title = title;
s.artist = artist;
s.positionUpdatedAt = updatedAt;
return s;
}
@Test
public void nothingToShow() {
assertNull(NowPlaying.pick(null));
assertNull(NowPlaying.pick(Collections.emptyList()));
// Bluetooth's empty session after the phone stopped, and one that only connects.
assertNull(NowPlaying.pick(Arrays.asList(
session("com.android.bluetooth", 1, "", "", 5),
session("com.android.car.radio", 8, "Radio", null, 6),
session("com.android.bluetooth", NowPlaying.STATE_PLAYING, " ", null, 7))));
}
@Test
public void whatPlaysWinsOverWhatIsPaused() {
// As on the car on 2026-10-28: CarPlay paused, Bluetooth playing.
NowPlaying.Track t = NowPlaying.pick(Arrays.asList(
session("com.allgo.remoteui.mediabrowserservice", NowPlaying.STATE_PAUSED, "A Mix", "Bass Bangers", 900),
session("com.android.bluetooth", NowPlaying.STATE_PLAYING, "Paramount", "Mark Petrie & Andrew Prahlow", 100)));
assertEquals(NowPlaying.Source.BLUETOOTH, t.source);
assertEquals("Paramount", t.title);
assertEquals("Mark Petrie & Andrew Prahlow", t.subtitle);
assertTrue(t.playing);
}
@Test
public void ofTwoPlayingTheNewerWins() {
NowPlaying.Track t = NowPlaying.pick(Arrays.asList(
session("com.android.bluetooth", NowPlaying.STATE_PLAYING, "Old", null, 100),
session("com.allgo.remoteui.mediabrowserservice", NowPlaying.STATE_BUFFERING, "New", null, 200)));
assertEquals(NowPlaying.Source.CARPLAY, t.source);
assertEquals("New", t.title);
}
@Test
public void withNothingPlayingThePausedOneShows() {
NowPlaying.Track t = NowPlaying.pick(Arrays.asList(
session("com.android.bluetooth", NowPlaying.STATE_PAUSED, "Earlier", null, 100),
session("com.allgo.remoteui.mediabrowserservice", NowPlaying.STATE_PAUSED, "Later", null, 300)));
assertEquals("Later", t.title);
assertFalse(t.playing);
}
@Test
public void theRadioShowsItsTextWithTheStationBelow() {
NowPlaying.Track t = NowPlaying.pick(Collections.singletonList(
session("com.saicmotor.radio", NowPlaying.STATE_PLAYING, "Brillux Radio", "BLIND MELON - NO RAIN", 1)));
assertEquals(NowPlaying.Source.RADIO, t.source);
assertEquals("BLIND MELON - NO RAIN", t.title);
assertEquals("Brillux Radio", t.subtitle);
NowPlaying.Track station = NowPlaying.pick(Collections.singletonList(
session("com.saicmotor.radio", NowPlaying.STATE_PLAYING, "Brillux Radio", "", 1)));
assertEquals("Brillux Radio", station.title);
assertNull(station.subtitle);
assertEquals(-1f, station.progressAt(5), 0f);
}
@Test
public void textIsCleaned() {
assertEquals("A Letter to the Past (A Seasonal Feels Mix) Ft. Porter Robinson & Friends By SAINT",
NowPlaying.clean("A Letter to the Past (A Seasonal Feels Mix) Ft. Porter Robinson & Friends By SAINT [X4nayMeMBuQ]"));
assertEquals("Live [Remastered 2011]", NowPlaying.clean("Live [Remastered 2011]"));
assertEquals("two lines", NowPlaying.clean(" two\n lines "));
assertNull(NowPlaying.clean(" "));
assertNull(NowPlaying.clean(null));
StringBuilder longText = new StringBuilder();
for (int i = 0; i < 300; i++) longText.append('x');
assertEquals(200, NowPlaying.clean(longText.toString()).length());
}
@Test
public void onlyAnArtistStillShows() {
NowPlaying.Track t = NowPlaying.pick(Collections.singletonList(
session("com.example.player", NowPlaying.STATE_PLAYING, null, "Someone", 1)));
assertEquals(NowPlaying.Source.OTHER, t.source);
assertEquals("Someone", t.title);
assertNull(t.subtitle);
}
@Test
public void thePositionRunsOnWhilePlayingAndStopsAtTheEnd() {
NowPlaying.Session s = session("com.android.bluetooth", NowPlaying.STATE_PLAYING, "Paramount", "M", 10_000);
s.positionMs = 3_000;
s.durationMs = 215_000;
NowPlaying.Track t = NowPlaying.pick(Collections.singletonList(s));
assertEquals(3_000, t.positionAt(10_000));
assertEquals(8_000, t.positionAt(15_000));
assertEquals(215_000, t.positionAt(10_000_000));
assertEquals(1f, t.progressAt(10_000_000), 0f);
assertEquals(8_000 / 215_000f, t.progressAt(15_000), 1e-6f);
}
@Test
public void aPausedPositionStaysPut() {
NowPlaying.Session s = session("com.android.bluetooth", NowPlaying.STATE_PAUSED, "Paramount", null, 10_000);
s.positionMs = 3_000;
s.durationMs = 215_000;
assertEquals(3_000, NowPlaying.pick(Collections.singletonList(s)).positionAt(99_000));
}
@Test
public void noPositionNoBar() {
NowPlaying.Session s = session("com.android.bluetooth", NowPlaying.STATE_PLAYING, "Paramount", null, 10_000);
s.durationMs = 215_000;
assertEquals(-1f, NowPlaying.pick(Collections.singletonList(s)).progressAt(20_000), 0f);
}
@Test
public void sourcesAreKnownByTheirApps() {
assertEquals(NowPlaying.Source.BLUETOOTH, NowPlaying.source("com.android.bluetooth"));
assertEquals(NowPlaying.Source.CARPLAY, NowPlaying.source("com.allgo.remoteui.mediabrowserservice"));
assertEquals(NowPlaying.Source.RADIO, NowPlaying.source("com.saicmotor.radio"));
assertEquals(NowPlaying.Source.OTHER, NowPlaying.source("com.android.music"));
assertEquals(NowPlaying.Source.OTHER, NowPlaying.source(null));
}
}
@@ -0,0 +1,67 @@
package com.evsuite.abrp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import java.io.IOException;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Collections;
import javax.net.ssl.SSLHandshakeException;
public class UpdateDiagnosisTest {
@Test
public void errorsAreToldApart() {
assertTrue(UpdateDiagnosis.failure(new UnknownHostException()).contains("no data connection"));
assertTrue(UpdateDiagnosis.failure(new SocketTimeoutException()).contains("in time"));
assertTrue(UpdateDiagnosis.failure(new ConnectException()).contains("no connection"));
assertTrue(UpdateDiagnosis.failure(new SSLHandshakeException("x")).contains("in between"));
assertTrue(UpdateDiagnosis.failure(new IOException("Release API returned 401")).contains("token"));
assertTrue(UpdateDiagnosis.failure(new IOException("Invalid release response")).contains("not a list"));
assertEquals("unknown failure", UpdateDiagnosis.failure(null));
}
@Test
public void anErrorsOwnTextNeverReachesTheLog() {
String secret = "https://car.example.com/v1/app/releases?token=abc";
for (Throwable t : Arrays.asList(new UnknownHostException(secret), new SocketTimeoutException(secret),
new ConnectException(secret), new SSLHandshakeException(secret), new IOException(secret),
new RuntimeException(secret))) {
String line = UpdateDiagnosis.failure(t);
assertFalse(line, line.contains("example"));
assertFalse(line, line.contains("abc"));
}
}
@Test
public void statusesSayWhoIsAtFault() {
assertTrue(UpdateDiagnosis.status(302).contains("SIM without data"));
assertTrue(UpdateDiagnosis.status(401).contains("token"));
assertTrue(UpdateDiagnosis.status(403).contains("token"));
assertTrue(UpdateDiagnosis.status(404).contains("does not know"));
assertTrue(UpdateDiagnosis.status(502).contains("forge"));
assertTrue(UpdateDiagnosis.status(418).contains("HTTP 418"));
}
@Test
public void onlyA204IsTheInternetWorking() {
assertTrue(UpdateDiagnosis.internet(204).startsWith("the internet works"));
assertTrue(UpdateDiagnosis.internet(200).contains("in between"));
assertTrue(UpdateDiagnosis.internet(302).contains("SIM without data"));
}
@Test
public void aNetworkInOneLine() {
assertEquals("cellular, in use, offers internet, not confirmed by Android, roaming",
UpdateDiagnosis.network(Collections.singletonList("cellular"), true, false, true, true));
assertEquals("unknown type, no internet, confirmed by Android",
UpdateDiagnosis.network(Collections.emptyList(), false, true, false, false));
}
}
+2
View File
@@ -18,6 +18,8 @@
android:name="android.permission.MEDIA_CONTENT_CONTROL" android:name="android.permission.MEDIA_CONTENT_CONTROL"
tools:ignore="ProtectedPermissions" /> tools:ignore="ProtectedPermissions" />
<!-- An update check writes down which networks Android sees (UpdateNetworkCheck). -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- The Logs tab's sound check (SoundProbe): Android's audio analyser asks for both. The <!-- The Logs tab's sound check (SoundProbe): Android's audio analyser asks for both. The
system user holds them without a prompt; the analyser reports levels only, no sound. --> system user holds them without a prompt; the analyser reports levels only, no sound. -->
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.RECORD_AUDIO" />
@@ -55,6 +55,9 @@ final class OtaUpdater {
private static final String TAG = "OtaUpdater"; private static final String TAG = "OtaUpdater";
private static final String CACHE_PREFIX = "NilsMG4-ota-"; private static final String CACHE_PREFIX = "NilsMG4-ota-";
/** Why the last download failed, for the update log. */
static volatile String downloadProblem = "unknown";
/** The release list on the car server, for the server configured in the app. */ /** The release list on the car server, for the server configured in the app. */
static String releasesUrl(ServerConfig config) { static String releasesUrl(ServerConfig config) {
return config.url + "/v1/app/releases"; return config.url + "/v1/app/releases";
@@ -366,6 +369,7 @@ final class OtaUpdater {
connection.setRequestProperty("User-Agent", "NilsMG4-Android"); connection.setRequestProperty("User-Agent", "NilsMG4-Android");
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
Log.w(TAG, "Update download returned " + connection.getResponseCode()); Log.w(TAG, "Update download returned " + connection.getResponseCode());
downloadProblem = UpdateDiagnosis.status(connection.getResponseCode());
return null; return null;
} }
long total = connection.getContentLengthLong(); long total = connection.getContentLengthLong();
@@ -390,10 +394,14 @@ final class OtaUpdater {
out.getFD().sync(); out.getFD().sync();
} }
ok = hex(digest.digest()).equalsIgnoreCase(expectedSha256); ok = hex(digest.digest()).equalsIgnoreCase(expectedSha256);
if (!ok) Log.w(TAG, "Update APK does not match its SHA-256"); if (!ok) {
Log.w(TAG, "Update APK does not match its SHA-256");
downloadProblem = "it does not match its SHA-256";
}
return ok ? target : null; return ok ? target : null;
} catch (Exception e) { } catch (Exception e) {
Log.w(TAG, "Update download failed: " + e.getClass().getSimpleName()); Log.w(TAG, "Update download failed: " + e.getClass().getSimpleName());
downloadProblem = UpdateDiagnosis.failure(e);
return null; return null;
} finally { } finally {
if (connection != null) connection.disconnect(); if (connection != null) connection.disconnect();
@@ -5,6 +5,11 @@ import android.util.Log;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
/** /**
@@ -58,7 +63,8 @@ final class UpdateHook {
"Update available: " + update.versionName, "Update available: " + update.versionName,
android.widget.Toast.LENGTH_LONG).show()); android.widget.Toast.LENGTH_LONG).show());
} catch (Throwable t) { } catch (Throwable t) {
Log.w(TAG, "Startup update check failed", t); Log.w(TAG, "Startup update check failed: " + t.getClass().getSimpleName());
UpdateLog.record(app, "Check at start: " + UpdateDiagnosis.failure(t));
} }
}, "ota-startup-check").start(); }, "ota-startup-check").start();
} }
@@ -78,24 +84,46 @@ final class UpdateHook {
return; return;
} }
new Thread(() -> { new Thread(() -> {
long startedMs = System.currentTimeMillis();
List<String> steps = new ArrayList<>();
step(app, steps, "Check started, app " + BuildConfig.VERSION_NAME);
String message; String message;
try { try {
for (String network : UpdateNetworkCheck.networks(app)) step(app, steps, network);
ServerConfig config = ServerConfig.get(app);
String host = config.isConfigured() ? OtaUpdater.allowedHost(config) : null;
if (host != null) step(app, steps, UpdateNetworkCheck.lookup(host));
message = runCheck(app, listener, main); message = runCheck(app, listener, main);
} catch (Throwable t) { } catch (Throwable t) {
Log.w(TAG, "Update check threw", t); Log.w(TAG, "Update check threw: " + t.getClass().getSimpleName());
// The class only: a network error's text can carry the server's address. message = "Update check failed: " + UpdateDiagnosis.failure(t);
message = "Update check failed (" + t.getClass().getSimpleName() + ")"; // Is it the server or the connection? The answer to "is my SIM out of data".
step(app, steps, UpdateNetworkCheck.internet());
} finally { } finally {
checking.set(false); checking.set(false);
} }
UpdateLog.record(app, "Check: " + message); step(app, steps, "Check: " + message);
String waiting = LogOutbox.status(app);
if (waiting != null) step(app, steps, "Reports: " + waiting);
if (listener != null) { if (listener != null) {
final String result = message; final String result = message;
main.post(() -> listener.onResult(result)); main.post(() -> listener.onResult(result));
} }
// After the answer: without a connection this waits for the send to fail.
String name = "update-check-" + new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.US)
.format(new Date(startedMs)) + ".txt";
// Only the newest waits: repeated checks offline must not push out a recording.
LogOutbox.dropWaiting(app, "update-check-");
SignalRecorder.saveCopies(app, "update_check.txt", name, steps);
}, "ota-check").start(); }, "ota-check").start();
} }
/** One step of a check: on the Logs tab now, and in the report saved when it ends. */
private static void step(Context app, List<String> steps, String what) {
UpdateLog.record(app, what);
steps.add(what);
}
/** /**
* Installs the newest car build from the top folder of a USB stick (UsbUpdate), with the * Installs the newest car build from the top folder of a USB stick (UsbUpdate), with the
* same checks as the over-the-air update except the server. Background thread; [listener] * same checks as the over-the-air update except the server. Background thread; [listener]
@@ -195,14 +223,14 @@ final class UpdateHook {
try { try {
expectedHash = OtaUpdater.fetchExpectedSha256(update, config); expectedHash = OtaUpdater.fetchExpectedSha256(update, config);
} catch (IOException e) { } catch (IOException e) {
Log.w(TAG, "OTA hash unavailable: " + e.getMessage()); Log.w(TAG, "OTA hash unavailable: " + e.getClass().getSimpleName());
return "Update refused: no SHA-256 verification"; return "Update refused, no SHA-256 verification: " + UpdateDiagnosis.failure(e);
} }
File apk = OtaUpdater.download(update, expectedHash, config, percent -> { File apk = OtaUpdater.download(update, expectedHash, config, percent -> {
if (listener != null) main.post(() -> listener.onProgress(percent)); if (listener != null) main.post(() -> listener.onProgress(percent));
}); });
if (apk == null) return "Download or SHA-256 verification failed (" if (apk == null) return "Download or SHA-256 verification failed ("
+ update.versionName + ")"; + update.versionName + "): " + OtaUpdater.downloadProblem;
switch (OtaUpdater.install(app, apk)) { switch (OtaUpdater.install(app, apk)) {
case SESSION_STARTED: case SESSION_STARTED:
@@ -0,0 +1,92 @@
package com.evsuite.abrp;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
/**
* What an update check writes down about the connection before and after it fails: the networks
* Android sees, whether the server's name can be looked up, and whether the internet answers at
* all, which tells a SIM without data from a server that is down. Blocking: background thread.
* Never logs the server's address or anything about the car. — UNSTABLE BUILDS ONLY.
*/
final class UpdateNetworkCheck {
/** Android's own connectivity test, as Android itself uses it; no data about the car is sent. */
private static final String INTERNET_TEST = "https://www.gstatic.com/generate_204";
private static final int TIMEOUT_MS = 10_000;
private UpdateNetworkCheck() {}
/** One line per network, or one saying there is none. */
static List<String> networks(Context app) {
List<String> out = new ArrayList<>();
try {
ConnectivityManager cm = (ConnectivityManager) app.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm == null) {
out.add("Network: no connectivity service");
return out;
}
Network active = cm.getActiveNetwork();
if (active == null) out.add("Network: none in use");
for (Network network : cm.getAllNetworks()) {
NetworkCapabilities caps = cm.getNetworkCapabilities(network);
if (caps == null) continue;
NetworkInfo info = cm.getNetworkInfo(network);
out.add("Network: " + UpdateDiagnosis.network(transports(caps),
caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET),
caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED),
network.equals(active), info != null && info.isRoaming()));
}
} catch (RuntimeException e) {
out.add("Network: unreadable (" + e.getClass().getSimpleName() + ")");
}
return out;
}
private static List<String> transports(NetworkCapabilities caps) {
List<String> out = new ArrayList<>();
if (caps.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) out.add("cellular");
if (caps.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) out.add("Wi-Fi");
if (caps.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) out.add("ethernet");
if (caps.hasTransport(NetworkCapabilities.TRANSPORT_BLUETOOTH)) out.add("Bluetooth");
if (caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) out.add("VPN");
return out;
}
/** Whether the host's name resolves, without saying the name. */
static String lookup(String host) {
long started = System.currentTimeMillis();
try {
InetAddress.getByName(host);
return "Server's name: found in " + (System.currentTimeMillis() - started) + " ms";
} catch (IOException | RuntimeException e) {
return "Server's name: " + UpdateDiagnosis.failure(e);
}
}
/** Whether the world outside the car server answers. */
static String internet() {
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) new URL(INTERNET_TEST).openConnection();
conn.setInstanceFollowRedirects(false);
conn.setConnectTimeout(TIMEOUT_MS);
conn.setReadTimeout(TIMEOUT_MS);
return "Internet test: " + UpdateDiagnosis.internet(conn.getResponseCode());
} catch (IOException | RuntimeException e) {
return "Internet test: " + UpdateDiagnosis.failure(e);
} finally {
if (conn != null) conn.disconnect();
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 249 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 KiB