src: add some asserts on `super` related things
[nit.git] / src / android_platform.nit
index 7de42f4..8532cf8 100644 (file)
@@ -19,6 +19,7 @@ module android_platform
 import platform
 import abstract_compiler
 import common_ffi
+intrude import common_ffi::extra_java_files
 import android_annotations
 
 redef class ToolContext
@@ -104,6 +105,30 @@ class AndroidToolchain
                        if f isa ExternCFile then cfiles.add(f.filename.basename(""))
                end
 
+               # Is there an icon?
+               var resolutions = ["ldpi", "mdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi"]
+               var icon_available = false
+               for res in resolutions do
+                       var path = "res/drawable-{res}/icon.png"
+                       if path.file_exists then
+                               icon_available = true
+                               break
+                       end
+               end
+
+               var icon_declaration
+               if icon_available then
+                       icon_declaration = "android:icon=\"@drawable/icon\""
+               else icon_declaration = ""
+
+               # Also copy over the java files
+               dir = "{android_project_root}/src/"
+               var extra_java_files = compiler.mainmodule.extra_java_files
+               if extra_java_files != null then for file in extra_java_files do
+                       var path = file.filename
+                       path.file_copy_to("{dir}/{path.basename("")}")
+               end
+
                ## Generate delagating makefile
                dir = "{android_project_root}/jni/"
                """
@@ -138,10 +163,10 @@ $(call import-module,android/native_app_glue)
         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}}}" 
-        {{{app_max_api}}} /> 
+    <uses-sdk
+        android:minSdkVersion="{{{app_min_api}}}"
+        android:targetSdkVersion="{{{app_target_api}}}"
+        {{{app_max_api}}} />
 
     <application
                android:label="@string/app_name"
@@ -154,7 +179,8 @@ $(call import-module,android/native_app_glue)
                 android:label="@string/app_name"
                 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                 android:configChanges="orientation|keyboardHidden"
-                android:screenOrientation="portrait">
+                android:screenOrientation="portrait"
+                {{{icon_declaration}}}>
             <!-- Tell NativeActivity the name of or .so -->
             <meta-data android:name=\"{{{app_package}}}\"
                     android:value=\"{{{app_name}}}\" />
@@ -170,7 +196,7 @@ $(call import-module,android/native_app_glue)
 
 {{{project.manifest_lines.join("\n")}}}
 
-</manifest> 
+</manifest>
 <!-- END_INCLUDE(manifest) -->
                """.write_to_file("{dir}/AndroidManifest.xml")
 
@@ -206,7 +232,7 @@ $(call import-module,android/native_app_glue)
                                toolcontext.exec_and_check(["ln", "-s", assets_dir, target_assets_dir], "Android project error")
                        end
                end
-               
+
                ### copy resources  (for android)
                # This will be accessed from `android_project_root`
                var res_dir
@@ -218,14 +244,19 @@ $(call import-module,android/native_app_glue)
                        res_dir = "res"
                end
                if res_dir.file_exists then
+                       # copy the res folder to .nit_compile
                        res_dir = res_dir.realpath
                        var target_res_dir = "{android_project_root}"
-                       if target_res_dir.file_exists then
-                               # copy the res folder to .nit_compile
-                               toolcontext.exec_and_check(["cp", "-R", res_dir, target_res_dir], "Android project error")
-                       end
+                       toolcontext.exec_and_check(["cp", "-R", res_dir, target_res_dir], "Android project error")
                end
 
+               if not res_dir.file_exists or not "{res_dir}/values/strings.xml".file_exists then
+                       # Create our own custom `res/values/string.xml` with the App name
+"""<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="app_name">{{{app_name}}}</string>
+</resources>""".write_to_file "{dir}/res/values/strings.xml"
+               end
        end
 
        redef fun write_makefile(compiler, compile_dir, cfiles)
@@ -239,7 +270,7 @@ $(call import-module,android/native_app_glue)
                var release = toolcontext.opt_release.value
 
                # Compile C code (and thus Nit)
-               toolcontext.exec_and_check(["ndk-build", "-s", "-j", "4", "-C", android_project_root], "Android project error")
+               toolcontext.exec_and_check(["ndk-build", "-s", "-j", "-C", android_project_root], "Android project error")
 
                # Generate the apk
                var args = ["ant", "-q", "-f", android_project_root+"/build.xml"]