From 775b63bc775c1b2c924826bd34990650bc4612cd Mon Sep 17 00:00:00 2001 From: NullVector Date: Sat, 10 Oct 2026 20:50:19 +1030 Subject: [PATCH] android: Improve changing web theme (#402) --- src/android/app/src/main/assets/ui.css | 31 +++++++++++++++++++ .../java/org/nxemu/ui/main/MainActivity.kt | 19 ++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/android/app/src/main/assets/ui.css b/src/android/app/src/main/assets/ui.css index 245701be..565b374f 100644 --- a/src/android/app/src/main/assets/ui.css +++ b/src/android/app/src/main/assets/ui.css @@ -33,6 +33,37 @@ html.light { --band: #f2f5f7; } +@property --bg { + syntax: ""; + inherits: true; + initial-value: #ffffff; +} +@property --text { + syntax: ""; + inherits: true; + initial-value: #111111; +} +@property --muted { + syntax: ""; + inherits: true; + initial-value: #4a555c; +} +@property --line { + syntax: ""; + inherits: true; + initial-value: rgba(128, 128, 128, 0.2); +} +@property --card { + syntax: ""; + inherits: true; + initial-value: rgba(128, 128, 128, 0.1); +} +@property --band { + syntax: ""; + inherits: true; + initial-value: #f2f5f7; +} + * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; diff --git a/src/android/app/src/main/java/org/nxemu/ui/main/MainActivity.kt b/src/android/app/src/main/java/org/nxemu/ui/main/MainActivity.kt index 1aa19db9..3b2c6cec 100644 --- a/src/android/app/src/main/java/org/nxemu/ui/main/MainActivity.kt +++ b/src/android/app/src/main/java/org/nxemu/ui/main/MainActivity.kt @@ -52,6 +52,9 @@ open class MainActivity : ComponentActivity() { } private val settingChangedForwarder: (String) -> Unit = { setting -> runOnUiThread { + if (setting == NXUISetting.ThemeMode) { + applyWebViewTheme() + } webView.evaluateJavascript( "onSettingChanged('${setting.replace("'", "\\'")}')", null @@ -175,6 +178,7 @@ open class MainActivity : ComponentActivity() { emulationLaunchPending = false InputHandler.updateControllerData() inputManager()?.registerInputDeviceListener(inputDeviceListener, null) + applyWebViewTheme() refreshConnectedControllers() resumeRunningGame() } @@ -359,6 +363,12 @@ open class MainActivity : ComponentActivity() { fun editOverlayLayout() { startActivity(Intent(this, OverlayLayoutActivity::class.java)) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + overrideActivityTransition(Activity.OVERRIDE_TRANSITION_OPEN, 0, 0) + } else { + @Suppress("DEPRECATION") + overridePendingTransition(0, 0) + } } override fun onDestroy() { @@ -389,6 +399,15 @@ open class MainActivity : ComponentActivity() { ) } + private fun applyWebViewTheme() { + if (!::webView.isInitialized) { + return + } + webView.setBackgroundColor(ThemeHelper.backgroundColor(this)) + ThemeHelper.applySystemBars(this) + webView.evaluateJavascript("typeof applyTheme==='function'&&applyTheme()", null) + } + companion object { private const val STICK_REPEAT_MS = 220L private const val STICK_DEADZONE = 0.5f