Skip to content

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

launcher: input_action for HDMI players that ignore VIEW, and keep the VPN badge visible

Florian Zaruba5d58f9c74e1d
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 54a5b4562..f40321079 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java
@@ -37,6 +37,7 @@ final class Config {
final String liveTvAction;
final String sourcePanelService;
final String sourcePanelAction;
+ final String inputAction;
final int columns;
final int rowsBelowDock;
final boolean shamsiDate;
@@ -50,7 +51,8 @@ final class Config {
final boolean overlayApplied;
private Config(List<String> dockApps, List<String> hiddenApps, String liveTvPackage, String liveTvAction,
- String sourcePanelService, String sourcePanelAction, int columns, int rowsBelowDock,
+ String sourcePanelService, String sourcePanelAction, String inputAction,
+ int columns, int rowsBelowDock,
boolean shamsiDate, String vpnApp, boolean showHomeSettingsShortcut, int backgroundColor,
File wallpaper, boolean overlayApplied) {
this.dockApps = Collections.unmodifiableList(dockApps);
@@ -59,6 +61,7 @@ final class Config {
this.liveTvAction = liveTvAction;
this.sourcePanelService = sourcePanelService;
this.sourcePanelAction = sourcePanelAction;
+ this.inputAction = inputAction;
this.columns = columns;
this.rowsBelowDock = rowsBelowDock;
this.shamsiDate = shamsiDate;
@@ -82,6 +85,7 @@ final class Config {
String liveTvAction = res.getString(R.string.live_tv_action).trim();
String panelService = res.getString(R.string.source_panel_service).trim();
String panelAction = res.getString(R.string.source_panel_action).trim();
+ String inputAction = res.getString(R.string.input_action).trim();
int columns = res.getInteger(R.integer.columns);
int rowsBelow = res.getInteger(R.integer.rows_below_dock);
boolean shamsi = res.getBoolean(R.bool.shamsi_date);
@@ -101,6 +105,7 @@ final class Config {
liveTvAction = string(json, "live_tv_action", liveTvAction);
panelService = string(json, "source_panel_service", panelService);
panelAction = string(json, "source_panel_action", panelAction);
+ inputAction = string(json, "input_action", inputAction);
columns = integer(json, "columns", columns, 1, 8);
rowsBelow = integer(json, "rows_below_dock", rowsBelow, 0, 3);
shamsi = bool(json, "shamsi_date", shamsi);
@@ -113,7 +118,7 @@ final class Config {
// A theme can also switch the wallpaper off while the file is still there.
if (json != null && json.has("wallpaper") && !bool(json, "wallpaper", true)) wallpaper = null;
- return new Config(dock, hidden, liveTv, liveTvAction, panelService, panelAction,
+ return new Config(dock, hidden, liveTv, liveTvAction, panelService, panelAction, inputAction,
Math.max(1, columns), Math.max(0, rowsBelow), shamsi, vpn, homeSettings, background,
wallpaper, applied);
}
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 b03823724..448e52157 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -17,6 +17,7 @@ import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
+import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
@@ -25,6 +26,8 @@ import android.os.Looper;
import android.provider.Settings;
import android.text.SpannableString;
import android.text.Spanned;
+import android.text.TextPaint;
+import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
@@ -63,6 +66,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
private static final long MINUTE_MS = 60_000L;
private String liveTvPkg;
private String liveTvAction;
+ private String inputAction;
private String sourcePanelService;
private String sourcePanelAction;
@@ -150,6 +154,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
COLUMNS = cfg.columns;
liveTvPkg = cfg.liveTvPackage;
liveTvAction = cfg.liveTvAction;
+ inputAction = cfg.inputAction;
sourcePanelService = cfg.sourcePanelService;
sourcePanelAction = cfg.sourcePanelAction;
@@ -557,9 +562,16 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
if (vpn) {
// Network name, then a green lock-and-VPN capsule drawn in place of the word "VPN".
String badge = getString(R.string.vpn);
+ VpnBadge span = new VpnBadge(getDrawable(R.drawable.ic_lock), 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.
+ TextPaint paint = btnWifi.getPaint();
+ float room = btnWifi.getMaxWidth() - btnWifi.getTotalPaddingStart() - btnWifi.getTotalPaddingEnd()
+ - span.getSize(paint, badge, 0, badge.length(), null) - paint.measureText(" ") - 2 * density;
+ text = TextUtils.ellipsize(text, paint, Math.max(0, room), TextUtils.TruncateAt.END).toString();
SpannableString label = new SpannableString(text + " " + badge);
- label.setSpan(new VpnBadge(getDrawable(R.drawable.ic_lock), density),
- text.length() + 1, label.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ label.setSpan(span, text.length() + 1, label.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
btnWifi.setText(label);
} else {
btnWifi.setText(text);
@@ -618,6 +630,25 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
}
}
+ /** Switches to a passthrough input (HDMI, AV). The standard way is ACTION_VIEW on its channel URI,
+ * which the Live TV app handles; where nothing takes that, the configured `input_action` is sent
+ * with the same URI instead (XGIMI's HDMI player only answers com.xgimi.action.hdmiPlayer). */
+ private void openInput(String inputId) {
+ Uri uri = TvContract.buildChannelUriForPassthroughInput(inputId);
+ Intent view = new Intent(Intent.ACTION_VIEW).setDataAndType(uri, "vnd.android.cursor.item/channel")
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ try {
+ startActivity(view);
+ return;
+ } catch (ActivityNotFoundException e) {
+ if (inputAction.isEmpty()) {
+ Toast.makeText(this, R.string.not_available, Toast.LENGTH_SHORT).show();
+ return;
+ }
+ }
+ open(new Intent(inputAction).setDataAndType(uri, "vnd.android.cursor.item/channel"));
+ }
+
/** Dropdown menu under the Inputs pill: HDMI ports (with connection state), AV and Live TV. */
private void showInputs() {
View anchor = findViewById(R.id.btnInputs);
@@ -674,8 +705,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
if (!hdmi && rows.getChildCount() > 0 && !sawNonHdmi) addSeparator(rows);
if (!hdmi) sawNonHdmi = true;
addInputRow(rows, popup, hdmi ? R.drawable.ic_input : R.drawable.ic_av, label, state,
- () -> open(new Intent(Intent.ACTION_VIEW).setDataAndType(
- TvContract.buildChannelUriForPassthroughInput(id), "vnd.android.cursor.item/channel")));
+ () -> openInput(id));
}
}
// Nothing to list where there is no TvInputManager: the TV's own source panel switches inputs.
diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xml
index 9f0c57a75..32937b8b5 100644
--- a/launcher/app/src/main/res/values/config.xml
+++ b/launcher/app/src/main/res/values/config.xml
@@ -35,6 +35,11 @@
<string name="source_panel_service" translatable="false"></string>
<string name="source_panel_action" translatable="false"></string>
+ <!-- Inputs menu: HDMI and AV rows normally open with ACTION_VIEW on the input's channel URI, which the
+ Live TV app handles. Where nothing answers that, this action is sent with the same URI instead
+ (XGIMI projectors: com.xgimi.action.hdmiPlayer). Leave empty to omit. -->
+ <string name="input_action" translatable="false"></string>
+
<!-- Show the Solar Hijri (Shamsi) date used in Iran and Afghanistan, e.g. "27 Mehr 1405", above the
Gregorian date. -->
<bool name="shamsi_date">false</bool>
diff --git a/themes/README.md b/themes/README.md
index 85cb6b313..ecc77a771 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -27,6 +27,7 @@ is ignored, and a file that doesn't parse is ignored as a whole, so a theme can
| `hidden_apps` | list of package names | Never shown as tiles |
| `live_tv_package`, `live_tv_action` | string | The Live TV app and, if it has no leanback entry, the action to start it with |
| `source_panel_service`, `source_panel_action` | string | The TV's own source panel, for sets with no TvInputManager |
+| `input_action` | string | Action sent with an HDMI/AV row's channel URI when nothing handles the standard `VIEW` (XGIMI: `com.xgimi.action.hdmiPlayer`) |
| `columns` | 1 to 8 | Tiles per row; tiles shrink to fit from 5 up |
| `rows_below_dock` | 0 to 3 | Grid rows left visible under the dock |
| `shamsi_date` | bool | Show the Solar Hijri date above the Gregorian one |