diff --git a/android/app/src/main/assets/phone/companion.html b/android/app/src/main/assets/phone/companion.html
index 0cb4f65a..b21e29c8 100644
--- a/android/app/src/main/assets/phone/companion.html
+++ b/android/app/src/main/assets/phone/companion.html
@@ -8,7 +8,7 @@
html,body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.35 system-ui,-apple-system,"Segoe UI",sans-serif}
button{font:inherit;color:inherit;border:0;background:none;cursor:pointer}
main{max-width:460px;margin:0 auto;padding:16px 16px 96px}
-header{display:flex;align-items:center;gap:8px;margin:4px 0 14px}
+header{display:flex;align-items:center;gap:8px;margin:0 0 12px;flex:none}
.brand{font-weight:800;letter-spacing:.14em;font-size:18px}.brand svg{vertical-align:-4px;margin-right:6px}
.page{color:var(--muted);font-size:16px}
.room{display:flex;align-items:center;gap:10px;background:var(--surface);border-radius:14px;padding:10px 14px;margin-bottom:12px;font-size:13px}
@@ -23,18 +23,21 @@ header{display:flex;align-items:center;gap:8px;margin:4px 0 14px}
.grow{flex:1;min-width:0}
.bar{height:4px;border-radius:2px;background:var(--deep);margin:12px 0 10px;overflow:hidden}.bar i{display:block;height:100%;background:var(--accent)}
.next{font-size:12px;color:var(--muted)}.next b{color:var(--ink);font-weight:600;letter-spacing:.04em}
-.pad{position:relative;width:240px;height:240px;margin:28px auto 22px;border-radius:50%;background:var(--surface)}
-.pad button{position:absolute;width:64px;height:64px;display:flex;align-items:center;justify-content:center;border-radius:50%}
+/* The remote fits the screen above the tabs (Paul, 6 November 2026: it overhung and scrolled): the pad takes what's left. */
+main.fit{height:calc(100svh - 72px - env(safe-area-inset-bottom));padding-bottom:12px;display:flex;flex-direction:column;overflow:hidden}
+.padwrap{flex:1 1 0;min-height:0;display:flex;align-items:center;justify-content:center;padding:12px 0}
+.pad{position:relative;height:min(240px,100%);aspect-ratio:1;border-radius:50%;background:var(--surface);container-type:size}
+.pad button{position:absolute;width:26.7%;height:26.7%;display:flex;align-items:center;justify-content:center;border-radius:50%}
.pad button:active{background:var(--raised)}
-.pad .up{left:88px;top:6px}.pad .down{left:88px;bottom:6px}.pad .left{left:6px;top:88px}.pad .right{right:6px;top:88px}
-.pad .ok{left:70px;top:70px;width:100px;height:100px;background:var(--accent);color:var(--on-accent);font-weight:800;font-size:24px}
+.pad .up{left:36.7%;top:2.5%}.pad .down{left:36.7%;bottom:2.5%}.pad .left{left:2.5%;top:36.7%}.pad .right{right:2.5%;top:36.7%}
+.pad .ok{left:29.2%;top:29.2%;width:41.6%;height:41.6%;background:var(--accent);color:var(--on-accent);font-weight:800;font-size:clamp(17px,10cqh,24px)}
.pad .ok:active{filter:brightness(.9);background:var(--accent)}
-.row{display:flex;gap:10px;align-items:center;justify-content:center}
-.round{width:52px;height:52px;border-radius:50%;background:var(--surface);display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:800;letter-spacing:.04em}
+.row{flex:none;display:flex;gap:10px;align-items:center;justify-content:center}
+.round{flex:none;width:52px;height:52px;border-radius:50%;background:var(--surface);display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:800;letter-spacing:.04em}
.rocker{display:flex;align-items:center;background:var(--surface);border-radius:999px;height:52px}
.rocker button{width:44px;height:52px;font-size:22px;font-weight:500}.rocker span{font-size:10px;font-weight:800;color:var(--muted);letter-spacing:.06em}
button:active{opacity:.75}
-.link{display:block;margin:18px auto 0;background:var(--surface);border-radius:999px;padding:8px 18px;font-size:13px;font-weight:600}
+.link{display:block;margin:12px auto 0;flex:none;background:var(--surface);border-radius:999px;padding:8px 18px;font-size:13px;font-weight:600}
.label{color:var(--muted);font-size:11px;font-weight:700;letter-spacing:.1em;text-transform:uppercase;margin:18px 0 8px}
.jumps{display:grid;grid-template-columns:repeat(4,1fr);gap:8px}
.jumps button{background:var(--raised);border-radius:12px;padding:12px 4px;font-size:12px;font-weight:600;display:flex;flex-direction:column;align-items:center;gap:6px}
@@ -135,8 +138,8 @@ function nowCard() {
}
function remote() {
return head('Remote') + nowCard() + `
-
-
+
+
CH
VOL
@@ -203,6 +206,7 @@ function more() {
}
function render() {
tabs();
+ $('#app').className = tab === 'remote' ? 'fit' : '';
$('#app').innerHTML = ({remote, guide, catchup, rooms, more})[tab]();
}
function openSheet(html) { $('#sheetIn').innerHTML = html; $('#sheet').classList.add('open'); $('#shade').classList.add('open'); }
diff --git a/android/app/src/main/java/tv/orbit/classic/MainActivity.kt b/android/app/src/main/java/tv/orbit/classic/MainActivity.kt
index e38aedc4..ab89c592 100644
--- a/android/app/src/main/java/tv/orbit/classic/MainActivity.kt
+++ b/android/app/src/main/java/tv/orbit/classic/MainActivity.kt
@@ -56,6 +56,7 @@ class MainActivity : ComponentActivity() {
}
override fun onStop() { RoomBeacon.off(this); PhoneLink.offerRoom(null); PhoneLink.stop(); super.onStop() }
override fun onCreate(savedInstanceState: Bundle?) {
+ OrbitCompanion.activity = java.lang.ref.WeakReference(this)
super.onCreate(savedInstanceState)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
Motion.load(OrbitSettings(this))
diff --git a/android/app/src/main/java/tv/orbit/classic/OrbitCompanion.kt b/android/app/src/main/java/tv/orbit/classic/OrbitCompanion.kt
index 6d0f49da..52b5e9c7 100644
--- a/android/app/src/main/java/tv/orbit/classic/OrbitCompanion.kt
+++ b/android/app/src/main/java/tv/orbit/classic/OrbitCompanion.kt
@@ -1,9 +1,15 @@
package tv.orbit.classic
-import android.app.Instrumentation
import android.content.Context
import android.media.AudioManager
+import android.os.Handler
+import android.os.Looper
+import android.os.SystemClock
+import android.view.InputDevice
+import android.view.KeyCharacterMap
import android.view.KeyEvent
+import android.view.View
+import androidx.activity.ComponentActivity
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
@@ -11,7 +17,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import org.json.JSONArray
import org.json.JSONObject
-import java.util.concurrent.Executors
/**
* Orbit Companion, phase 1 (Paul, 6 November 2026, from design/companion v2): the phone page grows into a remote for the TV
@@ -44,10 +49,35 @@ internal object OrbitCompanion {
private set
fun open(section: String) { asked = section to ((asked?.second ?: 0) + 1) }
- /** Presses go one at a time, in order, off the screen's thread (injecting waits for the TV to take each one). */
- private val presser = Executors.newSingleThreadExecutor { Thread(it, "orbit-companion-keys").apply { isDaemon = true } }
- internal var inject: (Int) -> Unit = { code -> Instrumentation().sendKeyDownUpSync(code) }
- fun press(code: Int) { presser.execute { runCatching { inject(code) }.onFailure { android.util.Log.i("OrbitCompanion", "press refused") } } }
+ /** Orbit itself, for Back on its main screen. Set while it's open. */
+ @Volatile var activity: java.lang.ref.WeakReference
? = null
+ /**
+ * A press, given to whichever of Orbit's windows has focus (the main screen, or a programme playing full screen), on the
+ * screen's own thread and in order, as the remote's would be. On the box, Android's injected keys never arrived
+ * (Paul, 6 November 2026), so Orbit hands the press to its own window instead.
+ */
+ internal var inject: (Int) -> Unit = { code -> main.post { runCatching { deliver(code) }.onFailure { android.util.Log.i("OrbitCompanion", "press not delivered") } } }
+ fun press(code: Int) = inject(code)
+ private val main by lazy { Handler(Looper.getMainLooper()) }
+
+ /** Orbit's windows, newest last: the activity's, and any dialog over it. */
+ @Suppress("UNCHECKED_CAST", "PrivateApi", "DiscouragedPrivateApi")
+ private fun windows(): List = runCatching {
+ val global = Class.forName("android.view.WindowManagerGlobal")
+ val instance = global.getMethod("getInstance").invoke(null)
+ (global.getDeclaredField("mViews").apply { isAccessible = true }.get(instance) as List).toList()
+ }.getOrDefault(emptyList())
+
+ private fun deliver(code: Int) {
+ val shown = activity?.get()
+ val root = windows().lastOrNull { it.hasWindowFocus() } ?: windows().lastOrNull { it.isShown } ?: shown?.window?.decorView ?: return
+ if (code == KeyEvent.KEYCODE_BACK && shown != null && root === shown.window.decorView) { shown.onBackPressedDispatcher.onBackPressed(); return }
+ val at = SystemClock.uptimeMillis()
+ val source = if (code == KeyEvent.KEYCODE_BACK || code == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) InputDevice.SOURCE_KEYBOARD else InputDevice.SOURCE_DPAD
+ fun event(action: Int, time: Long) = KeyEvent(at, time, action, code, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FROM_SYSTEM, source)
+ root.dispatchKeyEvent(event(KeyEvent.ACTION_DOWN, at))
+ root.dispatchKeyEvent(event(KeyEvent.ACTION_UP, at + 40))
+ }
internal var volume: (Int) -> Unit = { direction ->
(PhoneLink.context()?.getSystemService(Context.AUDIO_SERVICE) as? AudioManager)?.adjustStreamVolume(AudioManager.STREAM_MUSIC, direction, AudioManager.FLAG_SHOW_UI)