javascript and native side of a URL caching plugin + android plugin framework is complete

This commit is contained in:
Dave Johnson
2010-07-28 17:26:23 -07:00
parent 742910f369
commit 2b2b4f5dd4
8 changed files with 290 additions and 24 deletions
+18
View File
@@ -0,0 +1,18 @@
PhoneGap.addPlugin = function(name, obj) {
if ( !window.plugins ) {
window.plugins = {};
}
if ( !window.plugins[name] ) {
window.plugins[name] = obj;
}
}
function Cache() {
}
Cache.prototype.getCachedPathForURI = function(uri, success, fail) {
PhoneGap.execAsync(success, fail, 'com.phonegap.api.impl.Cache', 'getCachedPathForURI', [uri]);
};
PhoneGap.addPlugin('cache', new Cache());
+23 -5
View File
@@ -6,7 +6,7 @@ if (typeof(DeviceInfo) != 'object')
* information about the state of PhoneGap.
* @class
*/
PhoneGap = {
var PhoneGap = {
queue: {
ready: true,
commands: [],
@@ -205,6 +205,8 @@ document.addEventListener = function(evt, handler, capture) {
PhoneGap.callbackId = 0;
PhoneGap.callbacks = {};
/**
* Execute a PhoneGap command in a queued fashion, to ensure commands do not
@@ -213,12 +215,28 @@ document.addEventListener = function(evt, handler, capture) {
* @param {String} command Command to be run in PhoneGap, e.g. "ClassName.method"
* @param {String[]} [args] Zero or more arguments to pass to the method
*/
PhoneGap.exec = function() {
PhoneGap.queue.commands.push(arguments);
if (PhoneGap.queue.timer == null)
PhoneGap.queue.timer = setInterval(PhoneGap.run_command, 10);
PhoneGap.exec = function(clazz, action, args) {
CommandManager.exec(clazz, action, callbackId, args.join('__PHONEGAP__'), false);
};
PhoneGap.execAsync = function(success, fail, clazz, action, args) {
var callbackId = clazz + PhoneGap.callbackId++;
PhoneGap.callbacks[callbackId] = {success:success, fail:fail};
CommandManager.exec(clazz, action, callbackId, args.join('__PHONEGAP__'), true);
return callbackId;
};
PhoneGap.callbackSuccess = function(callbackId, args) {
PhoneGap.callbacks[callbackId].success.apply(this, JSON.parse(args));
delete PhoneGap.callbacks[callbackId];
};
PhoneGap.callbackFailure = function(callbackId, args) {
PhoneGap.callbacks[callbackId].fail.apply(this, JSON.parse(args));
delete PhoneGap.callbacks[callbackId];
};
/**
* Internal function used to dispatch the request to PhoneGap. It processes the
* command queue and executes the next command on the list. If one of the