summaryrefslogtreecommitdiffstats
path: root/platform/android/java/lib/src
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2024-01-19 20:46:26 +0200
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2024-02-13 18:38:53 +0200
commitee53ae28dff4ca227ba970c733bf89d53f432141 (patch)
treee06843f4904ae6aafeeb99b1beaade6a96dff74e /platform/android/java/lib/src
parente92d55bbf417aa9f4592a863cb5b2c7ba0740e21 (diff)
downloadredot-engine-ee53ae28dff4ca227ba970c733bf89d53f432141.tar.gz
Add method to get "base" system UI color (macOS/Windows) and system theme change callback.
Diffstat (limited to 'platform/android/java/lib/src')
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/Godot.kt21
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java8
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotLib.java5
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);