Skip to content

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

Align Hebrew stats and clock without changing counters

lionlev21ecbcabc504dd
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 118c8a510..88193c870 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -391,6 +391,17 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
greeting = findViewById(R.id.greeting);
clockBlock = findViewById(R.id.leftBlock);
greetingColor = greeting.getCurrentTextColor();
+ if (getResources().getBoolean(R.bool.rtl_menu_bar)) {
+ // Center Hebrew greetings over the numeric time, independent of a visible AM/PM label.
+ findViewById(R.id.clock).addOnLayoutChangeListener((v, l, t, right, bottom, ol, ot, or, ob) -> {
+ ViewGroup.LayoutParams params = greeting.getLayoutParams();
+ if (params.width != right - l) {
+ params.width = right - l;
+ greeting.setLayoutParams(params);
+ }
+ greeting.setTranslationX(l);
+ });
+ }
btnWifi = findViewById(R.id.btnWifi);
shamsiDate = findViewById(R.id.shamsiDate);
stats = findViewById(R.id.stats);
@@ -1748,7 +1759,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
if (mem != null) appendStat(line, getString(R.string.stats_memory, mem[0], mem[1]));
String free = formatGb(getResources(), Environment.getDataDirectory().getFreeSpace());
if (!free.isEmpty()) appendStat(line, getString(R.string.stats_storage, free));
- return line.toString();
+ return StatsText.forLocale(line.toString(), getResources().getConfiguration().getLocales().get(0));
}
// -1: need another sample. -2: this source cannot be read (Android 9 hides /proc/stat from apps).
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/StatsText.java b/launcher/app/src/main/java/com/gathin/tvhome/StatsText.java
new file mode 100644
index 000000000..0ee41fe50
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/StatsText.java
@@ -0,0 +1,20 @@
+package com.gathin.tvhome;
+
+import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/** Isolate complete measurements, not individual digits, in the Hebrew stats paragraph. */
+final class StatsText {
+ private static final Pattern MEASUREMENT = Pattern.compile("[0-9]+(?:[.,][0-9]+)?(?:\\s*/\\s*[0-9]+(?:[.,][0-9]+)?)?(?:\\s+(?:MB|GB)|%)");
+ static String forLocale(String text, Locale locale) {
+ String language = locale.getLanguage();
+ if (!language.equals("he") && !language.equals("iw")) return text;
+ Matcher matcher = MEASUREMENT.matcher(text);
+ StringBuffer isolated = new StringBuffer();
+ while (matcher.find()) matcher.appendReplacement(isolated, Matcher.quoteReplacement("\u200E\u202A" + matcher.group() + "\u202C\u200E"));
+ matcher.appendTail(isolated);
+ // Embeddings plus directional marks also work on TV text renderers that mishandle isolates.
+ return "\u200F" + isolated.toString().replace(" · ", "\u200F · \u200F");
+ }
+}
diff --git a/launcher/app/src/main/res/layout-iw/activity_main.xml b/launcher/app/src/main/res/layout-iw/activity_main.xml
index b3be2226b..2848882e7 100644
--- a/launcher/app/src/main/res/layout-iw/activity_main.xml
+++ b/launcher/app/src/main/res/layout-iw/activity_main.xml
@@ -248,23 +248,13 @@
android:layout_height="wrap_content"
android:orientation="horizontal"
android:baselineAligned="true">
- <TextClock
- android:id="@+id/clock"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:format12Hour="h:mm"
- android:format24Hour="HH:mm"
- android:textColor="#FFFFFFFF"
- android:textSize="52sp"
- android:fontFamily="@font/outfit_light"
- android:letterSpacing="-0.04"
- android:includeFontPadding="false" />
-
<TextClock
android:id="@+id/ampm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginStart="6dp"
+ android:layout_marginEnd="6dp"
+ android:singleLine="true"
+ android:textDirection="rtl"
android:layout_gravity="bottom"
android:layout_marginBottom="8dp"
android:format12Hour="a"
@@ -272,8 +262,22 @@
android:textColor="#B3FFFFFF"
android:textSize="15sp"
android:fontFamily="@font/outfit_medium"
- android:letterSpacing="0.08"
+ android:letterSpacing="0"
+ android:ellipsize="none"
android:textAllCaps="true" />
+
+ <TextClock
+ android:id="@+id/clock"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginEnd="6dp"
+ android:format12Hour="h:mm"
+ android:format24Hour="HH:mm"
+ android:textColor="#FFFFFFFF"
+ android:textSize="52sp"
+ android:fontFamily="@font/outfit_light"
+ android:letterSpacing="-0.04"
+ android:includeFontPadding="false" />
</LinearLayout>
</LinearLayout>
@@ -286,7 +290,10 @@
android:layout_width="wrap_content"
android:layout_below="@id/leftBlock"
android:layout_alignStart="@id/leftBlock"
+ android:layout_alignEnd="@id/leftBlock"
android:gravity="right"
+ android:textDirection="rtl"
+ android:layout_marginEnd="6dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:singleLine="true"
diff --git a/launcher/app/src/test/java/com/gathin/tvhome/StatsTextTest.java b/launcher/app/src/test/java/com/gathin/tvhome/StatsTextTest.java
new file mode 100644
index 000000000..7a0cdc3d6
--- /dev/null
+++ b/launcher/app/src/test/java/com/gathin/tvhome/StatsTextTest.java
@@ -0,0 +1,33 @@
+package com.gathin.tvhome;
+import org.junit.Test;
+import java.util.Locale;
+import static org.junit.Assert.*;
+public class StatsTextTest {
+ @Test public void preservesEnglishExactly() {
+ String text = "CPU 8% · Memory 1202 MB free · Storage 0.8 GB free";
+ assertEquals(text, StatsText.forLocale(text, Locale.ENGLISH));
+ }
+ @Test public void isolatesUnitsAndPercentAsWholeMeasurements() {
+ String text = StatsText.forLocale("CPU 8% · זיכרון 1202 MB פנוי · אחסון 0.8 GB פנוי", new Locale("he"));
+ assertTrue(text.contains("\u200E\u202A8%\u202C\u200E"));
+ assertTrue(text.contains("\u200E\u202A1202 MB\u202C\u200E"));
+ assertTrue(text.contains("\u200E\u202A0.8 GB\u202C\u200E"));
+ assertEquals(3, text.chars().filter(c -> c == '\u202A').count());
+ }
+ @Test public void supportsAbsentCpuAndLargeValues() {
+ String text = StatsText.forLocale("זיכרון 123456 MB פנוי · אחסון 100 GB פנוי", new Locale("iw"));
+ assertFalse(text.contains("CPU"));
+ assertTrue(text.contains("\u200E\u202A123456 MB\u202C\u200E"));
+ assertTrue(text.contains("\u200E\u202A100 GB\u202C\u200E"));
+ }
+ @Test public void keepsCapacityRatiosInOneDirectionRun() {
+ String text = StatsText.forLocale("זיכרון 850/2850 MB פנוי · אחסון 0.8/4.4 GB פנוי", new Locale("he"));
+ assertTrue(text.contains("\u200E\u202A850/2850 MB\u202C\u200E"));
+ assertTrue(text.contains("\u200E\u202A0.8/4.4 GB\u202C\u200E"));
+ }
+ @Test public void preservesUpstreamSpacedUsedTotalAsOneRun() {
+ String text = StatsText.forLocale("זיכרון 1853 / 2915 MB", new Locale("he"));
+ assertTrue(text.contains("\u200E\u202A1853 / 2915 MB\u202C\u200E"));
+ assertEquals(1, text.chars().filter(c -> c == '\u202A').count());
+ }
+}