diff options
author | Thaddeus Crews <repiteo@outlook.com> | 2024-11-04 21:52:04 -0600 |
---|---|---|
committer | Thaddeus Crews <repiteo@outlook.com> | 2024-11-04 21:52:04 -0600 |
commit | 7d950c15677b6c778294238ea29e00b6355cf931 (patch) | |
tree | a1dca2546b883526c815af7c0694f3ce352ffb15 /platform | |
parent | ef8aafc2dfba33e867f9b0b6e4be71a210daf78e (diff) | |
parent | 7b866f302ffbcdbacbc1d7fa0f280f2c36cfd481 (diff) | |
download | redot-engine-7d950c15677b6c778294238ea29e00b6355cf931.tar.gz |
Merge pull request #98712 from syntaxerror247/android_accent_color
[Android] Implement support for accent color retrieval
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/display_server_android.cpp | 6 | ||||
-rw-r--r-- | platform/android/display_server_android.h | 2 | ||||
-rw-r--r-- | platform/android/java/lib/src/org/godotengine/godot/Godot.kt | 6 | ||||
-rw-r--r-- | platform/android/java_godot_wrapper.cpp | 18 | ||||
-rw-r--r-- | platform/android/java_godot_wrapper.h | 3 |
5 files changed, 35 insertions, 0 deletions
diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp index 9930116c62..38f6931c8a 100644 --- a/platform/android/display_server_android.cpp +++ b/platform/android/display_server_android.cpp @@ -203,6 +203,12 @@ void DisplayServerAndroid::emit_file_picker_callback(bool p_ok, const Vector<Str } } +Color DisplayServerAndroid::get_accent_color() const { + GodotJavaWrapper *godot_java = OS_Android::get_singleton()->get_godot_java(); + ERR_FAIL_NULL_V(godot_java, Color(0, 0, 0, 0)); + return godot_java->get_accent_color(); +} + TypedArray<Rect2> DisplayServerAndroid::get_display_cutouts() const { GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java(); ERR_FAIL_NULL_V(godot_io_java, Array()); diff --git a/platform/android/display_server_android.h b/platform/android/display_server_android.h index 6abbd8787b..1744ad3069 100644 --- a/platform/android/display_server_android.h +++ b/platform/android/display_server_android.h @@ -125,6 +125,8 @@ public: virtual Error file_dialog_show(const String &p_title, const String &p_current_directory, const String &p_filename, bool p_show_hidden, const FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback) override; void emit_file_picker_callback(bool p_ok, const Vector<String> &p_selected_paths); + virtual Color get_accent_color() const override; + virtual TypedArray<Rect2> get_display_cutouts() const override; virtual Rect2i get_display_safe_area() const override; 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 898e3e04be..3ad8e6bc9e 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt @@ -925,6 +925,12 @@ class Godot(private val context: Context) { } } + @Keep + private fun getAccentColor(): Int { + val value = TypedValue() + context.theme.resolveAttribute(android.R.attr.colorAccent, value, true) + return value.data + } /** * Destroys the Godot Engine and kill the process it's running in. diff --git a/platform/android/java_godot_wrapper.cpp b/platform/android/java_godot_wrapper.cpp index 2811182e29..5ecd789d43 100644 --- a/platform/android/java_godot_wrapper.cpp +++ b/platform/android/java_godot_wrapper.cpp @@ -64,6 +64,7 @@ GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_activity, jobject p_ _alert = p_env->GetMethodID(godot_class, "alert", "(Ljava/lang/String;Ljava/lang/String;)V"); _is_dark_mode_supported = p_env->GetMethodID(godot_class, "isDarkModeSupported", "()Z"); _is_dark_mode = p_env->GetMethodID(godot_class, "isDarkMode", "()Z"); + _get_accent_color = p_env->GetMethodID(godot_class, "getAccentColor", "()I"); _get_clipboard = p_env->GetMethodID(godot_class, "getClipboard", "()Ljava/lang/String;"); _set_clipboard = p_env->GetMethodID(godot_class, "setClipboard", "(Ljava/lang/String;)V"); _has_clipboard = p_env->GetMethodID(godot_class, "hasClipboard", "()Z"); @@ -214,6 +215,23 @@ bool GodotJavaWrapper::is_dark_mode() { } } +Color GodotJavaWrapper::get_accent_color() { + if (_get_accent_color) { + JNIEnv *env = get_jni_env(); + ERR_FAIL_NULL_V(env, Color(0, 0, 0, 0)); + int accent_color = env->CallIntMethod(godot_instance, _get_accent_color); + + // Convert ARGB to RGBA. + int alpha = (accent_color >> 24) & 0xFF; + int red = (accent_color >> 16) & 0xFF; + int green = (accent_color >> 8) & 0xFF; + int blue = accent_color & 0xFF; + return Color(red / 255.0f, green / 255.0f, blue / 255.0f, alpha / 255.0f); + } else { + return Color(0, 0, 0, 0); + } +} + bool GodotJavaWrapper::has_get_clipboard() { return _get_clipboard != nullptr; } diff --git a/platform/android/java_godot_wrapper.h b/platform/android/java_godot_wrapper.h index 1a753c5c59..512779169a 100644 --- a/platform/android/java_godot_wrapper.h +++ b/platform/android/java_godot_wrapper.h @@ -34,6 +34,7 @@ #include "java_godot_view_wrapper.h" #include "string_android.h" +#include "core/math/color.h" #include "core/templates/list.h" #include <android/log.h> @@ -55,6 +56,7 @@ private: jmethodID _alert = nullptr; jmethodID _is_dark_mode_supported = nullptr; jmethodID _is_dark_mode = nullptr; + jmethodID _get_accent_color = nullptr; jmethodID _get_clipboard = nullptr; jmethodID _set_clipboard = nullptr; jmethodID _has_clipboard = nullptr; @@ -99,6 +101,7 @@ public: void alert(const String &p_message, const String &p_title); bool is_dark_mode_supported(); bool is_dark_mode(); + Color get_accent_color(); bool has_get_clipboard(); String get_clipboard(); bool has_set_clipboard(); |