1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

Add method to get "base" system UI color (macOS/Windows) and system theme change callback.

This commit is contained in:
bruvzg
2024-01-19 20:46:26 +02:00
parent e92d55bbf4
commit ee53ae28df
24 changed files with 282 additions and 22 deletions

View File

@@ -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
@@ -559,6 +562,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
*/
@@ -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 {

View File

@@ -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;
@@ -145,6 +146,13 @@ public class GodotFragment extends Fragment implements IDownloaderClient, GodotH
parentHost = null;
}
@CallSuper
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
godot.onConfigurationChanged(newConfig);
}
@CallSuper
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

View File

@@ -219,6 +219,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.
*/