/
App.java
138 lines (122 loc) Β· 4.33 KB
/
App.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by
* Appcelerator. It should not be modified by hand.
*/
package <%= appid %>;
import org.appcelerator.kroll.runtime.v8.V8Runtime;
import org.appcelerator.kroll.KrollExternalModule;
import org.appcelerator.kroll.common.KrollSourceCodeProvider;
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.KrollModuleInfo;
import org.appcelerator.kroll.KrollRuntime;
import org.appcelerator.kroll.util.KrollAssetCache;
import org.appcelerator.kroll.util.KrollAssetHelper;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiRootActivity;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import android.util.Log;
public final class <%= classname %>Application extends TiApplication
{
private static final String TAG = "<%= classname %>Application";
@Override
@SuppressWarnings("unchecked")
public void onCreate()
{
appInfo = new <%= classname %>AppInfo(this);
<% if (encryptJS) { %>
KrollAssetHelper.setAssetCrypt(new AssetCryptImpl());
<% } %>
// Load cache as soon as possible.
KrollAssetCache.init(this);
super.onCreate();
V8Runtime runtime = new V8Runtime();
<% customModules.forEach(function (module) { %>
{
<% if ((typeof module.manifest.minsdk === 'string') && (parseInt(module.manifest.minsdk.split('.')[0]) >= 9)) { %>
String className = "<%- module.manifest.moduleid %>.TiModuleBootstrap";
<% } else { %>
String className = "<%- module.manifest.moduleid %>.<%- module.apiName %>Bootstrap";
<% } %>
try {
runtime.addExternalModule(
"<%- module.manifest.moduleid %>",
(Class<KrollExternalModule>) Class.forName(className));
} catch (Throwable ex) {
Log.e(TAG, "Failed to add external module: " + className);
if ((ex instanceof RuntimeException) == false) {
ex = new RuntimeException(ex);
}
throw (RuntimeException) ex;
}
}
<% if (module.isNativeJsModule) { %>
{
String className = "<%- module.manifest.moduleid %>.CommonJsSourceProvider";
try {
runtime.addExternalCommonJsModule(
"<%- module.manifest.moduleid %>",
(Class<KrollSourceCodeProvider>) Class.forName(className));
} catch (Throwable ex) {
Log.e(TAG, "Failed to add external CommonJS module: " + className);
if ((ex instanceof RuntimeException) == false) {
ex = new RuntimeException(ex);
}
throw (RuntimeException) ex;
}
}
<% } %>
<% }); %>
KrollRuntime.init(this, runtime);
postAppInfo();
postOnCreate();
<% if (customModules.length) { %>
// Custom modules
KrollModuleInfo moduleInfo;
<% customModules.forEach(function (module) { %>
<% if (module.onAppCreate) { %>
{
String className = "<%- module.className %>";
String methodName = "<%- module.onAppCreate %>";
try {
Class moduleClass = Class.forName(className);
Method moduleMethod = moduleClass.getMethod(methodName, TiApplication.class);
moduleMethod.invoke(null, this);
} catch (Throwable ex) {
Log.e(TAG, "Error invoking: " + className + "." + methodName + "()");
if ((ex instanceof InvocationTargetException) && (ex.getCause() != null)) {
ex = ex.getCause();
}
if ((ex instanceof RuntimeException) == false) {
ex = new RuntimeException(ex);
}
throw (RuntimeException) ex;
}
}
<% } %>
moduleInfo = new KrollModuleInfo(
"<%- module.manifest.name %>", "<%- module.manifest.moduleid %>", "<%- module.manifest.guid %>", "<%- module.manifest.version %>",
"<%- (module.manifest.description || '').replace(/\\/g, '\\\\').replace(/\x22/g, '\\\x22') %>",
"<%- (module.manifest.author || '').replace(/\\/g, '\\\\').replace(/\x22/g, '\\\x22') %>",
"<%- (module.manifest.license || '').replace(/\\/g, '\\\\').replace(/\x22/g, '\\\x22') %>",
"<%- (module.manifest.copyright || '').replace(/\\/g, '\\\\').replace(/\x22/g, '\\\x22') %>");
<% if (module.manifest.licensekey) { %>
moduleInfo.setLicenseKey("<%- module.manifest.licensekey %>");
<% } %>
<% if (module.isNativeJsModule) { %>
moduleInfo.setIsJSModule(true);
<% } %>
KrollModule.addCustomModuleInfo(moduleInfo);
<% }); %>
<% } %>
}
@Override
public void verifyCustomModules(TiRootActivity rootActivity)
{
// This method is needed by the "appc" CLI.
}
}