summaryrefslogtreecommitdiff
path: root/plugins/hello_world/src
diff options
context:
space:
mode:
authorFredia Huya-Kouadio <fhuya@meta.com>2023-07-14 13:46:24 -0700
committerFredia Huya-Kouadio <fhuya@meta.com>2023-07-14 13:46:24 -0700
commitb4844e98619766232645d70f80a29c2a53bc2709 (patch)
tree500a6deee2dfbd36f4356d69a2d5cb762314b03f /plugins/hello_world/src
parent1d19d5912d1ac5bfa3cf6cc30f086aee8f0464f2 (diff)
downloadgodot-android-samples-b4844e98619766232645d70f80a29c2a53bc2709.tar.gz
godot-android-samples-b4844e98619766232645d70f80a29c2a53bc2709.tar.bz2
godot-android-samples-b4844e98619766232645d70f80a29c2a53bc2709.zip
Update the directory structure to make room for additional Godot Android samples besides plugins
Diffstat (limited to 'plugins/hello_world/src')
-rw-r--r--plugins/hello_world/src/main/AndroidManifest.xml20
-rw-r--r--plugins/hello_world/src/main/java/fhuyakou/godot/plugin/android/helloworld/HelloWorldPlugin.java49
-rw-r--r--plugins/hello_world/src/main/res/layout/hello_world_view.xml16
-rw-r--r--plugins/hello_world/src/main/res/values/strings.xml4
4 files changed, 89 insertions, 0 deletions
diff --git a/plugins/hello_world/src/main/AndroidManifest.xml b/plugins/hello_world/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..8bb5fa4
--- /dev/null
+++ b/plugins/hello_world/src/main/AndroidManifest.xml
@@ -0,0 +1,20 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="fhuyakou.godot.plugin.android.helloworld">
+
+ <application>
+ <!--
+ Plugin metadata:
+
+ - In the `android:name` attribute, the `org.godotengine.plugin.v1` prefix
+ is required so Godot can recognize the project as a valid Godot
+ Android plugin. The plugin name following the prefix should match the value
+ of the plugin name returned by the plugin initializer.
+
+ - The `android:value` attribute should be the classpath to the plugin
+ initializer.
+ -->
+ <meta-data
+ android:name="org.godotengine.plugin.v1.HelloWorld"
+ android:value="fhuyakou.godot.plugin.android.helloworld.HelloWorldPlugin" />
+ </application>
+</manifest>
diff --git a/plugins/hello_world/src/main/java/fhuyakou/godot/plugin/android/helloworld/HelloWorldPlugin.java b/plugins/hello_world/src/main/java/fhuyakou/godot/plugin/android/helloworld/HelloWorldPlugin.java
new file mode 100644
index 0000000..1dfa1b2
--- /dev/null
+++ b/plugins/hello_world/src/main/java/fhuyakou/godot/plugin/android/helloworld/HelloWorldPlugin.java
@@ -0,0 +1,49 @@
+package fhuyakou.godot.plugin.android.helloworld;
+
+import android.app.Activity;
+import android.view.View;
+import org.godotengine.godot.Godot;
+import org.godotengine.godot.plugin.GodotPlugin;
+import org.godotengine.godot.plugin.UsedByGodot;
+
+public class HelloWorldPlugin extends GodotPlugin {
+
+ private static final String HELLO_WORLD = "Hello World";
+
+ private View helloWorldContainer;
+
+ public HelloWorldPlugin(Godot godot) {
+ super(godot);
+ }
+
+ @Override
+ public String getPluginName() {
+ return "HelloWorld";
+ }
+
+ @Override
+ public View onMainCreate(Activity activity) {
+ View view = activity.getLayoutInflater().inflate(R.layout.hello_world_view, null);
+ helloWorldContainer = view.findViewById(R.id.hello_world_container);
+ return view;
+ }
+
+ /**
+ * Show/hide, print and return "Hello World".
+ */
+ @UsedByGodot
+ public String helloWorld() {
+ if (helloWorldContainer != null) {
+ helloWorldContainer.post(() -> {
+ if (helloWorldContainer.getVisibility() == View.VISIBLE) {
+ helloWorldContainer.setVisibility(View.GONE);
+ } else {
+ helloWorldContainer.setVisibility(View.VISIBLE);
+ }
+ });
+ }
+
+ System.out.println(HELLO_WORLD);
+ return HELLO_WORLD;
+ }
+}
diff --git a/plugins/hello_world/src/main/res/layout/hello_world_view.xml b/plugins/hello_world/src/main/res/layout/hello_world_view.xml
new file mode 100644
index 0000000..e831d87
--- /dev/null
+++ b/plugins/hello_world/src/main/res/layout/hello_world_view.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/hello_world_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:visibility="gone">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:padding="10dp"
+ android:text="@string/hello_world"
+ android:textSize="20sp" />
+
+</FrameLayout> \ No newline at end of file
diff --git a/plugins/hello_world/src/main/res/values/strings.xml b/plugins/hello_world/src/main/res/values/strings.xml
new file mode 100644
index 0000000..d2cf3ac
--- /dev/null
+++ b/plugins/hello_world/src/main/res/values/strings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="hello_world">Hello World</string>
+</resources> \ No newline at end of file