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_moods, to rotate the wallpapers that fit the time of day
Bansi Patel4fb0e47ca7c6
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Config.java b/launcher/app/src/main/java/com/gathin/tvhome/Config.javaindex 6071c886f..ce4521b66 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java@@ -8,6 +8,7 @@ import android.os.Environment;import android.util.Log;import org.json.JSONArray;+import org.json.JSONException;import org.json.JSONObject;import java.io.File;@@ -20,8 +21,10 @@ import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.HashMap;+import java.util.HashSet;import java.util.List;import java.util.Map;+import java.util.Set;/*** The launcher's settings: the values in res/values/config.xml, with an optional overlay read from@@ -175,6 +178,8 @@ final class Config {final boolean dockGlass;/** The dock band's padding equals the gap between its tiles (config.xml, dock_even_padding); false keeps the fixed padding. */final boolean dockEvenPadding;+ /** A rotating collection's groups by time of day, as file names (config.xml, wallpaper_moods); empty rotates through all of it. */+ final Map<String, Set<String>> wallpaperMoods;/** Shape of the glow behind the focused app (config.xml, glow_style): {@link #GLOW_RADIAL} or {@link #GLOW_HORIZON}. */final String glowStyle;@@ -198,7 +203,7 @@ final class Config {Festival festival, int[] inputKeycodes, List<String> appKeys, String stockHomeRedirect,List<RaceWeekend.Race> raceCalendar, boolean cinematicHome, boolean ambientGlow, boolean appGlow, int homeIdleClockMinutes,boolean keyFilter, boolean dockGlass, String glowStyle, boolean wallpaperCaptions,- boolean handleViewInputs, boolean tileMenu, boolean dockEvenPadding) {+ boolean handleViewInputs, boolean tileMenu, boolean dockEvenPadding, Map<String, Set<String>> wallpaperMoods) {this.handleViewInputs = handleViewInputs;this.tileMenu = tileMenu;this.inputKeycodes = inputKeycodes;@@ -269,6 +274,7 @@ final class Config {this.homeIdleClockMinutes = homeIdleClockMinutes;this.dockGlass = dockGlass;this.dockEvenPadding = dockEvenPadding;+ this.wallpaperMoods = wallpaperMoods;this.glowStyle = glowStyle(glowStyle);this.wallpaperCaptions = wallpaperCaptions;}@@ -346,6 +352,7 @@ final class Config {boolean keyFilter = res.getBoolean(R.bool.key_filter);boolean dockGlass = res.getBoolean(R.bool.dock_glass);boolean dockEvenPadding = res.getBoolean(R.bool.dock_even_padding);+ Map<String, Set<String>> wallpaperMoods = moods(res.getString(R.string.wallpaper_moods));String glowStyle = res.getString(R.string.glow_style);boolean applied = false;@@ -416,6 +423,8 @@ final class Config {keyFilter = bool(json, "key_filter", keyFilter);dockGlass = bool(json, "dock_glass", dockGlass);dockEvenPadding = bool(json, "dock_even_padding", dockEvenPadding);+ JSONObject moods = json.optJSONObject("wallpaper_moods");+ if (moods != null) wallpaperMoods = moods(moods);glowStyle = string(json, "glow_style", glowStyle);}// A theme push or reset invalidates choices made on the TV. On first use, remember the@@ -470,7 +479,7 @@ final class Config {Math.max(0, Math.min(100, skyIntensity)), settingsKeycodes, settingsKeyPanel, restoreKeyServices, wallpaperEnabled, wallpaper,wallpapers, rotationMinutes, wallpaperDim, dockOpacity, wallpaperOrder, applied,festival, inputKeycodes, appKeys, stockHomeRedirect, json == null ? Collections.emptyList() : raceCalendar(json), cinematic, ambientGlow, appGlow,- Math.max(0, idleClockMinutes), keyFilter, dockGlass, glowStyle, wallpaperCaptions, handleViewInputs, tileMenu, dockEvenPadding);+ Math.max(0, idleClockMinutes), keyFilter, dockGlass, glowStyle, wallpaperCaptions, handleViewInputs, tileMenu, dockEvenPadding, wallpaperMoods);}/**@@ -584,6 +593,32 @@ final class Config {}}+ /** wallpaper_moods as JSON text (config.xml); empty or unreadable is no groups. */+ private static Map<String, Set<String>> moods(String text) {+ if (text.trim().isEmpty()) return Collections.emptyMap();+ try {+ return moods(new JSONObject(text));+ } catch (JSONException e) {+ return Collections.emptyMap();+ }+ }++ /** {"night": ["03-moon-lake.jpg", ...], ...}: each mood's picture names; other keys and names are left out. */+ private static Map<String, Set<String>> moods(JSONObject o) {+ Map<String, Set<String>> groups = new HashMap<>();+ for (String mood : WallpaperMood.ALL) {+ JSONArray names = o.optJSONArray(mood);+ if (names == null) continue;+ Set<String> group = new HashSet<>();+ for (int i = 0; i < names.length(); i++) {+ String name = names.optString(i, "").trim();+ if (ThemeFiles.collectionImage(name)) group.add(name);+ }+ if (!group.isEmpty()) groups.put(mood, Collections.unmodifiableSet(group));+ }+ return Collections.unmodifiableMap(groups);+ }+private static String string(JSONObject o, String key, String fallback) {Object v = o.opt(key);return v instanceof String ? ((String) v).trim() : fallback;diff --git a/launcher/app/src/main/java/com/gathin/tvhome/WallpaperMood.java b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperMood.javanew file mode 100644index 000000000..a6f6979a3--- /dev/null+++ b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperMood.java@@ -0,0 +1,57 @@+package com.gathin.tvhome;++import java.io.File;+import java.time.LocalDate;+import java.time.ZoneId;+import java.util.ArrayList;+import java.util.List;+import java.util.Map;+import java.util.Set;++/**+ * wallpaper_moods: which group of a rotating wallpaper collection fits the time of day. Morning from sunrise to noon,+ * evening until half an hour after sunset, night the rest. The sun is the one at config.xml's latitude and longitude,+ * worked out offline by {@link Sun} as the sky does, or 07:00 and 18:30 without a place. A group that is missing, or+ * has none of the collection's pictures, falls back to the whole collection.+ */+final class WallpaperMood {+ static final String MORNING = "morning", EVENING = "evening", NIGHT = "night";+ static final String[] ALL = {MORNING, EVENING, NIGHT};+ /** Sunrise and sunset in minutes of the day, without a place (or where the sun does not rise or set that day). */+ static final int DEFAULT_SUNRISE = 7 * 60, DEFAULT_SUNSET = 18 * 60 + 30;+ private static final int NOON = 12 * 60;+ /** Evening lasts this long after sunset, while the sky still glows. */+ private static final int DUSK_MINUTES = 30;++ private WallpaperMood() {+ }++ /** The mood at this minute of the day, for a sunrise and sunset in minutes of the day. */+ static String timeOfDay(int minute, int sunrise, int sunset) {+ if (minute >= sunrise && minute < NOON) return MORNING;+ if (minute >= NOON && minute < sunset + DUSK_MINUTES) return EVENING;+ return NIGHT;+ }++ /** That day's {sunrise, sunset} at config.xml's latitude and longitude; the defaults when either is unusable. */+ static int[] sun(LocalDate day, String latitude, String longitude, ZoneId zone) {+ int[] times = null;+ try {+ if (!latitude.trim().isEmpty() && !longitude.trim().isEmpty()) {+ times = Sun.riseAndSet(day, Double.parseDouble(latitude.trim()), Double.parseDouble(longitude.trim()), zone);+ }+ } catch (NumberFormatException ignored) {+ // not a number: the defaults+ }+ return times != null ? times : new int[]{DEFAULT_SUNRISE, DEFAULT_SUNSET};+ }++ /** The pictures in the mood's group, in the collection's order; all of them when the group has none. */+ static List<File> select(List<File> all, Map<String, Set<String>> groups, String mood) {+ Set<String> names = groups.get(mood);+ if (names == null) return all;+ List<File> group = new ArrayList<>();+ for (File file : all) if (names.contains(file.getName())) group.add(file);+ return group.isEmpty() ? all : group;+ }+}diff --git a/launcher/app/src/main/java/com/gathin/tvhome/WallpaperPlayer.java b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperPlayer.javaindex 739c23081..b0c1592a1 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/WallpaperPlayer.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperPlayer.java@@ -17,11 +17,15 @@ import android.widget.ImageView;import android.widget.TextView;import java.io.File;+import java.time.LocalDate;+import java.time.LocalDateTime;+import java.time.ZoneId;import java.util.ArrayList;import java.util.Collections;import java.util.List;import java.util.Map;import java.util.Random;+import java.util.Set;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;@@ -50,6 +54,12 @@ final class WallpaperPlayer {/** 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;+ /** wallpaper_moods: the collection's groups by time of day; empty rotates through all of it. */+ private final Map<String, Set<String>> moods;+ /** config.xml latitude and longitude for the sun's times, and today's {sunrise, sunset} once worked out. */+ private final String latitude, longitude;+ private LocalDate sunDay;+ private int[] sun;WallpaperPlayer(Context context, FrameLayout root, Config config) {this.root = root;@@ -60,6 +70,9 @@ final class WallpaperPlayer {dimColor = config.wallpaperDim > 0 ? (config.wallpaperDim * 255 / 100) << 24 : 0;order = config.wallpaperOrder;preferences = context.getSharedPreferences("wallpaper_rotation", Context.MODE_PRIVATE);+ moods = config.wallpaperMoods;+ latitude = moods.isEmpty() ? "" : context.getString(R.string.latitude);+ longitude = moods.isEmpty() ? "" : context.getString(R.string.longitude);// Playback state belongs to one collection. Changing the collection starts from its first// picture instead of resuming a filename that belonged to the previous one.String collection = collectionKey(files);@@ -90,8 +103,9 @@ final class WallpaperPlayer {*/private void showFirst() {String previous = preferences.getString("image", "");- File first = WallpaperRotation.find(files, previous);- if (first == null) first = WallpaperRotation.pick(files, previous, order, random);+ List<File> playable = playable();+ File first = WallpaperRotation.find(playable, previous);+ if (first == null) first = WallpaperRotation.pick(playable, previous, order, random);while (first != null) {Bitmap bitmap = decode(first);if (bitmap != null) {@@ -107,7 +121,8 @@ final class WallpaperPlayer {return;}files.remove(first); // unreadable or over 4K: try another, or keep the plain colour- first = WallpaperRotation.pick(files, previous, order, random);+ playable = playable();+ first = WallpaperRotation.pick(playable, previous, order, random);}}@@ -120,6 +135,17 @@ final class WallpaperPlayer {active = false;}+ /** The pictures the rotation picks from now: wallpaper_moods' group for the time of day, or the whole collection. */+ private List<File> playable() {+ if (moods.isEmpty()) return files;+ LocalDateTime now = LocalDateTime.now();+ if (!now.toLocalDate().equals(sunDay)) {+ sunDay = now.toLocalDate();+ sun = WallpaperMood.sun(sunDay, latitude, longitude, ZoneId.systemDefault());+ }+ return WallpaperMood.select(files, moods, WallpaperMood.timeOfDay(now.getHour() * 60 + now.getMinute(), sun[0], sun[1]));+ }+void close() {active = false;closed = true;@@ -129,10 +155,12 @@ final class WallpaperPlayer {void update() {if (!active || closed || loading || files.isEmpty()) return;String previous = preferences.getString("image", "");- File selected = WallpaperRotation.find(files, previous);+ // A picture outside the time of day's group (the group changed) is replaced at once, not after the interval.+ List<File> playable = playable();+ File selected = WallpaperRotation.find(playable, previous);long changed = preferences.getLong("changed", 0);if (selected == null || WallpaperRotation.due(changed, System.currentTimeMillis(), interval)) {- selected = WallpaperRotation.pick(files, previous, order, random);+ selected = WallpaperRotation.pick(playable, previous, order, random);}if (selected == null || selected.getName().equals(displayed)) return;File next = selected;diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xmlindex f600676d0..896ceb169 100644--- a/launcher/app/src/main/res/values/config.xml+++ b/launcher/app/src/main/res/values/config.xml@@ -232,6 +232,13 @@pictures in wallpapers/ ("01-dusk.jpg<TAB>Dusk over the peaks", one per line). A picture without a lineshows no name. Can also be set with "wallpaper_captions": true in a theme's config.json. --><bool name="wallpaper_captions">false</bool>+ <!-- Rotating wallpapers grouped by the time of day, as JSON: {"morning": [file names], "evening": [...],+ "night": [...]}. While set, the rotation picks only from the group that fits now: morning from sunrise to+ noon, evening until half an hour after sunset, night the rest, with the sun at latitude and longitude (07:00+ and 18:30 without them). It moves to the new group as soon as the time of day changes. A missing or empty+ group falls back to the whole collection; empty rotates through every picture. A theme can set+ "wallpaper_moods" as an object. -->+ <string name="wallpaper_moods" translatable="false"></string><!-- Hold OK on a tile opens a small menu: Move (picks the tile up for reordering), Remove from Home (only withapp_library) and App info. false keeps the old behaviour: holding OK opens the app's App info page.Can also be set with "tile_menu": true in a theme's config.json. -->diff --git a/launcher/app/src/test/java/com/gathin/tvhome/WallpaperMoodTest.java b/launcher/app/src/test/java/com/gathin/tvhome/WallpaperMoodTest.javanew file mode 100644index 000000000..d73769c8f--- /dev/null+++ b/launcher/app/src/test/java/com/gathin/tvhome/WallpaperMoodTest.java@@ -0,0 +1,76 @@+package com.gathin.tvhome;++import static org.junit.Assert.assertArrayEquals;+import static org.junit.Assert.assertEquals;++import java.io.File;+import java.time.LocalDate;+import java.time.ZoneId;+import java.util.ArrayList;+import java.util.Arrays;+import java.util.Collections;+import java.util.HashMap;+import java.util.HashSet;+import java.util.List;+import java.util.Map;+import java.util.Set;++import org.junit.Test;++/** Plain JVM tests for wallpaper_moods: the time of day's group and the pictures it picks from. */+public class WallpaperMoodTest {+ private static final int RISE = 7 * 60 + 20, SET = 18 * 60 + 20;++ private static String at(int hour, int minute) {+ return WallpaperMood.timeOfDay(hour * 60 + minute, RISE, SET);+ }++ @Test+ public void timeOfDayFollowsSunriseNoonAndDusk() {+ assertEquals(WallpaperMood.NIGHT, at(0, 30));+ assertEquals(WallpaperMood.NIGHT, at(7, 19));+ assertEquals(WallpaperMood.MORNING, at(7, 20));+ assertEquals(WallpaperMood.MORNING, at(11, 59));+ assertEquals(WallpaperMood.EVENING, at(12, 0));+ assertEquals(WallpaperMood.EVENING, at(18, 49)); // half an hour after sunset is still evening+ assertEquals(WallpaperMood.NIGHT, at(18, 50));+ assertEquals(WallpaperMood.NIGHT, at(23, 59));+ }++ @Test+ public void sunComesFromTheConfiguredPlaceOrTheDefaults() {+ LocalDate day = LocalDate.of(2026, 10, 22);+ ZoneId zone = ZoneId.of("America/Los_Angeles");+ assertArrayEquals(Sun.riseAndSet(day, 37.35, -121.98, zone), WallpaperMood.sun(day, "37.35", " -121.98 ", zone));+ int[] defaults = {WallpaperMood.DEFAULT_SUNRISE, WallpaperMood.DEFAULT_SUNSET};+ assertArrayEquals(defaults, WallpaperMood.sun(day, "", "", zone));+ assertArrayEquals(defaults, WallpaperMood.sun(day, "37.35", "", zone));+ assertArrayEquals(defaults, WallpaperMood.sun(day, "north", "-121.98", zone));+ // the sun does not set at the pole in June: the defaults+ assertArrayEquals(defaults, WallpaperMood.sun(LocalDate.of(2026, 6, 21), "89.9", "0", ZoneId.of("UTC")));+ }++ private static List<File> files(String... names) {+ List<File> out = new ArrayList<>();+ for (String name : names) out.add(new File("/walls", name));+ return out;+ }++ private static List<String> names(List<File> files) {+ List<String> out = new ArrayList<>();+ for (File f : files) out.add(f.getName());+ return out;+ }++ @Test+ public void selectKeepsTheCollectionsOrderAndFallsBackToAll() {+ List<File> all = files("a.jpg", "b.jpg", "c.jpg", "d.jpg");+ Map<String, Set<String>> groups = new HashMap<>();+ groups.put(WallpaperMood.NIGHT, new HashSet<>(Arrays.asList("d.jpg", "a.jpg")));+ groups.put(WallpaperMood.MORNING, new HashSet<>(Collections.singletonList("gone.jpg")));+ assertEquals(Arrays.asList("a.jpg", "d.jpg"), names(WallpaperMood.select(all, groups, WallpaperMood.NIGHT)));+ assertEquals(all, WallpaperMood.select(all, groups, WallpaperMood.MORNING)); // none of its pictures here+ assertEquals(all, WallpaperMood.select(all, groups, WallpaperMood.EVENING)); // no group at all+ assertEquals(all, WallpaperMood.select(all, Collections.emptyMap(), WallpaperMood.NIGHT));+ }+}diff --git a/themes/README.md b/themes/README.mdindex c0b455181..245bc2e90 100644--- a/themes/README.md+++ b/themes/README.md@@ -82,6 +82,7 @@ is ignored, and a file that doesn't parse is ignored as a whole, so a theme can| `wallpaper_dim` | 0 to 90 | Black overlay over wallpaper images, in percent; 0 by default and no shade view at all || `dock_opacity` | 30 to 100 | Opacity of the dock's band, in percent, so a wallpaper shows through it; 100 by default (the cinematic shelf keeps its own translucent band). Launcher settings on the TV offers 100, 70, 50 or 30, which wins until the next theme push or Follow theme || `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) |+| `wallpaper_moods` | object | A rotating collection grouped by time of day: `{"morning": [...], "evening": [...], "night": [...]}` with file names from `wallpapers/`. Morning runs from sunrise to noon, evening until half an hour after sunset, night the rest, with the sun at config.xml's `latitude` and `longitude` (07:00 and 18:30 without them); a missing group rotates through every picture. Unset by default || `tile_menu` | bool | Hold OK or press the remote's Menu key on a tile to open a small menu: Move, Remove from Home (with `app_library`) and App info. `false` (the default) keeps holding OK as a shortcut to the app's App info page and leaves Menu unchanged || `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 |