Skip to content

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

Launcher: the VPN pill is an outline at rest, solid only while focused

Jackson Davis3b4c50a2e08a
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 179614434..4b521d9c8 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -2817,7 +2817,8 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
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. */
+ /** vpn_pill: the pill outlined in green with a lock while a VPN is up, outlined in red "VPN off" while it is not;
+ * solid with a white ring only while focused. */
private void updateVpnPill(boolean vpn) {
int state = VpnBadge.pillState(vpn, vpnAppIntent() != null);
if (state == VpnBadge.PILL_HIDDEN) {
@@ -2830,8 +2831,10 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
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);
+ // The state colour at rest (the pill is an outline then), the contrasting ink on the solid focused fill.
+ ColorStateList ink = new ColorStateList(
+ new int[][]{new int[]{android.R.attr.state_focused}, new int[0]},
+ new int[]{VpnBadge.pillInkColor(up, true), VpnBadge.pillInkColor(up, false)});
btnVpn.setText(up ? R.string.vpn : R.string.vpn_off);
btnVpn.setTextColor(ink);
btnVpn.setBackground(VpnBadge.pillBackground(up, density));
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 d9029bd0e..cb6b47d39 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/VpnBadge.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/VpnBadge.java
@@ -17,9 +17,9 @@ import androidx.annotation.NonNull;
*/
final class VpnBadge extends ReplacementSpan {
- private static final int GREEN = 0xFF30D158;
+ static final int GREEN = 0xFF30D158;
static final int INK = 0xFF06290F;
- private static final int RED = 0xFFFF453A;
+ static final int RED = 0xFFFF453A;
static final int INK_OFF = 0xFFFFFFFF;
private final Drawable lock;
@@ -47,16 +47,33 @@ final class VpnBadge extends ReplacementSpan {
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. */
+ /**
+ * vpn_pill: the pill's background. At rest it is an outline in the state colour and only the focused state is
+ * filled solid with a white ring — a solid pill at rest read as already selected, so OK pressed on a tile was
+ * taken for a press on the pill.
+ */
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));
+ GradientDrawable rest = new GradientDrawable();
+ rest.setColor(0x00000000);
+ rest.setCornerRadius(21 * density);
+ rest.setStroke(Math.round(2 * density), up ? GREEN : RED);
+ bg.addState(new int[0], rest);
return bg;
}
+ /**
+ * vpn_pill: the pill's text and icon colour. At rest the pill is an outline, so the ink is the state colour;
+ * on the solid focused fill it is the contrasting ink.
+ */
+ static int pillInkColor(boolean up, boolean focused) {
+ if (up) return focused ? INK : GREEN;
+ return focused ? INK_OFF : RED;
+ }
+
private static GradientDrawable pillShape(boolean up, float density) {
GradientDrawable shape = new GradientDrawable();
shape.setColor(up ? GREEN : RED);
diff --git a/launcher/app/src/test/java/com/gathin/tvhome/VpnPillTest.java b/launcher/app/src/test/java/com/gathin/tvhome/VpnPillTest.java
index 46729c9dc..8bce93153 100644
--- a/launcher/app/src/test/java/com/gathin/tvhome/VpnPillTest.java
+++ b/launcher/app/src/test/java/com/gathin/tvhome/VpnPillTest.java
@@ -21,4 +21,16 @@ public class VpnPillTest {
public void hiddenWithNoVpnAndNoInstalledVpnApp() {
assertEquals(VpnBadge.PILL_HIDDEN, VpnBadge.pillState(false, false));
}
+
+ /**
+ * At rest the pill is an outline, so its ink is the state colour; on the solid focused fill it is the
+ * contrasting ink. A solid pill at rest read as selected, which is the bug this pins.
+ */
+ @Test
+ public void inkContrastsTheSolidFillOnlyWhenFocused() {
+ assertEquals(VpnBadge.INK, VpnBadge.pillInkColor(true, true));
+ assertEquals(VpnBadge.GREEN, VpnBadge.pillInkColor(true, false));
+ assertEquals(VpnBadge.INK_OFF, VpnBadge.pillInkColor(false, true));
+ assertEquals(VpnBadge.RED, VpnBadge.pillInkColor(false, false));
+ }
}