mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-31 17:32:51 +08:00
Refactor out the Java casting code
When we return JSON to the Java side it does not have the proper methods such as Contact.save() so we need to cast the JSON to the correct JS object. This used to be done from the Java layer calling the right method to cast the JSON. In this new approach the JavaScript layer will no what needs to be cast and call it's own internal function to do the cast.
This commit is contained in:
parent
77547f8826
commit
9aa1cd756a
@ -95,7 +95,7 @@ var Capture = function(){
|
|||||||
* @param {CaptureAudioOptions} options
|
* @param {CaptureAudioOptions} options
|
||||||
*/
|
*/
|
||||||
Capture.prototype.captureAudio = function(successCallback, errorCallback, options){
|
Capture.prototype.captureAudio = function(successCallback, errorCallback, options){
|
||||||
Cordova.exec(successCallback, errorCallback, "Capture", "captureAudio", [options]);
|
navigator.device.capture._capture("captureAudio", successCallback, errorCallback, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,30 +106,7 @@ Capture.prototype.captureAudio = function(successCallback, errorCallback, option
|
|||||||
* @param {CaptureImageOptions} options
|
* @param {CaptureImageOptions} options
|
||||||
*/
|
*/
|
||||||
Capture.prototype.captureImage = function(successCallback, errorCallback, options){
|
Capture.prototype.captureImage = function(successCallback, errorCallback, options){
|
||||||
Cordova.exec(successCallback, errorCallback, "Capture", "captureImage", [options]);
|
navigator.device.capture._capture("captureImage", successCallback, errorCallback, options);
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Launch camera application for taking image(s).
|
|
||||||
*
|
|
||||||
* @param {Function} successCB
|
|
||||||
* @param {Function} errorCB
|
|
||||||
* @param {CaptureImageOptions} options
|
|
||||||
*/
|
|
||||||
Capture.prototype._castMediaFile = function(pluginResult){
|
|
||||||
var mediaFiles = [];
|
|
||||||
var i;
|
|
||||||
for (i = 0; i < pluginResult.message.length; i++) {
|
|
||||||
var mediaFile = new MediaFile();
|
|
||||||
mediaFile.name = pluginResult.message[i].name;
|
|
||||||
mediaFile.fullPath = pluginResult.message[i].fullPath;
|
|
||||||
mediaFile.type = pluginResult.message[i].type;
|
|
||||||
mediaFile.lastModifiedDate = pluginResult.message[i].lastModifiedDate;
|
|
||||||
mediaFile.size = pluginResult.message[i].size;
|
|
||||||
mediaFiles.push(mediaFile);
|
|
||||||
}
|
|
||||||
pluginResult.message = mediaFiles;
|
|
||||||
return pluginResult;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -140,9 +117,36 @@ Capture.prototype._castMediaFile = function(pluginResult){
|
|||||||
* @param {CaptureVideoOptions} options
|
* @param {CaptureVideoOptions} options
|
||||||
*/
|
*/
|
||||||
Capture.prototype.captureVideo = function(successCallback, errorCallback, options){
|
Capture.prototype.captureVideo = function(successCallback, errorCallback, options){
|
||||||
Cordova.exec(successCallback, errorCallback, "Capture", "captureVideo", [options]);
|
navigator.device.capture._capture("captureVideo", successCallback, errorCallback, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launches the correct capture.
|
||||||
|
*
|
||||||
|
* @param (DOMString} type
|
||||||
|
* @param {Function} successCB
|
||||||
|
* @param {Function} errorCB
|
||||||
|
* @param {CaptureVideoOptions} options
|
||||||
|
*/
|
||||||
|
Capture.prototype._capture = function(type, successCallback, errorCallback, options){
|
||||||
|
var win = function(result) {
|
||||||
|
var mediaFiles = [];
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < pluginResult.message.length; i++) {
|
||||||
|
var mediaFile = new MediaFile();
|
||||||
|
mediaFile.name = pluginResult.message[i].name;
|
||||||
|
mediaFile.fullPath = pluginResult.message[i].fullPath;
|
||||||
|
mediaFile.type = pluginResult.message[i].type;
|
||||||
|
mediaFile.lastModifiedDate = pluginResult.message[i].lastModifiedDate;
|
||||||
|
mediaFile.size = pluginResult.message[i].size;
|
||||||
|
mediaFiles.push(mediaFile);
|
||||||
|
}
|
||||||
|
successCallback(mediaFiles);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCallback, "Capture", type, [options]);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates a set of parameters that the capture device supports.
|
* Encapsulates a set of parameters that the capture device supports.
|
||||||
*/
|
*/
|
||||||
|
@ -73,9 +73,17 @@ Compass.prototype.getCurrentHeading = function(successCallback, errorCallback, o
|
|||||||
console.log("Compass Error: errorCallback is not a function");
|
console.log("Compass Error: errorCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var win = function(result) {
|
||||||
|
if (result.timestamp) {
|
||||||
|
var timestamp = new Date(result.timestamp);
|
||||||
|
result.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
successCallback(result);
|
||||||
|
};
|
||||||
|
|
||||||
// Get heading
|
// Get heading
|
||||||
Cordova.exec(successCallback, errorCallback, "Compass", "getHeading", []);
|
Cordova.exec(win, errorCallback, "Compass", "getHeading", []);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,7 +124,14 @@ Compass.prototype.watchHeading= function(successCallback, errorCallback, options
|
|||||||
var id = Cordova.createUUID();
|
var id = Cordova.createUUID();
|
||||||
navigator.compass.timers[id] = setInterval(
|
navigator.compass.timers[id] = setInterval(
|
||||||
function() {
|
function() {
|
||||||
Cordova.exec(successCallback, errorCallback, "Compass", "getHeading", []);
|
var win = function(result) {
|
||||||
|
if (result.timestamp) {
|
||||||
|
var timestamp = new Date(result.timestamp);
|
||||||
|
result.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
successCallback(result);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCallback, "Compass", "getHeading", []);
|
||||||
}, (frequency ? frequency : 1));
|
}, (frequency ? frequency : 1));
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
|
@ -259,7 +259,14 @@ Contacts.prototype.find = function(fields, successCB, errorCB, options) {
|
|||||||
errorCB({"code": ContactError.INVALID_ARGUMENT_ERROR});
|
errorCB({"code": ContactError.INVALID_ARGUMENT_ERROR});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Cordova.exec(successCB, errorCB, "Contacts", "search", [fields, options]);
|
var win = function(result) {
|
||||||
|
var cs = [];
|
||||||
|
for (var i = 0, l = result.length; i < l; i++) {
|
||||||
|
cs.push(navigator.contacts.create(result[i]));
|
||||||
|
}
|
||||||
|
successCB(cs);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCB, "Contacts", "search", [fields, options]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -281,24 +288,6 @@ Contacts.prototype.create = function(properties) {
|
|||||||
return contact;
|
return contact;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* This function returns and array of contacts. It is required as we need to convert raw
|
|
||||||
* JSON objects into concrete Contact objects. Currently this method is called after
|
|
||||||
* navigator.contacts.find but before the find methods success call back.
|
|
||||||
*
|
|
||||||
* @param jsonArray an array of JSON Objects that need to be converted to Contact objects.
|
|
||||||
* @returns an array of Contact objects
|
|
||||||
*/
|
|
||||||
Contacts.prototype.cast = function(pluginResult) {
|
|
||||||
var contacts = [];
|
|
||||||
var i;
|
|
||||||
for (i=0; i<pluginResult.message.length; i++) {
|
|
||||||
contacts.push(navigator.contacts.create(pluginResult.message[i]));
|
|
||||||
}
|
|
||||||
pluginResult.message = contacts;
|
|
||||||
return pluginResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ContactFindOptions.
|
* ContactFindOptions.
|
||||||
* @constructor
|
* @constructor
|
||||||
|
@ -624,7 +624,25 @@ var DirectoryReader = function(fullPath){
|
|||||||
* @param {Function} errorCallback is called with a FileError
|
* @param {Function} errorCallback is called with a FileError
|
||||||
*/
|
*/
|
||||||
DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) {
|
DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) {
|
||||||
Cordova.exec(successCallback, errorCallback, "File", "readEntries", [this.fullPath]);
|
var win = function(result) {
|
||||||
|
var retVal = [];
|
||||||
|
for (var i=0; i<result.length; i++) {
|
||||||
|
var entry = null;
|
||||||
|
if (result[i].isDirectory) {
|
||||||
|
entry = new DirectoryEntry();
|
||||||
|
}
|
||||||
|
else if (result[i].isFile) {
|
||||||
|
entry = new FileEntry();
|
||||||
|
}
|
||||||
|
entry.isDirectory = result[i].isDirectory;
|
||||||
|
entry.isFile = result[i].isFile;
|
||||||
|
entry.name = result[i].name;
|
||||||
|
entry.fullPath = result[i].fullPath;
|
||||||
|
retVal.push(entry);
|
||||||
|
}
|
||||||
|
successCallback(retVal);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCallback, "File", "readEntries", [this.fullPath]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -654,7 +672,21 @@ var DirectoryEntry = function() {
|
|||||||
* @param {Function} errorCallback is called with a FileError
|
* @param {Function} errorCallback is called with a FileError
|
||||||
*/
|
*/
|
||||||
DirectoryEntry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) {
|
DirectoryEntry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) {
|
||||||
Cordova.exec(successCallback, errorCallback, "File", "copyTo", [this.fullPath, parent, newName]);
|
var win = function(result) {
|
||||||
|
var entry = null;
|
||||||
|
if (result.isDirectory) {
|
||||||
|
entry = new DirectoryEntry();
|
||||||
|
}
|
||||||
|
else if (result.isFile) {
|
||||||
|
entry = new FileEntry();
|
||||||
|
}
|
||||||
|
entry.isDirectory = result.isDirectory;
|
||||||
|
entry.isFile = result.isFile;
|
||||||
|
entry.name = result.name;
|
||||||
|
entry.fullPath = result.fullPath;
|
||||||
|
successCallback(entry);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCallback, "File", "copyTo", [this.fullPath, parent, newName]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -664,7 +696,11 @@ DirectoryEntry.prototype.copyTo = function(parent, newName, successCallback, err
|
|||||||
* @param {Function} errorCallback is called with a FileError
|
* @param {Function} errorCallback is called with a FileError
|
||||||
*/
|
*/
|
||||||
DirectoryEntry.prototype.getMetadata = function(successCallback, errorCallback) {
|
DirectoryEntry.prototype.getMetadata = function(successCallback, errorCallback) {
|
||||||
Cordova.exec(successCallback, errorCallback, "File", "getMetadata", [this.fullPath]);
|
var win = function(result) {
|
||||||
|
result.modificationTime = new Date(result.modificationTime);
|
||||||
|
successCallback(result);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCallback, "File", "getMetadata", [this.fullPath]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -674,7 +710,16 @@ DirectoryEntry.prototype.getMetadata = function(successCallback, errorCallback)
|
|||||||
* @param {Function} errorCallback is called with a FileError
|
* @param {Function} errorCallback is called with a FileError
|
||||||
*/
|
*/
|
||||||
DirectoryEntry.prototype.getParent = function(successCallback, errorCallback) {
|
DirectoryEntry.prototype.getParent = function(successCallback, errorCallback) {
|
||||||
Cordova.exec(successCallback, errorCallback, "File", "getParent", [this.fullPath]);
|
var win = function(result) {
|
||||||
|
var entry = null;
|
||||||
|
entry = new DirectoryEntry();
|
||||||
|
entry.isDirectory = result.isDirectory;
|
||||||
|
entry.isFile = result.isFile;
|
||||||
|
entry.name = result.name;
|
||||||
|
entry.fullPath = result.fullPath;
|
||||||
|
successCallback(entry);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCallback, "File", "getParent", [this.fullPath]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -686,7 +731,21 @@ DirectoryEntry.prototype.getParent = function(successCallback, errorCallback) {
|
|||||||
* @param {Function} errorCallback is called with a FileError
|
* @param {Function} errorCallback is called with a FileError
|
||||||
*/
|
*/
|
||||||
DirectoryEntry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) {
|
DirectoryEntry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) {
|
||||||
Cordova.exec(successCallback, errorCallback, "File", "moveTo", [this.fullPath, parent, newName]);
|
var win = function(result) {
|
||||||
|
var entry = null;
|
||||||
|
if (result.isDirectory) {
|
||||||
|
entry = new DirectoryEntry();
|
||||||
|
}
|
||||||
|
else if (result.isFile) {
|
||||||
|
entry = new FileEntry();
|
||||||
|
}
|
||||||
|
entry.isDirectory = result.isDirectory;
|
||||||
|
entry.isFile = result.isFile;
|
||||||
|
entry.name = result.name;
|
||||||
|
entry.fullPath = result.fullPath;
|
||||||
|
successCallback(entry);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCallback, "File", "moveTo", [this.fullPath, parent, newName]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -725,7 +784,16 @@ DirectoryEntry.prototype.createReader = function(successCallback, errorCallback)
|
|||||||
* @param {Function} errorCallback is called with a FileError
|
* @param {Function} errorCallback is called with a FileError
|
||||||
*/
|
*/
|
||||||
DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback) {
|
DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback) {
|
||||||
Cordova.exec(successCallback, errorCallback, "File", "getDirectory", [this.fullPath, path, options]);
|
var win = function(result) {
|
||||||
|
var entry = null;
|
||||||
|
entry = new DirectoryEntry();
|
||||||
|
entry.isDirectory = result.isDirectory;
|
||||||
|
entry.isFile = result.isFile;
|
||||||
|
entry.name = result.name;
|
||||||
|
entry.fullPath = result.fullPath;
|
||||||
|
successCallback(entry);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCallback, "File", "getDirectory", [this.fullPath, path, options]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -737,7 +805,16 @@ DirectoryEntry.prototype.getDirectory = function(path, options, successCallback,
|
|||||||
* @param {Function} errorCallback is called with a FileError
|
* @param {Function} errorCallback is called with a FileError
|
||||||
*/
|
*/
|
||||||
DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) {
|
DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) {
|
||||||
Cordova.exec(successCallback, errorCallback, "File", "getFile", [this.fullPath, path, options]);
|
var win = function(result) {
|
||||||
|
var entry = null;
|
||||||
|
entry = new FileEntry();
|
||||||
|
entry.isDirectory = result.isDirectory;
|
||||||
|
entry.isFile = result.isFile;
|
||||||
|
entry.name = result.name;
|
||||||
|
entry.fullPath = result.fullPath;
|
||||||
|
successCallback(entry);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCallback, "File", "getFile", [this.fullPath, path, options]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -777,7 +854,21 @@ var FileEntry = function() {
|
|||||||
* @param {Function} errorCallback is called with a FileError
|
* @param {Function} errorCallback is called with a FileError
|
||||||
*/
|
*/
|
||||||
FileEntry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) {
|
FileEntry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) {
|
||||||
Cordova.exec(successCallback, errorCallback, "File", "copyTo", [this.fullPath, parent, newName]);
|
var win = function(result) {
|
||||||
|
var entry = null;
|
||||||
|
if (result.isDirectory) {
|
||||||
|
entry = new DirectoryEntry();
|
||||||
|
}
|
||||||
|
else if (result.isFile) {
|
||||||
|
entry = new FileEntry();
|
||||||
|
}
|
||||||
|
entry.isDirectory = result.isDirectory;
|
||||||
|
entry.isFile = result.isFile;
|
||||||
|
entry.name = result.name;
|
||||||
|
entry.fullPath = result.fullPath;
|
||||||
|
successCallback(entry);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCallback, "File", "copyTo", [this.fullPath, parent, newName]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -787,7 +878,11 @@ FileEntry.prototype.copyTo = function(parent, newName, successCallback, errorCal
|
|||||||
* @param {Function} errorCallback is called with a FileError
|
* @param {Function} errorCallback is called with a FileError
|
||||||
*/
|
*/
|
||||||
FileEntry.prototype.getMetadata = function(successCallback, errorCallback) {
|
FileEntry.prototype.getMetadata = function(successCallback, errorCallback) {
|
||||||
Cordova.exec(successCallback, errorCallback, "File", "getMetadata", [this.fullPath]);
|
var win = function(result) {
|
||||||
|
result.modificationTime = new Date(result.modificationTime);
|
||||||
|
successCallback(result);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCallback, "File", "getMetadata", [this.fullPath]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -797,7 +892,16 @@ FileEntry.prototype.getMetadata = function(successCallback, errorCallback) {
|
|||||||
* @param {Function} errorCallback is called with a FileError
|
* @param {Function} errorCallback is called with a FileError
|
||||||
*/
|
*/
|
||||||
FileEntry.prototype.getParent = function(successCallback, errorCallback) {
|
FileEntry.prototype.getParent = function(successCallback, errorCallback) {
|
||||||
Cordova.exec(successCallback, errorCallback, "File", "getParent", [this.fullPath]);
|
var win = function(result) {
|
||||||
|
var entry = null;
|
||||||
|
entry = new DirectoryEntry();
|
||||||
|
entry.isDirectory = result.isDirectory;
|
||||||
|
entry.isFile = result.isFile;
|
||||||
|
entry.name = result.name;
|
||||||
|
entry.fullPath = result.fullPath;
|
||||||
|
successCallback(entry);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCallback, "File", "getParent", [this.fullPath]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -809,7 +913,21 @@ FileEntry.prototype.getParent = function(successCallback, errorCallback) {
|
|||||||
* @param {Function} errorCallback is called with a FileError
|
* @param {Function} errorCallback is called with a FileError
|
||||||
*/
|
*/
|
||||||
FileEntry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) {
|
FileEntry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) {
|
||||||
Cordova.exec(successCallback, errorCallback, "File", "moveTo", [this.fullPath, parent, newName]);
|
var win = function(result) {
|
||||||
|
var entry = null;
|
||||||
|
if (result.isDirectory) {
|
||||||
|
entry = new DirectoryEntry();
|
||||||
|
}
|
||||||
|
else if (result.isFile) {
|
||||||
|
entry = new FileEntry();
|
||||||
|
}
|
||||||
|
entry.isDirectory = result.isDirectory;
|
||||||
|
entry.isFile = result.isFile;
|
||||||
|
entry.name = result.name;
|
||||||
|
entry.fullPath = result.fullPath;
|
||||||
|
successCallback(entry);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCallback, "File", "moveTo", [this.fullPath, parent, newName]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -863,7 +981,16 @@ FileEntry.prototype.createWriter = function(successCallback, errorCallback) {
|
|||||||
* @param {Function} errorCallback is called with a FileError
|
* @param {Function} errorCallback is called with a FileError
|
||||||
*/
|
*/
|
||||||
FileEntry.prototype.file = function(successCallback, errorCallback) {
|
FileEntry.prototype.file = function(successCallback, errorCallback) {
|
||||||
Cordova.exec(successCallback, errorCallback, "File", "getFileMetadata", [this.fullPath]);
|
var win = function(result) {
|
||||||
|
var file = new File();
|
||||||
|
file.size = result.size;
|
||||||
|
file.type = result.type;
|
||||||
|
file.name = result.name;
|
||||||
|
file.fullPath = result.fullPath;
|
||||||
|
file.lastModifiedDate = new Date(result.lastModifiedDate);
|
||||||
|
successCallback(file);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCallback, "File", "getFileMetadata", [this.fullPath]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @constructor */
|
/** @constructor */
|
||||||
@ -892,7 +1019,20 @@ LocalFileSystem.prototype.requestFileSystem = function(type, size, successCallba
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Cordova.exec(successCallback, errorCallback, "File", "requestFileSystem", [type, size]);
|
var win = function(result){
|
||||||
|
console.log("in win of requestFileSystem");
|
||||||
|
console.log("Result: " + JSON.stringify(result));
|
||||||
|
var entry = null;
|
||||||
|
entry = new DirectoryEntry();
|
||||||
|
entry.isDirectory = result.root.isDirectory;
|
||||||
|
entry.isFile = result.root.isFile;
|
||||||
|
entry.name = result.root.name;
|
||||||
|
entry.fullPath = result.root.fullPath;
|
||||||
|
result.root = entry;
|
||||||
|
successCallback(result);
|
||||||
|
};
|
||||||
|
console.log("about to call requestFileSystem");
|
||||||
|
Cordova.exec(win, errorCallback, "File", "requestFileSystem", [type, size]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -903,84 +1043,24 @@ LocalFileSystem.prototype.requestFileSystem = function(type, size, successCallba
|
|||||||
* @param {Function} errorCallback is called with a FileError
|
* @param {Function} errorCallback is called with a FileError
|
||||||
*/
|
*/
|
||||||
LocalFileSystem.prototype.resolveLocalFileSystemURI = function(uri, successCallback, errorCallback) {
|
LocalFileSystem.prototype.resolveLocalFileSystemURI = function(uri, successCallback, errorCallback) {
|
||||||
Cordova.exec(successCallback, errorCallback, "File", "resolveLocalFileSystemURI", [uri]);
|
var win = function(result) {
|
||||||
};
|
console.log("in win of resolveLocalFileSystemURI");
|
||||||
|
console.log("Result: " + JSON.stringify(result));
|
||||||
/**
|
var entry = null;
|
||||||
* This function returns and array of contacts. It is required as we need to convert raw
|
if (result.isDirectory) {
|
||||||
* JSON objects into concrete Contact objects. Currently this method is called after
|
entry = new DirectoryEntry();
|
||||||
* navigator.service.contacts.find but before the find methods success call back.
|
}
|
||||||
*
|
else if (result.isFile) {
|
||||||
* @param a JSON Objects that need to be converted to DirectoryEntry or FileEntry objects.
|
entry = new FileEntry();
|
||||||
* @returns an entry
|
}
|
||||||
*/
|
entry.isDirectory = result.isDirectory;
|
||||||
LocalFileSystem.prototype._castFS = function(pluginResult) {
|
entry.isFile = result.isFile;
|
||||||
var entry = null;
|
entry.name = result.name;
|
||||||
entry = new DirectoryEntry();
|
entry.fullPath = result.fullPath;
|
||||||
entry.isDirectory = pluginResult.message.root.isDirectory;
|
successCallback(entry);
|
||||||
entry.isFile = pluginResult.message.root.isFile;
|
};
|
||||||
entry.name = pluginResult.message.root.name;
|
console.log("about to call resolveLocalFileSystemURI");
|
||||||
entry.fullPath = pluginResult.message.root.fullPath;
|
Cordova.exec(win, errorCallback, "File", "resolveLocalFileSystemURI", [uri]);
|
||||||
pluginResult.message.root = entry;
|
|
||||||
return pluginResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
LocalFileSystem.prototype._castEntry = function(pluginResult) {
|
|
||||||
var entry = null;
|
|
||||||
if (pluginResult.message.isDirectory) {
|
|
||||||
entry = new DirectoryEntry();
|
|
||||||
}
|
|
||||||
else if (pluginResult.message.isFile) {
|
|
||||||
entry = new FileEntry();
|
|
||||||
}
|
|
||||||
entry.isDirectory = pluginResult.message.isDirectory;
|
|
||||||
entry.isFile = pluginResult.message.isFile;
|
|
||||||
entry.name = pluginResult.message.name;
|
|
||||||
entry.fullPath = pluginResult.message.fullPath;
|
|
||||||
pluginResult.message = entry;
|
|
||||||
return pluginResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
LocalFileSystem.prototype._castEntries = function(pluginResult) {
|
|
||||||
var entries = pluginResult.message;
|
|
||||||
var retVal = [];
|
|
||||||
for (var i=0; i<entries.length; i++) {
|
|
||||||
retVal.push(window.localFileSystem._createEntry(entries[i]));
|
|
||||||
}
|
|
||||||
pluginResult.message = retVal;
|
|
||||||
return pluginResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
LocalFileSystem.prototype._createEntry = function(castMe) {
|
|
||||||
var entry = null;
|
|
||||||
if (castMe.isDirectory) {
|
|
||||||
entry = new DirectoryEntry();
|
|
||||||
}
|
|
||||||
else if (castMe.isFile) {
|
|
||||||
entry = new FileEntry();
|
|
||||||
}
|
|
||||||
entry.isDirectory = castMe.isDirectory;
|
|
||||||
entry.isFile = castMe.isFile;
|
|
||||||
entry.name = castMe.name;
|
|
||||||
entry.fullPath = castMe.fullPath;
|
|
||||||
return entry;
|
|
||||||
};
|
|
||||||
|
|
||||||
LocalFileSystem.prototype._castDate = function(pluginResult) {
|
|
||||||
if (pluginResult.message.modificationTime) {
|
|
||||||
var modTime = new Date(pluginResult.message.modificationTime);
|
|
||||||
pluginResult.message.modificationTime = modTime;
|
|
||||||
}
|
|
||||||
else if (pluginResult.message.lastModifiedDate) {
|
|
||||||
var file = new File();
|
|
||||||
file.size = pluginResult.message.size;
|
|
||||||
file.type = pluginResult.message.type;
|
|
||||||
file.name = pluginResult.message.name;
|
|
||||||
file.fullPath = pluginResult.message.fullPath;
|
|
||||||
file.lastModifiedDate = new Date(pluginResult.message.lastModifiedDate);
|
|
||||||
pluginResult.message = file;
|
|
||||||
}
|
|
||||||
return pluginResult;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,7 +91,21 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
|
|||||||
* @param errorCallback {Function} Callback to be invoked upon error
|
* @param errorCallback {Function} Callback to be invoked upon error
|
||||||
*/
|
*/
|
||||||
FileTransfer.prototype.download = function(source, target, successCallback, errorCallback) {
|
FileTransfer.prototype.download = function(source, target, successCallback, errorCallback) {
|
||||||
Cordova.exec(successCallback, errorCallback, 'FileTransfer', 'download', [source, target]);
|
var win = function(result) {
|
||||||
|
var entry = null;
|
||||||
|
if (result.isDirectory) {
|
||||||
|
entry = new DirectoryEntry();
|
||||||
|
}
|
||||||
|
else if (result.isFile) {
|
||||||
|
entry = new FileEntry();
|
||||||
|
}
|
||||||
|
entry.isDirectory = result.isDirectory;
|
||||||
|
entry.isFile = result.isFile;
|
||||||
|
entry.name = result.name;
|
||||||
|
entry.fullPath = result.fullPath;
|
||||||
|
successCallback(entry);
|
||||||
|
};
|
||||||
|
Cordova.exec(win, errorCallback, 'FileTransfer', 'download', [source, target]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,14 +31,6 @@ public class PluginResult extends org.apache.cordova.api.PluginResult {
|
|||||||
super(status, message);
|
super(status, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginResult(Status status, JSONArray message, String cast) {
|
|
||||||
super(status, message, cast);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PluginResult(Status status, JSONObject message, String cast) {
|
|
||||||
super(status, message, cast);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PluginResult(Status status, JSONArray message) {
|
public PluginResult(Status status, JSONArray message) {
|
||||||
super(status, message);
|
super(status, message);
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ public class Capture extends Plugin {
|
|||||||
|
|
||||||
if (results.length() >= limit) {
|
if (results.length() >= limit) {
|
||||||
// Send Uri back to JavaScript for listening to audio
|
// Send Uri back to JavaScript for listening to audio
|
||||||
this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId);
|
this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
|
||||||
} else {
|
} else {
|
||||||
// still need to capture more audio clips
|
// still need to capture more audio clips
|
||||||
captureAudio();
|
captureAudio();
|
||||||
@ -291,7 +291,7 @@ public class Capture extends Plugin {
|
|||||||
|
|
||||||
if (results.length() >= limit) {
|
if (results.length() >= limit) {
|
||||||
// Send Uri back to JavaScript for viewing image
|
// Send Uri back to JavaScript for viewing image
|
||||||
this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId);
|
this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
|
||||||
} else {
|
} else {
|
||||||
// still need to capture more images
|
// still need to capture more images
|
||||||
captureImage();
|
captureImage();
|
||||||
@ -308,7 +308,7 @@ public class Capture extends Plugin {
|
|||||||
|
|
||||||
if (results.length() >= limit) {
|
if (results.length() >= limit) {
|
||||||
// Send Uri back to JavaScript for viewing video
|
// Send Uri back to JavaScript for viewing video
|
||||||
this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId);
|
this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
|
||||||
} else {
|
} else {
|
||||||
// still need to capture more video clips
|
// still need to capture more video clips
|
||||||
captureVideo(duration);
|
captureVideo(duration);
|
||||||
@ -319,7 +319,7 @@ public class Capture extends Plugin {
|
|||||||
else if (resultCode == Activity.RESULT_CANCELED) {
|
else if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
// If we have partial results send them back to the user
|
// If we have partial results send them back to the user
|
||||||
if (results.length() > 0) {
|
if (results.length() > 0) {
|
||||||
this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId);
|
this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
|
||||||
}
|
}
|
||||||
// user canceled the action
|
// user canceled the action
|
||||||
else {
|
else {
|
||||||
@ -330,7 +330,7 @@ public class Capture extends Plugin {
|
|||||||
else {
|
else {
|
||||||
// If we have partial results send them back to the user
|
// If we have partial results send them back to the user
|
||||||
if (results.length() > 0) {
|
if (results.length() > 0) {
|
||||||
this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId);
|
this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
|
||||||
}
|
}
|
||||||
// something bad happened
|
// something bad happened
|
||||||
else {
|
else {
|
||||||
|
@ -119,7 +119,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//float f = this.getHeading();
|
//float f = this.getHeading();
|
||||||
return new PluginResult(status, getCompassHeading(), "navigator.compass._castDate");
|
return new PluginResult(status, getCompassHeading());
|
||||||
}
|
}
|
||||||
else if (action.equals("setTimeout")) {
|
else if (action.equals("setTimeout")) {
|
||||||
this.setTimeout(args.getLong(0));
|
this.setTimeout(args.getLong(0));
|
||||||
|
@ -85,7 +85,7 @@ public class ContactManager extends Plugin {
|
|||||||
try {
|
try {
|
||||||
if (action.equals("search")) {
|
if (action.equals("search")) {
|
||||||
JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1));
|
JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1));
|
||||||
return new PluginResult(status, res, "navigator.contacts.cast");
|
return new PluginResult(status, res);
|
||||||
}
|
}
|
||||||
else if (action.equals("save")) {
|
else if (action.equals("save")) {
|
||||||
String id = contactAccessor.save(args.getJSONObject(0));
|
String id = contactAccessor.save(args.getJSONObject(0));
|
||||||
|
@ -101,7 +101,7 @@ public class FileTransfer extends Plugin {
|
|||||||
} else if (action.equals("download")) {
|
} else if (action.equals("download")) {
|
||||||
JSONObject r = download(source, target);
|
JSONObject r = download(source, target);
|
||||||
Log.d(LOG_TAG, "****** About to return a result from download");
|
Log.d(LOG_TAG, "****** About to return a result from download");
|
||||||
return new PluginResult(PluginResult.Status.OK, r, "window.localFileSystem._castEntry");
|
return new PluginResult(PluginResult.Status.OK, r);
|
||||||
} else {
|
} else {
|
||||||
return new PluginResult(PluginResult.Status.INVALID_ACTION);
|
return new PluginResult(PluginResult.Status.INVALID_ACTION);
|
||||||
}
|
}
|
||||||
|
@ -137,31 +137,31 @@ public class FileUtils extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
JSONObject obj = requestFileSystem(args.getInt(0));
|
JSONObject obj = requestFileSystem(args.getInt(0));
|
||||||
return new PluginResult(status, obj, "window.localFileSystem._castFS");
|
return new PluginResult(status, obj);
|
||||||
}
|
}
|
||||||
else if (action.equals("resolveLocalFileSystemURI")) {
|
else if (action.equals("resolveLocalFileSystemURI")) {
|
||||||
JSONObject obj = resolveLocalFileSystemURI(args.getString(0));
|
JSONObject obj = resolveLocalFileSystemURI(args.getString(0));
|
||||||
return new PluginResult(status, obj, "window.localFileSystem._castEntry");
|
return new PluginResult(status, obj);
|
||||||
}
|
}
|
||||||
else if (action.equals("getMetadata")) {
|
else if (action.equals("getMetadata")) {
|
||||||
JSONObject obj = getMetadata(args.getString(0));
|
JSONObject obj = getMetadata(args.getString(0));
|
||||||
return new PluginResult(status, obj, "window.localFileSystem._castDate");
|
return new PluginResult(status, obj);
|
||||||
}
|
}
|
||||||
else if (action.equals("getFileMetadata")) {
|
else if (action.equals("getFileMetadata")) {
|
||||||
JSONObject obj = getFileMetadata(args.getString(0));
|
JSONObject obj = getFileMetadata(args.getString(0));
|
||||||
return new PluginResult(status, obj, "window.localFileSystem._castDate");
|
return new PluginResult(status, obj);
|
||||||
}
|
}
|
||||||
else if (action.equals("getParent")) {
|
else if (action.equals("getParent")) {
|
||||||
JSONObject obj = getParent(args.getString(0));
|
JSONObject obj = getParent(args.getString(0));
|
||||||
return new PluginResult(status, obj, "window.localFileSystem._castEntry");
|
return new PluginResult(status, obj);
|
||||||
}
|
}
|
||||||
else if (action.equals("getDirectory")) {
|
else if (action.equals("getDirectory")) {
|
||||||
JSONObject obj = getFile(args.getString(0), args.getString(1), args.optJSONObject(2), true);
|
JSONObject obj = getFile(args.getString(0), args.getString(1), args.optJSONObject(2), true);
|
||||||
return new PluginResult(status, obj, "window.localFileSystem._castEntry");
|
return new PluginResult(status, obj);
|
||||||
}
|
}
|
||||||
else if (action.equals("getFile")) {
|
else if (action.equals("getFile")) {
|
||||||
JSONObject obj = getFile(args.getString(0), args.getString(1), args.optJSONObject(2), false);
|
JSONObject obj = getFile(args.getString(0), args.getString(1), args.optJSONObject(2), false);
|
||||||
return new PluginResult(status, obj, "window.localFileSystem._castEntry");
|
return new PluginResult(status, obj);
|
||||||
}
|
}
|
||||||
else if (action.equals("remove")) {
|
else if (action.equals("remove")) {
|
||||||
boolean success;
|
boolean success;
|
||||||
@ -187,15 +187,15 @@ public class FileUtils extends Plugin {
|
|||||||
}
|
}
|
||||||
else if (action.equals("moveTo")) {
|
else if (action.equals("moveTo")) {
|
||||||
JSONObject entry = transferTo(args.getString(0), args.getJSONObject(1), args.optString(2), true);
|
JSONObject entry = transferTo(args.getString(0), args.getJSONObject(1), args.optString(2), true);
|
||||||
return new PluginResult(status, entry, "window.localFileSystem._castEntry");
|
return new PluginResult(status, entry);
|
||||||
}
|
}
|
||||||
else if (action.equals("copyTo")) {
|
else if (action.equals("copyTo")) {
|
||||||
JSONObject entry = transferTo(args.getString(0), args.getJSONObject(1), args.optString(2), false);
|
JSONObject entry = transferTo(args.getString(0), args.getJSONObject(1), args.optString(2), false);
|
||||||
return new PluginResult(status, entry, "window.localFileSystem._castEntry");
|
return new PluginResult(status, entry);
|
||||||
}
|
}
|
||||||
else if (action.equals("readEntries")) {
|
else if (action.equals("readEntries")) {
|
||||||
JSONArray entries = readEntries(args.getString(0));
|
JSONArray entries = readEntries(args.getString(0));
|
||||||
return new PluginResult(status, entries, "window.localFileSystem._castEntries");
|
return new PluginResult(status, entries);
|
||||||
}
|
}
|
||||||
return new PluginResult(status, result);
|
return new PluginResult(status, result);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
|
@ -27,7 +27,6 @@ public class PluginResult {
|
|||||||
private final int status;
|
private final int status;
|
||||||
private final String message;
|
private final String message;
|
||||||
private boolean keepCallback = false;
|
private boolean keepCallback = false;
|
||||||
private String cast = null;
|
|
||||||
|
|
||||||
public PluginResult(Status status) {
|
public PluginResult(Status status) {
|
||||||
this.status = status.ordinal();
|
this.status = status.ordinal();
|
||||||
@ -39,18 +38,6 @@ public class PluginResult {
|
|||||||
this.message = JSONObject.quote(message);
|
this.message = JSONObject.quote(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginResult(Status status, JSONArray message, String cast) {
|
|
||||||
this.status = status.ordinal();
|
|
||||||
this.message = message.toString();
|
|
||||||
this.cast = cast;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PluginResult(Status status, JSONObject message, String cast) {
|
|
||||||
this.status = status.ordinal();
|
|
||||||
this.message = message.toString();
|
|
||||||
this.cast = cast;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PluginResult(Status status, JSONArray message) {
|
public PluginResult(Status status, JSONArray message) {
|
||||||
this.status = status.ordinal();
|
this.status = status.ordinal();
|
||||||
this.message = message.toString();
|
this.message = message.toString();
|
||||||
@ -97,15 +84,7 @@ public class PluginResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toSuccessCallbackString(String callbackId) {
|
public String toSuccessCallbackString(String callbackId) {
|
||||||
StringBuffer buf = new StringBuffer("");
|
return "Cordova.callbackSuccess('"+callbackId+"',"+this.getJSONString()+");";
|
||||||
if (cast != null) {
|
|
||||||
buf.append("var temp = "+cast+"("+this.getJSONString() + ");\n");
|
|
||||||
buf.append("Cordova.callbackSuccess('"+callbackId+"',temp);");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
buf.append("Cordova.callbackSuccess('"+callbackId+"',"+this.getJSONString()+");");
|
|
||||||
}
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toErrorCallbackString(String callbackId) {
|
public String toErrorCallbackString(String callbackId) {
|
||||||
|
Loading…
Reference in New Issue
Block a user