Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cdf78c6d32 | ||
|
|
a445fef407 | ||
|
|
f9813c2afd | ||
|
|
3a532cd498 | ||
|
|
06a61282a6 | ||
|
|
ed32fbbc1f | ||
|
|
91283093f5 | ||
|
|
bdb3f5e765 |
@@ -77,7 +77,7 @@ Repository: `ssh://git@git.stinnesbeck.com:2222/nils/mg4.git` (remote `origin`),
|
||||
|
||||
| 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 flaring on the kick drum while on screen, when "Pumpkin 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; 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, Día de Muertos and Halloween, 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), both counting with `Tally`, the pumpkin's light flaring on the kick drum while on screen, when "Pumpkin 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; 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 |
|
||||
| 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 |
|
||||
|
||||
@@ -89,7 +89,7 @@ with the server using a token of its own, obtained by pairing with a phone (belo
|
||||
|
||||
| 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 |
|
||||
| **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 |
|
||||
|
||||
@@ -140,6 +140,14 @@ 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
|
||||
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).
|
||||
- 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.
|
||||
|
||||
@@ -42,7 +42,9 @@ colours, and Sci-fi, Cartoon, Nixie tubes, Time circuits, Quest, Empire, Día de
|
||||
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
|
||||
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).
|
||||
|
||||

|
||||

|
||||
@@ -247,7 +249,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
|
||||
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
|
||||
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.
|
||||
|
||||

|
||||

|
||||
@@ -264,7 +269,10 @@ usage, climate and odometer, and the hill along the bottom is the last two minut
|
||||
you drive the bats fly, the potion bubbles and the ghost floats (where there is room for it, as on
|
||||
this screen). With "Pumpkin light follows the music" on (Settings, shown with this style; off by
|
||||
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. The app turns the
|
||||
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.
|
||||
|
||||

|
||||
|
||||
+2
-2
@@ -34,8 +34,8 @@ android {
|
||||
applicationId "com.stinnesbeck.nilsmg4"
|
||||
minSdk 27
|
||||
targetSdk 36
|
||||
versionCode 159
|
||||
versionName "2.44.0"
|
||||
versionCode 163
|
||||
versionName "2.46.0"
|
||||
|
||||
// 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.
|
||||
|
||||
@@ -23,4 +23,6 @@ final class ClusterValues {
|
||||
String tyreFl = "—", tyreFr = "—", tyreRl = "—", tyreRr = "—";
|
||||
/** Battery power over the last two minutes, oldest first, NaN where unread; null before any. */
|
||||
float[] powerTrail;
|
||||
/** What plays ({@link NowPlaying}): the title, null when nothing does or it is off, and the artist or null. */
|
||||
String songTitle, songArtist;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.Locale;
|
||||
* 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
|
||||
* 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 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 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);
|
||||
@@ -96,6 +97,7 @@ final class HalloweenView extends ClusterCanvasView {
|
||||
if (sky == null || skyW != w || skyH != h) buildSky(w, h, u);
|
||||
c.drawBitmap(sky, 0, 0, image);
|
||||
drawBats(c, w, u);
|
||||
boolean song = drawSong(c, w, u);
|
||||
drawMoon(c, w, u);
|
||||
drawGhost(c, w, u);
|
||||
drawHill(c, w, h, u);
|
||||
@@ -106,7 +108,7 @@ final class HalloweenView extends ClusterCanvasView {
|
||||
drawFlask(c, u);
|
||||
drawTombstone(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) {
|
||||
@@ -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 ----------
|
||||
|
||||
private void drawEmbers(Canvas c, int w, float u) {
|
||||
|
||||
@@ -78,6 +78,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
/** The pane of each Overview style, by its {@link OverviewStyle} ordinal. */
|
||||
private View[] stylePanes;
|
||||
private MusicTap musicTap;
|
||||
private NowPlayingWatcher nowPlaying;
|
||||
private View consumptionPane;
|
||||
private View chargingPane;
|
||||
/** Display, battery, charging price and Wi-Fi. */
|
||||
@@ -197,6 +198,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
markCurrentPage(position);
|
||||
applyOverviewFullScreen(position);
|
||||
updateMusicTap();
|
||||
updateNowPlaying();
|
||||
}
|
||||
});
|
||||
findViewById(R.id.edge_tab).setOnClickListener(v -> leaveOverviewFullScreen());
|
||||
@@ -215,6 +217,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
/** Whether the Overview hides the navigation (the button in the navigation's header). */
|
||||
static final String PREF_OVERVIEW_FULLSCREEN = "overview_fullscreen";
|
||||
/** The Overview shows what plays (Tiles, Halloween); on by default. */
|
||||
static final String PREF_NOW_PLAYING = "now_playing";
|
||||
/** The Halloween pumpkin's light follows the music; off by default, so the analyser stays off. */
|
||||
static final String PREF_MUSIC_LIGHT = "music_light";
|
||||
|
||||
@@ -359,6 +363,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
visorView = new VisorView(this);
|
||||
HalloweenView halloweenView = new HalloweenView(this);
|
||||
musicTap = new MusicTap(this);
|
||||
nowPlaying = new NowPlayingWatcher(this);
|
||||
halloweenView.setMusic(musicTap);
|
||||
java.util.Collections.addAll(canvasStyles, new MinimalView(this), terminalView,
|
||||
new NixieView(this), new ChronographView(this), gridView, gridMapView, new TimeCircuitsView(this),
|
||||
@@ -514,6 +519,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
inFront = true;
|
||||
updateMapLocation();
|
||||
updateMusicTap();
|
||||
updateNowPlaying();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -564,6 +570,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
inFront = false;
|
||||
updateMapLocation();
|
||||
updateMusicTap();
|
||||
updateNowPlaying();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1225,6 +1232,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
bindDriveMode();
|
||||
bindOverviewStyle();
|
||||
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) -> {
|
||||
@@ -1767,6 +1780,58 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (settingsPane != null) bindAccentColor();
|
||||
updateMapLocation();
|
||||
updateMusicTap();
|
||||
updateNowPlaying();
|
||||
}
|
||||
|
||||
/** The styles that show what plays. */
|
||||
private static boolean showsNowPlaying(OverviewStyle style) {
|
||||
return style == OverviewStyle.TILES || style == OverviewStyle.HALLOWEEN
|
||||
|| style == OverviewStyle.MUERTOS;
|
||||
}
|
||||
|
||||
/** 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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1840,6 +1905,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
TextView note = settingsPane.findViewById(R.id.accent_note);
|
||||
note.setVisibility(style.usesAccent ? View.GONE : View.VISIBLE);
|
||||
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 = style == OverviewStyle.HALLOWEEN ? View.VISIBLE : View.GONE;
|
||||
settingsPane.findViewById(R.id.music_light_switch).setVisibility(music);
|
||||
settingsPane.findViewById(R.id.music_light_hint).setVisibility(music);
|
||||
@@ -1925,6 +1993,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
v.tyreRl = unit.format(s.getTirePressures().getRearLeftKpa());
|
||||
v.tyreRr = unit.format(s.getTirePressures().getRearRightKpa());
|
||||
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);
|
||||
flowView.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 Path path = new Path();
|
||||
private final Path flag = 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);
|
||||
@@ -87,6 +88,7 @@ final class MuertosView extends ClusterCanvasView {
|
||||
c.drawBitmap(scene, 0, 0, image);
|
||||
float cx = w / 2f, cy = 345f * u;
|
||||
drawFlags(c, w, u);
|
||||
boolean song = drawSong(c, w, u);
|
||||
drawRing(c, cx, cy, u);
|
||||
drawSpeed(c, cx, cy, u);
|
||||
drawBattery(c, u);
|
||||
@@ -95,7 +97,7 @@ final class MuertosView extends ClusterCanvasView {
|
||||
drawClock(c, w, u);
|
||||
drawGears(c, w, 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) {
|
||||
@@ -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) {
|
||||
boolean low = v.socPercent != null && v.socPercent < 20f;
|
||||
float x = 36f * u;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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() + "…";
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,9 @@
|
||||
</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" />
|
||||
<!-- Only the styles that show what plays (Tiles, Halloween). -->
|
||||
<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 listens 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" />
|
||||
|
||||
@@ -31,7 +31,18 @@
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<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">
|
||||
<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" />
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
<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>
|
||||
<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 (Tiles, Halloween). -->
|
||||
<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 listens 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" />
|
||||
|
||||
@@ -129,6 +129,13 @@
|
||||
<string name="overview_style_scifi">Sci-fi</string>
|
||||
<string name="overview_style_cartoon">Cartoon</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">Pumpkin 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>
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user