Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.
Python adbadblockandroid-tvandroid-tv-launcherapple-tvbloatware-removalclaude-codedebloatfire-tvgoogle-tvlauncherprivacysmart-tvsony-braviatclvibe-codingxiaomi
addons: Lịch Vạn Niên, an offline Vietnamese lunar almanac card
Tung Phan Vancb7e471243d4
diff --git a/addons/README.md b/addons/README.mdindex 96f5fcfc0..e3cdfcd91 100644--- a/addons/README.md+++ b/addons/README.md@@ -40,6 +40,7 @@ the core bigger or change how it behaves. You install an add-on only if you want| [TV Inspector](tv-inspector/) | What the remote sends (key name, key code, scan code, device) and what the TV can play: display modes, HDR, video decoders, audio outputs and formats, input devices; every line also in logcat for a `tv.json` or a bug report | [@shaharukhs](https://github.com/shaharukhs) | Sansui TV (Skyworth eleonas, MediaTek MT9676), Android TV 14 | None | <img src="tv-inspector/screenshot.jpg" width="240" alt="TV Inspector on a TV"> || [Game Day](game-day/) | Each team's next game on Home, counted down ("Puck drop in 2h 18m", then "Live now"), from calendar links you add: any team, any sport, no scores; one turn per team, rotating, with the theme's F1 weekend | [@justin-newman](https://github.com/justin-newman) | Hisense 75U75N (hengshan), Google TV 12 | `INTERNET` (your calendar links only) | <img src="game-day/screenshot.jpg" width="240" alt="Game Day on a TV"> || [Haunted](haunted/) | A Halloween screensaver (and a card that starts it): the theme's night photos crossfading, bats drifting across, a ghost floating up, a flickering jack-o'-lantern glow and a small clock, drawn on the TV with no network | CleanYourTV contributors | Not yet tested on a real TV | None | <img src="haunted/screenshot.jpg" width="240" alt="Haunted on a TV"> |+| [Lịch Vạn Niên](lich-van-nien/) | Vietnamese lunar almanac, offline: the tile says whether today is hoàng đạo (auspicious) or hắc đạo and lists the day's good hours; OK opens the lunar date, can chi, the day's star and trực, a 12-hour ring with the zodiac animals, and what the day suits or should avoid; Left/Right page through days | [@mevvmevvcodinggarg](https://github.com/mevvmevvcodinggarg) | Expressluck AiPro4K (sepolia), Android TV 14 | start at boot (re-enable today's tile) | <img src="lich-van-nien/screenshot.jpg" width="240" alt="Lịch Vạn Niên on a TV"> |A widget, an info tile, a storage or smart-home card: if it can live as its own small app, it can livehere. See the rules below.diff --git a/addons/lich-van-nien/.gitignore b/addons/lich-van-nien/.gitignorenew file mode 100644index 000000000..b1ba6bbc2--- /dev/null+++ b/addons/lich-van-nien/.gitignore@@ -0,0 +1,3 @@+/.gradle/+/local.properties+/**/build/diff --git a/addons/lich-van-nien/DESIGN.md b/addons/lich-van-nien/DESIGN.mdnew file mode 100644index 000000000..926f24a50--- /dev/null+++ b/addons/lich-van-nien/DESIGN.md@@ -0,0 +1,204 @@+# Lịch Vạn Niên add-on: design++Status: implemented (03/11/2026); the user-facing summary is in README.md.++## Intent++The owner wants to glance at Home from the bed and know whether today is a good day (hoàng đạo) or a+bad one (hắc đạo) and which hours are good, without pressing anything. Pressing OK on the tile opens+a calm full screen with the lunar date, the can chi of day/month/year, the 12 double-hours with the good+ones marked, and what the day suits or should avoid.++Success: the tile always shows today's verdict and good hours in Vietnamese with diacritics, it changes by+itself after midnight Vietnam time, the numbers agree with published Vietnamese lịch vạn niên, and the+screen is readable from the bed and driven only by the D-pad.++## Goals++- Home tile: today's "Hoàng đạo" / "Hắc đạo" plus the six good double-hours, visible without focus.+- Detail screen (layout approved: "Bản phác 3", see Visual below).+- Fully offline, UTC+7, no INTERNET permission, no background service.+- Unit tests for can chi, hoàng đạo day, giờ hoàng đạo, trực, checked against published days.++## Non-goals++- No changes to `launcher/`, `config.xml`, `work/theme-*`; no `tools/theme.sh`; no reinstalling or+ force-stopping `com.gathin.tvhome`. Tile placement on Home belongs to the theme session.+- No accessibility service (on this firmware a key-filtering one breaks hold-to-repeat volume).+- No screensaver, no notifications, no settings screen, no other locales (Vietnamese UI only).+- No 28 sao (nhị thập bát tú), no tuổi xung/hợp, no personal horoscope.+- Upstream: one folder under `addons/`, a row in `addons/README.md`; no change under `launcher/`.++## Anti-goals++- Wrong verdicts. A day shown as hoàng đạo that published calendars call hắc đạo is a failure even if+ everything else works.+- A tile that is stale (yesterday's verdict) after the owner wakes up.+- Anything that wakes the TV, runs continuously, or costs RAM while not on screen (TV has 1.8 GB).+- Busy, cheap-looking UI. The owner rejected the first two mockups as ugly; the approved look is restrained.++## Constraints (from the launcher contract, verified in source)++- Card rules (`docs/specs/card.md`): one card per package; label 1–24 and caption ≤32 chars from+ `A-Z a-z 0-9 space . & + ' -` only (no diacritics, no colon). Changing the label re-prompts the owner,+ so the label is fixed: **`Lich Van Nien`**. The decision is keyed by package + signer + folded label,+ not by component, so switching which alias carries the card does not re-prompt.+- The card must sit on an exported, enabled activity with `MAIN` + `LEANBACK_LAUNCHER`; an+ `activity-alias` qualifies (it is returned by the package-manager query like an activity).+- Caption only shows while the tile is focused and is cut to ~26 chars with the label, so the+ information lives in the **banner**. The launcher loads the banner per activity+ (`AppAdapter.loadBanner`: `ri.activityInfo.banner`, else the application banner), so each alias can+ carry its own banner.+- The launcher listens for `PACKAGE_CHANGED` and rebuilds tiles; enabling/disabling an alias with+ `PackageManager.setComponentEnabledSetting(..., DONT_KILL_APP)` sends it. To be verified on the TV.+- Gradle project of its own like `addons/jewish-calendar`: minSdk 26, target/compile 34, Java 17,+ AGP 8.5.2, `local.properties` `sdk.dir=/Users/tungpv/Library/Android/sdk`, JAVA_HOME openjdk@17.+ Copy `gradlew`, `gradlew.bat`, `gradle/`, `.gitignore` from `addons/jewish-calendar`.++## How the tile changes daily++- 12 `activity-alias` entries, all targeting `CalendarActivity`, each with both intent filters+ (`LEANBACK_LAUNCHER`, `com.gathin.tvhome.category.DOCK_CARD`), the card `meta-data`, and its own+ `android:banner`. Variant = (good/bad day) × (hour set). Giờ hoàng đạo depend only on the day's chi,+ and chi pairs six apart share a set, so there are 6 hour sets:+ - Tý/Ngọ: Tý Sửu Mão Ngọ Thân Dậu+ - Sửu/Mùi: Dần Mão Tỵ Thân Tuất Hợi+ - Dần/Thân: Tý Sửu Thìn Tỵ Mùi Tuất+ - Mão/Dậu: Tý Dần Mão Ngọ Mùi Dậu+ - Thìn/Tuất: Dần Thìn Tỵ Thân Dậu Hợi+ - Tỵ/Hợi: Sửu Thìn Ngọ Mùi Tuất Hợi+- Exactly one alias enabled at a time (runtime state). `CalendarActivity` itself has no launcher filter+ (only aliases), so there is never a second tile. **All 12 aliases are declared `enabled="true"` in the+ manifest** and the app disables 11 at runtime. Reason (builder check): `Cards.java:293` rejects a card whose+ `ActivityInfo.enabled` is false, and that field may carry the manifest value rather than the runtime+ state; declaring all true makes the check pass whichever it is, while the package-manager query+ (flags 0) still skips runtime-disabled aliases. Cost: right after install, before the first run, all 12+ match; the launcher dedupes tiles by package + label and reads only the first card, so at worst the+ first-listed banner shows until the app runs once. The install step opens the app once with+ `am start` so the receivers and alarm are armed (a never-launched app is in stopped state).+- Known limit (builder check): the launcher keys saved tile order, dock rank and focus return by+ component (`AppAdapter.java:316`, `Order.compare`). The alias changes daily, so a position set with+ "Di chuyển" does not stick; the tile relies on the launcher's default placement (cards right after the+ dock apps). If `uniform_tiles` were ever on, banners would not show; the current theme does not set it.+- Order of operations when switching: enable the new alias first, then disable the old one, so the+ package never has zero launcher entries (which would drop the tile briefly or lose its place).+- When it runs (`DayUpdater`, idempotent; computes today in UTC+7 and enables the matching alias):+ 1. a `BroadcastReceiver` for `BOOT_COMPLETED`, `TIME_SET`, `TIMEZONE_CHANGED`, `DATE_CHANGED`,+ `MY_PACKAGE_REPLACED`;+ 2. an `AlarmManager.set(RTC, nextMidnightUtc7 + 1 min)` (inexact, no exact-alarm permission, does not+ wake the TV) re-armed on every run;+ 3. `CalendarActivity.onResume`.+ A few minutes late after midnight is acceptable; the owner looks in the morning.+- Caption per alias (optional, ASCII): `Hoang dao` / `Hac dao`. Needs 2 card XML files.++## Calendar rules++All dates are civil dates in UTC+7. The day (and its can chi, verdict and trực) changes at midnight, as on+Vietnamese printed calendars; see "Left to the builder" for how 23:00–24:00 is drawn. Lunar date and leap months from the launcher's+algorithm (Hồ Ngọc Đức), copied into the add-on, not linked (`launcher/.../Lunar.java`, MIT, same repo).++- **Can chi of day**: JDN based. can = (JDN + 9) mod 10, chi = (JDN + 1) mod 12 (Giáp=0, Tý=0).+ Check: 03/11/2026 → Tân Tỵ.+- **Can chi of lunar year**: can = (Y + 6) mod 10, chi = (Y + 8) mod 12. 2026 → Bính Ngọ.+- **Can chi of lunar month**: chi = (month + 1) mod 12 (month 1 = Dần); can = (Y·12 + month + 3) mod 10.+ Leap month: same can chi as the month it repeats. 9/2026 → Mậu Tuất.+- **Hoàng đạo / hắc đạo day**: 12 stars in order Thanh Long, Minh Đường, Thiên Hình, Chu Tước,+ Kim Quỹ, Kim Đường (Bảo Quang), Bạch Hổ, Ngọc Đường, Thiên Lao, Huyền Vũ, Tư Mệnh, Câu Trận; the+ good ones are Thanh Long, Minh Đường, Kim Quỹ, Kim Đường, Ngọc Đường, Tư Mệnh. Star index =+ (dayChi − start) mod 12, where Thanh Long starts at Tý for lunar months 1 and 7, Dần for 2/8, Thìn for 3/9,+ Ngọ for 4/10, Thân for 5/11, Tuất for 6/12. Indexed by **lunar month number** (leap month uses its+ number), which is what most Vietnamese online calendars do. My call. Source of truth for tests: two+ published Vietnamese online lịch vạn niên sites; where they disagree on a date, that date is dropped from+ the tests and noted, and the rule follows the majority of checked dates.+ Check: 03/11/2026, month 9, Tỵ → Minh Đường → hoàng đạo.+- **Giờ hoàng đạo**: same 12-star cycle over the 12 hours, Thanh Long starting at Thân for Tý/Ngọ days,+ Tuất for Sửu/Mùi, Tý for Dần/Thân, Dần for Mão/Dậu, Thìn for Thìn/Tuất, Ngọ for Tỵ/Hợi. Yields+ the six sets above.+- **12 trực** (for nên/kiêng): Kiến, Trừ, Mãn, Bình, Định, Chấp, Phá, Nguy, Thành, Thu, Khai, Bế.+ index = (dayChi − solarMonthChi) mod 12, where the solar month follows the 12 tiết (Lập Xuân 315° starts+ Dần, Kinh Trập 345° Mão, Thanh Minh 15° Thìn, … Tiểu Hàn 285° Sửu). The tiết is the one in force at the+ start of the civil day in UTC+7 (sun longitude at 00:00 local; Meeus low-precision formula is enough).+ This makes the trực repeat on the day a tiết begins, as the books say.+- **Nên / kiêng**: a fixed table per trực, short Vietnamese phrases (3–5 "nên", 2–4 "kiêng"), written+ as a summary of the standard trực descriptions, not quoted from a book. The screen says nothing more+ authoritative than "theo trực".++## Detail screen (approved look: "Bản phác 3")++Mockups: `/private/tmp/claude-501/-Users-tungpv-Work-tv-apps/e5191293-6918-433a-9011-62fef4bb0fa9/scratchpad/lvn/.superpowers/brainstorm/90134-1793642941/content/screen-v8.html`+(scratch, may vanish; summary here is authoritative).++- Background: dark, soft (blurred photo darkened to ~35 % with a vignette in the mockup). The add-on+ cannot read the launcher's wallpaper; it ships **one** bundled background of its own (a dark gradient,+ or one small blurred JPEG < 150 KB of a nature photo the owner has rights to, e.g. from+ `work/theme-nature-calm/wallpapers` if its CREDITS allow; otherwise gradient).+- Type: serif (Android `serif` = Noto Serif, has Vietnamese) for the calendar words and numbers; light+ sans (`sans-serif-light`) letter-spaced uppercase for small captions, like the launcher header. One+ accent colour, muted gold `#E8C77D`; muted red `#D99A8A` only for "Kiêng".+- Left column: caption "THỨ BA · 3 THÁNG 11 · 2026"; huge lunar day "25" with "tháng Chín" and caption+ "ÂM LỊCH · <moon phase word>"; thin gold rule; "Ngày Hoàng đạo" (gold) or "Ngày Hắc đạo" (silver)+ with "sao <star> chiếu"; three columns Ngày / Tháng / Năm with can chi.+- Right: a 12-segment ring like a clock face, Tý at top, each segment labelled with the chi and the+ starting hour outside; good hours filled gold, others faint; a dot at the current hour; centre text+ "BÂY GIỜ / giờ <chi> / giờ tốt|giờ xấu · đến <h>:00". Drawn with a custom `View` on `Canvas`.+- Zodiac animals (owner's request, 03/11/2026): each ring segment shows a cute cartoon animal above the+ chi name, Vietnamese set 🐭 Tý, 🐃 Sửu, 🐯 Dần, 🐱 Mão, 🐲 Thìn, 🐍 Tỵ, 🐴 Ngọ, 🐐 Mùi, 🐵 Thân,+ 🐔 Dậu, 🐶 Tuất, 🐷 Hợi; the current hour's animal is drawn large in the ring's centre. Art is the+ TV's own Noto Color Emoji font (`/system/fonts/NotoColorEmoji.ttf`, present on this TV), drawn with+ `Canvas.drawText`, so nothing is bundled. Bad-hour animals are drawn at reduced alpha.+- Bottom line: "Nên …" and "Kiêng …" for the trực, with "trực <name>"; right side hint+ "◀ ▶ đổi ngày · OK về hôm nay".+- Keys: Left/Right = previous/next day (ring then has no "bây giờ" dot, centre shows the date instead);+ OK/Center = back to today; Back = exit. Up/Down do nothing. No focusable widgets, the activity handles keys.+- Sizes for 3 m viewing on a 1920×1080 surface: smallest text ≥ 24 px, lunar day ~280 px, verdict ~100 px.+ Ring hour labels ≥ 30 px. Refresh the current-hour dot each minute while visible (Handler, stops onPause).+- Moon phase word from lunar day: 1 Sóc, 2–7 trăng non, 8 thượng huyền, 9–14 trăng khuyết, 15 rằm/vọng,+ 16–22 trăng khuyết, 23 hạ huyền, 24–30 trăng tàn (simple mapping, my call).++## Banners (the 12 tile pictures)++- Approved look: dark warm gradient (good) or cool grey (bad); small "HÔM NAY" letter-spaced caption;+ big serif "Hoàng đạo" in gold `#ECD08E` or "Hắc đạo" in silver `#C2C7D2`; thin rule; the six good+ hours "Sửu · Thìn · Ngọ · Mùi · Tuất · Hợi" on one line below. No date and no moon on the tile+ (banners are fixed per variant).+- Generated as PNGs (640×360, `res/drawable-nodpi/banner_<good|bad>_<0..5>.png`) by a small script in the+ add-on folder (`tools/make_banners.py`, Pillow, a Vietnamese-capable serif/sans font from macOS or+ Google Fonts Noto Serif). Generated files are checked in to the add-on folder so the Gradle build does not+ need Python.+- App icon: a simple drawable (gold ring segment on dark) for the App info page / library.++## Package and files++- Package `com.tungpv.lichvannien` (my call), app label "Lịch Vạn Niên" (app label may have diacritics;+ only the card label is ASCII).+- `addons/lich-van-nien/`: `settings.gradle`, `build.gradle`, `gradle.properties`, `gradlew*`, `gradle/`,+ `.gitignore`, `local.properties`, `app/` (manifest, `CalendarActivity`, `RingView`, `DayUpdater`,+ `DayReceiver`, `VnCalendar` (pure Java, no Android imports, holds all the rules), `Lunar` copy, res),+ `README.md` with a Permissions section (`RECEIVE_BOOT_COMPLETED` only), `DESIGN.md`.+- Release build signed with the debug key like the neighbours.++## Tests (JUnit, `VnCalendarTest`)++Expected values must come from a published Vietnamese lịch vạn niên (e.g. lichvannien / xemngay sites,+or a printed lịch bloc), recorded in the test with the source and date checked. At least 6 dates spread+over 2025–2027, including: today 03/11/2026 (Tân Tỵ, Mậu Tuất, Bính Ngọ, Minh Đường hoàng đạo, giờ Sửu+Thìn Ngọ Mùi Tuất Hợi), a Tết day, a day in a leap month (06/2025), a day a tiết begins (trực repeats).+Plus exhaustive structural tests: every day of 2026 maps to exactly one of the 12 aliases; exactly six+good hours per day; day can chi advances by one each day.++## Verification on the TV++Build `./gradlew --no-daemon testReleaseUnitTest assembleRelease`, `adb -s <tv ip>:5555 install -r`,+press Home, answer "Show card" (or Settings hold-OK → Module cards → Shown), screenshot to+`shots/lvn-home.png` and the detail screen to `shots/lvn-detail.png`, send both to the owner. Simulate the+midnight switch by broadcasting the receiver's action via adb (explicit component) and confirm the tile+changes without reinstalling. Check `adb logcat -s TvHomeCards` for rejections. Add a short section at+the end of `work/README.md`.++## Left to the builder++- Exact wording of the 12 nên/kiêng lists (keep short, plain, no superstition beyond the trực tables).+- Whether giờ Tý 23:00–24:00 is counted on the current date's ring (default: ring shows hours of the civil+ date; 23–24 belongs to the Tý segment of the same date).+- Fine typography, spacing and gradient colours, within the approved look.+- Whether the background is a gradient or a bundled photo (prefer gradient if photo rights are unclear).diff --git a/addons/lich-van-nien/README.md b/addons/lich-van-nien/README.mdnew file mode 100644index 000000000..29044f5ff--- /dev/null+++ b/addons/lich-van-nien/README.md@@ -0,0 +1,62 @@+# Lịch Vạn Niên (Vietnamese almanac)++An optional, standalone module card for the Vietnamese lunar almanac. The Home tile says whether today is a+*hoàng đạo* (auspicious) or *hắc đạo* (inauspicious) day and lists today's six good double-hours, so a glance+at Home is enough. OK opens a full screen with the lunar date, the *can chi* (sexagenary names) of day, month+and year, the day's star, a 12-hour ring with the zodiac animals (the TV's own emoji font) that marks the good+hours and the current one, and the day's *trực* with what it suits and what to avoid. Left/Right page through+days, OK returns to today. Everything is computed on the TV for Vietnam (UTC+7); no data is downloaded.+Design notes in [DESIGN.md](DESIGN.md). The screen is in Vietnamese.++## How the tile changes every day++A card can only carry fixed text and a fixed picture, so the app ships 12 launcher aliases (`.Day0` … `.Day11`),+each with its own banner: 6 sets of good hours × good/bad day. `DayUpdater` keeps the one for today enabled+and the others disabled: after boot, after a clock or time-zone change, on an inexact alarm within 15 minutes+after midnight (Vietnam time) and whenever the screen is opened. The launcher rebuilds its tiles on+`PACKAGE_CHANGED`. Because the tile's component changes with the day, a position chosen with the tile menu's+Move does not stick; put the package in `dock_apps` (matched by package name) to pin it.++## Setup++Build from this folder with JDK 17 and Android SDK 34:++```sh+./gradlew --no-daemon testReleaseUnitTest assembleRelease+```++Sideload `app/build/outputs/apk/release/app-release.apk` with the repository's normal ADB tools, then enable+today's tile once (the app has no launcher entry until it has run):++```sh+TV_HOST=<tv ip> tools/venv/bin/python -I tools/tv.py 'am broadcast -n com.tungpv.lichvannien/.DayReceiver'+```++Press Home and approve **Lich Van Nien** when the launcher asks about its card. Until the app has run once the+tile shows a neutral "Hôm nay / Bấm OK" picture. If the app is ever force-stopped, Android drops its alarm and its+boot receiver until it is opened again, so the tile can stay on an old day: open the tile once.++Preview another day's tile from ADB only (`PreviewReceiver` is protected by `DUMP`, which apps cannot hold):+`am broadcast -n com.tungpv.lichvannien/.PreviewReceiver --ei preview_days 1`; `--ei preview_days 0`, or the+next midnight, puts today's back. The banners are generated by `tools/make_banners.py` (Pillow, fonts pulled from+the TV's `/system/fonts`).++## Data and validation++The lunar calendar is Hồ Ngọc Đức's algorithm (astronomical new moons and solar terms at UTC+7). The day's+star, *trực* and good hours follow the usual Vietnamese almanac tables (*hoàng đạo* by the day's branch within+the lunar month, *trực* by the month's branch, good hours by the day's branch). Unit tests compare 9 dates in+2025–2027 with xemlicham.com and ngaydep.com (lunar date, can chi, star, trực, good hours), plus two 2027 solar+terms that begin just after midnight. From 23:00 the ring's Tý segment follows the next day, since giờ Tý opens+the next day. Left/Right stop at 1900 and 2199.++## Permissions++- `RECEIVE_BOOT_COMPLETED`: to put today's tile back after the TV starts.++No network access, no background service, no accessibility service. One inexact daily alarm that does not wake+the TV.++## Tested on++Expressluck AiPro4K (sepolia), Android TV 14 (UKN7.260716.014).diff --git a/addons/lich-van-nien/app/build.gradle b/addons/lich-van-nien/app/build.gradlenew file mode 100644index 000000000..fdb36fe5c--- /dev/null+++ b/addons/lich-van-nien/app/build.gradle@@ -0,0 +1,18 @@+plugins { id 'com.android.application' }+android {+ namespace 'com.tungpv.lichvannien'+ compileSdk 34+ buildFeatures { aidl false }+ defaultConfig { applicationId 'com.tungpv.lichvannien'; minSdk 26; targetSdk 34; versionCode 1; versionName '1.0' }+ buildTypes { release {+ minifyEnabled true+ shrinkResources true+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'+ signingConfig signingConfigs.debug+ } }+ compileOptions { sourceCompatibility JavaVersion.VERSION_17; targetCompatibility JavaVersion.VERSION_17 }+}+dependencies {++ testImplementation 'junit:junit:4.13.2'+}diff --git a/addons/lich-van-nien/app/proguard-rules.pro b/addons/lich-van-nien/app/proguard-rules.pronew file mode 100644index 000000000..e69de29bbdiff --git a/addons/lich-van-nien/app/src/main/AndroidManifest.xml b/addons/lich-van-nien/app/src/main/AndroidManifest.xmlnew file mode 100644index 000000000..79d617317--- /dev/null+++ b/addons/lich-van-nien/app/src/main/AndroidManifest.xml@@ -0,0 +1,101 @@+<?xml version="1.0" encoding="utf-8"?>+<manifest xmlns:android="http://schemas.android.com/apk/res/android">+ <uses-feature android:name="android.software.leanback" android:required="true" />+ <uses-feature android:name="android.hardware.touchscreen" android:required="false" />+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />+ <application android:allowBackup="false" android:label="@string/app_name" android:icon="@drawable/icon"+ android:banner="@drawable/banner_start" android:theme="@android:style/Theme.Material.NoActionBar.Fullscreen">+ <activity android:name=".CalendarActivity" android:exported="false" android:screenOrientation="landscape" />+ <!-- One alias per tile picture (VnCalendar.variant); DayUpdater keeps exactly one enabled. All are declared+ enabled so the launcher's card check passes whichever one is on. DayStart comes first, so before the+ app's first run the launcher reads its neutral picture instead of a verdict. -->+ <activity-alias android:name=".DayStart" android:targetActivity=".CalendarActivity" android:exported="true"+ android:enabled="true" android:banner="@drawable/banner_start">+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter>+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="com.gathin.tvhome.category.DOCK_CARD" /></intent-filter>+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/card_start" />+ </activity-alias>+ <activity-alias android:name=".Day0" android:targetActivity=".CalendarActivity" android:exported="true"+ android:enabled="true" android:banner="@drawable/banner_v0">+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter>+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="com.gathin.tvhome.category.DOCK_CARD" /></intent-filter>+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/card_good" />+ </activity-alias>+ <activity-alias android:name=".Day1" android:targetActivity=".CalendarActivity" android:exported="true"+ android:enabled="true" android:banner="@drawable/banner_v1">+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter>+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="com.gathin.tvhome.category.DOCK_CARD" /></intent-filter>+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/card_good" />+ </activity-alias>+ <activity-alias android:name=".Day2" android:targetActivity=".CalendarActivity" android:exported="true"+ android:enabled="true" android:banner="@drawable/banner_v2">+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter>+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="com.gathin.tvhome.category.DOCK_CARD" /></intent-filter>+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/card_good" />+ </activity-alias>+ <activity-alias android:name=".Day3" android:targetActivity=".CalendarActivity" android:exported="true"+ android:enabled="true" android:banner="@drawable/banner_v3">+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter>+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="com.gathin.tvhome.category.DOCK_CARD" /></intent-filter>+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/card_good" />+ </activity-alias>+ <activity-alias android:name=".Day4" android:targetActivity=".CalendarActivity" android:exported="true"+ android:enabled="true" android:banner="@drawable/banner_v4">+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter>+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="com.gathin.tvhome.category.DOCK_CARD" /></intent-filter>+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/card_good" />+ </activity-alias>+ <activity-alias android:name=".Day5" android:targetActivity=".CalendarActivity" android:exported="true"+ android:enabled="true" android:banner="@drawable/banner_v5">+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter>+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="com.gathin.tvhome.category.DOCK_CARD" /></intent-filter>+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/card_good" />+ </activity-alias>+ <activity-alias android:name=".Day6" android:targetActivity=".CalendarActivity" android:exported="true"+ android:enabled="true" android:banner="@drawable/banner_v6">+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter>+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="com.gathin.tvhome.category.DOCK_CARD" /></intent-filter>+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/card_bad" />+ </activity-alias>+ <activity-alias android:name=".Day7" android:targetActivity=".CalendarActivity" android:exported="true"+ android:enabled="true" android:banner="@drawable/banner_v7">+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter>+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="com.gathin.tvhome.category.DOCK_CARD" /></intent-filter>+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/card_bad" />+ </activity-alias>+ <activity-alias android:name=".Day8" android:targetActivity=".CalendarActivity" android:exported="true"+ android:enabled="true" android:banner="@drawable/banner_v8">+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter>+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="com.gathin.tvhome.category.DOCK_CARD" /></intent-filter>+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/card_bad" />+ </activity-alias>+ <activity-alias android:name=".Day9" android:targetActivity=".CalendarActivity" android:exported="true"+ android:enabled="true" android:banner="@drawable/banner_v9">+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter>+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="com.gathin.tvhome.category.DOCK_CARD" /></intent-filter>+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/card_bad" />+ </activity-alias>+ <activity-alias android:name=".Day10" android:targetActivity=".CalendarActivity" android:exported="true"+ android:enabled="true" android:banner="@drawable/banner_v10">+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter>+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="com.gathin.tvhome.category.DOCK_CARD" /></intent-filter>+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/card_bad" />+ </activity-alias>+ <activity-alias android:name=".Day11" android:targetActivity=".CalendarActivity" android:exported="true"+ android:enabled="true" android:banner="@drawable/banner_v11">+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LEANBACK_LAUNCHER" /></intent-filter>+ <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="com.gathin.tvhome.category.DOCK_CARD" /></intent-filter>+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/card_bad" />+ </activity-alias>+ <receiver android:name=".DayReceiver" android:exported="true">+ <intent-filter>+ <action android:name="android.intent.action.BOOT_COMPLETED" />+ <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />+ <action android:name="android.intent.action.TIME_SET" />+ <action android:name="android.intent.action.TIMEZONE_CHANGED" />+ </intent-filter>+ </receiver>+ <!-- adb only: DUMP is held by the shell and the system, not by apps, so no app can flip the tile. -->+ <receiver android:name=".PreviewReceiver" android:exported="true" android:permission="android.permission.DUMP" />+ </application>+</manifest>diff --git a/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/CalendarActivity.java b/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/CalendarActivity.javanew file mode 100644index 000000000..3ca3cdc0c--- /dev/null+++ b/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/CalendarActivity.java@@ -0,0 +1,86 @@+package com.tungpv.lichvannien;++import android.app.Activity;+import android.os.Bundle;+import android.os.Handler;+import android.os.Looper;+import android.view.KeyEvent;++import java.util.Calendar;++/** The screen behind the tile: Left/Right move a day, OK returns to today, Back leaves. */+public class CalendarActivity extends Activity {++ private final Handler handler = new Handler(Looper.getMainLooper());+ private final Runnable tick = new Runnable() {+ @Override+ public void run() {+ refresh();+ // Next run at the start of the next minute.+ handler.postDelayed(this, 60_000 - System.currentTimeMillis() % 60_000 + 50);+ }+ };+ private CalendarView view;+ private int offset;++ @Override+ protected void onCreate(Bundle savedInstanceState) {+ super.onCreate(savedInstanceState);+ view = new CalendarView(this);+ setContentView(view);+ }++ @Override+ protected void onResume() {+ super.onResume();+ DayUpdater.update(this);+ handler.post(tick);+ }++ @Override+ protected void onPause() {+ handler.removeCallbacks(tick);+ super.onPause();+ }++ private void refresh() {+ Calendar c = DayUpdater.now();+ int hour = c.get(Calendar.HOUR_OF_DAY);+ c.add(Calendar.DAY_OF_MONTH, offset);+ VnCalendar.Day day = VnCalendar.of(c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.MONTH) + 1, c.get(Calendar.YEAR));+ view.show(day, offset == 0 ? VnCalendar.hourIndex(hour) : -1, hour);+ }++ /** The lunar algorithm is trusted for 1900–2199; stop there. */+ private static boolean inRange(int offsetDays) {+ Calendar c = DayUpdater.now();+ c.add(Calendar.DAY_OF_MONTH, offsetDays);+ int year = c.get(Calendar.YEAR);+ return c.get(Calendar.ERA) == java.util.GregorianCalendar.AD && year >= 1900 && year <= 2199;+ }++ @Override+ public boolean onKeyDown(int keyCode, KeyEvent event) {+ switch (keyCode) {+ case KeyEvent.KEYCODE_DPAD_LEFT:+ case KeyEvent.KEYCODE_DPAD_RIGHT:+ int next = offset + (keyCode == KeyEvent.KEYCODE_DPAD_LEFT ? -1 : 1);+ if (inRange(next)) {+ offset = next;+ refresh();+ }+ return true;+ case KeyEvent.KEYCODE_DPAD_CENTER:+ case KeyEvent.KEYCODE_ENTER:+ case KeyEvent.KEYCODE_NUMPAD_ENTER:+ offset = 0;+ refresh();+ return true;+ case KeyEvent.KEYCODE_DPAD_UP:+ case KeyEvent.KEYCODE_DPAD_DOWN:+ return true;+ default:+ return super.onKeyDown(keyCode, event);+ }+ }+}diff --git a/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/CalendarView.java b/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/CalendarView.javanew file mode 100644index 000000000..5922d031b--- /dev/null+++ b/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/CalendarView.java@@ -0,0 +1,281 @@+package com.tungpv.lichvannien;++import android.content.Context;+import android.graphics.Canvas;+import android.graphics.Color;+import android.graphics.LinearGradient;+import android.graphics.Paint;+import android.graphics.Path;+import android.graphics.RadialGradient;+import android.graphics.RectF;+import android.graphics.Shader;+import android.graphics.Typeface;+import android.view.View;++/**+ * The whole calendar screen, drawn on one canvas. Every size is a fraction of the view's width, so the layout is+ * the approved mockup ("Bản phác 3") at any resolution: left column with the lunar date, verdict and can chi, a+ * 12-hour ring with the zodiac animals on the right, the day's trực at the bottom.+ */+final class CalendarView extends View {++ private static final int TEXT = 0xFFF4F1EA;+ private static final int GOLD = 0xFFE8C77D;+ private static final int SILVER = 0xFFC2C7D2;+ private static final int RED = 0xFFD99A8A;+ private static final String[] WEEKDAYS = {"Thứ Hai", "Thứ Ba", "Thứ Tư", "Thứ Năm", "Thứ Sáu", "Thứ Bảy", "Chủ Nhật"};+ private static final String[] LUNAR_MONTHS = {"Giêng", "Hai", "Ba", "Tư", "Năm", "Sáu", "Bảy", "Tám", "Chín",+ "Mười", "Mười Một", "Chạp"};+ /** Clock hour each double-hour starts at, Tý first. */+ private static final int[] START_HOUR = {23, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21};++ private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);+ private final Typeface serif = Typeface.create("serif", Typeface.NORMAL);+ private final Typeface sans = Typeface.create("sans-serif", Typeface.NORMAL);+ private final Typeface sansLight = Typeface.create("sans-serif-light", Typeface.NORMAL);+ private final Path path = new Path();+ private final RectF outer = new RectF(), inner = new RectF();++ private VnCalendar.Day day;+ /** Current double-hour, or -1 when another day than today is shown. */+ private int nowHour = -1;+ private int nowClockHour;++ CalendarView(Context context) {+ super(context);+ }++ void show(VnCalendar.Day day, int nowHour, int nowClockHour) {+ this.day = day;+ this.nowHour = nowHour;+ this.nowClockHour = nowClockHour;+ invalidate();+ }++ @Override+ protected void onDraw(Canvas c) {+ drawBackground(c, getWidth(), getHeight());+ if (day == null) return;+ // Lay out in a centred 16:9 frame, so another screen shape letterboxes instead of shifting things.+ float w = Math.min(getWidth(), getHeight() * 16f / 9f), h = w * 9f / 16f, u = w / 100f;+ c.save();+ c.translate((getWidth() - w) / 2f, (getHeight() - h) / 2f);+ float ringR = 18 * u, ringX = w - 6 * u - ringR, ringLeft = ringX - ringR * 1.16f;++ float left = 6 * u, y = 7 * u;+ caps(c, WEEKDAYS[day.weekday] + " · " + day.solarDay + " tháng " + day.solarMonth + " · " + day.solarYear,+ left, y, 1.45f * u, 0x8CF4F1EA);++ // Lunar day, big.+ paint.setTypeface(serif);+ paint.setTextSize(15 * u);+ paint.setColor(TEXT);+ String lunarDay = String.valueOf(day.lunarDay);+ float base = y + 14.5f * u;+ c.drawText(lunarDay, left - 0.6f * u, base, paint);+ float dx = left + paint.measureText(lunarDay) + 2.2f * u;+ paint.setTextSize(3.6f * u);+ c.drawText("tháng " + LUNAR_MONTHS[day.lunarMonth - 1] + (day.leap ? " nhuận" : ""), dx, base - 6.2f * u, paint);+ caps(c, "Âm lịch · " + VnCalendar.moonWord(day.lunarDay), dx, base - 2.4f * u, 1.35f * u, 0x8CF4F1EA,+ ringLeft - 1.5f * u);++ // Thin gold rule.+ float ry = base + 3.4f * u;+ paint.setShader(new LinearGradient(left, 0, left + 46 * u, 0, 0x99E8C77D, 0x00E8C77D, Shader.TileMode.CLAMP));+ c.drawRect(left, ry, left + 46 * u, ry + Math.max(1, 0.1f * u), paint);+ paint.setShader(null);++ // Verdict.+ paint.setTypeface(serif);+ paint.setTextSize(5.4f * u);+ paint.setColor(day.good ? GOLD : SILVER);+ float vy = ry + 7.6f * u;+ c.drawText(day.good ? "Ngày Hoàng đạo" : "Ngày Hắc đạo", left, vy, paint);+ paint.setTypeface(sans);+ paint.setTextSize(2f * u);+ paint.setColor(0xB3F4F1EA);+ c.drawText("sao " + VnCalendar.STARS[day.star] + " chiếu", left, vy + 3.6f * u, paint);++ // Can chi columns.+ float cy = vy + 10 * u;+ String[] heads = {"Ngày", "Tháng", "Năm"};+ String[] vals = {+ VnCalendar.CAN[day.dayCan] + " " + VnCalendar.CHI[day.dayChi],+ VnCalendar.CAN[day.monthCan] + " " + VnCalendar.CHI[day.monthChi],+ VnCalendar.CAN[day.yearCan] + " " + VnCalendar.CHI[day.yearChi]};+ float cx = left;+ for (int i = 0; i < 3; i++) {+ caps(c, heads[i], cx, cy, 1.35f * u, 0x8CF4F1EA);+ paint.setTypeface(serif);+ paint.setTextSize(3.1f * u);+ paint.setColor(TEXT);+ c.drawText(vals[i], cx, cy + 4.2f * u, paint);+ cx += paint.measureText(vals[i]) + 4.5f * u;+ }++ paint.setTypeface(sans);+ paint.setTextSize(1.4f * u);+ paint.setColor(0x73F4F1EA);+ paint.setTextAlign(Paint.Align.RIGHT);+ c.drawText("◀ ▶ đổi ngày · OK về hôm nay", w - 6 * u, y, paint);+ paint.setTextAlign(Paint.Align.LEFT);++ drawRing(c, ringX, h * 0.53f, ringR, u);+ drawTruc(c, left, w - 6 * u, h - 3.6f * u, u);+ c.restore();+ }++ private void drawBackground(Canvas c, float w, float h) {+ paint.setShader(new LinearGradient(0, 0, 0, h, 0xFF141821, 0xFF0B0D12, Shader.TileMode.CLAMP));+ c.drawRect(0, 0, w, h, paint);+ paint.setShader(new RadialGradient(w * 0.22f, h * 0.18f, w * 0.6f,+ day != null && !day.good ? 0x332E3445 : 0x3348391C, 0x00000000, Shader.TileMode.CLAMP));+ c.drawRect(0, 0, w, h, paint);+ paint.setShader(new RadialGradient(w * 0.8f, h * 0.55f, w * 0.35f, 0x1A3A4458, 0x00000000, Shader.TileMode.CLAMP));+ c.drawRect(0, 0, w, h, paint);+ paint.setShader(null);+ }++ /** Small letter-spaced uppercase caption, like the launcher's header. */+ private void caps(Canvas c, String text, float x, float y, float size, int color) {+ caps(c, text, x, y, size, color, Float.MAX_VALUE);+ }++ /** As above, made smaller when it would run past maxRight. */+ private void caps(Canvas c, String text, float x, float y, float size, int color, float maxRight) {+ String upper = text.toUpperCase(new java.util.Locale("vi"));+ paint.setTypeface(sansLight);+ paint.setLetterSpacing(0.3f);+ paint.setTextSize(size);+ float width = paint.measureText(upper);+ if (x + width > maxRight) paint.setTextSize(size * (maxRight - x) / width);+ paint.setColor(color);+ c.drawText(upper, x, y, paint);+ paint.setLetterSpacing(0);+ }++ /** The 12 double-hours as a clock face: Tý at the top, good hours gold, animal and name in each segment. */+ private void drawRing(Canvas c, float cx, float cy, float r, float u) {+ boolean[] good = VnCalendar.goodHours(day.dayChi);+ // From 23:00 the Tý segment is the next day's Tý.+ if (nowHour == 0) good[0] = VnCalendar.goodAt(day.dayChi, nowClockHour);+ float r1 = r, r2 = r * 0.64f;+ outer.set(cx - r1, cy - r1, cx + r1, cy + r1);+ inner.set(cx - r2, cy - r2, cx + r2, cy + r2);+ paint.setTextAlign(Paint.Align.CENTER);+ for (int i = 0; i < 12; i++) {+ float start = i * 30 - 90 - 15 + 0.8f, sweep = 30 - 1.6f;+ path.reset();+ path.arcTo(outer, start, sweep);+ path.arcTo(inner, start + sweep, -sweep);+ path.close();+ paint.setColor(good[i] ? (i == nowHour ? 0xFFF1D592 : 0xD9E8C77D) : (i == nowHour ? 0x33FFFFFF : 0x14FFFFFF));+ c.drawPath(path, paint);++ double a = Math.toRadians(i * 30 - 90);+ float cos = (float) Math.cos(a), sin = (float) Math.sin(a);+ // Animal above its name, both centred on the middle of the segment.+ float mx = cx + r * 0.82f * cos, my = cy + r * 0.82f * sin;+ paint.setTypeface(sans);+ paint.setTextSize(r * 0.12f);+ paint.setColor(Color.BLACK);+ paint.setAlpha(good[i] ? 255 : 110);+ c.drawText(VnCalendar.ANIMALS[i], mx, my + r * 0.005f, paint);+ paint.setTypeface(serif);+ paint.setTextSize(r * 0.082f);+ paint.setColor(good[i] ? 0xFF1B1A17 : 0x80F4F1EA);+ c.drawText(VnCalendar.CHI[i], mx, my + r * 0.1f, paint);++ // Starting clock hour outside the ring.+ paint.setTypeface(sans);+ paint.setTextSize(r * 0.07f);+ paint.setColor(0x80F4F1EA);+ float hr = r * 1.1f;+ c.drawText(String.valueOf(START_HOUR[i]), cx + hr * cos, cy + hr * sin + r * 0.025f, paint);+ }++ // Centre.+ if (nowHour >= 0) {+ double a = Math.toRadians(nowHour * 30 - 90);+ paint.setColor(TEXT);+ c.drawCircle(cx + r * 0.58f * (float) Math.cos(a), cy + r * 0.58f * (float) Math.sin(a), r * 0.025f, paint);+ centre(c, cx, cy, r, "Bây giờ", VnCalendar.ANIMALS[nowHour], "giờ " + VnCalendar.CHI[nowHour],+ (good[nowHour] ? "hoàng đạo" : "hắc đạo") + " · đến " + ((START_HOUR[nowHour] + 2) % 24) + ":00",+ good[nowHour]);+ } else {+ centre(c, cx, cy, r, "Ngày", VnCalendar.ANIMALS[day.dayChi], VnCalendar.CHI[day.dayChi],+ day.solarDay + "/" + day.solarMonth + "/" + day.solarYear, day.good);+ }+ paint.setTextAlign(Paint.Align.LEFT);+ }++ private void centre(Canvas c, float cx, float cy, float r, String top, String animal, String main, String sub,+ boolean gold) {+ paint.setTypeface(sansLight);+ paint.setTextSize(r * 0.058f);+ paint.setColor(0x8CF4F1EA);+ paint.setLetterSpacing(0.3f);+ c.drawText(top.toUpperCase(new java.util.Locale("vi")), cx, cy - r * 0.33f, paint);+ paint.setLetterSpacing(0);+ paint.setTypeface(sans);+ paint.setTextSize(r * 0.25f);+ paint.setColor(Color.BLACK);+ c.drawText(animal, cx, cy + r * 0.02f, paint);+ paint.setTypeface(serif);+ paint.setTextSize(r * 0.12f);+ paint.setColor(gold ? GOLD : SILVER);+ c.drawText(main, cx, cy + r * 0.2f, paint);+ paint.setTypeface(sans);+ paint.setTextSize(r * 0.06f);+ paint.setColor(0x99F4F1EA);+ c.drawText(sub, cx, cy + r * 0.31f, paint);+ }++ /** "Trực Nguy · Nên … · Kiêng …", made smaller as a whole when the day's lists would run past right. */+ private void drawTruc(Canvas c, float left, float right, float y, float u) {+ String truc = "Trực " + VnCalendar.TRUC[day.truc];+ String nen = list(VnCalendar.nen(day.truc)), kieng = list(VnCalendar.kieng(day.truc));+ float scale = 1;+ float width = trucLine(c, truc, nen, kieng, left, y, u, false);+ if (width > right - left) scale = (right - left) / width;+ trucLine(c, truc, nen, kieng, left, y, u * scale, true);+ }++ /** Draws the line (or only measures it) at unit u; returns its width. */+ private float trucLine(Canvas c, String truc, String nen, String kieng, float left, float y, float u, boolean draw) {+ float x = left;+ paint.setTypeface(sansLight);+ paint.setLetterSpacing(0.3f);+ paint.setTextSize(1.45f * u);+ String upper = truc.toUpperCase(new java.util.Locale("vi"));+ if (draw) {+ paint.setColor(0xB3F4F1EA);+ c.drawText(upper, x, y, paint);+ }+ x += paint.measureText(upper) + 2.2f * u;+ paint.setLetterSpacing(0);+ x = label(c, "Nên", nen, x, y, u, GOLD, draw);+ x = label(c, "Kiêng", kieng, x + 2.6f * u, y, u, RED, draw);+ return x - left;+ }++ /** "Cúng tế, cầu an, việc nhỏ": only the first item keeps its capital. */+ private static String list(String[] items) {+ StringBuilder b = new StringBuilder(items[0]);+ for (int i = 1; i < items.length; i++) {+ b.append(", ").append(items[i].substring(0, 1).toLowerCase(new java.util.Locale("vi"))).append(items[i].substring(1));+ }+ return b.toString();+ }++ private float label(Canvas c, String head, String body, float x, float y, float u, int color, boolean draw) {+ paint.setTypeface(sans);+ paint.setTextSize(1.75f * u);+ paint.setColor(color);+ if (draw) c.drawText(head, x, y, paint);+ x += paint.measureText(head) + 0.9f * u;+ paint.setColor(0xD9F4F1EA);+ if (draw) c.drawText(body, x, y, paint);+ return x + paint.measureText(body);+ }+}diff --git a/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/DayReceiver.java b/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/DayReceiver.javanew file mode 100644index 000000000..7f4d7bd22--- /dev/null+++ b/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/DayReceiver.java@@ -0,0 +1,13 @@+package com.tungpv.lichvannien;++import android.content.BroadcastReceiver;+import android.content.Context;+import android.content.Intent;++/** Boot, clock changes or the app's own midnight alarm: bring the tile up to today. */+public class DayReceiver extends BroadcastReceiver {+ @Override+ public void onReceive(Context context, Intent intent) {+ DayUpdater.update(context);+ }+}diff --git a/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/DayUpdater.java b/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/DayUpdater.javanew file mode 100644index 000000000..9c512e1f4--- /dev/null+++ b/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/DayUpdater.java@@ -0,0 +1,78 @@+package com.tungpv.lichvannien;++import android.app.AlarmManager;+import android.app.PendingIntent;+import android.content.ComponentName;+import android.content.Context;+import android.content.Intent;+import android.content.pm.PackageManager;++import java.util.Calendar;+import java.util.TimeZone;++/**+ * Keeps the one launcher alias whose banner matches today enabled, and arms an alarm for just after the next+ * midnight in Vietnam. Safe to call any number of times.+ */+final class DayUpdater {++ static final TimeZone VN = TimeZone.getTimeZone("GMT+07:00");+ static final int VARIANTS = 12;++ private DayUpdater() {+ }++ static Calendar now() {+ return Calendar.getInstance(VN);+ }++ static VnCalendar.Day today(int offsetDays) {+ Calendar c = now();+ c.add(Calendar.DAY_OF_MONTH, offsetDays);+ return VnCalendar.of(c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.MONTH) + 1, c.get(Calendar.YEAR));+ }++ static void update(Context ctx) {+ update(ctx, 0);+ }++ /** offsetDays other than 0 only previews another day's tile (adb test); the next run puts today's back. */+ static void update(Context ctx, int offsetDays) {+ int want = VnCalendar.variant(today(offsetDays));+ PackageManager pm = ctx.getPackageManager();+ // The new alias first, so the package never has zero launcher entries.+ set(pm, alias(ctx, want), PackageManager.COMPONENT_ENABLED_STATE_ENABLED);+ for (int v = 0; v < VARIANTS; v++) {+ if (v != want) set(pm, alias(ctx, v), PackageManager.COMPONENT_ENABLED_STATE_DISABLED);+ }+ set(pm, new ComponentName(ctx, ctx.getPackageName() + ".DayStart"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED);+ armMidnight(ctx);+ }++ static ComponentName alias(Context ctx, int variant) {+ return new ComponentName(ctx, ctx.getPackageName() + ".Day" + variant);+ }++ private static void set(PackageManager pm, ComponentName c, int state) {+ // DEFAULT means the manifest's enabled="true", so only DISABLED counts as off. Unchanged states are not+ // written again: every write sends PACKAGE_CHANGED and makes Home rebuild its tiles.+ boolean on = pm.getComponentEnabledSetting(c) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED;+ if (on == (state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED)) return;+ pm.setComponentEnabledSetting(c, state, PackageManager.DONT_KILL_APP);+ }++ /** An alarm within 15 minutes after the next Vietnamese midnight; it does not wake the TV. */+ private static void armMidnight(Context ctx) {+ Calendar next = now();+ next.add(Calendar.DAY_OF_MONTH, 1);+ next.set(Calendar.HOUR_OF_DAY, 0);+ next.set(Calendar.MINUTE, 1);+ next.set(Calendar.SECOND, 0);+ next.set(Calendar.MILLISECOND, 0);+ AlarmManager am = ctx.getSystemService(AlarmManager.class);+ if (am == null) return;+ PendingIntent pi = PendingIntent.getBroadcast(ctx, 0, new Intent(ctx, DayReceiver.class),+ PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);+ am.setWindow(AlarmManager.RTC, next.getTimeInMillis(), 15 * 60_000L, pi);+ }+}diff --git a/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/Lunar.java b/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/Lunar.javanew file mode 100644index 000000000..c64a5f81f--- /dev/null+++ b/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/Lunar.java@@ -0,0 +1,112 @@+package com.tungpv.lichvannien;++/**+ * Copied from the launcher's Lunar.java (cleanyourtv, MIT): Hồ Ngọc Đức's public algorithm, new moons and solar+ * terms from Jean Meeus' formulas. Only the date maths is kept.+ */+final class Lunar {++ private Lunar() {+ }++ /** 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) + 1;+ long monthStart = newMoonDay(k, tz);+ // The mean-month estimate can still be a new moon ahead when the real one falls just after local midnight;+ // one step back was not always enough, and the day before that new moon came out as day 0.+ while (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);+ // Term by term as in Hồ Ngọc Đức's code, each with its own sign: folding two terms into one "c1 -= a + b"+ // flips the second one, which moved new moons by hours and put the 2023 leap month a month early.+ c1 = c1 - 0.4068 * Math.sin(mpr * dr) + 0.0161 * Math.sin(dr * 2 * mpr);+ c1 = c1 - 0.0004 * Math.sin(dr * 3 * mpr);+ c1 = c1 + 0.0104 * Math.sin(dr * 2 * f) - 0.0051 * Math.sin(dr * (m + mpr));+ c1 = c1 - 0.0074 * Math.sin(dr * (m - mpr)) + 0.0004 * Math.sin(dr * (2 * f + m));+ c1 = 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/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/PreviewReceiver.java b/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/PreviewReceiver.javanew file mode 100644index 000000000..0d8fc3e53--- /dev/null+++ b/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/PreviewReceiver.java@@ -0,0 +1,17 @@+package com.tungpv.lichvannien;++import android.content.BroadcastReceiver;+import android.content.Context;+import android.content.Intent;++/**+ * Shows another day's tile until the next update, for testing over adb:+ * am broadcast -n com.tungpv.lichvannien/.PreviewReceiver --ei preview_days 1+ * The manifest guards it with DUMP, which apps cannot hold.+ */+public class PreviewReceiver extends BroadcastReceiver {+ @Override+ public void onReceive(Context context, Intent intent) {+ DayUpdater.update(context, intent.getIntExtra("preview_days", 0));+ }+}diff --git a/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/VnCalendar.java b/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/VnCalendar.javanew file mode 100644index 000000000..37cc155a9--- /dev/null+++ b/addons/lich-van-nien/app/src/main/java/com/tungpv/lichvannien/VnCalendar.java@@ -0,0 +1,174 @@+package com.tungpv.lichvannien;++/**+ * The Vietnamese calendar rules this add-on shows, for a civil date in UTC+7: lunar date, can chi of day, month and+ * year, the day's star (hoàng đạo or hắc đạo), the 12 double-hours and the day's trực. No Android imports, so the+ * whole of it is unit-tested on the JVM.+ */+final class VnCalendar {++ static final double TZ = 7;++ static final String[] CAN = {"Giáp", "Ất", "Bính", "Đinh", "Mậu", "Kỷ", "Canh", "Tân", "Nhâm", "Quý"};+ static final String[] CHI = {"Tý", "Sửu", "Dần", "Mão", "Thìn", "Tỵ", "Ngọ", "Mùi", "Thân", "Dậu", "Tuất", "Hợi"};+ /** The Vietnamese zodiac: Sửu is the buffalo, Mão the cat, Mùi the goat. Drawn with the TV's emoji font. */+ static final String[] ANIMALS = {"🐭", "🐃", "🐯", "🐱", "🐲", "🐍", "🐴", "🐐", "🐵", "🐔", "🐶", "🐷"};+ static final String[] STARS = {"Thanh Long", "Minh Đường", "Thiên Hình", "Chu Tước", "Kim Quỹ", "Kim Đường",+ "Bạch Hổ", "Ngọc Đường", "Thiên Lao", "Huyền Vũ", "Tư Mệnh", "Câu Trận"};+ /** Which of STARS are hoàng đạo. */+ static final boolean[] GOOD_STAR = {true, true, false, false, true, true, false, true, false, false, true, false};+ static final String[] TRUC = {"Kiến", "Trừ", "Mãn", "Bình", "Định", "Chấp", "Phá", "Nguy", "Thành", "Thu", "Khai", "Bế"};++ /** Chi where Thanh Long falls, by lunar month 1..12 (index month - 1); months six apart share it. */+ private static final int[] DAY_STAR_START = {0, 2, 4, 6, 8, 10, 0, 2, 4, 6, 8, 10};+ /** Chi of the hour where Thanh Long falls, by day chi; chi six apart share it. */+ private static final int[] HOUR_STAR_START = {8, 10, 0, 2, 4, 6};++ private static final String[][] NEN = {+ {"Xuất hành", "Khai trương", "Nhậm chức", "Cầu tài"}, // Kiến+ {"Chữa bệnh", "Dọn dẹp, tẩy uế", "Cúng giải hạn"}, // Trừ+ {"Cầu tài", "Mở kho, nhập hàng", "Cúng tế", "Sửa nhà"}, // Mãn+ {"Sửa đường, sửa nhà", "Làm việc thường ngày"}, // Bình+ {"Cưới hỏi", "Ký kết", "Nhập học", "Mua gia súc"}, // Định+ {"Xây dựng", "Trồng cây", "Thuê người làm"}, // Chấp+ {"Phá dỡ nhà cũ", "Chữa bệnh"}, // Phá+ {"Cúng tế, cầu an", "Việc nhỏ trong nhà"}, // Nguy+ {"Cưới hỏi", "Khai trương", "Nhập trạch", "Xuất hành"}, // Thành+ {"Thu nợ", "Thu hoạch, nhập kho", "Mua bán"}, // Thu+ {"Khai trương", "Cưới hỏi", "Động thổ", "Nhập học"}, // Khai+ {"Đắp đê, lấp hố", "Sửa tường rào", "Nghỉ ngơi"}, // Bế+ };+ private static final String[][] KIENG = {+ {"Động thổ", "Đào giếng"},+ {"Cưới hỏi", "Xuất hành xa"},+ {"Kiện tụng", "Nhậm chức"},+ {"Cưới hỏi", "Khai trương"},+ {"Kiện tụng", "Xuất hành"},+ {"Xuất hành", "Mở kho, xuất tiền"},+ {"Cưới hỏi", "Khai trương", "Ký kết"},+ {"Đi sông nước", "Leo cao"},+ {"Kiện tụng"},+ {"An táng", "Xuất hành"},+ {"An táng", "Chôn cất"},+ {"Khai trương", "Chữa mắt", "Nhậm chức"},+ };++ private VnCalendar() {+ }++ /** One civil day in UTC+7. */+ static final class Day {+ final int solarDay, solarMonth, solarYear;+ final long jdn;+ final int lunarDay, lunarMonth, lunarYear;+ final boolean leap;+ final int dayCan, dayChi, monthCan, monthChi, yearCan, yearChi;+ /** Index into STARS. */+ final int star;+ final boolean good;+ /** Index into TRUC. */+ final int truc;+ /** 0 = Monday … 6 = Sunday. */+ final int weekday;++ private Day(int dd, int mm, int yy) {+ solarDay = dd;+ solarMonth = mm;+ solarYear = yy;+ jdn = Lunar.jdFromDate(dd, mm, yy);+ int[] l = Lunar.fromSolar(dd, mm, yy, TZ);+ lunarDay = l[0];+ lunarMonth = l[1];+ lunarYear = l[2];+ leap = l[3] == 1;+ dayCan = (int) ((jdn + 9) % 10);+ dayChi = (int) ((jdn + 1) % 12);+ monthChi = (lunarMonth + 1) % 12;+ monthCan = (lunarYear * 12 + lunarMonth + 3) % 10;+ yearCan = Math.floorMod(lunarYear + 6, 10);+ yearChi = Math.floorMod(lunarYear + 8, 12);+ star = Math.floorMod(dayChi - DAY_STAR_START[lunarMonth - 1], 12);+ good = GOOD_STAR[star];+ truc = Math.floorMod(dayChi - solarMonthChi(jdn), 12);+ weekday = (int) (jdn % 7);+ }+ }++ static Day of(int dd, int mm, int yyyy) {+ return new Day(dd, mm, yyyy);+ }++ /** The six good double-hours of a day with this chi; index 0 is giờ Tý (23:00–01:00). */+ static boolean[] goodHours(int dayChi) {+ boolean[] out = new boolean[12];+ int start = HOUR_STAR_START[dayChi % 6];+ for (int h = 0; h < 12; h++) out[h] = GOOD_STAR[Math.floorMod(h - start, 12)];+ return out;+ }++ /**+ * Whether the double-hour at this clock hour is good, on a day with this chi. Giờ Tý starts at 23:00, so from+ * 23:00 it is already the next day's Tý and takes that day's table.+ */+ static boolean goodAt(int dayChi, int hour24) {+ return hour24 == 23 ? goodHours((dayChi + 1) % 12)[0] : goodHours(dayChi)[hourIndex(hour24)];+ }++ static int hourSet(int dayChi) {+ return dayChi % 6;+ }++ /** 0..5 a good day with hour set 0..5, 6..11 a bad one: the alias and banner to show. */+ static int variant(Day d) {+ return (d.good ? 0 : 6) + hourSet(d.dayChi);+ }++ /** Double-hour of a clock hour: 23 and 0 are Tý (0), 1 and 2 Sửu (1), … 21 and 22 Hợi (11). */+ static int hourIndex(int hour24) {+ return ((hour24 + 1) / 2) % 12;+ }++ /**+ * The sun's apparent longitude in degrees at 00:00 UTC+7 of day number jdn: Meeus' low-precision geometric+ * longitude plus nutation and aberration, in terrestrial time (ΔT ≈ 69 s). Good to about a minute of time, which+ * puts a tiết beginning near midnight on the right day.+ */+ static double sunLongitudeDeg(long jdn) {+ double t = (jdn - 2451545.5 - TZ / 24 + 69 / 86400.0) / 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 omega = 125.04 - 1934.136 * t;+ double l = (l0 + dl - 0.00569 - 0.00478 * Math.sin(dr * omega)) % 360;+ return l < 0 ? l + 360 : l;+ }++ /**+ * Chi of the solar (tiết) month the day belongs to: Dần from Lập Xuân (315°), Mão from Kinh Trập (345°), …+ * A tiết that begins during the day counts for that day, so the sun is read at the day's end.+ */+ static int solarMonthChi(long jdn) {+ double l = sunLongitudeDeg(jdn + 1);+ return (2 + (int) Math.floor(((l - 315 + 360) % 360) / 30)) % 12;+ }++ static String[] nen(int truc) {+ return NEN[truc];+ }++ static String[] kieng(int truc) {+ return KIENG[truc];+ }++ static String moonWord(int lunarDay) {+ if (lunarDay == 1) return "mùng một";+ if (lunarDay <= 7) return "trăng non";+ if (lunarDay == 8) return "thượng huyền";+ if (lunarDay <= 14) return "trăng gần tròn";+ if (lunarDay == 15) return "trăng rằm";+ if (lunarDay <= 22) return "trăng khuyết dần";+ if (lunarDay == 23) return "hạ huyền";+ return "trăng tàn";+ }+}diff --git a/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_start.png b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_start.pngnew file mode 100644index 000000000..83937f747Binary files /dev/null and b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_start.png differdiff --git a/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v0.png b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v0.pngnew file mode 100644index 000000000..4161706d8Binary files /dev/null and b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v0.png differdiff --git a/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v1.png b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v1.pngnew file mode 100644index 000000000..0aaad2893Binary files /dev/null and b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v1.png differdiff --git a/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v10.png b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v10.pngnew file mode 100644index 000000000..e38ce352fBinary files /dev/null and b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v10.png differdiff --git a/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v11.png b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v11.pngnew file mode 100644index 000000000..3486e811bBinary files /dev/null and b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v11.png differdiff --git a/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v2.png b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v2.pngnew file mode 100644index 000000000..5568b1f80Binary files /dev/null and b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v2.png differdiff --git a/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v3.png b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v3.pngnew file mode 100644index 000000000..ebd99a8f5Binary files /dev/null and b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v3.png differdiff --git a/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v4.png b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v4.pngnew file mode 100644index 000000000..a1cab5a71Binary files /dev/null and b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v4.png differdiff --git a/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v5.png b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v5.pngnew file mode 100644index 000000000..de18de419Binary files /dev/null and b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v5.png differdiff --git a/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v6.png b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v6.pngnew file mode 100644index 000000000..c546d1987Binary files /dev/null and b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v6.png differdiff --git a/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v7.png b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v7.pngnew file mode 100644index 000000000..e8bc0ebfdBinary files /dev/null and b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v7.png differdiff --git a/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v8.png b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v8.pngnew file mode 100644index 000000000..f2382e396Binary files /dev/null and b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v8.png differdiff --git a/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v9.png b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v9.pngnew file mode 100644index 000000000..93bf2e823Binary files /dev/null and b/addons/lich-van-nien/app/src/main/res/drawable-nodpi/banner_v9.png differdiff --git a/addons/lich-van-nien/app/src/main/res/drawable/icon.xml b/addons/lich-van-nien/app/src/main/res/drawable/icon.xmlnew file mode 100644index 000000000..912950344--- /dev/null+++ b/addons/lich-van-nien/app/src/main/res/drawable/icon.xml@@ -0,0 +1,12 @@+<?xml version="1.0" encoding="utf-8"?>+<vector xmlns:android="http://schemas.android.com/apk/res/android"+ android:width="108dp" android:height="108dp" android:viewportWidth="108" android:viewportHeight="108">+ <path android:fillColor="#15161C" android:pathData="M0,0h108v108h-108z" />+ <path android:strokeColor="#3A3C46" android:strokeWidth="10" android:fillColor="#00000000"+ android:pathData="M54,22a32,32 0,1 1,-0.01 0" />+ <path android:strokeColor="#E8C77D" android:strokeWidth="10" android:fillColor="#00000000"+ android:pathData="M54,22a32,32 0,0 1,27.7 16" />+ <path android:strokeColor="#E8C77D" android:strokeWidth="10" android:fillColor="#00000000"+ android:pathData="M81.7,70a32,32 0,0 1,-27.7 16" />+ <path android:fillColor="#E8C77D" android:pathData="M54,54m-6,0a6,6 0,1 1,12 0a6,6 0,1 1,-12 0" />+</vector>diff --git a/addons/lich-van-nien/app/src/main/res/values/strings.xml b/addons/lich-van-nien/app/src/main/res/values/strings.xmlnew file mode 100644index 000000000..f3decdbb4--- /dev/null+++ b/addons/lich-van-nien/app/src/main/res/values/strings.xml@@ -0,0 +1,4 @@+<?xml version="1.0" encoding="utf-8"?>+<resources>+ <string name="app_name">Lịch Vạn Niên</string>+</resources>diff --git a/addons/lich-van-nien/app/src/main/res/xml/card_bad.xml b/addons/lich-van-nien/app/src/main/res/xml/card_bad.xmlnew file mode 100644index 000000000..f9991dd31--- /dev/null+++ b/addons/lich-van-nien/app/src/main/res/xml/card_bad.xml@@ -0,0 +1,2 @@+<?xml version="1.0" encoding="utf-8"?>+<card spec="1" label="Lich Van Nien" caption="Hac dao" accent="#9AA3B2" />diff --git a/addons/lich-van-nien/app/src/main/res/xml/card_good.xml b/addons/lich-van-nien/app/src/main/res/xml/card_good.xmlnew file mode 100644index 000000000..15a9baba6--- /dev/null+++ b/addons/lich-van-nien/app/src/main/res/xml/card_good.xml@@ -0,0 +1,2 @@+<?xml version="1.0" encoding="utf-8"?>+<card spec="1" label="Lich Van Nien" caption="Hoang dao" accent="#E8C77D" />diff --git a/addons/lich-van-nien/app/src/main/res/xml/card_start.xml b/addons/lich-van-nien/app/src/main/res/xml/card_start.xmlnew file mode 100644index 000000000..ceb166bf4--- /dev/null+++ b/addons/lich-van-nien/app/src/main/res/xml/card_start.xml@@ -0,0 +1,2 @@+<?xml version="1.0" encoding="utf-8"?>+<card spec="1" label="Lich Van Nien" accent="#E8C77D" />diff --git a/addons/lich-van-nien/app/src/test/java/com/tungpv/lichvannien/VnCalendarTest.java b/addons/lich-van-nien/app/src/test/java/com/tungpv/lichvannien/VnCalendarTest.javanew file mode 100644index 000000000..e2733a352--- /dev/null+++ b/addons/lich-van-nien/app/src/test/java/com/tungpv/lichvannien/VnCalendarTest.java@@ -0,0 +1,199 @@+package com.tungpv.lichvannien;++import static org.junit.Assert.assertArrayEquals;+import static org.junit.Assert.assertEquals;+import static org.junit.Assert.assertFalse;+import static org.junit.Assert.assertTrue;++import java.util.Calendar;+import java.util.GregorianCalendar;+import org.junit.Test;++/** Vietnamese calendar rules, UTC+7. */+public class VnCalendarTest {++ private static String canChi(int can, int chi) {+ return VnCalendar.CAN[can] + " " + VnCalendar.CHI[chi];+ }++ private static boolean[] hours(String... names) {+ boolean[] out = new boolean[12];+ for (String n : names) out[java.util.Arrays.asList(VnCalendar.CHI).indexOf(n)] = true;+ return out;+ }++ @Test+ public void today() {+ VnCalendar.Day d = VnCalendar.of(3, 11, 2026);+ assertEquals(25, d.lunarDay);+ assertEquals(9, d.lunarMonth);+ assertEquals(2026, d.lunarYear);+ assertFalse(d.leap);+ assertEquals("Tân Tỵ", canChi(d.dayCan, d.dayChi));+ assertEquals("Mậu Tuất", canChi(d.monthCan, d.monthChi));+ assertEquals("Bính Ngọ", canChi(d.yearCan, d.yearChi));+ assertEquals("Minh Đường", VnCalendar.STARS[d.star]);+ assertTrue(d.good);+ assertEquals(1, d.weekday);+ assertArrayEquals(hours("Sửu", "Thìn", "Ngọ", "Mùi", "Tuất", "Hợi"), VnCalendar.goodHours(d.dayChi));+ }++ @Test+ public void sixHourSets() {+ String[][] sets = {+ {"Tý", "Sửu", "Mão", "Ngọ", "Thân", "Dậu"},+ {"Dần", "Mão", "Tỵ", "Thân", "Tuất", "Hợi"},+ {"Tý", "Sửu", "Thìn", "Tỵ", "Mùi", "Tuất"},+ {"Tý", "Dần", "Mão", "Ngọ", "Mùi", "Dậu"},+ {"Dần", "Thìn", "Tỵ", "Thân", "Dậu", "Hợi"},+ {"Sửu", "Thìn", "Ngọ", "Mùi", "Tuất", "Hợi"},+ };+ for (int chi = 0; chi < 12; chi++) {+ assertArrayEquals("chi " + chi, hours(sets[chi % 6]), VnCalendar.goodHours(chi));+ assertEquals(chi % 6, VnCalendar.hourSet(chi));+ }+ }++ @Test+ public void dayCanChiAdvancesAndVariantInRange() {+ Calendar c = new GregorianCalendar(2025, Calendar.JANUARY, 1);+ VnCalendar.Day prev = null;+ while (c.get(Calendar.YEAR) < 2028) {+ VnCalendar.Day d = VnCalendar.of(c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.MONTH) + 1, c.get(Calendar.YEAR));+ if (prev != null) {+ assertEquals((prev.dayCan + 1) % 10, d.dayCan);+ assertEquals((prev.dayChi + 1) % 12, d.dayChi);+ assertEquals((prev.weekday + 1) % 7, d.weekday);+ }+ int v = VnCalendar.variant(d);+ assertTrue(v >= 0 && v < 12);+ assertEquals(d.good, v < 6);+ int good = 0;+ for (boolean b : VnCalendar.goodHours(d.dayChi)) if (b) good++;+ assertEquals(6, good);+ prev = d;+ c.add(Calendar.DAY_OF_MONTH, 1);+ }+ }++ @Test+ public void yearSwitchesAtTet() {+ VnCalendar.Day eve = VnCalendar.of(16, 2, 2026), tet = VnCalendar.of(17, 2, 2026);+ assertEquals("Ất Tỵ", canChi(eve.yearCan, eve.yearChi));+ assertEquals("Bính Ngọ", canChi(tet.yearCan, tet.yearChi));+ assertEquals(1, tet.lunarDay);+ assertEquals(1, tet.lunarMonth);+ assertEquals("Canh Dần", canChi(tet.monthCan, tet.monthChi));+ }++ @Test+ public void leapMonthHasTheBaseMonthsCanChi() {+ VnCalendar.Day leap = VnCalendar.of(25, 7, 2025), base = VnCalendar.of(25, 6, 2025);+ assertTrue(leap.leap);+ assertEquals(6, leap.lunarMonth);+ assertFalse(base.leap);+ assertEquals(6, base.lunarMonth);+ assertEquals("Quý Mùi", canChi(base.monthCan, base.monthChi));+ assertEquals("Quý Mùi", canChi(leap.monthCan, leap.monthChi));+ }++ @Test+ public void trucRepeatsOnTheDayATietBegins() {+ // Lập Đông (225°) 2026 falls on 7 November in Vietnam.+ assertTrue(VnCalendar.sunLongitudeDeg(VnCalendar.of(7, 11, 2026).jdn) < 225);+ assertTrue(VnCalendar.sunLongitudeDeg(VnCalendar.of(8, 11, 2026).jdn) >= 225);+ int found = 0;+ Calendar c = new GregorianCalendar(2026, Calendar.JANUARY, 2);+ VnCalendar.Day prev = VnCalendar.of(1, 1, 2026);+ while (c.get(Calendar.YEAR) == 2026) {+ VnCalendar.Day d = VnCalendar.of(c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.MONTH) + 1, 2026);+ if (d.truc == prev.truc) found++;+ else assertEquals((prev.truc + 1) % 12, d.truc);+ prev = d;+ c.add(Calendar.DAY_OF_MONTH, 1);+ }+ assertEquals(12, found);+ }++ /**+ * Published values, read 03/11/2026 from xemlicham.com (/am-lich/nam/Y/thang/M/ngay/D) and ngaydep.com+ * (/xem-ngay-D-thang-M-nam-Y.html); the two agree on every field here. The star is ngaydep's "Nhằm ngày …"+ * (xemlicham lists Ngọc Hạp stars, two on 03/11/2026 and 15/03/2027). Huyền Vũ is ngaydep's "Nguyên Vũ".+ * Columns: d, m, y, lunar day, lunar month, day can chi, month can chi, year can chi, star, trực, good hours.+ */+ private static final String[][] PUBLISHED = {+ {"29", "1", "2025", "1", "1", "Mậu Tuất", "Mậu Dần", "Ất Tỵ", "Tư Mệnh", "Thu", "Dần Thìn Tỵ Thân Dậu Hợi"},+ {"25", "7", "2025", "1", "6", "Ất Mùi", "Quý Mùi", "Ất Tỵ", "Huyền Vũ", "Kiến", "Dần Mão Tỵ Thân Tuất Hợi"},+ {"6", "10", "2025", "15", "8", "Mậu Thân", "Ất Dậu", "Ất Tỵ", "Bạch Hổ", "Bế", "Tý Sửu Thìn Tỵ Mùi Tuất"},+ {"17", "2", "2026", "1", "1", "Nhâm Tuất", "Canh Dần", "Bính Ngọ", "Tư Mệnh", "Thành", "Dần Thìn Tỵ Thân Dậu Hợi"},+ {"3", "11", "2026", "25", "9", "Tân Tỵ", "Mậu Tuất", "Bính Ngọ", "Minh Đường", "Nguy", "Sửu Thìn Ngọ Mùi Tuất Hợi"},+ {"6", "11", "2026", "28", "9", "Giáp Thân", "Mậu Tuất", "Bính Ngọ", "Kim Quỹ", "Khai", "Tý Sửu Thìn Tỵ Mùi Tuất"},+ // Lập Đông begins on 07/11/2026 (both sites' "Tiết khí"), so the trực repeats.+ {"7", "11", "2026", "29", "9", "Ất Dậu", "Mậu Tuất", "Bính Ngọ", "Kim Đường", "Khai", "Tý Dần Mão Ngọ Mùi Dậu"},+ {"8", "11", "2026", "30", "9", "Bính Tuất", "Mậu Tuất", "Bính Ngọ", "Bạch Hổ", "Bế", "Dần Thìn Tỵ Thân Dậu Hợi"},+ {"15", "3", "2027", "8", "2", "Quý Tỵ", "Quý Mão", "Đinh Mùi", "Chu Tước", "Mãn", "Sửu Thìn Ngọ Mùi Tuất Hợi"},+ };++ @Test+ public void matchesPublishedCalendars() {+ for (String[] p : PUBLISHED) {+ String date = p[0] + "/" + p[1] + "/" + p[2];+ VnCalendar.Day d = VnCalendar.of(Integer.parseInt(p[0]), Integer.parseInt(p[1]), Integer.parseInt(p[2]));+ assertEquals(date, Integer.parseInt(p[3]), d.lunarDay);+ assertEquals(date, Integer.parseInt(p[4]), d.lunarMonth);+ assertEquals(date, p[5], canChi(d.dayCan, d.dayChi));+ assertEquals(date, p[6], canChi(d.monthCan, d.monthChi));+ assertEquals(date, p[7], canChi(d.yearCan, d.yearChi));+ assertEquals(date, p[8], VnCalendar.STARS[d.star]);+ assertEquals(date, p[9], VnCalendar.TRUC[d.truc]);+ assertArrayEquals(date, hours(p[10].split(" ")), VnCalendar.goodHours(d.dayChi));+ }+ }++ @Test+ public void hourIndex() {+ assertEquals(0, VnCalendar.hourIndex(23));+ assertEquals(0, VnCalendar.hourIndex(0));+ assertEquals(1, VnCalendar.hourIndex(1));+ assertEquals(1, VnCalendar.hourIndex(2));+ assertEquals(7, VnCalendar.hourIndex(13));+ assertEquals(11, VnCalendar.hourIndex(22));+ }++ /**+ * Tiết that begin within half an hour after midnight in Vietnam (Lập Hạ 2027 ≈ 00:22 on 6 May, Lập Thu 2027+ * ≈ 00:25 on 8 August): ngaydep.com, read 03/11/2026, gives the tiết and the repeated trực on those days.+ */+ @Test+ public void tietJustAfterMidnight() {+ assertEquals("Định", VnCalendar.TRUC[VnCalendar.of(5, 5, 2027).truc]);+ assertEquals("Định", VnCalendar.TRUC[VnCalendar.of(6, 5, 2027).truc]);+ assertEquals("Bế", VnCalendar.TRUC[VnCalendar.of(7, 8, 2027).truc]);+ assertEquals("Bế", VnCalendar.TRUC[VnCalendar.of(8, 8, 2027).truc]);+ assertEquals("Kim Quỹ", VnCalendar.STARS[VnCalendar.of(5, 5, 2027).star]);+ assertEquals("Chu Tước", VnCalendar.STARS[VnCalendar.of(6, 5, 2027).star]);+ assertEquals("Bạch Hổ", VnCalendar.STARS[VnCalendar.of(7, 8, 2027).star]);+ assertEquals("Ngọc Đường", VnCalendar.STARS[VnCalendar.of(8, 8, 2027).star]);+ // Apparent longitude (with nutation and aberration, about 0.01° less than the geometric one) at 00:00 on+ // the tiết day: 22 minutes of the sun's motion short of 45°.+ assertEquals(44.9855, VnCalendar.sunLongitudeDeg(VnCalendar.of(6, 5, 2027).jdn), 0.0008);+ }++ @Test+ public void elevenPmIsTomorrowsTy() {+ // A Tý day: its own giờ Tý (00:00–01:00) is good (Kim Quỹ); from 23:00 it is the Sửu day's Tý, Thiên Hình.+ assertTrue(VnCalendar.goodAt(0, 0));+ assertFalse(VnCalendar.goodAt(0, 23));+ assertEquals(VnCalendar.goodHours(0)[6], VnCalendar.goodAt(0, 12));+ }++ @Test+ public void textsExist() {+ for (int t = 0; t < 12; t++) {+ assertTrue(VnCalendar.nen(t).length >= 2);+ assertTrue(VnCalendar.kieng(t).length >= 1);+ }+ assertEquals(12, VnCalendar.ANIMALS.length);+ for (int day = 1; day <= 30; day++) assertFalse(VnCalendar.moonWord(day).isEmpty());+ }+}diff --git a/addons/lich-van-nien/build.gradle b/addons/lich-van-nien/build.gradlenew file mode 100644index 000000000..48978475f--- /dev/null+++ b/addons/lich-van-nien/build.gradle@@ -0,0 +1,3 @@+plugins {+ id 'com.android.application' version '8.5.2' apply false+}diff --git a/addons/lich-van-nien/gradle.properties b/addons/lich-van-nien/gradle.propertiesnew file mode 100644index 000000000..18825f968--- /dev/null+++ b/addons/lich-van-nien/gradle.properties@@ -0,0 +1,3 @@+org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8+android.useAndroidX=true+android.nonTransitiveRClass=truediff --git a/addons/lich-van-nien/gradle/wrapper/gradle-wrapper.jar b/addons/lich-van-nien/gradle/wrapper/gradle-wrapper.jarnew file mode 100644index 000000000..2c3521197Binary files /dev/null and b/addons/lich-van-nien/gradle/wrapper/gradle-wrapper.jar differdiff --git a/addons/lich-van-nien/gradle/wrapper/gradle-wrapper.properties b/addons/lich-van-nien/gradle/wrapper/gradle-wrapper.propertiesnew file mode 100644index 000000000..77f5d0ba6--- /dev/null+++ b/addons/lich-van-nien/gradle/wrapper/gradle-wrapper.properties@@ -0,0 +1,8 @@+distributionBase=GRADLE_USER_HOME+distributionPath=wrapper/dists+distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip+distributionSha256Sum=d725d707bfabd4dfdc958c624003b3c80accc03f7037b5122c4b1d0ef15cecab+networkTimeout=10000+validateDistributionUrl=true+zipStoreBase=GRADLE_USER_HOME+zipStorePath=wrapper/distsdiff --git a/addons/lich-van-nien/gradlew b/addons/lich-van-nien/gradlewnew file mode 100755index 000000000..f5feea6d6--- /dev/null+++ b/addons/lich-van-nien/gradlew@@ -0,0 +1,252 @@+#!/bin/sh++#+# Copyright © 2015-2021 the original authors.+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# https://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+#+# SPDX-License-Identifier: Apache-2.0+#++##############################################################################+#+# Gradle start up script for POSIX generated by Gradle.+#+# Important for running:+#+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is+# noncompliant, but you have some other compliant shell such as ksh or+# bash, then to run this script, type that shell name before the whole+# command line, like:+#+# ksh Gradle+#+# Busybox and similar reduced shells will NOT work, because this script+# requires all of these POSIX shell features:+# * functions;+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;+# * compound commands having a testable exit status, especially «case»;+# * various built-in commands including «command», «set», and «ulimit».+#+# Important for patching:+#+# (2) This script targets any POSIX shell, so it avoids extensions provided+# by Bash, Ksh, etc; in particular arrays are avoided.+#+# The "traditional" practice of packing multiple parameters into a+# space-separated string is a well documented source of bugs and security+# problems, so this is (mostly) avoided, by progressively accumulating+# options in "$@", and eventually passing that to Java.+#+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;+# see the in-line comments for details.+#+# There are tweaks for specific operating systems such as AIX, CygWin,+# Darwin, MinGW, and NonStop.+#+# (3) This script is generated from the Groovy template+# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt+# within the Gradle project.+#+# You can find Gradle at https://github.com/gradle/gradle/.+#+##############################################################################++# Attempt to set APP_HOME++# Resolve links: $0 may be a link+app_path=$0++# Need this for daisy-chained symlinks.+while+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path+ [ -h "$app_path" ]+do+ ls=$( ls -ld "$app_path" )+ link=${ls#*' -> '}+ case $link in #(+ /*) app_path=$link ;; #(+ *) app_path=$APP_HOME$link ;;+ esac+done++# This is normally unused+# shellcheck disable=SC2034+APP_BASE_NAME=${0##*/}+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)+APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s+' "$PWD" ) || exit++# Use the maximum available, or set MAX_FD != -1 to use that value.+MAX_FD=maximum++warn () {+ echo "$*"+} >&2++die () {+ echo+ echo "$*"+ echo+ exit 1+} >&2++# OS specific support (must be 'true' or 'false').+cygwin=false+msys=false+darwin=false+nonstop=false+case "$( uname )" in #(+ CYGWIN* ) cygwin=true ;; #(+ Darwin* ) darwin=true ;; #(+ MSYS* | MINGW* ) msys=true ;; #(+ NONSTOP* ) nonstop=true ;;+esac++CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar+++# Determine the Java command to use to start the JVM.+if [ -n "$JAVA_HOME" ] ; then+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then+ # IBM's JDK on AIX uses strange locations for the executables+ JAVACMD=$JAVA_HOME/jre/sh/java+ else+ JAVACMD=$JAVA_HOME/bin/java+ fi+ if [ ! -x "$JAVACMD" ] ; then+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME++Please set the JAVA_HOME variable in your environment to match the+location of your Java installation."+ fi+else+ JAVACMD=java+ if ! command -v java >/dev/null 2>&1+ then+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.++Please set the JAVA_HOME variable in your environment to match the+location of your Java installation."+ fi+fi++# Increase the maximum file descriptors if we can.+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then+ case $MAX_FD in #(+ max*)+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.+ # shellcheck disable=SC2039,SC3045+ MAX_FD=$( ulimit -H -n ) ||+ warn "Could not query maximum file descriptor limit"+ esac+ case $MAX_FD in #(+ '' | soft) :;; #(+ *)+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.+ # shellcheck disable=SC2039,SC3045+ ulimit -n "$MAX_FD" ||+ warn "Could not set maximum file descriptor limit to $MAX_FD"+ esac+fi++# Collect all arguments for the java command, stacking in reverse order:+# * args from the command line+# * the main class name+# * -classpath+# * -D...appname settings+# * --module-path (only if needed)+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.++# For Cygwin or MSYS, switch paths to Windows format before running java+if "$cygwin" || "$msys" ; then+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )++ JAVACMD=$( cygpath --unix "$JAVACMD" )++ # Now convert the arguments - kludge to limit ourselves to /bin/sh+ for arg do+ if+ case $arg in #(+ -*) false ;; # don't mess with options #(+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath+ [ -e "$t" ] ;; #(+ *) false ;;+ esac+ then+ arg=$( cygpath --path --ignore --mixed "$arg" )+ fi+ # Roll the args list around exactly as many times as the number of+ # args, so each arg winds up back in the position where it started, but+ # possibly modified.+ #+ # NB: a `for` loop captures its iteration list before it begins, so+ # changing the positional parameters here affects neither the number of+ # iterations, nor the values presented in `arg`.+ shift # remove old arg+ set -- "$@" "$arg" # push replacement arg+ done+fi+++# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'++# Collect all arguments for the java command:+# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,+# and any embedded shellness will be escaped.+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be+# treated as '${Hostname}' itself on the command line.++set -- \+ "-Dorg.gradle.appname=$APP_BASE_NAME" \+ -classpath "$CLASSPATH" \+ org.gradle.wrapper.GradleWrapperMain \+ "$@"++# Stop when "xargs" is not available.+if ! command -v xargs >/dev/null 2>&1+then+ die "xargs is not available"+fi++# Use "xargs" to parse quoted args.+#+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.+#+# In Bash we could simply go:+#+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&+# set -- "${ARGS[@]}" "$@"+#+# but POSIX shell has neither arrays nor command substitution, so instead we+# post-process each arg (as a line of input to sed) to backslash-escape any+# character that might be a shell metacharacter, then use eval to reverse+# that process (while maintaining the separation between arguments), and wrap+# the whole thing up as a single "set" statement.+#+# This will of course break if any of these variables contains a newline or+# an unmatched quote.+#++eval "set -- $(+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |+ xargs -n1 |+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |+ tr '\n' ' '+ )" '"$@"'++exec "$JAVACMD" "$@"diff --git a/addons/lich-van-nien/gradlew.bat b/addons/lich-van-nien/gradlew.batnew file mode 100644index 000000000..9d21a2183--- /dev/null+++ b/addons/lich-van-nien/gradlew.bat@@ -0,0 +1,94 @@+@rem+@rem Copyright 2015 the original author or authors.+@rem+@rem Licensed under the Apache License, Version 2.0 (the "License");+@rem you may not use this file except in compliance with the License.+@rem You may obtain a copy of the License at+@rem+@rem https://www.apache.org/licenses/LICENSE-2.0+@rem+@rem Unless required by applicable law or agreed to in writing, software+@rem distributed under the License is distributed on an "AS IS" BASIS,+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+@rem See the License for the specific language governing permissions and+@rem limitations under the License.+@rem+@rem SPDX-License-Identifier: Apache-2.0+@rem++@if "%DEBUG%"=="" @echo off+@rem ##########################################################################+@rem+@rem Gradle startup script for Windows+@rem+@rem ##########################################################################++@rem Set local scope for the variables with windows NT shell+if "%OS%"=="Windows_NT" setlocal++set DIRNAME=%~dp0+if "%DIRNAME%"=="" set DIRNAME=.+@rem This is normally unused+set APP_BASE_NAME=%~n0+set APP_HOME=%DIRNAME%++@rem Resolve any "." and ".." in APP_HOME to make it shorter.+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi++@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"++@rem Find java.exe+if defined JAVA_HOME goto findJavaFromJavaHome++set JAVA_EXE=java.exe+%JAVA_EXE% -version >NUL 2>&1+if %ERRORLEVEL% equ 0 goto execute++echo. 1>&2+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2+echo. 1>&2+echo Please set the JAVA_HOME variable in your environment to match the 1>&2+echo location of your Java installation. 1>&2++goto fail++:findJavaFromJavaHome+set JAVA_HOME=%JAVA_HOME:"=%+set JAVA_EXE=%JAVA_HOME%/bin/java.exe++if exist "%JAVA_EXE%" goto execute++echo. 1>&2+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2+echo. 1>&2+echo Please set the JAVA_HOME variable in your environment to match the 1>&2+echo location of your Java installation. 1>&2++goto fail++:execute+@rem Setup the command line++set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar+++@rem Execute Gradle+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*++:end+@rem End local scope for the variables with windows NT shell+if %ERRORLEVEL% equ 0 goto mainEnd++:fail+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of+rem the _cmd.exe /c_ return code!+set EXIT_CODE=%ERRORLEVEL%+if %EXIT_CODE% equ 0 set EXIT_CODE=1+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%+exit /b %EXIT_CODE%++:mainEnd+if "%OS%"=="Windows_NT" endlocal++:omegadiff --git a/addons/lich-van-nien/screenshot.jpg b/addons/lich-van-nien/screenshot.jpgnew file mode 100644index 000000000..71b6dae7fBinary files /dev/null and b/addons/lich-van-nien/screenshot.jpg differdiff --git a/addons/lich-van-nien/settings.gradle b/addons/lich-van-nien/settings.gradlenew file mode 100644index 000000000..5d7c05633--- /dev/null+++ b/addons/lich-van-nien/settings.gradle@@ -0,0 +1,16 @@+pluginManagement {+ repositories {+ google()+ mavenCentral()+ gradlePluginPortal()+ }+}+dependencyResolutionManagement {+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)+ repositories {+ google()+ mavenCentral()+ }+}+rootProject.name = "lich-van-nien"+include ':app'diff --git a/addons/lich-van-nien/tools/make_banners.py b/addons/lich-van-nien/tools/make_banners.pynew file mode 100644index 000000000..2939ccc68--- /dev/null+++ b/addons/lich-van-nien/tools/make_banners.py@@ -0,0 +1,79 @@+"""Draws the tile banners: banner_v0..5 for a hoàng đạo day, banner_v6..11 for a hắc đạo day, hour set v % 6,+and banner_start, the neutral one shown until the app first runs.++Usage: python3 tools/make_banners.py <NotoSerif-Regular.ttf> <Roboto-Regular.ttf>+(both are on the TV: adb pull /system/fonts/NotoSerif-Regular.ttf, /system/fonts/Roboto-Regular.ttf)+"""+import sys+from pathlib import Path+from PIL import Image, ImageDraw, ImageFont, ImageFilter++W, H = 640, 360+OUT = Path(__file__).resolve().parent.parent / "app/src/main/res/drawable-nodpi"+SETS = [+ "Tý Sửu Mão Ngọ Thân Dậu", "Dần Mão Tỵ Thân Tuất Hợi", "Tý Sửu Thìn Tỵ Mùi Tuất",+ "Tý Dần Mão Ngọ Mùi Dậu", "Dần Thìn Tỵ Thân Dậu Hợi", "Sửu Thìn Ngọ Mùi Tuất Hợi",+]+++def gradient(good):+ # Radial glow from the top right over a dark base, as in the approved mockup.+ glow, mid, base = ((74, 58, 28), (29, 26, 20), (18, 19, 24)) if good else ((46, 50, 61), (24, 26, 32), (17, 18, 22))+ img = Image.new("RGB", (W, H), base)+ px = img.load()+ for y in range(H):+ for x in range(W):+ d = (((x - W * 0.85) / (W * 1.3)) ** 2 + ((y - H * 0.1) / (H * 1.2)) ** 2) ** 0.5+ if d < 0.55:+ t = d / 0.55+ c = tuple(int(glow[i] + (mid[i] - glow[i]) * t) for i in range(3))+ else:+ t = min(1, (d - 0.55) / 0.45)+ c = tuple(int(mid[i] + (base[i] - mid[i]) * t) for i in range(3))+ px[x, y] = c+ return img+++def spaced(draw, xy, text, font, fill, spacing):+ x, y = xy+ for ch in text:+ draw.text((x, y), ch, font=font, fill=fill)+ x += draw.textlength(ch, font=font) + spacing+++def main(serif_path, sans_path):+ serif = ImageFont.truetype(serif_path, 92)+ cap = ImageFont.truetype(sans_path, 30)+ hours_font = ImageFont.truetype(sans_path, 33)+ OUT.mkdir(parents=True, exist_ok=True)+ for v in range(12):+ good = v < 6+ img = gradient(good)+ d = ImageDraw.Draw(img)+ left = 52+ spaced(d, (left, 46), "HÔM NAY", cap, (170, 160, 140) if good else (130, 134, 145), 9)+ word = "Hoàng đạo" if good else "Hắc đạo"+ d.text((left - 4, 92), word, font=serif, fill=(236, 208, 142) if good else (194, 199, 210))+ d.line([(left, 262), (W - 40, 262)], fill=(78, 70, 56) if good else (58, 61, 70), width=2)+ hours = " · ".join(SETS[v % 6].split())+ # Shrink the hour line if needed so it fits on one line.+ f = hours_font+ size = 33+ while d.textlength(hours, font=f) > W - left - 36 and size > 22:+ size -= 1+ f = ImageFont.truetype(sans_path, size)+ d.text((left, 282), hours, font=f, fill=(244, 241, 234) if good else (200, 203, 212))+ img.save(OUT / f"banner_v{v}.png", optimize=True)+ # Before the app's first run: no verdict, just the name and how to open it.+ img = gradient(True)+ d = ImageDraw.Draw(img)+ spaced(d, (52, 46), "LỊCH VẠN NIÊN", cap, (170, 160, 140), 9)+ d.text((48, 92), "Hôm nay", font=serif, fill=(236, 208, 142))+ d.line([(52, 262), (W - 40, 262)], fill=(78, 70, 56), width=2)+ d.text((52, 282), "Bấm OK để xem ngày tốt, giờ tốt", font=hours_font, fill=(244, 241, 234))+ img.save(OUT / "banner_start.png", optimize=True)+ print("wrote", OUT)+++if __name__ == "__main__":+ main(sys.argv[1], sys.argv[2])