package com.ultron.jarvistv import android.content.Intent import android.os.Bundle import android.provider.Settings import android.text.TextUtils import android.view.View import android.widget.TextView import androidx.appcompat.app.AppCompatActivity /** * The Jarvis face on the TV. Boots the ControlService, nudges the user to enable the * accessibility engine (one-time), shows the local IP to point commands at, and streams a * live status feed of what Jarvis is doing. v1 UI is intentionally simple — the animated * "arc reactor" Jarvis look comes in the next iteration. */ class MainActivity : AppCompatActivity() { private lateinit var statusView: TextView private lateinit var hintView: TextView private val feed = ArrayDeque() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) statusView = findViewById(R.id.status) hintView = findViewById(R.id.hint) // Start the always-on command server. startService(Intent(this, ControlService::class.java)) } override fun onResume() { super.onResume() UiBus.subscribe { line -> feed.addFirst(line) while (feed.size > 8) feed.removeLast() statusView.text = feed.joinToString("\n") } refreshHint() } override fun onPause() { UiBus.unsubscribe() super.onPause() } private fun refreshHint() { val ip = NetUtil.localIp(this) ?: "unknown" if (!accessibilityEnabled()) { hintView.visibility = View.VISIBLE hintView.text = "⚠ Enable Jarvis control:\n" + "Settings ▸ Accessibility ▸ Jarvis ▸ On\n\n" + "Then send commands to http://$ip:${ControlService.PORT}/cmd" } else { hintView.visibility = View.VISIBLE hintView.text = "Jarvis ready ✓ → http://$ip:${ControlService.PORT}/cmd" } } private fun accessibilityEnabled(): Boolean { val flat = Settings.Secure.getString( contentResolver, Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES) ?: return false val me = packageName + "/" + JarvisAccessibilityService::class.java.name val splitter = TextUtils.SimpleStringSplitter(':') splitter.setString(flat) while (splitter.hasNext()) if (splitter.next().equals(me, ignoreCase = true)) return true return false } }