Skip to content

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

Festive skin: diya network pill, bell and marigold pills, festive greeting, gold glow, petal shower

Gathin239668315fa1d3
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/BellDrawable.java b/launcher/app/src/main/java/com/gathin/tvhome/BellDrawable.java
new file mode 100644
index 000000000..a1c441368
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/BellDrawable.java
@@ -0,0 +1,257 @@
+package com.gathin.tvhome;
+
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.ValueAnimator;
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.LinearGradient;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.graphics.PixelFormat;
+import android.graphics.RadialGradient;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.Shader;
+import android.graphics.drawable.Drawable;
+import android.view.animation.LinearInterpolator;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+/**
+ * A brass temple bell (ghanta): a loop and knob on top, a domed body with two engraved bands and a flared lip,
+ * and the clapper hanging below. {@link #ring()} swings it about the loop, a damped swing of about 16 degrees
+ * that dies away within a second, with the clapper trailing the body. Each ring starts the other way from the
+ * last one, and ringing again mid-swing carries on from where the bell is. The highlight stays put as the bell
+ * swings, as if lit from the top left. Drawn in a 24 x 24 unit box scaled into the bounds; the swing is sized so
+ * the bell stays inside it.
+ */
+public final class BellDrawable extends Drawable {
+
+ private static final float BOX = 24f;
+ /** The pivot: the top of the loop. */
+ private static final float PX = 12f, PY = 1.3f;
+ private static final float AMPLITUDE = 16f;
+ private static final float OMEGA = (float) (2 * Math.PI * 3.4), TAU = 0.3f;
+ private static final long RING_MS = 1000;
+ /** The clapper follows the body this many seconds late, and never more than CLAPPER_MAX degrees apart. */
+ private static final float LAG = 0.055f, CLAPPER_MAX = 7f;
+
+ private final float density;
+ private final Path body = new Path(), lip = new Path(), lipTop = new Path();
+ private final Path band1 = new Path(), band2 = new Path(), sheen = new Path();
+ private final RectF crown = new RectF(10.3f, 3.1f, 13.7f, 5.5f);
+
+ private final Paint bodyPaint, lipPaint, crownPaint, outline, groove, bandDark, bandLight, sheenPaint,
+ loopDark, loopBrass, rodPaint, ballPaint, ballEdge;
+ private final Paint[] paints;
+ private final ValueAnimator animator;
+
+ private float angle, clapperAngle;
+ private float startAngle, amplitude;
+ private int direction = -1;
+ private boolean reduced;
+ private int alpha = 255;
+
+ public BellDrawable(float density) {
+ this.density = density;
+ buildPaths();
+
+ int[] brass = {0xFF6B430E, 0xFFB98424, 0xFFF0CF72, 0xFFD6A13A, 0xFF9C6A1A, 0xFF5C380A};
+ float[] stops = {0f, 0.16f, 0.33f, 0.52f, 0.8f, 1f};
+ bodyPaint = fill();
+ bodyPaint.setShader(new LinearGradient(5f, 0f, 19f, 0f, brass, stops, Shader.TileMode.CLAMP));
+ lipPaint = fill();
+ lipPaint.setShader(new LinearGradient(4.8f, 0f, 19.2f, 0f,
+ new int[]{0xFF7A4E12, 0xFFD9A43A, 0xFFFBE08A, 0xFFE3B04A, 0xFFA87420, 0xFF60400E},
+ stops, Shader.TileMode.CLAMP));
+ crownPaint = fill();
+ crownPaint.setShader(new LinearGradient(crown.left, 0f, crown.right, 0f, brass, stops,
+ Shader.TileMode.CLAMP));
+ outline = stroke(0xFF452A05, 0.55f);
+ groove = stroke(0xFF5A3608, 0.35f);
+ bandDark = stroke(0x995A3608, 0.38f);
+ bandLight = stroke(0x66FFF2C0, 0.25f);
+ sheenPaint = stroke(0xB3FFF4D2, 0.9f);
+ loopDark = stroke(0xFF452A05, 1.15f);
+ loopBrass = stroke(0xFFD6A13A, 0.55f);
+ rodPaint = stroke(0xFF4E3208, 0.75f);
+ ballPaint = fill();
+ ballPaint.setShader(new RadialGradient(11.6f, 20.7f, 1.7f,
+ new int[]{0xFFF2D27A, 0xFFB07E22, 0xFF5A3A0A}, new float[]{0f, 0.55f, 1f}, Shader.TileMode.CLAMP));
+ ballEdge = stroke(0xFF3E2604, 0.4f);
+ paints = new Paint[]{bodyPaint, lipPaint, crownPaint, outline, groove, bandDark, bandLight, sheenPaint,
+ loopDark, loopBrass, rodPaint, ballPaint, ballEdge};
+
+ animator = ValueAnimator.ofFloat(0f, 1f);
+ animator.setDuration(RING_MS);
+ animator.setInterpolator(new LinearInterpolator());
+ animator.addUpdateListener(a -> {
+ float t = (float) a.getAnimatedValue() * RING_MS / 1000f;
+ angle = swing(t);
+ float lagged = swing(Math.max(0f, t - LAG));
+ clapperAngle = Math.max(angle - CLAPPER_MAX, Math.min(angle + CLAPPER_MAX, lagged));
+ invalidateSelf();
+ });
+ animator.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator a) {
+ angle = clapperAngle = 0f;
+ invalidateSelf();
+ }
+ });
+ }
+
+ /** Rings the bell: a damped swing about the loop, with the clapper trailing. */
+ public void ring() {
+ if (reduced) return;
+ startAngle = angle;
+ direction = -direction;
+ amplitude = AMPLITUDE * direction;
+ animator.cancel();
+ animator.start();
+ }
+
+ /** With reduced motion {@link #ring()} does nothing and a swing in progress stops at rest. */
+ public void setReducedMotion(boolean reducedMotion) {
+ reduced = reducedMotion;
+ if (reduced && animator.isRunning()) animator.cancel();
+ }
+
+ /** Angle in degrees t seconds into a ring, carrying on from where the bell was when it was rung. */
+ private float swing(float t) {
+ float wt = OMEGA * t;
+ float a = (float) Math.exp(-t / TAU) * (startAngle * (float) Math.cos(wt) + amplitude * (float) Math.sin(wt));
+ if (t > 0.85f) {
+ float f = Math.min(1f, (t - 0.85f) / 0.15f);
+ a *= 1f - f * f * (3f - 2f * f);
+ }
+ return Math.max(-AMPLITUDE, Math.min(AMPLITUDE, a));
+ }
+
+ private void buildPaths() {
+ body.moveTo(9.8f, 5.0f);
+ body.cubicTo(7.6f, 5.3f, 7.0f, 7.8f, 7.0f, 10.6f);
+ body.cubicTo(7.0f, 13.6f, 6.6f, 15.6f, 5.3f, 16.9f);
+ body.quadTo(5.0f, 17.5f, 5.5f, 18.0f);
+ body.cubicTo(8.6f, 18.9f, 15.4f, 18.9f, 18.5f, 18.0f);
+ body.quadTo(19.0f, 17.5f, 18.7f, 16.9f);
+ body.cubicTo(17.4f, 15.6f, 17.0f, 13.6f, 17.0f, 10.6f);
+ body.cubicTo(17.0f, 7.8f, 16.4f, 5.3f, 14.2f, 5.0f);
+ body.quadTo(12.0f, 4.6f, 9.8f, 5.0f);
+ body.close();
+
+ lip.moveTo(5.3f, 16.9f);
+ lip.quadTo(5.0f, 17.5f, 5.5f, 18.0f);
+ lip.cubicTo(8.6f, 18.9f, 15.4f, 18.9f, 18.5f, 18.0f);
+ lip.quadTo(19.0f, 17.5f, 18.7f, 16.9f);
+ lip.cubicTo(15.4f, 17.7f, 8.6f, 17.7f, 5.3f, 16.9f);
+ lip.close();
+ lipTop.moveTo(5.3f, 16.9f);
+ lipTop.cubicTo(8.6f, 17.7f, 15.4f, 17.7f, 18.7f, 16.9f);
+
+ band1.moveTo(7.15f, 9.0f);
+ band1.cubicTo(9.5f, 9.7f, 14.5f, 9.7f, 16.85f, 9.0f);
+ band2.moveTo(6.8f, 14.9f);
+ band2.cubicTo(9.2f, 15.7f, 14.8f, 15.7f, 17.2f, 14.9f);
+
+ sheen.moveTo(9.2f, 6.2f);
+ sheen.cubicTo(8.3f, 7.8f, 8.2f, 11.4f, 8.0f, 15.0f);
+ }
+
+ @Override
+ public void draw(@NonNull Canvas c) {
+ Rect b = getBounds();
+ if (b.isEmpty()) return;
+ float s = Math.min(b.width(), b.height()) / BOX;
+ int save = alpha < 255 ? c.saveLayerAlpha(b.left, b.top, b.right, b.bottom, alpha) : c.save();
+ c.clipRect(b);
+ c.translate(b.exactCenterX() - 12f * s, b.exactCenterY() - 12f * s);
+ c.scale(s, s);
+
+ // clapper first: the body hides its top half
+ c.save();
+ c.rotate(clapperAngle, PX, PY);
+ c.drawLine(12f, 8f, 12f, 20.1f, rodPaint);
+ c.drawCircle(12f, 21.15f, 1.15f, ballPaint);
+ c.drawCircle(12f, 21.15f, 1.15f, ballEdge);
+ c.restore();
+
+ c.save();
+ c.rotate(angle, PX, PY);
+ c.drawCircle(12f, 2.35f, 1.0f, loopDark);
+ c.drawCircle(12f, 2.35f, 1.0f, loopBrass);
+ c.drawRoundRect(crown, 1.2f, 1.2f, crownPaint);
+ c.drawRoundRect(crown, 1.2f, 1.2f, outline);
+ c.drawPath(body, bodyPaint);
+ drawBand(c, band1);
+ drawBand(c, band2);
+ c.drawPath(lip, lipPaint);
+ c.drawPath(lipTop, groove);
+ // the light is fixed, so the highlight slides against the swing
+ float shift = -angle * 0.035f;
+ c.translate(shift, 0f);
+ c.drawPath(sheen, sheenPaint);
+ c.drawLine(7.0f, 17.55f, 8.6f, 17.95f, sheenPaint);
+ c.translate(-shift, 0f);
+ c.drawPath(body, outline);
+ c.restore();
+
+ c.restoreToCount(save);
+ }
+
+ private void drawBand(Canvas c, Path band) {
+ c.drawPath(band, bandDark);
+ c.translate(0f, 0.38f);
+ c.drawPath(band, bandLight);
+ c.translate(0f, -0.38f);
+ }
+
+ private static Paint fill() {
+ return new Paint(Paint.ANTI_ALIAS_FLAG);
+ }
+
+ private static Paint stroke(int color, float width) {
+ Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
+ p.setColor(color);
+ p.setStyle(Paint.Style.STROKE);
+ p.setStrokeWidth(width);
+ p.setStrokeCap(Paint.Cap.ROUND);
+ p.setStrokeJoin(Paint.Join.ROUND);
+ return p;
+ }
+
+ @Override
+ public int getIntrinsicWidth() {
+ return Math.round(BOX * density);
+ }
+
+ @Override
+ public int getIntrinsicHeight() {
+ return Math.round(BOX * density);
+ }
+
+ @Override
+ public void setAlpha(int alpha) {
+ if (this.alpha == alpha) return;
+ this.alpha = alpha;
+ invalidateSelf();
+ }
+
+ @Override
+ public int getAlpha() {
+ return alpha;
+ }
+
+ @Override
+ public void setColorFilter(@Nullable ColorFilter filter) {
+ for (Paint p : paints) p.setColorFilter(filter);
+ invalidateSelf();
+ }
+
+ @Override
+ public int getOpacity() {
+ return PixelFormat.TRANSLUCENT;
+ }
+}
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 f346f6afd..6b663b4f6 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java
@@ -60,13 +60,15 @@ final class Config {
final File wallpaper;
/** Whether the overlay file was present and parsed. */
final boolean overlayApplied;
+ /** Festive skin from a theme (festival, festival_until, greeting, accent_color); {@link Festival#NONE} if none. */
+ final Festival festival;
private Config(List<String> dockApps, List<String> hiddenApps, String liveTvPackage, String liveTvAction,
String sourcePanelService, String sourcePanelAction, String inputAction,
int columns, int rowsBelowDock, boolean animations, boolean advancedEffects,
boolean shamsiDate, boolean moduleCards, boolean reducedMotion, String vpnApp,
boolean showHomeSettingsShortcut, int backgroundColor, int skyIntensity,
- File wallpaper, boolean overlayApplied) {
+ File wallpaper, boolean overlayApplied, Festival festival) {
this.dockApps = Collections.unmodifiableList(dockApps);
this.hiddenApps = Collections.unmodifiableList(hiddenApps);
this.liveTvPackage = liveTvPackage;
@@ -87,6 +89,7 @@ final class Config {
this.skyIntensity = skyIntensity;
this.wallpaper = wallpaper;
this.overlayApplied = overlayApplied;
+ this.festival = festival;
}
/** The folder the theme tools push into; null when external storage is unavailable. */
@@ -152,11 +155,14 @@ final class Config {
if (wallpaper != null && !(wallpaper.isFile() && wallpaper.length() > 0)) wallpaper = null;
// A theme can also switch the wallpaper off while the file is still there.
if (json != null && json.has("wallpaper") && !bool(json, "wallpaper", true)) wallpaper = null;
+ // A festive skin comes only from a theme; config.xml has no festival.
+ Festival festival = json == null ? Festival.NONE : Festival.parse(string(json, "festival", ""),
+ string(json, "festival_until", ""), string(json, "greeting", ""), string(json, "accent_color", ""));
return new Config(dock, hidden, liveTv, liveTvAction, panelService, panelAction, inputAction,
Math.max(1, columns), Math.max(0, rowsBelow), animations, advancedEffects,
shamsi, moduleCards, reducedMotion, vpn, homeSettings, background,
- Math.max(0, Math.min(100, skyIntensity)), wallpaper, applied);
+ Math.max(0, Math.min(100, skyIntensity)), wallpaper, applied, festival);
}
private static void syncThemeChoices(SharedPreferences choices, File dir, File config) {
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/DiyaDrawable.java b/launcher/app/src/main/java/com/gathin/tvhome/DiyaDrawable.java
new file mode 100644
index 000000000..a4ce625d8
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/DiyaDrawable.java
@@ -0,0 +1,540 @@
+package com.gathin.tvhome;
+
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.LinearGradient;
+import android.graphics.Matrix;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.graphics.PixelFormat;
+import android.graphics.RadialGradient;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.Shader;
+import android.graphics.drawable.Animatable;
+import android.graphics.drawable.Drawable;
+import android.os.SystemClock;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import java.util.Random;
+
+/**
+ * A clay diya whose flame shows the network: the flame's height follows the signal level (1 to 4), it goes out
+ * with a wisp of smoke when the level drops to 0, and relights with a spark when it comes back. Ethernet gets a
+ * calm, steady flame. Drawn in a 24 x 24 unit box scaled into the bounds, with a dark outline so it reads on the
+ * frosted and on the white (focused) pill. The flame flickers only while started, at about 15 fps; nothing is
+ * allocated per frame. The first {@link #setFlame} call applies its level without an animation.
+ */
+public final class DiyaDrawable extends Drawable implements Animatable {
+
+ private static final float BOX = 24f;
+ private static final long FRAME_MS = 66;
+ private static final long LEVEL_MS = 300, OUT_MS = 350, SMOKE_DELAY_MS = 260, SMOKE_MS = 900;
+ private static final long OUT_END_MS = Math.max(OUT_MS, SMOKE_DELAY_MS + SMOKE_MS);
+ private static final long SPARK_MS = 200, GROW_DELAY_MS = 110, GROW_MS = 500;
+ private static final int IDLE = 0, OUT = 1, RELIGHT = 2;
+ /** Flame size for each level; index 0 is out. */
+ private static final float[] LEVEL_SCALE = {0f, 0.46f, 0.64f, 0.82f, 1f};
+ /** Where the flame stands: the wick at the tip of the spout. */
+ private static final float WICK_X = 18.5f, WICK_Y = 12.1f;
+ /** Full flame height and half width, in box units. */
+ private static final float FLAME_H = 10f, FLAME_W = 2f;
+ private static final int SMOKE_POINTS = 16;
+ /** Painted dots on the bowl, x/y pairs. */
+ private static final float[] DOTS = {5.0f, 17.6f, 7.4f, 18.5f, 9.9f, 18.8f, 12.4f, 18.4f, 14.6f, 17.3f};
+
+ private final float density;
+ private final float[] noise = new float[256];
+
+ private final Path body = new Path(), opening = new Path(), rimLip = new Path(), sheen = new Path();
+ private final Path flame = new Path(), core = new Path(), smoke = new Path();
+ private final RectF foot = new RectF(7.2f, 20.0f, 12.4f, 22.4f);
+ private final RectF oval = new RectF();
+ private final Matrix matrix = new Matrix();
+
+ private final Paint footPaint, bodyPaint, warmPaint, openingPaint, openingEdge, dotPaint, lipPaint, sheenPaint,
+ outlinePaint, wickPaint, glowPaint, flamePaint, edgePaint, corePaint, smokePaint, emberPaint, sparkPaint,
+ rayPaint;
+ private final Paint[] paints;
+ private final Shader glowShader, flameShader, coreShader, smokeShader, sparkShader;
+
+ private int level = 4;
+ private boolean primed;
+ private float scaleFrom = 1f, scaleTo = 1f;
+ private long scaleStart;
+ private int phase = IDLE;
+ private long phaseStart;
+ private float outFrom;
+ private boolean running, steady, reduced;
+ private int alpha = 255;
+ private final long epoch = SystemClock.uptimeMillis();
+
+ private final Runnable tick = new Runnable() {
+ @Override
+ public void run() {
+ long now = SystemClock.uptimeMillis();
+ update(now);
+ invalidateSelf();
+ if (wantsFrames()) scheduleSelf(this, now + FRAME_MS);
+ }
+ };
+
+ public DiyaDrawable(float density) {
+ this.density = density;
+ Random rnd = new Random(0xD1A5L);
+ for (int i = 0; i < noise.length; i++) noise[i] = rnd.nextFloat() * 2f - 1f;
+ buildLamp();
+
+ footPaint = fill(0xFF8E3E1E);
+ bodyPaint = fill(0xFFC4612F);
+ bodyPaint.setShader(new RadialGradient(7.5f, 14.5f, 13f,
+ new int[]{0xFFE58C57, 0xFFC4612F, 0xFF9A4220, 0xFF6E2C14},
+ new float[]{0f, 0.35f, 0.7f, 1f}, Shader.TileMode.CLAMP));
+ warmPaint = fill(0xFFFFB347);
+ RadialGradient warm = new RadialGradient(0f, 0f, 1f,
+ new int[]{0xA6FFB347, 0x40FF9A2A, 0x00FF8A1A}, new float[]{0f, 0.5f, 1f}, Shader.TileMode.CLAMP);
+ matrix.setScale(9f, 9f);
+ matrix.postTranslate(WICK_X, WICK_Y);
+ warm.setLocalMatrix(matrix);
+ warmPaint.setShader(warm);
+ openingPaint = fill(0xFF4A1E0E);
+ openingPaint.setShader(new LinearGradient(2.6f, 0f, 19f, 0f,
+ new int[]{0xFF3B170A, 0xFF5A2A10, 0xFF7A4416}, null, Shader.TileMode.CLAMP));
+ openingEdge = stroke(0xFF4A1A0A, 0.3f);
+ dotPaint = fill(0xFFFFE0A3);
+ lipPaint = stroke(0xFFEE9A68, 0.6f);
+ sheenPaint = stroke(0x73FFE8D2, 0.75f);
+ outlinePaint = stroke(0xFF3D1408, 0.7f);
+ wickPaint = stroke(0xFF2B140A, 0.6f);
+
+ glowPaint = fill(0xFFFFB040);
+ glowShader = new RadialGradient(0f, 0f, 1f,
+ new int[]{0x99FFC45A, 0x44FF9A2A, 0x00FF8A1A}, new float[]{0f, 0.45f, 1f}, Shader.TileMode.CLAMP);
+ glowPaint.setShader(glowShader);
+ flamePaint = fill(0xFFFF9A2A);
+ flameShader = new LinearGradient(0f, 0f, 0f, 1f,
+ new int[]{0xFFD9430B, 0xFFFF7A14, 0xFFFFA62B, 0xFFFFB83F, 0xFFF08A24},
+ new float[]{0f, 0.22f, 0.55f, 0.85f, 1f}, Shader.TileMode.CLAMP);
+ flamePaint.setShader(flameShader);
+ edgePaint = stroke(0xFFB8400A, 0.28f);
+ corePaint = fill(0xFFFFF0B8);
+ coreShader = new LinearGradient(0f, 0f, 0f, 1f,
+ new int[]{0xFFFFD25A, 0xFFFFF0B8, 0xFFFFF8E1, 0xFFFFE9A6},
+ new float[]{0f, 0.35f, 0.7f, 1f}, Shader.TileMode.CLAMP);
+ corePaint.setShader(coreShader);
+
+ smokePaint = stroke(0xFFA0A0A0, 0.6f);
+ smokeShader = new LinearGradient(0f, 0f, 0f, 1f,
+ new int[]{0x00A0A0A0, 0xB09A9A9A, 0xFF8E8E8E}, new float[]{0f, 0.4f, 1f}, Shader.TileMode.CLAMP);
+ smokePaint.setShader(smokeShader);
+ emberPaint = fill(0xFFFF5A1A);
+ sparkPaint = fill(0xFFFFF4C8);
+ sparkShader = new RadialGradient(0f, 0f, 1f,
+ new int[]{0xFFFFF4C8, 0xCCFFC24A, 0x00FF9A20}, new float[]{0f, 0.45f, 1f}, Shader.TileMode.CLAMP);
+ sparkPaint.setShader(sparkShader);
+ rayPaint = stroke(0xFFF2A12E, 0.35f);
+
+ paints = new Paint[]{footPaint, bodyPaint, warmPaint, openingPaint, openingEdge, dotPaint, lipPaint,
+ sheenPaint, outlinePaint, wickPaint, glowPaint, flamePaint, edgePaint, corePaint, smokePaint,
+ emberPaint, sparkPaint, rayPaint};
+ }
+
+ // ---- public API ----
+
+ /** 0 puts the flame out; 1 to 4 is the signal strength, which sets the flame's height. */
+ public void setFlame(int newLevel) {
+ int lvl = Math.max(0, Math.min(4, newLevel));
+ if (!primed) {
+ primed = true;
+ level = lvl;
+ snap();
+ kick();
+ return;
+ }
+ if (lvl == level) return;
+ long now = SystemClock.uptimeMillis();
+ update(now);
+ float current = flameScale(now);
+ int old = level;
+ level = lvl;
+ if (!animates()) {
+ snap();
+ } else if (lvl == 0) {
+ outFrom = current;
+ phase = OUT;
+ phaseStart = now;
+ } else if (old == 0) {
+ phase = RELIGHT;
+ phaseStart = now;
+ scaleFrom = scaleTo = LEVEL_SCALE[lvl];
+ scaleStart = now;
+ } else {
+ scaleFrom = baseScale(now);
+ scaleTo = LEVEL_SCALE[lvl];
+ scaleStart = now;
+ }
+ kick();
+ }
+
+ /** A steady flame (Ethernet) only breathes slowly and does not sway. */
+ public void setSteady(boolean steady) {
+ if (this.steady == steady) return;
+ this.steady = steady;
+ invalidateSelf();
+ }
+
+ /** With reduced motion the flame is still, there is no smoke or spark, and level changes are instant. */
+ public void setReducedMotion(boolean reducedMotion) {
+ if (reduced == reducedMotion) return;
+ reduced = reducedMotion;
+ if (reduced) snap();
+ kick();
+ }
+
+ @Override
+ public void start() {
+ if (running) return;
+ running = true;
+ kick();
+ }
+
+ @Override
+ public void stop() {
+ if (!running) return;
+ running = false;
+ snap();
+ kick();
+ }
+
+ @Override
+ public boolean isRunning() {
+ return running;
+ }
+
+ @Override
+ public boolean setVisible(boolean visible, boolean restart) {
+ boolean changed = super.setVisible(visible, restart);
+ if (changed) {
+ if (!visible) snap();
+ kick();
+ }
+ return changed;
+ }
+
+ // ---- state ----
+
+ private boolean animates() {
+ return running && !reduced && isVisible();
+ }
+
+ private boolean wantsFrames() {
+ return running && isVisible() && ((level > 0 && !reduced) || phase != IDLE);
+ }
+
+ private void kick() {
+ unscheduleSelf(tick);
+ if (wantsFrames()) scheduleSelf(tick, SystemClock.uptimeMillis() + FRAME_MS);
+ invalidateSelf();
+ }
+
+ /** Jumps to the end state of whatever is playing. */
+ private void snap() {
+ phase = IDLE;
+ scaleFrom = scaleTo = LEVEL_SCALE[level];
+ }
+
+ private void update(long now) {
+ if (phase == OUT && now - phaseStart >= OUT_END_MS) phase = IDLE;
+ else if (phase == RELIGHT && now - phaseStart >= GROW_DELAY_MS + GROW_MS) phase = IDLE;
+ }
+
+ private float baseScale(long now) {
+ float p = clamp01((now - scaleStart) / (float) LEVEL_MS);
+ return scaleFrom + (scaleTo - scaleFrom) * decel(p);
+ }
+
+ private float flameScale(long now) {
+ switch (phase) {
+ case OUT: {
+ float e = (now - phaseStart) / (float) OUT_MS;
+ return e >= 1f ? 0f : outFrom * (1f - e * e);
+ }
+ case RELIGHT: {
+ float g = (now - phaseStart - GROW_DELAY_MS) / (float) GROW_MS;
+ return g <= 0f ? 0f : baseScale(now) * backOut(Math.min(1f, g));
+ }
+ default:
+ return level == 0 ? 0f : baseScale(now);
+ }
+ }
+
+ private float flameBright(long now) {
+ if (phase != OUT) return 1f;
+ float e = clamp01((now - phaseStart) / (float) OUT_MS);
+ return 1f - e * (float) Math.sqrt(e);
+ }
+
+ // ---- drawing ----
+
+ @Override
+ public void draw(@NonNull Canvas c) {
+ Rect b = getBounds();
+ if (b.isEmpty()) return;
+ long now = SystemClock.uptimeMillis();
+ update(now);
+ float s = Math.min(b.width(), b.height()) / BOX;
+ int save = alpha < 255 ? c.saveLayerAlpha(b.left, b.top, b.right, b.bottom, alpha) : c.save();
+ c.clipRect(b);
+ c.translate(b.exactCenterX() - 12f * s, b.exactCenterY() - 12f * s);
+ c.scale(s, s);
+
+ float scale = flameScale(now);
+ float bright = flameBright(now);
+ float hMul = 1f, wMul = 1f, sway = 0f;
+ if (running && !reduced && isVisible()) {
+ float t = (now - epoch) / 1000f;
+ if (steady) {
+ float breath = sin(t / 4.2f);
+ hMul = 1f + 0.035f * breath;
+ wMul = 1f + 0.02f * breath;
+ } else {
+ hMul = 1f + 0.055f * sin(0.83f * t) + 0.035f * sin(1.71f * t + 0.21f)
+ + 0.025f * sin(2.63f * t + 0.33f) + 0.03f * noise(t * 1.9f);
+ wMul = 1f + 0.045f * sin(1.37f * t + 0.14f) + 0.03f * noise(t * 2.2f + 31f);
+ sway = 0.45f * sin(0.47f * t + 0.1f) + 0.28f * sin(1.13f * t + 0.38f) + 0.2f * noise(t * 1.3f + 17f);
+ }
+ }
+ float h = FLAME_H * scale * hMul;
+ float w = FLAME_W * Math.min(1f, scale * 2.2f) * (0.5f + 0.5f * scale) * wMul;
+ float lean = sway * scale;
+ float vis = scale * bright;
+
+ if (vis > 0.01f) {
+ float cx = WICK_X + lean * 0.4f, cy = WICK_Y - h * 0.45f;
+ float rx = 2.6f + 3.4f * scale, ry = rx * 1.2f;
+ matrix.setScale(rx, ry);
+ matrix.postTranslate(cx, cy);
+ glowShader.setLocalMatrix(matrix);
+ glowPaint.setAlpha((int) (255 * bright * (0.5f + 0.5f * scale)));
+ oval.set(cx - rx, cy - ry, cx + rx, cy + ry);
+ c.drawOval(oval, glowPaint);
+ }
+
+ drawLamp(c, vis);
+
+ if (phase == OUT) drawSmoke(c, now);
+ if (phase == RELIGHT) drawSpark(c, now);
+
+ if (h > 0.15f && bright > 0.01f) {
+ float by = WICK_Y + 0.2f;
+ teardrop(flame, WICK_X, by, h, w, lean);
+ matrix.setScale(1f, h);
+ matrix.postTranslate(0f, by - h);
+ flameShader.setLocalMatrix(matrix);
+ flamePaint.setAlpha((int) (255 * bright));
+ c.drawPath(flame, flamePaint);
+ edgePaint.setAlpha((int) (150 * bright));
+ c.drawPath(flame, edgePaint);
+
+ float cby = WICK_Y - h * 0.06f, ch = h * 0.58f, cw = w * 0.5f;
+ teardrop(core, WICK_X + lean * 0.05f, cby, ch, cw, lean * 0.55f);
+ matrix.setScale(1f, ch);
+ matrix.postTranslate(0f, cby - ch);
+ coreShader.setLocalMatrix(matrix);
+ corePaint.setAlpha((int) (255 * bright * bright));
+ c.drawPath(core, corePaint);
+ }
+ c.restoreToCount(save);
+ }
+
+ private void drawLamp(Canvas c, float warmth) {
+ c.drawOval(foot, footPaint);
+ c.drawOval(foot, outlinePaint);
+ c.drawPath(body, bodyPaint);
+ if (warmth > 0.01f) {
+ warmPaint.setAlpha((int) (190 * warmth));
+ c.drawPath(body, warmPaint);
+ }
+ c.drawPath(opening, openingPaint);
+ if (warmth > 0.01f) {
+ warmPaint.setAlpha((int) (255 * warmth));
+ c.drawPath(opening, warmPaint);
+ }
+ c.drawPath(opening, openingEdge);
+ for (int i = 0; i < DOTS.length; i += 2) c.drawCircle(DOTS[i], DOTS[i + 1], 0.42f, dotPaint);
+ c.drawPath(rimLip, lipPaint);
+ c.drawPath(sheen, sheenPaint);
+ c.drawPath(body, outlinePaint);
+ c.drawLine(WICK_X - 0.9f, WICK_Y + 0.7f, WICK_X, WICK_Y, wickPaint);
+ }
+
+ private void drawSmoke(Canvas c, long now) {
+ long since = now - phaseStart;
+ // the wick glows for a moment after the flame dies
+ float ember = 1f - since / (float) (SMOKE_DELAY_MS + SMOKE_MS * 0.6f);
+ if (ember > 0f) {
+ emberPaint.setAlpha((int) (255 * ember));
+ c.drawCircle(WICK_X, WICK_Y, 0.5f, emberPaint);
+ }
+ if (reduced) return;
+ float sp = (since - SMOKE_DELAY_MS) / (float) SMOKE_MS;
+ if (sp <= 0f || sp >= 1f) return;
+ float head = 10.5f * decel(sp);
+ float tp = (sp - 0.3f) / 0.7f;
+ float tail = tp <= 0f ? 0f : Math.min(head - 0.6f, 8.5f * tp * tp);
+ if (head - tail < 0.3f) return;
+ smoke.reset();
+ for (int i = 0; i < SMOKE_POINTS; i++) {
+ float d = tail + (head - tail) * i / (SMOKE_POINTS - 1);
+ float curl = (0.2f + 0.17f * d) * (float) Math.sin(d * 0.9f - sp * 5.5f);
+ float x = WICK_X - 0.28f * d + curl, y = WICK_Y - 0.3f - d;
+ if (i == 0) smoke.moveTo(x, y);
+ else smoke.lineTo(x, y);
+ }
+ float top = WICK_Y - 0.3f - head;
+ matrix.setScale(1f, head - tail);
+ matrix.postTranslate(0f, top);
+ smokeShader.setLocalMatrix(matrix);
+ smokePaint.setStrokeWidth(0.55f + 0.35f * sp);
+ smokePaint.setAlpha((int) (230 * (1f - sp)));
+ c.drawPath(smoke, smokePaint);
+ }
+
+ private void drawSpark(Canvas c, long now) {
+ float k = (now - phaseStart) / (float) SPARK_MS;
+ if (k >= 1.5f) return;
+ float r = 0.5f + 2.8f * decel(Math.min(1f, k));
+ float a = k < 0.25f ? k / 0.25f : 1f - (k - 0.25f) / 1.25f;
+ float cx = WICK_X, cy = WICK_Y - 0.5f;
+ matrix.setScale(r, r);
+ matrix.postTranslate(cx, cy);
+ sparkShader.setLocalMatrix(matrix);
+ sparkPaint.setAlpha((int) (255 * a));
+ c.drawCircle(cx, cy, r, sparkPaint);
+ rayPaint.setAlpha((int) (255 * a));
+ for (int i = 0; i < 4; i++) {
+ double ang = Math.toRadians(45 + 90 * i + 30 * k);
+ float cs = (float) Math.cos(ang), sn = (float) Math.sin(ang);
+ c.drawLine(cx + cs * r * 0.55f, cy + sn * r * 0.55f, cx + cs * r * 1.15f, cy + sn * r * 1.15f, rayPaint);
+ }
+ }
+
+ /** A candle-flame teardrop standing on (bx, by): round bulb low down, pointed tip leaning by {@code lean}. */
+ private static void teardrop(Path p, float bx, float by, float h, float w, float lean) {
+ float tx = bx + lean, ty = by - h;
+ float ml = lean * 0.35f;
+ float wy = by - Math.max(w * 1.1f, h * 0.24f);
+ float up = (wy - ty) * 0.35f, down = (by - wy) * 0.55f;
+ p.reset();
+ p.moveTo(tx, ty);
+ p.cubicTo(tx + w * 0.25f, ty + h * 0.3f, bx + ml + w, wy - up, bx + w, wy);
+ p.cubicTo(bx + w, wy + down, bx + w * 0.55f, by, bx, by);
+ p.cubicTo(bx - w * 0.55f, by, bx - w, wy + down, bx - w, wy);
+ p.cubicTo(bx + ml - w, wy - up, tx - w * 0.25f, ty + h * 0.3f, tx, ty);
+ p.close();
+ }
+
+ private void buildLamp() {
+ body.moveTo(1.6f, 14.2f);
+ body.cubicTo(1.8f, 18.6f, 5.4f, 21.0f, 9.6f, 21.0f);
+ body.cubicTo(13.2f, 21.0f, 15.6f, 19.4f, 16.8f, 16.6f);
+ body.cubicTo(17.6f, 15.0f, 18.6f, 13.6f, 20.2f, 12.4f);
+ body.quadTo(20.5f, 12.0f, 19.9f, 11.9f);
+ body.cubicTo(18.2f, 12.1f, 16.8f, 12.6f, 15.4f, 13.0f);
+ body.cubicTo(12.0f, 11.6f, 5.0f, 11.8f, 1.6f, 14.2f);
+ body.close();
+
+ opening.moveTo(2.6f, 14.2f);
+ opening.cubicTo(5.6f, 12.6f, 11.8f, 12.5f, 15.2f, 13.4f);
+ opening.cubicTo(16.6f, 13.0f, 17.8f, 12.7f, 19.2f, 12.4f);
+ opening.cubicTo(17.6f, 13.4f, 16.6f, 14.0f, 15.4f, 14.6f);
+ opening.cubicTo(11.6f, 16.4f, 5.0f, 16.2f, 2.6f, 14.2f);
+ opening.close();
+
+ rimLip.moveTo(2.7f, 14.65f);
+ rimLip.cubicTo(5.1f, 16.65f, 11.6f, 16.85f, 15.5f, 15.0f);
+ rimLip.cubicTo(16.7f, 14.4f, 17.7f, 13.8f, 19.4f, 12.75f);
+
+ sheen.moveTo(3.2f, 15.4f);
+ sheen.quadTo(4.0f, 18.4f, 6.9f, 19.7f);
+ }
+
+ // ---- helpers ----
+
+ private float noise(float x) {
+ int i = (int) Math.floor(x);
+ float f = x - i;
+ float s = f * f * (3f - 2f * f);
+ float a = noise[i & 255], b = noise[(i + 1) & 255];
+ return a + (b - a) * s;
+ }
+
+ /** sin of a phase given in turns. */
+ private static float sin(float turns) {
+ return (float) Math.sin(turns * 2.0 * Math.PI);
+ }
+
+ private static float clamp01(float v) {
+ return v < 0f ? 0f : (v > 1f ? 1f : v);
+ }
+
+ private static float decel(float p) {
+ float q = 1f - p;
+ return 1f - q * q;
+ }
+
+ private static float backOut(float x) {
+ float s = 1.4f, q = x - 1f;
+ return 1f + (s + 1f) * q * q * q + s * q * q;
+ }
+
+ private static Paint fill(int color) {
+ Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
+ p.setColor(color);
+ return p;
+ }
+
+ private static Paint stroke(int color, float width) {
+ Paint p = fill(color);
+ p.setStyle(Paint.Style.STROKE);
+ p.setStrokeWidth(width);
+ p.setStrokeCap(Paint.Cap.ROUND);
+ p.setStrokeJoin(Paint.Join.ROUND);
+ return p;
+ }
+
+ @Override
+ public int getIntrinsicWidth() {
+ return Math.round(BOX * density);
+ }
+
+ @Override
+ public int getIntrinsicHeight() {
+ return Math.round(BOX * density);
+ }
+
+ @Override
+ public void setAlpha(int alpha) {
+ if (this.alpha == alpha) return;
+ this.alpha = alpha;
+ invalidateSelf();
+ }
+
+ @Override
+ public int getAlpha() {
+ return alpha;
+ }
+
+ @Override
+ public void setColorFilter(@Nullable ColorFilter filter) {
+ for (Paint p : paints) p.setColorFilter(filter);
+ invalidateSelf();
+ }
+
+ @Override
+ public int getOpacity() {
+ return PixelFormat.TRANSLUCENT;
+ }
+}
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Festival.java b/launcher/app/src/main/java/com/gathin/tvhome/Festival.java
new file mode 100644
index 000000000..dd67b01f4
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/Festival.java
@@ -0,0 +1,84 @@
+package com.gathin.tvhome;
+
+import java.time.LocalDate;
+import java.time.format.DateTimeParseException;
+import java.util.Locale;
+
+/**
+ * A festive skin set by a theme's config.json: {@code festival}, {@code festival_until}, {@code greeting}
+ * and {@code accent_color}. While it is active the pills get festive icons (a diya for the network, a bell
+ * for Inputs, a marigold for Settings), the greeting is replaced and the focus glow takes the accent colour.
+ * It switches itself off after {@code festival_until}, so nobody has to remember to undo it.
+ */
+final class Festival {
+
+ static final Festival NONE = new Festival("", null, "", 0);
+
+ /** Warm diya gold, the accent when a theme names a festival but no colour. */
+ static final int DEFAULT_ACCENT = 0xFFFFB23C;
+
+ /** Lower-case festival name, or "" for none. */
+ final String name;
+ /** Last day the skin shows, inclusive; null for no end date. */
+ final LocalDate until;
+ /** Text that replaces the time-of-day greeting; "" uses the festival's own default. */
+ final String greeting;
+ /** Focus glow colour as 0xAARRGGBB, or 0 for {@link #DEFAULT_ACCENT}. */
+ final int accent;
+
+ private Festival(String name, LocalDate until, String greeting, int accent) {
+ this.name = name;
+ this.until = until;
+ this.greeting = greeting;
+ this.accent = accent;
+ }
+
+ /**
+ * Builds the skin from raw config values. Anything malformed turns the skin off rather than leaving a
+ * festival on the screen forever: an unreadable end date or an empty name gives {@link #NONE}.
+ */
+ static Festival parse(String name, String until, String greeting, String accent) {
+ String n = name == null ? "" : name.trim().toLowerCase(Locale.ROOT);
+ if (n.isEmpty() || n.length() > 40) return NONE;
+ LocalDate end = null;
+ if (until != null && !until.trim().isEmpty()) {
+ try {
+ end = LocalDate.parse(until.trim());
+ } catch (DateTimeParseException e) {
+ return NONE;
+ }
+ }
+ String g = greeting == null ? "" : Cards.cleanLabel(greeting, "");
+ return new Festival(n, end, g, parseColor(accent));
+ }
+
+ /** Whether the skin shows today. */
+ boolean active(LocalDate today) {
+ return !name.isEmpty() && (until == null || !today.isAfter(until));
+ }
+
+ /** The greeting to show while active, or "" to keep the normal time-of-day greeting. */
+ String greetingText() {
+ if (!greeting.isEmpty()) return greeting;
+ switch (name) {
+ case "dussehra":
+ return "Happy Dussehra";
+ case "diwali":
+ return "Happy Diwali";
+ default:
+ return "";
+ }
+ }
+
+ int accentColor() {
+ return accent != 0 ? accent : DEFAULT_ACCENT;
+ }
+
+ /** {@code #RRGGBB} to an opaque colour, anything else to 0. */
+ static int parseColor(String s) {
+ if (s == null) return 0;
+ String t = s.trim();
+ if (!t.matches("#[0-9A-Fa-f]{6}")) return 0;
+ return 0xFF000000 | Integer.parseInt(t.substring(1), 16);
+ }
+}
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/GlassView.java b/launcher/app/src/main/java/com/gathin/tvhome/GlassView.java
index 6b3fa85ed..6479ada02 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/GlassView.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/GlassView.java
@@ -22,6 +22,10 @@ public class GlassView extends View {
private final RectF rect = new RectF();
private final float density;
private float radius;
+ /** Glow colour as 0xRRGGBB: white normally, a festival's accent (diya gold) while a festive skin is on. */
+ private int glowRgb = 0xFFFFFF;
+ /** Glow strength: the white glow stays faint, a coloured one needs more alpha to read as warm light. */
+ private int glowAlpha = 0x30;
public GlassView(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -37,6 +41,23 @@ public class GlassView extends View {
setLayerType(LAYER_TYPE_HARDWARE, null);
}
+ /** Tints the rim and the outer glow; 0 restores the plain white glass. */
+ void setAccent(int argb) {
+ if (argb == 0) {
+ glowRgb = 0xFFFFFF;
+ glowAlpha = 0x30;
+ rim.setColor(0xCCFFFFFF);
+ } else {
+ glowRgb = argb & 0xFFFFFF;
+ glowAlpha = 0x70;
+ // The rim is the accent lifted towards white, so the edge still reads as glass, not paint.
+ int r = (((glowRgb >> 16) & 0xFF) + 255 * 2) / 3, g = (((glowRgb >> 8) & 0xFF) + 255 * 2) / 3,
+ b = ((glowRgb & 0xFF) + 255 * 2) / 3;
+ rim.setColor(0xE6000000 | (r << 16) | (g << 8) | b);
+ }
+ invalidate();
+ }
+
void setRadius(float px) {
radius = px;
invalidate();
@@ -58,7 +79,7 @@ public class GlassView extends View {
// they cost one draw, not one per frame of the spring.
for (int i = 1; i <= 3; i++) {
glow.setStrokeWidth(i * 2f * density);
- glow.setColor((0x30 / i) << 24 | 0xFFFFFF);
+ glow.setColor((glowAlpha / i) << 24 | glowRgb);
float o = i * density;
canvas.drawRoundRect(rect.left - o, rect.top - o, rect.right + o, rect.bottom + o, radius + o, radius + o, glow);
}
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 653182d8e..a2375c73f 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -20,6 +20,7 @@ import android.graphics.Rect;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
import android.media.tv.TvContract;
import android.media.tv.TvInputInfo;
import android.media.tv.TvInputManager;
@@ -62,6 +63,7 @@ import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.io.File;
+import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
@@ -121,6 +123,15 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
private boolean moduleCards;
/** Calmer motion for weak GPUs (config.xml, reduced_motion): stiff spring, short fades, no replay. */
private boolean reducedMotion;
+ /** Festive skin from the theme (see Festival); applied while it is active today. */
+ private Festival festival = Festival.NONE;
+ private boolean festive;
+ private DiyaDrawable diya;
+ private BellDrawable bell;
+ private MarigoldDrawable marigold;
+ private int greetingColor;
+ /** The day the petal shower last played, so it greets the first Home of each day only. */
+ private static LocalDate lastPetalShower;
/** hidden_apps as the adapter sees them (config.xml or a theme's config.json): a hidden app gets no card either. */
private Set<String> hiddenApps = Collections.emptySet();
private List<Cards.Card> cards = Collections.emptyList();
@@ -202,6 +213,8 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
animations = cfg.animations;
advancedEffects = cfg.animations && cfg.advancedEffects;
reducedMotion = cfg.reducedMotion;
+ festival = cfg.festival;
+ festive = festival.active(LocalDate.now());
liveTvPkg = cfg.liveTvPackage;
liveTvAction = cfg.liveTvAction;
inputAction = cfg.inputAction;
@@ -214,12 +227,14 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
sky = findViewById(R.id.sky);
sky.setIntensity(cfg.skyIntensity);
glass = findViewById(R.id.glass);
+ if (festive) glass.setAccent(festival.accentColor());
ambient = findViewById(R.id.ambient);
// The glow is one bitmap, so its alpha can be applied while drawing it. Otherwise every frame of
// a fade renders it into a full-screen offscreen buffer first.
ambient.forceHasOverlappingRendering(false);
heroName = findViewById(R.id.heroName);
greeting = findViewById(R.id.greeting);
+ greetingColor = greeting.getCurrentTextColor();
btnWifi = findViewById(R.id.btnWifi);
shamsiDate = findViewById(R.id.shamsiDate);
shamsi = cfg.shamsiDate;
@@ -347,6 +362,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
.setDuration(160).start());
}
}
+ if (festive) applyFestiveSkin((TextView) btnInputs, (TextView) btnSettings);
// Hide the glass when focus leaves the tiles.
getWindow().getDecorView().getViewTreeObserver().addOnGlobalFocusChangeListener((oldF, newF) -> {
@@ -425,6 +441,11 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
@Override
protected void onResume() {
super.onResume();
+ // A festival that started or ended while Home was in the background: rebuild with or without it.
+ if (festive != festival.active(LocalDate.now())) {
+ recreate();
+ return;
+ }
promptsPaused = false;
if (rebuildOnResume) {
tilesReady = false;
@@ -436,6 +457,14 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
updateInputsButton();
sky.update();
handler.postDelayed(minuteTick, MINUTE_MS);
+ if (festive && diya != null) {
+ diya.start();
+ LocalDate today = LocalDate.now();
+ if (!reducedMotion && !today.equals(lastPetalShower)) {
+ lastPetalShower = today;
+ handler.postDelayed(this::playPetalShower, 450);
+ }
+ }
}
@Override
@@ -513,6 +542,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
heroName.animate().cancel();
ambient.animate().cancel();
handler.removeCallbacks(minuteTick);
+ if (diya != null) diya.stop();
// Nothing of ours stays on screen over another app; an undecided prompt simply returns next time.
if (cardPrompt != null) cardPrompt.dismiss();
if (openPopup != null) openPopup.dismiss();
@@ -818,7 +848,14 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
else if (hour < 17) res = R.string.good_afternoon;
else if (hour < 22) res = R.string.good_evening;
else res = R.string.good_night;
- greeting.setText(res);
+ String festiveGreeting = festive ? festival.greetingText() : "";
+ if (!festiveGreeting.isEmpty()) {
+ greeting.setText(festiveGreeting);
+ greeting.setTextColor(liftTowardsWhite(festival.accentColor(), 0.25f));
+ } else {
+ greeting.setText(res);
+ greeting.setTextColor(greetingColor);
+ }
if (shamsi) shamsiDate.setText(Shamsi.today());
}
@@ -827,6 +864,9 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
String text = getString(R.string.wifi);
boolean vpn = false, online = false;
int icon = R.drawable.ic_wifi;
+ // The diya's flame: 0 is out (offline), 1 to 4 follow the Wi-Fi signal, Ethernet burns steady at 4.
+ int flame = 0;
+ boolean steady = false;
try {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
boolean wifi = false, ethernet = false;
@@ -849,10 +889,13 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
} else if (ethernet) {
text = getString(R.string.ethernet);
icon = R.drawable.ic_ethernet;
+ flame = 4;
+ steady = true;
} else if (wifi) {
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wm != null ? wm.getConnectionInfo() : null;
String ssid = info != null ? info.getSSID() : null;
+ flame = info != null ? Math.max(1, Math.min(4, WifiManager.calculateSignalLevel(info.getRssi(), 5))) : 3;
if (ssid != null) {
ssid = ssid.replace("\"", "").trim();
if (!ssid.isEmpty() && !ssid.contains("unknown") && !ssid.equals("0x")) text = ssid;
@@ -879,7 +922,64 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
} else {
btnWifi.setText(text);
}
- btnWifi.setCompoundDrawablesRelativeWithIntrinsicBounds(icon, 0, 0, 0);
+ if (festive && diya != null) {
+ if (online && flame == 0) flame = 3; // online some other way (cellular, USB tethering)
+ diya.setSteady(steady);
+ diya.setFlame(flame);
+ } else {
+ btnWifi.setCompoundDrawablesRelativeWithIntrinsicBounds(icon, 0, 0, 0);
+ }
+ }
+
+ // ---- festive skin ------------------------------------------------------------------------------
+
+ /**
+ * Swaps the pill icons for the festival's: a bell for Inputs that swings when focused, a diya for the
+ * network whose flame follows the connection, and a marigold for Settings that turns when focused.
+ */
+ private void applyFestiveSkin(TextView inputs, TextView settings) {
+ bell = new BellDrawable(density);
+ marigold = new MarigoldDrawable(density);
+ diya = new DiyaDrawable(density);
+ bell.setReducedMotion(reducedMotion);
+ marigold.setReducedMotion(reducedMotion);
+ diya.setReducedMotion(reducedMotion);
+ setFestiveIcon(inputs, bell);
+ setFestiveIcon(btnWifi, diya);
+ setFestiveIcon(settings, marigold);
+ addFocusAction(inputs, bell::ring);
+ addFocusAction(settings, marigold::turn);
+ }
+
+ private static void setFestiveIcon(TextView pill, Drawable icon) {
+ // The pills tint their icons to follow focus; the festive ones keep their own colours.
+ pill.setCompoundDrawableTintList(null);
+ pill.setCompoundDrawablesRelativeWithIntrinsicBounds(icon, null, null, null);
+ }
+
+ /** Runs {@code action} when the view gains focus, keeping any focus listener it already had. */
+ private static void addFocusAction(View view, Runnable action) {
+ View.OnFocusChangeListener previous = view.getOnFocusChangeListener();
+ view.setOnFocusChangeListener((v, focused) -> {
+ if (previous != null) previous.onFocusChange(v, focused);
+ if (focused) action.run();
+ });
+ }
+
+ private void playPetalShower() {
+ if (isFinishing() || isDestroyed()) return;
+ PetalShowerView shower = new PetalShowerView(this);
+ root.addView(shower, new FrameLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ shower.play(28, 1800, () -> root.removeView(shower));
+ }
+
+ private static int liftTowardsWhite(int argb, float amount) {
+ int r = (argb >> 16) & 0xFF, g = (argb >> 8) & 0xFF, b = argb & 0xFF;
+ r += (int) ((255 - r) * amount);
+ g += (int) ((255 - g) * amount);
+ b += (int) ((255 - b) * amount);
+ return 0xFF000000 | (r << 16) | (g << 8) | b;
}
/** The network pill opens the VPN app when one is configured and installed, otherwise Wi-Fi settings. */
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/MarigoldDrawable.java b/launcher/app/src/main/java/com/gathin/tvhome/MarigoldDrawable.java
new file mode 100644
index 000000000..80e064d60
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MarigoldDrawable.java
@@ -0,0 +1,286 @@
+package com.gathin.tvhome;
+
+import android.animation.ValueAnimator;
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.graphics.PixelFormat;
+import android.graphics.RadialGradient;
+import android.graphics.Rect;
+import android.graphics.Shader;
+import android.graphics.drawable.Drawable;
+import android.view.animation.DecelerateInterpolator;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import java.util.Random;
+
+/**
+ * A marigold (genda phool) seen from the front: four rings of ruffled petals, deep saffron outside to golden
+ * inside, around a dark centre. Petal shapes and colours come from a fixed seed and are built once. Light comes
+ * from the top left and stays there while the flower turns, and each ring shades the base of the one behind it.
+ * {@link #turn()} rotates the flower a further 60 degrees; the inner rings turn slightly more than the outer
+ * ones. Drawn in a 24 x 24 unit box scaled into the bounds.
+ */
+public final class MarigoldDrawable extends Drawable {
+
+ private static final float BOX = 24f, C = 12f;
+ private static final int[] COUNT = {13, 11, 9, 7};
+ private static final float[] RADIUS = {11.6f, 9.4f, 7.2f, 5.0f};
+ /** How much faster each ring turns than the outer one, so a turn ruffles the flower a little. */
+ private static final float[] SPIN = {1f, 1.04f, 1.09f, 1.15f};
+ private static final float CORE_SPIN = 1.2f;
+ private static final int[][] SHADES = {
+ {0xFFE5600A, 0xFFF0800E}, {0xFFF0800E, 0xFFF79A16}, {0xFFF9A31B, 0xFFFFB524}, {0xFFFFB524, 0xFFFFC63E}};
+ private static final float CORE_R = 2.9f;
+ /** Direction the light comes from (top left), in degrees with y pointing down. */
+ private static final float LIGHT_DEG = 225f;
+ private static final int LIT = 0xFFFFE9A6, SHADOWED = 0xFFA43E00, EDGE = 0xFF6E2400;
+ /** Shadows fall a little down and right of each ring, away from the light. */
+ private static final float SHADOW_DX = 0.35f, SHADOW_DY = 0.45f;
+ private static final long TURN_MS = 900;
+
+ private final float density;
+ private final Path[][] petals = new Path[COUNT.length][];
+ private final float[][] angles = new float[COUNT.length][];
+ private final int[][] colors = new int[COUNT.length][];
+ private final int[][] edges = new int[COUNT.length][];
+ private final float[] shadowR = new float[COUNT.length];
+ private final Paint[] shadowPaints = new Paint[COUNT.length];
+ private final Path core = new Path();
+ private final float[] seeds = new float[18];
+
+ private final Paint fill, edge, coreFill, coreEdge, seedPaint;
+ private final Paint[] paints;
+ private final ValueAnimator animator;
+
+ private double rotation, from, target;
+ private boolean reduced;
+ private int alpha = 255;
+
+ public MarigoldDrawable(float density) {
+ this.density = density;
+ Random rnd = new Random(0x6E7DAL);
+ for (int i = 0; i < COUNT.length; i++) buildRing(i, rnd);
+ buildCore(rnd);
+
+ fill = new Paint(Paint.ANTI_ALIAS_FLAG);
+ edge = new Paint(Paint.ANTI_ALIAS_FLAG);
+ edge.setStyle(Paint.Style.STROKE);
+ edge.setStrokeWidth(0.3f);
+ edge.setStrokeJoin(Paint.Join.ROUND);
+ for (int i = 0; i < COUNT.length; i++) {
+ float inner = i + 1 < COUNT.length ? RADIUS[i + 1] : CORE_R;
+ float sr = inner + 0.6f * (RADIUS[i] - inner);
+ float q = inner / sr;
+ shadowR[i] = sr;
+ Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
+ p.setShader(new RadialGradient(C + SHADOW_DX, C + SHADOW_DY, sr,
+ new int[]{0x805A1E00, 0x805A1E00, 0x665A1E00, 0x005A1E00},
+ new float[]{0f, q * 0.9f, q, 1f}, Shader.TileMode.CLAMP));
+ shadowPaints[i] = p;
+ }
+ coreFill = new Paint(Paint.ANTI_ALIAS_FLAG);
+ coreFill.setShader(new RadialGradient(C - 0.7f, C - 0.7f, 3.6f,
+ new int[]{0xFFE0821A, 0xFFB04E08, 0xFF7A3004}, new float[]{0f, 0.5f, 1f}, Shader.TileMode.CLAMP));
+ coreEdge = new Paint(Paint.ANTI_ALIAS_FLAG);
+ coreEdge.setStyle(Paint.Style.STROKE);
+ coreEdge.setStrokeWidth(0.3f);
+ coreEdge.setStrokeJoin(Paint.Join.ROUND);
+ coreEdge.setColor(0xFF5C2403);
+ seedPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
+ seedPaint.setColor(0xFFFFB84A);
+
+ paints = new Paint[COUNT.length + 5];
+ System.arraycopy(shadowPaints, 0, paints, 0, COUNT.length);
+ paints[COUNT.length] = fill;
+ paints[COUNT.length + 1] = edge;
+ paints[COUNT.length + 2] = coreFill;
+ paints[COUNT.length + 3] = coreEdge;
+ paints[COUNT.length + 4] = seedPaint;
+
+ animator = ValueAnimator.ofFloat(0f, 1f);
+ animator.setDuration(TURN_MS);
+ animator.setInterpolator(new DecelerateInterpolator(1.6f));
+ animator.addUpdateListener(a -> {
+ rotation = from + (target - from) * (float) a.getAnimatedValue();
+ invalidateSelf();
+ });
+ }
+
+ /** Turns the flower a further 60 degrees, easing to a stop. Repeated calls add up smoothly. */
+ public void turn() {
+ if (reduced) return;
+ from = rotation;
+ target += 60.0;
+ animator.cancel();
+ animator.start();
+ }
+
+ /** With reduced motion {@link #turn()} does nothing; a turn in progress jumps to its end. */
+ public void setReducedMotion(boolean reducedMotion) {
+ reduced = reducedMotion;
+ if (reduced && animator.isRunning()) animator.end();
+ }
+
+ // ---- geometry, built once ----
+
+ private void buildRing(int ring, Random rnd) {
+ int n = COUNT[ring];
+ petals[ring] = new Path[n];
+ angles[ring] = new float[n];
+ colors[ring] = new int[n];
+ edges[ring] = new int[n];
+ float offset = ring * (180f / n) + (rnd.nextFloat() - 0.5f) * 8f;
+ float edgeDepth = ring == 0 ? 0.55f : 0.45f;
+ for (int j = 0; j < n; j++) {
+ float deg = offset + j * 360f / n + (rnd.nextFloat() - 0.5f) * 10f;
+ float r = RADIUS[ring] * (0.96f + 0.04f * rnd.nextFloat());
+ float hw = (float) (Math.PI / n) * (1.18f + 0.15f * rnd.nextFloat());
+ int scallops = 3 + rnd.nextInt(2);
+ petals[ring][j] = petal((float) Math.toRadians(deg), hw, r * 0.25f, r, scallops, rnd);
+ angles[ring][j] = deg;
+ int base = lerp(SHADES[ring][0], SHADES[ring][1], rnd.nextFloat());
+ colors[ring][j] = base;
+ edges[ring][j] = lerp(base, EDGE, edgeDepth);
+ }
+ }
+
+ /** One petal: narrow at the base, fanning out to a frilled, notched edge. */
+ private static Path petal(float a, float hw, float r0, float r, int scallops, Random rnd) {
+ Path p = new Path();
+ float a0 = a - hw, a1 = a + hw;
+ p.moveTo(px(r0, a - hw * 0.35f), py(r0, a - hw * 0.35f));
+ float sideA = a0 - hw * 0.08f;
+ p.quadTo(px(r * 0.62f, sideA), py(r * 0.62f, sideA), px(r * 0.86f, a0), py(r * 0.86f, a0));
+ int steps = scallops * 2;
+ for (int k = 1; k < steps; k += 2) {
+ float ta = a0 + (a1 - a0) * k / steps + (rnd.nextFloat() - 0.5f) * hw * 0.12f;
+ float na = a0 + (a1 - a0) * (k + 1) / steps;
+ float tr = r * (1.0f + 0.06f * rnd.nextFloat());
+ float nr = k + 1 >= steps ? r * 0.86f : r * (0.83f + 0.06f * rnd.nextFloat());
+ p.quadTo(px(tr, ta), py(tr, ta), px(nr, na), py(nr, na));
+ }
+ float sideB = a1 + hw * 0.08f;
+ float endA = a + hw * 0.35f;
+ p.quadTo(px(r * 0.62f, sideB), py(r * 0.62f, sideB), px(r0, endA), py(r0, endA));
+ p.close();
+ return p;
+ }
+
+ private void buildCore(Random rnd) {
+ int bumps = 18;
+ for (int k = 0; k <= bumps * 2; k++) {
+ float a = (float) (Math.PI * k / bumps);
+ float r = (k % 2 == 1) ? CORE_R * (1.0f + 0.06f * rnd.nextFloat()) : CORE_R * 0.84f;
+ if (k == 0) core.moveTo(px(r, a), py(r, a));
+ else if (k % 2 == 1) {
+ float na = (float) (Math.PI * (k + 1) / bumps);
+ float nr = CORE_R * 0.84f;
+ core.quadTo(px(r, a), py(r, a), px(nr, na), py(nr, na));
+ }
+ }
+ core.close();
+ // tiny florets in a sunflower spiral
+ double golden = Math.PI * (3 - Math.sqrt(5));
+ for (int k = 0; k < seeds.length / 2; k++) {
+ float r = 0.62f * (float) Math.sqrt(k + 0.5);
+ float a = (float) (k * golden);
+ seeds[k * 2] = px(r, a);
+ seeds[k * 2 + 1] = py(r, a);
+ }
+ }
+
+ // ---- drawing ----
+
+ @Override
+ public void draw(@NonNull Canvas c) {
+ Rect b = getBounds();
+ if (b.isEmpty()) return;
+ float s = Math.min(b.width(), b.height()) / BOX;
+ int save = alpha < 255 ? c.saveLayerAlpha(b.left, b.top, b.right, b.bottom, alpha) : c.save();
+ c.clipRect(b);
+ c.translate(b.exactCenterX() - C * s, b.exactCenterY() - C * s);
+ c.scale(s, s);
+
+ for (int i = 0; i < COUNT.length; i++) {
+ float rot = (float) ((rotation * SPIN[i]) % 360.0);
+ c.save();
+ c.rotate(rot, C, C);
+ Path[] ring = petals[i];
+ for (int j = 0; j < ring.length; j++) {
+ float l = (float) Math.cos(Math.toRadians(angles[i][j] + rot - LIGHT_DEG));
+ int base = colors[i][j];
+ fill.setColor(l >= 0f ? lerp(base, LIT, 0.3f * l) : lerp(base, SHADOWED, -0.24f * l));
+ c.drawPath(ring[j], fill);
+ edge.setColor(edges[i][j]);
+ c.drawPath(ring[j], edge);
+ }
+ c.restore();
+ c.drawCircle(C + SHADOW_DX, C + SHADOW_DY, shadowR[i], shadowPaints[i]);
+ }
+
+ c.save();
+ c.rotate((float) ((rotation * CORE_SPIN) % 360.0), C, C);
+ c.drawPath(core, coreFill);
+ c.drawPath(core, coreEdge);
+ for (int k = 0; k < seeds.length; k += 2) c.drawCircle(seeds[k], seeds[k + 1], 0.26f, seedPaint);
+ c.restore();
+
+ c.restoreToCount(save);
+ }
+
+ // ---- helpers ----
+
+ private static float px(float r, float a) {
+ return C + r * (float) Math.cos(a);
+ }
+
+ private static float py(float r, float a) {
+ return C + r * (float) Math.sin(a);
+ }
+
+ private static int lerp(int a, int b, float t) {
+ int ar = (a >> 16) & 0xFF, ag = (a >> 8) & 0xFF, ab = a & 0xFF;
+ int br = (b >> 16) & 0xFF, bg = (b >> 8) & 0xFF, bb = b & 0xFF;
+ return 0xFF000000
+ | ((int) (ar + (br - ar) * t) << 16)
+ | ((int) (ag + (bg - ag) * t) << 8)
+ | (int) (ab + (bb - ab) * t);
+ }
+
+ @Override
+ public int getIntrinsicWidth() {
+ return Math.round(BOX * density);
+ }
+
+ @Override
+ public int getIntrinsicHeight() {
+ return Math.round(BOX * density);
+ }
+
+ @Override
+ public void setAlpha(int alpha) {
+ if (this.alpha == alpha) return;
+ this.alpha = alpha;
+ invalidateSelf();
+ }
+
+ @Override
+ public int getAlpha() {
+ return alpha;
+ }
+
+ @Override
+ public void setColorFilter(@Nullable ColorFilter filter) {
+ for (Paint p : paints) p.setColorFilter(filter);
+ invalidateSelf();
+ }
+
+ @Override
+ public int getOpacity() {
+ return PixelFormat.TRANSLUCENT;
+ }
+}
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/PetalShowerView.java b/launcher/app/src/main/java/com/gathin/tvhome/PetalShowerView.java
new file mode 100644
index 000000000..a32bea782
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/PetalShowerView.java
@@ -0,0 +1,230 @@
+package com.gathin.tvhome;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.os.SystemClock;
+import android.util.AttributeSet;
+import android.view.View;
+
+import java.util.Random;
+
+/**
+ * A transparent full-screen overlay that plays a one-off shower of marigold petals. Each petal drops in from
+ * just above the top edge, gathers speed as it falls, sways from side to side, spins, flips over (showing its
+ * darker back) and fades out over the last quarter of its fall. Everything finishes within the given duration,
+ * then the callback runs on the main thread. The view takes no focus, clicks or accessibility, uses a hardware
+ * layer only while playing, and allocates nothing per frame.
+ */
+public final class PetalShowerView extends View {
+
+ private static final int[] COLORS = {0xFFFF8C1A, 0xFFFFB627, 0xFFF26A0D, 0xFFFFC93C, 0xFFE85D04};
+ private static final int EDGE = 0xFF7A2800;
+ private static final double TAU = 2 * Math.PI;
+
+ private final float density;
+ private final Random rnd = new Random();
+ private final Path[] shapes = new Path[3];
+ private final Path[] veins = new Path[3];
+ private final Paint fill = new Paint(Paint.ANTI_ALIAS_FLAG);
+ private final Paint edge = new Paint(Paint.ANTI_ALIAS_FLAG);
+ private final Paint vein = new Paint(Paint.ANTI_ALIAS_FLAG);
+
+ // per-petal state, grown only when a bigger shower is asked for
+ private int count;
+ private float[] xFrac = new float[0], delay = new float[0], life = new float[0], drop = new float[0],
+ size = new float[0], swayAmp = new float[0], swayFreq = new float[0], swayPhase = new float[0],
+ rot0 = new float[0], spin = new float[0], flipFreq = new float[0], flipPhase = new float[0];
+ private int[] color = new int[0], shape = new int[0];
+
+ private boolean playing;
+ private long start, duration;
+ private Runnable onDone;
+ private final Runnable finish = this::finish;
+
+ public PetalShowerView(Context context) {
+ this(context, null);
+ }
+
+ public PetalShowerView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public PetalShowerView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ density = context.getResources().getDisplayMetrics().density;
+ setFocusable(false);
+ setClickable(false);
+ setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
+ setWillNotDraw(false);
+
+ Random seeded = new Random(0x9E7A1L);
+ for (int i = 0; i < shapes.length; i++) {
+ shapes[i] = petalShape(seeded);
+ veins[i] = veinPath(seeded);
+ }
+ edge.setStyle(Paint.Style.STROKE);
+ edge.setStrokeWidth(0.045f);
+ edge.setStrokeJoin(Paint.Join.ROUND);
+ vein.setStyle(Paint.Style.STROKE);
+ vein.setStrokeWidth(0.035f);
+ vein.setStrokeCap(Paint.Cap.ROUND);
+ vein.setColor(EDGE);
+ }
+
+ /**
+ * Plays a shower of {@code petals} petals lasting {@code durationMs}, then runs {@code done} on the main
+ * thread. Playing again before the last shower ends finishes that one first (its callback runs).
+ */
+ public void play(int petals, long durationMs, Runnable done) {
+ if (playing) {
+ removeCallbacks(finish);
+ finish();
+ }
+ int n = Math.max(0, petals);
+ ensureCapacity(n);
+ count = n;
+ duration = Math.max(1, durationMs);
+ onDone = done;
+ for (int i = 0; i < n; i++) {
+ xFrac[i] = (i + rnd.nextFloat()) / n; // spread evenly across the width
+ delay[i] = rnd.nextFloat() * 0.32f; // fractions of the duration
+ life[i] = 0.6f + rnd.nextFloat() * (1f - delay[i] - 0.6f);
+ drop[i] = 0.8f + rnd.nextFloat() * 0.35f; // fraction of the height fallen over its life
+ size[i] = 9f + rnd.nextFloat() * 7f; // dp
+ swayAmp[i] = 10f + rnd.nextFloat() * 24f; // dp
+ swayFreq[i] = 0.5f + rnd.nextFloat() * 0.6f; // Hz
+ swayPhase[i] = rnd.nextFloat() * (float) TAU;
+ rot0[i] = rnd.nextFloat() * 360f;
+ spin[i] = (40f + rnd.nextFloat() * 120f) * (rnd.nextBoolean() ? 1f : -1f); // degrees per second
+ flipFreq[i] = 0.4f + rnd.nextFloat(); // Hz
+ flipPhase[i] = rnd.nextFloat() * (float) TAU;
+ color[i] = rnd.nextInt(COLORS.length);
+ shape[i] = rnd.nextInt(shapes.length);
+ }
+ playing = true;
+ start = SystemClock.uptimeMillis();
+ postDelayed(finish, duration);
+ postInvalidateOnAnimation();
+ }
+
+ private void finish() {
+ if (!playing) return;
+ playing = false;
+ invalidate();
+ Runnable done = onDone;
+ onDone = null;
+ if (done != null) done.run();
+ }
+
+ @Override
+ protected void onDetachedFromWindow() {
+ super.onDetachedFromWindow();
+ if (playing) {
+ removeCallbacks(finish);
+ finish();
+ }
+ }
+
+ @Override
+ protected void onDraw(Canvas c) {
+ if (!playing) return;
+ long now = SystemClock.uptimeMillis();
+ float elapsed = (now - start) / (float) duration;
+ float secs = (now - start) / 1000f;
+ float w = getWidth(), h = getHeight();
+ for (int i = 0; i < count; i++) {
+ float p = (elapsed - delay[i]) / life[i];
+ if (p <= 0f || p >= 1f) continue;
+ float len = size[i] * density;
+ float fall = (p + p * p) * 0.5f; // gathers speed, like a petal against the air
+ float y = -len * 1.5f + (h * drop[i] + len * 1.5f) * fall;
+ double sway = TAU * swayFreq[i] * secs + swayPhase[i];
+ float x = xFrac[i] * w + swayAmp[i] * density * (float) Math.sin(sway);
+ float angle = rot0[i] + spin[i] * secs + 22f * (float) Math.cos(sway); // tilts into the sway
+ float flip = (float) Math.cos(TAU * flipFreq[i] * secs + flipPhase[i]);
+ float sx = Math.abs(flip) < 0.08f ? (flip < 0f ? -0.08f : 0.08f) : flip;
+ int a = p > 0.75f ? (int) (255 * (1f - (p - 0.75f) / 0.25f)) : 255;
+
+ // turned edge-on it looks darker; the back is darker still
+ float shade = (flip < 0f ? 0.78f : 1f) * (0.8f + 0.2f * Math.abs(flip));
+ int base = COLORS[color[i]];
+ fill.setColor(scale(base, shade));
+ fill.setAlpha(a);
+ edge.setColor(scale(base, 0.55f));
+ edge.setAlpha(a * 3 / 4);
+ vein.setAlpha(a / 4);
+
+ c.save();
+ c.translate(x, y);
+ c.rotate(angle);
+ c.scale(len * sx, len);
+ c.drawPath(shapes[shape[i]], fill);
+ c.drawPath(shapes[shape[i]], edge);
+ c.drawPath(veins[shape[i]], vein);
+ c.restore();
+ }
+ postInvalidateOnAnimation();
+ }
+
+ private void ensureCapacity(int n) {
+ if (xFrac.length >= n) return;
+ xFrac = new float[n];
+ delay = new float[n];
+ life = new float[n];
+ drop = new float[n];
+ size = new float[n];
+ swayAmp = new float[n];
+ swayFreq = new float[n];
+ swayPhase = new float[n];
+ rot0 = new float[n];
+ spin = new float[n];
+ flipFreq = new float[n];
+ flipPhase = new float[n];
+ color = new int[n];
+ shape = new int[n];
+ }
+
+ /** One marigold petal, 1 unit tall around the origin: a narrow base fanning out to a frilled top. */
+ private static Path petalShape(Random r) {
+ Path p = new Path();
+ float wTop = 0.36f + 0.08f * r.nextFloat();
+ p.moveTo(0f, 0.5f);
+ p.cubicTo(-0.16f, 0.36f, -wTop - 0.04f, 0.02f, -wTop, -0.3f);
+ int scallops = 4 + r.nextInt(2);
+ for (int k = 0; k < scallops; k++) {
+ float tx = -wTop + 2 * wTop * (k + 0.5f) / scallops;
+ float nx = -wTop + 2 * wTop * (k + 1f) / scallops;
+ float tipY = -0.5f + 0.2f * sq(tx / wTop) - 0.06f - 0.05f * r.nextFloat();
+ float notchY = k == scallops - 1 ? -0.3f : -0.5f + 0.2f * sq(nx / wTop) + 0.05f + 0.03f * r.nextFloat();
+ p.quadTo(tx, tipY, nx, notchY);
+ }
+ p.cubicTo(wTop + 0.04f, 0.02f, 0.16f, 0.36f, 0f, 0.5f);
+ p.close();
+ return p;
+ }
+
+ private static Path veinPath(Random r) {
+ Path p = new Path();
+ float bend = (r.nextFloat() - 0.5f) * 0.06f;
+ p.moveTo(0f, 0.42f);
+ p.quadTo(bend, 0f, 0f, -0.36f);
+ p.moveTo(0f, 0.3f);
+ p.quadTo(-0.12f, -0.05f, -0.2f, -0.3f);
+ p.moveTo(0f, 0.3f);
+ p.quadTo(0.12f, -0.05f, 0.2f, -0.3f);
+ return p;
+ }
+
+ private static float sq(float v) {
+ return v * v;
+ }
+
+ private static int scale(int c, float f) {
+ int r = Math.min(255, (int) (((c >> 16) & 0xFF) * f));
+ int g = Math.min(255, (int) (((c >> 8) & 0xFF) * f));
+ int b = Math.min(255, (int) ((c & 0xFF) * f));
+ return 0xFF000000 | (r << 16) | (g << 8) | b;
+ }
+}
diff --git a/launcher/app/src/test/java/com/gathin/tvhome/FestivalTest.java b/launcher/app/src/test/java/com/gathin/tvhome/FestivalTest.java
new file mode 100644
index 000000000..e2786f72f
--- /dev/null
+++ b/launcher/app/src/test/java/com/gathin/tvhome/FestivalTest.java
@@ -0,0 +1,50 @@
+package com.gathin.tvhome;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.time.LocalDate;
+
+import org.junit.Test;
+
+public class FestivalTest {
+
+ private static final LocalDate DAY = LocalDate.of(2026, 10, 20);
+
+ @Test
+ public void activeThroughTheLastDayInclusive() {
+ Festival f = Festival.parse("Dussehra", "2026-10-21", "", "");
+ assertTrue(f.active(DAY));
+ assertTrue(f.active(DAY.plusDays(1)));
+ assertFalse(f.active(DAY.plusDays(2)));
+ }
+
+ @Test
+ public void noEndDateStaysOn() {
+ assertTrue(Festival.parse("diwali", "", "", "").active(DAY.plusYears(1)));
+ }
+
+ @Test
+ public void malformedValuesTurnTheSkinOff() {
+ assertSame(Festival.NONE, Festival.parse("", "2026-10-21", "", ""));
+ assertSame(Festival.NONE, Festival.parse("dussehra", "21/10/2026", "", ""));
+ assertFalse(Festival.NONE.active(DAY));
+ }
+
+ @Test
+ public void greetingDefaultsByFestivalAndCanBeOverridden() {
+ assertEquals("Happy Dussehra", Festival.parse("dussehra", "", "", "").greetingText());
+ assertEquals("Happy Diwali", Festival.parse("DIWALI", "", "", "").greetingText());
+ assertEquals("", Festival.parse("onam", "", "", "").greetingText());
+ assertEquals("Shubho Bijoya", Festival.parse("dussehra", "", " Shubho‮ Bijoya ", "").greetingText());
+ }
+
+ @Test
+ public void accentFallsBackToDiyaGold() {
+ assertEquals(Festival.DEFAULT_ACCENT, Festival.parse("dussehra", "", "", "").accentColor());
+ assertEquals(0xFF102030, Festival.parse("dussehra", "", "", "#102030").accentColor());
+ assertEquals(Festival.DEFAULT_ACCENT, Festival.parse("dussehra", "", "", "gold").accentColor());
+ }
+}
diff --git a/themes/dussehra/config.json b/themes/dussehra/config.json
index 039a1d6e4..705ae4aa0 100644
--- a/themes/dussehra/config.json
+++ b/themes/dussehra/config.json
@@ -1,4 +1,7 @@
{
- "background_color": "#12081A",
+ "festival": "dussehra",
+ "festival_until": "2026-10-21",
+ "accent_color": "#FFB23C",
+ "background_color": "#120809",
"wallpaper": true
}