mobile_template 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mobile_template/version.rb +1 -1
- data/mobile_template.gemspec +1 -1
- data/templates/assets/Gemfile +1 -1
- data/templates/assets/source/javascripts/vendor/cordova.js +2106 -1975
- data/templates/assets/source/javascripts/vendor/jquery.js +614 -477
- data/templates/assets/source/javascripts/vendor/jquery.mobile.js +519 -378
- data/templates/assets/source/stylesheets/vendor/jquery.mobile.css.scss +683 -502
- data/templates/cordova_android/VERSION +1 -1
- data/templates/cordova_android/bin/create +5 -1
- data/templates/cordova_android/bin/templates/project/cordova/create +5 -0
- data/templates/cordova_android/bin/templates/project/cordova/debug +1 -1
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/AndroidManifest.xml +18 -25
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/index.html +6 -6
- data/templates/cordova_android/framework/assets/js/cordova.android.js +2106 -1975
- data/templates/cordova_android/framework/assets/www/index.html +1 -1
- data/templates/cordova_android/framework/build.xml +2 -42
- data/templates/cordova_android/framework/project.properties +1 -1
- data/templates/cordova_android/framework/res/drawable/splash.png +0 -0
- data/templates/cordova_android/framework/res/drawable-hdpi/icon.png +0 -0
- data/templates/cordova_android/framework/res/drawable-ldpi/icon.png +0 -0
- data/templates/cordova_android/framework/res/drawable-mdpi/icon.png +0 -0
- data/templates/cordova_android/framework/res/xml/plugins.xml +2 -1
- data/templates/cordova_android/framework/src/com/phonegap/api/PluginManager.java +1 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/AudioPlayer.java +24 -16
- data/templates/cordova_android/framework/src/org/apache/cordova/CameraLauncher.java +35 -10
- data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessor.java +2 -1
- data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessorSdk5.java +67 -65
- data/templates/cordova_android/framework/src/org/apache/cordova/ContactManager.java +51 -63
- data/templates/cordova_android/framework/src/org/apache/cordova/CordovaChromeClient.java +3 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CordovaWebViewClient.java +6 -2
- data/templates/cordova_android/framework/src/org/apache/cordova/Device.java +108 -108
- data/templates/cordova_android/framework/src/org/apache/cordova/DroidGap.java +110 -77
- data/templates/cordova_android/framework/src/org/apache/cordova/FileTransfer.java +90 -44
- data/templates/cordova_android/framework/src/org/apache/cordova/FileUtils.java +20 -20
- data/templates/cordova_android/framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java +2 -2
- data/templates/cordova_android/framework/src/org/apache/cordova/NetworkManager.java +7 -8
- data/templates/cordova_android/framework/src/org/apache/cordova/Notification.java +2 -2
- data/templates/cordova_android/framework/src/org/apache/cordova/SplashScreen.java +23 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/Storage.java +3 -3
- data/templates/cordova_android/framework/src/org/apache/cordova/api/CordovaInterface.java +2 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginEntry.java +119 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginManager.java +260 -258
- data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginResult.java +2 -2
- data/templates/cordova_android/releasenotes.md +42 -0
- data/templates/cordova_android/test/.classpath +8 -0
- data/templates/cordova_android/test/.project +33 -0
- data/templates/cordova_android/test/AndroidManifest.xml +87 -0
- data/templates/cordova_android/test/README.md +23 -0
- data/templates/cordova_android/test/ant.properties +17 -0
- data/templates/cordova_android/test/assets/www/backbuttonmultipage/index.html +23 -0
- data/templates/cordova_android/test/assets/www/backbuttonmultipage/sample2.html +23 -0
- data/templates/cordova_android/test/assets/www/backbuttonmultipage/sample3.html +26 -0
- data/templates/cordova_android/test/assets/www/background/index.html +99 -0
- data/templates/cordova_android/test/assets/www/background/index2.html +98 -0
- data/templates/cordova_android/test/assets/www/cordova-1.6.0.js +4985 -0
- data/templates/cordova_android/test/assets/www/cordova.js +2 -0
- data/templates/cordova_android/test/assets/www/htmlnotfound/error.html +1 -0
- data/templates/cordova_android/test/assets/www/iframe/index.html +33 -0
- data/templates/cordova_android/test/assets/www/iframe/index2.html +24 -0
- data/templates/cordova_android/test/assets/www/index.html +47 -0
- data/templates/cordova_android/test/assets/www/jqmtabbackbutton/index.html +49 -0
- data/templates/cordova_android/test/assets/www/jqmtabbackbutton/tab1.html +29 -0
- data/templates/cordova_android/test/assets/www/jqmtabbackbutton/tab2.html +30 -0
- data/templates/cordova_android/test/assets/www/jqmtabbackbutton/tab3.html +30 -0
- data/templates/cordova_android/test/assets/www/lifecycle/index.html +108 -0
- data/templates/cordova_android/test/assets/www/lifecycle/index2.html +104 -0
- data/templates/cordova_android/test/assets/www/main.js +150 -0
- data/templates/cordova_android/test/assets/www/master.css +117 -0
- data/templates/cordova_android/test/assets/www/menus/index.html +29 -0
- data/templates/cordova_android/test/assets/www/splashscreen/index.html +22 -0
- data/templates/cordova_android/test/assets/www/userwebview/index.html +49 -0
- data/templates/cordova_android/test/assets/www/whitelist/index.html +29 -0
- data/templates/cordova_android/test/assets/www/whitelist/index2.html +23 -0
- data/templates/cordova_android/test/assets/www/xhr/index.html +48 -0
- data/templates/cordova_android/test/build.xml +85 -0
- data/templates/cordova_android/test/libs/cordova-1.6.0.jar +0 -0
- data/templates/cordova_android/test/project.properties +11 -0
- data/templates/cordova_android/{framework → test}/res/drawable/icon.png +0 -0
- data/templates/cordova_android/test/res/drawable/sandy.jpg +0 -0
- data/templates/cordova_android/test/res/drawable-hdpi/ic_launcher.png +0 -0
- data/templates/cordova_android/test/res/drawable-ldpi/ic_launcher.png +0 -0
- data/templates/cordova_android/test/res/drawable-mdpi/ic_launcher.png +0 -0
- data/templates/cordova_android/test/res/layout/main.xml +13 -0
- data/templates/cordova_android/test/res/values/strings.xml +4 -0
- data/templates/cordova_android/{bin/templates/project/cordova/templates/project → test}/res/xml/cordova.xml +0 -0
- data/templates/cordova_android/{bin/templates/project/cordova/templates/project → test}/res/xml/plugins.xml +1 -1
- data/templates/cordova_android/test/src/org/apache/cordova/test/ActivityPlugin.java +81 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/FixWebView.java +43 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/backbuttonmultipage.java +30 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/background.java +34 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/errorurl.java +32 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/htmlnotfound.java +31 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/iframe.java +30 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/jqmtabbackbutton.java +30 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/lifecycle.java +30 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/loading.java +31 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/menus.java +80 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/splashscreen.java +35 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/tests.java +32 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/timeout.java +34 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/userwebview.java +72 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/whitelist.java +51 -0
- data/templates/cordova_android/test/src/org/apache/cordova/test/xhr.java +30 -0
- metadata +83 -30
- data/templates/cordova_android/framework/assets/js/accelerometer.js +0 -137
- data/templates/cordova_android/framework/assets/js/app.js +0 -89
- data/templates/cordova_android/framework/assets/js/battery.js +0 -134
- data/templates/cordova_android/framework/assets/js/camera.js +0 -168
- data/templates/cordova_android/framework/assets/js/capture.js +0 -203
- data/templates/cordova_android/framework/assets/js/compass.js +0 -168
- data/templates/cordova_android/framework/assets/js/contact.js +0 -310
- data/templates/cordova_android/framework/assets/js/cordova.js.base +0 -924
- data/templates/cordova_android/framework/assets/js/crypto.js +0 -54
- data/templates/cordova_android/framework/assets/js/device.js +0 -83
- data/templates/cordova_android/framework/assets/js/file.js +0 -1082
- data/templates/cordova_android/framework/assets/js/filetransfer.js +0 -125
- data/templates/cordova_android/framework/assets/js/geolocation.js +0 -209
- data/templates/cordova_android/framework/assets/js/header.txt +0 -19
- data/templates/cordova_android/framework/assets/js/media.js +0 -233
- data/templates/cordova_android/framework/assets/js/network.js +0 -100
- data/templates/cordova_android/framework/assets/js/notification.js +0 -133
- data/templates/cordova_android/framework/assets/js/position.js +0 -100
- data/templates/cordova_android/framework/assets/js/storage.js +0 -439
@@ -15,7 +15,7 @@
|
|
15
15
|
KIND, either express or implied. See the License for the
|
16
16
|
specific language governing permissions and limitations
|
17
17
|
under the License.
|
18
|
-
*/
|
18
|
+
*/
|
19
19
|
package org.apache.cordova.api;
|
20
20
|
|
21
21
|
import java.io.IOException;
|
@@ -29,7 +29,6 @@ import org.xmlpull.v1.XmlPullParserException;
|
|
29
29
|
|
30
30
|
import android.content.Intent;
|
31
31
|
import android.content.res.XmlResourceParser;
|
32
|
-
import android.util.Log;
|
33
32
|
import android.webkit.WebView;
|
34
33
|
|
35
34
|
/**
|
@@ -39,321 +38,324 @@ import android.webkit.WebView;
|
|
39
38
|
* from JavaScript.
|
40
39
|
*/
|
41
40
|
public class PluginManager {
|
41
|
+
private static String TAG = "PluginManager";
|
42
|
+
|
43
|
+
// List of service entries
|
44
|
+
private final HashMap<String, PluginEntry> entries = new HashMap<String, PluginEntry>();
|
45
|
+
|
46
|
+
private final CordovaInterface ctx;
|
47
|
+
private final WebView app;
|
48
|
+
|
49
|
+
// Flag to track first time through
|
50
|
+
private boolean firstRun;
|
42
51
|
|
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
52
|
// Map URL schemes like foo: to plugins that want to handle those schemes
|
50
53
|
// 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
|
-
}
|
54
|
+
protected HashMap<String, String> urlMap = new HashMap<String, String>();
|
228
55
|
|
229
56
|
/**
|
230
|
-
*
|
231
|
-
* If plugin is already created, then just return it.
|
57
|
+
* Constructor.
|
232
58
|
*
|
233
|
-
* @param
|
234
|
-
* @param
|
235
|
-
|
236
|
-
|
59
|
+
* @param app
|
60
|
+
* @param ctx
|
61
|
+
*/
|
62
|
+
public PluginManager(WebView app, CordovaInterface ctx) {
|
63
|
+
this.ctx = ctx;
|
64
|
+
this.app = app;
|
65
|
+
this.firstRun = true;
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Init when loading a new HTML page into webview.
|
70
|
+
*/
|
71
|
+
public void init() {
|
72
|
+
LOG.d(TAG, "init()");
|
73
|
+
|
74
|
+
// If first time, then load plugins from plugins.xml file
|
75
|
+
if (firstRun) {
|
76
|
+
this.loadPlugins();
|
77
|
+
firstRun = false;
|
78
|
+
}
|
79
|
+
|
80
|
+
// Stop plugins on current HTML page and discard plugin objects
|
81
|
+
else {
|
82
|
+
this.onPause(false);
|
83
|
+
this.onDestroy();
|
84
|
+
this.clearPluginObjects();
|
85
|
+
}
|
86
|
+
|
87
|
+
// Start up all plugins that have onload specified
|
88
|
+
this.startupPlugins();
|
89
|
+
}
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Load plugins from res/xml/plugins.xml
|
93
|
+
*/
|
94
|
+
public void loadPlugins() {
|
95
|
+
int id = ctx.getResources().getIdentifier("plugins", "xml", ctx.getPackageName());
|
96
|
+
if (id == 0) {
|
97
|
+
pluginConfigurationMissing();
|
98
|
+
}
|
99
|
+
XmlResourceParser xml = ctx.getResources().getXml(id);
|
100
|
+
int eventType = -1;
|
101
|
+
String service = "", pluginClass = "";
|
102
|
+
boolean onload = false;
|
103
|
+
PluginEntry entry = null;
|
104
|
+
while (eventType != XmlResourceParser.END_DOCUMENT) {
|
105
|
+
if (eventType == XmlResourceParser.START_TAG) {
|
106
|
+
String strNode = xml.getName();
|
107
|
+
if (strNode.equals("plugin")) {
|
108
|
+
service = xml.getAttributeValue(null, "name");
|
109
|
+
pluginClass = xml.getAttributeValue(null, "value");
|
110
|
+
// System.out.println("Plugin: "+name+" => "+value);
|
111
|
+
onload = "true".equals(xml.getAttributeValue(null, "onload"));
|
112
|
+
entry = new PluginEntry(service, pluginClass, onload);
|
113
|
+
this.addService(entry);
|
114
|
+
} else if (strNode.equals("url-filter")) {
|
115
|
+
this.urlMap.put(xml.getAttributeValue(null, "value"), service);
|
116
|
+
}
|
117
|
+
}
|
118
|
+
try {
|
119
|
+
eventType = xml.next();
|
120
|
+
} catch (XmlPullParserException e) {
|
121
|
+
e.printStackTrace();
|
122
|
+
} catch (IOException e) {
|
123
|
+
e.printStackTrace();
|
124
|
+
}
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
/**
|
129
|
+
* Delete all plugin objects.
|
237
130
|
*/
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
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;
|
131
|
+
public void clearPluginObjects() {
|
132
|
+
for (PluginEntry entry : this.entries.values()) {
|
133
|
+
entry.plugin = null;
|
134
|
+
}
|
254
135
|
}
|
255
|
-
|
136
|
+
|
256
137
|
/**
|
257
|
-
*
|
138
|
+
* Create plugins objects that have onload set.
|
139
|
+
*/
|
140
|
+
public void startupPlugins() {
|
141
|
+
for (PluginEntry entry : this.entries.values()) {
|
142
|
+
if (entry.onload) {
|
143
|
+
entry.createPlugin(this.app, this.ctx);
|
144
|
+
}
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
/**
|
149
|
+
* Receives a request for execution and fulfills it by finding the appropriate
|
150
|
+
* Java class and calling it's execute method.
|
151
|
+
*
|
152
|
+
* PluginManager.exec can be used either synchronously or async. In either case, a JSON encoded
|
153
|
+
* string is returned that will indicate if any errors have occurred when trying to find
|
154
|
+
* or execute the class denoted by the clazz argument.
|
258
155
|
*
|
259
|
-
*
|
156
|
+
* @param service String containing the service to run
|
157
|
+
* @param action String containt the action that the class is supposed to perform. This is
|
158
|
+
* passed to the plugin execute method and it is up to the plugin developer
|
159
|
+
* how to deal with it.
|
160
|
+
* @param callbackId String containing the id of the callback that is execute in JavaScript if
|
161
|
+
* this is an async plugin call.
|
162
|
+
* @param args An Array literal string containing any arguments needed in the
|
163
|
+
* plugin execute method.
|
164
|
+
* @param async Boolean indicating whether the calling JavaScript code is expecting an
|
165
|
+
* immediate return value. If true, either Cordova.callbackSuccess(...) or
|
166
|
+
* Cordova.callbackError(...) is called once the plugin code has executed.
|
260
167
|
*
|
261
|
-
* @
|
262
|
-
* @return
|
168
|
+
* @return JSON encoded string with a response message and status.
|
263
169
|
*/
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
170
|
+
@SuppressWarnings("unchecked")
|
171
|
+
public String exec(final String service, final String action, final String callbackId, final String jsonArgs, final boolean async) {
|
172
|
+
PluginResult cr = null;
|
173
|
+
boolean runAsync = async;
|
174
|
+
try {
|
175
|
+
final JSONArray args = new JSONArray(jsonArgs);
|
176
|
+
final IPlugin plugin = this.getPlugin(service);
|
177
|
+
final CordovaInterface ctx = this.ctx;
|
178
|
+
if (plugin != null) {
|
179
|
+
runAsync = async && !plugin.isSynch(action);
|
180
|
+
if (runAsync) {
|
181
|
+
// Run this on a different thread so that this one can return back to JS
|
182
|
+
Thread thread = new Thread(new Runnable() {
|
183
|
+
public void run() {
|
184
|
+
try {
|
185
|
+
// Call execute on the plugin so that it can do it's thing
|
186
|
+
PluginResult cr = plugin.execute(action, args, callbackId);
|
187
|
+
int status = cr.getStatus();
|
188
|
+
|
189
|
+
// If no result to be sent and keeping callback, then no need to sent back to JavaScript
|
190
|
+
if ((status == PluginResult.Status.NO_RESULT.ordinal()) && cr.getKeepCallback()) {
|
191
|
+
}
|
192
|
+
|
193
|
+
// Check the success (OK, NO_RESULT & !KEEP_CALLBACK)
|
194
|
+
else if ((status == PluginResult.Status.OK.ordinal()) || (status == PluginResult.Status.NO_RESULT.ordinal())) {
|
195
|
+
ctx.sendJavascript(cr.toSuccessCallbackString(callbackId));
|
196
|
+
}
|
197
|
+
|
198
|
+
// If error
|
199
|
+
else {
|
200
|
+
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
201
|
+
}
|
202
|
+
} catch (Exception e) {
|
203
|
+
PluginResult cr = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
|
204
|
+
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
205
|
+
}
|
206
|
+
}
|
207
|
+
});
|
208
|
+
thread.start();
|
209
|
+
return "";
|
210
|
+
} else {
|
211
|
+
// Call execute on the plugin so that it can do it's thing
|
212
|
+
cr = plugin.execute(action, args, callbackId);
|
213
|
+
|
214
|
+
// If no result to be sent and keeping callback, then no need to sent back to JavaScript
|
215
|
+
if ((cr.getStatus() == PluginResult.Status.NO_RESULT.ordinal()) && cr.getKeepCallback()) {
|
216
|
+
return "";
|
217
|
+
}
|
218
|
+
}
|
219
|
+
}
|
220
|
+
} catch (JSONException e) {
|
221
|
+
System.out.println("ERROR: " + e.toString());
|
222
|
+
cr = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
223
|
+
}
|
224
|
+
// if async we have already returned at this point unless there was an error...
|
225
|
+
if (runAsync) {
|
226
|
+
if (cr == null) {
|
227
|
+
cr = new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION);
|
228
|
+
}
|
229
|
+
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
230
|
+
}
|
231
|
+
return (cr != null ? cr.getJSONString() : "{ status: 0, message: 'all good' }");
|
271
232
|
}
|
272
|
-
|
233
|
+
|
273
234
|
/**
|
274
|
-
*
|
275
|
-
*
|
235
|
+
* Get the plugin object that implements the service.
|
236
|
+
* If the plugin object does not already exist, then create it.
|
237
|
+
* If the service doesn't exist, then return null.
|
276
238
|
*
|
277
|
-
* @param
|
278
|
-
* @
|
239
|
+
* @param service The name of the service.
|
240
|
+
* @return IPlugin or null
|
279
241
|
*/
|
280
|
-
|
281
|
-
|
242
|
+
private IPlugin getPlugin(String service) {
|
243
|
+
PluginEntry entry = entries.get(service);
|
244
|
+
if (entry == null) {
|
245
|
+
return null;
|
246
|
+
}
|
247
|
+
IPlugin plugin = entry.plugin;
|
248
|
+
if (plugin == null) {
|
249
|
+
plugin = entry.createPlugin(this.app, this.ctx);
|
250
|
+
}
|
251
|
+
return plugin;
|
282
252
|
}
|
283
253
|
|
284
254
|
/**
|
285
|
-
*
|
255
|
+
* Add a plugin class that implements a service to the service entry table.
|
256
|
+
* This does not create the plugin object instance.
|
286
257
|
*
|
287
|
-
* @param
|
258
|
+
* @param service The service name
|
259
|
+
* @param className The plugin class name
|
260
|
+
*/
|
261
|
+
public void addService(String service, String className) {
|
262
|
+
PluginEntry entry = new PluginEntry(service, className, false);
|
263
|
+
this.addService(entry);
|
264
|
+
}
|
265
|
+
|
266
|
+
/**
|
267
|
+
* Add a plugin class that implements a service to the service entry table.
|
268
|
+
* This does not create the plugin object instance.
|
269
|
+
*
|
270
|
+
* @param entry The plugin entry
|
271
|
+
*/
|
272
|
+
public void addService(PluginEntry entry) {
|
273
|
+
this.entries.put(entry.service, entry);
|
274
|
+
}
|
275
|
+
|
276
|
+
/**
|
277
|
+
* Called when the system is about to start resuming a previous activity.
|
278
|
+
*
|
279
|
+
* @param multitasking Flag indicating if multitasking is turned on for app
|
288
280
|
*/
|
289
281
|
public void onPause(boolean multitasking) {
|
290
|
-
for (
|
291
|
-
plugin
|
282
|
+
for (PluginEntry entry : this.entries.values()) {
|
283
|
+
if (entry.plugin != null) {
|
284
|
+
entry.plugin.onPause(multitasking);
|
285
|
+
}
|
292
286
|
}
|
293
287
|
}
|
294
|
-
|
288
|
+
|
295
289
|
/**
|
296
|
-
* Called when the activity will start interacting with the user.
|
290
|
+
* Called when the activity will start interacting with the user.
|
297
291
|
*
|
298
|
-
* @param multitasking
|
292
|
+
* @param multitasking Flag indicating if multitasking is turned on for app
|
299
293
|
*/
|
300
294
|
public void onResume(boolean multitasking) {
|
301
|
-
for (
|
302
|
-
plugin
|
295
|
+
for (PluginEntry entry : this.entries.values()) {
|
296
|
+
if (entry.plugin != null) {
|
297
|
+
entry.plugin.onResume(multitasking);
|
298
|
+
}
|
303
299
|
}
|
304
300
|
}
|
305
301
|
|
306
302
|
/**
|
307
|
-
* The final call you receive before your activity is destroyed.
|
303
|
+
* The final call you receive before your activity is destroyed.
|
308
304
|
*/
|
309
305
|
public void onDestroy() {
|
310
|
-
for (
|
311
|
-
plugin
|
306
|
+
for (PluginEntry entry : this.entries.values()) {
|
307
|
+
if (entry.plugin != null) {
|
308
|
+
entry.plugin.onDestroy();
|
309
|
+
}
|
312
310
|
}
|
313
311
|
}
|
314
312
|
|
315
313
|
/**
|
316
|
-
* Send a message to all plugins.
|
314
|
+
* Send a message to all plugins.
|
317
315
|
*
|
318
|
-
* @param id
|
319
|
-
* @param data
|
316
|
+
* @param id The message id
|
317
|
+
* @param data The message data
|
320
318
|
*/
|
321
319
|
public void postMessage(String id, Object data) {
|
322
|
-
for (
|
323
|
-
plugin
|
320
|
+
for (PluginEntry entry : this.entries.values()) {
|
321
|
+
if (entry.plugin != null) {
|
322
|
+
entry.plugin.onMessage(id, data);
|
323
|
+
}
|
324
324
|
}
|
325
325
|
}
|
326
326
|
|
327
327
|
/**
|
328
|
-
* Called when the activity receives a new intent.
|
329
|
-
*/
|
328
|
+
* Called when the activity receives a new intent.
|
329
|
+
*/
|
330
330
|
public void onNewIntent(Intent intent) {
|
331
|
-
for (
|
332
|
-
plugin
|
331
|
+
for (PluginEntry entry : this.entries.values()) {
|
332
|
+
if (entry.plugin != null) {
|
333
|
+
entry.plugin.onNewIntent(intent);
|
334
|
+
}
|
333
335
|
}
|
334
336
|
}
|
335
337
|
|
336
338
|
/**
|
337
339
|
* Called when the URL of the webview changes.
|
338
340
|
*
|
339
|
-
* @param url
|
340
|
-
* @return
|
341
|
+
* @param url The URL that is being changed to.
|
342
|
+
* @return Return false to allow the URL to load, return true to prevent the URL from loading.
|
341
343
|
*/
|
342
344
|
public boolean onOverrideUrlLoading(String url) {
|
343
|
-
|
345
|
+
Iterator<Entry<String, String>> it = this.urlMap.entrySet().iterator();
|
344
346
|
while (it.hasNext()) {
|
345
347
|
HashMap.Entry<String, String> pairs = it.next();
|
346
348
|
if (url.startsWith(pairs.getKey())) {
|
347
|
-
|
349
|
+
return this.getPlugin(pairs.getValue()).onOverrideUrlLoading(url);
|
348
350
|
}
|
349
351
|
}
|
350
|
-
|
352
|
+
return false;
|
351
353
|
}
|
352
354
|
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
355
|
+
private void pluginConfigurationMissing() {
|
356
|
+
System.err.println("=====================================================================================");
|
357
|
+
System.err.println("ERROR: plugin.xml is missing. Add res/xml/plugins.xml to your project.");
|
358
|
+
System.err.println("https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=blob;f=framework/res/xml/plugins.xml");
|
359
|
+
System.err.println("=====================================================================================");
|
360
|
+
}
|
359
361
|
}
|
@@ -84,11 +84,11 @@ public class PluginResult {
|
|
84
84
|
}
|
85
85
|
|
86
86
|
public String toSuccessCallbackString(String callbackId) {
|
87
|
-
return "
|
87
|
+
return "cordova.callbackSuccess('"+callbackId+"',"+this.getJSONString()+");";
|
88
88
|
}
|
89
89
|
|
90
90
|
public String toErrorCallbackString(String callbackId) {
|
91
|
-
return "
|
91
|
+
return "cordova.callbackError('"+callbackId+"', " + this.getJSONString()+ ");";
|
92
92
|
}
|
93
93
|
|
94
94
|
public static String[] StatusMessages = new String[] {
|
@@ -0,0 +1,42 @@
|
|
1
|
+
Bryce Curtis (5):
|
2
|
+
[CB-352] Support initializing DroidGap with existing WebView, WebViewClient and webViewChrome. [CB-353] Create PluginEntry object to use by PluginManager.
|
3
|
+
[CB-367] Back button event should fire on key up not key down Also changed menu key and search key to be consistent.
|
4
|
+
Tests to verify Android native features.
|
5
|
+
[CB-423] Problem displaying patch-9 splash screen.
|
6
|
+
Update project template cordova.js reference and title.
|
7
|
+
|
8
|
+
Fil Maj (6):
|
9
|
+
switched from "require" syntax to "cordova.require"
|
10
|
+
cordova.require("cordova") is pretty funny. wish i didnt write it
|
11
|
+
updates to JS: removing require+define from global scope, tweaking geolocation code, online/offline events fire on document now
|
12
|
+
removed old javascript files and removed unused target + commented out lines in build.xml
|
13
|
+
spacing fixes, null check in getPhoneType in contacts, returning error integers instead of objects in contacts
|
14
|
+
updating network status plugin label and updating cordova-js to latest
|
15
|
+
|
16
|
+
Joe Bowser (11):
|
17
|
+
We show the default 404 on non-resolved domains
|
18
|
+
Fixing CB-210 with patch and adding fix for CB-210
|
19
|
+
Tweaked File Transfer to fix CB-74
|
20
|
+
Changing to the modern icon
|
21
|
+
Added temporary Cordova splash for now
|
22
|
+
Checking for the callback server before we call sendJavascript for the Kindle Fire, CB-247
|
23
|
+
Fixing CB-343: We need to respect the whitelist
|
24
|
+
Fixing a bug with File Upload on Android where Chunked mode isn't used by default
|
25
|
+
First stab at CB-21, I really need more info before I can close this
|
26
|
+
Tagged 1.6rc1
|
27
|
+
Fixing the template, since this doesn't have to be unit tested. :)
|
28
|
+
|
29
|
+
macdonst (12):
|
30
|
+
CB-383: Fixes issue with misspelled destinationType for Camera.getPicture()
|
31
|
+
Fix for CB-389: resolveLocalFileSystemURI does not work on a resized image captured from Camera.getPicture()
|
32
|
+
Fixing license header in com.phonegap.api.PluginManager
|
33
|
+
CB-321: Media API: 'mediaSuccess' callback param to new Media() is called soon after new obj created
|
34
|
+
CB-163: contactFindOptions.filter does not work as expected on Android
|
35
|
+
CB-426: camera.getPicture ignores mediaType in 1.5
|
36
|
+
Updating cordova.android.js for CB-421 and CB-426
|
37
|
+
CB-438: File metadata.modificationTime returns an invalid date
|
38
|
+
Return MediaError object and not error code from native side of Media API
|
39
|
+
CB-446: Enhance setting data source for local files in AudioPlayer
|
40
|
+
CB-453: FileWriter.append - Chinese characters are not appended to the file correctly
|
41
|
+
CB-446: Enhance setting data source for local files in AudioPlayer
|
42
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<classpath>
|
3
|
+
<classpathentry kind="src" path="src"/>
|
4
|
+
<classpathentry kind="src" path="gen"/>
|
5
|
+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
6
|
+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
7
|
+
<classpathentry kind="output" path="bin/classes"/>
|
8
|
+
</classpath>
|