diff options
Diffstat (limited to 'platform/android/java/lib')
16 files changed, 193 insertions, 118 deletions
diff --git a/platform/android/java/lib/AndroidManifest.xml b/platform/android/java/lib/AndroidManifest.xml index 79b5aadf2a..1f77e2fc34 100644 --- a/platform/android/java/lib/AndroidManifest.xml +++ b/platform/android/java/lib/AndroidManifest.xml @@ -4,9 +4,6 @@      android:versionCode="1"      android:versionName="1.0"> -    <!-- Should match the mindSdk and targetSdk values in platform/android/java/app/config.gradle --> -    <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="32" /> -      <application>          <!-- Records the version of the Godot library --> diff --git a/platform/android/java/lib/build.gradle b/platform/android/java/lib/build.gradle index c9e2a5d7d2..841656a240 100644 --- a/platform/android/java/lib/build.gradle +++ b/platform/android/java/lib/build.gradle @@ -176,11 +176,10 @@ android {          }      } -    // TODO: Enable when issues with AGP 7.1+ are resolved (https://github.com/GodotVR/godot_openxr/issues/187). -//    publishing { -//        singleVariant("templateRelease") { -//            withSourcesJar() -//            withJavadocJar() -//        } -//    } +    publishing { +        singleVariant("templateRelease") { +            withSourcesJar() +            withJavadocJar() +        } +    }  } 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 92e5e59496..3487e5019c 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.java @@ -175,6 +175,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  	public GodotIO io;  	public GodotNetUtils netUtils;  	public GodotTTS tts; +	DirectoryAccessHandler directoryAccessHandler;  	public interface ResultCallback {  		void callback(int requestCode, int resultCode, Intent data); @@ -299,7 +300,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  			for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {  				plugin.onRegisterPluginWithGodotNative();  			} -			setKeepScreenOn("True".equals(GodotLib.getGlobal("display/window/energy_saving/keep_screen_on"))); +			setKeepScreenOn(Boolean.parseBoolean(GodotLib.getGlobal("display/window/energy_saving/keep_screen_on")));  		});  		// Include the returned non-null views in the Godot view hierarchy. @@ -488,7 +489,7 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC  		netUtils = new GodotNetUtils(activity);  		tts = new GodotTTS(activity);  		Context context = getContext(); -		DirectoryAccessHandler directoryAccessHandler = new DirectoryAccessHandler(context); +		directoryAccessHandler = new DirectoryAccessHandler(context);  		FileAccessHandler fileAccessHandler = new FileAccessHandler(context);  		mSensorManager = (SensorManager)activity.getSystemService(Context.SENSOR_SERVICE);  		mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); 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 3dfc37f6b0..f8d937521b 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotGLRenderView.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotGLRenderView.java @@ -43,8 +43,13 @@ import org.godotengine.godot.xr.regular.RegularFallbackConfigChooser;  import android.annotation.SuppressLint;  import android.content.Context; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory;  import android.graphics.PixelFormat;  import android.os.Build; +import android.text.TextUtils; +import android.util.SparseArray;  import android.view.KeyEvent;  import android.view.MotionEvent;  import android.view.PointerIcon; @@ -52,6 +57,8 @@ import android.view.SurfaceView;  import androidx.annotation.Keep; +import java.io.InputStream; +  /**   * A simple GLSurfaceView sub-class that demonstrate how to perform   * OpenGL ES 2.0 rendering into a GL Surface. Note the following important @@ -61,7 +68,7 @@ import androidx.annotation.Keep;   *   See ContextFactory class definition below.   *   * - The class must use a custom EGLConfigChooser to be able to select - *   an EGLConfig that supports 2.0. This is done by providing a config + *   an EGLConfig that supports 3.0. This is done by providing a config   *   specification to eglChooseConfig() that has the attribute   *   EGL10.ELG_RENDERABLE_TYPE containing the EGL_OPENGL_ES2_BIT flag   *   set. See ConfigChooser class definition below. @@ -74,6 +81,7 @@ public class GodotGLRenderView extends GLSurfaceView implements GodotRenderView  	private final Godot godot;  	private final GodotInputHandler inputHandler;  	private final GodotRenderer godotRenderer; +	private final SparseArray<PointerIcon> customPointerIcons = new SparseArray<>();  	public GodotGLRenderView(Context context, Godot godot, XRMode xrMode, boolean p_use_debug_opengl) {  		super(context); @@ -169,12 +177,49 @@ public class GodotGLRenderView extends GLSurfaceView implements GodotRenderView  	}  	/** +	 * Used to configure the PointerIcon for the given type. +	 * +	 * Called from JNI +	 */ +	@Keep +	@Override +	public void configurePointerIcon(int pointerType, String imagePath, float hotSpotX, float hotSpotY) { +		if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { +			try { +				Bitmap bitmap = null; +				if (!TextUtils.isEmpty(imagePath)) { +					if (godot.directoryAccessHandler.filesystemFileExists(imagePath)) { +						// Try to load the bitmap from the file system +						bitmap = BitmapFactory.decodeFile(imagePath); +					} else if (godot.directoryAccessHandler.assetsFileExists(imagePath)) { +						// Try to load the bitmap from the assets directory +						AssetManager am = getContext().getAssets(); +						InputStream imageInputStream = am.open(imagePath); +						bitmap = BitmapFactory.decodeStream(imageInputStream); +					} +				} + +				PointerIcon customPointerIcon = PointerIcon.create(bitmap, hotSpotX, hotSpotY); +				customPointerIcons.put(pointerType, customPointerIcon); +			} catch (Exception e) { +				// Reset the custom pointer icon +				customPointerIcons.delete(pointerType); +			} +		} +	} + +	/**  	 * called from JNI to change pointer icon  	 */  	@Keep +	@Override  	public void setPointerIcon(int pointerType) {  		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { -			setPointerIcon(PointerIcon.getSystemIcon(getContext(), pointerType)); +			PointerIcon pointerIcon = customPointerIcons.get(pointerType); +			if (pointerIcon == null) { +				pointerIcon = PointerIcon.getSystemIcon(getContext(), pointerType); +			} +			setPointerIcon(pointerIcon);  		}  	} 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 26aad867b1..33896ecb95 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java @@ -110,7 +110,7 @@ public class GodotLib {  	/**  	 * Forward touch events.  	 */ -	public static native void dispatchTouchEvent(int event, int pointer, int pointerCount, float[] positions); +	public static native void dispatchTouchEvent(int event, int pointer, int pointerCount, float[] positions, boolean doubleTap);  	/**  	 * Dispatch mouse events diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotRenderView.java b/platform/android/java/lib/src/org/godotengine/godot/GodotRenderView.java index cb63fd885f..ab74ba037d 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotRenderView.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotRenderView.java @@ -48,5 +48,7 @@ public interface GodotRenderView {  	GodotInputHandler getInputHandler(); +	void configurePointerIcon(int pointerType, String imagePath, float hotSpotX, float hotSpotY); +  	void setPointerIcon(int pointerType);  } 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 0becf00d93..56bc7f9e76 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotVulkanRenderView.java @@ -36,7 +36,12 @@ import org.godotengine.godot.vulkan.VkSurfaceView;  import android.annotation.SuppressLint;  import android.content.Context; +import android.content.res.AssetManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory;  import android.os.Build; +import android.text.TextUtils; +import android.util.SparseArray;  import android.view.KeyEvent;  import android.view.MotionEvent;  import android.view.PointerIcon; @@ -44,10 +49,13 @@ import android.view.SurfaceView;  import androidx.annotation.Keep; +import java.io.InputStream; +  public class GodotVulkanRenderView extends VkSurfaceView implements GodotRenderView {  	private final Godot godot;  	private final GodotInputHandler mInputHandler;  	private final VkRenderer mRenderer; +	private final SparseArray<PointerIcon> customPointerIcons = new SparseArray<>();  	public GodotVulkanRenderView(Context context, Godot godot) {  		super(context); @@ -143,12 +151,49 @@ public class GodotVulkanRenderView extends VkSurfaceView implements GodotRenderV  	}  	/** +	 * Used to configure the PointerIcon for the given type. +	 * +	 * Called from JNI +	 */ +	@Keep +	@Override +	public void configurePointerIcon(int pointerType, String imagePath, float hotSpotX, float hotSpotY) { +		if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { +			try { +				Bitmap bitmap = null; +				if (!TextUtils.isEmpty(imagePath)) { +					if (godot.directoryAccessHandler.filesystemFileExists(imagePath)) { +						// Try to load the bitmap from the file system +						bitmap = BitmapFactory.decodeFile(imagePath); +					} else if (godot.directoryAccessHandler.assetsFileExists(imagePath)) { +						// Try to load the bitmap from the assets directory +						AssetManager am = getContext().getAssets(); +						InputStream imageInputStream = am.open(imagePath); +						bitmap = BitmapFactory.decodeStream(imageInputStream); +					} +				} + +				PointerIcon customPointerIcon = PointerIcon.create(bitmap, hotSpotX, hotSpotY); +				customPointerIcons.put(pointerType, customPointerIcon); +			} catch (Exception e) { +				// Reset the custom pointer icon +				customPointerIcons.delete(pointerType); +			} +		} +	} + +	/**  	 * called from JNI to change pointer icon  	 */  	@Keep +	@Override  	public void setPointerIcon(int pointerType) {  		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { -			setPointerIcon(PointerIcon.getSystemIcon(getContext(), pointerType)); +			PointerIcon pointerIcon = customPointerIcons.get(pointerType); +			if (pointerIcon == null) { +				pointerIcon = PointerIcon.getSystemIcon(getContext(), pointerType); +			} +			setPointerIcon(pointerIcon);  		}  	} diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java index 7925b54fc4..804dbaf165 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java @@ -127,7 +127,9 @@ public class GodotEditText extends EditText {  					edit.setText("");  					edit.append(text);  					if (msg.arg2 != -1) { -						edit.setSelection(msg.arg1, msg.arg2); +						int selectionStart = Math.min(msg.arg1, edit.length()); +						int selectionEnd = Math.min(msg.arg2, edit.length()); +						edit.setSelection(selectionStart, selectionEnd);  						edit.mInputWrapper.setSelection(true);  					} else {  						edit.mInputWrapper.setSelection(false); diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.kt b/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.kt index 9715c31fc1..cde8d7cdae 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotGestureHandler.kt @@ -55,18 +55,15 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi  	 */  	var panningAndScalingEnabled = false -	private var doubleTapInProgress = false +	private var nextDownIsDoubleTap = false  	private var dragInProgress = false  	private var scaleInProgress = false  	private var contextClickInProgress = false  	private var pointerCaptureInProgress = false  	override fun onDown(event: MotionEvent): Boolean { -		// Don't send / register a down event while we're in the middle of a double-tap -		if (!doubleTapInProgress) { -			// Send the down event -			GodotInputHandler.handleMotionEvent(event) -		} +		GodotInputHandler.handleMotionEvent(event.source, MotionEvent.ACTION_DOWN, event.buttonState, event.x, event.y, nextDownIsDoubleTap) +		nextDownIsDoubleTap = false  		return true  	} @@ -80,7 +77,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi  	}  	private fun contextClickRouter(event: MotionEvent) { -		if (scaleInProgress) { +		if (scaleInProgress || nextDownIsDoubleTap) {  			return  		} @@ -137,40 +134,24 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi  	}  	private fun onActionUp(event: MotionEvent): Boolean { +		if (event.actionMasked == MotionEvent.ACTION_CANCEL && pointerCaptureInProgress) { +			// Don't dispatch the ACTION_CANCEL while a capture is in progress +			return true +		} +  		val sourceMouseRelative = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {  			event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)  		} else {  			false  		} -		when { -			pointerCaptureInProgress -> { -				return if (event.actionMasked == MotionEvent.ACTION_CANCEL) { -					// Don't dispatch the ACTION_CANCEL while a capture is in progress -					true -				} else { -					GodotInputHandler.handleMouseEvent( -						MotionEvent.ACTION_UP, -						event.buttonState, -						event.x, -						event.y, -						0f, -						0f, -						false, -						sourceMouseRelative -					) -					pointerCaptureInProgress = false -					true -				} -			} -			dragInProgress -> { -				GodotInputHandler.handleMotionEvent(event) -				dragInProgress = false -				return true -			} -			contextClickInProgress -> { + +		if (pointerCaptureInProgress || dragInProgress || contextClickInProgress) { +			if (contextClickInProgress || GodotInputHandler.isMouseEvent(event)) { +				// This may be an ACTION_BUTTON_RELEASE event which we don't handle, +				// so we convert it to an ACTION_UP event.  				GodotInputHandler.handleMouseEvent( -					event.actionMasked, -					0, +					MotionEvent.ACTION_UP, +					event.buttonState,  					event.x,  					event.y,  					0f, @@ -178,11 +159,16 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi  					false,  					sourceMouseRelative  				) -				contextClickInProgress = false -				return true +			} else { +				GodotInputHandler.handleTouchEvent(event)  			} -			else -> return false +			pointerCaptureInProgress = false +			dragInProgress = false +			contextClickInProgress = false +			return true  		} + +		return false  	}  	private fun onActionMove(event: MotionEvent): Boolean { @@ -209,24 +195,14 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi  	override fun onDoubleTapEvent(event: MotionEvent): Boolean {  		if (event.actionMasked == MotionEvent.ACTION_UP) { -			doubleTapInProgress = false +			nextDownIsDoubleTap = false +			GodotInputHandler.handleMotionEvent(event)  		}  		return true  	}  	override fun onDoubleTap(event: MotionEvent): Boolean { -		doubleTapInProgress = true -		val x = event.x -		val y = event.y -		val buttonMask = -			if (GodotInputHandler.isMouseEvent(event)) { -				event.buttonState -			} else { -				MotionEvent.BUTTON_PRIMARY -			} -		GodotInputHandler.handleMouseEvent(MotionEvent.ACTION_DOWN, buttonMask, x, y, true) -		GodotInputHandler.handleMouseEvent(MotionEvent.ACTION_UP, 0, x, y, false) - +		nextDownIsDoubleTap = true  		return true  	} @@ -255,7 +231,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi  		val x = terminusEvent.x  		val y = terminusEvent.y -		if (terminusEvent.pointerCount >= 2 && panningAndScalingEnabled) { +		if (terminusEvent.pointerCount >= 2 && panningAndScalingEnabled && !pointerCaptureInProgress) {  			GodotLib.pan(x, y, distanceX / 5f, distanceY / 5f)  		} else {  			GodotInputHandler.handleMotionEvent(terminusEvent) @@ -264,7 +240,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi  	}  	override fun onScale(detector: ScaleGestureDetector?): Boolean { -		if (detector == null || !panningAndScalingEnabled) { +		if (detector == null || !panningAndScalingEnabled || pointerCaptureInProgress) {  			return false  		}  		GodotLib.magnify( @@ -276,7 +252,7 @@ internal class GodotGestureHandler : SimpleOnGestureListener(), OnScaleGestureLi  	}  	override fun onScaleBegin(detector: ScaleGestureDetector?): Boolean { -		if (detector == null || !panningAndScalingEnabled) { +		if (detector == null || !panningAndScalingEnabled || pointerCaptureInProgress) {  			return false  		}  		scaleInProgress = 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 03cb8034fa..0ba86e4316 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 @@ -245,7 +245,7 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {  				}  				return true;  			} -		} else if (isMouseEvent(event)) { +		} else {  			return handleMouseEvent(event);  		} @@ -422,7 +422,7 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {  	}  	private static boolean isMouseEvent(int eventSource) { -		boolean mouseSource = ((eventSource & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) || ((eventSource & InputDevice.SOURCE_STYLUS) == InputDevice.SOURCE_STYLUS); +		boolean mouseSource = ((eventSource & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) || ((eventSource & (InputDevice.SOURCE_TOUCHSCREEN | InputDevice.SOURCE_STYLUS)) == InputDevice.SOURCE_STYLUS);  		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {  			mouseSource = mouseSource || ((eventSource & InputDevice.SOURCE_MOUSE_RELATIVE) == InputDevice.SOURCE_MOUSE_RELATIVE);  		} @@ -438,15 +438,19 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {  	}  	static boolean handleMotionEvent(int eventSource, int eventAction, int buttonsMask, float x, float y) { -		return handleMotionEvent(eventSource, eventAction, buttonsMask, x, y, 0, 0); +		return handleMotionEvent(eventSource, eventAction, buttonsMask, x, y, false); +	} + +	static boolean handleMotionEvent(int eventSource, int eventAction, int buttonsMask, float x, float y, boolean doubleTap) { +		return handleMotionEvent(eventSource, eventAction, buttonsMask, x, y, 0, 0, doubleTap);  	} -	static boolean handleMotionEvent(int eventSource, int eventAction, int buttonsMask, float x, float y, float deltaX, float deltaY) { +	static boolean handleMotionEvent(int eventSource, int eventAction, int buttonsMask, float x, float y, float deltaX, float deltaY, boolean doubleTap) {  		if (isMouseEvent(eventSource)) { -			return handleMouseEvent(eventAction, buttonsMask, x, y, deltaX, deltaY, false, false); +			return handleMouseEvent(eventAction, buttonsMask, x, y, deltaX, deltaY, doubleTap, false);  		} -		return handleTouchEvent(eventAction, x, y); +		return handleTouchEvent(eventAction, x, y, doubleTap);  	}  	static boolean handleMouseEvent(final MotionEvent event) { @@ -468,11 +472,10 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {  		return handleMouseEvent(eventAction, buttonsMask, x, y, 0, 0, false, false);  	} -	static boolean handleMouseEvent(int eventAction, int buttonsMask, float x, float y, boolean doubleClick) { -		return handleMouseEvent(eventAction, buttonsMask, x, y, 0, 0, doubleClick, false); -	} -  	static boolean handleMouseEvent(int eventAction, int buttonsMask, float x, float y, float deltaX, float deltaY, boolean doubleClick, boolean sourceMouseRelative) { +		// We don't handle ACTION_BUTTON_PRESS and ACTION_BUTTON_RELEASE events as they typically +		// follow ACTION_DOWN and ACTION_UP events. As such, handling them would result in duplicate +		// stream of events to the engine.  		switch (eventAction) {  			case MotionEvent.ACTION_CANCEL:  			case MotionEvent.ACTION_UP: @@ -508,14 +511,14 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {  		final int action = event.getActionMasked();  		final int actionPointerId = event.getPointerId(event.getActionIndex()); -		return handleTouchEvent(action, actionPointerId, pointerCount, positions); +		return handleTouchEvent(action, actionPointerId, pointerCount, positions, false);  	} -	static boolean handleTouchEvent(int eventAction, float x, float y) { -		return handleTouchEvent(eventAction, 0, 1, new float[] { 0, x, y }); +	static boolean handleTouchEvent(int eventAction, float x, float y, boolean doubleTap) { +		return handleTouchEvent(eventAction, 0, 1, new float[] { 0, x, y }, doubleTap);  	} -	static boolean handleTouchEvent(int eventAction, int actionPointerId, int pointerCount, float[] positions) { +	static boolean handleTouchEvent(int eventAction, int actionPointerId, int pointerCount, float[] positions, boolean doubleTap) {  		switch (eventAction) {  			case MotionEvent.ACTION_DOWN:  			case MotionEvent.ACTION_CANCEL: @@ -523,7 +526,7 @@ public class GodotInputHandler implements InputManager.InputDeviceListener {  			case MotionEvent.ACTION_MOVE:  			case MotionEvent.ACTION_POINTER_UP:  			case MotionEvent.ACTION_POINTER_DOWN: { -				GodotLib.dispatchTouchEvent(eventAction, actionPointerId, pointerCount, positions); +				GodotLib.dispatchTouchEvent(eventAction, actionPointerId, pointerCount, positions, doubleTap);  				return true;  			}  		} diff --git a/platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt b/platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt index c9282dd247..1a3576a6a9 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt @@ -90,6 +90,11 @@ internal enum class StorageScope {  				return APP  			} +			var rootDir: String? = System.getenv("ANDROID_ROOT") +			if (rootDir != null && canonicalPathFile.startsWith(rootDir)) { +				return APP +			} +  			if (sharedDir != null && canonicalPathFile.startsWith(sharedDir)) {  				if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {  					// Before R, apps had access to shared storage so long as they have the right diff --git a/platform/android/java/lib/src/org/godotengine/godot/io/directory/DirectoryAccessHandler.kt b/platform/android/java/lib/src/org/godotengine/godot/io/directory/DirectoryAccessHandler.kt index fedcf4843f..6bc317415f 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/io/directory/DirectoryAccessHandler.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/io/directory/DirectoryAccessHandler.kt @@ -79,6 +79,9 @@ class DirectoryAccessHandler(context: Context) {  	private val assetsDirAccess = AssetsDirectoryAccess(context)  	private val fileSystemDirAccess = FilesystemDirectoryAccess(context) +	fun assetsFileExists(assetsPath: String) = assetsDirAccess.fileExists(assetsPath) +	fun filesystemFileExists(path: String) = fileSystemDirAccess.fileExists(path) +  	private fun hasDirId(accessType: AccessType, dirId: Int): Boolean {  		return when (accessType) {  			ACCESS_RESOURCES -> assetsDirAccess.hasDirId(dirId) diff --git a/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java index bb5042fa09..8ca5bcaa6e 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java +++ b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java @@ -71,11 +71,11 @@ import javax.microedition.khronos.opengles.GL10;   * - 'plugin.init.ClassFullName' is the full name (package + class name) of the plugin class   * extending {@link GodotPlugin}.   * - * A plugin can also define and provide c/c++ gdnative libraries and nativescripts for the target + * A plugin can also define and provide c/c++ gdextension libraries and nativescripts for the target   * app/game to leverage. - * The shared library for the gdnative library will be automatically bundled by the aar build + * The shared library for the gdextension library will be automatically bundled by the aar build   * system. - * Godot '*.gdnlib' and '*.gdns' resource files must however be manually defined in the project + * Godot '*.gdextension' resource files must however be manually defined in the project   * 'assets' directory. The recommended path for these resources in the 'assets' directory should be:   * 'godot/plugin/v1/[PluginName]/'   */ @@ -112,7 +112,7 @@ public abstract class GodotPlugin {  	public final void onRegisterPluginWithGodotNative() {  		registeredSignals.putAll(  				registerPluginWithGodotNative(this, getPluginName(), getPluginMethods(), getPluginSignals(), -						getPluginGDNativeLibrariesPaths())); +						getPluginGDExtensionLibrariesPaths()));  	}  	/** @@ -124,7 +124,7 @@ public abstract class GodotPlugin {  			GodotPluginInfoProvider pluginInfoProvider) {  		registerPluginWithGodotNative(pluginObject, pluginInfoProvider.getPluginName(),  				Collections.emptyList(), pluginInfoProvider.getPluginSignals(), -				pluginInfoProvider.getPluginGDNativeLibrariesPaths()); +				pluginInfoProvider.getPluginGDExtensionLibrariesPaths());  		// Notify that registration is complete.  		pluginInfoProvider.onPluginRegistered(); @@ -132,7 +132,7 @@ public abstract class GodotPlugin {  	private static Map<String, SignalInfo> registerPluginWithGodotNative(Object pluginObject,  			String pluginName, List<String> pluginMethods, Set<SignalInfo> pluginSignals, -			Set<String> pluginGDNativeLibrariesPaths) { +			Set<String> pluginGDExtensionLibrariesPaths) {  		nativeRegisterSingleton(pluginName, pluginObject);  		Set<Method> filteredMethods = new HashSet<>(); @@ -176,9 +176,9 @@ public abstract class GodotPlugin {  			registeredSignals.put(signalName, signalInfo);  		} -		// Get the list of gdnative libraries to register. -		if (!pluginGDNativeLibrariesPaths.isEmpty()) { -			nativeRegisterGDNativeLibraries(pluginGDNativeLibrariesPaths.toArray(new String[0])); +		// Get the list of gdextension libraries to register. +		if (!pluginGDExtensionLibrariesPaths.isEmpty()) { +			nativeRegisterGDExtensionLibraries(pluginGDExtensionLibrariesPaths.toArray(new String[0]));  		}  		return registeredSignals; @@ -304,12 +304,12 @@ public abstract class GodotPlugin {  	}  	/** -	 * Returns the paths for the plugin's gdnative libraries. +	 * Returns the paths for the plugin's gdextension libraries.  	 * -	 * The paths must be relative to the 'assets' directory and point to a '*.gdnlib' file. +	 * The paths must be relative to the 'assets' directory and point to a '*.gdextension' file.  	 */  	@NonNull -	protected Set<String> getPluginGDNativeLibrariesPaths() { +	protected Set<String> getPluginGDExtensionLibrariesPaths() {  		return Collections.emptySet();  	} @@ -420,10 +420,10 @@ public abstract class GodotPlugin {  	private static native void nativeRegisterMethod(String p_sname, String p_name, String p_ret, String[] p_params);  	/** -	 * Used to register gdnative libraries bundled by the plugin. -	 * @param gdnlibPaths Paths to the libraries relative to the 'assets' directory. +	 * Used to register gdextension libraries bundled by the plugin. +	 * @param gdextensionPaths Paths to the libraries relative to the 'assets' directory.  	 */ -	private static native void nativeRegisterGDNativeLibraries(String[] gdnlibPaths); +	private static native void nativeRegisterGDExtensionLibraries(String[] gdextensionPaths);  	/**  	 * Used to complete registration of the {@link GodotPlugin} instance's methods. diff --git a/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPluginInfoProvider.java b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPluginInfoProvider.java index cfb84c3931..53b78aebfb 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPluginInfoProvider.java +++ b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPluginInfoProvider.java @@ -54,12 +54,12 @@ public interface GodotPluginInfoProvider {  	}  	/** -	 * Returns the paths for the plugin's gdnative libraries (if any). +	 * Returns the paths for the plugin's gdextension libraries (if any).  	 * -	 * The paths must be relative to the 'assets' directory and point to a '*.gdnlib' file. +	 * The paths must be relative to the 'assets' directory and point to a '*.gdextension' file.  	 */  	@NonNull -	default Set<String> getPluginGDNativeLibrariesPaths() { +	default Set<String> getPluginGDExtensionLibrariesPaths() {  		return Collections.emptySet();  	} diff --git a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularConfigChooser.java b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularConfigChooser.java index 445238b1c2..9834fdfb88 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularConfigChooser.java +++ b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularConfigChooser.java @@ -45,20 +45,18 @@ public class RegularConfigChooser implements GLSurfaceView.EGLConfigChooser {  	private int[] mValue = new int[1]; -	// FIXME: Add support for Vulkan. - -	/* This EGL config specification is used to specify 2.0 rendering. +	/* This EGL config specification is used to specify 3.0 rendering.  	 * We use a minimum size of 4 bits for red/green/blue, but will  	 * perform actual matching in chooseConfig() below.  	 */  	private static int EGL_OPENGL_ES2_BIT = 4; -	private static int[] s_configAttribs2 = { +	private static int[] s_configAttribs = {  		EGL10.EGL_RED_SIZE, 4,  		EGL10.EGL_GREEN_SIZE, 4,  		EGL10.EGL_BLUE_SIZE, 4, -		//  EGL10.EGL_DEPTH_SIZE,     16, +		// EGL10.EGL_DEPTH_SIZE,     16,  		// EGL10.EGL_STENCIL_SIZE,   EGL10.EGL_DONT_CARE, -		EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, +		EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, //apparently there is no EGL_OPENGL_ES3_BIT  		EGL10.EGL_NONE  	}; @@ -75,7 +73,7 @@ public class RegularConfigChooser implements GLSurfaceView.EGLConfigChooser {  		/* Get the number of minimally matching EGL configurations  		 */  		int[] num_config = new int[1]; -		egl.eglChooseConfig(display, s_configAttribs2, null, 0, num_config); +		egl.eglChooseConfig(display, s_configAttribs, null, 0, num_config);  		int numConfigs = num_config[0]; @@ -86,7 +84,7 @@ public class RegularConfigChooser implements GLSurfaceView.EGLConfigChooser {  		/* Allocate then read the array of minimally matching EGL configs  		 */  		EGLConfig[] configs = new EGLConfig[numConfigs]; -		egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs, num_config); +		egl.eglChooseConfig(display, s_configAttribs, configs, numConfigs, num_config);  		if (GLUtils.DEBUG) {  			GLUtils.printConfigs(egl, display, configs); diff --git a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java index 5d62723170..8fb86bf6d0 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java +++ b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java @@ -52,17 +52,16 @@ public class RegularContextFactory implements GLSurfaceView.EGLContextFactory {  	private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;  	public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) { -		// FIXME: Add support for Vulkan. -		Log.w(TAG, "creating OpenGL ES 2.0 context :"); +		Log.w(TAG, "creating OpenGL ES 3.0 context :");  		GLUtils.checkEglError(TAG, "Before eglCreateContext", egl);  		EGLContext context;  		if (GLUtils.use_debug_opengl) { -			int[] attrib_list2 = { EGL_CONTEXT_CLIENT_VERSION, 2, _EGL_CONTEXT_FLAGS_KHR, _EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR, EGL10.EGL_NONE }; -			context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list2); +			int[] attrib_list = { 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, attrib_list);  		} else { -			int[] attrib_list2 = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE }; -			context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list2); +			int[] attrib_list = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL10.EGL_NONE }; +			context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);  		}  		GLUtils.checkEglError(TAG, "After eglCreateContext", egl);  		return context;  |