android: declare Activities for the manifest in an annotation
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 16 Mar 2015 18:11:49 +0000 (14:11 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Tue, 17 Mar 2015 21:12:50 +0000 (17:12 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/android/README.md
lib/android/aware.nit
lib/android/native_app_glue.nit
src/platform/android.nit
src/platform/android_annotations.nit

index 1f4e659..41f4830 100644 (file)
@@ -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
index 6740fe2..bb512d2 100644 (file)
@@ -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
index e713467..826eef2 100644 (file)
 #   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
index c04bd28..b411225 100644 (file)
@@ -181,14 +181,15 @@ $(call import-module,android/native_app_glue)
 
                ### generate AndroidManifest.xml
                dir = android_project_root
-               """<?xml version="1.0" encoding="utf-8"?>
+               var manifest_file = new FileWriter.open("{dir}/AndroidManifest.xml")
+               manifest_file.write """
+<?xml version="1.0" encoding="utf-8"?>
 <!-- BEGIN_INCLUDE(manifest) -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
         package="{{{app_package}}}"
         android:versionCode="{{{project.version_code}}}"
         android:versionName="{{{app_version}}}">
 
-    <!-- This is the platform API where NativeActivity was introduced. -->
     <uses-sdk
         android:minSdkVersion="{{{app_min_api}}}"
         android:targetSdkVersion="{{{app_target_api}}}"
@@ -200,22 +201,23 @@ $(call import-module,android/native_app_glue)
                android:debuggable="{{{not release}}}"
                {{{icon_declaration}}}
                android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation">
+"""
 
-        <!-- Our activity is the built-in NativeActivity framework class.
-             This will take care of integrating with our NDK code. -->
-        <activity android:name="android.app.NativeActivity"
+               for activity in project.activities do
+                       manifest_file.write """
+        <activity android:name="{{{activity}}}"
                 android:label="@string/app_name"
                 {{{project.manifest_activity_attributes.join("\n")}}}
                 {{{icon_declaration}}}>
-            <!-- Tell NativeActivity the name of our .so -->
-            <meta-data android:name=\"android.app.lib_name\"
-                    android:value=\"main\" />
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
+"""
+               end
 
+               manifest_file.write """
 {{{project.manifest_application_lines.join("\n")}}}
 
     </application>
@@ -224,7 +226,7 @@ $(call import-module,android/native_app_glue)
 
 </manifest>
 <!-- END_INCLUDE(manifest) -->
-               """.write_to_file("{dir}/AndroidManifest.xml")
+"""
 
                ### Link to png sources
                # libpng is not available on Android NDK
index 484c0a6..717c6ae 100644 (file)
@@ -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")