summaryrefslogtreecommitdiffstats
path: root/platform/android/java/lib
diff options
context:
space:
mode:
authorSpartan322 <Megacake1234@gmail.com>2024-10-30 05:22:24 -0400
committerSpartan322 <Megacake1234@gmail.com>2024-10-30 05:22:24 -0400
commit82de309d58c5f0e221b85463cca2983cd7ed0289 (patch)
tree5c87dc486c61310a1eafc2e7cb2fd52be0d52e22 /platform/android/java/lib
parent77eaec766e2e40f2a5d399989d827f9582a3be15 (diff)
parent8004c7524fb9f43425c4d6f614410a76678e0f7c (diff)
downloadredot-engine-82de309d58c5f0e221b85463cca2983cd7ed0289.tar.gz
Merge commit godotengine/godot@8004c7524fb9f43425c4d6f614410a76678e0f7c
Diffstat (limited to 'platform/android/java/lib')
-rw-r--r--platform/android/java/lib/res/values/dimens.xml2
-rw-r--r--platform/android/java/lib/res/values/strings.xml3
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/Godot.kt47
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotIO.java23
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotLib.java5
5 files changed, 76 insertions, 4 deletions
diff --git a/platform/android/java/lib/res/values/dimens.xml b/platform/android/java/lib/res/values/dimens.xml
index 9034dbbcc1..287d1c8920 100644
--- a/platform/android/java/lib/res/values/dimens.xml
+++ b/platform/android/java/lib/res/values/dimens.xml
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_edit_height">48dp</dimen>
+ <dimen name="input_dialog_padding_horizontal">10dp</dimen>
+ <dimen name="input_dialog_padding_vertical">5dp</dimen>
</resources>
diff --git a/platform/android/java/lib/res/values/strings.xml b/platform/android/java/lib/res/values/strings.xml
index 03752e092e..e44addadd0 100644
--- a/platform/android/java/lib/res/values/strings.xml
+++ b/platform/android/java/lib/res/values/strings.xml
@@ -55,4 +55,7 @@
<string name="kilobytes_per_second">%1$s KB/s</string>
<string name="time_remaining">Time remaining: %1$s</string>
<string name="time_remaining_notification">%1$s left</string>
+
+ <!-- Labels for the dialog action buttons -->
+ <string name="dialog_ok">OK</string>
</resources>
diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt
index d20c5c90db..508c0a30ce 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt
+++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt
@@ -46,6 +46,7 @@ import android.os.*
import android.util.Log
import android.util.TypedValue
import android.view.*
+import android.widget.EditText
import android.widget.FrameLayout
import androidx.annotation.Keep
import androidx.annotation.StringRes
@@ -83,6 +84,7 @@ import java.util.*
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference
+
/**
* Core component used to interface with the native layer of the engine.
*
@@ -479,12 +481,17 @@ class Godot(private val context: Context) {
// ...add to FrameLayout
containerLayout?.addView(editText)
renderView = if (usesVulkan()) {
- if (!meetsVulkanRequirements(activity.packageManager)) {
+ if (meetsVulkanRequirements(activity.packageManager)) {
+ GodotVulkanRenderView(host, this, godotInputHandler)
+ } else if (canFallbackToOpenGL()) {
+ // Fallback to OpenGl.
+ GodotGLRenderView(host, this, godotInputHandler, xrMode, useDebugOpengl)
+ } else {
throw IllegalStateException(activity.getString(R.string.error_missing_vulkan_requirements_message))
}
- GodotVulkanRenderView(host, this, godotInputHandler)
+
} else {
- // Fallback to openGl
+ // Fallback to OpenGl.
GodotGLRenderView(host, this, godotInputHandler, xrMode, useDebugOpengl)
}
@@ -774,7 +781,7 @@ class Godot(private val context: Context) {
val builder = AlertDialog.Builder(activity)
builder.setMessage(message).setTitle(title)
builder.setPositiveButton(
- "OK"
+ R.string.dialog_ok
) { dialog: DialogInterface, id: Int ->
okCallback?.run()
dialog.cancel()
@@ -819,6 +826,13 @@ class Godot(private val context: Context) {
}
/**
+ * Returns true if can fallback to OpenGL.
+ */
+ private fun canFallbackToOpenGL(): Boolean {
+ return java.lang.Boolean.parseBoolean(GodotLib.getGlobal("rendering/rendering_device/fallback_to_opengl3"))
+ }
+
+ /**
* Returns true if the device meets the base requirements for Vulkan support, false otherwise.
*/
private fun meetsVulkanRequirements(packageManager: PackageManager?): Boolean {
@@ -879,6 +893,31 @@ class Godot(private val context: Context) {
}
/**
+ * Popup a dialog to input text.
+ */
+ @Keep
+ private fun showInputDialog(title: String, message: String, existingText: String) {
+ val activity: Activity = getActivity() ?: return
+ val inputField = EditText(activity)
+ val paddingHorizontal = activity.resources.getDimensionPixelSize(R.dimen.input_dialog_padding_horizontal)
+ val paddingVertical = activity.resources.getDimensionPixelSize(R.dimen.input_dialog_padding_vertical)
+ inputField.setPadding(paddingHorizontal, paddingVertical, paddingHorizontal, paddingVertical)
+ inputField.setText(existingText)
+ runOnUiThread {
+ val builder = AlertDialog.Builder(activity)
+ builder.setMessage(message).setTitle(title).setView(inputField)
+ builder.setPositiveButton(R.string.dialog_ok) {
+ dialog: DialogInterface, id: Int ->
+ GodotLib.inputDialogCallback(inputField.text.toString())
+ dialog.dismiss()
+ }
+ val dialog = builder.create()
+ dialog.show()
+ }
+ }
+
+
+ /**
* Destroys the Godot Engine and kill the process it's running in.
*/
@JvmOverloads
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 542c93d4e2..44102c5d9c 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java
@@ -49,6 +49,7 @@ import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.DisplayCutout;
+import android.view.Surface;
import android.view.WindowInsets;
import androidx.core.content.FileProvider;
@@ -297,6 +298,28 @@ public class GodotIO {
}
}
+ /**
+ This function is used by DisplayServer::screen_get_internal_current_rotation (C++)
+ and is used to implement a performance optimization in devices that do not offer
+ a HW rotator.
+ @return
+ Rotation in degrees, in multiples of 90°
+ */
+ public int getInternalCurrentScreenRotation() {
+ int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
+
+ switch (rotation) {
+ case Surface.ROTATION_90:
+ return 90;
+ case Surface.ROTATION_180:
+ return 180;
+ case Surface.ROTATION_270:
+ return 270;
+ default:
+ return 0;
+ }
+ }
+
public void setEdit(GodotEditText _edit) {
edit = _edit;
}
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 a6b02a96bd..b7adc96196 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
@@ -227,6 +227,11 @@ public class GodotLib {
public static native void onNightModeChanged();
/**
+ * Invoked on the input dialog submitted.
+ */
+ public static native void inputDialogCallback(String p_text);
+
+ /**
* Invoked on the GL thread to configure the height of the virtual keyboard.
*/
public static native void setVirtualKeyboardHeight(int p_height);