From b4844e98619766232645d70f80a29c2a53bc2709 Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Fri, 14 Jul 2023 13:46:24 -0700 Subject: Update the directory structure to make room for additional Godot Android samples besides plugins --- plugins/hello_world/src/main/AndroidManifest.xml | 20 +++++++++ .../android/helloworld/HelloWorldPlugin.java | 49 ++++++++++++++++++++++ .../src/main/res/layout/hello_world_view.xml | 16 +++++++ .../hello_world/src/main/res/values/strings.xml | 4 ++ 4 files changed, 89 insertions(+) create mode 100644 plugins/hello_world/src/main/AndroidManifest.xml create mode 100644 plugins/hello_world/src/main/java/fhuyakou/godot/plugin/android/helloworld/HelloWorldPlugin.java create mode 100644 plugins/hello_world/src/main/res/layout/hello_world_view.xml create mode 100644 plugins/hello_world/src/main/res/values/strings.xml (limited to 'plugins/hello_world/src') 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 @@ + + + + + + + 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 @@ + + + + + + \ 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 @@ + + + Hello World + \ No newline at end of file -- cgit v1.2.3