Skip to content

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

Launcher: count the network pill's icon by hand so the VPN badge fits on the first draw (#961)

Oleksiy Penkov8705fb3e535c
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 e6d030c6d..23f110675 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -2332,10 +2332,14 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
String badge = getString(vpn ? R.string.vpn : R.string.vpn_off);
VpnBadge span = new VpnBadge(vpn ? getDrawable(R.drawable.ic_lock) : null, density);
// The pill has a maximum width and ellipsizes at the end, which would cut the badge off after
- // a long network name, so shorten the name to whatever room the badge leaves. The total paddings
- // include the Wi-Fi icon.
+ // a long network name, so shorten the name to whatever room the badge leaves. The Wi-Fi icon and its
+ // gap are counted by hand: until the pill has a resolved layout direction (the first call, from
+ // onResume, runs before that) getTotalPaddingStart/End leave the compound drawables out, which
+ // left the name about 31dp too much room and the badge cut off.
TextPaint paint = btnWifi.getPaint();
- float room = btnWifi.getMaxWidth() - btnWifi.getTotalPaddingStart() - btnWifi.getTotalPaddingEnd()
+ Drawable[] compound = btnWifi.getCompoundDrawablesRelative();
+ int iconRoom = compound[0] != null ? compound[0].getIntrinsicWidth() + btnWifi.getCompoundDrawablePadding() : 0;
+ float room = btnWifi.getMaxWidth() - btnWifi.getPaddingStart() - btnWifi.getPaddingEnd() - iconRoom
- span.getSize(paint, badge, 0, badge.length(), null) - paint.measureText(" ") - 2 * density;
String name = TextUtils.ellipsize(text, paint, Math.max(0, room), TextUtils.TruncateAt.END).toString();
// A long badge ("VPN отключён") can leave room for a stub like "MT…", which says nothing and, after