]> git.tdb.fi Git - builder.git/blob - source/androidmanifestgenerator.cpp
Inline simple constructors
[builder.git] / source / androidmanifestgenerator.cpp
1 #include <msp/io/file.h>
2 #include <msp/io/print.h>
3 #include "androidmanifestfile.h"
4 #include "androidmanifestgenerator.h"
5 #include "component.h"
6 #include "sharedlibrary.h"
7 #include "sourcepackage.h"
8
9 using namespace std;
10 using namespace Msp;
11
12 Target *AndroidManifestGenerator::create_target(const vector<Target *> &, const string &)
13 {
14         throw logic_error("not implemented");
15 }
16
17 Task *AndroidManifestGenerator::run(const Target &target) const
18 {
19         const AndroidManifestFile &manifest = dynamic_cast<const AndroidManifestFile &>(target);
20         Worker *worker = new Worker(manifest);
21         return new InternalTask(worker);
22 }
23
24
25 void AndroidManifestGenerator::Worker::main()
26 {
27         const Component &comp = *manifest.get_component();
28         const SourcePackage &pkg = comp.get_package();
29
30         BuildInfo binfo;
31         manifest.collect_build_info(binfo);
32
33         IO::BufferedFile out(manifest.get_path().str(), IO::M_WRITE);
34         out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
35         IO::print(out, "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\" package=\"%s\">\n", comp.get_name());
36         out.write("\t<uses-sdk android:minSdkVersion=\"9\" />\n");
37         // TODO Make the icon name configurable
38         bool debuggable = binfo.debug;
39         IO::print(out, "\t<application android:icon=\"@drawable/icon\" android:label=\"%s\" android:hasCode=\"false\" android:debuggable=\"%s\">\n", pkg.get_label(), debuggable);
40         if(SharedLibrary *native_lib = manifest.get_native_library())
41         {
42                 out.write("\t\t<activity android:name=\"android.app.NativeActivity\"");
43                 const string &orientation = manifest.get_orientation();
44                 if(!orientation.empty())
45                         IO::print(out, " android:screenOrientation=\"%s\"", orientation);
46                 out.write(">\n");
47                 IO::print(out, "\t\t\t<meta-data android:name=\"android.app.lib_name\" android:value=\"%s\" />\n", native_lib->get_libname());
48                 out.write("\t\t\t<intent-filter>\n");
49                 out.write("\t\t\t\t<action android:name=\"android.intent.action.MAIN\" />\n");
50                 out.write("\t\t\t\t<category android:name=\"android.intent.category.LAUNCHER\" />\n");
51                 out.write("\t\t\t</intent-filter>\n");
52                 out.write("\t\t</activity>\n");
53         }
54         out.write("\t</application>\n");
55         for(const string &p: manifest.get_permissions())
56                 IO::print(out, "\t<uses-permission android:name=\"%s\" />\n", p);
57         out.write("</manifest>\n");
58
59         status = Task::SUCCESS;
60 }