Files
LLeMbas-Android/scripts/gen-icons.py
T
HomerandClaude Opus 5.5 4f09bc41bb
CI / check (push) Canceled after 0s
LLeMbas for Android 0.1.0 (alpha, unreleased): the first commit
A native client for a LLeMbas instance on the server's /api/v2, and the
phone's digital assistant.

- Sign in by device code; the token sealed in the Android Keystore; several
  instances.
- Chats and agent chats: the list, a chat with its reply streaming as JSON
  server-sent events (reconnecting, whole blocks), thinking, tool calls,
  steered messages, the plan, jobs, stop, edit, regenerate, continue, the
  model, effort and Plan mode, attachments and dictation.
- Cards in a sheet, answered as the page's form says it; first answer wins.
- Notifications through UnifiedPush, no Google services; an approval can be
  answered from its notification.
- The digital assistant: a VoiceInteractionService with its session (a sheet
  over the current app, "Include screen" off by default), a recognition
  service through the instance's speech-to-text, the lock-screen path that
  asks to unlock before sending, a Quick Settings tile and an Ask shortcut.
- Share to LLeMbas; Moria and Shire from the server's tokens; nine
  languages; a self-updater in the `full` flavour, none in `fdroid`.

Generated and pinned from the server, each checked in CI: the theme
(tokens.lock.json), the contract (contract/lock.json, server 2124ba9), the
strings and the icons. Built and tested only on GitHub Actions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 13:44:30 +00:00

82 lines
3.3 KiB
Python
Executable File

#!/usr/bin/env python3
"""The app's icons, from the server's pixel leaf (`web/static/img/logo-mark.svg`).
scripts/gen-icons.py [<server-ref>] (default HEAD of ../LLeMbas, or LEMBAS_SERVER)
The mark is a 16x16 grid of rects, so it converts exactly into Android vector drawables -- one
path per colour -- and needs no PNG at any density:
drawable/ic_launcher_foreground.xml the leaf, in the adaptive icon's 66dp safe zone
drawable/ic_launcher_monochrome.xml its silhouette, for themed icons
drawable/ic_notification.xml the same silhouette: a status-bar icon is alpha only
"""
from __future__ import annotations
import os
import re
import subprocess
import sys
from collections import defaultdict
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
SERVER = Path(os.environ.get("LEMBAS_SERVER", ROOT.parent / "LLeMbas"))
SOURCE = "src/lembas/web/static/img/logo-mark.svg"
RES = ROOT / "app/src/main/res/drawable"
HEADER = "<!-- Generated by scripts/gen-icons.py from the LLeMbas server's logo-mark.svg. Do not edit. -->"
def rects(svg: str) -> list[tuple[int, int, int, int, str]]:
found = []
for attrs in re.findall(r"<rect\s+([^>]*)/>", svg):
a = dict(re.findall(r'(\w+)="([^"]*)"', attrs))
found.append((int(a["x"]), int(a["y"]), int(a["width"]), int(a["height"]), a["fill"].upper()))
if not found:
sys.exit("gen-icons: no rects in the mark")
return found
def path(cells) -> str:
return " ".join(f"M{x},{y}h{w}v{h}h-{w}z" for x, y, w, h, _ in cells)
def vector(size: int, viewport: int, body: str) -> str:
return (
f'<?xml version="1.0" encoding="utf-8"?>\n{HEADER}\n'
'<vector xmlns:android="http://schemas.android.com/apk/res/android"\n'
f' android:width="{size}dp" android:height="{size}dp"\n'
f' android:viewportWidth="{viewport}" android:viewportHeight="{viewport}">\n'
f"{body}</vector>\n"
)
def main() -> None:
ref = sys.argv[1] if len(sys.argv) > 1 else "HEAD"
svg = subprocess.run(
["git", "-C", str(SERVER), "show", f"{ref}:{SOURCE}"], capture_output=True, text=True, check=True
).stdout
cells = rects(svg)
by_colour: dict[str, list] = defaultdict(list)
for cell in cells:
by_colour[cell[4]].append(cell)
# 108dp adaptive canvas; the leaf scaled x3.5 (56dp) and centred, inside the 66dp safe zone.
coloured = "".join(
f' <path android:fillColor="{colour}" android:pathData="{path(group)}"/>\n'
for colour, group in sorted(by_colour.items())
)
group = f' <group android:translateX="26" android:translateY="26" android:scaleX="3.5" android:scaleY="3.5">\n{coloured} </group>\n'
silhouette = f' <path android:fillColor="#FFFFFFFF" android:pathData="{path(cells)}"/>\n'
mono = f' <group android:translateX="26" android:translateY="26" android:scaleX="3.5" android:scaleY="3.5">\n{silhouette} </group>\n'
RES.mkdir(parents=True, exist_ok=True)
(RES / "ic_launcher_foreground.xml").write_text(vector(108, 108, group))
(RES / "ic_launcher_monochrome.xml").write_text(vector(108, 108, mono))
(RES / "ic_notification.xml").write_text(vector(24, 16, silhouette.replace(" ", " ")))
print(f"gen-icons: {len(cells)} cells in {len(by_colour)} colours, from {ref}")
if __name__ == "__main__":
main()