mobile_template 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +28 -0
  5. data/Rakefile +3 -0
  6. data/bin/mobile_template +71 -0
  7. data/lib/mobile_template/version.rb +4 -0
  8. data/lib/mobile_template.rb +5 -0
  9. data/mobile_template.gemspec +21 -0
  10. data/templates/assets/Gemfile +4 -0
  11. data/templates/assets/config.rb +96 -0
  12. data/templates/assets/config.ru +4 -0
  13. data/templates/assets/source/images/vendor/ajax-loader.gif +0 -0
  14. data/templates/assets/source/images/vendor/ajax-loader.png +0 -0
  15. data/templates/assets/source/images/vendor/icons-18-black.png +0 -0
  16. data/templates/assets/source/images/vendor/icons-18-white.png +0 -0
  17. data/templates/assets/source/images/vendor/icons-36-black.png +0 -0
  18. data/templates/assets/source/images/vendor/icons-36-white.png +0 -0
  19. data/templates/assets/source/index.html.erb +2 -0
  20. data/templates/assets/source/javascripts/app/index.js.coffee +2 -0
  21. data/templates/assets/source/javascripts/application.js.coffee +5 -0
  22. data/templates/assets/source/javascripts/vendor/cordova.js +4841 -0
  23. data/templates/assets/source/javascripts/vendor/jquery.js +9267 -0
  24. data/templates/assets/source/javascripts/vendor/jquery.mobile.js +7410 -0
  25. data/templates/assets/source/layout.erb +24 -0
  26. data/templates/assets/source/stylesheets/application.css.scss +2 -0
  27. data/templates/assets/source/stylesheets/vendor/jquery.mobile.css.scss +1872 -0
  28. data/templates/cordova_android/.gitignore +18 -0
  29. data/templates/cordova_android/LICENSE +202 -0
  30. data/templates/cordova_android/NOTICE +5 -0
  31. data/templates/cordova_android/README.md +95 -0
  32. data/templates/cordova_android/VERSION +1 -0
  33. data/templates/cordova_android/bin/BOOM +4 -0
  34. data/templates/cordova_android/bin/autotest +2 -0
  35. data/templates/cordova_android/bin/bench +29 -0
  36. data/templates/cordova_android/bin/create +46 -0
  37. data/templates/cordova_android/bin/create.bat +1 -0
  38. data/templates/cordova_android/bin/create.js +88 -0
  39. data/templates/cordova_android/bin/create.xml +79 -0
  40. data/templates/cordova_android/bin/node_modules/.bin/cake +7 -0
  41. data/templates/cordova_android/bin/node_modules/.bin/coffee +7 -0
  42. data/templates/cordova_android/bin/node_modules/.bin/nodeunit +120 -0
  43. data/templates/cordova_android/bin/node_modules/coffee-script/.npmignore +11 -0
  44. data/templates/cordova_android/bin/node_modules/coffee-script/LICENSE +22 -0
  45. data/templates/cordova_android/bin/node_modules/coffee-script/README +48 -0
  46. data/templates/cordova_android/bin/node_modules/coffee-script/Rakefile +78 -0
  47. data/templates/cordova_android/bin/node_modules/coffee-script/bin/cake +7 -0
  48. data/templates/cordova_android/bin/node_modules/coffee-script/bin/coffee +7 -0
  49. data/templates/cordova_android/bin/node_modules/coffee-script/extras/jsl.conf +44 -0
  50. data/templates/cordova_android/bin/node_modules/coffee-script/lib/browser.js +75 -0
  51. data/templates/cordova_android/bin/node_modules/coffee-script/lib/cake.js +76 -0
  52. data/templates/cordova_android/bin/node_modules/coffee-script/lib/coffee-script.js +135 -0
  53. data/templates/cordova_android/bin/node_modules/coffee-script/lib/command.js +301 -0
  54. data/templates/cordova_android/bin/node_modules/coffee-script/lib/grammar.js +591 -0
  55. data/templates/cordova_android/bin/node_modules/coffee-script/lib/helpers.js +66 -0
  56. data/templates/cordova_android/bin/node_modules/coffee-script/lib/index.js +8 -0
  57. data/templates/cordova_android/bin/node_modules/coffee-script/lib/lexer.js +656 -0
  58. data/templates/cordova_android/bin/node_modules/coffee-script/lib/nodes.js +2289 -0
  59. data/templates/cordova_android/bin/node_modules/coffee-script/lib/optparse.js +111 -0
  60. data/templates/cordova_android/bin/node_modules/coffee-script/lib/parser.js +676 -0
  61. data/templates/cordova_android/bin/node_modules/coffee-script/lib/repl.js +123 -0
  62. data/templates/cordova_android/bin/node_modules/coffee-script/lib/rewriter.js +363 -0
  63. data/templates/cordova_android/bin/node_modules/coffee-script/lib/scope.js +120 -0
  64. data/templates/cordova_android/bin/node_modules/coffee-script/package.json +27 -0
  65. data/templates/cordova_android/bin/node_modules/nodeunit/.gitignore +5 -0
  66. data/templates/cordova_android/bin/node_modules/nodeunit/.npmignore +3 -0
  67. data/templates/cordova_android/bin/node_modules/nodeunit/CONTRIBUTORS.md +60 -0
  68. data/templates/cordova_android/bin/node_modules/nodeunit/LICENSE +19 -0
  69. data/templates/cordova_android/bin/node_modules/nodeunit/Makefile +126 -0
  70. data/templates/cordova_android/bin/node_modules/nodeunit/README.md +432 -0
  71. data/templates/cordova_android/bin/node_modules/nodeunit/bin/nodeunit +120 -0
  72. data/templates/cordova_android/bin/node_modules/nodeunit/bin/nodeunit.json +10 -0
  73. data/templates/cordova_android/bin/node_modules/nodeunit/deps/async.js +623 -0
  74. data/templates/cordova_android/bin/node_modules/nodeunit/deps/console.log.js +55 -0
  75. data/templates/cordova_android/bin/node_modules/nodeunit/deps/ejs.js +125 -0
  76. data/templates/cordova_android/bin/node_modules/nodeunit/deps/json2.js +483 -0
  77. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/nodeunit.js +1757 -0
  78. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/suite1.js +12 -0
  79. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/suite2.js +13 -0
  80. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/test.html +16 -0
  81. data/templates/cordova_android/bin/node_modules/nodeunit/img/example_fail.png +0 -0
  82. data/templates/cordova_android/bin/node_modules/nodeunit/img/example_pass.png +0 -0
  83. data/templates/cordova_android/bin/node_modules/nodeunit/index.js +3 -0
  84. data/templates/cordova_android/bin/node_modules/nodeunit/lib/assert.js +316 -0
  85. data/templates/cordova_android/bin/node_modules/nodeunit/lib/core.js +260 -0
  86. data/templates/cordova_android/bin/node_modules/nodeunit/lib/nodeunit.js +82 -0
  87. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/browser.js +119 -0
  88. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/default.js +123 -0
  89. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/html.js +107 -0
  90. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/index.js +9 -0
  91. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/junit.js +183 -0
  92. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/minimal.js +112 -0
  93. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/skip_passed.js +105 -0
  94. data/templates/cordova_android/bin/node_modules/nodeunit/lib/track.js +48 -0
  95. data/templates/cordova_android/bin/node_modules/nodeunit/lib/types.js +187 -0
  96. data/templates/cordova_android/bin/node_modules/nodeunit/lib/utils.js +209 -0
  97. data/templates/cordova_android/bin/node_modules/nodeunit/man1/nodeunit.1 +95 -0
  98. data/templates/cordova_android/bin/node_modules/nodeunit/nodelint.cfg +4 -0
  99. data/templates/cordova_android/bin/node_modules/nodeunit/package.json +56 -0
  100. data/templates/cordova_android/bin/node_modules/nodeunit/share/junit.xml.ejs +19 -0
  101. data/templates/cordova_android/bin/node_modules/nodeunit/share/license.js +11 -0
  102. data/templates/cordova_android/bin/node_modules/nodeunit/share/nodeunit.css +70 -0
  103. data/templates/cordova_android/bin/templates/project/.cordova/android/readme.md +1 -0
  104. data/templates/cordova_android/bin/templates/project/.cordova/readme.md +3 -0
  105. data/templates/cordova_android/bin/templates/project/cordova/create +36 -0
  106. data/templates/cordova_android/bin/templates/project/cordova/debug +9 -0
  107. data/templates/cordova_android/bin/templates/project/cordova/emulate +12 -0
  108. data/templates/cordova_android/bin/templates/project/cordova/log +3 -0
  109. data/templates/cordova_android/bin/templates/project/cordova/templates/Activity.java +16 -0
  110. data/templates/cordova_android/bin/templates/project/cordova/templates/project/AndroidManifest.xml +50 -0
  111. data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/index.html +42 -0
  112. data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/main.js +146 -0
  113. data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/master.css +96 -0
  114. data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/drawable/icon.png +0 -0
  115. data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/xml/cordova.xml +5 -0
  116. data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/xml/plugins.xml +19 -0
  117. data/templates/cordova_android/bin/test +26 -0
  118. data/templates/cordova_android/bin/tests/autotest.coffee +4 -0
  119. data/templates/cordova_android/bin/tests/create.coffee +21 -0
  120. data/templates/cordova_android/bin/tests/debug.coffee +0 -0
  121. data/templates/cordova_android/bin/tests/test.coffee +0 -0
  122. data/templates/cordova_android/framework/.classpath +8 -0
  123. data/templates/cordova_android/framework/.project +33 -0
  124. data/templates/cordova_android/framework/AndroidManifest.xml +68 -0
  125. data/templates/cordova_android/framework/ant.properties +34 -0
  126. data/templates/cordova_android/framework/assets/js/accelerometer.js +137 -0
  127. data/templates/cordova_android/framework/assets/js/app.js +89 -0
  128. data/templates/cordova_android/framework/assets/js/battery.js +134 -0
  129. data/templates/cordova_android/framework/assets/js/camera.js +168 -0
  130. data/templates/cordova_android/framework/assets/js/capture.js +203 -0
  131. data/templates/cordova_android/framework/assets/js/compass.js +168 -0
  132. data/templates/cordova_android/framework/assets/js/contact.js +310 -0
  133. data/templates/cordova_android/framework/assets/js/cordova.android.js +4841 -0
  134. data/templates/cordova_android/framework/assets/js/cordova.js.base +924 -0
  135. data/templates/cordova_android/framework/assets/js/crypto.js +54 -0
  136. data/templates/cordova_android/framework/assets/js/device.js +83 -0
  137. data/templates/cordova_android/framework/assets/js/file.js +1082 -0
  138. data/templates/cordova_android/framework/assets/js/filetransfer.js +125 -0
  139. data/templates/cordova_android/framework/assets/js/geolocation.js +209 -0
  140. data/templates/cordova_android/framework/assets/js/header.txt +19 -0
  141. data/templates/cordova_android/framework/assets/js/media.js +233 -0
  142. data/templates/cordova_android/framework/assets/js/network.js +100 -0
  143. data/templates/cordova_android/framework/assets/js/notification.js +133 -0
  144. data/templates/cordova_android/framework/assets/js/position.js +100 -0
  145. data/templates/cordova_android/framework/assets/js/storage.js +439 -0
  146. data/templates/cordova_android/framework/assets/www/index.html +27 -0
  147. data/templates/cordova_android/framework/build.xml +216 -0
  148. data/templates/cordova_android/framework/libs/commons-codec-1.3.jar +0 -0
  149. data/templates/cordova_android/framework/proguard-project.txt +20 -0
  150. data/templates/cordova_android/framework/project.properties +14 -0
  151. data/templates/cordova_android/framework/res/drawable/icon.png +0 -0
  152. data/templates/cordova_android/framework/res/drawable/splash.png +0 -0
  153. data/templates/cordova_android/framework/res/layout/main.xml +29 -0
  154. data/templates/cordova_android/framework/res/values/strings.xml +23 -0
  155. data/templates/cordova_android/framework/res/xml/cordova.xml +37 -0
  156. data/templates/cordova_android/framework/res/xml/plugins.xml +37 -0
  157. data/templates/cordova_android/framework/src/com/phonegap/api/IPlugin.java +27 -0
  158. data/templates/cordova_android/framework/src/com/phonegap/api/LOG.java +28 -0
  159. data/templates/cordova_android/framework/src/com/phonegap/api/PhonegapActivity.java +28 -0
  160. data/templates/cordova_android/framework/src/com/phonegap/api/Plugin.java +27 -0
  161. data/templates/cordova_android/framework/src/com/phonegap/api/PluginManager.java +35 -0
  162. data/templates/cordova_android/framework/src/com/phonegap/api/PluginResult.java +53 -0
  163. data/templates/cordova_android/framework/src/org/apache/cordova/AccelListener.java +311 -0
  164. data/templates/cordova_android/framework/src/org/apache/cordova/App.java +198 -0
  165. data/templates/cordova_android/framework/src/org/apache/cordova/AudioHandler.java +364 -0
  166. data/templates/cordova_android/framework/src/org/apache/cordova/AudioPlayer.java +450 -0
  167. data/templates/cordova_android/framework/src/org/apache/cordova/AuthenticationToken.java +69 -0
  168. data/templates/cordova_android/framework/src/org/apache/cordova/BatteryListener.java +156 -0
  169. data/templates/cordova_android/framework/src/org/apache/cordova/CallbackServer.java +431 -0
  170. data/templates/cordova_android/framework/src/org/apache/cordova/CameraLauncher.java +500 -0
  171. data/templates/cordova_android/framework/src/org/apache/cordova/Capture.java +400 -0
  172. data/templates/cordova_android/framework/src/org/apache/cordova/CompassListener.java +308 -0
  173. data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessor.java +198 -0
  174. data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessorSdk5.java +1934 -0
  175. data/templates/cordova_android/framework/src/org/apache/cordova/ContactManager.java +113 -0
  176. data/templates/cordova_android/framework/src/org/apache/cordova/CordovaChromeClient.java +314 -0
  177. data/templates/cordova_android/framework/src/org/apache/cordova/CordovaWebViewClient.java +306 -0
  178. data/templates/cordova_android/framework/src/org/apache/cordova/Device.java +219 -0
  179. data/templates/cordova_android/framework/src/org/apache/cordova/DirectoryManager.java +161 -0
  180. data/templates/cordova_android/framework/src/org/apache/cordova/DroidGap.java +1417 -0
  181. data/templates/cordova_android/framework/src/org/apache/cordova/ExifHelper.java +165 -0
  182. data/templates/cordova_android/framework/src/org/apache/cordova/FileTransfer.java +458 -0
  183. data/templates/cordova_android/framework/src/org/apache/cordova/FileUploadResult.java +63 -0
  184. data/templates/cordova_android/framework/src/org/apache/cordova/FileUtils.java +1048 -0
  185. data/templates/cordova_android/framework/src/org/apache/cordova/GeoBroker.java +165 -0
  186. data/templates/cordova_android/framework/src/org/apache/cordova/GeoListener.java +133 -0
  187. data/templates/cordova_android/framework/src/org/apache/cordova/GpsListener.java +163 -0
  188. data/templates/cordova_android/framework/src/org/apache/cordova/HttpHandler.java +80 -0
  189. data/templates/cordova_android/framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java +104 -0
  190. data/templates/cordova_android/framework/src/org/apache/cordova/NetworkListener.java +153 -0
  191. data/templates/cordova_android/framework/src/org/apache/cordova/NetworkManager.java +248 -0
  192. data/templates/cordova_android/framework/src/org/apache/cordova/Notification.java +366 -0
  193. data/templates/cordova_android/framework/src/org/apache/cordova/PreferenceNode.java +34 -0
  194. data/templates/cordova_android/framework/src/org/apache/cordova/PreferenceSet.java +62 -0
  195. data/templates/cordova_android/framework/src/org/apache/cordova/StandAlone.java +35 -0
  196. data/templates/cordova_android/framework/src/org/apache/cordova/Storage.java +239 -0
  197. data/templates/cordova_android/framework/src/org/apache/cordova/TempListener.java +112 -0
  198. data/templates/cordova_android/framework/src/org/apache/cordova/api/CordovaInterface.java +145 -0
  199. data/templates/cordova_android/framework/src/org/apache/cordova/api/IPlugin.java +116 -0
  200. data/templates/cordova_android/framework/src/org/apache/cordova/api/LOG.java +234 -0
  201. data/templates/cordova_android/framework/src/org/apache/cordova/api/Plugin.java +210 -0
  202. data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginManager.java +359 -0
  203. data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginResult.java +119 -0
  204. data/templates/cordova_android/framework/src/org/apache/cordova/file/EncodingException.java +28 -0
  205. data/templates/cordova_android/framework/src/org/apache/cordova/file/FileExistsException.java +28 -0
  206. data/templates/cordova_android/framework/src/org/apache/cordova/file/InvalidModificationException.java +29 -0
  207. data/templates/cordova_android/framework/src/org/apache/cordova/file/NoModificationAllowedException.java +28 -0
  208. data/templates/cordova_android/framework/src/org/apache/cordova/file/TypeMismatchException.java +29 -0
  209. data/templates/cordova_android/framework/test/org/apache/cordova/PreferenceNodeTest.java +53 -0
  210. data/templates/cordova_android/framework/test/org/apache/cordova/PreferenceSetTest.java +73 -0
  211. metadata +279 -0
@@ -0,0 +1,359 @@
1
+ /*
2
+ Licensed to the Apache Software Foundation (ASF) under one
3
+ or more contributor license agreements. See the NOTICE file
4
+ distributed with this work for additional information
5
+ regarding copyright ownership. The ASF licenses this file
6
+ to you under the Apache License, Version 2.0 (the
7
+ "License"); you may not use this file except in compliance
8
+ with the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing,
13
+ software distributed under the License is distributed on an
14
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ KIND, either express or implied. See the License for the
16
+ specific language governing permissions and limitations
17
+ under the License.
18
+ */
19
+ package org.apache.cordova.api;
20
+
21
+ import java.io.IOException;
22
+ import java.util.HashMap;
23
+ import java.util.Iterator;
24
+ import java.util.Map.Entry;
25
+
26
+ import org.json.JSONArray;
27
+ import org.json.JSONException;
28
+ import org.xmlpull.v1.XmlPullParserException;
29
+
30
+ import android.content.Intent;
31
+ import android.content.res.XmlResourceParser;
32
+ import android.util.Log;
33
+ import android.webkit.WebView;
34
+
35
+ /**
36
+ * PluginManager is exposed to JavaScript in the Cordova WebView.
37
+ *
38
+ * Calling native plugin code can be done by calling PluginManager.exec(...)
39
+ * from JavaScript.
40
+ */
41
+ public class PluginManager {
42
+
43
+ private HashMap<String, IPlugin> plugins = new HashMap<String,IPlugin>();
44
+ private HashMap<String, String> services = new HashMap<String,String>();
45
+
46
+ private final CordovaInterface ctx;
47
+ private final WebView app;
48
+
49
+ // Map URL schemes like foo: to plugins that want to handle those schemes
50
+ // This would allow how all URLs are handled to be offloaded to a plugin
51
+ protected HashMap<String, String> urlMap = new HashMap<String,String>();
52
+
53
+ /**
54
+ * Constructor.
55
+ *
56
+ * @param app
57
+ * @param ctx
58
+ */
59
+ public PluginManager(WebView app, CordovaInterface ctx) {
60
+ this.ctx = ctx;
61
+ this.app = app;
62
+ this.loadPlugins();
63
+ }
64
+
65
+ /**
66
+ * Re-init when loading a new HTML page into webview.
67
+ */
68
+ public void reinit() {
69
+
70
+ // Stop plugins on current HTML page and discard
71
+ this.onPause(false);
72
+ this.onDestroy();
73
+ this.plugins = new HashMap<String, IPlugin>();
74
+ }
75
+
76
+ /**
77
+ * Load plugins from res/xml/plugins.xml
78
+ */
79
+ public void loadPlugins() {
80
+ int id = ctx.getResources().getIdentifier("plugins", "xml", ctx.getPackageName());
81
+ if (id == 0) { pluginConfigurationMissing(); }
82
+ XmlResourceParser xml = ctx.getResources().getXml(id);
83
+ int eventType = -1;
84
+ String pluginClass = "", pluginName = "";
85
+ while (eventType != XmlResourceParser.END_DOCUMENT) {
86
+ if (eventType == XmlResourceParser.START_TAG) {
87
+ String strNode = xml.getName();
88
+ if (strNode.equals("plugin")) {
89
+ pluginClass = xml.getAttributeValue(null, "value");
90
+ pluginName = xml.getAttributeValue(null, "name");
91
+ //System.out.println("Plugin: "+name+" => "+value);
92
+ this.addService(pluginName, pluginClass);
93
+
94
+ // Create plugin at load time if attribute "onload"
95
+ if ("true".equals(xml.getAttributeValue(null, "onload"))) {
96
+ this.getPlugin(pluginName);
97
+ }
98
+ } else if (strNode.equals("url-filter")) {
99
+ this.urlMap.put(xml.getAttributeValue(null, "value"), pluginName);
100
+ }
101
+ }
102
+ try {
103
+ eventType = xml.next();
104
+ } catch (XmlPullParserException e) {
105
+ e.printStackTrace();
106
+ } catch (IOException e) {
107
+ e.printStackTrace();
108
+ }
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Receives a request for execution and fulfills it by finding the appropriate
114
+ * Java class and calling it's execute method.
115
+ *
116
+ * PluginManager.exec can be used either synchronously or async. In either case, a JSON encoded
117
+ * string is returned that will indicate if any errors have occurred when trying to find
118
+ * or execute the class denoted by the clazz argument.
119
+ *
120
+ * @param service String containing the service to run
121
+ * @param action String containt the action that the class is supposed to perform. This is
122
+ * passed to the plugin execute method and it is up to the plugin developer
123
+ * how to deal with it.
124
+ * @param callbackId String containing the id of the callback that is execute in JavaScript if
125
+ * this is an async plugin call.
126
+ * @param args An Array literal string containing any arguments needed in the
127
+ * plugin execute method.
128
+ * @param async Boolean indicating whether the calling JavaScript code is expecting an
129
+ * immediate return value. If true, either Cordova.callbackSuccess(...) or
130
+ * Cordova.callbackError(...) is called once the plugin code has executed.
131
+ *
132
+ * @return JSON encoded string with a response message and status.
133
+ */
134
+ @SuppressWarnings("unchecked")
135
+ public String exec(final String service, final String action, final String callbackId, final String jsonArgs, final boolean async) {
136
+ PluginResult cr = null;
137
+ boolean runAsync = async;
138
+ try {
139
+ final JSONArray args = new JSONArray(jsonArgs);
140
+ final IPlugin plugin = this.getPlugin(service);
141
+ final CordovaInterface ctx = this.ctx;
142
+ if (plugin != null) {
143
+ runAsync = async && !plugin.isSynch(action);
144
+ if (runAsync) {
145
+ // Run this on a different thread so that this one can return back to JS
146
+ Thread thread = new Thread(new Runnable() {
147
+ public void run() {
148
+ try {
149
+ // Call execute on the plugin so that it can do it's thing
150
+ PluginResult cr = plugin.execute(action, args, callbackId);
151
+ int status = cr.getStatus();
152
+
153
+ // If no result to be sent and keeping callback, then no need to sent back to JavaScript
154
+ if ((status == PluginResult.Status.NO_RESULT.ordinal()) && cr.getKeepCallback()) {
155
+ }
156
+
157
+ // Check the success (OK, NO_RESULT & !KEEP_CALLBACK)
158
+ else if ((status == PluginResult.Status.OK.ordinal()) || (status == PluginResult.Status.NO_RESULT.ordinal())) {
159
+ ctx.sendJavascript(cr.toSuccessCallbackString(callbackId));
160
+ }
161
+
162
+ // If error
163
+ else {
164
+ ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
165
+ }
166
+ } catch (Exception e) {
167
+ PluginResult cr = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
168
+ ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
169
+ }
170
+ }
171
+ });
172
+ thread.start();
173
+ return "";
174
+ } else {
175
+ // Call execute on the plugin so that it can do it's thing
176
+ cr = plugin.execute(action, args, callbackId);
177
+
178
+ // If no result to be sent and keeping callback, then no need to sent back to JavaScript
179
+ if ((cr.getStatus() == PluginResult.Status.NO_RESULT.ordinal()) && cr.getKeepCallback()) {
180
+ return "";
181
+ }
182
+ }
183
+ }
184
+ } catch (JSONException e) {
185
+ System.out.println("ERROR: "+e.toString());
186
+ cr = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
187
+ }
188
+ // if async we have already returned at this point unless there was an error...
189
+ if (runAsync) {
190
+ if (cr == null) {
191
+ cr = new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION);
192
+ }
193
+ ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
194
+ }
195
+ return ( cr != null ? cr.getJSONString() : "{ status: 0, message: 'all good' }" );
196
+ }
197
+
198
+ /**
199
+ * Get the class.
200
+ *
201
+ * @param clazz
202
+ * @return
203
+ * @throws ClassNotFoundException
204
+ */
205
+ @SuppressWarnings("unchecked")
206
+ private Class getClassByName(final String clazz) throws ClassNotFoundException {
207
+ Class c = null;
208
+ if (clazz != null) {
209
+ c = Class.forName(clazz);
210
+ }
211
+ return c;
212
+ }
213
+
214
+ /**
215
+ * Get the interfaces that a class implements and see if it implements the
216
+ * org.apache.cordova.api.Plugin interface.
217
+ *
218
+ * @param c The class to check the interfaces of.
219
+ * @return Boolean indicating if the class implements org.apache.cordova.api.Plugin
220
+ */
221
+ @SuppressWarnings("unchecked")
222
+ private boolean isCordovaPlugin(Class c) {
223
+ if (c != null) {
224
+ return org.apache.cordova.api.Plugin.class.isAssignableFrom(c) || org.apache.cordova.api.IPlugin.class.isAssignableFrom(c);
225
+ }
226
+ return false;
227
+ }
228
+
229
+ /**
230
+ * Add plugin to be loaded and cached. This creates an instance of the plugin.
231
+ * If plugin is already created, then just return it.
232
+ *
233
+ * @param className The class to load
234
+ * @param clazz The class object (must be a class object of the className)
235
+ * @param callbackId The callback id to use when calling back into JavaScript
236
+ * @return The plugin
237
+ */
238
+ @SuppressWarnings("unchecked")
239
+ private IPlugin addPlugin(String pluginName, String className) {
240
+ try {
241
+ Class c = getClassByName(className);
242
+ if (isCordovaPlugin(c)) {
243
+ IPlugin plugin = (IPlugin)c.newInstance();
244
+ this.plugins.put(className, plugin);
245
+ plugin.setContext(this.ctx);
246
+ plugin.setView(this.app);
247
+ return plugin;
248
+ }
249
+ } catch (Exception e) {
250
+ e.printStackTrace();
251
+ System.out.println("Error adding plugin "+className+".");
252
+ }
253
+ return null;
254
+ }
255
+
256
+ /**
257
+ * Get the loaded plugin.
258
+ *
259
+ * If the plugin is not already loaded then load it.
260
+ *
261
+ * @param className The class of the loaded plugin.
262
+ * @return
263
+ */
264
+ private IPlugin getPlugin(String pluginName) {
265
+ String className = this.services.get(pluginName);
266
+ if (this.plugins.containsKey(className)) {
267
+ return this.plugins.get(className);
268
+ } else {
269
+ return this.addPlugin(pluginName, className);
270
+ }
271
+ }
272
+
273
+ /**
274
+ * Add a class that implements a service.
275
+ * This does not create the class instance. It just maps service name to class name.
276
+ *
277
+ * @param serviceType
278
+ * @param className
279
+ */
280
+ public void addService(String serviceType, String className) {
281
+ this.services.put(serviceType, className);
282
+ }
283
+
284
+ /**
285
+ * Called when the system is about to start resuming a previous activity.
286
+ *
287
+ * @param multitasking Flag indicating if multitasking is turned on for app
288
+ */
289
+ public void onPause(boolean multitasking) {
290
+ for (IPlugin plugin : this.plugins.values()) {
291
+ plugin.onPause(multitasking);
292
+ }
293
+ }
294
+
295
+ /**
296
+ * Called when the activity will start interacting with the user.
297
+ *
298
+ * @param multitasking Flag indicating if multitasking is turned on for app
299
+ */
300
+ public void onResume(boolean multitasking) {
301
+ for (IPlugin plugin : this.plugins.values()) {
302
+ plugin.onResume(multitasking);
303
+ }
304
+ }
305
+
306
+ /**
307
+ * The final call you receive before your activity is destroyed.
308
+ */
309
+ public void onDestroy() {
310
+ for (IPlugin plugin : this.plugins.values()) {
311
+ plugin.onDestroy();
312
+ }
313
+ }
314
+
315
+ /**
316
+ * Send a message to all plugins.
317
+ *
318
+ * @param id The message id
319
+ * @param data The message data
320
+ */
321
+ public void postMessage(String id, Object data) {
322
+ for (IPlugin plugin : this.plugins.values()) {
323
+ plugin.onMessage(id, data);
324
+ }
325
+ }
326
+
327
+ /**
328
+ * Called when the activity receives a new intent.
329
+ */
330
+ public void onNewIntent(Intent intent) {
331
+ for (IPlugin plugin : this.plugins.values()) {
332
+ plugin.onNewIntent(intent);
333
+ }
334
+ }
335
+
336
+ /**
337
+ * Called when the URL of the webview changes.
338
+ *
339
+ * @param url The URL that is being changed to.
340
+ * @return Return false to allow the URL to load, return true to prevent the URL from loading.
341
+ */
342
+ public boolean onOverrideUrlLoading(String url) {
343
+ Iterator<Entry<String, String>> it = this.urlMap.entrySet().iterator();
344
+ while (it.hasNext()) {
345
+ HashMap.Entry<String, String> pairs = it.next();
346
+ if (url.startsWith(pairs.getKey())) {
347
+ return this.getPlugin(pairs.getValue()).onOverrideUrlLoading(url);
348
+ }
349
+ }
350
+ return false;
351
+ }
352
+
353
+ private void pluginConfigurationMissing() {
354
+ System.err.println("=====================================================================================");
355
+ System.err.println("ERROR: plugin.xml is missing. Add res/xml/plugins.xml to your project.");
356
+ System.err.println("https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=blob;f=framework/res/xml/plugins.xml");
357
+ System.err.println("=====================================================================================");
358
+ }
359
+ }
@@ -0,0 +1,119 @@
1
+ /*
2
+ Licensed to the Apache Software Foundation (ASF) under one
3
+ or more contributor license agreements. See the NOTICE file
4
+ distributed with this work for additional information
5
+ regarding copyright ownership. The ASF licenses this file
6
+ to you under the Apache License, Version 2.0 (the
7
+ "License"); you may not use this file except in compliance
8
+ with the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing,
13
+ software distributed under the License is distributed on an
14
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ KIND, either express or implied. See the License for the
16
+ specific language governing permissions and limitations
17
+ under the License.
18
+ */
19
+ package org.apache.cordova.api;
20
+
21
+ import org.json.JSONArray;
22
+ import org.json.JSONObject;
23
+
24
+ import android.util.Log;
25
+
26
+ public class PluginResult {
27
+ private final int status;
28
+ private final String message;
29
+ private boolean keepCallback = false;
30
+
31
+ public PluginResult(Status status) {
32
+ this.status = status.ordinal();
33
+ this.message = "'" + PluginResult.StatusMessages[this.status] + "'";
34
+ }
35
+
36
+ public PluginResult(Status status, String message) {
37
+ this.status = status.ordinal();
38
+ this.message = JSONObject.quote(message);
39
+ }
40
+
41
+ public PluginResult(Status status, JSONArray message) {
42
+ this.status = status.ordinal();
43
+ this.message = message.toString();
44
+ }
45
+
46
+ public PluginResult(Status status, JSONObject message) {
47
+ this.status = status.ordinal();
48
+ this.message = message.toString();
49
+ }
50
+
51
+ public PluginResult(Status status, int i) {
52
+ this.status = status.ordinal();
53
+ this.message = ""+i;
54
+ }
55
+
56
+ public PluginResult(Status status, float f) {
57
+ this.status = status.ordinal();
58
+ this.message = ""+f;
59
+ }
60
+
61
+ public PluginResult(Status status, boolean b) {
62
+ this.status = status.ordinal();
63
+ this.message = ""+b;
64
+ }
65
+
66
+ public void setKeepCallback(boolean b) {
67
+ this.keepCallback = b;
68
+ }
69
+
70
+ public int getStatus() {
71
+ return status;
72
+ }
73
+
74
+ public String getMessage() {
75
+ return message;
76
+ }
77
+
78
+ public boolean getKeepCallback() {
79
+ return this.keepCallback;
80
+ }
81
+
82
+ public String getJSONString() {
83
+ return "{status:" + this.status + ",message:" + this.message + ",keepCallback:" + this.keepCallback + "}";
84
+ }
85
+
86
+ public String toSuccessCallbackString(String callbackId) {
87
+ return "require('cordova').callbackSuccess('"+callbackId+"',"+this.getJSONString()+");";
88
+ }
89
+
90
+ public String toErrorCallbackString(String callbackId) {
91
+ return "require('cordova').callbackError('"+callbackId+"', " + this.getJSONString()+ ");";
92
+ }
93
+
94
+ public static String[] StatusMessages = new String[] {
95
+ "No result",
96
+ "OK",
97
+ "Class not found",
98
+ "Illegal access",
99
+ "Instantiation error",
100
+ "Malformed url",
101
+ "IO error",
102
+ "Invalid action",
103
+ "JSON error",
104
+ "Error"
105
+ };
106
+
107
+ public enum Status {
108
+ NO_RESULT,
109
+ OK,
110
+ CLASS_NOT_FOUND_EXCEPTION,
111
+ ILLEGAL_ACCESS_EXCEPTION,
112
+ INSTANTIATION_EXCEPTION,
113
+ MALFORMED_URL_EXCEPTION,
114
+ IO_EXCEPTION,
115
+ INVALID_ACTION,
116
+ JSON_EXCEPTION,
117
+ ERROR
118
+ }
119
+ }
@@ -0,0 +1,28 @@
1
+ /*
2
+ Licensed to the Apache Software Foundation (ASF) under one
3
+ or more contributor license agreements. See the NOTICE file
4
+ distributed with this work for additional information
5
+ regarding copyright ownership. The ASF licenses this file
6
+ to you under the Apache License, Version 2.0 (the
7
+ "License"); you may not use this file except in compliance
8
+ with the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing,
13
+ software distributed under the License is distributed on an
14
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ KIND, either express or implied. See the License for the
16
+ specific language governing permissions and limitations
17
+ under the License.
18
+ */
19
+
20
+ package org.apache.cordova.file;
21
+
22
+ public class EncodingException extends Exception {
23
+
24
+ public EncodingException(String message) {
25
+ super(message);
26
+ }
27
+
28
+ }
@@ -0,0 +1,28 @@
1
+ /*
2
+ Licensed to the Apache Software Foundation (ASF) under one
3
+ or more contributor license agreements. See the NOTICE file
4
+ distributed with this work for additional information
5
+ regarding copyright ownership. The ASF licenses this file
6
+ to you under the Apache License, Version 2.0 (the
7
+ "License"); you may not use this file except in compliance
8
+ with the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing,
13
+ software distributed under the License is distributed on an
14
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ KIND, either express or implied. See the License for the
16
+ specific language governing permissions and limitations
17
+ under the License.
18
+ */
19
+
20
+ package org.apache.cordova.file;
21
+
22
+ public class FileExistsException extends Exception {
23
+
24
+ public FileExistsException(String msg) {
25
+ super(msg);
26
+ }
27
+
28
+ }
@@ -0,0 +1,29 @@
1
+ /*
2
+ Licensed to the Apache Software Foundation (ASF) under one
3
+ or more contributor license agreements. See the NOTICE file
4
+ distributed with this work for additional information
5
+ regarding copyright ownership. The ASF licenses this file
6
+ to you under the Apache License, Version 2.0 (the
7
+ "License"); you may not use this file except in compliance
8
+ with the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing,
13
+ software distributed under the License is distributed on an
14
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ KIND, either express or implied. See the License for the
16
+ specific language governing permissions and limitations
17
+ under the License.
18
+ */
19
+
20
+
21
+ package org.apache.cordova.file;
22
+
23
+ public class InvalidModificationException extends Exception {
24
+
25
+ public InvalidModificationException(String message) {
26
+ super(message);
27
+ }
28
+
29
+ }
@@ -0,0 +1,28 @@
1
+ /*
2
+ Licensed to the Apache Software Foundation (ASF) under one
3
+ or more contributor license agreements. See the NOTICE file
4
+ distributed with this work for additional information
5
+ regarding copyright ownership. The ASF licenses this file
6
+ to you under the Apache License, Version 2.0 (the
7
+ "License"); you may not use this file except in compliance
8
+ with the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing,
13
+ software distributed under the License is distributed on an
14
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ KIND, either express or implied. See the License for the
16
+ specific language governing permissions and limitations
17
+ under the License.
18
+ */
19
+
20
+ package org.apache.cordova.file;
21
+
22
+ public class NoModificationAllowedException extends Exception {
23
+
24
+ public NoModificationAllowedException(String message) {
25
+ super(message);
26
+ }
27
+
28
+ }
@@ -0,0 +1,29 @@
1
+ /*
2
+ Licensed to the Apache Software Foundation (ASF) under one
3
+ or more contributor license agreements. See the NOTICE file
4
+ distributed with this work for additional information
5
+ regarding copyright ownership. The ASF licenses this file
6
+ to you under the Apache License, Version 2.0 (the
7
+ "License"); you may not use this file except in compliance
8
+ with the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing,
13
+ software distributed under the License is distributed on an
14
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ KIND, either express or implied. See the License for the
16
+ specific language governing permissions and limitations
17
+ under the License.
18
+ */
19
+
20
+
21
+ package org.apache.cordova.file;
22
+
23
+ public class TypeMismatchException extends Exception {
24
+
25
+ public TypeMismatchException(String message) {
26
+ super(message);
27
+ }
28
+
29
+ }
@@ -0,0 +1,53 @@
1
+ /*
2
+ Licensed to the Apache Software Foundation (ASF) under one
3
+ or more contributor license agreements. See the NOTICE file
4
+ distributed with this work for additional information
5
+ regarding copyright ownership. The ASF licenses this file
6
+ to you under the Apache License, Version 2.0 (the
7
+ "License"); you may not use this file except in compliance
8
+ with the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing,
13
+ software distributed under the License is distributed on an
14
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ KIND, either express or implied. See the License for the
16
+ specific language governing permissions and limitations
17
+ under the License.
18
+ */
19
+ import org.junit.*;
20
+ import static org.junit.Assert.*;
21
+
22
+ import org.apache.cordova.PreferenceNode;
23
+
24
+ public class PreferenceNodeTest {
25
+ @Test
26
+ public void testConstructor() {
27
+ PreferenceNode foo = new org.apache.cordova.PreferenceNode("fullscreen", "false", false);
28
+ assertEquals("fullscreen", foo.name);
29
+ assertEquals("false", foo.value);
30
+ assertEquals(false, foo.readonly);
31
+ }
32
+
33
+ @Test
34
+ public void testNameAssignment() {
35
+ PreferenceNode foo = new org.apache.cordova.PreferenceNode("fullscreen", "false", false);
36
+ foo.name = "widescreen";
37
+ assertEquals("widescreen", foo.name);
38
+ }
39
+
40
+ @Test
41
+ public void testValueAssignment() {
42
+ PreferenceNode foo = new org.apache.cordova.PreferenceNode("fullscreen", "false", false);
43
+ foo.value = "maybe";
44
+ assertEquals("maybe", foo.value);
45
+ }
46
+
47
+ @Test
48
+ public void testReadonlyAssignment() {
49
+ PreferenceNode foo = new org.apache.cordova.PreferenceNode("fullscreen", "false", false);
50
+ foo.readonly = true;
51
+ assertEquals(true, foo.readonly);
52
+ }
53
+ }