From 34c1e5415bb56ba9e05a5d9ce836d9038cb21468 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Mon, 16 Mar 2015 14:11:49 -0400 Subject: [PATCH] android: declare Activities for the manifest in an annotation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/android/README.md | 5 +++++ lib/android/aware.nit | 1 + lib/android/native_app_glue.nit | 5 ++++- src/platform/android.nit | 20 +++++++++++--------- src/platform/android_annotations.nit | 9 +++++++++ 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/android/README.md b/lib/android/README.md index 1f4e659..41f4830 100644 --- a/lib/android/README.md +++ b/lib/android/README.md @@ -54,6 +54,11 @@ integer as argument. They are applied in the Android manifest as See http://developer.android.com/guide/topics/manifest/uses-sdk-element.html +* The annotation `android_activity` defines a Java class used as an + entrypoint to your application. As of now, this annotation should + only be used by low level implementations of Nit on Android. + It's usefulness will be extended in the future to customize user applications. + ## Project entry points Importing `android::landscape` or `android::portrait` locks the generated diff --git a/lib/android/aware.nit b/lib/android/aware.nit index 6740fe2..bb512d2 100644 --- a/lib/android/aware.nit +++ b/lib/android/aware.nit @@ -27,4 +27,5 @@ module aware is new_annotation android_manifest new_annotation android_manifest_application new_annotation android_manifest_activity + new_annotation android_activity end diff --git a/lib/android/native_app_glue.nit b/lib/android/native_app_glue.nit index e713467..826eef2 100644 --- a/lib/android/native_app_glue.nit +++ b/lib/android/native_app_glue.nit @@ -36,7 +36,10 @@ # which is a subclass of `Activity` and `Context` (in Java). It represent # main activity of the running application. Use it to get anything related # to the `Context` and as anchor to execute Java UI code. -module native_app_glue is ldflags "-landroid" +module native_app_glue is + ldflags "-landroid" + android_activity "android.app.NativeActivity" +end import platform import log diff --git a/src/platform/android.nit b/src/platform/android.nit index c04bd28..b411225 100644 --- a/src/platform/android.nit +++ b/src/platform/android.nit @@ -181,14 +181,15 @@ $(call import-module,android/native_app_glue) ### generate AndroidManifest.xml dir = android_project_root - """ + var manifest_file = new FileWriter.open("{dir}/AndroidManifest.xml") + manifest_file.write """ + - +""" - - - - +""" + end + manifest_file.write """ {{{project.manifest_application_lines.join("\n")}}} @@ -224,7 +226,7 @@ $(call import-module,android/native_app_glue) - """.write_to_file("{dir}/AndroidManifest.xml") +""" ### Link to png sources # libpng is not available on Android NDK diff --git a/src/platform/android_annotations.nit b/src/platform/android_annotations.nit index 484c0a6..717c6ae 100644 --- a/src/platform/android_annotations.nit +++ b/src/platform/android_annotations.nit @@ -56,6 +56,9 @@ class AndroidProject # Maximum API level on which the application will be allowed to run var max_api: nullable Int = null + # Activities to declare in the manifest + var activities = new Array[String] + redef fun to_s do return """ name: {{{name or else "null"}}} namespace: {{{java_package or else "null"}}} @@ -113,6 +116,12 @@ redef class ModelBuilder annots = collect_annotations_on_modules("android_manifest_activity", mmodule) for an in annots do project.manifest_activity_attributes.add an.arg_as_string(self) or else "" + annots = collect_annotations_on_modules("android_activity", mmodule) + for an in annots do + var activity = an.arg_as_string(self) + if activity != null then project.activities.add activity + end + # Get the date and time (down to the minute) as string var local_time = new Tm.localtime var local_time_s = local_time.strftime("%y%m%d%H%M") -- 1.7.9.5