Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.
Python adbadblockandroid-tvandroid-tv-launcherapple-tvbloatware-removalclaude-codedebloatfire-tvgoogle-tvlauncherprivacysmart-tvsony-braviatclvibe-codingxiaomi
Launcher: wallpaper_captions shows the rotating picture's name
Luiz Fernandof8dba9f1cb89
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Config.java b/launcher/app/src/main/java/com/gathin/tvhome/Config.javaindex b55b5a100..e69cd02c7 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java@@ -128,6 +128,8 @@ final class Config {final boolean ambientGlow;/** Minutes Home may sit untouched before the clock screensaver (config.xml, home_idle_clock_minutes); 0 is off. */final int homeIdleClockMinutes;+ /** Show each rotating wallpaper's name from wallpapers/captions.txt (config.xml / theme wallpaper_captions). */+ final boolean wallpaperCaptions;private Config(List<String> dockApps, boolean fillDock, List<String> hiddenApps, String liveTvPackage,String liveTvAction, Map<String, String> launchActions, Map<String, String> appLabels,@@ -138,7 +140,8 @@ final class Config {int[] settingsKeycodes, boolean settingsKeyPanel, boolean wallpaperEnabled, File wallpaper, List<File> wallpapers,int wallpaperRotationMinutes, int wallpaperDim, String wallpaperOrder, boolean overlayApplied,Festival festival, int[] inputKeycodes, List<String> appKeys,- List<RaceWeekend.Race> raceCalendar, boolean cinematicHome, boolean ambientGlow, int homeIdleClockMinutes) {+ List<RaceWeekend.Race> raceCalendar, boolean cinematicHome, boolean ambientGlow, int homeIdleClockMinutes,+ boolean wallpaperCaptions) {this.inputKeycodes = inputKeycodes;this.appKeys = Collections.unmodifiableList(appKeys);this.dockApps = Collections.unmodifiableList(dockApps);@@ -189,6 +192,7 @@ final class Config {this.cinematicHome = cinematicHome;this.ambientGlow = ambientGlow;this.homeIdleClockMinutes = homeIdleClockMinutes;+ this.wallpaperCaptions = wallpaperCaptions;}/** The folder the theme tools push into; null when external storage is unavailable. */@@ -226,6 +230,7 @@ final class Config {int wifiLabelWidth = res.getInteger(R.integer.wifi_label_width);boolean alwaysShowNames = res.getBoolean(R.bool.always_show_names);boolean wallpaperTrueColor = res.getBoolean(R.bool.wallpaper_true_color);+ boolean wallpaperCaptions = res.getBoolean(R.bool.wallpaper_captions);String vpn = res.getString(R.string.vpn_app).trim();boolean homeSettings = res.getBoolean(R.bool.show_home_settings_shortcut);boolean showStats = res.getBoolean(R.bool.show_stats);@@ -275,6 +280,7 @@ final class Config {wifiLabelWidth = integer(json, "wifi_label_width", wifiLabelWidth, 0, 300);alwaysShowNames = bool(json, "always_show_names", alwaysShowNames);wallpaperTrueColor = bool(json, "wallpaper_true_color", wallpaperTrueColor);+ wallpaperCaptions = bool(json, "wallpaper_captions", wallpaperCaptions);vpn = string(json, "vpn_app", vpn);homeSettings = bool(json, "show_home_settings_shortcut", homeSettings);showStats = bool(json, "show_stats", showStats);@@ -347,7 +353,7 @@ final class Config {Math.max(0, Math.min(100, skyIntensity)), settingsKeycodes, settingsKeyPanel, wallpaperEnabled, wallpaper,wallpapers, rotationMinutes, wallpaperDim, wallpaperOrder, applied,festival, inputKeycodes, appKeys, json == null ? Collections.emptyList() : raceCalendar(json), cinematic, ambientGlow,- Math.max(0, idleClockMinutes));+ Math.max(0, idleClockMinutes), wallpaperCaptions);}/**diff --git a/launcher/app/src/main/java/com/gathin/tvhome/ThemeFiles.java b/launcher/app/src/main/java/com/gathin/tvhome/ThemeFiles.javaindex bf7852597..18fded94d 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/ThemeFiles.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/ThemeFiles.java@@ -20,7 +20,8 @@ final class ThemeFiles {return Config.FILE_NAME.equals(name) || "wallpaper.jpg".equals(name) || "theme_revision".equals(name)? name : null;}- if (segments.size() == 2 && WALLPAPERS.equals(segments.get(0)) && collectionImage(segments.get(1))) {+ if (segments.size() == 2 && WALLPAPERS.equals(segments.get(0))+ && (collectionImage(segments.get(1)) || WallpaperCaptions.FILE_NAME.equals(segments.get(1)))) {return WALLPAPERS + "/" + segments.get(1);}return null;diff --git a/launcher/app/src/main/java/com/gathin/tvhome/WallpaperCaptions.java b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperCaptions.javanew file mode 100644index 000000000..7dedb382a--- /dev/null+++ b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperCaptions.java@@ -0,0 +1,47 @@+package com.gathin.tvhome;++import java.io.File;+import java.nio.charset.StandardCharsets;+import java.nio.file.Files;+import java.util.Collections;+import java.util.HashMap;+import java.util.List;+import java.util.Map;++/**+ * Names for a wallpaper collection (wallpaper_captions): {@code wallpapers/captions.txt}, one+ * "filename<TAB>name" per line. Blank lines, lines starting with # and lines without a tab are skipped; a name+ * is cut to {@link #MAX_LENGTH} characters. No Android types, so it is tested on the JVM.+ */+final class WallpaperCaptions {+ static final String FILE_NAME = "captions.txt";+ static final int MAX_LENGTH = 80;++ private WallpaperCaptions() { }++ static Map<String, String> parse(List<String> lines) {+ Map<String, String> names = new HashMap<>();+ for (String line : lines) {+ if (line == null || line.trim().isEmpty() || line.trim().startsWith("#")) continue;+ int tab = line.indexOf('\t');+ if (tab <= 0) continue;+ String file = line.substring(0, tab).trim();+ String name = line.substring(tab + 1).trim();+ if (file.isEmpty() || name.isEmpty()) continue;+ if (name.length() > MAX_LENGTH) name = name.substring(0, MAX_LENGTH).trim();+ names.put(file, name);+ }+ return names;+ }++ /** The names in {@code folder}/captions.txt, or none when the file is missing or unreadable. */+ static Map<String, String> read(File folder) {+ File file = folder == null ? null : new File(folder, FILE_NAME);+ if (file == null || !file.isFile() || file.length() > 256 * 1024) return Collections.emptyMap();+ try {+ return parse(Files.readAllLines(file.toPath(), StandardCharsets.UTF_8));+ } catch (Exception e) {+ return Collections.emptyMap();+ }+ }+}diff --git a/launcher/app/src/main/java/com/gathin/tvhome/WallpaperPlayer.java b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperPlayer.javaindex f51a14a25..7151ee4f4 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/WallpaperPlayer.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperPlayer.java@@ -4,16 +4,22 @@ import android.content.Context;import android.content.SharedPreferences;import android.graphics.Bitmap;import android.graphics.BitmapFactory;+import android.text.TextUtils;import android.util.DisplayMetrics;import android.util.Log;+import android.util.TypedValue;+import android.view.Gravity;import android.view.View;import android.view.ViewGroup;import android.widget.FrameLayout;import android.widget.ImageView;+import android.widget.TextView;import java.io.File;import java.util.ArrayList;+import java.util.Collections;import java.util.List;+import java.util.Map;import java.util.Random;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;@@ -36,6 +42,9 @@ final class WallpaperPlayer {private boolean closed;private boolean loading;private String displayed = "";+ /** wallpaper_captions: the shown picture's name from wallpapers/captions.txt; null when off or there are none. */+ private final TextView caption;+ private final Map<String, String> names;WallpaperPlayer(Context context, FrameLayout root, Config config) {this.root = root;@@ -57,6 +66,9 @@ final class WallpaperPlayer {image = new ImageView(context);image.setScaleType(ImageView.ScaleType.CENTER_CROP);image.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);+ names = config.wallpaperCaptions && config.wallpaperEnabled && !files.isEmpty()+ ? WallpaperCaptions.read(files.get(0).getParentFile()) : Collections.emptyMap();+ caption = names.isEmpty() ? null : makeCaption(context, root);if (config.wallpaperEnabled && !files.isEmpty()) {root.addView(image, 0, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));@@ -86,6 +98,7 @@ final class WallpaperPlayer {if (bitmap != null) {image.setImageBitmap(bitmap);displayed = first.getName();+ showCaption(false);if (!displayed.equals(previous)) {preferences.edit().putString("image", displayed).putLong("changed", System.currentTimeMillis()).apply();@@ -139,6 +152,7 @@ final class WallpaperPlayer {}image.setImageBitmap(bitmap);displayed = next.getName();+ showCaption(true);if (!displayed.equals(previous) || changed == 0) {preferences.edit().putString("image", displayed).putLong("changed", System.currentTimeMillis()).apply();@@ -147,6 +161,55 @@ final class WallpaperPlayer {});}+ /**+ * Small light text under the top-right buttons, above everything else and never focusable. It sits where the+ * top bar ends in every layout, so it does not cover the clock, the stats line or the tiles.+ */+ private static TextView makeCaption(Context context, FrameLayout root) {+ float dp = context.getResources().getDisplayMetrics().density;+ TextView text = new TextView(context);+ text.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);+ text.setTextColor(0xD9FFFFFF);+ text.setShadowLayer(6 * dp, 0, dp, 0xCC000000);+ text.setSingleLine(true);+ text.setEllipsize(TextUtils.TruncateAt.END);+ text.setMaxWidth(Math.round(520 * dp));+ text.setFocusable(false);+ text.setAlpha(0f);+ try {+ text.setTypeface(context.getResources().getFont(R.font.outfit_regular));+ } catch (Exception ignored) {+ // the system font is fine+ }+ FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,+ ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.TOP | Gravity.END);+ params.topMargin = Math.round(110 * dp);+ params.setMarginEnd(Math.round(62 * dp));+ root.addView(text, params);+ return text;+ }++ /** The displayed picture's name, faded across a change; a picture without a name hides the caption. */+ private void showCaption(boolean fade) {+ if (caption == null) return;+ String name = names.get(displayed);+ caption.animate().cancel();+ if (name == null) {+ caption.setAlpha(0f);+ return;+ }+ caption.setContentDescription(name);+ if (!fade || caption.getAlpha() == 0f) {+ caption.setText(name);+ caption.setAlpha(1f);+ return;+ }+ caption.animate().alpha(0f).setDuration(250).withEndAction(() -> {+ caption.setText(name);+ caption.animate().alpha(1f).setDuration(350).start();+ }).start();+ }+/** Names plus sizes: enough to notice a different collection without hashing every image. */private static String collectionKey(List<File> images) {StringBuilder key = new StringBuilder();diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xmlindex 4ca1b963c..73d0ed125 100644--- a/launcher/app/src/main/res/values/config.xml+++ b/launcher/app/src/main/res/values/config.xml@@ -132,6 +132,10 @@<!-- Wallpapers decode as RGB_565 (2 bytes a pixel, 4 MB at 1080p), which bands dark gradients such as a nightsky, most of all under wallpaper_dim. true decodes them in 32-bit colour: 8 MB, for TVs with 2 GB or more. --><bool name="wallpaper_true_color">false</bool>+ <!-- Rotating wallpapers: show each picture's name under the top-right buttons, from a captions.txt next to the+ pictures in wallpapers/ ("01-dusk.jpg<TAB>Dusk over the peaks", one per line). A picture without a line+ shows no name. Can also be set with "wallpaper_captions": true in a theme's config.json. -->+ <bool name="wallpaper_captions">false</bool><!-- Grid rows left visible under the dock on the home screen. 0 = dock sits at the very bottom. Tiles shrink ifthe dock, its title and this many rows would not otherwise fit the screen height. -->diff --git a/launcher/app/src/test/java/com/gathin/tvhome/ThemeFilesTest.java b/launcher/app/src/test/java/com/gathin/tvhome/ThemeFilesTest.javaindex 7e4e2c92c..f523ab63f 100644--- a/launcher/app/src/test/java/com/gathin/tvhome/ThemeFilesTest.java+++ b/launcher/app/src/test/java/com/gathin/tvhome/ThemeFilesTest.java@@ -22,6 +22,13 @@ public class ThemeFilesTest {assertEquals("wallpapers/Night_2.WEBP", ThemeFiles.path(Arrays.asList("wallpapers", "Night_2.WEBP")));}+ @Test public void theCollectionsCaptionsAreAllowed() {+ assertEquals("wallpapers/captions.txt", ThemeFiles.path(Arrays.asList("wallpapers", "captions.txt")));+ assertNull(ThemeFiles.path(Collections.singletonList("captions.txt")));+ assertNull(ThemeFiles.path(Arrays.asList("wallpapers", "notes.txt")));+ assertFalse(ThemeFiles.collectionImage("captions.txt"));+ }+@Test public void anythingElseIsRefused() {assertNull(ThemeFiles.path(null));assertNull(ThemeFiles.path(Collections.emptyList()));diff --git a/launcher/app/src/test/java/com/gathin/tvhome/WallpaperCaptionsTest.java b/launcher/app/src/test/java/com/gathin/tvhome/WallpaperCaptionsTest.javanew file mode 100644index 000000000..1304ae8e9--- /dev/null+++ b/launcher/app/src/test/java/com/gathin/tvhome/WallpaperCaptionsTest.java@@ -0,0 +1,49 @@+package com.gathin.tvhome;++import static org.junit.Assert.assertEquals;+import static org.junit.Assert.assertFalse;+import static org.junit.Assert.assertTrue;++import java.util.Arrays;+import java.util.Map;++import org.junit.Test;++public class WallpaperCaptionsTest {++ @Test+ public void readsFilenameTabName() {+ Map<String, String> names = WallpaperCaptions.parse(Arrays.asList(+ "001.jpg\tRed Spider Nebula · Hubble",+ "002.jpg\t Falcon 9 at sunset "));+ assertEquals("Red Spider Nebula · Hubble", names.get("001.jpg"));+ assertEquals("Falcon 9 at sunset", names.get("002.jpg"));+ }++ @Test+ public void skipsCommentsBlankAndMalformedLines() {+ Map<String, String> names = WallpaperCaptions.parse(Arrays.asList(+ "# captions for the collection", "", " ", "no-tab-here.jpg Dusk", "\tno file", "003.jpg\t", null));+ assertTrue(names.isEmpty());+ }++ @Test+ public void cutsVeryLongNames() {+ StringBuilder longName = new StringBuilder();+ for (int i = 0; i < 30; i++) longName.append("word ");+ Map<String, String> names = WallpaperCaptions.parse(Arrays.asList("004.jpg\t" + longName));+ assertTrue(names.get("004.jpg").length() <= WallpaperCaptions.MAX_LENGTH);+ }++ @Test+ public void laterLineWinsForTheSameFile() {+ Map<String, String> names = WallpaperCaptions.parse(Arrays.asList("005.jpg\tOld", "005.jpg\tNew"));+ assertEquals("New", names.get("005.jpg"));+ assertFalse(names.containsKey("006.jpg"));+ }++ @Test+ public void missingFolderHasNoNames() {+ assertTrue(WallpaperCaptions.read(null).isEmpty());+ }+}diff --git a/themes/README.md b/themes/README.mdindex e9ae32cfe..6e4d9fd72 100644--- a/themes/README.md+++ b/themes/README.md@@ -63,6 +63,7 @@ is ignored, and a file that doesn't parse is ignored as a whole, so a theme can| `wallpaper_rotation_minutes` | 0 to 1440 | Rotate images in the theme's `wallpapers/` folder at this interval; 0 keeps the single-image behaviour. A negative or non-numeric value is ignored, and 0 means "no rotation", not "every minute" || `wallpaper_order` | `shuffle` or `sequential` | How a collection advances. `shuffle` (the default, and what launchers did before this key existed) avoids repeating the current picture; `sequential` walks the folder in filename order and wraps at the end. An unknown value falls back to `shuffle` || `wallpaper_dim` | 0 to 90 | Black overlay over wallpaper images, in percent; 0 by default and no shade view at all |+| `wallpaper_captions` | bool | With a rotating collection, the shown picture's name under the top-right buttons, from `wallpapers/captions.txt` (`001.jpg<TAB>Dusk over the peaks`, one per line); a picture without a line shows no name (`false` by default) || `festival` | string | Turns on a festive skin: the network pill becomes a diya whose flame follows the connection, Inputs a temple bell, Settings a marigold, and the first Home of the day gets a petal shower. `dussehra` and `diwali` have built-in greetings || `festival_until` | `YYYY-MM-DD` | Last day the festive skin shows; it switches itself off after that. A malformed date turns it off || `greeting` | string | Replaces the time-of-day greeting while the festive skin is on |diff --git a/tools/theme.ps1 b/tools/theme.ps1index ee5a36c56..00d15ee61 100644--- a/tools/theme.ps1+++ b/tools/theme.ps1@@ -60,6 +60,14 @@ if (Test-Path $wallpapers -PathType Container) {& $py -I tv.py (Put "wallpapers/$($_.Name)") | Out-Null}}+# The collection's names (wallpaper_captions); a theme without them leaves no stale names behind.+$captions = Join-Path $Theme 'wallpapers\captions.txt'+if (Test-Path $captions -PathType Leaf) {+ & $py -I b64push.py $captions (Stage 'wallpapers/captions.txt')+ & $py -I tv.py (Put 'wallpapers/captions.txt') | Out-Null+} else {+ & $py -I tv.py (Drop 'wallpapers/captions.txt') | Out-Null+}& $py -I tv.py "printf '%s' '$revision' > $tmp-theme_revision; $(Put 'theme_revision')" | Out-Null& $py -I tv.py "$restart; echo applied"Write-Host "Theme $(Split-Path $Theme -Leaf) is on the TV. Undo with: tools\theme.ps1 -TvHost $TvHost -Reset"diff --git a/tools/theme.sh b/tools/theme.shindex 889a8b699..3a297a8ad 100755--- a/tools/theme.sh+++ b/tools/theme.sh@@ -72,6 +72,13 @@ if [ -d "$THEME/wallpapers" ]; thenesacdonefi+# The collection's names (wallpaper_captions); a theme without them leaves no stale names behind.+if [ -f "$THEME/wallpapers/captions.txt" ]; then+ "$PY" -I b64push.py "$THEME/wallpapers/captions.txt" "$(stage wallpapers/captions.txt)"+ tv "$(put wallpapers/captions.txt)" >/dev/null+else+ tv "$(del wallpapers/captions.txt)" >/dev/null+fitv "printf '%s' '$REVISION' > $TMP-theme_revision; $(put theme_revision)" >/dev/nulltv "$RESTART; echo applied" | tail -n 1echo "Theme $(basename "$THEME") is on the TV. Undo with: tools/theme.sh --reset"