diff options
Diffstat (limited to 'platform/android')
| -rw-r--r-- | platform/android/build.gradle.template | 2 | ||||
| -rw-r--r-- | platform/android/detect.py | 4 | ||||
| -rw-r--r-- | platform/android/export/export.cpp | 81 | ||||
| -rw-r--r-- | platform/android/java/src/org/godotengine/godot/Godot.java | 2 | ||||
| -rw-r--r-- | platform/android/java/src/org/godotengine/godot/GodotView.java | 188 | ||||
| -rw-r--r-- | platform/android/os_android.cpp | 8 | 
6 files changed, 192 insertions, 93 deletions
diff --git a/platform/android/build.gradle.template b/platform/android/build.gradle.template index 1603ea70d9..18ffc74fc3 100644 --- a/platform/android/build.gradle.template +++ b/platform/android/build.gradle.template @@ -14,9 +14,9 @@ apply plugin: 'com.android.application'  allprojects {      repositories { -    	jcenter()  	mavenCentral()  	google() +	jcenter()  	$$GRADLE_REPOSITORY_URLS$$      }  } diff --git a/platform/android/detect.py b/platform/android/detect.py index 953a2fa6d2..e4cab2fb23 100644 --- a/platform/android/detect.py +++ b/platform/android/detect.py @@ -186,7 +186,7 @@ def configure(env):      env.PrependENVPath('PATH', tools_path)      ccache_path = os.environ.get("CCACHE") -    if ccache_path == None: +    if ccache_path is None:          env['CC'] = compiler_path + '/clang'          env['CXX'] = compiler_path + '/clang++'      else: @@ -293,7 +293,7 @@ def configure(env):  # Return NDK version string in source.properties (adapted from the Chromium project).  def get_ndk_version(path): -    if path == None: +    if path is None:          return None      prop_file_path = os.path.join(path, "source.properties")      try: diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 3b503e2657..3766f732e4 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -395,7 +395,7 @@ class EditorExportAndroid : public EditorExportPlatform {  		return aname;  	} -	String get_package_name(const String &p_package) { +	String get_package_name(const String &p_package) const {  		String pname = p_package;  		String basename = ProjectSettings::get_singleton()->get("application/config/name"); @@ -420,6 +420,70 @@ class EditorExportAndroid : public EditorExportPlatform {  		return pname;  	} +	bool is_package_name_valid(const String &p_package, String *r_error = NULL) const { + +		String pname = p_package; + +		if (pname.length() == 0) { +			if (r_error) { +				*r_error = "Package name is missing."; +			} +			return false; +		} + +		int segments = 0; +		bool first = true; +		for (int i = 0; i < pname.length(); i++) { +			CharType c = pname[i]; +			if (first && c == '.') { +				if (r_error) { +					*r_error = "Package segments must be of non-zero length."; +				} +				return false; +			} +			if (c == '.') { +				segments++; +				first = true; +				continue; +			} +			if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')) { +				if (r_error) { +					*r_error = "The character '" + String::chr(c) + "' is not allowed in Android application package names."; +				} +				return false; +			} +			if (first && (c >= '0' && c <= '9')) { +				if (r_error) { +					*r_error = "A digit cannot be the first character in a package segment."; +				} +				return false; +			} +			if (first && c == '_') { +				if (r_error) { +					*r_error = "The character '" + String::chr(c) + "' cannot be the first character in a package segment."; +				} +				return false; +			} +			first = false; +		} + +		if (segments == 0) { +			if (r_error) { +				*r_error = "The package must have at least one '.' separator."; +			} +			return false; +		} + +		if (first) { +			if (r_error) { +				*r_error = "Package segments must be of non-zero length."; +			} +			return false; +		} + +		return true; +	} +  	static bool _should_compress_asset(const String &p_path, const Vector<uint8_t> &p_data) {  		/* @@ -1382,12 +1446,23 @@ public:  			}  		} +		String pn = p_preset->get("package/unique_name"); +		String pn_err; + +		if (!is_package_name_valid(get_package_name(pn), &pn_err)) { + +			valid = false; +			err += "Invalid package name - " + pn_err + "\n"; +		} +  		r_error = err;  		return valid;  	} -	virtual String get_binary_extension(const Ref<EditorExportPreset> &p_preset) const { -		return "apk"; +	virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const { +		List<String> list; +		list.push_back("apk"); +		return list;  	}  	virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) { diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java index ab37f7a02c..88194f00d1 100644 --- a/platform/android/java/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/src/org/godotengine/godot/Godot.java @@ -279,7 +279,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC  		// ...add to FrameLayout  		layout.addView(edittext); -		mView = new GodotView(getApplication(), io, use_gl3, use_32_bits, use_debug_opengl,this); +		mView = new GodotView(getApplication(), io, use_gl3, use_32_bits, use_debug_opengl, this);  		layout.addView(mView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));  		edittext.setView(mView);  		io.setEdit(edittext); diff --git a/platform/android/java/src/org/godotengine/godot/GodotView.java b/platform/android/java/src/org/godotengine/godot/GodotView.java index 181ffc3b4b..4cb4db33de 100644 --- a/platform/android/java/src/org/godotengine/godot/GodotView.java +++ b/platform/android/java/src/org/godotengine/godot/GodotView.java @@ -86,7 +86,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {  	private Godot activity;  	private InputManagerCompat mInputManager; -	public GodotView(Context context, GodotIO p_io, boolean p_use_gl3, boolean p_use_32_bits, boolean p_use_debug_opengl,Godot p_activity) { +	public GodotView(Context context, GodotIO p_io, boolean p_use_gl3, boolean p_use_32_bits, boolean p_use_debug_opengl, Godot p_activity) {  		super(context);  		ctx = context;  		io = p_io; @@ -204,48 +204,65 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {  				return i;  			}  		} -		onInputDeviceAdded(device_id); -		return joy_devices.size() - 1; + +		return -1;  	}  	@Override  	public void onInputDeviceAdded(int deviceId) { -		joystick joy = new joystick(); -		joy.device_id = deviceId; -		final int id = joy_devices.size(); -		InputDevice device = mInputManager.getInputDevice(deviceId); -		final String name = device.getName(); -		joy.name = device.getName(); -		joy.axes = new ArrayList<InputDevice.MotionRange>(); -		joy.hats = new ArrayList<InputDevice.MotionRange>(); -		List<InputDevice.MotionRange> ranges = device.getMotionRanges(); -		Collections.sort(ranges, new RangeComparator()); -		for (InputDevice.MotionRange range : ranges) { -			if (range.getAxis() == MotionEvent.AXIS_HAT_X || range.getAxis() == MotionEvent.AXIS_HAT_Y) { -				joy.hats.add(range); -			} else { -				joy.axes.add(range); +		int id = find_joy_device(deviceId); + +		// Check if the device has not been already added +		if (id < 0) { +			InputDevice device = mInputManager.getInputDevice(deviceId); + +			id = joy_devices.size(); + +			joystick joy = new joystick(); +			joy.device_id = deviceId; +			joy.name = device.getName(); +			joy.axes = new ArrayList<InputDevice.MotionRange>(); +			joy.hats = new ArrayList<InputDevice.MotionRange>(); + +			List<InputDevice.MotionRange> ranges = device.getMotionRanges(); +			Collections.sort(ranges, new RangeComparator()); + +			for (InputDevice.MotionRange range : ranges) { +				if (range.getAxis() == MotionEvent.AXIS_HAT_X || range.getAxis() == MotionEvent.AXIS_HAT_Y) { +					joy.hats.add(range); +				} else { +					joy.axes.add(range); +				}  			} + +			joy_devices.add(joy); + +			final int device_id = id; +			final String name = joy.name; +			queueEvent(new Runnable() { +				@Override +				public void run() { +					GodotLib.joyconnectionchanged(device_id, true, name); +				} +			});  		} -		joy_devices.add(joy); -		queueEvent(new Runnable() { -			@Override -			public void run() { -				GodotLib.joyconnectionchanged(id, true, name); -			} -		});  	}  	@Override  	public void onInputDeviceRemoved(int deviceId) { -		final int id = find_joy_device(deviceId); -		joy_devices.remove(id); -		queueEvent(new Runnable() { -			@Override -			public void run() { -				GodotLib.joyconnectionchanged(id, false, ""); -			} -		}); +		final int device_id = find_joy_device(deviceId); + +		// Check if the evice has not been already removed +		if (device_id > -1) { +			joy_devices.remove(device_id); + +			queueEvent(new Runnable() { +				@Override +				public void run() { +					GodotLib.joyconnectionchanged(device_id, false, ""); +				} +			}); +		}  	}  	@Override @@ -266,15 +283,18 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {  		if ((source & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK || (source & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD || (source & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) {  			final int button = get_godot_button(keyCode); -			final int device = find_joy_device(event.getDeviceId()); +			final int device_id = find_joy_device(event.getDeviceId()); -			queueEvent(new Runnable() { -				@Override -				public void run() { -					GodotLib.joybutton(device, button, false); -				} -			}); -			return true; +			// Check if the device exists +			if (device_id > -1) { +				queueEvent(new Runnable() { +					@Override +					public void run() { +						GodotLib.joybutton(device_id, button, false); +					} +				}); +				return true; +			}  		} else {  			final int chr = event.getUnicodeChar(0);  			queueEvent(new Runnable() { @@ -284,6 +304,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {  				}  			});  		}; +  		return super.onKeyUp(keyCode, event);  	}; @@ -308,18 +329,20 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {  			if (event.getRepeatCount() > 0) // ignore key echo  				return true; -			final int button = get_godot_button(keyCode); -			final int device = find_joy_device(event.getDeviceId()); -			//Log.e(TAG, String.format("joy button down! button %x, %d, device %d", keyCode, button, device)); -			queueEvent(new Runnable() { -				@Override -				public void run() { -					GodotLib.joybutton(device, button, true); -				} -			}); -			return true; +			final int button = get_godot_button(keyCode); +			final int device_id = find_joy_device(event.getDeviceId()); +			// Check if the device exists +			if (device_id > -1) { +				queueEvent(new Runnable() { +					@Override +					public void run() { +						GodotLib.joybutton(device_id, button, true); +					} +				}); +				return true; +			}  		} else {  			final int chr = event.getUnicodeChar(0);  			queueEvent(new Runnable() { @@ -329,6 +352,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {  				}  			});  		}; +  		return super.onKeyDown(keyCode, event);  	} @@ -338,33 +362,35 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {  		if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK && event.getAction() == MotionEvent.ACTION_MOVE) {  			final int device_id = find_joy_device(event.getDeviceId()); -			joystick joy = joy_devices.get(device_id); -			for (int i = 0; i < joy.axes.size(); i++) { -				InputDevice.MotionRange range = joy.axes.get(i); -				final float value = (event.getAxisValue(range.getAxis()) - range.getMin()) / range.getRange() * 2.0f - 1.0f; -				//Log.e(TAG, String.format("axis event: %d, value %f", i, value)); -				final int idx = i; -				queueEvent(new Runnable() { -					@Override -					public void run() { -						GodotLib.joyaxis(device_id, idx, value); -					} -				}); -			} +			// Check if the device exists +			if (device_id > -1) { +				joystick joy = joy_devices.get(device_id); + +				for (int i = 0; i < joy.axes.size(); i++) { +					InputDevice.MotionRange range = joy.axes.get(i); +					final float value = (event.getAxisValue(range.getAxis()) - range.getMin()) / range.getRange() * 2.0f - 1.0f; +					final int idx = i; +					queueEvent(new Runnable() { +						@Override +						public void run() { +							GodotLib.joyaxis(device_id, idx, value); +						} +					}); +				} -			for (int i = 0; i < joy.hats.size(); i += 2) { -				final int hatX = Math.round(event.getAxisValue(joy.hats.get(i).getAxis())); -				final int hatY = Math.round(event.getAxisValue(joy.hats.get(i + 1).getAxis())); -				//Log.e(TAG, String.format("HAT EVENT %d, %d", hatX, hatY)); -				queueEvent(new Runnable() { -					@Override -					public void run() { -						GodotLib.joyhat(device_id, hatX, hatY); -					} -				}); +				for (int i = 0; i < joy.hats.size(); i += 2) { +					final int hatX = Math.round(event.getAxisValue(joy.hats.get(i).getAxis())); +					final int hatY = Math.round(event.getAxisValue(joy.hats.get(i + 1).getAxis())); +					queueEvent(new Runnable() { +						@Override +						public void run() { +							GodotLib.joyhat(device_id, hatX, hatY); +						} +					}); +				} +				return true;  			} -			return true;  		};  		return super.onGenericMotionEvent(event); @@ -408,9 +434,9 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {  		setRenderer(new Renderer());  	} -	private static final int  _EGL_CONTEXT_FLAGS_KHR = 0x30FC; -	private static final int  _EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR= 0x00000001; -	 +	private static final int _EGL_CONTEXT_FLAGS_KHR = 0x30FC; +	private static final int _EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR = 0x00000001; +  	private static class ContextFactory implements GLSurfaceView.EGLContextFactory {  		private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;  		public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) { @@ -422,9 +448,9 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {  			checkEglError("Before eglCreateContext", egl);  			EGLContext context;  			if (use_debug_opengl) { -				int[] attrib_list2 = { EGL_CONTEXT_CLIENT_VERSION, 2,_EGL_CONTEXT_FLAGS_KHR,_EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR, EGL10.EGL_NONE }; -				int[] attrib_list3 = { EGL_CONTEXT_CLIENT_VERSION, 3,_EGL_CONTEXT_FLAGS_KHR,_EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR, EGL10.EGL_NONE }; -				context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, use_gl3 ? attrib_list3 : attrib_list2);			 +				int[] attrib_list2 = { EGL_CONTEXT_CLIENT_VERSION, 2, _EGL_CONTEXT_FLAGS_KHR, _EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR, EGL10.EGL_NONE }; +				int[] attrib_list3 = { EGL_CONTEXT_CLIENT_VERSION, 3, _EGL_CONTEXT_FLAGS_KHR, _EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR, EGL10.EGL_NONE }; +				context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, use_gl3 ? attrib_list3 : attrib_list2);  			} else {  				int[] attrib_list2 = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };  				int[] attrib_list3 = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL10.EGL_NONE }; diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 8e050c1d27..96ff226402 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -39,7 +39,7 @@  #include "file_access_android.h"  #include "main/main.h"  #include "servers/visual/visual_server_raster.h" -//#include "servers/visual/visual_server_wrap_mt.h" +#include "servers/visual/visual_server_wrap_mt.h"  #ifdef ANDROID_NATIVE_ACTIVITY  #include "dir_access_android.h" @@ -183,13 +183,11 @@ Error OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int  	video_driver_index = p_video_driver;  	visual_server = memnew(VisualServerRaster); -	/*	if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { - +	if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {  		visual_server = memnew(VisualServerWrapMT(visual_server, false)); -	};*/ +	}  	visual_server->init(); -	//	visual_server->cursor_set_visible(false, 0);  	AudioDriverManager::initialize(p_audio_driver);  |