# -*- coding: utf-8 -*- r'''快捷栏:按钮做大 + **4 格全部可自定义**。 == 用户这次的反馈(原话)== "屏幕最上面这个按钮有些按不到,按钮太小了,做大一点, 然后呢,这个每每个四格算换一下吧,第一个第二个第三个第四个都能换东西" == 两个改动 == 1. **按钮做大**:30dp -> 46dp,字号 11 -> 14。 30dp 在手表上确实太小了 —— 表盘本来就小,手指按上去一半在栏外。 46dp 接近 Android 建议的最小可点区域(48dp)。 ⚠ 栏高和面板 topMargin 必须**用同一个常量**。分开写的话 改一个忘一个,表现是"内容要么被栏盖住,要么上面空一条"。 2. **第 4 格也变成可自定义**。 用户最早说"其中有一个按钮不能改,功能就是一键返回桌面", 现在改主意了:"第一个第二个第三个第四个都能换东西"。 所以「显示桌面」从"固定的那一格"变成**普通可选动作**, 而且默认就放在第 4 格 —— 这样默认行为跟以前一样 (最后一个还是显示桌面),但用户想换也能换。 实现上就是把 QUICK_CUSTOM_SLOTS 从 3 改成 4, 再把 {"desktop","显示桌面"} 加进 QUICK_ACTIONS, 然后去掉所有"第 4 格特殊"的分支。 ''' from __future__ import annotations import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent MAIN = ROOT / "android" / "src" / "com" / "lanremote" / "watch" / "MainActivity.java" PAIRS = [ # ---- 1. 格子数 3 -> 4 ---- (' private static final int QUICK_CUSTOM_SLOTS = 3; // 固定那个不算在内', ''' /** 快捷栏一共几格。用户最初要求"最多 4 个", * 后来又改成"第一二三四格都能换东西",所以 4 格都可自定义。 */ private static final int QUICK_SLOTS = 4; /** 快捷栏高度(dp)。46 接近 Android 建议的最小可点区域 48。 * ⚠ 面板的 topMargin 也用这个值 —— 分两处写的话改一个忘一个, * 表现是"内容被栏盖住"或"上面空一条"。 */ private static final int QUICK_BAR_DP = 46;'''), # ---- 2. 加 desktop 到可选动作 ---- (''' {"image", "投图到电脑"}, };''', ''' {"image", "投图到电脑"}, // 用户最早说这一格"不能改",后来又改成四格都能换 —— // 所以它现在是**普通可选动作**,只是默认放在第 4 格。 {"desktop", "显示桌面"}, };'''), # ---- 3. 默认值 3 -> 4 格 ---- (''' private String[] quickSlots = new String[]{"file", "mirror", "sfx"};''', ''' private String[] quickSlots = new String[]{"file", "mirror", "sfx", "desktop"};'''), # ---- 4. buildQuickBar:格数、高度、字号 ---- (''' for (int i = 0; i < QUICK_CUSTOM_SLOTS + 1; i++) { final int slot = i; Button b = new Button(this); b.setTextSize(11f);''', ''' for (int i = 0; i < QUICK_SLOTS; i++) { final int slot = i; Button b = new Button(this); b.setTextSize(14f); // 11 太小,用户说"按不到"'''), (''' FrameLayout.LayoutParams barLp = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, dp(30));''', ''' FrameLayout.LayoutParams barLp = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, dp(QUICK_BAR_DP));'''), # ---- 5. refreshQuickBar:不再有"固定那一格" ---- (''' boolean connected = isConnected(); for (int i = 0; i < quickButtons.size(); i++) { Button b = quickButtons.get(i); String id = (i < QUICK_CUSTOM_SLOTS) ? quickSlots[i] : "desktop";''', ''' boolean connected = isConnected(); for (int i = 0; i < quickButtons.size(); i++) { Button b = quickButtons.get(i); String id = quickSlots[i];'''), # ---- 6. onQuickClick:不再有"固定那一格" ---- (''' /** 点第 slot 个按钮。0..2 是自定义,3 是那个固定的显示桌面。 */ private void onQuickClick(int slot) { String id = (slot < QUICK_CUSTOM_SLOTS) ? quickSlots[slot] : "desktop"; if (id == null || id.isEmpty()) { return; } runQuickAction(id); }''', ''' /** 点第 slot 个按钮。四格完全平等,都从 quickSlots 里取。 */ private void onQuickClick(int slot) { if (slot < 0 || slot >= quickSlots.length) { return; } String id = quickSlots[slot]; if (id == null || id.isEmpty()) { return; } runQuickAction(id); }'''), # ---- 7. loadQuickSlots:4 格 + 允许 desktop ---- (''' String[] want = (raw == null || raw.isEmpty()) ? new String[]{"file", "mirror", "sfx"} : raw.split(",", -1);''', ''' String[] want = (raw == null || raw.isEmpty()) ? new String[]{"file", "mirror", "sfx", "desktop"} : raw.split(",", -1);'''), (''' String[] out = new String[QUICK_CUSTOM_SLOTS]; int n = 0; for (String id : want) { if (n >= QUICK_CUSTOM_SLOTS) { break; } if (id != null && !id.isEmpty() && !"desktop".equals(id) && isKnownQuickAction(id)) { out[n++] = id; } } String[] fallback = {"file", "mirror", "sfx"}; for (int i = 0; i < QUICK_CUSTOM_SLOTS; i++) {''', ''' String[] out = new String[QUICK_SLOTS]; int n = 0; for (String id : want) { if (n >= QUICK_SLOTS) { break; } // ⚠ 这里**不再排除 desktop** —— 用户改成四格都能换了 if (id != null && !id.isEmpty() && isKnownQuickAction(id)) { out[n++] = id; } } String[] fallback = {"file", "mirror", "sfx", "desktop"}; for (int i = 0; i < QUICK_SLOTS; i++) {'''), # ---- 8. applyPanelTopMargin:用同一个常量 ---- (''' flp.topMargin = dp(30); // 跟 quickBar 的高度一致''', ''' // 用同一个常量 —— 栏高改了这里自动跟着改 flp.topMargin = dp(QUICK_BAR_DP);'''), # ---- 9. onCreate 里 addView 的高度 ---- (''' root.addView(quickBar, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, dp(30)));''', ''' root.addView(quickBar, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, dp(QUICK_BAR_DP)));'''), # ---- 10. 设置页:4 格 + 去掉"固定改不了"的说法 ---- (''' settingsExtraBox.addView(hintText("顶部那条栏,最多 4 个按钮。" + "最后一个「显示桌面」是固定的、改不了;" + "前三个点下面自己选。(还没连上电脑时它们是灰的)")); for (int slot = 0; slot < QUICK_CUSTOM_SLOTS; slot++) {''', ''' settingsExtraBox.addView(hintText("顶部那条栏,4 个格子" + "**每一个都能换**,点下面自己选。" + "(还没连上电脑时它们是灰的)")); for (int slot = 0; slot < QUICK_SLOTS; slot++) {'''), (''' settingsExtraBox.addView(smallButton( "恢复默认(传文件 / 屏幕镜像 / 音效)", C_CARD, new Runnable() { public void run() { quickSlots = new String[]{"file", "mirror", "sfx"};''', ''' settingsExtraBox.addView(smallButton( "恢复默认(传文件 / 屏幕镜像 / 音效 / 显示桌面)", C_CARD, new Runnable() { public void run() { quickSlots = new String[]{"file", "mirror", "sfx", "desktop"};'''), # ---- 11. 设置页标题也说明 4 格都能换 ---- (''' private void pickQuickSlot(final int slot) { final java.util.List labels = new java.util.ArrayList(); final java.util.List ids = new java.util.ArrayList(); labels.add("留空(这一格不显示)");''', ''' private void pickQuickSlot(final int slot) { final java.util.List labels = new java.util.ArrayList(); final java.util.List ids = new java.util.ArrayList(); labels.add("留空(这一格不显示)");'''), ] def main() -> int: print("=" * 58) print(" 快捷栏:按钮做大 + 4 格全部可自定义") print("=" * 58) print() raw = MAIN.read_bytes() bom = raw.startswith(b"\xef\xbb\xbf") t = raw.decode("utf-8-sig") if "QUICK_SLOTS = 4" in t: print(" 已经改过了") return 0 # 先全部校验,避免改一半 missing = [] for i, (old, _new) in enumerate(PAIRS, 1): if old not in t: missing.append((i, old.strip().splitlines()[0][:66])) if missing: print(" ✗ 这些锚点找不到:") for i, s in missing: print(" #%d %s" % (i, s)) return 1 print(" ✓ %d 个锚点全部就位" % len(PAIRS)) for i, (old, new) in enumerate(PAIRS, 1): t = t.replace(old, new, 1) # 收尾:把残留的 QUICK_CUSTOM_SLOTS 全换掉(应该已经没有了) left = t.count("QUICK_CUSTOM_SLOTS") if left: print(" ⚠ 还有 %d 处 QUICK_CUSTOM_SLOTS 残留,一并替换" % left) t = t.replace("QUICK_CUSTOM_SLOTS", "QUICK_SLOTS") MAIN.write_bytes((b"\xef\xbb\xbf" if bom else b"") + t.encode("utf-8")) print(" ✓ 改完了") return 0 if __name__ == "__main__": sys.exit(main())