Skip to content

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

Launcher: vpn_pill, the VPN as its own pill next to the network pill

TheWombRaider3d255738d236
diff --git a/docs/switches.md b/docs/switches.md
index 44773bfef..d37b9e017 100644
--- a/docs/switches.md
+++ b/docs/switches.md
@@ -50,3 +50,4 @@ fits the rules; keys from before the rule sit on its wanted list until a screens
| `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"> |
| `power_on_home` | <img src="switches/power_on_home.jpg" width="320" alt="power_on_home on a TV"> |
+| `vpn_pill` | <img src="switches/vpn_pill.jpg" width="320" alt="vpn_pill on a TV"> |
diff --git a/docs/switches/vpn_pill.jpg b/docs/switches/vpn_pill.jpg
new file mode 100644
index 000000000..fc384dd43
Binary files /dev/null and b/docs/switches/vpn_pill.jpg differ
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..9099eeafa 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;
+ /** The VPN state as its own pill after the network pill, instead of a badge inside it (config.xml, vpn_pill). */
+ final boolean vpnPill;
/** 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, boolean vpnPill) {
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.vpnPill = vpnPill;
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);
+ boolean vpnPill = res.getBoolean(R.bool.vpn_pill);
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);
+ vpnPill = bool(json, "vpn_pill", vpnPill);
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, vpnPill);
}
/**
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..55d6d6a0f 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -195,6 +195,11 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
/** Optional time-of-day backdrop (config.xml, sky_intensity); 0 keeps it hidden. */
private SkyView sky;
private String vpnApp;
+ /** vpn_pill: the VPN shown as its own pill (btnVpn) instead of a badge in the network pill. Off with top_menu. */
+ private boolean vpnPill;
+ private TextView btnVpn;
+ /** The VpnBadge pill state btnVpn shows, so a refresh that changes nothing does not restyle it. */
+ private int vpnPillState = VpnBadge.PILL_HIDDEN;
private SpringAnimation springX, springY;
private float glassTargetX, glassTargetY;
// How far the grid has scrolled the glass. springY works without it, in grid content space, so a
@@ -495,6 +500,8 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
date.setPadding(0, (int) (4 * density), 0, 0);
}
vpnApp = cfg.vpnApp;
+ vpnPill = cfg.vpnPill && !cfg.topMenu;
+ btnVpn = findViewById(R.id.btnVpn);
moduleCards = cfg.moduleCards;
hiddenApps = new HashSet<>(cfg.hiddenApps);
@@ -690,6 +697,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
View btnSettings = findViewById(R.id.btnSettings);
btnInputs.setOnClickListener(v -> showInputs());
btnWifi.setOnClickListener(v -> openNetworkPill());
+ btnVpn.setOnClickListener(v -> openVpnPill());
btnWifi.setOnLongClickListener(v -> {
open(systemIntent(Settings.ACTION_WIFI_SETTINGS));
return true;
@@ -776,12 +784,13 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
};
btnInputs.setOnKeyListener(pillKeys);
btnWifi.setOnKeyListener(pillKeys);
+ btnVpn.setOnKeyListener(pillKeys);
btnSettings.setOnKeyListener(pillKeys);
btnReorder.setOnKeyListener(pillKeys);
btnLibraryTop.setOnKeyListener(pillKeys);
for (View button : topAppButtons) button.setOnKeyListener(pillKeys);
if (advancedEffects) {
- List<View> pills = new ArrayList<>(Arrays.asList(btnInputs, btnWifi, btnReorder, btnLibraryTop, btnSettings));
+ List<View> pills = new ArrayList<>(Arrays.asList(btnInputs, btnWifi, btnVpn, btnReorder, btnLibraryTop, btnSettings));
pills.addAll(topAppButtons);
for (View button : pills) {
button.setOnFocusChangeListener((view, focused) -> view.animate()
@@ -1570,6 +1579,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
if (openPopup != null) openPopup.dismiss();
libraryFocusPending = false;
libraryFromTopBar = false;
+ libraryFromVpnPill = false;
appLibrary = new AppLibraryDialog(this, animations, reducedMotion, appLibrarySelection, libraryOkOpens, adapter::containsPackage, () -> reloadApps(false), () -> {
appLibrary = null;
openPopup = null;
@@ -1578,6 +1588,13 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
btnLibraryTop.requestFocus();
return;
}
+ boolean fromVpnPill = libraryFromVpnPill;
+ libraryFromVpnPill = false;
+ // The VPN pill can hide while the library is open (its VPN dropped): then focus goes as from the grid.
+ if (fromVpnPill && btnVpn.getVisibility() == View.VISIBLE) {
+ btnVpn.requestFocus();
+ return;
+ }
libraryFocusPending = true;
grid.post(() -> {
if (libraryFocusPending && appLibrary == null && hasWindowFocus() && !isFinishing()) focusLibrary();
@@ -2320,7 +2337,8 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
button.setContentDescription(label);
Intent target = launch;
button.setOnClickListener(v -> open(new Intent(target)));
- bar.addView(button, bar.indexOfChild(btnWifi));
+ // After the network pill and the VPN pill; the Hebrew bar runs the other way, so before both there.
+ bar.addView(button, bar.indexOfChild(getResources().getBoolean(R.bool.rtl_menu_bar) ? btnVpn : btnWifi));
topAppButtons.add(button);
}
}
@@ -2605,7 +2623,8 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
}
// With a VPN app configured, a VPN that is down matters too: show a red "VPN off" capsule then.
boolean vpnDown = !vpn && online && !vpnApp.isEmpty();
- if (vpn || vpnDown) {
+ if (vpnPill) updateVpnPill(vpn);
+ if ((vpn || vpnDown) && !vpnPill) {
// Network name, then the green lock-and-VPN (or red "VPN off") capsule drawn in place of the word.
String badge = getString(vpn ? R.string.vpn : R.string.vpn_off);
VpnBadge span = new VpnBadge(vpn ? getDrawable(R.drawable.ic_lock) : null, density);
@@ -2672,6 +2691,8 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
private View btnLibraryTop;
/** The open library came from that button: closing it returns there instead of scrolling to the grid's end. */
private boolean libraryFromTopBar;
+ /** The open library came from the VPN pill (vpn_pill, no VPN app): closing it returns there while the pill still shows. */
+ private boolean libraryFromVpnPill;
/** Turns a labelled top pill into the round TopButtonIcon shape: no text, the icon centred by even padding. */
private void makeIconOnly(TextView pill) {
@@ -2735,13 +2756,60 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
return 0xFF000000 | (r << 16) | (g << 8) | b;
}
- /** The network pill opens the VPN app when one is configured and installed, otherwise Wi-Fi settings. */
+ /**
+ * The network pill opens the VPN app when one is configured and installed, otherwise Wi-Fi settings. With
+ * vpn_pill the VPN app has its own pill, so this one always opens Wi-Fi settings.
+ */
private void openNetworkPill() {
- Intent i = vpnApp.isEmpty() ? null : getPackageManager().getLeanbackLaunchIntentForPackage(vpnApp);
- if (i == null && !vpnApp.isEmpty()) i = getPackageManager().getLaunchIntentForPackage(vpnApp);
+ Intent i = vpnPill ? null : vpnAppIntent();
open(i != null ? i : systemIntent(Settings.ACTION_WIFI_SETTINGS));
}
+ /** vpn_app's launch intent, or null when none is set or it is not installed. */
+ private Intent vpnAppIntent() {
+ if (vpnApp.isEmpty()) return null;
+ Intent i = getPackageManager().getLeanbackLaunchIntentForPackage(vpnApp);
+ return i != null ? i : getPackageManager().getLaunchIntentForPackage(vpnApp);
+ }
+
+ /**
+ * vpn_pill: the VPN app, where it is switched on and off. Without one installed, the App library to pick from, or
+ * Android's VPN settings when the theme turned the library off.
+ */
+ private void openVpnPill() {
+ Intent i = vpnAppIntent();
+ if (i != null || !appLibraryEnabled) {
+ open(i != null ? i : systemIntent(Settings.ACTION_VPN_SETTINGS));
+ return;
+ }
+ onLibraryRequested();
+ libraryFromVpnPill = true;
+ }
+
+ /** vpn_pill: the whole pill solid green with a lock while a VPN is up, solid red "VPN off" while it is not. */
+ private void updateVpnPill(boolean vpn) {
+ int state = VpnBadge.pillState(vpn, vpnAppIntent() != null);
+ if (state == VpnBadge.PILL_HIDDEN) {
+ if (btnVpn.getVisibility() == View.GONE) return;
+ boolean focused = btnVpn.hasFocus();
+ btnVpn.setVisibility(View.GONE);
+ if (focused) (btnWifi.getVisibility() == View.VISIBLE ? btnWifi : firstTopButton()).requestFocus();
+ return;
+ }
+ if (state != vpnPillState) {
+ vpnPillState = state;
+ boolean up = state == VpnBadge.PILL_UP;
+ // Dark ink on green, white on red, focused or not: the white focus ring is drawn by the background.
+ ColorStateList ink = ColorStateList.valueOf(up ? VpnBadge.INK : VpnBadge.INK_OFF);
+ btnVpn.setText(up ? R.string.vpn : R.string.vpn_off);
+ btnVpn.setTextColor(ink);
+ btnVpn.setBackground(VpnBadge.pillBackground(up, density));
+ btnVpn.setCompoundDrawablesRelativeWithIntrinsicBounds(up ? R.drawable.ic_lock : 0, 0, 0, 0);
+ btnVpn.setCompoundDrawableTintList(ink);
+ }
+ btnVpn.setVisibility(View.VISIBLE);
+ }
+
/** Every settings entry shares the standard intent and the vendor fallback (SystemSettings). */
private Intent systemIntent(String standardAction) {
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/VpnBadge.java b/launcher/app/src/main/java/com/gathin/tvhome/VpnBadge.java
index 229e869f8..d9029bd0e 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/VpnBadge.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/VpnBadge.java
@@ -4,6 +4,8 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
+import android.graphics.drawable.GradientDrawable;
+import android.graphics.drawable.StateListDrawable;
import android.text.style.ReplacementSpan;
import androidx.annotation.NonNull;
@@ -16,9 +18,9 @@ import androidx.annotation.NonNull;
final class VpnBadge extends ReplacementSpan {
private static final int GREEN = 0xFF30D158;
- private static final int INK = 0xFF06290F;
+ static final int INK = 0xFF06290F;
private static final int RED = 0xFFFF453A;
- private static final int INK_OFF = 0xFFFFFFFF;
+ static final int INK_OFF = 0xFFFFFFFF;
private final Drawable lock;
private final float density;
@@ -34,6 +36,34 @@ final class VpnBadge extends ReplacementSpan {
this.density = density;
}
+ /** vpn_pill: what the VPN pill shows, from {@link #pillState}. */
+ static final int PILL_HIDDEN = 0, PILL_UP = 1, PILL_OFF = 2;
+
+ /**
+ * vpn_pill: green while any VPN is up, red "VPN off" while none is but the configured VPN app is installed (so a
+ * dropped VPN is noticed), hidden while neither is true: no pill on a TV without a VPN.
+ */
+ static int pillState(boolean vpnUp, boolean vpnAppInstalled) {
+ return vpnUp ? PILL_UP : vpnAppInstalled ? PILL_OFF : PILL_HIDDEN;
+ }
+
+ /** vpn_pill: the pill's background, solid green or red; focused it keeps its colour and gets a white ring. */
+ static StateListDrawable pillBackground(boolean up, float density) {
+ StateListDrawable bg = new StateListDrawable();
+ GradientDrawable focused = pillShape(up, density);
+ focused.setStroke(Math.round(3 * density), 0xFFFFFFFF);
+ bg.addState(new int[]{android.R.attr.state_focused}, focused);
+ bg.addState(new int[0], pillShape(up, density));
+ return bg;
+ }
+
+ private static GradientDrawable pillShape(boolean up, float density) {
+ GradientDrawable shape = new GradientDrawable();
+ shape.setColor(up ? GREEN : RED);
+ shape.setCornerRadius(21 * density);
+ return shape;
+ }
+
private float textSize(Paint p) {
return p.getTextSize() * 0.78f;
}
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 6b61aa402..a70f261df 100644
--- a/launcher/app/src/main/res/layout-iw/activity_main.xml
+++ b/launcher/app/src/main/res/layout-iw/activity_main.xml
@@ -359,6 +359,14 @@
android:drawableStart="@drawable/ic_swap_vert"
android:nextFocusDown="@+id/grid" />
+ <TextView
+ android:id="@+id/btnVpn"
+ style="@style/TopButton"
+ android:visibility="gone"
+ android:singleLine="true"
+ android:text="@string/vpn"
+ android:nextFocusDown="@+id/grid" />
+
<TextView
android:id="@+id/btnWifi"
style="@style/TopButton"
diff --git a/launcher/app/src/main/res/layout/activity_main.xml b/launcher/app/src/main/res/layout/activity_main.xml
index 398058032..9c0715959 100644
--- a/launcher/app/src/main/res/layout/activity_main.xml
+++ b/launcher/app/src/main/res/layout/activity_main.xml
@@ -339,6 +339,14 @@
android:drawableStart="@drawable/ic_wifi"
android:nextFocusDown="@+id/grid" />
+ <TextView
+ android:id="@+id/btnVpn"
+ style="@style/TopButton"
+ android:visibility="gone"
+ android:singleLine="true"
+ android:text="@string/vpn"
+ android:nextFocusDown="@+id/grid" />
+
<TextView
android:id="@+id/btnReorder"
style="@style/TopButtonIcon"
diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xml
index 580e748f8..05a5fd02d 100644
--- a/launcher/app/src/main/res/values/config.xml
+++ b/launcher/app/src/main/res/values/config.xml
@@ -226,6 +226,14 @@
VPN you use. Empty: the pill opens Wi-Fi settings. The green VPN badge shows for any VPN either way;
with an app set here, a red "VPN off" badge also shows while no VPN is up. -->
<string name="vpn_app" translatable="false"></string>
+ <!-- The VPN as its own pill after the network pill, instead of a badge inside it: solid green with a lock while a
+ VPN is up, solid red "VPN off" while none is and vpn_app is installed. Pressing it opens vpn_app (without it,
+ the App library, or VPN settings when app_library is off), and the network pill then always opens Wi-Fi
+ settings. Hidden while no VPN is up and vpn_app is empty or not installed, and with top_menu. It keeps its
+ label with icon_only_buttons, since the red state has no icon. A VPN app's kill switch keeps a VPN up while
+ the app says disconnected (it holds the tunnel to block traffic), so the pill stays green then. Can also be
+ set with "vpn_pill" in a theme. -->
+ <bool name="vpn_pill">false</bool>
<!-- The dock as its own row: a lighter band, no names under the tiles, parked low on the screen with the top
shelf above it. false makes the dock apps simply the first tiles of one plain grid (still in dock_apps
order, no empty slots), with names under every tile and the glow behind every focused tile. -->
diff --git a/launcher/app/src/test/java/com/gathin/tvhome/VpnPillTest.java b/launcher/app/src/test/java/com/gathin/tvhome/VpnPillTest.java
new file mode 100644
index 000000000..46729c9dc
--- /dev/null
+++ b/launcher/app/src/test/java/com/gathin/tvhome/VpnPillTest.java
@@ -0,0 +1,24 @@
+package com.gathin.tvhome;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class VpnPillTest {
+
+ @Test
+ public void greenWhileAnyVpnIsUp() {
+ assertEquals(VpnBadge.PILL_UP, VpnBadge.pillState(true, true));
+ assertEquals(VpnBadge.PILL_UP, VpnBadge.pillState(true, false));
+ }
+
+ @Test
+ public void redWhileTheInstalledVpnAppIsDown() {
+ assertEquals(VpnBadge.PILL_OFF, VpnBadge.pillState(false, true));
+ }
+
+ @Test
+ public void hiddenWithNoVpnAndNoInstalledVpnApp() {
+ assertEquals(VpnBadge.PILL_HIDDEN, VpnBadge.pillState(false, false));
+ }
+}
diff --git a/themes/README.md b/themes/README.md
index d080af63c..30d432a69 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -92,6 +92,7 @@ A new key needs one there in the same pull request.
| `open_on_start_choice` | bool | `true` adds an **Open on start** row to Launcher settings: pick an app on the TV, and the first Home after each boot opens it instead (once per boot; `boot_to_live_tv` wins when both are set; an app that is gone or disabled leaves Home on screen). Off by default |
| `focus_overshoot` | bool | The highlight and the focused tile swing past their target before settling (`true` by default); `false` glides straight there with smooth scrolling |
| `vpn_app` | string | App the network pill opens when a VPN is configured; also shows a red "VPN off" badge while no VPN is up |
+| `vpn_pill` | bool | The VPN as its own pill after the network pill instead of a badge inside it: solid green while a VPN is up, solid red "VPN off" while none is and `vpn_app` is installed, hidden otherwise. Pressing it opens `vpn_app` (without it, the App library, or VPN settings with `app_library` off); it keeps its label with `icon_only_buttons`; the network pill then opens Wi-Fi settings. Ignored with `top_menu`. A VPN app's kill switch holds a VPN up while the app says disconnected, so the pill stays green then (`false` by default) |
| `animations` | bool | Basic focus, glass, title and tile entrance motion; true by default |
| `advanced_effects` | bool | Optional lifted tile, icon zoom, smooth ambient colour and app opening effects; false by default |
| `show_home_settings_shortcut` | bool | Keep the optional Default-home tile visible when the TV has a home picker; false by default |