diff options
Diffstat (limited to 'hello_world/plugin')
-rw-r--r-- | hello_world/plugin/.gitignore | 1 | ||||
-rw-r--r-- | hello_world/plugin/build.gradle | 34 | ||||
-rw-r--r-- | hello_world/plugin/libs/godot-lib.release.aar | bin | 0 -> 9139166 bytes | |||
-rw-r--r-- | hello_world/plugin/src/main/AndroidManifest.xml | 20 | ||||
-rw-r--r-- | hello_world/plugin/src/main/java/fhuyakou/godot/plugin/android/helloworld/HelloWorldPlugin.java | 57 | ||||
-rw-r--r-- | hello_world/plugin/src/main/res/layout/hello_world_view.xml | 16 | ||||
-rw-r--r-- | hello_world/plugin/src/main/res/values/strings.xml | 4 |
7 files changed, 132 insertions, 0 deletions
diff --git a/hello_world/plugin/.gitignore b/hello_world/plugin/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/hello_world/plugin/.gitignore @@ -0,0 +1 @@ +/build diff --git a/hello_world/plugin/build.gradle b/hello_world/plugin/build.gradle new file mode 100644 index 0000000..2d1e7fa --- /dev/null +++ b/hello_world/plugin/build.gradle @@ -0,0 +1,34 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.1" + + defaultConfig { + minSdkVersion 18 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + } + + // Used to customize the name of generated AAR file. + libraryVariants.all { variant -> + variant.outputs.all { output -> + output.outputFileName = "HelloWorld.${variant.name}.aar" + } + } + +} + +dependencies { + /* + Used to provide dependency on the Godot Android library. A version of that + library will be made available for each stable release of Godot. + + `compileOnly` is used instead of `implementation` to ensure that the + godot library is not bundled with the generated plugin AAR file. This is + necessary since the Godot editor will also provide a version of the godot + library when building the final binary. + */ + compileOnly fileTree(dir: 'libs', include: ['godot-lib*.aar']) +} diff --git a/hello_world/plugin/libs/godot-lib.release.aar b/hello_world/plugin/libs/godot-lib.release.aar Binary files differnew file mode 100644 index 0000000..ee116a4 --- /dev/null +++ b/hello_world/plugin/libs/godot-lib.release.aar diff --git a/hello_world/plugin/src/main/AndroidManifest.xml b/hello_world/plugin/src/main/AndroidManifest.xml new file mode 100644 index 0000000..63ec50f --- /dev/null +++ b/hello_world/plugin/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.v2` 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.v2.HelloWorld" + android:value="fhuyakou.godot.plugin.android.helloworld.HelloWorldPlugin" /> + </application> +</manifest> diff --git a/hello_world/plugin/src/main/java/fhuyakou/godot/plugin/android/helloworld/HelloWorldPlugin.java b/hello_world/plugin/src/main/java/fhuyakou/godot/plugin/android/helloworld/HelloWorldPlugin.java new file mode 100644 index 0000000..fe0a319 --- /dev/null +++ b/hello_world/plugin/src/main/java/fhuyakou/godot/plugin/android/helloworld/HelloWorldPlugin.java @@ -0,0 +1,57 @@ +package fhuyakou.godot.plugin.android.helloworld; + +import android.app.Activity; +import android.view.View; +import java.util.Collections; +import java.util.List; +import org.godotengine.godot.Godot; +import org.godotengine.godot.plugin.GodotPlugin; + +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 List<String> getPluginMethods() { + return Collections.singletonList("helloWorld"); + } + + @Override + public View onMainCreateView(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". + */ + public String helloWorld() { + if (helloWorldContainer != null) { + helloWorldContainer.post(new Runnable() { + @Override + public void run() { + 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/hello_world/plugin/src/main/res/layout/hello_world_view.xml b/hello_world/plugin/src/main/res/layout/hello_world_view.xml new file mode 100644 index 0000000..e831d87 --- /dev/null +++ b/hello_world/plugin/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/hello_world/plugin/src/main/res/values/strings.xml b/hello_world/plugin/src/main/res/values/strings.xml new file mode 100644 index 0000000..d2cf3ac --- /dev/null +++ b/hello_world/plugin/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 |