diff options
Diffstat (limited to 'platform/android/java/lib/src')
3 files changed, 29 insertions, 5 deletions
diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt index da86e67c7d..dd007a4254 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt @@ -149,6 +149,7 @@ class Godot(private val context: Context) : SensorEventListener { private var useApkExpansion = false private var useImmersive = false private var useDebugOpengl = false + private var darkMode = false; private var containerLayout: FrameLayout? = null var renderView: GodotRenderView? = null @@ -184,6 +185,8 @@ class Godot(private val context: Context) : SensorEventListener { return } + darkMode = context.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES + beginBenchmarkMeasure("Startup", "Godot::onCreate") try { this.primaryHost = primaryHost @@ -560,6 +563,17 @@ class Godot(private val context: Context) : SensorEventListener { } /** + * Configuration change callback + */ + fun onConfigurationChanged(newConfig: Configuration) { + var newDarkMode = newConfig.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES + if (darkMode != newDarkMode) { + darkMode = newDarkMode + GodotLib.onNightModeChanged() + } + } + + /** * Activity result callback */ fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { @@ -731,7 +745,7 @@ class Godot(private val context: Context) : SensorEventListener { */ @Keep private fun isDarkModeSupported(): Boolean { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q + return context.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_UNDEFINED } /** @@ -739,10 +753,7 @@ class Godot(private val context: Context) : SensorEventListener { */ @Keep private fun isDarkMode(): Boolean { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - return context.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES - } - return false + return darkMode } fun hasClipboard(): Boolean { diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java b/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java index 643c9a658e..a323045e1b 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java @@ -38,6 +38,7 @@ import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; import android.os.Messenger; @@ -147,6 +148,13 @@ public class GodotFragment extends Fragment implements IDownloaderClient, GodotH @CallSuper @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + godot.onConfigurationChanged(newConfig); + } + + @CallSuper + @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCallback != null) { diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java index fee50e93c2..d0c3d4a687 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java @@ -220,6 +220,11 @@ public class GodotLib { public static native void requestPermissionResult(String p_permission, boolean p_result); /** + * Invoked on the theme light/dark mode change. + */ + public static native void onNightModeChanged(); + + /** * Invoked on the GL thread to configure the height of the virtual keyboard. */ public static native void setVirtualKeyboardHeight(int p_height); |