Orbit Companion: phone presses reach the TV, and the remote fits the screen

Android dropped injected key presses on the box, so arrows, OK, Back and
Subtitles did nothing. Orbit now hands each press to its own focused window
(Back on the main screen goes through its back handling). The remote's pad
sizes to the space left, so it no longer overhangs or scrolls.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-06 21:44:11 +00:00
co-authored by Claude Opus 5.5
parent 823eda12bd
commit 973fbcdb11
6 changed files with 56 additions and 21 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ android {
applicationId = "tv.orbit.classic"
minSdk = 26
targetSdk = 36
versionCode = 235
versionName = "0.108.75-companion"
versionCode = 236
versionName = "0.108.76-companion"
}
buildFeatures { compose = true }
// The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so
@@ -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() + `
<div class="pad"><button class="up" data-key="up" aria-label="Up">${I.chev('up')}</button><button class="left" data-key="left" aria-label="Left">${I.chev('left')}</button>
<button class="ok" data-key="ok">OK</button><button class="right" data-key="right" aria-label="Right">${I.chev('right')}</button><button class="down" data-key="down" aria-label="Down">${I.chev('down')}</button></div>
<div class="padwrap"><div class="pad"><button class="up" data-key="up" aria-label="Up">${I.chev('up')}</button><button class="left" data-key="left" aria-label="Left">${I.chev('left')}</button>
<button class="ok" data-key="ok">OK</button><button class="right" data-key="right" aria-label="Right">${I.chev('right')}</button><button class="down" data-key="down" aria-label="Down">${I.chev('down')}</button></div></div>
<div class="row"><button class="round" data-key="back" aria-label="Back">${I.back}</button>
<div class="rocker"><button data-ch="1" aria-label="Channel up">+</button><span>CH</span><button data-ch="-1" aria-label="Channel down">−</button></div>
<div class="rocker"><button data-vol="down" aria-label="Volume down">−</button><span>VOL</span><button data-vol="up" aria-label="Volume up">+</button></div>
@@ -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'); }
@@ -62,9 +62,9 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI
}
/** The sign-in headers for this kind of server. */
internal fun authHeaders(token: String?): Map<String, String> = when (kind) {
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.75\"") +
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.76\"") +
(token?.let { mapOf("X-Emby-Token" to it) } ?: emptyMap())
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.75\"" +
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.76\"" +
(token?.let { ", Token=\"$it\"" } ?: ""))
}
/** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */
@@ -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))
@@ -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<ComponentActivity>? = 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<View> = 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<View>).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)
@@ -39,7 +39,7 @@ internal class SecureMediaDataSource(private val session: EmbySampleSession) : B
next.instanceFollowRedirects = false
next.connectTimeout = 10_000
next.readTimeout = 20_000
next.setRequestProperty("User-Agent", "OrbitTV/0.108.75")
next.setRequestProperty("User-Agent", "OrbitTV/0.108.76")
next.setRequestProperty("Accept-Encoding", "identity")
session.mediaHeaders(address).forEach { (key, value) -> next.setRequestProperty(key, value) }
if (dataSpec.position != 0L || dataSpec.length != C.LENGTH_UNSET.toLong()) {