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: add Nepali Calendar, offline Bikram Sambat dates, a BS month grid and a clock screensaver
1yuvefd52e0b37df
diff --git a/addons/README.md b/addons/README.mdindex ad9825bbc..5a8820acd 100644--- a/addons/README.md+++ b/addons/README.md@@ -10,6 +10,7 @@ the core bigger or change how it behaves. You install an add-on only if you want| Add-on | What it does | Author | Tested on | Permissions | Screenshot ||---|---|---|---|---|---|| [Jewish Calendar](jewish-calendar/) | Offline Hebrew and Gregorian dates, holiday/Shabbat greetings, and an optional clock screensaver | [lionlev21](https://github.com/lionlev21) | Android TV 12 (model private) | None | <img src="jewish-calendar/screenshot.jpg" width="240" alt="Jewish Calendar on a TV"> |+| [Nepali Calendar](nepali-calendar/) | Offline Bikram Sambat and Gregorian dates in Devanagari and Latin, a BS month grid with weekends and fixed-date national days in red, and an optional clock screensaver | [@1yuv](https://github.com/1yuv) | Hisense 50A6H4 (SmartTV 4K, songshan), Android TV 11 | None | <img src="nepali-calendar/screenshot.jpg" width="240" alt="Nepali Calendar on a TV"> || [Frigate Glance](frigate-glance/) | Frigate camera pop-ups over whatever is playing | [NickLD](https://github.com/NickLD) | TCL 65Q650G | overlay, accessibility (card keys), network, foreground service | <img src="frigate-glance/screenshot.jpg" width="240" alt="Frigate Glance on a TV"> || [Capacity Stats](capacity-stats/) | Available/total and used/total RAM; available/total storage | [lionlev21](https://github.com/lionlev21) | Android TV 12 (model private) | None | <img src="capacity-stats/screenshot.jpg" width="240" alt="Capacity Stats on a TV"> || [Weather](weather/) | The weather for one city: now, US air quality and the next three days, from Open-Meteo (no key) | [@Sumyabazar1](https://github.com/Sumyabazar1) | Hisense SmartTV 4K FFM (lushan), Google TV 12 | `INTERNET` | <img src="weather/screenshot.jpg" width="240" alt="Weather on a TV"> |diff --git a/addons/nepali-calendar/.gitignore b/addons/nepali-calendar/.gitignorenew file mode 100644index 000000000..b1ba6bbc2--- /dev/null+++ b/addons/nepali-calendar/.gitignore@@ -0,0 +1,3 @@+/.gradle/+/local.properties+/**/build/diff --git a/addons/nepali-calendar/LICENSE-bikram-sambat b/addons/nepali-calendar/LICENSE-bikram-sambatnew file mode 100644index 000000000..261eeb9e9--- /dev/null+++ b/addons/nepali-calendar/LICENSE-bikram-sambat@@ -0,0 +1,201 @@+ Apache License+ Version 2.0, January 2004+ http://www.apache.org/licenses/++ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION++ 1. Definitions.++ "License" shall mean the terms and conditions for use, reproduction,+ and distribution as defined by Sections 1 through 9 of this document.++ "Licensor" shall mean the copyright owner or entity authorized by+ the copyright owner that is granting the License.++ "Legal Entity" shall mean the union of the acting entity and all+ other entities that control, are controlled by, or are under common+ control with that entity. For the purposes of this definition,+ "control" means (i) the power, direct or indirect, to cause the+ direction or management of such entity, whether by contract or+ otherwise, or (ii) ownership of fifty percent (50%) or more of the+ outstanding shares, or (iii) beneficial ownership of such entity.++ "You" (or "Your") shall mean an individual or Legal Entity+ exercising permissions granted by this License.++ "Source" form shall mean the preferred form for making modifications,+ including but not limited to software source code, documentation+ source, and configuration files.++ "Object" form shall mean any form resulting from mechanical+ transformation or translation of a Source form, including but+ not limited to compiled object code, generated documentation,+ and conversions to other media types.++ "Work" shall mean the work of authorship, whether in Source or+ Object form, made available under the License, as indicated by a+ copyright notice that is included in or attached to the work+ (an example is provided in the Appendix below).++ "Derivative Works" shall mean any work, whether in Source or Object+ form, that is based on (or derived from) the Work and for which the+ editorial revisions, annotations, elaborations, or other modifications+ represent, as a whole, an original work of authorship. For the purposes+ of this License, Derivative Works shall not include works that remain+ separable from, or merely link (or bind by name) to the interfaces of,+ the Work and Derivative Works thereof.++ "Contribution" shall mean any work of authorship, including+ the original version of the Work and any modifications or additions+ to that Work or Derivative Works thereof, that is intentionally+ submitted to Licensor for inclusion in the Work by the copyright owner+ or by an individual or Legal Entity authorized to submit on behalf of+ the copyright owner. For the purposes of this definition, "submitted"+ means any form of electronic, verbal, or written communication sent+ to the Licensor or its representatives, including but not limited to+ communication on electronic mailing lists, source code control systems,+ and issue tracking systems that are managed by, or on behalf of, the+ Licensor for the purpose of discussing and improving the Work, but+ excluding communication that is conspicuously marked or otherwise+ designated in writing by the copyright owner as "Not a Contribution."++ "Contributor" shall mean Licensor and any individual or Legal Entity+ on behalf of whom a Contribution has been received by Licensor and+ subsequently incorporated within the Work.++ 2. Grant of Copyright License. Subject to the terms and conditions of+ this License, each Contributor hereby grants to You a perpetual,+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable+ copyright license to reproduce, prepare Derivative Works of,+ publicly display, publicly perform, sublicense, and distribute the+ Work and such Derivative Works in Source or Object form.++ 3. Grant of Patent License. Subject to the terms and conditions of+ this License, each Contributor hereby grants to You a perpetual,+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable+ (except as stated in this section) patent license to make, have made,+ use, offer to sell, sell, import, and otherwise transfer the Work,+ where such license applies only to those patent claims licensable+ by such Contributor that are necessarily infringed by their+ Contribution(s) alone or by combination of their Contribution(s)+ with the Work to which such Contribution(s) was submitted. If You+ institute patent litigation against any entity (including a+ cross-claim or counterclaim in a lawsuit) alleging that the Work+ or a Contribution incorporated within the Work constitutes direct+ or contributory patent infringement, then any patent licenses+ granted to You under this License for that Work shall terminate+ as of the date such litigation is filed.++ 4. Redistribution. You may reproduce and distribute copies of the+ Work or Derivative Works thereof in any medium, with or without+ modifications, and in Source or Object form, provided that You+ meet the following conditions:++ (a) You must give any other recipients of the Work or+ Derivative Works a copy of this License; and++ (b) You must cause any modified files to carry prominent notices+ stating that You changed the files; and++ (c) You must retain, in the Source form of any Derivative Works+ that You distribute, all copyright, patent, trademark, and+ attribution notices from the Source form of the Work,+ excluding those notices that do not pertain to any part of+ the Derivative Works; and++ (d) If the Work includes a "NOTICE" text file as part of its+ distribution, then any Derivative Works that You distribute must+ include a readable copy of the attribution notices contained+ within such NOTICE file, excluding those notices that do not+ pertain to any part of the Derivative Works, in at least one+ of the following places: within a NOTICE text file distributed+ as part of the Derivative Works; within the Source form or+ documentation, if provided along with the Derivative Works; or,+ within a display generated by the Derivative Works, if and+ wherever such third-party notices normally appear. The contents+ of the NOTICE file are for informational purposes only and+ do not modify the License. You may add Your own attribution+ notices within Derivative Works that You distribute, alongside+ or as an addendum to the NOTICE text from the Work, provided+ that such additional attribution notices cannot be construed+ as modifying the License.++ You may add Your own copyright statement to Your modifications and+ may provide additional or different license terms and conditions+ for use, reproduction, or distribution of Your modifications, or+ for any such Derivative Works as a whole, provided Your use,+ reproduction, and distribution of the Work otherwise complies with+ the conditions stated in this License.++ 5. Submission of Contributions. Unless You explicitly state otherwise,+ any Contribution intentionally submitted for inclusion in the Work+ by You to the Licensor shall be under the terms and conditions of+ this License, without any additional terms or conditions.+ Notwithstanding the above, nothing herein shall supersede or modify+ the terms of any separate license agreement you may have executed+ with Licensor regarding such Contributions.++ 6. Trademarks. This License does not grant permission to use the trade+ names, trademarks, service marks, or product names of the Licensor,+ except as required for reasonable and customary use in describing the+ origin of the Work and reproducing the content of the NOTICE file.++ 7. Disclaimer of Warranty. Unless required by applicable law or+ agreed to in writing, Licensor provides the Work (and each+ Contributor provides its Contributions) on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or+ implied, including, without limitation, any warranties or conditions+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A+ PARTICULAR PURPOSE. You are solely responsible for determining the+ appropriateness of using or redistributing the Work and assume any+ risks associated with Your exercise of permissions under this License.++ 8. Limitation of Liability. In no event and under no legal theory,+ whether in tort (including negligence), contract, or otherwise,+ unless required by applicable law (such as deliberate and grossly+ negligent acts) or agreed to in writing, shall any Contributor be+ liable to You for damages, including any direct, indirect, special,+ incidental, or consequential damages of any character arising as a+ result of this License or out of the use or inability to use the+ Work (including but not limited to damages for loss of goodwill,+ work stoppage, computer failure or malfunction, or any and all+ other commercial damages or losses), even if such Contributor+ has been advised of the possibility of such damages.++ 9. Accepting Warranty or Additional Liability. While redistributing+ the Work or Derivative Works thereof, You may choose to offer,+ and charge a fee for, acceptance of support, warranty, indemnity,+ or other liability obligations and/or rights consistent with this+ License. However, in accepting such obligations, You may act only+ on Your own behalf and on Your sole responsibility, not on behalf+ of any other Contributor, and only if You agree to indemnify,+ defend, and hold each Contributor harmless for any liability+ incurred by, or claims asserted against, such Contributor by reason+ of your accepting any such warranty or additional liability.++ END OF TERMS AND CONDITIONS++ APPENDIX: How to apply the Apache License to your work.++ To apply the Apache License to your work, attach the following+ boilerplate notice, with the fields enclosed by brackets "[]"+ replaced with your own identifying information. (Don't include+ the brackets!) The text should be enclosed in the appropriate+ comment syntax for the file format. We also recommend that a+ file or class name and description of purpose be included on the+ same "printed page" as the copyright notice for easier+ identification within third-party archives.++ Copyright [yyyy] [name of copyright owner]++ 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++ http://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.diff --git a/addons/nepali-calendar/README.md b/addons/nepali-calendar/README.mdnew file mode 100644index 000000000..9e080da93--- /dev/null+++ b/addons/nepali-calendar/README.md@@ -0,0 +1,65 @@+# Nepali Calendar++An optional, standalone module card with today's Bikram Sambat (BS) date in Devanagari and in Latin+letters, the Gregorian date, a clock, and the BS month as a grid. It also offers an optional system+clock screensaver. Installing it never changes the launcher's header, date line, settings or theme; it+uses only the existing module-card contract.++## Setup++Build from this folder with JDK 17 and Android SDK 34:++```sh+./gradlew --no-daemon testReleaseUnitTest lintRelease assembleRelease+```++Sideload the APK with the repository's normal ADB tools. On Home, approve **Nepali Calendar** when the+launcher asks about its card, or enable it later under Settings → Module cards. The card opens the+calendar's own screen; it cannot put a live date into the launcher header or tile caption.++The screen shows the clock, the date as "मंगलबार, कार्तिक १०, २०८३" and "Kartik 10, 2083 BS", and the+Gregorian date in the TV's language. The grid shows the BS month, Sunday first, each day with its+Gregorian day underneath; today is marked, and Saturdays, Sundays and the fixed-date national days are in red.+**Previous**, **Today** and **Next** page the grid, as do Channel Up/Down and Rewind/Fast+forward. The BS day changes at local midnight, so keep the TV's date, time and time zone correct.++The national days are the ones kept on a fixed BS date: New Year (Baishakh 1), Loktantra Diwas+(Baishakh 11), Republic Day (Jestha 15), Constitution Day (Asoj 3), Prithvi Jayanti (Poush 27), Maghe+Sankranti (Magh 1), Martyrs' Day (Magh 16) and Democracy Day (Falgun 7). On those days the screen shows+the day's name. Dashain, Tihar, Holi, Teej and the other lunar festivals move every year and are not+shown; neither are tithis or government-announced holidays. This is a date calendar, not a patro for+rituals.++English and Nepali UI strings are included; the BS date is always shown in both scripts.++## Optional screensaver++Open **Screensaver** and select this app if desired. The button appears only on TVs with a+screensaver picker; Google TV has none for other apps' screensavers, so there it is hidden. The add-on+does not select itself or change the idle timeout. Its dream shows the national day when there is one, the clock, the BS date in+both scripts and the Gregorian date, and drifts within a padded area. Any key leaves the screensaver.+It does not replace the launcher's own idle-clock activity.++## Permissions++None requested. The exported dream requires Android's `BIND_DREAM_SERVICE` permission from its caller;+this is a binding restriction, not a permission granted to the app. No Internet, location, overlays,+accessibility, boot receiver, alarms, foreground service, analytics or ads. Nothing is stored. The only+service is the optional system-managed `DreamService`; updates stop when the activity/dream is not+visible.++## Data and validation++BS months have 29 to 32 days set each year by the calendar committee, so conversion needs a table,+kept in `BikramSambat.java`. It covers BS 1970 to 2090 (13 April 1913 to about April 2034); outside+that the screen says so and shows only the clock and the Gregorian date.++Unit tests cover known conversions both ways, the 2082 and 2083 new years, month lengths, a day-by-day+round trip across the whole table, the table's edges, month paging across years, Devanagari digits,+weekday and weekend handling, and that every national day exists in every year.++Tested on a Hisense 50A6H4 (SmartTV 4K, songshan), Android TV 11, with the CleanYourTV launcher: the+card, the screen, D-pad focus from every edge, month paging by button and Channel Down, Back to Home,+and the screensaver started and left with a key.++diff --git a/addons/nepali-calendar/app/build.gradle b/addons/nepali-calendar/app/build.gradlenew file mode 100644index 000000000..6c386a92e--- /dev/null+++ b/addons/nepali-calendar/app/build.gradle@@ -0,0 +1,18 @@+plugins { id 'com.android.application' }+android {+ namespace 'com.oneyuv.tv.nepalicalendar'+ compileSdk 34+ buildFeatures { aidl false }+ defaultConfig { applicationId 'com.oneyuv.tv.nepalicalendar'; 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/nepali-calendar/app/proguard-rules.pro b/addons/nepali-calendar/app/proguard-rules.pronew file mode 100644index 000000000..e69de29bbdiff --git a/addons/nepali-calendar/app/src/main/AndroidManifest.xml b/addons/nepali-calendar/app/src/main/AndroidManifest.xmlnew file mode 100644index 000000000..5ac941fdf--- /dev/null+++ b/addons/nepali-calendar/app/src/main/AndroidManifest.xml@@ -0,0 +1,16 @@+<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" />+ <queries><intent><action android:name="android.settings.DREAM_SETTINGS" /></intent></queries>+ <application android:allowBackup="false" android:theme="@android:style/Theme.Material.NoActionBar.Fullscreen"+ android:label="@string/app_name" android:icon="@drawable/icon" android:banner="@drawable/icon">+ <activity android:name=".CalendarActivity" android:exported="true">+ <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/module_card" />+ </activity>+ <service android:name=".CalendarDream" android:exported="true" android:permission="android.permission.BIND_DREAM_SERVICE">+ <intent-filter><action android:name="android.service.dreams.DreamService" /></intent-filter>+ </service>+ </application>+</manifest>diff --git a/addons/nepali-calendar/app/src/main/java/com/oneyuv/tv/nepalicalendar/BikramSambat.java b/addons/nepali-calendar/app/src/main/java/com/oneyuv/tv/nepalicalendar/BikramSambat.javanew file mode 100644index 000000000..7db7f5898--- /dev/null+++ b/addons/nepali-calendar/app/src/main/java/com/oneyuv/tv/nepalicalendar/BikramSambat.java@@ -0,0 +1,84 @@+package com.oneyuv.tv.nepalicalendar;++import java.time.LocalDate;++/**+ * Offline Bikram Sambat (Nepali solar calendar) conversion.+ *+ * The month-length table and its encoding are copied from medic/bikram-sambat+ * (https://github.com/medic/bikram-sambat, java/lib/.../BsCalendar.java, Apache License 2.0,+ * see LICENSE-bikram-sambat). Changed here: java.time epoch days replace the string and+ * millisecond arithmetic, and dates outside the table return null instead of throwing.+ */+final class BikramSambat {+ static final int FIRST_YEAR = 1970;+ /** BS 1970-01-01 (Baisakh 1). */+ private static final LocalDate EPOCH = LocalDate.of(1913, 4, 13);+ /** Two bits per month, Baisakh in the lowest bits: days = 29 + value. */+ private static final long[] ENCODED_MONTH_LENGTHS = {+ 5315258L, 5314490L, 9459438L, 8673005L, 5315258L, 5315066L, 9459438L, 8673005L, 5315258L, 5314298L,+ 9459438L, 5327594L, 5315258L, 5314298L, 9459438L, 5327594L, 5315258L, 5314286L, 9459438L, 5315306L,+ 5315258L, 5314286L, 8673006L, 5315306L, 5315258L, 5265134L, 8673006L, 5315258L, 5315258L, 9459438L,+ 8673005L, 5315258L, 5314298L, 9459438L, 8673005L, 5315258L, 5314298L, 9459438L, 8473322L, 5315258L,+ 5314298L, 9459438L, 5327594L, 5315258L, 5314298L, 9459438L, 5327594L, 5315258L, 5314286L, 8673006L,+ 5315306L, 5315258L, 5265134L, 8673006L, 5315306L, 5315258L, 9459438L, 8673005L, 5315258L, 5314490L,+ 9459438L, 8673005L, 5315258L, 5314298L, 9459438L, 8473325L, 5315258L, 5314298L, 9459438L, 5327594L,+ 5315258L, 5314298L, 9459438L, 5327594L, 5315258L, 5314286L, 9459438L, 5315306L, 5315258L, 5265134L,+ 8673006L, 5315306L, 5315258L, 5265134L, 8673006L, 5315258L, 5314490L, 9459438L, 8673005L, 5315258L,+ 5314298L, 9459438L, 8669933L, 5315258L, 5314298L, 9459438L, 8473322L, 5315258L, 5314298L, 9459438L,+ 5327594L, 5315258L, 5314286L, 9459438L, 5315306L, 5315258L, 5265134L, 8673006L, 5315306L, 5315258L,+ 5265134L, 8673006L, 5315258L, 5315258L, 5527226L, 5528046L, 5527277L, 5528250L, 5528057L, 5527277L,+ 5527277L+ };+ static final int LAST_YEAR = FIRST_YEAR + ENCODED_MONTH_LENGTHS.length - 1;++ final int year, month, day;++ BikramSambat(int year, int month, int day) { this.year = year; this.month = month; this.day = day; }++ static boolean supported(int year) { return year >= FIRST_YEAR && year <= LAST_YEAR; }++ /** 29 to 32; month is 1 (Baisakh) to 12 (Chaitra). */+ static int daysInMonth(int year, int month) {+ if (!supported(year) || month < 1 || month > 12) throw new IllegalArgumentException(year + "/" + month);+ return 29 + (int) ((ENCODED_MONTH_LENGTHS[year - FIRST_YEAR] >>> ((month - 1) << 1)) & 3);+ }++ /** The BS date of a Gregorian day, or null outside the table. */+ static BikramSambat of(LocalDate date) {+ long days = date.toEpochDay() - EPOCH.toEpochDay();+ if (days < 0) return null;+ for (int year = FIRST_YEAR; year <= LAST_YEAR; year++) {+ for (int month = 1; month <= 12; month++) {+ int length = daysInMonth(year, month);+ if (days < length) return new BikramSambat(year, month, (int) days + 1);+ days -= length;+ }+ }+ return null;+ }++ LocalDate toGregorian() {+ if (day < 1 || day > daysInMonth(year, month)) throw new IllegalArgumentException(toString());+ long days = day - 1;+ for (int y = FIRST_YEAR; y < year; y++) for (int m = 1; m <= 12; m++) days += daysInMonth(y, m);+ for (int m = 1; m < month; m++) days += daysInMonth(year, m);+ return EPOCH.plusDays(days);+ }++ /** The first day of the month a number of months away, or null outside the table. */+ BikramSambat plusMonths(int months) {+ int index = year * 12 + month - 1 + months;+ return supported(index / 12) ? new BikramSambat(index / 12, index % 12 + 1, 1) : null;+ }++ @Override public boolean equals(Object other) {+ if (!(other instanceof BikramSambat)) return false;+ BikramSambat that = (BikramSambat) other;+ return year == that.year && month == that.month && day == that.day;+ }++ @Override public int hashCode() { return (year * 13 + month) * 32 + day; }++ @Override public String toString() { return String.format(java.util.Locale.ROOT, "%d-%02d-%02d", year, month, day); }+}diff --git a/addons/nepali-calendar/app/src/main/java/com/oneyuv/tv/nepalicalendar/CalendarActivity.java b/addons/nepali-calendar/app/src/main/java/com/oneyuv/tv/nepalicalendar/CalendarActivity.javanew file mode 100644index 000000000..451f88bb9--- /dev/null+++ b/addons/nepali-calendar/app/src/main/java/com/oneyuv/tv/nepalicalendar/CalendarActivity.java@@ -0,0 +1,92 @@+package com.oneyuv.tv.nepalicalendar;++import android.app.Activity;+import android.content.ActivityNotFoundException;+import android.content.Intent;+import android.content.res.ColorStateList;+import android.graphics.drawable.GradientDrawable;+import android.graphics.drawable.StateListDrawable;+import android.os.Bundle;+import android.provider.Settings;+import android.view.Gravity;+import android.view.KeyEvent;+import android.widget.Button;+import android.widget.LinearLayout;+import android.widget.Toast;++/** A standalone module card; it never writes the launcher's configuration. */+public final class CalendarActivity extends Activity {+ private CalendarPanel panel;++ @Override public void onCreate(Bundle state) {+ super.onCreate(state);+ panel = new CalendarPanel(this, false);+ LinearLayout actions = new LinearLayout(this);+ actions.setGravity(Gravity.CENTER);+ actions.setPadding(0, panel.dp(16), 0, 0);+ button(actions, R.string.previous).setOnClickListener(v -> panel.showMonth(-1));+ Button today = button(actions, R.string.today);+ today.setOnClickListener(v -> panel.showMonth(0));+ button(actions, R.string.next).setOnClickListener(v -> panel.showMonth(1));+ // Google TV has no screensaver picker for other apps' dreams: offer the button only where one exists.+ Intent dreams = new Intent(Settings.ACTION_DREAM_SETTINGS);+ if (dreams.resolveActivity(getPackageManager()) != null) {+ button(actions, R.string.screensaver).setOnClickListener(v -> {+ try { startActivity(dreams); }+ catch (ActivityNotFoundException | SecurityException e) {+ Toast.makeText(this, R.string.screensaver_missing, Toast.LENGTH_LONG).show();+ }+ });+ }+ panel.addActions(actions);+ setContentView(panel);+ today.requestFocus();+ }++ private Button button(LinearLayout parent, int label) {+ Button button = new Button(this);+ button.setText(label);+ button.setAllCaps(false);+ button.setSingleLine(true);+ button.setMinWidth(0);+ button.setMinimumWidth(0);+ // The stock button barely changes when focused; on a TV the focus has to be plain to see.+ StateListDrawable background = new StateListDrawable();+ background.addState(new int[]{android.R.attr.state_focused}, shape(CalendarPanel.ACCENT));+ background.addState(new int[0], shape(0x33ffffff));+ button.setBackground(background);+ button.setTextColor(new ColorStateList(new int[][]{{android.R.attr.state_focused}, {}},+ new int[]{CalendarPanel.BACKGROUND, CalendarPanel.TEXT}));+ button.setPadding(panel.dp(16), panel.dp(8), panel.dp(16), panel.dp(8));+ LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(+ LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);+ params.setMargins(panel.dp(4), 0, panel.dp(4), 0);+ button.setLayoutParams(params);+ parent.addView(button);+ return button;+ }++ private GradientDrawable shape(int color) {+ GradientDrawable shape = new GradientDrawable();+ shape.setColor(color);+ shape.setCornerRadius(panel.dp(6));+ return shape;+ }++ /** Channel and media keys page the month from anywhere on the screen. */+ @Override public boolean onKeyDown(int code, KeyEvent event) {+ switch (code) {+ case KeyEvent.KEYCODE_CHANNEL_UP: case KeyEvent.KEYCODE_PAGE_UP: case KeyEvent.KEYCODE_MEDIA_REWIND:+ panel.showMonth(-1);+ return true;+ case KeyEvent.KEYCODE_CHANNEL_DOWN: case KeyEvent.KEYCODE_PAGE_DOWN: case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:+ panel.showMonth(1);+ return true;+ default:+ return super.onKeyDown(code, event);+ }+ }++ @Override protected void onResume() { super.onResume(); panel.start(); }+ @Override protected void onPause() { panel.stop(); super.onPause(); }+}diff --git a/addons/nepali-calendar/app/src/main/java/com/oneyuv/tv/nepalicalendar/CalendarDream.java b/addons/nepali-calendar/app/src/main/java/com/oneyuv/tv/nepalicalendar/CalendarDream.javanew file mode 100644index 000000000..3d1639a15--- /dev/null+++ b/addons/nepali-calendar/app/src/main/java/com/oneyuv/tv/nepalicalendar/CalendarDream.java@@ -0,0 +1,19 @@+package com.oneyuv.tv.nepalicalendar;++import android.service.dreams.DreamService;++/** Optional system screensaver. Android starts it only when the owner selects this dream. */+public final class CalendarDream extends DreamService {+ private CalendarPanel panel;+ @Override public void onAttachedToWindow() {+ super.onAttachedToWindow();+ setInteractive(false);+ setFullscreen(true);+ setScreenBright(false);+ panel = new CalendarPanel(this, true);+ setContentView(panel);+ }+ @Override public void onDreamingStarted() { super.onDreamingStarted(); panel.start(); }+ @Override public void onDreamingStopped() { if (panel != null) panel.stop(); super.onDreamingStopped(); }+ @Override public void onDetachedFromWindow() { if (panel != null) panel.stop(); super.onDetachedFromWindow(); }+}diff --git a/addons/nepali-calendar/app/src/main/java/com/oneyuv/tv/nepalicalendar/CalendarPanel.java b/addons/nepali-calendar/app/src/main/java/com/oneyuv/tv/nepalicalendar/CalendarPanel.javanew file mode 100644index 000000000..3e6799b51--- /dev/null+++ b/addons/nepali-calendar/app/src/main/java/com/oneyuv/tv/nepalicalendar/CalendarPanel.java@@ -0,0 +1,194 @@+package com.oneyuv.tv.nepalicalendar;++import android.content.Context;+import android.graphics.Color;+import android.graphics.drawable.GradientDrawable;+import android.os.Handler;+import android.os.Looper;+import android.text.SpannableStringBuilder;+import android.text.Spanned;+import android.text.style.RelativeSizeSpan;+import android.view.Gravity;+import android.view.View;+import android.widget.LinearLayout;+import android.widget.TextView;+import java.time.LocalDate;+import java.time.ZonedDateTime;+import java.time.format.DateTimeFormatter;+import java.util.Locale;++/** Shared foreground-only scene. No timers survive the activity or dream stopping. */+final class CalendarPanel extends LinearLayout {+ static final int TEXT = Color.WHITE, DIM = 0xffa0aab8, SOFT = 0xffdddddd,+ ACCENT = 0xffe8a05a, BACKGROUND = 0xff1c1210, HOLIDAY = 0xffff7b72, TODAY = 0xff8a3a1c;+ private final Handler handler = new Handler(Looper.getMainLooper());+ private final boolean dream;+ private final LinearLayout info;+ private final TextView greeting, clock, nepali, latin, gregorian, note;+ private TextView title;+ private final TextView[] cells = new TextView[42];+ /** Months between today's BS month and the one in the grid. */+ private int offset;+ private final Runnable tick = new Runnable() {+ @Override public void run() {+ refresh();+ handler.postDelayed(this, 60_000L - System.currentTimeMillis() % 60_000L);+ }+ };++ CalendarPanel(Context context, boolean dream) {+ super(context);+ this.dream = dream;+ setOrientation(HORIZONTAL);+ setGravity(Gravity.CENTER);+ setPadding(dp(40), dp(24), dp(40), dp(24));+ setBackgroundColor(BACKGROUND);+ info = new LinearLayout(context);+ info.setOrientation(VERTICAL);+ info.setGravity(Gravity.CENTER);+ addView(info, new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));+ greeting = line(dream ? 28 : 22, ACCENT);+ clock = line(dream ? 92 : 64, TEXT);+ nepali = line(dream ? 34 : 26, TEXT);+ latin = line(dream ? 24 : 20, SOFT);+ gregorian = line(dream ? 24 : 20, SOFT);+ note = line(14, DIM);+ note.setPadding(0, dp(16), 0, 0);+ if (!dream) addView(grid(context), new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));+ }++ /** The card screen adds its buttons under the dates. */+ void addActions(View actions) { info.addView(actions); }++ private TextView line(int size, int color) {+ TextView text = text(size, color);+ text.setMaxLines(2);+ text.setPadding(0, dp(4), 0, dp(4));+ info.addView(text, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));+ return text;+ }++ private TextView text(int size, int color) {+ TextView text = new TextView(getContext());+ text.setTextSize(size);+ text.setTextColor(color);+ text.setGravity(Gravity.CENTER);+ text.setIncludeFontPadding(false);+ return text;+ }++ private View grid(Context context) {+ LinearLayout grid = new LinearLayout(context);+ grid.setOrientation(VERTICAL);+ grid.setPadding(dp(24), 0, 0, 0);+ title = text(22, TEXT);+ title.setPadding(0, 0, 0, dp(8));+ grid.addView(title);+ LinearLayout header = row(grid);+ for (int i = 0; i < 7; i++) {+ TextView name = cell(header, 15, i == 0 || i == 6 ? HOLIDAY : DIM, dp(28));+ name.setText(NepaliDate.WEEKDAYS_SHORT[i]);+ }+ for (int r = 0; r < 6; r++) {+ LinearLayout week = row(grid);+ for (int c = 0; c < 7; c++) cells[r * 7 + c] = cell(week, 22, TEXT, dp(46));+ }+ return grid;+ }++ private LinearLayout row(LinearLayout parent) {+ LinearLayout row = new LinearLayout(getContext());+ row.setBaselineAligned(false); // Empty cells would otherwise push their row down.+ parent.addView(row);+ return row;+ }++ private TextView cell(LinearLayout row, int size, int color, int height) {+ TextView cell = text(size, color);+ LayoutParams params = new LayoutParams(dp(58), height);+ params.setMargins(dp(2), dp(2), dp(2), dp(2));+ row.addView(cell, params);+ return cell;+ }++ int dp(int value) { return Math.round(value * getResources().getDisplayMetrics().density); }++ void start() {+ handler.removeCallbacks(tick);+ tick.run();+ }++ void stop() { handler.removeCallbacksAndMessages(null); }++ /** Moves the grid by whole months; 0 returns to today's month. */+ void showMonth(int delta) {+ offset = delta == 0 ? 0 : offset + delta;+ refresh();+ }++ private void refresh() {+ ZonedDateTime now = ZonedDateTime.now();+ Locale locale = Locale.getDefault();+ LocalDate date = now.toLocalDate();+ BikramSambat today = BikramSambat.of(date);+ clock.setText(DateTimeFormatter.ofPattern(+ android.text.format.DateFormat.is24HourFormat(getContext()) ? "HH:mm" : "h:mm a", locale).format(now));+ gregorian.setText(DateTimeFormatter.ofPattern(+ android.text.format.DateFormat.getBestDateTimePattern(locale, "EEEEdMMMMyyyy"), locale).format(now));+ if (today == null || !BikramSambat.supported(today.year)) {+ nepali.setVisibility(View.GONE);+ latin.setVisibility(View.GONE);+ greeting.setVisibility(View.GONE);+ note.setText(getContext().getString(R.string.out_of_range, BikramSambat.FIRST_YEAR, BikramSambat.LAST_YEAR));+ note.setVisibility(View.VISIBLE);+ if (title != null) title.setText("");+ for (TextView cell : cells) if (cell != null) { cell.setText(""); cell.setBackground(null); }+ return;+ }+ nepali.setText(NepaliDate.text(today, date));+ latin.setText(NepaliDate.latin(today));+ nepali.setVisibility(View.VISIBLE);+ latin.setVisibility(View.VISIBLE);+ int day = NepaliDate.nationalDay(today);+ greeting.setText(day == 0 ? "" : getResources().getStringArray(R.array.national_days)[day - 1]);+ greeting.setVisibility(day == 0 ? View.GONE : View.VISIBLE);+ note.setVisibility(View.GONE);+ if (!dream) month(today);+ // Drift in a padded area, keeping all content inside the full-screen panel.+ if (dream) info.setTranslationY(((now.getMinute() % 5) - 2) * dp(8));+ }++ private void month(BikramSambat today) {+ BikramSambat first = new BikramSambat(today.year, today.month, 1).plusMonths(offset);+ if (first == null) { // Past either end of the table: stay on the last month that has data.+ offset -= Integer.signum(offset);+ first = new BikramSambat(today.year, today.month, 1).plusMonths(offset);+ }+ title.setText(NepaliDate.monthTitle(first));+ LocalDate start = first.toGregorian();+ int lead = NepaliDate.weekday(start), length = BikramSambat.daysInMonth(first.year, first.month);+ for (int i = 0; i < cells.length; i++) {+ TextView cell = cells[i];+ int d = i - lead + 1;+ boolean inMonth = d >= 1 && d <= length;+ cell.setVisibility(i >= 35 && lead + length <= 35 ? View.GONE : View.VISIBLE);+ if (!inMonth) { cell.setText(""); cell.setBackground(null); continue; }+ LocalDate date = start.plusDays(d - 1);+ BikramSambat bs = new BikramSambat(first.year, first.month, d);+ SpannableStringBuilder label = new SpannableStringBuilder(NepaliDate.digits(d));+ int split = label.length();+ label.append('\n').append(Integer.toString(date.getDayOfMonth()));+ label.setSpan(new RelativeSizeSpan(0.5f), split, label.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);+ cell.setText(label);+ cell.setTextColor(NepaliDate.weekend(date) || NepaliDate.nationalDay(bs) != 0 ? HOLIDAY : TEXT);+ if (bs.equals(today)) {+ GradientDrawable mark = new GradientDrawable();+ mark.setColor(TODAY);+ mark.setCornerRadius(dp(8));+ cell.setBackground(mark);+ } else {+ cell.setBackground(null);+ }+ }+ }+}diff --git a/addons/nepali-calendar/app/src/main/java/com/oneyuv/tv/nepalicalendar/NepaliDate.java b/addons/nepali-calendar/app/src/main/java/com/oneyuv/tv/nepalicalendar/NepaliDate.javanew file mode 100644index 000000000..095d726b0--- /dev/null+++ b/addons/nepali-calendar/app/src/main/java/com/oneyuv/tv/nepalicalendar/NepaliDate.java@@ -0,0 +1,76 @@+package com.oneyuv.tv.nepalicalendar;++import java.time.DayOfWeek;+import java.time.LocalDate;++/** Names, numerals and the fixed-date national days of the Bikram Sambat calendar. */+final class NepaliDate {+ static final String[] MONTHS = {"बैशाख", "जेठ", "असार", "साउन", "भदौ", "असोज",+ "कार्तिक", "मंसिर", "पौष", "माघ", "फाल्गुन", "चैत"};+ static final String[] MONTHS_LATIN = {"Baishakh", "Jestha", "Asar", "Shrawan", "Bhadra", "Asoj",+ "Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra"};+ /** Sunday first, as Nepali calendars print the week. */+ static final String[] WEEKDAYS = {"आइतबार", "सोमबार", "मंगलबार", "बुधबार", "बिहीबार", "शुक्रबार", "शनिबार"};+ static final String[] WEEKDAYS_SHORT = {"आइत", "सोम", "मंगल", "बुध", "बिही", "शुक्र", "शनि"};++ /**+ * National days kept on a fixed BS date, {month, day}, in the order of R.array.national_days.+ * Lunar festivals (Dashain, Tihar, Holi, Teej and others) move every year and are not here.+ */+ private static final int[][] NATIONAL_DAYS = {+ {1, 1}, // Nawa Barsha, New Year+ {1, 11}, // Loktantra Diwas+ {2, 15}, // Ganatantra Diwas, Republic Day+ {6, 3}, // Sambidhan Diwas, Constitution Day+ {9, 27}, // Prithvi Jayanti+ {10, 1}, // Maghe Sankranti+ {10, 16}, // Shahid Diwas, Martyrs' Day+ {11, 7}, // Prajatantra Diwas, Democracy Day+ };++ private NepaliDate() {}++ /** Western digits to Devanagari digits; everything else is kept. */+ static String digits(CharSequence text) {+ StringBuilder out = new StringBuilder(text.length());+ for (int i = 0; i < text.length(); i++) {+ char c = text.charAt(i);+ out.append(c >= '0' && c <= '9' ? (char) (c - '0' + '०') : c);+ }+ return out.toString();+ }++ static String digits(int number) { return digits(Integer.toString(number)); }++ /** Sunday = 0 to Saturday = 6. */+ static int weekday(LocalDate date) { return date.getDayOfWeek().getValue() % 7; }++ /** Saturday and Sunday, shown in red like the holidays. */+ static boolean weekend(LocalDate date) {+ DayOfWeek day = date.getDayOfWeek();+ return day == DayOfWeek.SATURDAY || day == DayOfWeek.SUNDAY;+ }++ /** "मंगलबार, कार्तिक १०, २०८३" */+ static String text(BikramSambat bs, LocalDate date) {+ return WEEKDAYS[weekday(date)] + ", " + MONTHS[bs.month - 1] + " " + digits(bs.day) + ", " + digits(bs.year);+ }++ /** "Kartik 10, 2083 BS" */+ static String latin(BikramSambat bs) { return MONTHS_LATIN[bs.month - 1] + " " + bs.day + ", " + bs.year + " BS"; }++ /** "कार्तिक २०८३ · Kartik 2083" */+ static String monthTitle(BikramSambat bs) {+ return MONTHS[bs.month - 1] + " " + digits(bs.year) + " · " + MONTHS_LATIN[bs.month - 1] + " " + bs.year;+ }++ /** 1-based index into R.array.national_days, or 0 when the day is none of them. */+ static int nationalDay(BikramSambat bs) {+ for (int i = 0; i < NATIONAL_DAYS.length; i++) {+ if (NATIONAL_DAYS[i][0] == bs.month && NATIONAL_DAYS[i][1] == bs.day) return i + 1;+ }+ return 0;+ }++ static int nationalDayCount() { return NATIONAL_DAYS.length; }+}diff --git a/addons/nepali-calendar/app/src/main/res/drawable/icon.xml b/addons/nepali-calendar/app/src/main/res/drawable/icon.xmlnew file mode 100644index 000000000..efefe42c9--- /dev/null+++ b/addons/nepali-calendar/app/src/main/res/drawable/icon.xml@@ -0,0 +1,7 @@+<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="320dp" android:height="180dp" android:viewportWidth="320" android:viewportHeight="180">+ <path android:fillColor="#1C1210" android:pathData="M0,0h320v180h-320z" />+ <path android:fillColor="#E8A05A" android:pathData="M109,44h102v96h-102z" />+ <path android:fillColor="#1C1210" android:pathData="M118,70h84v61h-84zM125,36h9v26h-9zM186,36h9v26h-9z" />+ <path android:fillColor="#FFFFFF" android:pathData="M132,83h13v13h-13zM154,83h13v13h-13zM132,106h13v13h-13zM154,106h13v13h-13zM176,106h13v13h-13z" />+ <path android:fillColor="#FF7B72" android:pathData="M176,83h13v13h-13z" />+</vector>diff --git a/addons/nepali-calendar/app/src/main/res/values-ne/strings.xml b/addons/nepali-calendar/app/src/main/res/values-ne/strings.xmlnew file mode 100644index 000000000..9c1ac6e23--- /dev/null+++ b/addons/nepali-calendar/app/src/main/res/values-ne/strings.xml@@ -0,0 +1,19 @@+<resources>+ <string name="app_name">नेपाली पात्रो</string>+ <string name="previous">अघिल्लो</string>+ <string name="today">आज</string>+ <string name="next">अर्को</string>+ <string name="screensaver">स्क्रिनसेभर</string>+ <string name="screensaver_missing">यो टिभीमा स्क्रिनसेभर सेटिङ उपलब्ध छैन।</string>+ <string name="out_of_range">विक्रम संवत् %1$d देखि %2$d सम्मका मिति मात्र उपलब्ध छन्। टिभीको मिति जाँच गर्नुहोस्।</string>+ <string-array name="national_days">+ <item>नयाँ वर्षको शुभकामना</item>+ <item>लोकतन्त्र दिवस</item>+ <item>गणतन्त्र दिवस</item>+ <item>संविधान दिवस</item>+ <item>पृथ्वी जयन्ती</item>+ <item>माघे संक्रान्ति</item>+ <item>शहीद दिवस</item>+ <item>प्रजातन्त्र दिवस</item>+ </string-array>+</resources>diff --git a/addons/nepali-calendar/app/src/main/res/values/strings.xml b/addons/nepali-calendar/app/src/main/res/values/strings.xmlnew file mode 100644index 000000000..d8353add3--- /dev/null+++ b/addons/nepali-calendar/app/src/main/res/values/strings.xml@@ -0,0 +1,19 @@+<resources>+ <string name="app_name">Nepali Calendar</string>+ <string name="previous">Previous</string>+ <string name="today">Today</string>+ <string name="next">Next</string>+ <string name="screensaver">Screensaver</string>+ <string name="screensaver_missing">Screensaver settings are unavailable on this TV.</string>+ <string name="out_of_range">Bikram Sambat dates are available for BS %1$d to %2$d. Check the TV\'s date.</string>+ <string-array name="national_days">+ <item>Happy New Year · नयाँ वर्षको शुभकामना</item>+ <item>Loktantra Diwas · लोकतन्त्र दिवस</item>+ <item>Republic Day · गणतन्त्र दिवस</item>+ <item>Constitution Day · संविधान दिवस</item>+ <item>Prithvi Jayanti · पृथ्वी जयन्ती</item>+ <item>Maghe Sankranti · माघे संक्रान्ति</item>+ <item>Martyrs\' Day · शहीद दिवस</item>+ <item>Democracy Day · प्रजातन्त्र दिवस</item>+ </string-array>+</resources>diff --git a/addons/nepali-calendar/app/src/main/res/xml/module_card.xml b/addons/nepali-calendar/app/src/main/res/xml/module_card.xmlnew file mode 100644index 000000000..d3d9cb312--- /dev/null+++ b/addons/nepali-calendar/app/src/main/res/xml/module_card.xml@@ -0,0 +1 @@+<card spec="1" label="Nepali Calendar" caption="Bikram Sambat dates" accent="#E8A05A" />diff --git a/addons/nepali-calendar/app/src/test/java/com/oneyuv/tv/nepalicalendar/BikramSambatTest.java b/addons/nepali-calendar/app/src/test/java/com/oneyuv/tv/nepalicalendar/BikramSambatTest.javanew file mode 100644index 000000000..3a31ca113--- /dev/null+++ b/addons/nepali-calendar/app/src/test/java/com/oneyuv/tv/nepalicalendar/BikramSambatTest.java@@ -0,0 +1,90 @@+package com.oneyuv.tv.nepalicalendar;++import static org.junit.Assert.*;++import java.time.LocalDate;+import org.junit.Test;++public class BikramSambatTest {+ /** Known Gregorian and BS pairs. */+ private static final String[][] PAIRS = {+ {"1913-04-13", "1970-01-01"},+ {"1952-01-20", "2008-10-06"},+ {"1956-03-29", "2012-12-16"},+ {"1958-05-12", "2015-01-30"},+ {"1959-07-14", "2016-03-30"},+ {"1964-03-09", "2020-11-26"},+ {"1971-06-20", "2028-03-06"},+ {"1976-04-02", "2032-12-20"},+ {"1977-07-02", "2034-03-18"},+ {"1985-10-29", "2042-07-13"},+ {"1986-04-28", "2043-01-15"},+ {"1993-04-04", "2049-12-22"},+ {"1999-08-03", "2056-04-18"},+ {"2015-01-01", "2071-09-17"},+ {"2032-08-26", "2089-05-10"},+ {"2033-12-31", "2090-09-16"},+ };++ @Test public void convertsKnownDatesBothWays() {+ for (String[] pair : PAIRS) {+ LocalDate gregorian = LocalDate.parse(pair[0]);+ BikramSambat bs = BikramSambat.of(gregorian);+ assertEquals(pair[0], pair[1], bs.toString());+ assertEquals(pair[1], gregorian, bs.toGregorian());+ }+ }++ @Test public void newYears() {+ assertEquals("2082-01-01", BikramSambat.of(LocalDate.of(2025, 4, 14)).toString());+ assertEquals("2083-01-01", BikramSambat.of(LocalDate.of(2026, 4, 14)).toString());+ assertEquals("2082-12-30", BikramSambat.of(LocalDate.of(2026, 4, 13)).toString());+ }++ @Test public void monthLengthsMatchTheTestData() {+ int[] y2081 = {31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31};+ int[] y2090 = {30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30};+ for (int m = 1; m <= 12; m++) {+ assertEquals(y2081[m - 1], BikramSambat.daysInMonth(2081, m));+ assertEquals(y2090[m - 1], BikramSambat.daysInMonth(2090, m));+ }+ }++ @Test public void everyYearIsASolarYear() {+ for (int y = BikramSambat.FIRST_YEAR; y <= BikramSambat.LAST_YEAR; y++) {+ int days = 0;+ for (int m = 1; m <= 12; m++) days += BikramSambat.daysInMonth(y, m);+ assertTrue(y + " has " + days, days == 365 || days == 366);+ }+ }++ @Test public void roundTripsEveryDayInTheTable() {+ LocalDate day = LocalDate.of(1913, 4, 13);+ BikramSambat previous = null;+ for (BikramSambat bs = BikramSambat.of(day); bs != null; day = day.plusDays(1), bs = BikramSambat.of(day)) {+ assertEquals(day, bs.toGregorian());+ if (previous != null && bs.day != 1) assertEquals(previous.day + 1, bs.day);+ previous = bs;+ }+ assertEquals(BikramSambat.LAST_YEAR, previous.year);+ assertEquals(12, previous.month);+ }++ @Test public void outsideTheTableIsNull() {+ assertNull(BikramSambat.of(LocalDate.of(1913, 4, 12)));+ assertNull(BikramSambat.of(LocalDate.of(2040, 1, 1)));+ assertFalse(BikramSambat.supported(BikramSambat.LAST_YEAR + 1));+ assertNull(new BikramSambat(BikramSambat.LAST_YEAR, 12, 1).plusMonths(1));+ assertNull(new BikramSambat(BikramSambat.FIRST_YEAR, 1, 1).plusMonths(-1));+ }++ @Test public void monthStepsCrossYears() {+ assertEquals("2083-01-01", new BikramSambat(2082, 12, 5).plusMonths(1).toString());+ assertEquals("2081-12-01", new BikramSambat(2082, 1, 1).plusMonths(-1).toString());+ assertEquals("2082-07-01", new BikramSambat(2082, 7, 9).plusMonths(0).toString());+ }++ @Test(expected = IllegalArgumentException.class) public void rejectsDaysPastTheMonth() {+ new BikramSambat(2081, 9, 30).toGregorian();+ }+}diff --git a/addons/nepali-calendar/app/src/test/java/com/oneyuv/tv/nepalicalendar/NepaliDateTest.java b/addons/nepali-calendar/app/src/test/java/com/oneyuv/tv/nepalicalendar/NepaliDateTest.javanew file mode 100644index 000000000..6b9173703--- /dev/null+++ b/addons/nepali-calendar/app/src/test/java/com/oneyuv/tv/nepalicalendar/NepaliDateTest.java@@ -0,0 +1,49 @@+package com.oneyuv.tv.nepalicalendar;++import static org.junit.Assert.*;++import java.time.LocalDate;+import org.junit.Test;++public class NepaliDateTest {+ @Test public void devanagariDigits() {+ assertEquals("२०८३", NepaliDate.digits(2083));+ assertEquals("१०:४५ AM", NepaliDate.digits("10:45 AM"));+ }++ @Test public void formatsToday() {+ LocalDate date = LocalDate.of(2026, 10, 27);+ BikramSambat bs = BikramSambat.of(date);+ assertEquals("मंगलबार, कार्तिक १०, २०८३", NepaliDate.text(bs, date));+ assertEquals("Kartik 10, 2083 BS", NepaliDate.latin(bs));+ assertEquals("कार्तिक २०८३ · Kartik 2083", NepaliDate.monthTitle(bs));+ }++ @Test public void weekStartsOnSundayAndTheWeekendIsRed() {+ assertEquals(0, NepaliDate.weekday(LocalDate.of(2026, 10, 25)));+ assertEquals(6, NepaliDate.weekday(LocalDate.of(2026, 10, 31)));+ assertTrue(NepaliDate.weekend(LocalDate.of(2026, 10, 31)));+ assertTrue(NepaliDate.weekend(LocalDate.of(2026, 11, 1)));+ assertFalse(NepaliDate.weekend(LocalDate.of(2026, 11, 2)));+ assertFalse(NepaliDate.weekend(LocalDate.of(2026, 10, 30)));+ }++ @Test public void nationalDays() {+ assertEquals(1, NepaliDate.nationalDay(new BikramSambat(2083, 1, 1)));+ assertEquals(4, NepaliDate.nationalDay(new BikramSambat(2083, 6, 3)));+ assertEquals(6, NepaliDate.nationalDay(new BikramSambat(2083, 10, 1)));+ assertEquals(0, NepaliDate.nationalDay(new BikramSambat(2083, 7, 10)));+ }++ @Test public void everyNationalDayFitsInItsMonth() {+ for (int y = BikramSambat.FIRST_YEAR; y <= BikramSambat.LAST_YEAR; y++) {+ int found = 0;+ for (int m = 1; m <= 12; m++) {+ for (int d = 1; d <= BikramSambat.daysInMonth(y, m); d++) {+ if (NepaliDate.nationalDay(new BikramSambat(y, m, d)) != 0) found++;+ }+ }+ assertEquals(Integer.toString(y), NepaliDate.nationalDayCount(), found);+ }+ }+}diff --git a/addons/nepali-calendar/build.gradle b/addons/nepali-calendar/build.gradlenew file mode 100644index 000000000..48978475f--- /dev/null+++ b/addons/nepali-calendar/build.gradle@@ -0,0 +1,3 @@+plugins {+ id 'com.android.application' version '8.5.2' apply false+}diff --git a/addons/nepali-calendar/gradle.properties b/addons/nepali-calendar/gradle.propertiesnew file mode 100644index 000000000..18825f968--- /dev/null+++ b/addons/nepali-calendar/gradle.properties@@ -0,0 +1,3 @@+org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8+android.useAndroidX=true+android.nonTransitiveRClass=truediff --git a/addons/nepali-calendar/gradle/wrapper/gradle-wrapper.jar b/addons/nepali-calendar/gradle/wrapper/gradle-wrapper.jarnew file mode 100644index 000000000..2c3521197Binary files /dev/null and b/addons/nepali-calendar/gradle/wrapper/gradle-wrapper.jar differdiff --git a/addons/nepali-calendar/gradle/wrapper/gradle-wrapper.properties b/addons/nepali-calendar/gradle/wrapper/gradle-wrapper.propertiesnew file mode 100644index 000000000..77f5d0ba6--- /dev/null+++ b/addons/nepali-calendar/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/nepali-calendar/gradlew b/addons/nepali-calendar/gradlewnew file mode 100755index 000000000..f5feea6d6--- /dev/null+++ b/addons/nepali-calendar/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/nepali-calendar/gradlew.bat b/addons/nepali-calendar/gradlew.batnew file mode 100644index 000000000..9d21a2183--- /dev/null+++ b/addons/nepali-calendar/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/nepali-calendar/screenshot.jpg b/addons/nepali-calendar/screenshot.jpgnew file mode 100644index 000000000..1646bc86fBinary files /dev/null and b/addons/nepali-calendar/screenshot.jpg differdiff --git a/addons/nepali-calendar/settings.gradle b/addons/nepali-calendar/settings.gradlenew file mode 100644index 000000000..758d486cc--- /dev/null+++ b/addons/nepali-calendar/settings.gradle@@ -0,0 +1,16 @@+pluginManagement {+ repositories {+ google()+ mavenCentral()+ gradlePluginPortal()+ }+}+dependencyResolutionManagement {+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)+ repositories {+ google()+ mavenCentral()+ }+}+rootProject.name = "nepali-calendar"+include ':app'