Skip to content

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

launcher: optional Solar Hijri (Shamsi) date

Sam Dehghand02480cb3f3d
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
index 1983ab73e..b9d4188d5 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -67,6 +67,8 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
private boolean heroShown;
private TextView greeting;
private TextView btnWifi;
+ private TextView shamsiDate;
+ private boolean shamsi;
private SpringAnimation springX, springY;
private float glassTargetX, glassTargetY;
private boolean glassShown;
@@ -119,6 +121,14 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
ambientGlow.setGradientRadius((r - l) * 0.62f));
greeting = findViewById(R.id.greeting);
btnWifi = findViewById(R.id.btnWifi);
+ shamsiDate = findViewById(R.id.shamsiDate);
+ shamsi = getResources().getBoolean(R.bool.shamsi_date);
+ if (shamsi) {
+ shamsiDate.setVisibility(View.VISIBLE);
+ TextView date = findViewById(R.id.date);
+ date.setTextSize(11f);
+ date.setPadding(0, (int) (4 * density), 0, 0);
+ }
grid = findViewById(R.id.grid);
grid.setLayoutManager(new GridLayoutManager(this, COLUMNS));
@@ -386,6 +396,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
else if (hour < 22) res = R.string.good_evening;
else res = R.string.good_night;
greeting.setText(res);
+ if (shamsi) shamsiDate.setText(Shamsi.today());
}
/** Shows the Wi-Fi network name on the button when we can read it, otherwise the connection type. */
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Shamsi.java b/launcher/app/src/main/java/com/gathin/tvhome/Shamsi.java
new file mode 100644
index 000000000..3d38aab06
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/Shamsi.java
@@ -0,0 +1,45 @@
+package com.gathin.tvhome;
+
+import java.util.Calendar;
+
+/** Solar Hijri (Shamsi) date in Latin letters, without ICU: the arithmetic is small and stable. */
+final class Shamsi {
+
+ private static final String[] MONTHS = {
+ "Farvardin", "Ordibehesht", "Khordad", "Tir", "Mordad", "Shahrivar",
+ "Mehr", "Aban", "Azar", "Dey", "Bahman", "Esfand"};
+
+ private Shamsi() {
+ }
+
+ /** e.g. "27 Mehr 1405" */
+ static String today() {
+ Calendar c = Calendar.getInstance();
+ int[] j = toJalali(c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1, c.get(Calendar.DAY_OF_MONTH));
+ return j[2] + " " + MONTHS[j[1] - 1] + " " + j[0];
+ }
+
+ /** Gregorian to Jalali, the 33-year-cycle algorithm used by jalaali-js. Returns {year, month, day}. */
+ static int[] toJalali(int gy, int gm, int gd) {
+ int[] monthStart = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
+ int gy2 = gm > 2 ? gy + 1 : gy;
+ int days = 355666 + 365 * gy + (gy2 + 3) / 4 - (gy2 + 99) / 100 + (gy2 + 399) / 400 + gd + monthStart[gm - 1];
+ int jy = -1595 + 33 * (days / 12053);
+ days %= 12053;
+ jy += 4 * (days / 1461);
+ days %= 1461;
+ if (days > 365) {
+ jy += (days - 1) / 365;
+ days = (days - 1) % 365;
+ }
+ int jm, jd;
+ if (days < 186) {
+ jm = 1 + days / 31;
+ jd = 1 + days % 31;
+ } else {
+ jm = 7 + (days - 186) / 30;
+ jd = 1 + (days - 186) % 30;
+ }
+ return new int[]{jy, jm, jd};
+ }
+}
diff --git a/launcher/app/src/main/res/layout/activity_main.xml b/launcher/app/src/main/res/layout/activity_main.xml
index f6ac88fb3..c75a6a25f 100644
--- a/launcher/app/src/main/res/layout/activity_main.xml
+++ b/launcher/app/src/main/res/layout/activity_main.xml
@@ -102,20 +102,39 @@
android:layout_marginBottom="8dp"
android:background="#33FFFFFF" />
- <TextClock
- android:id="@+id/date"
+ <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="9dp"
- android:format12Hour="@string/date_format"
- android:format24Hour="@string/date_format"
- android:textColor="#A6FFFFFF"
- android:textSize="14sp"
- android:fontFamily="@font/outfit"
- android:fontVariationSettings="'wght' 400"
- android:letterSpacing="0.14"
- android:textAllCaps="true" />
+ android:orientation="vertical">
+
+ <!-- Shamsi date ("27 Mehr 1405"), shown when shamsi_date is on. -->
+ <TextView
+ android:id="@+id/shamsiDate"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textColor="#E6FFFFFF"
+ android:textSize="17sp"
+ android:fontFamily="@font/outfit"
+ android:fontVariationSettings="'wght' 400"
+ android:letterSpacing="0.02"
+ android:includeFontPadding="false"
+ android:visibility="gone" />
+
+ <TextClock
+ android:id="@+id/date"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:format12Hour="@string/date_format"
+ android:format24Hour="@string/date_format"
+ android:textColor="#A6FFFFFF"
+ android:textSize="14sp"
+ android:fontFamily="@font/outfit"
+ android:fontVariationSettings="'wght' 400"
+ android:letterSpacing="0.14"
+ android:textAllCaps="true" />
+ </LinearLayout>
</LinearLayout>
</LinearLayout>
diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xml
index c3dd51ca8..9ec77e3e3 100644
--- a/launcher/app/src/main/res/values/config.xml
+++ b/launcher/app/src/main/res/values/config.xml
@@ -22,6 +22,10 @@
<!-- The TV's Live TV / tuner app, offered at the end of the Inputs menu. Leave empty to omit. -->
<string name="live_tv_package" translatable="false">com.mediatek.wwtv.tvcenter</string>
+ <!-- Show the Solar Hijri (Shamsi) date used in Iran and Afghanistan, e.g. "27 Mehr 1405", above the
+ Gregorian date. -->
+ <bool name="shamsi_date">false</bool>
+
<!-- Tiles per row in the grid; the dock always has this many slots. -->
<integer name="columns">4</integer>
</resources>