diff options
author | Thaddeus Crews <repiteo@outlook.com> | 2024-10-29 19:25:37 -0500 |
---|---|---|
committer | Thaddeus Crews <repiteo@outlook.com> | 2024-10-29 19:25:37 -0500 |
commit | 08d8909a655ff190a3807171f5a75982881dd6bb (patch) | |
tree | 8ec7caa0991c615e7030cac64075bd288628faf9 /platform/android/java/lib | |
parent | b7a0971ad2d168e31d9a3ba93bbc59865bb1c337 (diff) | |
parent | be5d7f757d70596f628c9ac8a3cba8412cc34fa7 (diff) | |
download | redot-engine-08d8909a655ff190a3807171f5a75982881dd6bb.tar.gz |
Merge pull request #98574 from syntaxerror247/android_input_dialog
[Android] Implement native input dialog support
Diffstat (limited to 'platform/android/java/lib')
4 files changed, 38 insertions, 1 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 567b134234..f4b9771128 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt @@ -44,6 +44,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 @@ -81,6 +82,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. * @@ -772,7 +774,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() @@ -877,6 +879,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/GodotLib.java b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java index 295a4a6340..3c58e05dda 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java @@ -225,6 +225,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); |