Skip to content

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

launcher: lunar_date, the Vietnamese / Chinese lunisolar date under the date

VGS4158a879e30f
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 f56a54dad..a781f9772 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java
@@ -70,6 +70,9 @@ final class Config {
final boolean advancedEffects;
final int rowsBelowDock;
final boolean shamsiDate;
+ /** Lunisolar date under the date (config.json lunar_date), computed for lunarUtcOffset hours east of UTC (-1: by locale). */
+ final boolean lunarDate;
+ final int lunarUtcOffset;
/** Name after the greeting ("Good morning, Mr. Trịnh"); empty for the greeting alone. */
final String greetingName;
final boolean moduleCards;
@@ -178,7 +181,7 @@ final class Config {
Festival festival, int[] inputKeycodes, List<String> appKeys, String stockHomeRedirect,
List<RaceWeekend.Race> raceCalendar, boolean cinematicHome, boolean ambientGlow, boolean appGlow, int homeIdleClockMinutes,
boolean keyFilter, boolean dockGlass, String glowStyle, boolean wallpaperCaptions,
- boolean handleViewInputs) {
+ boolean handleViewInputs, boolean lunarDate, int lunarUtcOffset) {
this.handleViewInputs = handleViewInputs;
this.inputKeycodes = inputKeycodes;
this.appKeys = Collections.unmodifiableList(appKeys);
@@ -204,6 +207,8 @@ final class Config {
this.animations = animations;
this.advancedEffects = advancedEffects;
this.shamsiDate = shamsiDate;
+ this.lunarDate = lunarDate;
+ this.lunarUtcOffset = lunarUtcOffset;
this.greetingName = greetingName;
this.moduleCards = moduleCards;
this.reducedMotion = reducedMotion;
@@ -280,6 +285,8 @@ final class Config {
boolean animations = res.getBoolean(R.bool.animations);
boolean advancedEffects = res.getBoolean(R.bool.advanced_effects);
boolean shamsi = res.getBoolean(R.bool.shamsi_date);
+ boolean lunar = res.getBoolean(R.bool.lunar_date);
+ int lunarOffset = -1;
String greetingName = res.getString(R.string.greeting_name).trim();
boolean moduleCards = res.getBoolean(R.bool.module_cards);
boolean reducedMotion = res.getBoolean(R.bool.reduced_motion);
@@ -345,6 +352,8 @@ final class Config {
animations = bool(json, "animations", animations);
advancedEffects = bool(json, "advanced_effects", advancedEffects);
shamsi = bool(json, "shamsi_date", shamsi);
+ lunar = bool(json, "lunar_date", lunar);
+ lunarOffset = integer(json, "lunar_utc_offset", lunarOffset, -1, 14);
greetingName = string(json, "greeting_name", greetingName).trim();
moduleCards = bool(json, "module_cards", moduleCards);
reducedMotion = bool(json, "reduced_motion", reducedMotion);
@@ -443,7 +452,7 @@ final class Config {
Math.max(0, Math.min(100, skyIntensity)), settingsKeycodes, settingsKeyPanel, restoreKeyServices, wallpaperEnabled, wallpaper,
wallpapers, rotationMinutes, wallpaperDim, dockOpacity, wallpaperOrder, applied,
festival, inputKeycodes, appKeys, stockHomeRedirect, json == null ? Collections.emptyList() : raceCalendar(json), cinematic, ambientGlow, appGlow,
- Math.max(0, idleClockMinutes), keyFilter, dockGlass, glowStyle, wallpaperCaptions, handleViewInputs);
+ Math.max(0, idleClockMinutes), keyFilter, dockGlass, glowStyle, wallpaperCaptions, handleViewInputs, lunar, lunarOffset);
}
/**
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Lunar.java b/launcher/app/src/main/java/com/gathin/tvhome/Lunar.java
new file mode 100644
index 000000000..41817804b
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/Lunar.java
@@ -0,0 +1,132 @@
+package com.gathin.tvhome;
+
+import android.content.res.Resources;
+
+import java.util.Calendar;
+import java.util.Locale;
+
+/**
+ * Lunisolar (Vietnamese / Chinese) date, e.g. "2/9 âm lịch · Bính Ngọ" or "Lunar 2/9 · Year of the Horse", without ICU.
+ * The astronomy is Hồ Ngọc Đức's public algorithm (new moons and solar terms from Jean Meeus' formulas); the only
+ * difference between the Vietnamese and the Chinese calendar is the time zone it is computed for (UTC+7 or UTC+8),
+ * which now and then moves a new moon, and with it the first day of a month, by one day.
+ */
+final class Lunar {
+
+ private Lunar() {
+ }
+
+ /** Hours east of UTC used for the calendar: lunar_utc_offset, or 7 for Vietnamese and 8 otherwise. */
+ static int offsetFor(int configured, Locale locale) {
+ if (configured >= 0) return configured;
+ return "vi".equals(locale.getLanguage()) ? 7 : 8;
+ }
+
+ /** Today's lunar date, formatted with the locale's strings. */
+ static String today(Resources res, int utcOffset) {
+ Calendar c = Calendar.getInstance();
+ int[] l = fromSolar(c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.MONTH) + 1, c.get(Calendar.YEAR), utcOffset);
+ String month = l[3] == 1 ? res.getString(R.string.lunar_month_leap, l[1]) : String.valueOf(l[1]);
+ String[] stems = res.getStringArray(R.array.lunar_stems);
+ String[] branches = res.getStringArray(R.array.lunar_branches);
+ String year = res.getString(R.string.lunar_year, stems[Math.floorMod(l[2] + 6, 10)], branches[Math.floorMod(l[2] + 8, 12)]);
+ return res.getString(R.string.lunar_date_format, l[0], month, year);
+ }
+
+ /** Gregorian date to {day, month, year, leap (1 = leap month)} of the lunar calendar at UTC+tz. */
+ static int[] fromSolar(int dd, int mm, int yy, double tz) {
+ long dayNumber = jdFromDate(dd, mm, yy);
+ int k = (int) Math.floor((dayNumber - 2415021.076998695) / 29.530588853);
+ long monthStart = newMoonDay(k + 1, tz);
+ if (monthStart > dayNumber) monthStart = newMoonDay(k, tz);
+ long a11 = lunarMonth11(yy, tz);
+ long b11 = a11;
+ int lunarYear;
+ if (a11 >= monthStart) {
+ lunarYear = yy;
+ a11 = lunarMonth11(yy - 1, tz);
+ } else {
+ lunarYear = yy + 1;
+ b11 = lunarMonth11(yy + 1, tz);
+ }
+ int lunarDay = (int) (dayNumber - monthStart + 1);
+ int diff = (int) Math.floor((monthStart - a11) / 29.0);
+ int leap = 0;
+ int lunarMonth = diff + 11;
+ if (b11 - a11 > 365) {
+ int leapDiff = leapMonthOffset(a11, tz);
+ if (diff >= leapDiff) {
+ lunarMonth = diff + 10;
+ if (diff == leapDiff) leap = 1;
+ }
+ }
+ if (lunarMonth > 12) lunarMonth -= 12;
+ if (lunarMonth >= 11 && diff < 4) lunarYear -= 1;
+ return new int[]{lunarDay, lunarMonth, lunarYear, leap};
+ }
+
+ static long jdFromDate(int dd, int mm, int yy) {
+ int a = (14 - mm) / 12;
+ long y = yy + 4800 - a;
+ int m = mm + 12 * a - 3;
+ long jd = dd + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 32045;
+ if (jd < 2299161) jd = dd + (153 * m + 2) / 5 + 365 * y + y / 4 - 32083;
+ return jd;
+ }
+
+ /** Day number of the k-th new moon after 1900-01-01, in local time. */
+ static long newMoonDay(int k, double tz) {
+ double t = k / 1236.85, t2 = t * t, t3 = t2 * t, dr = Math.PI / 180;
+ double jd1 = 2415020.75933 + 29.53058868 * k + 0.0001178 * t2 - 0.000000155 * t3;
+ jd1 += 0.00033 * Math.sin((166.56 + 132.87 * t - 0.009173 * t2) * dr);
+ double m = 359.2242 + 29.10535608 * k - 0.0000333 * t2 - 0.00000347 * t3;
+ double mpr = 306.0253 + 385.81691806 * k + 0.0107306 * t2 + 0.00001236 * t3;
+ double f = 21.2964 + 390.67050646 * k - 0.0016528 * t2 - 0.00000239 * t3;
+ double c1 = (0.1734 - 0.000393 * t) * Math.sin(m * dr) + 0.0021 * Math.sin(2 * dr * m);
+ c1 -= 0.4068 * Math.sin(mpr * dr) + 0.0161 * Math.sin(dr * 2 * mpr);
+ c1 -= 0.0004 * Math.sin(dr * 3 * mpr);
+ c1 += 0.0104 * Math.sin(dr * 2 * f) - 0.0051 * Math.sin(dr * (m + mpr));
+ c1 -= 0.0074 * Math.sin(dr * (m - mpr)) + 0.0004 * Math.sin(dr * (2 * f + m));
+ c1 -= 0.0004 * Math.sin(dr * (2 * f - m)) - 0.0006 * Math.sin(dr * (2 * f + mpr));
+ c1 += 0.0010 * Math.sin(dr * (2 * f - mpr)) + 0.0005 * Math.sin(dr * (2 * mpr + m));
+ double deltaT = t < -11
+ ? 0.001 + 0.000839 * t + 0.0002261 * t2 - 0.00000845 * t3 - 0.000000081 * t * t3
+ : -0.000278 + 0.000265 * t + 0.000262 * t2;
+ return (long) Math.floor(jd1 + c1 - deltaT + 0.5 + tz / 24);
+ }
+
+ /** Which of the 12 thirty-degree sectors the sun's longitude is in at the start of the day. */
+ static int sunLongitude(long jdn, double tz) {
+ double t = (jdn - 2451545.5 - tz / 24) / 36525, t2 = t * t, dr = Math.PI / 180;
+ double m = 357.52910 + 35999.05030 * t - 0.0001559 * t2 - 0.00000048 * t * t2;
+ double l0 = 280.46645 + 36000.76983 * t + 0.0003032 * t2;
+ double dl = (1.914600 - 0.004817 * t - 0.000014 * t2) * Math.sin(dr * m);
+ dl += (0.019993 - 0.000101 * t) * Math.sin(dr * 2 * m) + 0.000290 * Math.sin(dr * 3 * m);
+ double l = (l0 + dl) * dr;
+ l -= Math.PI * 2 * Math.floor(l / (Math.PI * 2));
+ return (int) Math.floor(l / Math.PI * 6);
+ }
+
+ /** First day of the 11th lunar month (the one holding the winter solstice) of a Gregorian year. */
+ static long lunarMonth11(int yy, double tz) {
+ long off = jdFromDate(31, 12, yy) - 2415021;
+ int k = (int) Math.floor(off / 29.530588853);
+ long nm = newMoonDay(k, tz);
+ if (sunLongitude(nm, tz) >= 9) nm = newMoonDay(k - 1, tz);
+ return nm;
+ }
+
+ /** Index of the leap month after month 11 in a 13-month year: the first month with no solar term. */
+ static int leapMonthOffset(long a11, double tz) {
+ int k = (int) Math.floor((a11 - 2415021.076998695) / 29.530588853 + 0.5);
+ int i = 1;
+ int arc = sunLongitude(newMoonDay(k + i, tz), tz);
+ int last;
+ do {
+ last = arc;
+ i++;
+ arc = sunLongitude(newMoonDay(k + i, tz), tz);
+ } while (arc != last && i < 14);
+ return i - 1;
+ }
+}
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 183e582af..5d476c3d2 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -167,6 +167,10 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
/** The pills have been filled in once; later resumes refresh them after the first frame. */
private boolean pillsShown;
private TextView shamsiDate;
+ /** lunar_date: the lunisolar date under the date line, and the time zone it is computed for. */
+ private TextView lunarDate;
+ private boolean lunar;
+ private int lunarOffset;
private TextView stats;
private List<RaceWeekend.Race> raceCalendar;
private View racePanel;
@@ -421,11 +425,16 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
raceSessions = findViewById(R.id.raceSessions);
showStats = cfg.showStats;
shamsi = cfg.shamsiDate;
+ lunarDate = findViewById(R.id.lunarDate);
+ lunar = cfg.lunarDate;
+ lunarOffset = Lunar.offsetFor(cfg.lunarUtcOffset, Locale.getDefault());
+ if (lunar) lunarDate.setVisibility(View.VISIBLE);
greetingName = cfg.greetingName;
if (shamsi) {
shamsiDate.setVisibility(View.VISIBLE);
TextView date = findViewById(R.id.date);
date.setTextSize(11f);
+ lunarDate.setTextSize(11f);
date.setPadding(0, (int) (4 * density), 0, 0);
}
vpnApp = cfg.vpnApp;
@@ -2138,6 +2147,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
greeting.setTextColor(greetingColor);
}
if (shamsi) shamsiDate.setText(Shamsi.today(getResources()));
+ if (lunar) lunarDate.setText(Lunar.today(getResources(), lunarOffset));
}
// ---- race-weekend panel (a theme's race_calendar) -----------------------------------------------
diff --git a/launcher/app/src/main/res/layout-iw/activity_main.xml b/launcher/app/src/main/res/layout-iw/activity_main.xml
index f11791c68..fc8f17aee 100644
--- a/launcher/app/src/main/res/layout-iw/activity_main.xml
+++ b/launcher/app/src/main/res/layout-iw/activity_main.xml
@@ -215,6 +215,22 @@
android:fontFamily="@string/font_regular"
android:letterSpacing="0.14"
android:textAllCaps="true" />
+
+ <!-- Lunar date ("Lunar 13/9 · Year of the Horse"), shown when lunar_date is on. -->
+ <TextView
+ android:id="@+id/lunarDate"
+ android:gravity="right"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="4dp"
+ android:singleLine="true"
+ android:ellipsize="end"
+ android:textColor="#80FFFFFF"
+ android:textSize="14sp"
+ android:fontFamily="@font/outfit_regular"
+ android:letterSpacing="0.14"
+ android:textAllCaps="true"
+ android:visibility="gone" />
</LinearLayout>
<View
diff --git a/launcher/app/src/main/res/layout/activity_main.xml b/launcher/app/src/main/res/layout/activity_main.xml
index c5d56e735..0a379dc93 100644
--- a/launcher/app/src/main/res/layout/activity_main.xml
+++ b/launcher/app/src/main/res/layout/activity_main.xml
@@ -270,6 +270,22 @@
android:fontFamily="@string/font_regular"
android:letterSpacing="0.14"
android:textAllCaps="true" />
+
+ <!-- Lunar date ("Lunar 13/9 · Year of the Horse"), shown when lunar_date is on. -->
+ <TextView
+ android:id="@+id/lunarDate"
+ android:gravity="left"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="4dp"
+ android:singleLine="true"
+ android:ellipsize="end"
+ android:textColor="#80FFFFFF"
+ android:textSize="14sp"
+ android:fontFamily="@font/outfit_regular"
+ android:letterSpacing="0.14"
+ android:textAllCaps="true"
+ android:visibility="gone" />
</LinearLayout>
</LinearLayout>
diff --git a/launcher/app/src/main/res/values-vi/strings.xml b/launcher/app/src/main/res/values-vi/strings.xml
index 03277318a..de371a107 100644
--- a/launcher/app/src/main/res/values-vi/strings.xml
+++ b/launcher/app/src/main/res/values-vi/strings.xml
@@ -112,4 +112,15 @@
<string name="race_countdown_hours">%1$d giờ %2$d phút</string>
<string name="race_countdown_days">%1$d ngày %2$d giờ</string>
<string name="last_opened">Mở lần cuối %1$s</string>
+ <string name="lunar_date_format">%1$d/%2$s âm lịch · %3$s</string>
+ <string name="lunar_month_leap">%1$d nhuận</string>
+ <string name="lunar_year">%1$s %2$s</string>
+ <string-array name="lunar_stems">
+ <item>Giáp</item><item>Ất</item><item>Bính</item><item>Đinh</item><item>Mậu</item>
+ <item>Kỷ</item><item>Canh</item><item>Tân</item><item>Nhâm</item><item>Quý</item>
+ </string-array>
+ <string-array name="lunar_branches">
+ <item>Tý</item><item>Sửu</item><item>Dần</item><item>Mão</item><item>Thìn</item><item>Tỵ</item>
+ <item>Ngọ</item><item>Mùi</item><item>Thân</item><item>Dậu</item><item>Tuất</item><item>Hợi</item>
+ </string-array>
</resources>
diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xml
index 141d9dd14..6bc5149b1 100644
--- a/launcher/app/src/main/res/values/config.xml
+++ b/launcher/app/src/main/res/values/config.xml
@@ -177,6 +177,8 @@
<!-- Show the Solar Hijri (Shamsi) date used in Iran and Afghanistan, e.g. "27 Mehr 1405", above the
Gregorian date. -->
<bool name="shamsi_date">false</bool>
+ <!-- Lunisolar (Vietnamese / Chinese) date under the date; config.json lunar_date, lunar_utc_offset (7 or 8, default by locale). -->
+ <bool name="lunar_date">false</bool>
<!-- A name after the greeting: "Mr. Trịnh" shows GOOD MORNING, MR. TRỊNH. Empty: the greeting alone. -->
<string name="greeting_name" translatable="false"></string>
diff --git a/launcher/app/src/main/res/values/strings.xml b/launcher/app/src/main/res/values/strings.xml
index 1a385d403..e3eaea861 100644
--- a/launcher/app/src/main/res/values/strings.xml
+++ b/launcher/app/src/main/res/values/strings.xml
@@ -23,6 +23,18 @@
<string name="date_format">EEEE d MMMM</string>
<!-- Date next to the clock on Home; a locale can split it over two lines with \n. -->
<string name="date_format_home" translatable="false">@string/date_format</string>
+ <!-- Lunar date under the date: day, month, year name. -->
+ <string name="lunar_date_format">Lunar %1$d/%2$s · %3$s</string>
+ <string name="lunar_month_leap">%1$d (leap)</string>
+ <string name="lunar_year">Year of the %2$s</string>
+ <string-array name="lunar_stems">
+ <item>Jia</item><item>Yi</item><item>Bing</item><item>Ding</item><item>Wu</item>
+ <item>Ji</item><item>Geng</item><item>Xin</item><item>Ren</item><item>Gui</item>
+ </string-array>
+ <string-array name="lunar_branches">
+ <item>Rat</item><item>Ox</item><item>Tiger</item><item>Rabbit</item><item>Dragon</item><item>Snake</item>
+ <item>Horse</item><item>Goat</item><item>Monkey</item><item>Rooster</item><item>Dog</item><item>Pig</item>
+ </string-array>
<string name="shamsi_month_farvardin">Farvardin</string>
<string name="shamsi_month_ordibehesht">Ordibehesht</string>
<string name="shamsi_month_khordad">Khordad</string>
diff --git a/launcher/app/src/test/java/com/gathin/tvhome/LunarTest.java b/launcher/app/src/test/java/com/gathin/tvhome/LunarTest.java
new file mode 100644
index 000000000..81e7ff455
--- /dev/null
+++ b/launcher/app/src/test/java/com/gathin/tvhome/LunarTest.java
@@ -0,0 +1,41 @@
+package com.gathin.tvhome;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+
+/** Known lunar dates (Vietnamese calendar, UTC+7 unless noted). Arrays are {day, month, year, leap}. */
+public class LunarTest {
+
+ @Test
+ public void lunarNewYear() {
+ assertArrayEquals(new int[]{1, 1, 2024, 0}, Lunar.fromSolar(10, 2, 2024, 7));
+ assertArrayEquals(new int[]{1, 1, 2025, 0}, Lunar.fromSolar(29, 1, 2025, 7));
+ assertArrayEquals(new int[]{1, 1, 2026, 0}, Lunar.fromSolar(17, 2, 2026, 7));
+ assertArrayEquals(new int[]{1, 1, 2027, 0}, Lunar.fromSolar(6, 2, 2027, 7));
+ }
+
+ @Test
+ public void dayBeforeNewYearBelongsToTheOldYear() {
+ assertArrayEquals(new int[]{29, 12, 2025, 0}, Lunar.fromSolar(16, 2, 2026, 7));
+ }
+
+ @Test
+ public void midAutumn() {
+ assertArrayEquals(new int[]{15, 8, 2024, 0}, Lunar.fromSolar(17, 9, 2024, 7));
+ assertArrayEquals(new int[]{15, 8, 2025, 0}, Lunar.fromSolar(6, 10, 2025, 7));
+ }
+
+ @Test
+ public void leapSixthMonth2025() {
+ assertArrayEquals(new int[]{1, 6, 2025, 1}, Lunar.fromSolar(25, 7, 2025, 7));
+ assertArrayEquals(new int[]{1, 6, 2025, 0}, Lunar.fromSolar(25, 6, 2025, 7));
+ }
+
+ @Test
+ public void vietnamAndChinaDifferIn1985() {
+ // The 1985 new year: 21 January in Vietnam (UTC+7), 20 February in China (UTC+8).
+ assertArrayEquals(new int[]{1, 1, 1985, 0}, Lunar.fromSolar(21, 1, 1985, 7));
+ assertArrayEquals(new int[]{1, 1, 1985, 0}, Lunar.fromSolar(20, 2, 1985, 8));
+ }
+}
diff --git a/themes/README.md b/themes/README.md
index d43bc1a52..ef405ef3a 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -60,6 +60,8 @@ is ignored, and a file that doesn't parse is ignored as a whole, so a theme can
| `wallpaper_true_color` | bool | Decode wallpapers in 32-bit colour (8 MB at 1080p) instead of RGB_565 (4 MB), which bands dark gradients such as a night sky; for TVs with 2 GB or more (`false` by default) |
| `app_library` | bool | An App library pill after the last Home row: every installed app, add one to Home or take it off (`false` by default). The choices stay on the TV when a theme is pushed or reset; see [docs/app-library.md](../docs/app-library.md) |
| `shamsi_date` | bool | Show the Solar Hijri date above the Gregorian one |
+| `lunar_date` | bool | Show the lunisolar date under the Gregorian one, e.g. `LUNAR 13/9 · YEAR OF THE HORSE`, or `13/9 ÂM LỊCH · BÍNH NGỌ` in Vietnamese; a leap month is marked. Off by default |
+| `lunar_utc_offset` | 0 to 14 | Hours east of UTC the lunar calendar is computed for: `7` is the Vietnamese calendar, `8` the Chinese one; they differ by a day now and then (and by a month in 1985). Unset: 7 when the TV is in Vietnamese, 8 otherwise |
| `greeting_name` | string | A name after the greeting, e.g. `"Mr. Trịnh"` for GOOD MORNING, MR. TRỊNH; empty for the greeting alone |
| `module_cards` | bool | Look for module cards and ask about them (`true`); `false` turns the feature off |
| `reduced_motion` | bool | Calmer motion for weak GPUs: highlight settles in 5 frames, animations 90 ms or less, no fades, no tile entrance |