Skip to content

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

Launcher: locale, the language the launcher shows itself in instead of the TV's (off by default)

VGS24aa8de65538
diff --git a/docs/switches.md b/docs/switches.md
index 44773bfef..38ed888f2 100644
--- a/docs/switches.md
+++ b/docs/switches.md
@@ -49,4 +49,5 @@ fits the rules; keys from before the rule sit on its wanted list until a screens
| `show_library_pill` | <img src="switches/show_library_pill.jpg" width="320" alt="show_library_pill on a TV"> |
| `library_ok_opens` | <img src="switches/library_ok_opens.jpg" width="320" alt="library_ok_opens on a TV"> |
| `date_below_clock` | <img src="switches/date_below_clock.jpg" width="320" alt="date_below_clock on a TV"> |
+| `locale` | <img src="switches/locale.jpg" width="320" alt="locale set to en on a TV whose system language is Vietnamese"> |
| `power_on_home` | <img src="switches/power_on_home.jpg" width="320" alt="power_on_home on a TV"> |
diff --git a/docs/switches/locale.jpg b/docs/switches/locale.jpg
new file mode 100644
index 000000000..6ade6cd7f
Binary files /dev/null and b/docs/switches/locale.jpg differ
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/ClockActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/ClockActivity.java
index 8454a4949..905931f87 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/ClockActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/ClockActivity.java
@@ -12,6 +12,11 @@ import android.view.View;
* this one only ever starts from Home. Any key returns to Home.
*/
public class ClockActivity extends Activity {
+ @Override
+ protected void attachBaseContext(android.content.Context base) {
+ super.attachBaseContext(LauncherLocale.wrap(base)); // locale
+ }
+
private ClockScene scene;
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Config.java b/launcher/app/src/main/java/com/gathin/tvhome/Config.java
index be67171ae..c36535727 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java
@@ -90,6 +90,8 @@ final class Config {
final int lunarUtcOffset;
/** The date on its own line under the clock instead of beside it (config.xml, date_below_clock). */
final boolean dateBelowClock;
+ /** Language tag the launcher shows itself in instead of the TV's, or "" for the TV's (config.xml, locale). */
+ final String locale;
/** Name after the greeting ("Good morning, Mr. Trịnh"); empty for the greeting alone. */
final String greetingName;
final boolean moduleCards;
@@ -260,7 +262,7 @@ final class Config {
List<RaceWeekend.Race> raceCalendar, boolean cinematicHome, boolean ambientGlow, boolean appGlow, boolean fadeRows, int homeIdleClockMinutes,
boolean keyFilter, boolean dockGlass, String glowStyle, boolean wallpaperCaptions,
boolean handleViewInputs, boolean tileMenu, boolean dockEvenPadding, boolean dockBand, boolean cinematicDots, boolean cinematicWhiteFocus, boolean wifiStatusColor, int cinematicScrim, int cinematicArt,
- Map<String, Set<String>> wallpaperMoods, boolean gamepadPassthrough, boolean consumeVolumeKeys, boolean powerOnHome, boolean wifiStatusWarnings, List<String> topBarApps, boolean showGreeting, boolean headerWhite, boolean clockWallpaper, int clockWallpaperDim, boolean clockGlow, String glassStyle, boolean singleRow, boolean dockBandAll, boolean lunarDate, int lunarUtcOffset, boolean dateBelowClock) {
+ Map<String, Set<String>> wallpaperMoods, boolean gamepadPassthrough, boolean consumeVolumeKeys, boolean powerOnHome, boolean wifiStatusWarnings, List<String> topBarApps, boolean showGreeting, boolean headerWhite, boolean clockWallpaper, int clockWallpaperDim, boolean clockGlow, String glassStyle, boolean singleRow, boolean dockBandAll, boolean lunarDate, int lunarUtcOffset, boolean dateBelowClock, String locale) {
this.handleViewInputs = handleViewInputs;
this.tileMenu = tileMenu;
this.inputKeycodes = inputKeycodes;
@@ -291,6 +293,7 @@ final class Config {
this.lunarDate = lunarDate;
this.lunarUtcOffset = lunarUtcOffset;
this.dateBelowClock = dateBelowClock;
+ this.locale = locale;
this.greetingName = greetingName;
this.moduleCards = moduleCards;
this.reducedMotion = reducedMotion;
@@ -466,6 +469,7 @@ final class Config {
String glowStyle = res.getString(R.string.glow_style);
boolean wifiStatusWarnings = res.getBoolean(R.bool.wifi_status_warnings);
boolean dateBelowClock = res.getBoolean(R.bool.date_below_clock);
+ String locale = res.getString(R.string.locale).trim();
List<String> topBarApps = new ArrayList<>(Arrays.asList(res.getStringArray(R.array.top_bar_apps)));
boolean showGreeting = res.getBoolean(R.bool.show_greeting);
boolean headerWhite = res.getBoolean(R.bool.header_white);
@@ -565,6 +569,7 @@ final class Config {
if (moods != null) wallpaperMoods = moods(moods);
wifiStatusWarnings = bool(json, "wifi_status_warnings", wifiStatusWarnings);
dateBelowClock = bool(json, "date_below_clock", dateBelowClock);
+ locale = string(json, "locale", locale).trim();
topBarApps = stringList(json, "top_bar_apps", topBarApps);
showGreeting = bool(json, "show_greeting", showGreeting);
headerWhite = bool(json, "header_white", headerWhite);
@@ -635,7 +640,7 @@ final class Config {
dockBand, cinematicDots, cinematicWhiteFocus, wifiStatusColor, cinematicScrim, cinematicArt, wallpaperMoods, gamepadPassthrough,
consumeVolumeKeys, powerOnHome, wifiStatusWarnings, topBarApps, showGreeting, headerWhite, clockWallpaper,
Math.max(0, Math.min(90, clockWallpaperDim)), clockGlow, glassStyle, singleRow && dockRow, dockBandAll, lunar, lunarOffset,
- dateBelowClock);
+ dateBelowClock, locale);
}
/**
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/HomeSettingsActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/HomeSettingsActivity.java
index ef0b22b3c..53b2ffe5e 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/HomeSettingsActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/HomeSettingsActivity.java
@@ -9,6 +9,11 @@ import android.widget.Toast;
/** Lets the user change HOME through the system UI, without shell or privileged permissions. */
public class HomeSettingsActivity extends Activity {
+ @Override
+ protected void attachBaseContext(android.content.Context base) {
+ super.attachBaseContext(LauncherLocale.wrap(base)); // locale
+ }
+
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/InputsRequestActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/InputsRequestActivity.java
index e0cc83fc2..42d4182f6 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/InputsRequestActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/InputsRequestActivity.java
@@ -11,6 +11,11 @@ import android.os.Bundle;
* so a TV with its own input picker is never offered a chooser. No UI of its own (Theme.NoDisplay).
*/
public class InputsRequestActivity extends Activity {
+ @Override
+ protected void attachBaseContext(android.content.Context base) {
+ super.attachBaseContext(LauncherLocale.wrap(base)); // locale
+ }
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/LauncherLocale.java b/launcher/app/src/main/java/com/gathin/tvhome/LauncherLocale.java
new file mode 100644
index 000000000..4bfeb0d1c
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/LauncherLocale.java
@@ -0,0 +1,35 @@
+package com.gathin.tvhome;
+
+import android.content.Context;
+import android.content.res.Configuration;
+import java.util.Locale;
+import java.util.regex.Pattern;
+
+/**
+ * locale: the language the launcher shows itself in, instead of the TV's. A China-market Xiaomi offers Chinese and
+ * English only, so a Vietnamese owner saw the launcher in Chinese although it is translated into Vietnamese.
+ * Each activity wraps its base context here; an empty or malformed tag leaves the TV's language.
+ */
+final class LauncherLocale {
+ private static final Pattern TAG = Pattern.compile("[a-z]{2,3}(-[A-Za-z0-9]{2,8})?");
+
+ private LauncherLocale() {
+ }
+
+ /** The Locale for a config tag such as "vi" or "pt-BR", or null for "" or anything that is not a plain tag. */
+ static Locale parse(String tag) {
+ if (tag == null || !TAG.matcher(tag.trim()).matches()) return null;
+ return Locale.forLanguageTag(tag.trim());
+ }
+
+ /** base with the configured language, or base itself when locale is off. */
+ static Context wrap(Context base) {
+ Locale locale = parse(Config.load(base).locale);
+ if (locale == null) return base;
+ // Formatters that take no Context (the clock's date, the lunar line) follow the default locale.
+ Locale.setDefault(locale);
+ Configuration c = new Configuration(base.getResources().getConfiguration());
+ c.setLocale(locale);
+ return base.createConfigurationContext(c);
+ }
+}
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/LauncherSettingsActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/LauncherSettingsActivity.java
index 93dc758b1..914f8866d 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/LauncherSettingsActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/LauncherSettingsActivity.java
@@ -21,6 +21,11 @@ import java.util.List;
/** Remote-friendly settings owned by the launcher; system settings stay one row away. */
public final class LauncherSettingsActivity extends Activity {
+ @Override
+ protected void attachBaseContext(android.content.Context base) {
+ super.attachBaseContext(LauncherLocale.wrap(base)); // locale
+ }
+
static final String EXTRA_REORDER = "com.gathin.tvhome.extra.REORDER_FROM_SETTINGS";
private SharedPreferences choices;
private final TextView[] columnChoices = new TextView[4];
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 880d15fcc..207ac8a5e 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -95,6 +95,11 @@ import java.util.Set;
* tvOS style home: black, a pinned dock row, an app grid, and one glass highlight that springs between tiles.
*/
public class MainActivity extends Activity implements AppAdapter.TileListener {
+ @Override
+ protected void attachBaseContext(android.content.Context base) {
+ super.attachBaseContext(LauncherLocale.wrap(base)); // locale
+ }
+
private static final int LAUNCHER_SETTINGS_REQUEST = 42;
/** Sent by QuickSettingsActivity: open Launcher settings from here so Home rebuilds when they close. */
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/QuickSettingsActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/QuickSettingsActivity.java
index 8f5a1aa8b..a13e08450 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/QuickSettingsActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/QuickSettingsActivity.java
@@ -18,6 +18,11 @@ import android.widget.Toast;
* closes the panel.
*/
public final class QuickSettingsActivity extends Activity {
+ @Override
+ protected void attachBaseContext(android.content.Context base) {
+ super.attachBaseContext(LauncherLocale.wrap(base)); // locale
+ }
+
@Override
protected void onCreate(Bundle state) {
diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xml
index 580e748f8..578c6a736 100644
--- a/launcher/app/src/main/res/values/config.xml
+++ b/launcher/app/src/main/res/values/config.xml
@@ -214,6 +214,10 @@
<!-- The date (with the Shamsi and lunar lines) on its own line under the clock instead of beside it, for a top bar
whose pills leave the date too little room. Can also be set with "date_below_clock" in a theme. -->
<bool name="date_below_clock">false</bool>
+ <!-- The language the launcher shows itself in, as a language tag ("vi", "pt-BR"), instead of the TV's. For firmware
+ that has no menu entry for the owner's language although the launcher is translated into it (a China-market
+ Xiaomi offers Chinese and English only). Empty, the default, follows the TV. A theme can set it ("locale"). -->
+ <string name="locale" translatable="false"></string>
<!-- A name after the greeting: "Mr. Trịnh" shows GOOD MORNING, MR. TRỊNH. Empty: the greeting alone. -->
<string name="greeting_name" translatable="false"></string>
diff --git a/launcher/app/src/test/java/com/gathin/tvhome/LauncherLocaleTest.java b/launcher/app/src/test/java/com/gathin/tvhome/LauncherLocaleTest.java
new file mode 100644
index 000000000..b924582d4
--- /dev/null
+++ b/launcher/app/src/test/java/com/gathin/tvhome/LauncherLocaleTest.java
@@ -0,0 +1,24 @@
+package com.gathin.tvhome;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+public class LauncherLocaleTest {
+ @Test
+ public void plainTagsBecomeLocales() {
+ assertEquals("vi", LauncherLocale.parse("vi").getLanguage());
+ assertEquals("BR", LauncherLocale.parse("pt-BR").getCountry());
+ assertEquals("fil", LauncherLocale.parse(" fil ").getLanguage());
+ }
+
+ @Test
+ public void emptyOrMalformedTagsFollowTheTv() {
+ assertNull(LauncherLocale.parse(""));
+ assertNull(LauncherLocale.parse(null));
+ assertNull(LauncherLocale.parse("Vietnamese"));
+ assertNull(LauncherLocale.parse("vi_VN"));
+ assertNull(LauncherLocale.parse("../vi"));
+ }
+}
diff --git a/themes/README.md b/themes/README.md
index d080af63c..0a184c0e0 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -83,6 +83,7 @@ A new key needs one there in the same pull request.
| `lunar_date` | bool | Show the lunisolar date under the Gregorian one, e.g. `LUNAR 13/9 · YEAR OF THE HORSE`, or `13/9 ÂM LỊCH · BÍNH NGỌ` in Vietnamese; a leap month is marked. Off by default |
| `lunar_utc_offset` | 0 to 14 | Hours east of UTC the lunar calendar is computed for: `7` is the Vietnamese calendar, `8` the Chinese one; they differ by a day now and then (and by a month in 1985). Unset: 7 when the TV is in Vietnamese, 8 otherwise |
| `date_below_clock` | bool | The date (with the Shamsi and lunar lines) on its own line under the clock instead of beside it, for a top bar whose pills leave the date too little room (`false` by default) |
+| `locale` | string | The language the launcher shows itself in, as a language tag (`"vi"`, `"pt-BR"`), instead of the TV's: for firmware with no menu entry for a language the launcher speaks (a China-market Xiaomi offers Chinese and English only). Empty by default, which follows the TV |
| `greeting_name` | string | A name after the greeting, e.g. `"Mr. Trịnh"` for GOOD MORNING, MR. TRỊNH; empty for the greeting alone |
| `show_greeting` | bool | The greeting above the clock (`true` by default); `false` hides it |
| `header_white` | bool | The date and the line between the clock and the date in the clock's full white instead of dimmed (`false` by default) |