Files
EasyDesignCollection/tools/gen-android-icons.py
T
admin fad82a30d8 feat(android): 平板版适配(1280×800dp,免授权,应用商店分发)
- flutter create 增加 android 平台:包名 cc.sincos.sequence_diagram,应用名「时序图设计器」,minSdk 24 / targetSdk 36

- 多分辨率动态兼容:触屏侧栏默认贴边把手(点把手直接停靠),面板宽度随屏宽压缩,窄屏双侧栏停靠不溢出

- 免授权:LicenseService 非 Windows 平台直接判定已授权

- 移动端存储/文件浏览器适配(无 APPDATA/盘符/桌面);edge-to-edge + SafeArea + 文本缩放固定 1.0

- launcher 图标沿用「环序」标志(tools/gen-android-icons.py);Gradle 腾讯镜像 + Maven 阿里镜像

- 自测:7 种分辨率无溢出回归(test/tablet_layout_test.dart)+ 平板截图(demo/tablet-*.png)

- 产物:release/sequence_diagram_tablet_v1.0.1_release.apk(universal,50.3MB)
2026-10-06 21:04:38 +08:00

114 lines
3.6 KiB
Python

#!/usr/bin/env python3
"""Generate Android launcher icons from the original "Cycle-Step" mark.
Renders the same geometry as tools/gen-icon.py (gapped ring + step polyline
+ origin/terminal dots), full-bleed (no transparent inset) so the tile fills
the icon, at every Android launcher density.
Outputs:
android/app/src/main/res/mipmap-*/ic_launcher.png
"""
import math
import os
from PIL import Image, ImageDraw
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
RES = os.path.join(ROOT, "android", "app", "src", "main", "res")
TILE_TOP = (24, 33, 61, 255) # #18213D
TILE_BOT = (12, 18, 38, 255) # #0C1226
EDGE = (255, 255, 255, 38)
RING = (76, 201, 240, 255) # #4CC9F0
STEP = (255, 209, 102, 255) # #FFD166
ORIGIN = (255, 255, 255, 255)
END = (52, 211, 153, 255) # #34D399
DENSITIES = {
"mdpi": 48,
"hdpi": 72,
"xhdpi": 96,
"xxhdpi": 144,
"xxxhdpi": 192,
}
def lerp(a, b, t):
return tuple(round(a[i] + (b[i] - a[i]) * t) for i in range(4))
def polar(cx, cy, r, deg):
t = math.radians(deg - 90)
return (cx + r * math.cos(t), cy + r * math.sin(t))
def draw_ring(img, cx, cy, r_ring, ring_w, gap_deg, color, s):
outer = r_ring + ring_w / 2
inner = r_ring - ring_w / 2
mask = Image.new("L", (s, s), 0)
md = ImageDraw.Draw(mask)
md.ellipse([cx - outer, cy - outer, cx + outer, cy + outer], fill=255)
md.ellipse([cx - inner, cy - inner, cx + inner, cy + inner], fill=0)
a0 = polar(cx, cy, outer + 8, -90 - gap_deg / 2)
a1 = polar(cx, cy, outer + 8, -90 + gap_deg / 2)
md.polygon([(cx, cy), a0, a1], fill=0)
for deg in (-90 + gap_deg / 2, -90 - gap_deg / 2):
p = polar(cx, cy, r_ring, deg)
md.ellipse([p[0] - ring_w / 2, p[1] - ring_w / 2,
p[0] + ring_w / 2, p[1] + ring_w / 2], fill=255)
img.paste(color, (0, 0), mask)
def draw_steps(img, pts, width, color):
d = ImageDraw.Draw(img)
d.line(pts, fill=color, width=width, joint="curve")
for p in pts:
d.ellipse([p[0] - width / 2, p[1] - width / 2,
p[0] + width / 2, p[1] + width / 2], fill=color)
def build(s):
img = Image.new("RGBA", (s, s), (0, 0, 0, 0))
body = Image.new("RGBA", (s, s), (0, 0, 0, 0))
bd = ImageDraw.Draw(body)
for y in range(s):
bd.line([(0, y), (s, y)], fill=lerp(TILE_TOP, TILE_BOT, y / (s - 1)))
mask = Image.new("L", (s, s), 0)
ImageDraw.Draw(mask).rounded_rectangle([0, 0, s - 1, s - 1], radius=int(0.27 * s), fill=255)
img.paste(body, (0, 0), mask)
ImageDraw.Draw(img).rounded_rectangle([0, 0, s - 1, s - 1], radius=int(0.27 * s), outline=EDGE, width=max(1, s // 200))
cx = cy = s / 2.0
r_ring = 0.293 * s
ring_w = (0.075 if s <= 48 else 0.062) * s
draw_ring(img, cx, cy, r_ring, ring_w, 68, RING, s)
d = ImageDraw.Draw(img)
od = 0.045 * s
op = (cx, cy - r_ring)
d.ellipse([op[0] - od, op[1] - od, op[0] + od, op[1] + od], fill=ORIGIN)
sw = (0.075 if s <= 48 else 0.057) * s
p1 = (cx - 0.146 * s, cy + 0.088 * s)
p2 = (cx - 0.010 * s, cy + 0.088 * s)
p3 = (cx - 0.010 * s, cy - 0.059 * s)
p4 = (cx + 0.166 * s, cy - 0.059 * s)
draw_steps(img, [p1, p2, p3, p4], int(sw), STEP)
ed = (0.050 if s <= 48 else 0.037) * s
d.ellipse([p4[0] - ed, p4[1] - ed, p4[0] + ed, p4[1] + ed], fill=END)
return img
def main():
for density, size in DENSITIES.items():
out_dir = os.path.join(RES, "mipmap-%s" % density)
os.makedirs(out_dir, exist_ok=True)
out = os.path.join(out_dir, "ic_launcher.png")
build(size).save(out)
print("wrote", out)
if __name__ == "__main__":
main()