Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

launcher: opt-in clock screensaver that starts only from Home

avazibra6122ef5eca6d
diff --git a/launcher/app/src/main/AndroidManifest.xml b/launcher/app/src/main/AndroidManifest.xml
index 1f96dd066..7dc9ee681 100644
--- a/launcher/app/src/main/AndroidManifest.xml
+++ b/launcher/app/src/main/AndroidManifest.xml
@@ -99,6 +99,14 @@
android:resource="@xml/home_key_service" />
</service>
+ <!-- The same clock, started by Home itself after home_idle_clock_minutes without input. -->
+ <activity
+ android:name=".ClockActivity"
+ android:exported="false"
+ android:excludeFromRecents="true"
+ android:noHistory="true"
+ android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />
+
<!-- Screensaver: pick it in Settings, or `settings put secure screensaver_components
com.gathin.tvhome/.ClockDream` over adb. -->
<service
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/ClockActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/ClockActivity.java
new file mode 100644
index 000000000..f188114f7
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/ClockActivity.java
@@ -0,0 +1,58 @@
+package com.gathin.tvhome;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.view.View;
+
+/**
+ * The clock screensaver shown by Home itself after home_idle_clock_minutes without input. Some TVs' own
+ * screens (CVTE's live TV) do not keep the screen on, so the system screensaver would cut into programmes;
+ * this one only ever starts from Home. Any key returns to Home.
+ */
+public class ClockActivity extends Activity {
+
+ private ClockScene scene;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.dream_clock);
+ getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE);
+ scene = new ClockScene(getWindow().getDecorView());
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ scene.start();
+ }
+
+ @Override
+ protected void onPause() {
+ scene.stop();
+ super.onPause();
+ finish(); // never left behind in the back stack
+ }
+
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent event) {
+ // The key that wakes the clock should not also act on Home, so it is consumed here.
+ if (event.getAction() == KeyEvent.ACTION_UP) finish();
+ return true;
+ }
+
+ @Override
+ public boolean dispatchGenericMotionEvent(MotionEvent event) {
+ finish();
+ return true;
+ }
+
+ @Override
+ public void finish() {
+ super.finish();
+ overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
+ }
+}
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/ClockDream.java b/launcher/app/src/main/java/com/gathin/tvhome/ClockDream.java
index 75d05f10c..caf84eee8 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/ClockDream.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/ClockDream.java
@@ -1,41 +1,14 @@
package com.gathin.tvhome;
-import android.animation.ArgbEvaluator;
-import android.animation.ValueAnimator;
-import android.graphics.drawable.GradientDrawable;
-import android.os.Handler;
-import android.os.Looper;
import android.service.dreams.DreamService;
-import android.view.View;
-
-import java.util.Random;
/**
- * Screensaver: the launcher's thin clock and date on black, over a slow ambient glow.
- * Every minute the clock drifts to a new spot and the glow shifts colour, so nothing burns in.
+ * Screensaver: the launcher's thin clock and date on black, over a slow ambient glow (ClockScene).
* No network, no images: cheap enough for a 1 GB TV.
*/
public class ClockDream extends DreamService {
- private static final long MOVE_MS = 60_000L;
- /** Deep, low-brightness glow colours; the glow is drawn at partial alpha on black. */
- private static final int[] PALETTE = {0xFF2B5CFF, 0xFF00A39A, 0xFF8A3FFC, 0xFFE0661B, 0xFFD6336C};
-
- private final Handler handler = new Handler(Looper.getMainLooper());
- private final Random random = new Random();
- private View content;
- private GradientDrawable glow;
- private int colorIndex;
- private int glowColor;
-
- private final Runnable tick = new Runnable() {
- @Override
- public void run() {
- moveClock();
- shiftGlow();
- handler.postDelayed(this, MOVE_MS);
- }
- };
+ private ClockScene scene;
@Override
public void onAttachedToWindow() {
@@ -44,75 +17,24 @@ public class ClockDream extends DreamService {
setFullscreen(true);
setScreenBright(false);
setContentView(R.layout.dream_clock);
-
- content = findViewById(R.id.dreamContent);
- View ambient = findViewById(R.id.dreamAmbient);
- glow = new GradientDrawable();
- glow.setGradientType(GradientDrawable.RADIAL_GRADIENT);
- ambient.setBackground(glow);
- ambient.addOnLayoutChangeListener((v, l, t, r, b, ol, ot, or, ob) ->
- glow.setGradientRadius((r - l) * 0.55f));
- colorIndex = random.nextInt(PALETTE.length);
- setGlow(PALETTE[colorIndex]);
+ scene = new ClockScene(getWindow().getDecorView());
}
@Override
public void onDreamingStarted() {
super.onDreamingStarted();
- content.setAlpha(0f);
- content.post(() -> {
- placeClock();
- content.animate().alpha(1f).setDuration(1200).start();
- });
- handler.postDelayed(tick, MOVE_MS);
+ scene.start();
}
@Override
public void onDreamingStopped() {
- handler.removeCallbacks(tick);
+ scene.stop();
super.onDreamingStopped();
}
@Override
public void onDetachedFromWindow() {
- handler.removeCallbacks(tick);
+ if (scene != null) scene.stop();
super.onDetachedFromWindow();
}
-
- private void moveClock() {
- content.animate().alpha(0f).setDuration(900).withEndAction(() -> {
- placeClock();
- content.animate().alpha(1f).setDuration(1200).start();
- }).start();
- }
-
- /** A random spot that keeps the whole clock on screen, with the glow centred behind it. */
- private void placeClock() {
- View parent = (View) content.getParent();
- int maxX = Math.max(0, parent.getWidth() - content.getWidth());
- int maxY = Math.max(0, parent.getHeight() - content.getHeight());
- float x = maxX * (0.1f + 0.8f * random.nextFloat());
- float y = maxY * (0.1f + 0.8f * random.nextFloat());
- content.setX(x);
- content.setY(y);
- if (parent.getWidth() > 0 && parent.getHeight() > 0) {
- glow.setGradientCenter((x + content.getWidth() / 2f) / parent.getWidth(),
- (y + content.getHeight() / 2f) / parent.getHeight());
- }
- }
-
- private void shiftGlow() {
- int from = glowColor;
- colorIndex = (colorIndex + 1) % PALETTE.length;
- ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), from, PALETTE[colorIndex]);
- anim.setDuration(8000);
- anim.addUpdateListener(a -> setGlow((int) a.getAnimatedValue()));
- anim.start();
- }
-
- private void setGlow(int color) {
- glowColor = color;
- int c = color & 0x00FFFFFF;
- glow.setColors(new int[]{0x40000000 | c, 0x14000000 | c, 0x00000000 | c});
- }
}
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/ClockScene.java b/launcher/app/src/main/java/com/gathin/tvhome/ClockScene.java
new file mode 100644
index 000000000..192c29c5e
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/ClockScene.java
@@ -0,0 +1,102 @@
+package com.gathin.tvhome;
+
+import android.animation.ArgbEvaluator;
+import android.animation.ValueAnimator;
+import android.graphics.drawable.GradientDrawable;
+import android.os.Handler;
+import android.os.Looper;
+import android.view.View;
+
+import java.util.Random;
+
+/**
+ * The clock screensaver's scene (layout dream_clock): the thin clock and date on black over a slow ambient
+ * glow. Every minute the clock drifts to a new spot and the glow shifts colour, so nothing burns in.
+ * Shared by ClockDream (the system screensaver) and ClockActivity (Home left idle).
+ */
+final class ClockScene {
+
+ private static final long MOVE_MS = 60_000L;
+ /** Deep, low-brightness glow colours; the glow is drawn at partial alpha on black. */
+ private static final int[] PALETTE = {0xFF2B5CFF, 0xFF00A39A, 0xFF8A3FFC, 0xFFE0661B, 0xFFD6336C};
+
+ private final Handler handler = new Handler(Looper.getMainLooper());
+ private final Random random = new Random();
+ private final View content;
+ private final GradientDrawable glow;
+ private int colorIndex;
+ private int glowColor;
+
+ private final Runnable tick = new Runnable() {
+ @Override
+ public void run() {
+ moveClock();
+ shiftGlow();
+ handler.postDelayed(this, MOVE_MS);
+ }
+ };
+
+ /** root is the inflated dream_clock layout. */
+ ClockScene(View root) {
+ content = root.findViewById(R.id.dreamContent);
+ View ambient = root.findViewById(R.id.dreamAmbient);
+ glow = new GradientDrawable();
+ glow.setGradientType(GradientDrawable.RADIAL_GRADIENT);
+ ambient.setBackground(glow);
+ ambient.addOnLayoutChangeListener((v, l, t, r, b, ol, ot, or, ob) ->
+ glow.setGradientRadius((r - l) * 0.55f));
+ colorIndex = random.nextInt(PALETTE.length);
+ setGlow(PALETTE[colorIndex]);
+ }
+
+ void start() {
+ content.setAlpha(0f);
+ content.post(() -> {
+ placeClock();
+ content.animate().alpha(1f).setDuration(1200).start();
+ });
+ handler.removeCallbacks(tick);
+ handler.postDelayed(tick, MOVE_MS);
+ }
+
+ void stop() {
+ handler.removeCallbacks(tick);
+ }
+
+ private void moveClock() {
+ content.animate().alpha(0f).setDuration(900).withEndAction(() -> {
+ placeClock();
+ content.animate().alpha(1f).setDuration(1200).start();
+ }).start();
+ }
+
+ /** A random spot that keeps the whole clock on screen, with the glow centred behind it. */
+ private void placeClock() {
+ View parent = (View) content.getParent();
+ int maxX = Math.max(0, parent.getWidth() - content.getWidth());
+ int maxY = Math.max(0, parent.getHeight() - content.getHeight());
+ float x = maxX * (0.1f + 0.8f * random.nextFloat());
+ float y = maxY * (0.1f + 0.8f * random.nextFloat());
+ content.setX(x);
+ content.setY(y);
+ if (parent.getWidth() > 0 && parent.getHeight() > 0) {
+ glow.setGradientCenter((x + content.getWidth() / 2f) / parent.getWidth(),
+ (y + content.getHeight() / 2f) / parent.getHeight());
+ }
+ }
+
+ private void shiftGlow() {
+ int from = glowColor;
+ colorIndex = (colorIndex + 1) % PALETTE.length;
+ ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), from, PALETTE[colorIndex]);
+ anim.setDuration(8000);
+ anim.addUpdateListener(a -> setGlow((int) a.getAnimatedValue()));
+ anim.start();
+ }
+
+ private void setGlow(int color) {
+ glowColor = color;
+ int c = color & 0x00FFFFFF;
+ glow.setColors(new int[]{0x40000000 | c, 0x14000000 | c, 0x00000000 | c});
+ }
+}
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Config.java b/launcher/app/src/main/java/com/gathin/tvhome/Config.java
index 8f41173e3..a3583ed8b 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java
@@ -104,6 +104,8 @@ final class Config {
final List<RaceWeekend.Race> raceCalendar;
/** Cinematic top shelf (config.xml, cinematic_home): the focused dock app's artwork behind a larger shelf. */
final boolean cinematicHome;
+ /** Minutes Home may sit untouched before the clock screensaver (config.xml, home_idle_clock_minutes); 0 is off. */
+ final int homeIdleClockMinutes;
private Config(List<String> dockApps, boolean fillDock, List<String> hiddenApps, String liveTvPackage,
String liveTvAction, Map<String, String> launchActions, Map<String, String> appLabels,
@@ -114,7 +116,7 @@ final class Config {
int[] settingsKeycodes, boolean settingsKeyPanel, boolean wallpaperEnabled, File wallpaper, List<File> wallpapers,
int wallpaperRotationMinutes, int wallpaperDim, boolean overlayApplied,
Festival festival, int[] inputKeycodes, List<String> appKeys,
- List<RaceWeekend.Race> raceCalendar, boolean cinematicHome) {
+ List<RaceWeekend.Race> raceCalendar, boolean cinematicHome, int homeIdleClockMinutes) {
this.inputKeycodes = inputKeycodes;
this.appKeys = Collections.unmodifiableList(appKeys);
this.dockApps = Collections.unmodifiableList(dockApps);
@@ -156,6 +158,7 @@ final class Config {
this.festival = festival;
this.raceCalendar = Collections.unmodifiableList(raceCalendar);
this.cinematicHome = cinematicHome;
+ this.homeIdleClockMinutes = homeIdleClockMinutes;
}
/** The folder the theme tools push into; null when external storage is unavailable. */
@@ -198,6 +201,7 @@ final class Config {
int[] inputKeycodes = res.getIntArray(R.array.input_key_keycodes);
List<String> appKeys = new ArrayList<>(Arrays.asList(res.getStringArray(R.array.app_keys)));
boolean cinematic = res.getBoolean(R.bool.cinematic_home);
+ int idleClockMinutes = res.getInteger(R.integer.home_idle_clock_minutes);
boolean applied = false;
File dir = dir(ctx);
@@ -238,6 +242,7 @@ final class Config {
inputKeycodes = intArray(json, "input_key_keycodes", inputKeycodes);
appKeys = stringList(json, "app_keys", appKeys);
cinematic = bool(json, "cinematic_home", cinematic);
+ idleClockMinutes = integer(json, "home_idle_clock_minutes", idleClockMinutes, 0, 1440);
}
// A theme push or reset invalidates choices made on the TV. On first use, remember the
// current theme without clearing choices from an older launcher version.
@@ -291,7 +296,8 @@ final class Config {
shamsi, greetingName, moduleCards, reducedMotion, dockTitle, dockRow, reorderButton, vpn, homeSettings, showStats, library, background,
Math.max(0, Math.min(100, skyIntensity)), settingsKeycodes, settingsKeyPanel, wallpaperEnabled, wallpaper,
wallpapers, rotationMinutes, wallpaperDim, applied,
- festival, inputKeycodes, appKeys, json == null ? Collections.emptyList() : raceCalendar(json), cinematic);
+ festival, inputKeycodes, appKeys, json == null ? Collections.emptyList() : raceCalendar(json), cinematic,
+ Math.max(0, idleClockMinutes));
}
/**
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
index 7597e0e60..1865a056b 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -102,6 +102,9 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
*/
private static final long TIME_VALID_AFTER_MS = 1_735_689_600_000L;
private String liveTvPkg;
+ /** Idle time on Home before ClockActivity; 0 is off (config.xml, home_idle_clock_minutes). */
+ private long idleClockMs;
+ private final Runnable showIdleClock = () -> startActivity(new Intent(this, ClockActivity.class));
private String liveTvAction;
private String inputAction;
private String sourcePanelService;
@@ -299,6 +302,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
festival = cfg.festival;
festive = festival.active(LocalDate.now());
liveTvPkg = cfg.liveTvPackage;
+ idleClockMs = cfg.homeIdleClockMinutes * MINUTE_MS;
liveTvAction = cfg.liveTvAction;
inputAction = cfg.inputAction;
sourcePanelService = cfg.sourcePanelService;
@@ -606,6 +610,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
recreate();
return;
}
+ restartIdleClock();
promptsPaused = false;
if (rebuildOnResume) {
tilesReady = false;
@@ -712,9 +717,22 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
});
}
+ /** Any key on Home restarts the countdown to the idle clock. */
+ @Override
+ public void onUserInteraction() {
+ super.onUserInteraction();
+ restartIdleClock();
+ }
+
+ private void restartIdleClock() {
+ root.removeCallbacks(showIdleClock);
+ if (idleClockMs > 0) root.postDelayed(showIdleClock, idleClockMs);
+ }
+
@Override
protected void onPause() {
super.onPause();
+ root.removeCallbacks(showIdleClock);
endReorder(); // Home or another app while reordering keeps the order so far
wallpaperPlayer.stop();
stopAmbientAnimation();
diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xml
index 3deebbea4..f442baef9 100644
--- a/launcher/app/src/main/res/values/config.xml
+++ b/launcher/app/src/main/res/values/config.xml
@@ -159,4 +159,10 @@
dots, the focus glow takes the app's colour and the dock band turns translucent. false keeps the plain
shelf. Can also be set with "cinematic_home": true in a theme's config.json. -->
<bool name="cinematic_home">false</bool>
+
+ <!-- Minutes Home may sit untouched before it shows the clock screensaver (ClockActivity); 0 turns it off.
+ Unlike the system screensaver this never starts over live TV or an app, which matters on TVs whose
+ Live TV window does not keep the screen on (CVTE): there the system screensaver would start in the
+ middle of a programme. Can also be set with "home_idle_clock_minutes": 10 in a theme's config.json. -->
+ <integer name="home_idle_clock_minutes">0</integer>
</resources>
diff --git a/themes/README.md b/themes/README.md
index d08c19670..225347c1e 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -64,6 +64,7 @@ is ignored, and a file that doesn't parse is ignored as a whole, so a theme can
| `input_key_keycodes` | list of keycodes | More remote buttons that open the input switcher, for `InputKeyService` (`KEYCODE_TV` and `KEYCODE_TV_INPUT` always do) |
| `app_keys` | list of strings | Remote buttons that open an app, as `"190:com.google.android.youtube.tv"` or `"KEYCODE_BUTTON_3:com.google.android.youtube.tv"`, for `InputKeyService` or `HomeKeyService` |
| `race_calendar` | list of races | F1 race-weekend mode: from 12 hours before a weekend's first session until 4 hours after the race starts, a panel under the clock shows the next session with a countdown (or the live one) and the weekend's session times in the TV's time zone. Write it with `tools/race_calendar.py <theme folder>`, which fetches the season from the free Jolpica API; the launcher itself never goes online |
+| `home_idle_clock_minutes` | 0 to 1440 | Minutes Home may sit untouched before it shows the clock screensaver (a thin clock and date drifting over a slow glow, as the system "Clock" screensaver does). Any key returns to Home. It starts only from Home, never over Live TV or an app; 0 is off (default) |
| `cinematic_home` | bool | Cinematic top shelf: the focused dock app's artwork, softened, fills the top of the screen in its colour, with a larger name, "Last opened" (apps opened from Home), dock position dots, a focus glow in the app's colour and a translucent dock band; off by default |
## Wallpapers