summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/android_keys_utils.h127
-rw-r--r--platform/android/api/api.cpp2
-rw-r--r--platform/android/api/java_class_wrapper.h2
-rw-r--r--platform/android/api/jni_singleton.h4
-rw-r--r--platform/android/audio_driver_jandroid.cpp2
-rw-r--r--platform/android/dir_access_jandroid.cpp2
-rw-r--r--platform/android/display_server_android.cpp177
-rw-r--r--platform/android/display_server_android.h16
-rw-r--r--platform/android/export/export.cpp157
-rw-r--r--platform/android/export/gradle_export_util.h63
-rw-r--r--platform/android/file_access_android.cpp2
-rw-r--r--platform/android/java/app/build.gradle4
-rw-r--r--platform/android/java/app/config.gradle9
-rw-r--r--platform/android/java/app/res/values/themes.xml1
-rw-r--r--platform/android/java/build.gradle2
-rw-r--r--platform/android/java/gradle.properties2
-rw-r--r--platform/android/java/gradle/wrapper/gradle-wrapper.properties2
-rw-r--r--platform/android/java/lib/build.gradle54
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/Godot.java58
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotGLRenderView.java3
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotIO.java26
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotLib.java8
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java9
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.java4
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java105
-rw-r--r--platform/android/java/nativeSrcsConfigs/AndroidManifest.xml2
-rw-r--r--platform/android/java/nativeSrcsConfigs/CMakeLists.txt (renamed from platform/android/java/lib/CMakeLists.txt)1
-rw-r--r--platform/android/java/nativeSrcsConfigs/README.md4
-rw-r--r--platform/android/java/nativeSrcsConfigs/build.gradle54
-rw-r--r--platform/android/java/settings.gradle1
-rw-r--r--platform/android/java_godot_io_wrapper.cpp16
-rw-r--r--platform/android/java_godot_io_wrapper.h2
-rw-r--r--platform/android/java_godot_lib_jni.cpp42
-rw-r--r--platform/android/java_godot_lib_jni.h9
-rw-r--r--platform/android/jni_utils.h4
-rw-r--r--platform/android/os_android.cpp3
-rw-r--r--platform/android/plugin/godot_plugin_config.h4
-rw-r--r--platform/android/plugin/godot_plugin_jni.cpp6
-rw-r--r--platform/android/string_android.h2
-rw-r--r--platform/android/thread_jandroid.cpp4
-rw-r--r--platform/android/vulkan/vulkan_context_android.cpp1
41 files changed, 676 insertions, 320 deletions
diff --git a/platform/android/android_keys_utils.h b/platform/android/android_keys_utils.h
index 857bef02d1..a10afa1df8 100644
--- a/platform/android/android_keys_utils.h
+++ b/platform/android/android_keys_utils.h
@@ -31,130 +31,9 @@
#ifndef ANDROID_KEYS_UTILS_H
#define ANDROID_KEYS_UTILS_H
+#include <android/input.h>
#include <core/os/keyboard.h>
-/*
- * Android Key codes.
- */
-enum {
- AKEYCODE_UNKNOWN = 0,
- AKEYCODE_SOFT_LEFT = 1,
- AKEYCODE_SOFT_RIGHT = 2,
- AKEYCODE_HOME = 3,
- AKEYCODE_BACK = 4,
- AKEYCODE_CALL = 5,
- AKEYCODE_ENDCALL = 6,
- AKEYCODE_0 = 7,
- AKEYCODE_1 = 8,
- AKEYCODE_2 = 9,
- AKEYCODE_3 = 10,
- AKEYCODE_4 = 11,
- AKEYCODE_5 = 12,
- AKEYCODE_6 = 13,
- AKEYCODE_7 = 14,
- AKEYCODE_8 = 15,
- AKEYCODE_9 = 16,
- AKEYCODE_STAR = 17,
- AKEYCODE_POUND = 18,
- AKEYCODE_DPAD_UP = 19,
- AKEYCODE_DPAD_DOWN = 20,
- AKEYCODE_DPAD_LEFT = 21,
- AKEYCODE_DPAD_RIGHT = 22,
- AKEYCODE_DPAD_CENTER = 23,
- AKEYCODE_VOLUME_UP = 24,
- AKEYCODE_VOLUME_DOWN = 25,
- AKEYCODE_POWER = 26,
- AKEYCODE_CAMERA = 27,
- AKEYCODE_CLEAR = 28,
- AKEYCODE_A = 29,
- AKEYCODE_B = 30,
- AKEYCODE_C = 31,
- AKEYCODE_D = 32,
- AKEYCODE_E = 33,
- AKEYCODE_F = 34,
- AKEYCODE_G = 35,
- AKEYCODE_H = 36,
- AKEYCODE_I = 37,
- AKEYCODE_J = 38,
- AKEYCODE_K = 39,
- AKEYCODE_L = 40,
- AKEYCODE_M = 41,
- AKEYCODE_N = 42,
- AKEYCODE_O = 43,
- AKEYCODE_P = 44,
- AKEYCODE_Q = 45,
- AKEYCODE_R = 46,
- AKEYCODE_S = 47,
- AKEYCODE_T = 48,
- AKEYCODE_U = 49,
- AKEYCODE_V = 50,
- AKEYCODE_W = 51,
- AKEYCODE_X = 52,
- AKEYCODE_Y = 53,
- AKEYCODE_Z = 54,
- AKEYCODE_COMMA = 55,
- AKEYCODE_PERIOD = 56,
- AKEYCODE_ALT_LEFT = 57,
- AKEYCODE_ALT_RIGHT = 58,
- AKEYCODE_SHIFT_LEFT = 59,
- AKEYCODE_SHIFT_RIGHT = 60,
- AKEYCODE_TAB = 61,
- AKEYCODE_SPACE = 62,
- AKEYCODE_SYM = 63,
- AKEYCODE_EXPLORER = 64,
- AKEYCODE_ENVELOPE = 65,
- AKEYCODE_ENTER = 66,
- AKEYCODE_DEL = 67,
- AKEYCODE_GRAVE = 68,
- AKEYCODE_MINUS = 69,
- AKEYCODE_EQUALS = 70,
- AKEYCODE_LEFT_BRACKET = 71,
- AKEYCODE_RIGHT_BRACKET = 72,
- AKEYCODE_BACKSLASH = 73,
- AKEYCODE_SEMICOLON = 74,
- AKEYCODE_APOSTROPHE = 75,
- AKEYCODE_SLASH = 76,
- AKEYCODE_AT = 77,
- AKEYCODE_NUM = 78,
- AKEYCODE_HEADSETHOOK = 79,
- AKEYCODE_FOCUS = 80, // *Camera* focus
- AKEYCODE_PLUS = 81,
- AKEYCODE_MENU = 82,
- AKEYCODE_NOTIFICATION = 83,
- AKEYCODE_SEARCH = 84,
- AKEYCODE_MEDIA_PLAY_PAUSE = 85,
- AKEYCODE_MEDIA_STOP = 86,
- AKEYCODE_MEDIA_NEXT = 87,
- AKEYCODE_MEDIA_PREVIOUS = 88,
- AKEYCODE_MEDIA_REWIND = 89,
- AKEYCODE_MEDIA_FAST_FORWARD = 90,
- AKEYCODE_MUTE = 91,
- AKEYCODE_PAGE_UP = 92,
- AKEYCODE_PAGE_DOWN = 93,
- AKEYCODE_PICTSYMBOLS = 94,
- AKEYCODE_SWITCH_CHARSET = 95,
- AKEYCODE_BUTTON_A = 96,
- AKEYCODE_BUTTON_B = 97,
- AKEYCODE_BUTTON_C = 98,
- AKEYCODE_BUTTON_X = 99,
- AKEYCODE_BUTTON_Y = 100,
- AKEYCODE_BUTTON_Z = 101,
- AKEYCODE_BUTTON_L1 = 102,
- AKEYCODE_BUTTON_R1 = 103,
- AKEYCODE_BUTTON_L2 = 104,
- AKEYCODE_BUTTON_R2 = 105,
- AKEYCODE_BUTTON_THUMBL = 106,
- AKEYCODE_BUTTON_THUMBR = 107,
- AKEYCODE_BUTTON_START = 108,
- AKEYCODE_BUTTON_SELECT = 109,
- AKEYCODE_BUTTON_MODE = 110,
- AKEYCODE_CONTROL_LEFT = 113,
- AKEYCODE_CONTROL_RIGHT = 114,
-
- // NOTE: If you add a new keycode here you must also add it to several other files.
- // Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
-};
-
struct _WinTranslatePair {
unsigned int keysym;
unsigned int keycode;
@@ -248,8 +127,8 @@ static _WinTranslatePair _ak_to_keycode[] = {
{ KEY_BACKSLASH, AKEYCODE_BACKSLASH },
{ KEY_BRACKETLEFT, AKEYCODE_LEFT_BRACKET },
{ KEY_BRACKETRIGHT, AKEYCODE_RIGHT_BRACKET },
- { KEY_CONTROL, AKEYCODE_CONTROL_LEFT },
- { KEY_CONTROL, AKEYCODE_CONTROL_RIGHT },
+ { KEY_CONTROL, AKEYCODE_CTRL_LEFT },
+ { KEY_CONTROL, AKEYCODE_CTRL_RIGHT },
{ KEY_UNKNOWN, 0 }
};
/*
diff --git a/platform/android/api/api.cpp b/platform/android/api/api.cpp
index 1f140f7119..8b82733d2d 100644
--- a/platform/android/api/api.cpp
+++ b/platform/android/api/api.cpp
@@ -30,7 +30,7 @@
#include "api.h"
-#include "core/engine.h"
+#include "core/config/engine.h"
#include "java_class_wrapper.h"
#include "jni_singleton.h"
diff --git a/platform/android/api/java_class_wrapper.h b/platform/android/api/java_class_wrapper.h
index 1fa2726784..4718de29ad 100644
--- a/platform/android/api/java_class_wrapper.h
+++ b/platform/android/api/java_class_wrapper.h
@@ -31,7 +31,7 @@
#ifndef JAVA_CLASS_WRAPPER_H
#define JAVA_CLASS_WRAPPER_H
-#include "core/reference.h"
+#include "core/object/reference.h"
#ifdef ANDROID_ENABLED
#include <android/log.h>
diff --git a/platform/android/api/jni_singleton.h b/platform/android/api/jni_singleton.h
index 5e63f20d6c..7f20c354a0 100644
--- a/platform/android/api/jni_singleton.h
+++ b/platform/android/api/jni_singleton.h
@@ -31,8 +31,8 @@
#ifndef JNI_SINGLETON_H
#define JNI_SINGLETON_H
-#include <core/engine.h>
-#include <core/variant.h>
+#include <core/config/engine.h>
+#include <core/variant/variant.h>
#ifdef ANDROID_ENABLED
#include <platform/android/jni_utils.h>
#endif
diff --git a/platform/android/audio_driver_jandroid.cpp b/platform/android/audio_driver_jandroid.cpp
index 09c981b3fa..1363c5ac1e 100644
--- a/platform/android/audio_driver_jandroid.cpp
+++ b/platform/android/audio_driver_jandroid.cpp
@@ -30,8 +30,8 @@
#include "audio_driver_jandroid.h"
+#include "core/config/project_settings.h"
#include "core/os/os.h"
-#include "core/project_settings.h"
#include "thread_jandroid.h"
AudioDriverAndroid *AudioDriverAndroid::s_ad = nullptr;
diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp
index ca312b427f..ba75a4b10c 100644
--- a/platform/android/dir_access_jandroid.cpp
+++ b/platform/android/dir_access_jandroid.cpp
@@ -29,7 +29,7 @@
/*************************************************************************/
#include "dir_access_jandroid.h"
-#include "core/print_string.h"
+#include "core/string/print_string.h"
#include "file_access_jandroid.h"
#include "string_android.h"
#include "thread_jandroid.h"
diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp
index 3aa2fb5451..e82a12ece5 100644
--- a/platform/android/display_server_android.cpp
+++ b/platform/android/display_server_android.cpp
@@ -31,11 +31,13 @@
#include "display_server_android.h"
#include "android_keys_utils.h"
-#include "core/project_settings.h"
+#include "core/config/project_settings.h"
#include "java_godot_io_wrapper.h"
#include "java_godot_wrapper.h"
#include "os_android.h"
+#include <android/input.h>
+
#if defined(VULKAN_ENABLED)
#include "drivers/vulkan/rendering_device_vulkan.h"
#include "platform/android/vulkan/vulkan_context_android.h"
@@ -55,7 +57,7 @@ bool DisplayServerAndroid::has_feature(Feature p_feature) const {
//case FEATURE_HIDPI:
//case FEATURE_ICON:
//case FEATURE_IME:
- //case FEATURE_MOUSE:
+ case FEATURE_MOUSE:
//case FEATURE_MOUSE_WARP:
//case FEATURE_NATIVE_DIALOG:
//case FEATURE_NATIVE_ICON:
@@ -137,8 +139,11 @@ Size2i DisplayServerAndroid::screen_get_size(int p_screen) const {
}
Rect2i DisplayServerAndroid::screen_get_usable_rect(int p_screen) const {
- Size2i display_size = OS_Android::get_singleton()->get_display_size();
- return Rect2i(0, 0, display_size.width, display_size.height);
+ GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java();
+ ERR_FAIL_COND_V(!godot_io_java, Rect2i());
+ int xywh[4];
+ godot_io_java->screen_get_usable_rect(xywh);
+ return Rect2i(xywh[0], xywh[1], xywh[2], xywh[3]);
}
int DisplayServerAndroid::screen_get_dpi(int p_screen) const {
@@ -340,7 +345,7 @@ void DisplayServerAndroid::alert(const String &p_alert, const String &p_title) {
}
void DisplayServerAndroid::process_events() {
- // Nothing to do
+ Input::get_singleton()->flush_accumulated_events();
}
Vector<String> DisplayServerAndroid::get_rendering_drivers_func() {
@@ -395,6 +400,8 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis
keep_screen_on = GLOBAL_GET("display/window/energy_saving/keep_screen_on");
+ buttons_state = 0;
+
#if defined(OPENGL_ENABLED)
if (rendering_driver == "opengl") {
bool gl_initialization_error = false;
@@ -529,12 +536,12 @@ void DisplayServerAndroid::process_key_event(int p_keycode, int p_scancode, int
OS_Android::get_singleton()->main_loop_request_go_back();
}
- Input::get_singleton()->parse_input_event(ev);
+ Input::get_singleton()->accumulate_input_event(ev);
}
-void DisplayServerAndroid::process_touch(int p_what, int p_pointer, const Vector<DisplayServerAndroid::TouchPos> &p_points) {
- switch (p_what) {
- case 0: { //gesture begin
+void DisplayServerAndroid::process_touch(int p_event, int p_pointer, const Vector<DisplayServerAndroid::TouchPos> &p_points) {
+ switch (p_event) {
+ case AMOTION_EVENT_ACTION_DOWN: { //gesture begin
if (touch.size()) {
//end all if exist
for (int i = 0; i < touch.size(); i++) {
@@ -543,7 +550,7 @@ void DisplayServerAndroid::process_touch(int p_what, int p_pointer, const Vector
ev->set_index(touch[i].id);
ev->set_pressed(false);
ev->set_position(touch[i].pos);
- Input::get_singleton()->parse_input_event(ev);
+ Input::get_singleton()->accumulate_input_event(ev);
}
}
@@ -560,11 +567,11 @@ void DisplayServerAndroid::process_touch(int p_what, int p_pointer, const Vector
ev->set_index(touch[i].id);
ev->set_pressed(true);
ev->set_position(touch[i].pos);
- Input::get_singleton()->parse_input_event(ev);
+ Input::get_singleton()->accumulate_input_event(ev);
}
} break;
- case 1: { //motion
+ case AMOTION_EVENT_ACTION_MOVE: { //motion
ERR_FAIL_COND(touch.size() != p_points.size());
for (int i = 0; i < touch.size(); i++) {
@@ -586,12 +593,13 @@ void DisplayServerAndroid::process_touch(int p_what, int p_pointer, const Vector
ev->set_index(touch[i].id);
ev->set_position(p_points[idx].pos);
ev->set_relative(p_points[idx].pos - touch[i].pos);
- Input::get_singleton()->parse_input_event(ev);
+ Input::get_singleton()->accumulate_input_event(ev);
touch.write[i].pos = p_points[idx].pos;
}
} break;
- case 2: { //release
+ case AMOTION_EVENT_ACTION_CANCEL:
+ case AMOTION_EVENT_ACTION_UP: { //release
if (touch.size()) {
//end all if exist
for (int i = 0; i < touch.size(); i++) {
@@ -600,12 +608,12 @@ void DisplayServerAndroid::process_touch(int p_what, int p_pointer, const Vector
ev->set_index(touch[i].id);
ev->set_pressed(false);
ev->set_position(touch[i].pos);
- Input::get_singleton()->parse_input_event(ev);
+ Input::get_singleton()->accumulate_input_event(ev);
}
touch.clear();
}
} break;
- case 3: { // add touch
+ case AMOTION_EVENT_ACTION_POINTER_DOWN: { // add touch
for (int i = 0; i < p_points.size(); i++) {
if (p_points[i].id == p_pointer) {
TouchPos tp = p_points[i];
@@ -617,13 +625,13 @@ void DisplayServerAndroid::process_touch(int p_what, int p_pointer, const Vector
ev->set_index(tp.id);
ev->set_pressed(true);
ev->set_position(tp.pos);
- Input::get_singleton()->parse_input_event(ev);
+ Input::get_singleton()->accumulate_input_event(ev);
break;
}
}
} break;
- case 4: { // remove touch
+ case AMOTION_EVENT_ACTION_POINTER_UP: { // remove touch
for (int i = 0; i < touch.size(); i++) {
if (touch[i].id == p_pointer) {
Ref<InputEventScreenTouch> ev;
@@ -631,7 +639,7 @@ void DisplayServerAndroid::process_touch(int p_what, int p_pointer, const Vector
ev->set_index(touch[i].id);
ev->set_pressed(false);
ev->set_position(touch[i].pos);
- Input::get_singleton()->parse_input_event(ev);
+ Input::get_singleton()->accumulate_input_event(ev);
touch.remove(i);
break;
@@ -644,30 +652,116 @@ void DisplayServerAndroid::process_touch(int p_what, int p_pointer, const Vector
void DisplayServerAndroid::process_hover(int p_type, Point2 p_pos) {
// https://developer.android.com/reference/android/view/MotionEvent.html#ACTION_HOVER_ENTER
switch (p_type) {
- case 7: // hover move
- case 9: // hover enter
- case 10: { // hover exit
+ case AMOTION_EVENT_ACTION_HOVER_MOVE: // hover move
+ case AMOTION_EVENT_ACTION_HOVER_ENTER: // hover enter
+ case AMOTION_EVENT_ACTION_HOVER_EXIT: { // hover exit
Ref<InputEventMouseMotion> ev;
ev.instance();
_set_key_modifier_state(ev);
ev->set_position(p_pos);
ev->set_global_position(p_pos);
ev->set_relative(p_pos - hover_prev_pos);
- Input::get_singleton()->parse_input_event(ev);
+ Input::get_singleton()->accumulate_input_event(ev);
hover_prev_pos = p_pos;
} break;
}
}
-void DisplayServerAndroid::process_double_tap(Point2 p_pos) {
+void DisplayServerAndroid::process_mouse_event(int event_action, int event_android_buttons_mask, Point2 event_pos, float event_vertical_factor, float event_horizontal_factor) {
+ int event_buttons_mask = _android_button_mask_to_godot_button_mask(event_android_buttons_mask);
+ switch (event_action) {
+ case AMOTION_EVENT_ACTION_BUTTON_PRESS:
+ case AMOTION_EVENT_ACTION_BUTTON_RELEASE: {
+ Ref<InputEventMouseButton> ev;
+ ev.instance();
+ _set_key_modifier_state(ev);
+ ev->set_position(event_pos);
+ ev->set_global_position(event_pos);
+ ev->set_pressed(event_action == AMOTION_EVENT_ACTION_BUTTON_PRESS);
+ int changed_button_mask = buttons_state ^ event_buttons_mask;
+
+ buttons_state = event_buttons_mask;
+
+ ev->set_button_index(_button_index_from_mask(changed_button_mask));
+ ev->set_button_mask(event_buttons_mask);
+ Input::get_singleton()->accumulate_input_event(ev);
+ } break;
+
+ case AMOTION_EVENT_ACTION_MOVE: {
+ Ref<InputEventMouseMotion> ev;
+ ev.instance();
+ _set_key_modifier_state(ev);
+ ev->set_position(event_pos);
+ ev->set_global_position(event_pos);
+ ev->set_relative(event_pos - hover_prev_pos);
+ ev->set_button_mask(event_buttons_mask);
+ Input::get_singleton()->accumulate_input_event(ev);
+ hover_prev_pos = event_pos;
+ } break;
+ case AMOTION_EVENT_ACTION_SCROLL: {
+ Ref<InputEventMouseButton> ev;
+ ev.instance();
+ ev->set_position(event_pos);
+ ev->set_global_position(event_pos);
+ ev->set_pressed(true);
+ buttons_state = event_buttons_mask;
+ if (event_vertical_factor > 0) {
+ _wheel_button_click(event_buttons_mask, ev, BUTTON_WHEEL_UP, event_vertical_factor);
+ } else if (event_vertical_factor < 0) {
+ _wheel_button_click(event_buttons_mask, ev, BUTTON_WHEEL_DOWN, -event_vertical_factor);
+ }
+
+ if (event_horizontal_factor > 0) {
+ _wheel_button_click(event_buttons_mask, ev, BUTTON_WHEEL_RIGHT, event_horizontal_factor);
+ } else if (event_horizontal_factor < 0) {
+ _wheel_button_click(event_buttons_mask, ev, BUTTON_WHEEL_LEFT, -event_horizontal_factor);
+ }
+ } break;
+ }
+}
+
+void DisplayServerAndroid::_wheel_button_click(int event_buttons_mask, const Ref<InputEventMouseButton> &ev, int wheel_button, float factor) {
+ Ref<InputEventMouseButton> evd = ev->duplicate();
+ _set_key_modifier_state(evd);
+ evd->set_button_index(wheel_button);
+ evd->set_button_mask(event_buttons_mask ^ (1 << (wheel_button - 1)));
+ evd->set_factor(factor);
+ Input::get_singleton()->accumulate_input_event(evd);
+ Ref<InputEventMouseButton> evdd = evd->duplicate();
+ evdd->set_pressed(false);
+ evdd->set_button_mask(event_buttons_mask);
+ Input::get_singleton()->accumulate_input_event(evdd);
+}
+
+void DisplayServerAndroid::process_double_tap(int event_android_button_mask, Point2 p_pos) {
+ int event_button_mask = _android_button_mask_to_godot_button_mask(event_android_button_mask);
Ref<InputEventMouseButton> ev;
ev.instance();
_set_key_modifier_state(ev);
ev->set_position(p_pos);
ev->set_global_position(p_pos);
- ev->set_pressed(false);
+ ev->set_pressed(event_button_mask != 0);
+ ev->set_button_index(_button_index_from_mask(event_button_mask));
+ ev->set_button_mask(event_button_mask);
ev->set_doubleclick(true);
- Input::get_singleton()->parse_input_event(ev);
+ Input::get_singleton()->accumulate_input_event(ev);
+}
+
+int DisplayServerAndroid::_button_index_from_mask(int button_mask) {
+ switch (button_mask) {
+ case BUTTON_MASK_LEFT:
+ return BUTTON_LEFT;
+ case BUTTON_MASK_RIGHT:
+ return BUTTON_RIGHT;
+ case BUTTON_MASK_MIDDLE:
+ return BUTTON_MIDDLE;
+ case BUTTON_MASK_XBUTTON1:
+ return BUTTON_XBUTTON1;
+ case BUTTON_MASK_XBUTTON2:
+ return BUTTON_XBUTTON2;
+ default:
+ return 0;
+ }
}
void DisplayServerAndroid::process_scroll(Point2 p_pos) {
@@ -676,7 +770,7 @@ void DisplayServerAndroid::process_scroll(Point2 p_pos) {
_set_key_modifier_state(ev);
ev->set_position(p_pos);
ev->set_delta(p_pos - scroll_prev_pos);
- Input::get_singleton()->parse_input_event(ev);
+ Input::get_singleton()->accumulate_input_event(ev);
scroll_prev_pos = p_pos;
}
@@ -695,3 +789,32 @@ void DisplayServerAndroid::process_magnetometer(const Vector3 &p_magnetometer) {
void DisplayServerAndroid::process_gyroscope(const Vector3 &p_gyroscope) {
Input::get_singleton()->set_gyroscope(p_gyroscope);
}
+
+Point2i DisplayServerAndroid::mouse_get_position() const {
+ return hover_prev_pos;
+}
+
+int DisplayServerAndroid::mouse_get_button_state() const {
+ return buttons_state;
+}
+
+int DisplayServerAndroid::_android_button_mask_to_godot_button_mask(int android_button_mask) {
+ int godot_button_mask = 0;
+ if (android_button_mask & AMOTION_EVENT_BUTTON_PRIMARY) {
+ godot_button_mask |= BUTTON_MASK_LEFT;
+ }
+ if (android_button_mask & AMOTION_EVENT_BUTTON_SECONDARY) {
+ godot_button_mask |= BUTTON_MASK_RIGHT;
+ }
+ if (android_button_mask & AMOTION_EVENT_BUTTON_TERTIARY) {
+ godot_button_mask |= BUTTON_MASK_MIDDLE;
+ }
+ if (android_button_mask & AMOTION_EVENT_BUTTON_BACK) {
+ godot_button_mask |= BUTTON_MASK_XBUTTON1;
+ }
+ if (android_button_mask & AMOTION_EVENT_BUTTON_SECONDARY) {
+ godot_button_mask |= BUTTON_MASK_XBUTTON2;
+ }
+
+ return godot_button_mask;
+}
diff --git a/platform/android/display_server_android.h b/platform/android/display_server_android.h
index 5cdc69ee83..aa5a2c1185 100644
--- a/platform/android/display_server_android.h
+++ b/platform/android/display_server_android.h
@@ -68,6 +68,8 @@ private:
bool control_mem = false;
bool meta_mem = false;
+ int buttons_state;
+
bool keep_screen_on;
Vector<TouchPos> touch;
@@ -91,6 +93,12 @@ private:
void _set_key_modifier_state(Ref<InputEventWithModifiers> ev);
+ static int _button_index_from_mask(int button_mask);
+
+ static int _android_button_mask_to_godot_button_mask(int android_button_mask);
+
+ void _wheel_button_click(int event_buttons_mask, const Ref<InputEventMouseButton> &ev, int wheel_button, float factor);
+
public:
static DisplayServerAndroid *get_singleton();
@@ -162,9 +170,10 @@ public:
void process_gravity(const Vector3 &p_gravity);
void process_magnetometer(const Vector3 &p_magnetometer);
void process_gyroscope(const Vector3 &p_gyroscope);
- void process_touch(int p_what, int p_pointer, const Vector<TouchPos> &p_points);
+ void process_touch(int p_event, int p_pointer, const Vector<TouchPos> &p_points);
void process_hover(int p_type, Point2 p_pos);
- void process_double_tap(Point2 p_pos);
+ void process_mouse_event(int event_action, int event_android_buttons_mask, Point2 event_pos, float event_vertical_factor = 0, float event_horizontal_factor = 0);
+ void process_double_tap(int event_android_button_mask, Point2 p_pos);
void process_scroll(Point2 p_pos);
void process_joy_event(JoypadEvent p_event);
void process_key_event(int p_keycode, int p_scancode, int p_unicode_char, bool p_pressed);
@@ -175,6 +184,9 @@ public:
void reset_window();
+ virtual Point2i mouse_get_position() const;
+ virtual int mouse_get_button_state() const;
+
DisplayServerAndroid(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error);
~DisplayServerAndroid();
};
diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp
index 5e6cc3e4e2..53b43ae0e8 100644
--- a/platform/android/export/export.cpp
+++ b/platform/android/export/export.cpp
@@ -29,15 +29,14 @@
/*************************************************************************/
#include "export.h"
-#include "gradle_export_util.h"
+#include "core/config/project_settings.h"
#include "core/io/image_loader.h"
#include "core/io/marshalls.h"
#include "core/io/zip_io.h"
#include "core/os/dir_access.h"
#include "core/os/file_access.h"
#include "core/os/os.h"
-#include "core/project_settings.h"
#include "core/version.h"
#include "drivers/png/png_driver_common.h"
#include "editor/editor_export.h"
@@ -592,7 +591,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
zipfi.tmz_date.tm_hour = time.hour;
zipfi.tmz_date.tm_mday = date.day;
zipfi.tmz_date.tm_min = time.min;
- zipfi.tmz_date.tm_mon = date.month;
+ zipfi.tmz_date.tm_mon = date.month - 1; // tm_mon is zero indexed
zipfi.tmz_date.tm_sec = time.sec;
zipfi.tmz_date.tm_year = date.year;
zipfi.dosDate = 0;
@@ -827,7 +826,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
int version_code = p_preset->get("version/code");
String package_name = p_preset->get("package/unique_name");
- int orientation = p_preset->get("screen/orientation");
+ const int screen_orientation = _get_android_orientation_value(_get_screen_orientation());
bool screen_support_small = p_preset->get("screen/support_small");
bool screen_support_normal = p_preset->get("screen/support_normal");
@@ -937,7 +936,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
}
if (tname == "activity" && attrname == "screenOrientation") {
- encode_uint32(orientation == 0 ? 0 : 1, &p_manifest.write[iofs + 16]);
+ encode_uint32(screen_orientation, &p_manifest.write[iofs + 16]);
}
if (tname == "supports-screens") {
@@ -1636,7 +1635,6 @@ public:
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "package/name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Game Name [default if blank]"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "package/signed"), true));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "screen/immersive_mode"), true));
- r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "screen/orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait"), 0));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "screen/support_small"), true));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "screen/support_normal"), true));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "screen/support_large"), true));
@@ -1645,10 +1643,10 @@ public:
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_icon_option, PROPERTY_HINT_FILE, "*.png"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_adaptive_icon_foreground_option, PROPERTY_HINT_FILE, "*.png"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, launcher_adaptive_icon_background_option, PROPERTY_HINT_FILE, "*.png"), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "keystore/debug", PROPERTY_HINT_GLOBAL_FILE, "*.keystore"), ""));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "keystore/debug", PROPERTY_HINT_GLOBAL_FILE, "*.keystore,*.jks"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "keystore/debug_user"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "keystore/debug_password"), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "keystore/release", PROPERTY_HINT_GLOBAL_FILE, "*.keystore"), ""));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "keystore/release", PROPERTY_HINT_GLOBAL_FILE, "*.keystore,*.jks"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "keystore/release_user"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "keystore/release_password"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "apk_expansion/enable"), false));
@@ -1968,9 +1966,21 @@ public:
valid = false;
} else {
Error errn;
+ // Check for the platform-tools directory.
DirAccessRef da = DirAccess::open(sdk_path.plus_file("platform-tools"), &errn);
if (errn != OK) {
- err += TTR("Invalid Android SDK path for custom build in Editor Settings.") + "\n";
+ err += TTR("Invalid Android SDK path for custom build in Editor Settings.");
+ err += TTR("Missing 'platform-tools' directory!");
+ err += "\n";
+ valid = false;
+ }
+
+ // Check for the build-tools directory.
+ DirAccessRef build_tools_da = DirAccess::open(sdk_path.plus_file("build-tools"), &errn);
+ if (errn != OK) {
+ err += TTR("Invalid Android SDK path for custom build in Editor Settings.");
+ err += TTR("Missing 'build-tools' directory!");
+ err += "\n";
valid = false;
}
}
@@ -2159,14 +2169,16 @@ public:
}
}
- Error sign_apk(const Ref<EditorExportPreset> &p_preset, bool p_debug, String apk_path, EditorProgress ep) {
+ Error sign_apk(const Ref<EditorExportPreset> &p_preset, bool p_debug, String export_path, EditorProgress ep) {
+ int export_format = int(p_preset->get("custom_template/export_format"));
+ String export_label = export_format == 1 ? "AAB" : "APK";
String release_keystore = p_preset->get("keystore/release");
String release_username = p_preset->get("keystore/release_user");
String release_password = p_preset->get("keystore/release_password");
String jarsigner = EditorSettings::get_singleton()->get("export/android/jarsigner");
if (!FileAccess::exists(jarsigner)) {
- EditorNode::add_io_error("'jarsigner' could not be found.\nPlease supply a path in the Editor Settings.\nThe resulting APK is unsigned.");
+ EditorNode::add_io_error("'jarsigner' could not be found.\nPlease supply a path in the Editor Settings.\nThe resulting " + export_label + " is unsigned.");
return OK;
}
@@ -2184,7 +2196,7 @@ public:
user = EditorSettings::get_singleton()->get("export/android/debug_keystore_user");
}
- if (ep.step("Signing debug APK...", 103)) {
+ if (ep.step("Signing debug " + export_label + "...", 103)) {
return ERR_SKIP;
}
@@ -2193,7 +2205,7 @@ public:
password = release_password;
user = release_username;
- if (ep.step("Signing release APK...", 103)) {
+ if (ep.step("Signing release " + export_label + "...", 103)) {
return ERR_SKIP;
}
}
@@ -2218,7 +2230,7 @@ public:
args.push_back(keystore);
args.push_back("-storepass");
args.push_back(password);
- args.push_back(apk_path);
+ args.push_back(export_path);
args.push_back(user);
int retval;
OS::get_singleton()->execute(jarsigner, args, true, NULL, NULL, &retval);
@@ -2227,7 +2239,7 @@ public:
return ERR_CANT_CREATE;
}
- if (ep.step("Verifying APK...", 104)) {
+ if (ep.step("Verifying " + export_label + "...", 104)) {
return ERR_SKIP;
}
@@ -2235,17 +2247,78 @@ public:
args.push_back("-verify");
args.push_back("-keystore");
args.push_back(keystore);
- args.push_back(apk_path);
+ args.push_back(export_path);
args.push_back("-verbose");
OS::get_singleton()->execute(jarsigner, args, true, NULL, NULL, &retval);
if (retval) {
- EditorNode::add_io_error("'jarsigner' verification of APK failed. Make sure to use a jarsigner from OpenJDK 8.");
+ EditorNode::add_io_error("'jarsigner' verification of " + export_label + " failed. Make sure to use a jarsigner from OpenJDK 8.");
return ERR_CANT_CREATE;
}
return OK;
}
+ void _clear_assets_directory() {
+ DirAccessRef da_res = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+ if (da_res->dir_exists("res://android/build/assets")) {
+ DirAccessRef da_assets = DirAccess::open("res://android/build/assets");
+ da_assets->erase_contents_recursive();
+ da_res->remove("res://android/build/assets");
+ }
+ }
+
+ Error _zip_align_project(const String &sdk_path, const String &unaligned_file_path, const String &aligned_file_path) {
+ // Look for the zipalign tool.
+ String zipalign_command;
+ Error errn;
+ String build_tools_dir = sdk_path.plus_file("build-tools");
+ DirAccessRef da = DirAccess::open(build_tools_dir, &errn);
+ if (errn != OK) {
+ return errn;
+ }
+
+ // There are additional versions directories we need to go through.
+ da->list_dir_begin();
+ String sub_dir = da->get_next();
+ while (!sub_dir.empty()) {
+ if (!sub_dir.begins_with(".") && da->current_is_dir()) {
+ // Check if the tool is here.
+ String tool_path = build_tools_dir.plus_file(sub_dir).plus_file("zipalign");
+ if (FileAccess::exists(tool_path)) {
+ zipalign_command = tool_path;
+ break;
+ }
+ }
+ sub_dir = da->get_next();
+ }
+ da->list_dir_end();
+
+ if (zipalign_command.empty()) {
+ EditorNode::get_singleton()->show_warning(TTR("Unable to find the zipalign tool."));
+ return ERR_CANT_CREATE;
+ }
+
+ List<String> zipalign_args;
+ zipalign_args.push_back("-f");
+ zipalign_args.push_back("-v");
+ zipalign_args.push_back("4");
+ zipalign_args.push_back(unaligned_file_path); // source file
+ zipalign_args.push_back(aligned_file_path); // destination file
+
+ int result = EditorNode::get_singleton()->execute_and_show_output(TTR("Aligning APK..."), zipalign_command, zipalign_args);
+ if (result != 0) {
+ EditorNode::get_singleton()->show_warning(TTR("Unable to complete APK alignment."));
+ return ERR_CANT_CREATE;
+ }
+
+ // Delete the unaligned path.
+ errn = da->remove(unaligned_file_path);
+ if (errn != OK) {
+ EditorNode::get_singleton()->show_warning(TTR("Unable to delete unaligned APK."));
+ }
+ return OK;
+ }
+
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override {
ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
@@ -2297,15 +2370,18 @@ public:
if (use_custom_build) {
//test that installed build version is alright
- FileAccessRef f = FileAccess::open("res://android/.build_version", FileAccess::READ);
- if (!f) {
- EditorNode::get_singleton()->show_warning(TTR("Trying to build from a custom built template, but no version info for it exists. Please reinstall from the 'Project' menu."));
- return ERR_UNCONFIGURED;
- }
- String version = f->get_line().strip_edges();
- if (version != VERSION_FULL_CONFIG) {
- EditorNode::get_singleton()->show_warning(vformat(TTR("Android build version mismatch:\n Template installed: %s\n Godot Version: %s\nPlease reinstall Android build template from 'Project' menu."), version, VERSION_FULL_CONFIG));
- return ERR_UNCONFIGURED;
+ {
+ FileAccessRef f = FileAccess::open("res://android/.build_version", FileAccess::READ);
+ if (!f) {
+ EditorNode::get_singleton()->show_warning(TTR("Trying to build from a custom built template, but no version info for it exists. Please reinstall from the 'Project' menu."));
+ return ERR_UNCONFIGURED;
+ }
+ String version = f->get_line().strip_edges();
+ f->close();
+ if (version != VERSION_FULL_CONFIG) {
+ EditorNode::get_singleton()->show_warning(vformat(TTR("Android build version mismatch:\n Template installed: %s\n Godot Version: %s\nPlease reinstall Android build template from 'Project' menu."), version, VERSION_FULL_CONFIG));
+ return ERR_UNCONFIGURED;
+ }
}
String sdk_path = EDITOR_GET("export/android/custom_build_sdk_path");
ERR_FAIL_COND_V_MSG(sdk_path == "", ERR_UNCONFIGURED, "Android SDK path must be configured in Editor Settings at 'export/android/custom_build_sdk_path'.");
@@ -2322,13 +2398,8 @@ public:
_write_tmp_manifest(p_preset, p_give_internet, p_debug);
//stores all the project files inside the Gradle project directory. Also includes all ABIs
+ _clear_assets_directory();
if (!apk_expansion) {
- DirAccess *da_res = DirAccess::create(DirAccess::ACCESS_RESOURCES);
- if (da_res->dir_exists("res://android/build/assets")) {
- DirAccess *da_assets = DirAccess::open("res://android/build/assets");
- da_assets->erase_contents_recursive();
- da_res->remove("res://android/build/assets");
- }
err = export_project_files(p_preset, rename_and_store_file_in_gradle_project, NULL, ignore_so_file);
if (err != OK) {
EditorNode::add_io_error("Could not export project files to gradle project\n");
@@ -2416,7 +2487,16 @@ public:
copy_args.push_back(build_path); // start directory.
String export_filename = p_path.get_file();
+ if (export_format == 0) {
+ // By default, generated apk are not aligned.
+ export_filename += ".unaligned";
+ }
String export_path = p_path.get_base_dir();
+ if (export_path.is_rel_path()) {
+ export_path = OS::get_singleton()->get_resource_dir().plus_file(export_path);
+ }
+ export_path = ProjectSettings::get_singleton()->globalize_path(export_path).simplify_path();
+ String export_file_path = export_path.plus_file(export_filename);
copy_args.push_back("-Pexport_path=file:" + export_path);
copy_args.push_back("-Pexport_filename=" + export_filename);
@@ -2427,11 +2507,20 @@ public:
return ERR_CANT_CREATE;
}
if (_signed) {
- err = sign_apk(p_preset, p_debug, p_path, ep);
+ err = sign_apk(p_preset, p_debug, export_file_path, ep);
if (err != OK) {
return err;
}
}
+
+ if (export_format == 0) {
+ // Perform zip alignment
+ err = _zip_align_project(sdk_path, export_file_path, export_path.plus_file(p_path.get_file()));
+ if (err != OK) {
+ return err;
+ }
+ }
+
return OK;
}
// This is the start of the Legacy build system
@@ -2778,7 +2867,7 @@ void register_android_exporter() {
EDITOR_DEF("export/android/jarsigner", "");
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/android/jarsigner", PROPERTY_HINT_GLOBAL_FILE, exe_ext));
EDITOR_DEF("export/android/debug_keystore", "");
- EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/android/debug_keystore", PROPERTY_HINT_GLOBAL_FILE, "*.keystore"));
+ EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/android/debug_keystore", PROPERTY_HINT_GLOBAL_FILE, "*.keystore,*.jks"));
EDITOR_DEF("export/android/debug_keystore_user", "androiddebugkey");
EDITOR_DEF("export/android/debug_keystore_pass", "android");
EDITOR_DEF("export/android/force_system_user", false);
diff --git a/platform/android/export/gradle_export_util.h b/platform/android/export/gradle_export_util.h
index 95f870bc35..3bc3651712 100644
--- a/platform/android/export/gradle_export_util.h
+++ b/platform/android/export/gradle_export_util.h
@@ -44,6 +44,67 @@ const String godot_project_name_xml_string = R"(<?xml version="1.0" encoding="ut
</resources>
)";
+DisplayServer::ScreenOrientation _get_screen_orientation() {
+ String orientation_settings = ProjectSettings::get_singleton()->get("display/window/handheld/orientation");
+ DisplayServer::ScreenOrientation screen_orientation;
+ if (orientation_settings == "portrait")
+ screen_orientation = DisplayServer::SCREEN_PORTRAIT;
+ else if (orientation_settings == "reverse_landscape")
+ screen_orientation = DisplayServer::SCREEN_REVERSE_LANDSCAPE;
+ else if (orientation_settings == "reverse_portrait")
+ screen_orientation = DisplayServer::SCREEN_REVERSE_PORTRAIT;
+ else if (orientation_settings == "sensor_landscape")
+ screen_orientation = DisplayServer::SCREEN_SENSOR_LANDSCAPE;
+ else if (orientation_settings == "sensor_portrait")
+ screen_orientation = DisplayServer::SCREEN_SENSOR_PORTRAIT;
+ else if (orientation_settings == "sensor")
+ screen_orientation = DisplayServer::SCREEN_SENSOR;
+ else
+ screen_orientation = DisplayServer::SCREEN_LANDSCAPE;
+
+ return screen_orientation;
+}
+
+int _get_android_orientation_value(DisplayServer::ScreenOrientation screen_orientation) {
+ switch (screen_orientation) {
+ case DisplayServer::SCREEN_PORTRAIT:
+ return 1;
+ case DisplayServer::SCREEN_REVERSE_LANDSCAPE:
+ return 8;
+ case DisplayServer::SCREEN_REVERSE_PORTRAIT:
+ return 9;
+ case DisplayServer::SCREEN_SENSOR_LANDSCAPE:
+ return 11;
+ case DisplayServer::SCREEN_SENSOR_PORTRAIT:
+ return 12;
+ case DisplayServer::SCREEN_SENSOR:
+ return 13;
+ case DisplayServer::SCREEN_LANDSCAPE:
+ default:
+ return 0;
+ }
+}
+
+String _get_android_orientation_label(DisplayServer::ScreenOrientation screen_orientation) {
+ switch (screen_orientation) {
+ case DisplayServer::SCREEN_PORTRAIT:
+ return "portrait";
+ case DisplayServer::SCREEN_REVERSE_LANDSCAPE:
+ return "reverseLandscape";
+ case DisplayServer::SCREEN_REVERSE_PORTRAIT:
+ return "reversePortrait";
+ case DisplayServer::SCREEN_SENSOR_LANDSCAPE:
+ return "userLandscape";
+ case DisplayServer::SCREEN_SENSOR_PORTRAIT:
+ return "userPortrait";
+ case DisplayServer::SCREEN_SENSOR:
+ return "fullUser";
+ case DisplayServer::SCREEN_LANDSCAPE:
+ default:
+ return "landscape";
+ }
+}
+
// Utility method used to create a directory.
Error create_directory(const String &p_dir) {
if (!DirAccess::exists(p_dir)) {
@@ -209,7 +270,7 @@ String _get_plugins_tag(const String &plugins_names) {
String _get_activity_tag(const Ref<EditorExportPreset> &p_preset) {
bool uses_xr = (int)(p_preset->get("xr_features/xr_mode")) == 1;
- String orientation = (int)(p_preset->get("screen/orientation")) == 1 ? "portrait" : "landscape";
+ String orientation = _get_android_orientation_label(_get_screen_orientation());
String manifest_activity_text = vformat(
" <activity android:name=\"com.godot.game.GodotApp\" "
"tools:replace=\"android:screenOrientation\" "
diff --git a/platform/android/file_access_android.cpp b/platform/android/file_access_android.cpp
index 05d5fb576d..11faeff3e8 100644
--- a/platform/android/file_access_android.cpp
+++ b/platform/android/file_access_android.cpp
@@ -29,7 +29,7 @@
/*************************************************************************/
#include "file_access_android.h"
-#include "core/print_string.h"
+#include "core/string/print_string.h"
AAssetManager *FileAccessAndroid::asset_manager = nullptr;
diff --git a/platform/android/java/app/build.gradle b/platform/android/java/app/build.gradle
index ceacfec9e1..6de1d2dd30 100644
--- a/platform/android/java/app/build.gradle
+++ b/platform/android/java/app/build.gradle
@@ -70,8 +70,8 @@ android {
buildToolsVersion versions.buildTools
compileOptions {
- sourceCompatibility 1.8
- targetCompatibility 1.8
+ sourceCompatibility versions.javaVersion
+ targetCompatibility versions.javaVersion
}
defaultConfig {
diff --git a/platform/android/java/app/config.gradle b/platform/android/java/app/config.gradle
index d1176e6196..e6c45b73a7 100644
--- a/platform/android/java/app/config.gradle
+++ b/platform/android/java/app/config.gradle
@@ -1,12 +1,13 @@
ext.versions = [
- androidGradlePlugin: '3.5.3',
+ androidGradlePlugin: '4.1.0',
compileSdk : 29,
minSdk : 18,
targetSdk : 29,
- buildTools : '29.0.3',
+ buildTools : '30.0.1',
supportCoreUtils : '1.0.0',
- kotlinVersion : '1.3.61',
- v4Support : '1.0.0'
+ kotlinVersion : '1.4.10',
+ v4Support : '1.0.0',
+ javaVersion : 1.8
]
diff --git a/platform/android/java/app/res/values/themes.xml b/platform/android/java/app/res/values/themes.xml
index 26912538d3..99f723f5ba 100644
--- a/platform/android/java/app/res/values/themes.xml
+++ b/platform/android/java/app/res/values/themes.xml
@@ -5,5 +5,6 @@
<style name="GodotAppSplashTheme" parent="@style/GodotAppMainTheme">
<item name="android:windowBackground">@drawable/splash_drawable</item>
+ <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
</resources>
diff --git a/platform/android/java/build.gradle b/platform/android/java/build.gradle
index 821a4dc584..73c136ed0e 100644
--- a/platform/android/java/build.gradle
+++ b/platform/android/java/build.gradle
@@ -22,8 +22,6 @@ allprojects {
}
ext {
- sconsExt = org.gradle.internal.os.OperatingSystem.current().isWindows() ? ".bat" : ""
-
supportedAbis = ["armv7", "arm64v8", "x86", "x86_64"]
supportedTargets = ["release", "debug"]
diff --git a/platform/android/java/gradle.properties b/platform/android/java/gradle.properties
index e14cd5ba5c..2dc069ad2f 100644
--- a/platform/android/java/gradle.properties
+++ b/platform/android/java/gradle.properties
@@ -18,3 +18,5 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
+
+org.gradle.warning.mode=all
diff --git a/platform/android/java/gradle/wrapper/gradle-wrapper.properties b/platform/android/java/gradle/wrapper/gradle-wrapper.properties
index f56b0f6a5e..a7d8a0f310 100644
--- a/platform/android/java/gradle/wrapper/gradle-wrapper.properties
+++ b/platform/android/java/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
diff --git a/platform/android/java/lib/build.gradle b/platform/android/java/lib/build.gradle
index 19eee5a315..89ce3d15e6 100644
--- a/platform/android/java/lib/build.gradle
+++ b/platform/android/java/lib/build.gradle
@@ -18,6 +18,11 @@ android {
targetSdkVersion versions.targetSdk
}
+ compileOptions {
+ sourceCompatibility versions.javaVersion
+ targetCompatibility versions.javaVersion
+ }
+
lintOptions {
abortOnError false
disable 'MissingTranslation', 'UnusedResources'
@@ -50,15 +55,6 @@ android {
def buildType = variant.buildType.name.capitalize()
- def taskPrefix = ""
- if (project.path != ":") {
- taskPrefix = project.path + ":"
- }
-
- // Disable the externalNativeBuild* task as it would cause build failures since the cmake build
- // files is only setup for editing support.
- gradle.startParameter.excludedTaskNames += taskPrefix + "externalNativeBuild" + buildType
-
def releaseTarget = buildType.toLowerCase()
if (releaseTarget == null || releaseTarget == "") {
throw new GradleException("Invalid build type: " + buildType)
@@ -68,20 +64,46 @@ android {
throw new GradleException("Invalid default abi: " + defaultAbi)
}
+ // Find scons' executable path
+ File sconsExecutableFile = null
+ def sconsName = "scons"
+ def sconsExts = (org.gradle.internal.os.OperatingSystem.current().isWindows()
+ ? [".bat", ".exe"]
+ : [""])
+ logger.lifecycle("Looking for $sconsName executable path")
+ for (ext in sconsExts) {
+ String sconsNameExt = sconsName + ext
+ logger.lifecycle("Checking $sconsNameExt")
+
+ sconsExecutableFile = org.gradle.internal.os.OperatingSystem.current().findInPath(sconsNameExt)
+ if (sconsExecutableFile != null) {
+ // We're done!
+ break
+ }
+
+ // Check all the options in path
+ List<File> allOptions = org.gradle.internal.os.OperatingSystem.current().findAllInPath(sconsNameExt)
+ if (!allOptions.isEmpty()) {
+ // Pick the first option and we're done!
+ sconsExecutableFile = allOptions.get(0)
+ break
+ }
+ }
+
+ if (sconsExecutableFile == null) {
+ throw new GradleException("Unable to find executable path for the '$sconsName' command.")
+ } else {
+ logger.lifecycle("Found executable path for $sconsName: ${sconsExecutableFile.absolutePath}")
+ }
+
// Creating gradle task to generate the native libraries for the default abi.
def taskName = getSconsTaskName(buildType)
tasks.create(name: taskName, type: Exec) {
- executable "scons" + sconsExt
+ executable sconsExecutableFile.absolutePath
args "--directory=${pathToRootDir}", "platform=android", "target=${releaseTarget}", "android_arch=${defaultAbi}", "-j" + Runtime.runtime.availableProcessors()
}
// Schedule the tasks so the generated libs are present before the aar file is packaged.
tasks["merge${buildType}JniLibFolders"].dependsOn taskName
}
-
- externalNativeBuild {
- cmake {
- path "CMakeLists.txt"
- }
- }
}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.java b/platform/android/java/lib/src/org/godotengine/godot/Godot.java
index 524f32bf5e..6cf340c418 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/Godot.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.java
@@ -70,6 +70,7 @@ import android.os.VibrationEffect;
import android.os.Vibrator;
import android.provider.Settings.Secure;
import android.view.Display;
+import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@@ -854,63 +855,6 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
}
}
- public boolean gotTouchEvent(final MotionEvent event) {
- final int evcount = event.getPointerCount();
- if (evcount == 0)
- return true;
-
- if (mRenderView != null) {
- final int[] arr = new int[event.getPointerCount() * 3];
-
- for (int i = 0; i < event.getPointerCount(); i++) {
- arr[i * 3 + 0] = (int)event.getPointerId(i);
- arr[i * 3 + 1] = (int)event.getX(i);
- arr[i * 3 + 2] = (int)event.getY(i);
- }
- final int pointer_idx = event.getPointerId(event.getActionIndex());
-
- //System.out.printf("gaction: %d\n",event.getAction());
- final int action = event.getAction() & MotionEvent.ACTION_MASK;
- mRenderView.queueOnRenderThread(new Runnable() {
- @Override
- public void run() {
- switch (action) {
- case MotionEvent.ACTION_DOWN: {
- GodotLib.touch(0, 0, evcount, arr);
- //System.out.printf("action down at: %f,%f\n", event.getX(),event.getY());
- } break;
- case MotionEvent.ACTION_MOVE: {
- GodotLib.touch(1, 0, evcount, arr);
- /*
- for(int i=0;i<event.getPointerCount();i++) {
- System.out.printf("%d - moved to: %f,%f\n",i, event.getX(i),event.getY(i));
- }
- */
- } break;
- case MotionEvent.ACTION_POINTER_UP: {
- GodotLib.touch(4, pointer_idx, evcount, arr);
- //System.out.printf("%d - s.up at: %f,%f\n",pointer_idx, event.getX(pointer_idx),event.getY(pointer_idx));
- } break;
- case MotionEvent.ACTION_POINTER_DOWN: {
- GodotLib.touch(3, pointer_idx, evcount, arr);
- //System.out.printf("%d - s.down at: %f,%f\n",pointer_idx, event.getX(pointer_idx),event.getY(pointer_idx));
- } break;
- case MotionEvent.ACTION_CANCEL:
- case MotionEvent.ACTION_UP: {
- GodotLib.touch(2, 0, evcount, arr);
- /*
- for(int i=0;i<event.getPointerCount();i++) {
- System.out.printf("%d - up! %f,%f\n",i, event.getX(i),event.getY(i));
- }
- */
- } break;
- }
- }
- });
- }
- return true;
- }
-
public boolean onKeyMultiple(final int inKeyCode, int repeatCount, KeyEvent event) {
String s = event.getCharacters();
if (s == null || s.length() == 0)
diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotGLRenderView.java b/platform/android/java/lib/src/org/godotengine/godot/GodotGLRenderView.java
index d169f46599..d731e080c4 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotGLRenderView.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotGLRenderView.java
@@ -29,7 +29,6 @@
/*************************************************************************/
package org.godotengine.godot;
-
import org.godotengine.godot.input.GodotGestureHandler;
import org.godotengine.godot.input.GodotInputHandler;
import org.godotengine.godot.utils.GLUtils;
@@ -127,7 +126,7 @@ public class GodotGLRenderView extends GLSurfaceView implements GodotRenderView
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
this.detector.onTouchEvent(event);
- return godot.gotTouchEvent(event);
+ return inputHandler.onTouchEvent(event);
}
@Override
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 c2f3c88416..874fd88848 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java
@@ -37,12 +37,16 @@ import android.content.*;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.AssetManager;
+import android.graphics.Point;
import android.media.*;
import android.net.Uri;
import android.os.*;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.SparseArray;
+import android.view.Display;
+import android.view.DisplayCutout;
+import android.view.WindowInsets;
import java.io.IOException;
import java.io.InputStream;
@@ -461,6 +465,28 @@ public class GodotIO {
return (int)(metrics.density * 160f);
}
+ public int[] screenGetUsableRect() {
+ DisplayMetrics metrics = activity.getResources().getDisplayMetrics();
+ Display display = activity.getWindowManager().getDefaultDisplay();
+ Point size = new Point();
+ display.getRealSize(size);
+
+ int result[] = { 0, 0, size.x, size.y };
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
+ WindowInsets insets = activity.getWindow().getDecorView().getRootWindowInsets();
+ DisplayCutout cutout = insets.getDisplayCutout();
+ if (cutout != null) {
+ int insetLeft = cutout.getSafeInsetLeft();
+ int insetTop = cutout.getSafeInsetTop();
+ result[0] = insetLeft;
+ result[1] = insetTop;
+ result[2] -= insetLeft + cutout.getSafeInsetRight();
+ result[3] -= insetTop + cutout.getSafeInsetBottom();
+ }
+ }
+ return result;
+ }
+
public void showKeyboard(String p_existing_text, boolean p_multiline, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
if (edit != null)
edit.showKeyboard(p_existing_text, p_multiline, p_max_input_length, p_cursor_start, p_cursor_end);
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 318e2816ff..6ccbe91e60 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
@@ -94,17 +94,19 @@ public class GodotLib {
/**
* Forward touch events from the main thread to the GL thread.
*/
- public static native void touch(int what, int pointer, int howmany, int[] arr);
+ public static native void touch(int inputDevice, int event, int pointer, int pointerCount, float[] positions);
+ public static native void touch(int inputDevice, int event, int pointer, int pointerCount, float[] positions, int buttonsMask);
+ public static native void touch(int inputDevice, int event, int pointer, int pointerCount, float[] positions, int buttonsMask, float verticalFactor, float horizontalFactor);
/**
* Forward hover events from the main thread to the GL thread.
*/
- public static native void hover(int type, int x, int y);
+ public static native void hover(int type, float x, float y);
/**
* Forward double_tap events from the main thread to the GL thread.
*/
- public static native void doubletap(int x, int y);
+ public static native void doubleTap(int buttonMask, int x, int y);
/**
* Forward scroll events from the main thread to the GL thread.
diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java b/platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java
index 65708389c3..6cd5ca7b4e 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java
@@ -38,6 +38,7 @@ import org.godotengine.godot.vulkan.VkSurfaceView;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.GestureDetector;
+import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.SurfaceView;
@@ -100,22 +101,22 @@ public class GodotVulkanRenderView extends VkSurfaceView implements GodotRenderV
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
mGestureDetector.onTouchEvent(event);
- return godot.gotTouchEvent(event);
+ return mInputHandler.onTouchEvent(event);
}
@Override
public boolean onKeyUp(final int keyCode, KeyEvent event) {
- return mInputHandler.onKeyUp(keyCode, event) || super.onKeyUp(keyCode, event);
+ return mInputHandler.onKeyUp(keyCode, event);
}
@Override
public boolean onKeyDown(final int keyCode, KeyEvent event) {
- return mInputHandler.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
+ return mInputHandler.onKeyDown(keyCode, event);
}
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
- return mInputHandler.onGenericMotionEvent(event) || super.onGenericMotionEvent(event);
+ return mInputHandler.onGenericMotionEvent(event);
}
@Override
diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.java
index 1c9a683bbd..fb151fa504 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.java
@@ -33,7 +33,6 @@ package org.godotengine.godot.input;
import org.godotengine.godot.GodotLib;
import org.godotengine.godot.GodotRenderView;
-import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
@@ -75,10 +74,11 @@ public class GodotGestureHandler extends GestureDetector.SimpleOnGestureListener
//Log.i("GodotGesture", "onDoubleTap");
final int x = Math.round(event.getX());
final int y = Math.round(event.getY());
+ final int buttonMask = event.getButtonState();
queueEvent(new Runnable() {
@Override
public void run() {
- GodotLib.doubletap(x, y);
+ GodotLib.doubleTap(buttonMask, x, y);
}
});
return true;
diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java
index 9abd65cc67..f3e985f944 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java
@@ -36,6 +36,7 @@ import org.godotengine.godot.GodotLib;
import org.godotengine.godot.GodotRenderView;
import org.godotengine.godot.input.InputManagerCompat.InputDeviceListener;
+import android.os.Build;
import android.util.Log;
import android.view.InputDevice;
import android.view.InputDevice.MotionRange;
@@ -156,6 +157,53 @@ public class GodotInputHandler implements InputDeviceListener {
return true;
}
+ public boolean onTouchEvent(final MotionEvent event) {
+ // Mouse drag (mouse pressed and move) doesn't fire onGenericMotionEvent so this is needed
+ if (event.isFromSource(InputDevice.SOURCE_MOUSE)) {
+ if (event.getAction() != MotionEvent.ACTION_MOVE) {
+ // we return true because every time a mouse event is fired, the event is already handled
+ // in onGenericMotionEvent, so by touch event we can say that the event is also handled
+ return true;
+ }
+ return handleMouseEvent(event);
+ }
+
+ final int evcount = event.getPointerCount();
+ if (evcount == 0)
+ return true;
+
+ if (mRenderView != null) {
+ final float[] arr = new float[event.getPointerCount() * 3]; // pointerId1, x1, y1, pointerId2, etc...
+
+ for (int i = 0; i < event.getPointerCount(); i++) {
+ arr[i * 3 + 0] = event.getPointerId(i);
+ arr[i * 3 + 1] = event.getX(i);
+ arr[i * 3 + 2] = event.getY(i);
+ }
+ final int action = event.getActionMasked();
+
+ mRenderView.queueOnRenderThread(new Runnable() {
+ @Override
+ public void run() {
+ switch (action) {
+ case MotionEvent.ACTION_DOWN:
+ case MotionEvent.ACTION_CANCEL:
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_MOVE: {
+ GodotLib.touch(event.getSource(), action, 0, evcount, arr);
+ } break;
+ case MotionEvent.ACTION_POINTER_UP:
+ case MotionEvent.ACTION_POINTER_DOWN: {
+ int pointer_idx = event.getPointerId(event.getActionIndex());
+ GodotLib.touch(event.getSource(), action, pointer_idx, evcount, arr);
+ } break;
+ }
+ }
+ });
+ }
+ return true;
+ }
+
public boolean onGenericMotionEvent(MotionEvent event) {
if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK && event.getAction() == MotionEvent.ACTION_MOVE) {
final int device_id = findJoystickDevice(event.getDeviceId());
@@ -189,8 +237,8 @@ public class GodotInputHandler implements InputDeviceListener {
return true;
}
} else if ((event.getSource() & InputDevice.SOURCE_STYLUS) == InputDevice.SOURCE_STYLUS) {
- final int x = Math.round(event.getX());
- final int y = Math.round(event.getY());
+ final float x = event.getX();
+ final float y = event.getY();
final int type = event.getAction();
queueEvent(new Runnable() {
@Override
@@ -199,6 +247,10 @@ public class GodotInputHandler implements InputDeviceListener {
}
});
return true;
+ } else if ((event.getSource() & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ return handleMouseEvent(event);
+ }
}
return false;
@@ -366,4 +418,53 @@ public class GodotInputHandler implements InputDeviceListener {
return -1;
}
+
+ private boolean handleMouseEvent(final MotionEvent event) {
+ switch (event.getActionMasked()) {
+ case MotionEvent.ACTION_HOVER_ENTER:
+ case MotionEvent.ACTION_HOVER_MOVE:
+ case MotionEvent.ACTION_HOVER_EXIT: {
+ final float x = event.getX();
+ final float y = event.getY();
+ final int type = event.getAction();
+ queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ GodotLib.hover(type, x, y);
+ }
+ });
+ return true;
+ }
+ case MotionEvent.ACTION_BUTTON_PRESS:
+ case MotionEvent.ACTION_BUTTON_RELEASE:
+ case MotionEvent.ACTION_MOVE: {
+ final float x = event.getX();
+ final float y = event.getY();
+ final int buttonsMask = event.getButtonState();
+ final int action = event.getAction();
+ queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ GodotLib.touch(event.getSource(), action, 0, 1, new float[] { 0, x, y }, buttonsMask);
+ }
+ });
+ return true;
+ }
+ case MotionEvent.ACTION_SCROLL: {
+ final float x = event.getX();
+ final float y = event.getY();
+ final int buttonsMask = event.getButtonState();
+ final int action = event.getAction();
+ final float verticalFactor = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
+ final float horizontalFactor = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
+ queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ GodotLib.touch(event.getSource(), action, 0, 1, new float[] { 0, x, y }, buttonsMask, verticalFactor, horizontalFactor);
+ }
+ });
+ }
+ }
+ return false;
+ }
}
diff --git a/platform/android/java/nativeSrcsConfigs/AndroidManifest.xml b/platform/android/java/nativeSrcsConfigs/AndroidManifest.xml
new file mode 100644
index 0000000000..dc180375d5
--- /dev/null
+++ b/platform/android/java/nativeSrcsConfigs/AndroidManifest.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest package="org.godotengine.godot" />
diff --git a/platform/android/java/lib/CMakeLists.txt b/platform/android/java/nativeSrcsConfigs/CMakeLists.txt
index d3bdf6a5f2..34925684da 100644
--- a/platform/android/java/lib/CMakeLists.txt
+++ b/platform/android/java/nativeSrcsConfigs/CMakeLists.txt
@@ -1,3 +1,4 @@
+# Non functional cmake build file used to provide Android Studio editor support to the project.
cmake_minimum_required(VERSION 3.6)
project(godot)
diff --git a/platform/android/java/nativeSrcsConfigs/README.md b/platform/android/java/nativeSrcsConfigs/README.md
new file mode 100644
index 0000000000..e48505ccda
--- /dev/null
+++ b/platform/android/java/nativeSrcsConfigs/README.md
@@ -0,0 +1,4 @@
+## Native sources configs
+
+This is a non functional Android library used to provide Android Studio editor support to the Godot project native files.
+Nothing else should be added to this library.
diff --git a/platform/android/java/nativeSrcsConfigs/build.gradle b/platform/android/java/nativeSrcsConfigs/build.gradle
new file mode 100644
index 0000000000..65b7bb9dc9
--- /dev/null
+++ b/platform/android/java/nativeSrcsConfigs/build.gradle
@@ -0,0 +1,54 @@
+// Non functional android library used to provide Android Studio editor support to the project.
+plugins {
+ id 'com.android.library'
+}
+
+android {
+ compileSdkVersion versions.compileSdk
+ buildToolsVersion versions.buildTools
+
+ defaultConfig {
+ minSdkVersion versions.minSdk
+ targetSdkVersion versions.targetSdk
+ }
+
+ compileOptions {
+ sourceCompatibility versions.javaVersion
+ targetCompatibility versions.javaVersion
+ }
+
+ packagingOptions {
+ exclude 'META-INF/LICENSE'
+ exclude 'META-INF/NOTICE'
+
+ // Should be uncommented for development purpose within Android Studio
+ // doNotStrip '**/*.so'
+ }
+
+ sourceSets {
+ main {
+ manifest.srcFile 'AndroidManifest.xml'
+ }
+ }
+
+ externalNativeBuild {
+ cmake {
+ path "CMakeLists.txt"
+ }
+ }
+
+ libraryVariants.all { variant ->
+ def buildType = variant.buildType.name.capitalize()
+
+ def taskPrefix = ""
+ if (project.path != ":") {
+ taskPrefix = project.path + ":"
+ }
+
+ // Disable the externalNativeBuild* task as it would cause build failures since the cmake build
+ // files is only setup for editing support.
+ gradle.startParameter.excludedTaskNames += taskPrefix + "externalNativeBuild" + buildType
+ }
+}
+
+dependencies {}
diff --git a/platform/android/java/settings.gradle b/platform/android/java/settings.gradle
index f6921c70aa..524031d93f 100644
--- a/platform/android/java/settings.gradle
+++ b/platform/android/java/settings.gradle
@@ -3,3 +3,4 @@ rootProject.name = "Godot"
include ':app'
include ':lib'
+include ':nativeSrcsConfigs'
diff --git a/platform/android/java_godot_io_wrapper.cpp b/platform/android/java_godot_io_wrapper.cpp
index 4ccbc6b97e..8d1db395ab 100644
--- a/platform/android/java_godot_io_wrapper.cpp
+++ b/platform/android/java_godot_io_wrapper.cpp
@@ -29,7 +29,7 @@
/*************************************************************************/
#include "java_godot_io_wrapper.h"
-#include "core/error_list.h"
+#include "core/error/error_list.h"
// JNIEnv is only valid within the thread it belongs to, in a multi threading environment
// we can't cache it.
@@ -52,6 +52,7 @@ GodotIOJavaWrapper::GodotIOJavaWrapper(JNIEnv *p_env, jobject p_godot_io_instanc
_get_locale = p_env->GetMethodID(cls, "getLocale", "()Ljava/lang/String;");
_get_model = p_env->GetMethodID(cls, "getModel", "()Ljava/lang/String;");
_get_screen_DPI = p_env->GetMethodID(cls, "getScreenDPI", "()I");
+ _screen_get_usable_rect = p_env->GetMethodID(cls, "screenGetUsableRect", "()[I"),
_get_unique_id = p_env->GetMethodID(cls, "getUniqueID", "()Ljava/lang/String;");
_show_keyboard = p_env->GetMethodID(cls, "showKeyboard", "(Ljava/lang/String;ZIII)V");
_hide_keyboard = p_env->GetMethodID(cls, "hideKeyboard", "()V");
@@ -118,6 +119,19 @@ int GodotIOJavaWrapper::get_screen_dpi() {
}
}
+void GodotIOJavaWrapper::screen_get_usable_rect(int (&p_rect_xywh)[4]) {
+ if (_screen_get_usable_rect) {
+ JNIEnv *env = ThreadAndroid::get_env();
+ jintArray returnArray = (jintArray)env->CallObjectMethod(godot_io_instance, _screen_get_usable_rect);
+ ERR_FAIL_COND(env->GetArrayLength(returnArray) != 4);
+ jint *arrayBody = env->GetIntArrayElements(returnArray, JNI_FALSE);
+ for (int i = 0; i < 4; i++) {
+ p_rect_xywh[i] = arrayBody[i];
+ }
+ env->ReleaseIntArrayElements(returnArray, arrayBody, 0);
+ }
+}
+
String GodotIOJavaWrapper::get_unique_id() {
if (_get_unique_id) {
JNIEnv *env = ThreadAndroid::get_env();
diff --git a/platform/android/java_godot_io_wrapper.h b/platform/android/java_godot_io_wrapper.h
index 6465ded985..13270c794b 100644
--- a/platform/android/java_godot_io_wrapper.h
+++ b/platform/android/java_godot_io_wrapper.h
@@ -50,6 +50,7 @@ private:
jmethodID _get_locale = 0;
jmethodID _get_model = 0;
jmethodID _get_screen_DPI = 0;
+ jmethodID _screen_get_usable_rect = 0;
jmethodID _get_unique_id = 0;
jmethodID _show_keyboard = 0;
jmethodID _hide_keyboard = 0;
@@ -68,6 +69,7 @@ public:
String get_locale();
String get_model();
int get_screen_dpi();
+ void screen_get_usable_rect(int (&p_rect_xywh)[4]);
String get_unique_id();
bool has_vk();
void show_vk(const String &p_existing, bool p_multiline, int p_max_input_length, int p_cursor_start, int p_cursor_end);
diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp
index 4610b94363..5dc773fae2 100644
--- a/platform/android/java_godot_lib_jni.cpp
+++ b/platform/android/java_godot_lib_jni.cpp
@@ -37,9 +37,9 @@
#include "api/java_class_wrapper.h"
#include "api/jni_singleton.h"
#include "audio_driver_jandroid.h"
-#include "core/engine.h"
+#include "core/config/engine.h"
+#include "core/config/project_settings.h"
#include "core/input/input.h"
-#include "core/project_settings.h"
#include "dir_access_jandroid.h"
#include "display_server_android.h"
#include "file_access_android.h"
@@ -51,6 +51,7 @@
#include "string_android.h"
#include "thread_jandroid.h"
+#include <android/input.h>
#include <unistd.h>
#include <android/native_window_jni.h>
@@ -237,40 +238,51 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jcl
}
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch(JNIEnv *env, jclass clazz, jint ev, jint pointer, jint count, jintArray positions) {
+void touch_preprocessing(JNIEnv *env, jclass clazz, jint input_device, jint ev, jint pointer, jint pointer_count, jfloatArray positions, jint buttons_mask, jfloat vertical_factor, jfloat horizontal_factor) {
if (step == 0)
return;
Vector<DisplayServerAndroid::TouchPos> points;
- for (int i = 0; i < count; i++) {
- jint p[3];
- env->GetIntArrayRegion(positions, i * 3, 3, p);
+ for (int i = 0; i < pointer_count; i++) {
+ jfloat p[3];
+ env->GetFloatArrayRegion(positions, i * 3, 3, p);
DisplayServerAndroid::TouchPos tp;
tp.pos = Point2(p[1], p[2]);
- tp.id = p[0];
+ tp.id = (int)p[0];
points.push_back(tp);
}
- DisplayServerAndroid::get_singleton()->process_touch(ev, pointer, points);
+ if ((input_device & AINPUT_SOURCE_MOUSE) == AINPUT_SOURCE_MOUSE) {
+ DisplayServerAndroid::get_singleton()->process_mouse_event(ev, buttons_mask, points[0].pos, vertical_factor, horizontal_factor);
+ } else {
+ DisplayServerAndroid::get_singleton()->process_touch(ev, pointer, points);
+ }
+}
+
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch__IIII_3F(JNIEnv *env, jclass clazz, jint input_device, jint ev, jint pointer, jint pointer_count, jfloatArray position) {
+ touch_preprocessing(env, clazz, input_device, ev, pointer, pointer_count, position);
+}
+
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch__IIII_3FI(JNIEnv *env, jclass clazz, jint input_device, jint ev, jint pointer, jint pointer_count, jfloatArray position, jint buttons_mask) {
+ touch_preprocessing(env, clazz, input_device, ev, pointer, pointer_count, position, buttons_mask);
+}
- /*
- if (os_android)
- os_android->process_touch(ev,pointer,points);
- */
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch__IIII_3FIFF(JNIEnv *env, jclass clazz, jint input_device, jint ev, jint pointer, jint pointer_count, jfloatArray position, jint buttons_mask, jfloat vertical_factor, jfloat horizontal_factor) {
+ touch_preprocessing(env, clazz, input_device, ev, pointer, pointer_count, position, buttons_mask, vertical_factor, horizontal_factor);
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hover(JNIEnv *env, jclass clazz, jint p_type, jint p_x, jint p_y) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hover(JNIEnv *env, jclass clazz, jint p_type, jfloat p_x, jfloat p_y) {
if (step == 0)
return;
DisplayServerAndroid::get_singleton()->process_hover(p_type, Point2(p_x, p_y));
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_doubletap(JNIEnv *env, jclass clazz, jint p_x, jint p_y) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_doubleTap(JNIEnv *env, jclass clazz, jint p_button_mask, jint p_x, jint p_y) {
if (step == 0)
return;
- DisplayServerAndroid::get_singleton()->process_double_tap(Point2(p_x, p_y));
+ DisplayServerAndroid::get_singleton()->process_double_tap(p_button_mask, Point2(p_x, p_y));
}
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_scroll(JNIEnv *env, jclass clazz, jint p_x, jint p_y) {
diff --git a/platform/android/java_godot_lib_jni.h b/platform/android/java_godot_lib_jni.h
index 07584518e5..b499f6dfa1 100644
--- a/platform/android/java_godot_lib_jni.h
+++ b/platform/android/java_godot_lib_jni.h
@@ -44,9 +44,12 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_resize(JNIEnv *env, j
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *env, jclass clazz, jobject p_surface, jboolean p_32_bits);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jclass clazz);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jclass clazz);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch(JNIEnv *env, jclass clazz, jint ev, jint pointer, jint count, jintArray positions);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hover(JNIEnv *env, jclass clazz, jint p_type, jint p_x, jint p_y);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_doubletap(JNIEnv *env, jclass clazz, jint p_x, jint p_y);
+void touch_preprocessing(JNIEnv *env, jclass clazz, jint input_device, jint ev, jint pointer, jint pointer_count, jfloatArray positions, jint buttons_mask = 0, jfloat vertical_factor = 0, jfloat horizontal_factor = 0);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch__IIII_3F(JNIEnv *env, jclass clazz, jint input_device, jint ev, jint pointer, jint pointer_count, jfloatArray positions);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch__IIII_3FI(JNIEnv *env, jclass clazz, jint input_device, jint ev, jint pointer, jint pointer_count, jfloatArray positions, jint buttons_mask);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch__IIII_3FIFF(JNIEnv *env, jclass clazz, jint input_device, jint ev, jint pointer, jint pointer_count, jfloatArray positions, jint buttons_mask, jfloat vertical_factor, jfloat horizontal_factor);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hover(JNIEnv *env, jclass clazz, jint p_type, jfloat p_x, jfloat p_y);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_doubleTap(JNIEnv *env, jclass clazz, jint p_button_mask, jint p_x, jint p_y);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_scroll(JNIEnv *env, jclass clazz, jint p_x, jint p_y);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_keycode, jint p_scancode, jint p_unicode_char, jboolean p_pressed);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jclass clazz, jint p_device, jint p_button, jboolean p_pressed);
diff --git a/platform/android/jni_utils.h b/platform/android/jni_utils.h
index 5320715853..bda056604f 100644
--- a/platform/android/jni_utils.h
+++ b/platform/android/jni_utils.h
@@ -32,8 +32,8 @@
#define JNI_UTILS_H
#include "string_android.h"
-#include <core/engine.h>
-#include <core/variant.h>
+#include <core/config/engine.h>
+#include <core/variant/variant.h>
#include <jni.h>
struct jvalret {
diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp
index baf6ee952a..00733f6dbb 100644
--- a/platform/android/os_android.cpp
+++ b/platform/android/os_android.cpp
@@ -30,8 +30,8 @@
#include "os_android.h"
+#include "core/config/project_settings.h"
#include "core/io/file_access_buffered_fa.h"
-#include "core/project_settings.h"
#include "drivers/unix/dir_access_unix.h"
#include "drivers/unix/file_access_unix.h"
#include "file_access_android.h"
@@ -153,6 +153,7 @@ void OS_Android::main_loop_begin() {
bool OS_Android::main_loop_iterate() {
if (!main_loop)
return false;
+ DisplayServerAndroid::get_singleton()->process_events();
return Main::iteration();
}
diff --git a/platform/android/plugin/godot_plugin_config.h b/platform/android/plugin/godot_plugin_config.h
index ea3c7b4f55..ecb9c0c7f5 100644
--- a/platform/android/plugin/godot_plugin_config.h
+++ b/platform/android/plugin/godot_plugin_config.h
@@ -31,9 +31,9 @@
#ifndef GODOT_PLUGIN_CONFIG_H
#define GODOT_PLUGIN_CONFIG_H
-#include "core/error_list.h"
+#include "core/error/error_list.h"
#include "core/io/config_file.h"
-#include "core/ustring.h"
+#include "core/string/ustring.h"
static const char *PLUGIN_CONFIG_EXT = ".gdap";
diff --git a/platform/android/plugin/godot_plugin_jni.cpp b/platform/android/plugin/godot_plugin_jni.cpp
index d2528bebeb..b8e5345b85 100644
--- a/platform/android/plugin/godot_plugin_jni.cpp
+++ b/platform/android/plugin/godot_plugin_jni.cpp
@@ -30,9 +30,9 @@
#include "godot_plugin_jni.h"
-#include <core/engine.h>
-#include <core/error_macros.h>
-#include <core/project_settings.h>
+#include <core/config/engine.h>
+#include <core/config/project_settings.h>
+#include <core/error/error_macros.h>
#include <platform/android/api/jni_singleton.h>
#include <platform/android/jni_utils.h>
#include <platform/android/string_android.h>
diff --git a/platform/android/string_android.h b/platform/android/string_android.h
index 88ccd3b652..0a7dbf475d 100644
--- a/platform/android/string_android.h
+++ b/platform/android/string_android.h
@@ -30,7 +30,7 @@
#ifndef STRING_ANDROID_H
#define STRING_ANDROID_H
-#include "core/ustring.h"
+#include "core/string/ustring.h"
#include "thread_jandroid.h"
#include <jni.h>
diff --git a/platform/android/thread_jandroid.cpp b/platform/android/thread_jandroid.cpp
index 13aa313ebf..442e4d781b 100644
--- a/platform/android/thread_jandroid.cpp
+++ b/platform/android/thread_jandroid.cpp
@@ -30,9 +30,9 @@
#include "thread_jandroid.h"
+#include "core/object/script_language.h"
#include "core/os/memory.h"
-#include "core/safe_refcount.h"
-#include "core/script_language.h"
+#include "core/templates/safe_refcount.h"
static void _thread_id_key_destr_callback(void *p_value) {
memdelete(static_cast<Thread::ID *>(p_value));
diff --git a/platform/android/vulkan/vulkan_context_android.cpp b/platform/android/vulkan/vulkan_context_android.cpp
index 5fb7a83da4..56ef99dfc7 100644
--- a/platform/android/vulkan/vulkan_context_android.cpp
+++ b/platform/android/vulkan/vulkan_context_android.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "vulkan_context_android.h"
+
#include <vulkan/vulkan_android.h>
const char *VulkanContextAndroid::_get_platform_surface_extension() const {