Skip to content

Show the tag card battery as an icon instead of a word - #283

Merged
parawanderer merged 2 commits into
parawanderer:mainfrom
ibrahim-iqbal:228-battery-icon-on-tag-card
Nov 17, 2026
Merged

parawanderer merged 2 commits into
parawanderer:mainfrom
ibrahim-iqbal:228-battery-icon-on-tag-card

Conversation

@ibrahim-iqbal

Copy link
Copy Markdown
Contributor

Closes #228.

The map tag card's nearby line no longer spells out the battery. "Nearby (●●●○○) · Battery medium" is now "Nearby (●●●○○)" followed by a battery icon.

What changed

  • Icons: four Material Symbols vectors, exported as-is from google/material-design-icons and in the same format as history_24px.xml (viewportWidth="960", ?attr/colorControlNormal tint). I used the horizontal battery_android_* set so the icon sits on a 12sp text line. No new dependency.

    Level Icon
    FULL battery_android_full
    MEDIUM battery_android_3
    LOW battery_android_1
    VERY_LOW battery_android_alert
  • NearbyTagLabel.batteryIcon(level): picks the drawable, next to shortBatteryLabel, so the choice is covered by the JVM test.

  • ui/maps/NearbyBatteryIcon.show(icon, level): sets the drawable, the content description and the visibility. A null level (Google trackers) hides the icon. It is a separate class so the layout test can drive it without MapsActivity.

  • maps_tag_card.xml: adds device_nearby_battery, a 16dp ImageView tinted ?attr/colorOutline like the text next to it. device_last_update is now wrap_content instead of a weighted 0dp, so the icon follows the text rather than sitting at the far end of the row.

  • MapsActivity: the nearby line always uses nearby_now_with_signal and calls NearbyBatteryIcon.show. The timestamp branch hides the icon along with the pulse.

  • Strings:

    • New battery_icon_description ("Battery %1$s"), used as the icon's content description. A screen reader still hears "Battery medium". Each translation reuses the wording already in that locale's battery line.
    • nearby_now_with_battery_and_signal had no other user, so I removed it with add_strings.py --remove.
    • --check passes.

I left the Device Info screen alone. It still shows the battery word, which seemed right for a diagnostics view.

Screenshots

Before and after, in dark and light, rendered by the new test:

full
medium
low
critical

Tests

TagCardBatteryIconTest (new, instrumented) inflates the real card in the light and dark app themes:

  • every level shows an icon with a drawable and a content description ("Battery " + the level word), with the English "Battery medium" checked literally
  • every level draws visible pixels in both themes, and no two levels draw the same image
  • a sighting with no battery level hides the icon
  • the icon measures 16dp × 16dp, and the card is no taller than the plain "Last Updated" card
  • the tint clears 3:1 against the card background:
    • light: #6F797A on #F5FAFB = 4.25:1
    • dark: #899294 on #0E1415 = 5.85:1
  • it writes the screenshots above

Other test changes:

  • NearbyTagLabelTest: each level gets its own icon, and critical gets the alert glyph.
  • TagCardLayoutTest.theLongestNearbyStatusLineDoesNotMakeItsCardTaller: now checks the new line (five dots plus the icon) instead of the old "· Battery critical" text.

I also checked that the tests can fail. I made MEDIUM reuse the full icon and dropped the content description. That turned exactly four tests red: batteryIconGivesEveryLevelItsOwnIcon, everyLevelShowsAnIconAndKeepsTheWordForScreenReaders, everyLevelDrawsADifferentVisibleIconInBothThemes and theMediumIconIsReadAsBatteryMedium. Putting the code back turned them green again.

What I ran, and what I did not

  • Ran:
    • ./gradlew testAll
    • python scripts/add_strings.py --check
    • ./gradlew :app:testEmulatorDebugAndroidTest on the managed aosp-atd device, filtered to TagCardBatteryIconTest and TagCardLayoutTest: 28 tests, 0 failures
  • Not run locally: the full 580-test emulator suite. CI runs it on this PR.
  • Not checked: I have not seen it on a phone with a real tag nearby. The screenshots come from the inflated card, not from a live sighting.

The icon asked for colorOutline through app:tint, which only AppCompat's
inflater reads. A plain LayoutInflater ignored it, so the icon kept the
vector's own colorControlNormal: darker than the text in light mode,
lighter in dark. Use android:tint instead.

The contrast test resolved colorOutline from the theme and never looked at
what the view painted, which is why it stayed green. Add a test that samples
the rendered pixels. It fails on the previous layout (#44474F rendered
where #6F797A is expected) and passes with this change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@parawanderer

Copy link
Copy Markdown
Owner

Thanks again for the contribution, @ibrahim-iqbal. I pushed one commit to this branch that changes the icon colour to match the rest of the text.

The icon was rendering in colorControlNormal instead of colorOutline: app:tint is only read by AppCompat's inflater, so the plain LayoutInflater in the test left the vector's own tint (#44474F in light, #C4C6D0 in dark, against #6F797A and #899294 for the text). I switched it to android:tint and added theIconIsPaintedInTheColourOfTheTextBesideIt, which samples the rendered pixels and fails on the previous layout. The screenshots in the description still show the old colour.

Interactively co-authored by Claude Code and @parawanderer

@parawanderer
parawanderer merged commit 81fa906 into parawanderer:main Nov 17, 2026
4 checks passed

This branch was previously deployed

1 inactive deployment
Android Build — 944c912a Deployed Nov 17, 2026 by parawanderer via Instrumented tests (emulator) #351
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show the tag card's battery as an icon instead of the word "medium"

2 participants