Skip to content

Commit

Permalink
Merge pull request #43022 from Klowner/3.2-android-display-orientation
Browse files Browse the repository at this point in the history
Implement OS.get_screen_orientation() for Android
  • Loading branch information
akien-mga authored Nov 15, 2020
2 parents b6d76c9 + 92ff6c5 commit c36a755
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ public void setScreenOrientation(int p_orientation) {
}
};

public int getScreenOrientation() {
return activity.getRequestedOrientation();
}

public void setEdit(GodotEditText _edit) {
edit = _edit;
}
Expand Down
10 changes: 10 additions & 0 deletions platform/android/java_godot_io_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions platform/android/java_godot_io_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions platform/android/os_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions platform/android/os_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c36a755

Please sign in to comment.