summaryrefslogtreecommitdiffstats
path: root/platform/android/java/lib/src
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-02-13 23:43:21 +0100
committerRémi Verschelde <rverschelde@gmail.com>2024-02-13 23:43:21 +0100
commitb6dee8850b7846d1e1414f0119f7f15697aa7603 (patch)
treea5219aea4e81e7fa3320643839c6677b646c2442 /platform/android/java/lib/src
parentdc99c8d4a4e2456da2988dac078e3085d2034664 (diff)
parentee53ae28dff4ca227ba970c733bf89d53f432141 (diff)
downloadredot-engine-b6dee8850b7846d1e1414f0119f7f15697aa7603.tar.gz
Merge pull request #87384 from bruvzg/sys_base_color
Add method to get "base" system UI color 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);