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,113 @@
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;
20
+
21
+ import org.apache.cordova.api.Plugin;
22
+ import org.apache.cordova.api.PluginResult;
23
+ import org.json.JSONArray;
24
+ import org.json.JSONException;
25
+ import org.json.JSONObject;
26
+ import android.util.Log;
27
+
28
+ public class ContactManager extends Plugin {
29
+
30
+ private ContactAccessor contactAccessor;
31
+ private static final String LOG_TAG = "Contact Query";
32
+
33
+ public static final int UNKNOWN_ERROR = 0;
34
+ public static final int INVALID_ARGUMENT_ERROR = 1;
35
+ public static final int TIMEOUT_ERROR = 2;
36
+ public static final int PENDING_OPERATION_ERROR = 3;
37
+ public static final int IO_ERROR = 4;
38
+ public static final int NOT_SUPPORTED_ERROR = 5;
39
+ public static final int PERMISSION_DENIED_ERROR = 20;
40
+
41
+
42
+ /**
43
+ * Constructor.
44
+ */
45
+ public ContactManager() {
46
+ }
47
+
48
+ /**
49
+ * Executes the request and returns PluginResult.
50
+ *
51
+ * @param action The action to execute.
52
+ * @param args JSONArry of arguments for the plugin.
53
+ * @param callbackId The callback id used when calling back into JavaScript.
54
+ * @return A PluginResult object with a status and message.
55
+ */
56
+ public PluginResult execute(String action, JSONArray args, String callbackId) {
57
+ PluginResult.Status status = PluginResult.Status.OK;
58
+ String result = "";
59
+
60
+ /**
61
+ * Check to see if we are on an Android 1.X device. If we are return an error as we
62
+ * do not support this as of Cordova 1.0.
63
+ */
64
+ if (android.os.Build.VERSION.RELEASE.startsWith("1.")) {
65
+ JSONObject res = null;
66
+ try {
67
+ res = new JSONObject();
68
+ res.put("code", NOT_SUPPORTED_ERROR);
69
+ res.put("message", "Contacts are not supported in Android 1.X devices");
70
+ } catch (JSONException e) {
71
+ // This should never happen
72
+ Log.e(LOG_TAG, e.getMessage(), e);
73
+ }
74
+ return new PluginResult(PluginResult.Status.ERROR, res);
75
+ }
76
+
77
+ /**
78
+ * Only create the contactAccessor after we check the Android version or the program will crash
79
+ * older phones.
80
+ */
81
+ if (this.contactAccessor == null) {
82
+ this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx.getContext());
83
+ }
84
+
85
+ try {
86
+ if (action.equals("search")) {
87
+ JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1));
88
+ return new PluginResult(status, res);
89
+ }
90
+ else if (action.equals("save")) {
91
+ String id = contactAccessor.save(args.getJSONObject(0));
92
+ if (id != null) {
93
+ JSONObject res = contactAccessor.getContactById(id);
94
+ if (res != null) {
95
+ return new PluginResult(status, res);
96
+ }
97
+ }
98
+ }
99
+ else if (action.equals("remove")) {
100
+ if (contactAccessor.remove(args.getString(0))) {
101
+ return new PluginResult(status, result);
102
+ }
103
+ }
104
+ // If we get to this point an error has occurred
105
+ JSONObject r = new JSONObject();
106
+ r.put("code", UNKNOWN_ERROR);
107
+ return new PluginResult(PluginResult.Status.ERROR, r);
108
+ } catch (JSONException e) {
109
+ Log.e(LOG_TAG, e.getMessage(), e);
110
+ return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
111
+ }
112
+ }
113
+ }
@@ -0,0 +1,314 @@
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;
20
+ import org.apache.cordova.api.LOG;
21
+ import org.json.JSONArray;
22
+ import org.json.JSONException;
23
+
24
+
25
+ import android.app.AlertDialog;
26
+ import android.content.Context;
27
+ import android.content.DialogInterface;
28
+ import android.view.KeyEvent;
29
+ import android.view.View;
30
+ import android.webkit.ConsoleMessage;
31
+ import android.webkit.JsPromptResult;
32
+ import android.webkit.JsResult;
33
+ import android.webkit.WebChromeClient;
34
+ import android.webkit.WebStorage;
35
+ import android.webkit.WebView;
36
+ import android.webkit.GeolocationPermissions.Callback;
37
+ import android.widget.EditText;
38
+
39
+ /**
40
+ * This class is the WebChromeClient that implements callbacks for our web view.
41
+ */
42
+ public class CordovaChromeClient extends WebChromeClient {
43
+
44
+
45
+ private String TAG = "CordovaLog";
46
+ private long MAX_QUOTA = 100 * 1024 * 1024;
47
+ private DroidGap ctx;
48
+
49
+ /**
50
+ * Constructor.
51
+ *
52
+ * @param ctx
53
+ */
54
+ public CordovaChromeClient(Context ctx) {
55
+ this.ctx = (DroidGap) ctx;
56
+ }
57
+
58
+ /**
59
+ * Tell the client to display a javascript alert dialog.
60
+ *
61
+ * @param view
62
+ * @param url
63
+ * @param message
64
+ * @param result
65
+ */
66
+ @Override
67
+ public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
68
+ AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx);
69
+ dlg.setMessage(message);
70
+ dlg.setTitle("Alert");
71
+ //Don't let alerts break the back button
72
+ dlg.setCancelable(true);
73
+ dlg.setPositiveButton(android.R.string.ok,
74
+ new AlertDialog.OnClickListener() {
75
+ public void onClick(DialogInterface dialog, int which) {
76
+ result.confirm();
77
+ }
78
+ });
79
+ dlg.setOnCancelListener(
80
+ new DialogInterface.OnCancelListener() {
81
+ public void onCancel(DialogInterface dialog) {
82
+ result.confirm();
83
+ }
84
+ });
85
+ dlg.setOnKeyListener(new DialogInterface.OnKeyListener() {
86
+ //DO NOTHING
87
+ public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
88
+ if(keyCode == KeyEvent.KEYCODE_BACK)
89
+ {
90
+ result.confirm();
91
+ return false;
92
+ }
93
+ else
94
+ return true;
95
+ }
96
+ });
97
+ dlg.create();
98
+ dlg.show();
99
+ return true;
100
+ }
101
+
102
+ /**
103
+ * Tell the client to display a confirm dialog to the user.
104
+ *
105
+ * @param view
106
+ * @param url
107
+ * @param message
108
+ * @param result
109
+ */
110
+ @Override
111
+ public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
112
+ AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx);
113
+ dlg.setMessage(message);
114
+ dlg.setTitle("Confirm");
115
+ dlg.setCancelable(true);
116
+ dlg.setPositiveButton(android.R.string.ok,
117
+ new DialogInterface.OnClickListener() {
118
+ public void onClick(DialogInterface dialog, int which) {
119
+ result.confirm();
120
+ }
121
+ });
122
+ dlg.setNegativeButton(android.R.string.cancel,
123
+ new DialogInterface.OnClickListener() {
124
+ public void onClick(DialogInterface dialog, int which) {
125
+ result.cancel();
126
+ }
127
+ });
128
+ dlg.setOnCancelListener(
129
+ new DialogInterface.OnCancelListener() {
130
+ public void onCancel(DialogInterface dialog) {
131
+ result.cancel();
132
+ }
133
+ });
134
+ dlg.setOnKeyListener(new DialogInterface.OnKeyListener() {
135
+ //DO NOTHING
136
+ public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
137
+ if(keyCode == KeyEvent.KEYCODE_BACK)
138
+ {
139
+ result.cancel();
140
+ return false;
141
+ }
142
+ else
143
+ return true;
144
+ }
145
+ });
146
+ dlg.create();
147
+ dlg.show();
148
+ return true;
149
+ }
150
+
151
+ /**
152
+ * Tell the client to display a prompt dialog to the user.
153
+ * If the client returns true, WebView will assume that the client will
154
+ * handle the prompt dialog and call the appropriate JsPromptResult method.
155
+ *
156
+ * Since we are hacking prompts for our own purposes, we should not be using them for
157
+ * this purpose, perhaps we should hack console.log to do this instead!
158
+ *
159
+ * @param view
160
+ * @param url
161
+ * @param message
162
+ * @param defaultValue
163
+ * @param result
164
+ */
165
+ @Override
166
+ public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
167
+
168
+ // Security check to make sure any requests are coming from the page initially
169
+ // loaded in webview and not another loaded in an iframe.
170
+ boolean reqOk = false;
171
+ if (url.startsWith("file://") || url.indexOf(this.ctx.baseUrl) == 0 || ctx.isUrlWhiteListed(url)) {
172
+ reqOk = true;
173
+ }
174
+
175
+ // Calling PluginManager.exec() to call a native service using
176
+ // prompt(this.stringify(args), "gap:"+this.stringify([service, action, callbackId, true]));
177
+ if (reqOk && defaultValue != null && defaultValue.length() > 3 && defaultValue.substring(0, 4).equals("gap:")) {
178
+ JSONArray array;
179
+ try {
180
+ array = new JSONArray(defaultValue.substring(4));
181
+ String service = array.getString(0);
182
+ String action = array.getString(1);
183
+ String callbackId = array.getString(2);
184
+ boolean async = array.getBoolean(3);
185
+ String r = ctx.pluginManager.exec(service, action, callbackId, message, async);
186
+ result.confirm(r);
187
+ } catch (JSONException e) {
188
+ e.printStackTrace();
189
+ }
190
+ }
191
+
192
+ // Polling for JavaScript messages
193
+ else if (reqOk && defaultValue != null && defaultValue.equals("gap_poll:")) {
194
+ String r = ctx.callbackServer.getJavascript();
195
+ result.confirm(r);
196
+ }
197
+
198
+ // Calling into CallbackServer
199
+ else if (reqOk && defaultValue != null && defaultValue.equals("gap_callbackServer:")) {
200
+ String r = "";
201
+ if (message.equals("usePolling")) {
202
+ r = ""+ ctx.callbackServer.usePolling();
203
+ }
204
+ else if (message.equals("restartServer")) {
205
+ ctx.callbackServer.restartServer();
206
+ }
207
+ else if (message.equals("getPort")) {
208
+ r = Integer.toString(ctx.callbackServer.getPort());
209
+ }
210
+ else if (message.equals("getToken")) {
211
+ r = ctx.callbackServer.getToken();
212
+ }
213
+ result.confirm(r);
214
+ }
215
+
216
+ // Cordova JS has initialized, so show webview
217
+ // (This solves white flash seen when rendering HTML)
218
+ else if (reqOk && defaultValue != null && defaultValue.equals("gap_init:")) {
219
+ ctx.appView.setVisibility(View.VISIBLE);
220
+ ctx.spinnerStop();
221
+ result.confirm("OK");
222
+ }
223
+
224
+ // Show dialog
225
+ else {
226
+ final JsPromptResult res = result;
227
+ AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx);
228
+ dlg.setMessage(message);
229
+ final EditText input = new EditText(this.ctx);
230
+ if (defaultValue != null) {
231
+ input.setText(defaultValue);
232
+ }
233
+ dlg.setView(input);
234
+ dlg.setCancelable(false);
235
+ dlg.setPositiveButton(android.R.string.ok,
236
+ new DialogInterface.OnClickListener() {
237
+ public void onClick(DialogInterface dialog, int which) {
238
+ String usertext = input.getText().toString();
239
+ res.confirm(usertext);
240
+ }
241
+ });
242
+ dlg.setNegativeButton(android.R.string.cancel,
243
+ new DialogInterface.OnClickListener() {
244
+ public void onClick(DialogInterface dialog, int which) {
245
+ res.cancel();
246
+ }
247
+ });
248
+ dlg.create();
249
+ dlg.show();
250
+ }
251
+ return true;
252
+ }
253
+
254
+ /**
255
+ * Handle database quota exceeded notification.
256
+ *
257
+ * @param url
258
+ * @param databaseIdentifier
259
+ * @param currentQuota
260
+ * @param estimatedSize
261
+ * @param totalUsedQuota
262
+ * @param quotaUpdater
263
+ */
264
+ @Override
265
+ public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize,
266
+ long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)
267
+ {
268
+ LOG.d(TAG, "DroidGap: onExceededDatabaseQuota estimatedSize: %d currentQuota: %d totalUsedQuota: %d", estimatedSize, currentQuota, totalUsedQuota);
269
+
270
+ if( estimatedSize < MAX_QUOTA)
271
+ {
272
+ //increase for 1Mb
273
+ long newQuota = estimatedSize;
274
+ LOG.d(TAG, "calling quotaUpdater.updateQuota newQuota: %d", newQuota);
275
+ quotaUpdater.updateQuota(newQuota);
276
+ }
277
+ else
278
+ {
279
+ // Set the quota to whatever it is and force an error
280
+ // TODO: get docs on how to handle this properly
281
+ quotaUpdater.updateQuota(currentQuota);
282
+ }
283
+ }
284
+
285
+ // console.log in api level 7: http://developer.android.com/guide/developing/debug-tasks.html
286
+ @Override
287
+ public void onConsoleMessage(String message, int lineNumber, String sourceID)
288
+ {
289
+ LOG.d(TAG, "%s: Line %d : %s", sourceID, lineNumber, message);
290
+ super.onConsoleMessage(message, lineNumber, sourceID);
291
+ }
292
+
293
+ @Override
294
+ public boolean onConsoleMessage(ConsoleMessage consoleMessage)
295
+ {
296
+ if(consoleMessage.message() != null)
297
+ LOG.d(TAG, consoleMessage.message());
298
+ return super.onConsoleMessage(consoleMessage);
299
+ }
300
+
301
+ @Override
302
+ /**
303
+ * Instructs the client to show a prompt to ask the user to set the Geolocation permission state for the specified origin.
304
+ *
305
+ * @param origin
306
+ * @param callback
307
+ */
308
+ public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
309
+ super.onGeolocationPermissionsShowPrompt(origin, callback);
310
+ callback.invoke(origin, true, false);
311
+ }
312
+
313
+
314
+ }