Skip to content

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

Launcher: add a Clock screensaver (DreamService)

pananon6d1bad39b603
diff --git a/README.md b/README.md
index 7ab7c1b4a..420924814 100644
--- a/README.md
+++ b/README.md
@@ -50,6 +50,11 @@ A small native Android TV home screen (`com.gathin.tvhome`), built for sets with
set in [Outfit](https://fonts.google.com/specimen/Outfit).
- Deterministic D-pad navigation, last focused tile remembered, staggered entrance animation.
No blur, no video, no network, no background services.
+- A **Clock** screensaver in the same style: a large thin clock and the date over an ambient glow.
+ Every minute the clock drifts to a new spot and the glow shifts colour, so nothing burns in. The
+ system runs it only while the TV is idle. Turn it on with
+ `tools/tv.py 'settings put secure screensaver_components com.gathin.tvhome/.ClockDream; settings put secure screensaver_enabled 1'`
+ (it starts after the TV's "screen off" idle time, `settings get system screen_off_timeout`).
Configure it in [`launcher/app/src/main/res/values/config.xml`](launcher/app/src/main/res/values/config.xml):
dock order, hidden apps, Live TV package and columns. Build and install with
diff --git a/launcher/app/src/main/AndroidManifest.xml b/launcher/app/src/main/AndroidManifest.xml
index 3bff8f106..8cea721b9 100644
--- a/launcher/app/src/main/AndroidManifest.xml
+++ b/launcher/app/src/main/AndroidManifest.xml
@@ -31,5 +31,18 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
+
+ <!-- Screensaver: pick it in Settings, or `settings put secure screensaver_components
+ com.gathin.tvhome/.ClockDream` over adb. -->
+ <service
+ android:name=".ClockDream"
+ android:label="@string/dream_name"
+ android:exported="true"
+ android:permission="android.permission.BIND_DREAM_SERVICE">
+ <intent-filter>
+ <action android:name="android.service.dreams.DreamService" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </service>
</application>
</manifest>
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/ClockDream.java b/launcher/app/src/main/java/com/gathin/tvhome/ClockDream.java
new file mode 100644
index 000000000..75d05f10c
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/ClockDream.java
@@ -0,0 +1,118 @@
+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.
+ * 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);
+ }
+ };
+
+ @Override
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ setInteractive(false); // any key wakes the TV back to where it was
+ 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]);
+ }
+
+ @Override
+ public void onDreamingStarted() {
+ super.onDreamingStarted();
+ content.setAlpha(0f);
+ content.post(() -> {
+ placeClock();
+ content.animate().alpha(1f).setDuration(1200).start();
+ });
+ handler.postDelayed(tick, MOVE_MS);
+ }
+
+ @Override
+ public void onDreamingStopped() {
+ handler.removeCallbacks(tick);
+ super.onDreamingStopped();
+ }
+
+ @Override
+ public void onDetachedFromWindow() {
+ handler.removeCallbacks(tick);
+ 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/res/layout/dream_clock.xml b/launcher/app/src/main/res/layout/dream_clock.xml
new file mode 100644
index 000000000..96d385efa
--- /dev/null
+++ b/launcher/app/src/main/res/layout/dream_clock.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Screensaver (ClockDream): clock and date that drift around a black screen over an ambient glow. -->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#FF000000">
+
+ <View
+ android:id="@+id/dreamAmbient"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+
+ <LinearLayout
+ android:id="@+id/dreamContent"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:baselineAligned="true">
+
+ <TextClock
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:format12Hour="h:mm"
+ android:format24Hour="HH:mm"
+ android:textColor="#E6FFFFFF"
+ android:textSize="120sp"
+ android:fontFamily="@font/outfit"
+ android:fontVariationSettings="'wght' 200"
+ android:letterSpacing="-0.04"
+ android:includeFontPadding="false" />
+
+ <TextClock
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="10dp"
+ android:format12Hour="a"
+ android:format24Hour=""
+ android:textColor="#99FFFFFF"
+ android:textSize="22sp"
+ android:fontFamily="@font/outfit"
+ android:fontVariationSettings="'wght' 500"
+ android:letterSpacing="0.08"
+ android:textAllCaps="true" />
+ </LinearLayout>
+
+ <TextClock
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="6dp"
+ android:layout_marginTop="4dp"
+ android:format12Hour="EEEE d MMMM"
+ android:format24Hour="EEEE d MMMM"
+ android:textColor="#8CFFFFFF"
+ android:textSize="18sp"
+ android:fontFamily="@font/outfit"
+ android:fontVariationSettings="'wght' 400"
+ android:letterSpacing="0.14"
+ android:textAllCaps="true" />
+ </LinearLayout>
+</FrameLayout>
diff --git a/launcher/app/src/main/res/values/strings.xml b/launcher/app/src/main/res/values/strings.xml
index a12dac4d7..c932a5a90 100644
--- a/launcher/app/src/main/res/values/strings.xml
+++ b/launcher/app/src/main/res/values/strings.xml
@@ -16,4 +16,5 @@
<string name="good_night">Good night</string>
<string name="ethernet">Ethernet</string>
<string name="offline">Offline</string>
+ <string name="dream_name">Clock</string>
</resources>