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,125 @@
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
+ if (!Cordova.hasResource("filetransfer")) {
21
+ Cordova.addResource("filetransfer");
22
+
23
+ /**
24
+ * FileTransfer uploads a file to a remote server.
25
+ * @constructor
26
+ */
27
+ var FileTransfer = function() {};
28
+
29
+ /**
30
+ * FileUploadResult
31
+ * @constructor
32
+ */
33
+ var FileUploadResult = function() {
34
+ this.bytesSent = 0;
35
+ this.responseCode = null;
36
+ this.response = null;
37
+ };
38
+
39
+ /**
40
+ * FileTransferError
41
+ * @constructor
42
+ */
43
+ var FileTransferError = function() {
44
+ this.code = null;
45
+ };
46
+
47
+ FileTransferError.FILE_NOT_FOUND_ERR = 1;
48
+ FileTransferError.INVALID_URL_ERR = 2;
49
+ FileTransferError.CONNECTION_ERR = 3;
50
+
51
+ /**
52
+ * Given an absolute file path, uploads a file on the device to a remote server
53
+ * using a multipart HTTP request.
54
+ * @param filePath {String} Full path of the file on the device
55
+ * @param server {String} URL of the server to receive the file
56
+ * @param successCallback (Function} Callback to be invoked when upload has completed
57
+ * @param errorCallback {Function} Callback to be invoked upon error
58
+ * @param options {FileUploadOptions} Optional parameters such as file name and mimetype
59
+ */
60
+ FileTransfer.prototype.upload = function(filePath, server, successCallback, errorCallback, options, debug) {
61
+
62
+ // check for options
63
+ var fileKey = null;
64
+ var fileName = null;
65
+ var mimeType = null;
66
+ var params = null;
67
+ var chunkedMode = true;
68
+ if (options) {
69
+ fileKey = options.fileKey;
70
+ fileName = options.fileName;
71
+ mimeType = options.mimeType;
72
+ if (options.chunkedMode !== null || typeof options.chunkedMode !== "undefined") {
73
+ chunkedMode = options.chunkedMode;
74
+ }
75
+ if (options.params) {
76
+ params = options.params;
77
+ }
78
+ else {
79
+ params = {};
80
+ }
81
+ }
82
+
83
+ Cordova.exec(successCallback, errorCallback, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, debug, chunkedMode]);
84
+ };
85
+
86
+ /**
87
+ * Downloads a file form a given URL and saves it to the specified directory.
88
+ * @param source {String} URL of the server to receive the file
89
+ * @param target {String} Full path of the file on the device
90
+ * @param successCallback (Function} Callback to be invoked when upload has completed
91
+ * @param errorCallback {Function} Callback to be invoked upon error
92
+ */
93
+ FileTransfer.prototype.download = function(source, target, successCallback, errorCallback) {
94
+ var win = function(result) {
95
+ var entry = null;
96
+ if (result.isDirectory) {
97
+ entry = new DirectoryEntry();
98
+ }
99
+ else if (result.isFile) {
100
+ entry = new FileEntry();
101
+ }
102
+ entry.isDirectory = result.isDirectory;
103
+ entry.isFile = result.isFile;
104
+ entry.name = result.name;
105
+ entry.fullPath = result.fullPath;
106
+ successCallback(entry);
107
+ };
108
+ Cordova.exec(win, errorCallback, 'FileTransfer', 'download', [source, target]);
109
+ };
110
+
111
+ /**
112
+ * Options to customize the HTTP request used to upload files.
113
+ * @constructor
114
+ * @param fileKey {String} Name of file request parameter.
115
+ * @param fileName {String} Filename to be used by the server. Defaults to image.jpg.
116
+ * @param mimeType {String} Mimetype of the uploaded file. Defaults to image/jpeg.
117
+ * @param params {Object} Object with key: value params to send to the server.
118
+ */
119
+ var FileUploadOptions = function(fileKey, fileName, mimeType, params) {
120
+ this.fileKey = fileKey || null;
121
+ this.fileName = fileName || null;
122
+ this.mimeType = mimeType || null;
123
+ this.params = params || null;
124
+ };
125
+ }
@@ -0,0 +1,209 @@
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
+ if (!Cordova.hasResource("geolocation")) {
21
+ Cordova.addResource("geolocation");
22
+
23
+ /**
24
+ * This class provides access to device GPS data.
25
+ * @constructor
26
+ */
27
+ var Geolocation = function() {
28
+
29
+ // The last known GPS position.
30
+ this.lastPosition = null;
31
+
32
+ // Geolocation listeners
33
+ this.listeners = {};
34
+ };
35
+
36
+ /**
37
+ * Position error object
38
+ *
39
+ * @constructor
40
+ * @param code
41
+ * @param message
42
+ */
43
+ var PositionError = function(code, message) {
44
+ this.code = code;
45
+ this.message = message;
46
+ };
47
+
48
+ PositionError.PERMISSION_DENIED = 1;
49
+ PositionError.POSITION_UNAVAILABLE = 2;
50
+ PositionError.TIMEOUT = 3;
51
+
52
+ /**
53
+ * Asynchronously aquires the current position.
54
+ *
55
+ * @param {Function} successCallback The function to call when the position data is available
56
+ * @param {Function} errorCallback The function to call when there is an error getting the heading position. (OPTIONAL)
57
+ * @param {PositionOptions} options The options for getting the position data. (OPTIONAL)
58
+ */
59
+ Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
60
+ if (navigator._geo.listeners.global) {
61
+ console.log("Geolocation Error: Still waiting for previous getCurrentPosition() request.");
62
+ try {
63
+ errorCallback(new PositionError(PositionError.TIMEOUT, "Geolocation Error: Still waiting for previous getCurrentPosition() request."));
64
+ } catch (e) {
65
+ }
66
+ return;
67
+ }
68
+ var maximumAge = 10000;
69
+ var enableHighAccuracy = false;
70
+ var timeout = 10000;
71
+ if (typeof options !== "undefined") {
72
+ if (typeof options.maximumAge !== "undefined") {
73
+ maximumAge = options.maximumAge;
74
+ }
75
+ if (typeof options.enableHighAccuracy !== "undefined") {
76
+ enableHighAccuracy = options.enableHighAccuracy;
77
+ }
78
+ if (typeof options.timeout !== "undefined") {
79
+ timeout = options.timeout;
80
+ }
81
+ }
82
+ navigator._geo.listeners.global = {"success" : successCallback, "fail" : errorCallback };
83
+ Cordova.exec(null, null, "Geolocation", "getCurrentLocation", [enableHighAccuracy, timeout, maximumAge]);
84
+ };
85
+
86
+ /**
87
+ * Asynchronously watches the geolocation for changes to geolocation. When a change occurs,
88
+ * the successCallback is called with the new location.
89
+ *
90
+ * @param {Function} successCallback The function to call each time the location data is available
91
+ * @param {Function} errorCallback The function to call when there is an error getting the location data. (OPTIONAL)
92
+ * @param {PositionOptions} options The options for getting the location data such as frequency. (OPTIONAL)
93
+ * @return String The watch id that must be passed to #clearWatch to stop watching.
94
+ */
95
+ Geolocation.prototype.watchPosition = function(successCallback, errorCallback, options) {
96
+ var maximumAge = 10000;
97
+ var enableHighAccuracy = false;
98
+ var timeout = 10000;
99
+ if (typeof options !== "undefined") {
100
+ if (typeof options.frequency !== "undefined") {
101
+ maximumAge = options.frequency;
102
+ }
103
+ if (typeof options.maximumAge !== "undefined") {
104
+ maximumAge = options.maximumAge;
105
+ }
106
+ if (typeof options.enableHighAccuracy !== "undefined") {
107
+ enableHighAccuracy = options.enableHighAccuracy;
108
+ }
109
+ if (typeof options.timeout !== "undefined") {
110
+ timeout = options.timeout;
111
+ }
112
+ }
113
+ var id = Cordova.createUUID();
114
+ navigator._geo.listeners[id] = {"success" : successCallback, "fail" : errorCallback };
115
+ Cordova.exec(null, null, "Geolocation", "start", [id, enableHighAccuracy, timeout, maximumAge]);
116
+ return id;
117
+ };
118
+
119
+ /*
120
+ * Native callback when watch position has a new position.
121
+ * PRIVATE METHOD
122
+ *
123
+ * @param {String} id
124
+ * @param {Number} lat
125
+ * @param {Number} lng
126
+ * @param {Number} alt
127
+ * @param {Number} altacc
128
+ * @param {Number} head
129
+ * @param {Number} vel
130
+ * @param {Number} stamp
131
+ */
132
+ Geolocation.prototype.success = function(id, lat, lng, alt, altacc, head, vel, stamp) {
133
+ var coords = new Coordinates(lat, lng, alt, altacc, head, vel);
134
+ var loc = new Position(coords, stamp);
135
+ try {
136
+ if (lat === "undefined" || lng === "undefined") {
137
+ navigator._geo.listeners[id].fail(new PositionError(PositionError.POSITION_UNAVAILABLE, "Lat/Lng are undefined."));
138
+ }
139
+ else {
140
+ navigator._geo.lastPosition = loc;
141
+ navigator._geo.listeners[id].success(loc);
142
+ }
143
+ }
144
+ catch (e) {
145
+ console.log("Geolocation Error: Error calling success callback function.");
146
+ }
147
+
148
+ if (id === "global") {
149
+ delete navigator._geo.listeners.global;
150
+ }
151
+ };
152
+
153
+ /**
154
+ * Native callback when watch position has an error.
155
+ * PRIVATE METHOD
156
+ *
157
+ * @param {String} id The ID of the watch
158
+ * @param {Number} code The error code
159
+ * @param {String} msg The error message
160
+ */
161
+ Geolocation.prototype.fail = function(id, code, msg) {
162
+ try {
163
+ navigator._geo.listeners[id].fail(new PositionError(code, msg));
164
+ }
165
+ catch (e) {
166
+ console.log("Geolocation Error: Error calling error callback function.");
167
+ }
168
+ };
169
+
170
+ /**
171
+ * Clears the specified heading watch.
172
+ *
173
+ * @param {String} id The ID of the watch returned from #watchPosition
174
+ */
175
+ Geolocation.prototype.clearWatch = function(id) {
176
+ Cordova.exec(null, null, "Geolocation", "stop", [id]);
177
+ delete navigator._geo.listeners[id];
178
+ };
179
+
180
+ /**
181
+ * Force the Cordova geolocation to be used instead of built-in.
182
+ */
183
+ Geolocation.usingCordova = false;
184
+ Geolocation.useCordova = function() {
185
+ if (Geolocation.usingCordova) {
186
+ return;
187
+ }
188
+ Geolocation.usingCordova = true;
189
+
190
+ // Set built-in geolocation methods to our own implementations
191
+ // (Cannot replace entire geolocation, but can replace individual methods)
192
+ navigator.geolocation.setLocation = navigator._geo.setLocation;
193
+ navigator.geolocation.getCurrentPosition = navigator._geo.getCurrentPosition;
194
+ navigator.geolocation.watchPosition = navigator._geo.watchPosition;
195
+ navigator.geolocation.clearWatch = navigator._geo.clearWatch;
196
+ navigator.geolocation.start = navigator._geo.start;
197
+ navigator.geolocation.stop = navigator._geo.stop;
198
+ };
199
+
200
+ Cordova.addConstructor(function() {
201
+ navigator._geo = new Geolocation();
202
+
203
+ // No native geolocation object for Android 1.x, so use Cordova geolocation
204
+ if (typeof navigator.geolocation === 'undefined') {
205
+ navigator.geolocation = navigator._geo;
206
+ Geolocation.usingCordova = true;
207
+ }
208
+ });
209
+ }
@@ -0,0 +1,19 @@
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
+
@@ -0,0 +1,233 @@
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
+ if (!Cordova.hasResource("media")) {
21
+ Cordova.addResource("media");
22
+
23
+ /**
24
+ * This class provides access to the device media, interfaces to both sound and video
25
+ *
26
+ * @constructor
27
+ * @param src The file name or url to play
28
+ * @param successCallback The callback to be called when the file is done playing or recording.
29
+ * successCallback() - OPTIONAL
30
+ * @param errorCallback The callback to be called if there is an error.
31
+ * errorCallback(int errorCode) - OPTIONAL
32
+ * @param statusCallback The callback to be called when media status has changed.
33
+ * statusCallback(int statusCode) - OPTIONAL
34
+ * @param positionCallback The callback to be called when media position has changed.
35
+ * positionCallback(long position) - OPTIONAL
36
+ */
37
+ var Media = function(src, successCallback, errorCallback, statusCallback, positionCallback) {
38
+
39
+ // successCallback optional
40
+ if (successCallback && (typeof successCallback !== "function")) {
41
+ console.log("Media Error: successCallback is not a function");
42
+ return;
43
+ }
44
+
45
+ // errorCallback optional
46
+ if (errorCallback && (typeof errorCallback !== "function")) {
47
+ console.log("Media Error: errorCallback is not a function");
48
+ return;
49
+ }
50
+
51
+ // statusCallback optional
52
+ if (statusCallback && (typeof statusCallback !== "function")) {
53
+ console.log("Media Error: statusCallback is not a function");
54
+ return;
55
+ }
56
+
57
+ // statusCallback optional
58
+ if (positionCallback && (typeof positionCallback !== "function")) {
59
+ console.log("Media Error: positionCallback is not a function");
60
+ return;
61
+ }
62
+
63
+ this.id = Cordova.createUUID();
64
+ Cordova.mediaObjects[this.id] = this;
65
+ this.src = src;
66
+ this.successCallback = successCallback;
67
+ this.errorCallback = errorCallback;
68
+ this.statusCallback = statusCallback;
69
+ this.positionCallback = positionCallback;
70
+ this._duration = -1;
71
+ this._position = -1;
72
+ };
73
+
74
+ // Media messages
75
+ Media.MEDIA_STATE = 1;
76
+ Media.MEDIA_DURATION = 2;
77
+ Media.MEDIA_POSITION = 3;
78
+ Media.MEDIA_ERROR = 9;
79
+
80
+ // Media states
81
+ Media.MEDIA_NONE = 0;
82
+ Media.MEDIA_STARTING = 1;
83
+ Media.MEDIA_RUNNING = 2;
84
+ Media.MEDIA_PAUSED = 3;
85
+ Media.MEDIA_STOPPED = 4;
86
+ Media.MEDIA_MSG = ["None", "Starting", "Running", "Paused", "Stopped"];
87
+
88
+ // TODO: Will MediaError be used?
89
+ /**
90
+ * This class contains information about any Media errors.
91
+ * @constructor
92
+ */
93
+ var MediaError = function() {
94
+ this.code = null;
95
+ this.message = "";
96
+ };
97
+
98
+ MediaError.MEDIA_ERR_NONE_ACTIVE = 0;
99
+ MediaError.MEDIA_ERR_ABORTED = 1;
100
+ MediaError.MEDIA_ERR_NETWORK = 2;
101
+ MediaError.MEDIA_ERR_DECODE = 3;
102
+ MediaError.MEDIA_ERR_NONE_SUPPORTED = 4;
103
+
104
+ /**
105
+ * Start or resume playing audio file.
106
+ */
107
+ Media.prototype.play = function() {
108
+ Cordova.exec(null, null, "Media", "startPlayingAudio", [this.id, this.src]);
109
+ };
110
+
111
+ /**
112
+ * Stop playing audio file.
113
+ */
114
+ Media.prototype.stop = function() {
115
+ return Cordova.exec(null, null, "Media", "stopPlayingAudio", [this.id]);
116
+ };
117
+
118
+ /**
119
+ * Seek or jump to a new time in the track..
120
+ */
121
+ Media.prototype.seekTo = function(milliseconds) {
122
+ Cordova.exec(null, null, "Media", "seekToAudio", [this.id, milliseconds]);
123
+ };
124
+
125
+ /**
126
+ * Pause playing audio file.
127
+ */
128
+ Media.prototype.pause = function() {
129
+ Cordova.exec(null, null, "Media", "pausePlayingAudio", [this.id]);
130
+ };
131
+
132
+ /**
133
+ * Get duration of an audio file.
134
+ * The duration is only set for audio that is playing, paused or stopped.
135
+ *
136
+ * @return duration or -1 if not known.
137
+ */
138
+ Media.prototype.getDuration = function() {
139
+ return this._duration;
140
+ };
141
+
142
+ /**
143
+ * Get position of audio.
144
+ */
145
+ Media.prototype.getCurrentPosition = function(success, fail) {
146
+ Cordova.exec(success, fail, "Media", "getCurrentPositionAudio", [this.id]);
147
+ };
148
+
149
+ /**
150
+ * Start recording audio file.
151
+ */
152
+ Media.prototype.startRecord = function() {
153
+ Cordova.exec(null, null, "Media", "startRecordingAudio", [this.id, this.src]);
154
+ };
155
+
156
+ /**
157
+ * Stop recording audio file.
158
+ */
159
+ Media.prototype.stopRecord = function() {
160
+ Cordova.exec(null, null, "Media", "stopRecordingAudio", [this.id]);
161
+ };
162
+
163
+ /**
164
+ * Release the resources.
165
+ */
166
+ Media.prototype.release = function() {
167
+ Cordova.exec(null, null, "Media", "release", [this.id]);
168
+ };
169
+
170
+ /**
171
+ * Adjust the volume.
172
+ */
173
+ Media.prototype.setVolume = function(volume) {
174
+ Cordova.exec(null, null, "Media", "setVolume", [this.id, volume]);
175
+ };
176
+
177
+ /**
178
+ * List of media objects.
179
+ * PRIVATE
180
+ */
181
+ Cordova.mediaObjects = {};
182
+
183
+ /**
184
+ * Object that receives native callbacks.
185
+ * PRIVATE
186
+ * @constructor
187
+ */
188
+ Cordova.Media = function() {};
189
+
190
+ /**
191
+ * Get the media object.
192
+ * PRIVATE
193
+ *
194
+ * @param id The media object id (string)
195
+ */
196
+ Cordova.Media.getMediaObject = function(id) {
197
+ return Cordova.mediaObjects[id];
198
+ };
199
+
200
+ /**
201
+ * Audio has status update.
202
+ * PRIVATE
203
+ *
204
+ * @param id The media object id (string)
205
+ * @param status The status code (int)
206
+ * @param msg The status message (string)
207
+ */
208
+ Cordova.Media.onStatus = function(id, msg, value) {
209
+ var media = Cordova.mediaObjects[id];
210
+ // If state update
211
+ if (msg === Media.MEDIA_STATE) {
212
+ if (value === Media.MEDIA_STOPPED) {
213
+ if (media.successCallback) {
214
+ media.successCallback();
215
+ }
216
+ }
217
+ if (media.statusCallback) {
218
+ media.statusCallback(value);
219
+ }
220
+ }
221
+ else if (msg === Media.MEDIA_DURATION) {
222
+ media._duration = value;
223
+ }
224
+ else if (msg === Media.MEDIA_ERROR) {
225
+ if (media.errorCallback) {
226
+ media.errorCallback({"code":value});
227
+ }
228
+ }
229
+ else if (msg === Media.MEDIA_POSITION) {
230
+ media._position = value;
231
+ }
232
+ };
233
+ }
@@ -0,0 +1,100 @@
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
+ if (!Cordova.hasResource("network")) {
22
+ Cordova.addResource("network");
23
+
24
+ /**
25
+ * This class contains information about the current network Connection.
26
+ * @constructor
27
+ */
28
+ var Connection = function() {
29
+ this.type = null;
30
+ this._firstRun = true;
31
+ this._timer = null;
32
+ this.timeout = 500;
33
+
34
+ var me = this;
35
+ this.getInfo(
36
+ function(type) {
37
+ // Need to send events if we are on or offline
38
+ if (type === "none") {
39
+ // set a timer if still offline at the end of timer send the offline event
40
+ me._timer = setTimeout(function(){
41
+ me.type = type;
42
+ Cordova.fireDocumentEvent('offline');
43
+ me._timer = null;
44
+ }, me.timeout);
45
+ } else {
46
+ // If there is a current offline event pending clear it
47
+ if (me._timer !== null) {
48
+ clearTimeout(me._timer);
49
+ me._timer = null;
50
+ }
51
+ me.type = type;
52
+ Cordova.fireDocumentEvent('online');
53
+ }
54
+
55
+ // should only fire this once
56
+ if (me._firstRun) {
57
+ me._firstRun = false;
58
+ Cordova.onCordovaConnectionReady.fire();
59
+ }
60
+ },
61
+ function(e) {
62
+ // If we can't get the network info we should still tell Cordova
63
+ // to fire the deviceready event.
64
+ if (me._firstRun) {
65
+ me._firstRun = false;
66
+ Cordova.onCordovaConnectionReady.fire();
67
+ }
68
+ console.log("Error initializing Network Connection: " + e);
69
+ });
70
+ };
71
+
72
+ Connection.UNKNOWN = "unknown";
73
+ Connection.ETHERNET = "ethernet";
74
+ Connection.WIFI = "wifi";
75
+ Connection.CELL_2G = "2g";
76
+ Connection.CELL_3G = "3g";
77
+ Connection.CELL_4G = "4g";
78
+ Connection.NONE = "none";
79
+
80
+ /**
81
+ * Get connection info
82
+ *
83
+ * @param {Function} successCallback The function to call when the Connection data is available
84
+ * @param {Function} errorCallback The function to call when there is an error getting the Connection data. (OPTIONAL)
85
+ */
86
+ Connection.prototype.getInfo = function(successCallback, errorCallback) {
87
+ // Get info
88
+ Cordova.exec(successCallback, errorCallback, "Network Status", "getConnectionInfo", []);
89
+ };
90
+
91
+
92
+ Cordova.addConstructor(function() {
93
+ if (typeof navigator.network === "undefined") {
94
+ navigator.network = {};
95
+ }
96
+ if (typeof navigator.network.connection === "undefined") {
97
+ navigator.network.connection = new Connection();
98
+ }
99
+ });
100
+ }