Skip to content

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

Open
ibrahim-iqbal wants to merge 1 commit into
parawanderer:mainfrom
ibrahim-iqbal:228-battery-icon-on-tag-card
Open

ibrahim-iqbal wants to merge 1 commit into
parawanderer:mainfrom
ibrahim-iqbal:228-battery-icon-on-tag-card

Conversation

@ibrahim-iqbal

Copy link
Copy Markdown

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.

@parawanderer parawanderer self-assigned this Nov 6, 2026

This branch has not been deployed

No deployments
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