diff --git a/core/os/os.h b/core/os/os.h index 6eb1e0736794..5714e101d98b 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -473,7 +473,7 @@ class OS { }; virtual void set_screen_orientation(ScreenOrientation p_orientation); - ScreenOrientation get_screen_orientation() const; + virtual ScreenOrientation get_screen_orientation() const; virtual void enable_for_stealing_focus(ProcessID pid) {} virtual void move_window_to_foreground() {} diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java index 576f09fb24c2..cc2e4097335d 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java @@ -561,6 +561,10 @@ public void setScreenOrientation(int p_orientation) { } }; + public int getScreenOrientation() { + return activity.getRequestedOrientation(); + } + public void setEdit(GodotEditText _edit) { edit = _edit; } diff --git a/platform/android/java_godot_io_wrapper.cpp b/platform/android/java_godot_io_wrapper.cpp index 8d3f667317bc..0c5a49e49ca2 100644 --- a/platform/android/java_godot_io_wrapper.cpp +++ b/platform/android/java_godot_io_wrapper.cpp @@ -57,6 +57,7 @@ GodotIOJavaWrapper::GodotIOJavaWrapper(JNIEnv *p_env, jobject p_godot_io_instanc _show_keyboard = p_env->GetMethodID(cls, "showKeyboard", "(Ljava/lang/String;ZIII)V"); _hide_keyboard = p_env->GetMethodID(cls, "hideKeyboard", "()V"); _set_screen_orientation = p_env->GetMethodID(cls, "setScreenOrientation", "(I)V"); + _get_screen_orientation = p_env->GetMethodID(cls, "getScreenOrientation", "()I"); _get_system_dir = p_env->GetMethodID(cls, "getSystemDir", "(I)Ljava/lang/String;"); _play_video = p_env->GetMethodID(cls, "playVideo", "(Ljava/lang/String;)V"); _is_video_playing = p_env->GetMethodID(cls, "isVideoPlaying", "()Z"); @@ -171,6 +172,15 @@ void GodotIOJavaWrapper::set_screen_orientation(int p_orient) { } } +int GodotIOJavaWrapper::get_screen_orientation() const { + if (_get_screen_orientation) { + JNIEnv *env = ThreadAndroid::get_env(); + return env->CallIntMethod(godot_io_instance, _get_screen_orientation); + } else { + return 0; + } +} + String GodotIOJavaWrapper::get_system_dir(int p_dir) { if (_get_system_dir) { JNIEnv *env = ThreadAndroid::get_env(); diff --git a/platform/android/java_godot_io_wrapper.h b/platform/android/java_godot_io_wrapper.h index d03e3cbde548..202d0578747f 100644 --- a/platform/android/java_godot_io_wrapper.h +++ b/platform/android/java_godot_io_wrapper.h @@ -55,6 +55,7 @@ class GodotIOJavaWrapper { jmethodID _show_keyboard = 0; jmethodID _hide_keyboard = 0; jmethodID _set_screen_orientation = 0; + jmethodID _get_screen_orientation = 0; jmethodID _get_system_dir = 0; jmethodID _play_video = 0; jmethodID _is_video_playing = 0; @@ -80,6 +81,7 @@ class GodotIOJavaWrapper { int get_vk_height(); void set_vk_height(int p_height); void set_screen_orientation(int p_orient); + int get_screen_orientation() const; String get_system_dir(int p_dir); void play_video(const String &p_path); bool is_video_playing(); diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index ba6c44464c55..0a45e46cd655 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -846,6 +846,11 @@ void OS_Android::set_screen_orientation(ScreenOrientation p_orientation) { godot_io_java->set_screen_orientation(p_orientation); } +OS::ScreenOrientation OS_Android::get_screen_orientation() const { + const int orientation = godot_io_java->get_screen_orientation(); + return OS::ScreenOrientation(orientation); +} + String OS_Android::get_unique_id() const { String unique_id = godot_io_java->get_unique_id(); diff --git a/platform/android/os_android.h b/platform/android/os_android.h index d70021bc512d..944587aa966d 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -184,6 +184,7 @@ class OS_Android : public OS_Unix { void set_context_is_16_bits(bool p_is_16); virtual void set_screen_orientation(ScreenOrientation p_orientation); + virtual ScreenOrientation get_screen_orientation() const; virtual Error shell_open(String p_uri); virtual String get_user_data_dir() const;