mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-04 00:13:20 +08:00
Merge branch 'master' of git://github.com/phonegap/phonegap-android into contactSpec
This commit is contained in:
commit
4e4207f294
30
framework/assets/js/device.js
Normal file → Executable file
30
framework/assets/js/device.js
Normal file → Executable file
@ -12,22 +12,46 @@ function Device() {
|
|||||||
this.phonegap = null;
|
this.phonegap = null;
|
||||||
|
|
||||||
var me = this;
|
var me = this;
|
||||||
PhoneGap.execAsync(
|
this.getInfo(
|
||||||
function(info) {
|
function(info) {
|
||||||
me.available = true;
|
me.available = true;
|
||||||
me.platform = info.platform;
|
me.platform = info.platform;
|
||||||
me.version = info.version;
|
me.version = info.version;
|
||||||
me.uuid = info.uuid;
|
me.uuid = info.uuid;
|
||||||
me.phonegap = info.phonegap;
|
me.phonegap = info.phonegap;
|
||||||
|
PhoneGap.onPhoneGapInfoReady.fire();
|
||||||
},
|
},
|
||||||
function(e) {
|
function(e) {
|
||||||
me.available = false;
|
me.available = false;
|
||||||
console.log("Error initializing PhoneGap: " + e);
|
console.log("Error initializing PhoneGap: " + e);
|
||||||
alert("Error initializing PhoneGap: "+e);
|
alert("Error initializing PhoneGap: "+e);
|
||||||
},
|
});
|
||||||
"Device", "getDeviceInfo", []);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get device info
|
||||||
|
*
|
||||||
|
* @param {Function} successCallback The function to call when the heading data is available
|
||||||
|
* @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)
|
||||||
|
*/
|
||||||
|
Device.prototype.getInfo = function(successCallback, errorCallback) {
|
||||||
|
|
||||||
|
// successCallback required
|
||||||
|
if (typeof successCallback != "function") {
|
||||||
|
console.log("Device Error: successCallback is not a function");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// errorCallback optional
|
||||||
|
if (errorCallback && (typeof errorCallback != "function")) {
|
||||||
|
console.log("Device Error: errorCallback is not a function");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get info
|
||||||
|
PhoneGap.execAsync(successCallback, errorCallback, "Device", "getDeviceInfo", []);
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is only for Android.
|
* This is only for Android.
|
||||||
*
|
*
|
||||||
|
606
framework/assets/js/file.js
Normal file → Executable file
606
framework/assets/js/file.js
Normal file → Executable file
@ -1,226 +1,416 @@
|
|||||||
|
/**
|
||||||
|
* This class provides generic read and write access to the mobile device file system.
|
||||||
|
* They are not used to read files from a server.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of files
|
||||||
|
*/
|
||||||
|
function FileList() {
|
||||||
|
this.files = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes a single file in a FileList
|
||||||
|
*/
|
||||||
|
function File() {
|
||||||
|
this.name = null;
|
||||||
|
this.type = null;
|
||||||
|
this.urn = null;
|
||||||
|
};
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() { if (typeof navigator.fileMgr == "undefined") navigator.fileMgr = new FileMgr();});
|
/**
|
||||||
|
* Create an event object since we can't set target on DOM event.
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param target
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
File._createEvent = function(type, target) {
|
||||||
|
// Can't create event object, since we can't set target (its readonly)
|
||||||
|
//var evt = document.createEvent('Events');
|
||||||
|
//evt.initEvent("onload", false, false);
|
||||||
|
var evt = {"type": type};
|
||||||
|
evt.target = target;
|
||||||
|
return evt;
|
||||||
|
};
|
||||||
|
|
||||||
|
function FileError() {
|
||||||
|
// File error codes
|
||||||
|
// Found in DOMException
|
||||||
|
this.NOT_FOUND_ERR = 8;
|
||||||
|
this.SECURITY_ERR = 18;
|
||||||
|
this.ABORT_ERR = 20;
|
||||||
|
|
||||||
|
// Added by this specification
|
||||||
|
this.NOT_READABLE_ERR = 24;
|
||||||
|
this.ENCODING_ERR = 26;
|
||||||
|
|
||||||
|
this.code = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// File manager
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function FileMgr() {
|
||||||
|
};
|
||||||
|
|
||||||
|
FileMgr.prototype.getFileBasePaths = function() {
|
||||||
|
};
|
||||||
|
|
||||||
|
FileMgr.prototype.testSaveLocationExists = function(successCallback, errorCallback) {
|
||||||
|
PhoneGap.execAsync(successCallback, errorCallback, "File", "testSaveLocationExists", []);
|
||||||
|
};
|
||||||
|
|
||||||
|
FileMgr.prototype.testFileExists = function(fileName, successCallback, errorCallback) {
|
||||||
|
PhoneGap.execAsync(successCallback, errorCallback, "File", "testFileExists", [fileName]);
|
||||||
|
};
|
||||||
|
|
||||||
|
FileMgr.prototype.testDirectoryExists = function(dirName, successCallback, errorCallback) {
|
||||||
|
PhoneGap.execAsync(successCallback, errorCallback, "File", "testDirectoryExists", [dirName]);
|
||||||
|
};
|
||||||
|
|
||||||
|
FileMgr.prototype.createDirectory = function(dirName, successCallback, errorCallback) {
|
||||||
|
PhoneGap.execAsync(successCallback, errorCallback, "File", "createDirectory", [dirName]);
|
||||||
|
};
|
||||||
|
|
||||||
|
FileMgr.prototype.deleteDirectory = function(dirName, successCallback, errorCallback) {
|
||||||
|
PhoneGap.execAsync(successCallback, errorCallback, "File", "deleteDirectory", [dirName]);
|
||||||
|
};
|
||||||
|
|
||||||
|
FileMgr.prototype.deleteFile = function(fileName, successCallback, errorCallback) {
|
||||||
|
PhoneGap.execAsync(successCallback, errorCallback, "File", "deleteFile", [fileName]);
|
||||||
|
};
|
||||||
|
|
||||||
|
FileMgr.prototype.getFreeDiskSpace = function(successCallback, errorCallback) {
|
||||||
|
PhoneGap.execAsync(successCallback, errorCallback, "File", "getFreeDiskSpace", []);
|
||||||
|
};
|
||||||
|
|
||||||
|
FileMgr.prototype.writeAsText = function(fileName, data, append, successCallback, errorCallback) {
|
||||||
|
PhoneGap.execAsync(successCallback, errorCallback, "File", "writeAsText", [fileName, data, append]);
|
||||||
|
};
|
||||||
|
|
||||||
|
FileMgr.prototype.readAsText = function(fileName, encoding, successCallback, errorCallback) {
|
||||||
|
PhoneGap.execAsync(successCallback, errorCallback, "File", "readAsText", [fileName, encoding]);
|
||||||
|
};
|
||||||
|
|
||||||
|
FileMgr.prototype.readAsDataURL = function(fileName, successCallback, errorCallback) {
|
||||||
|
PhoneGap.execAsync(successCallback, errorCallback, "File", "readAsDataURL", [fileName]);
|
||||||
|
};
|
||||||
|
|
||||||
|
PhoneGap.addConstructor(function() {
|
||||||
|
if (typeof navigator.fileMgr == "undefined") navigator.fileMgr = new FileMgr();
|
||||||
|
});
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// File Reader
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// TODO: All other FileMgr function operate on the SD card as root. However,
|
||||||
|
// for FileReader & FileWriter the root is not SD card. Should this be changed?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class reads the mobile device file system.
|
||||||
|
*
|
||||||
|
* For Android:
|
||||||
|
* The root directory is the root of the file system.
|
||||||
|
* To read from the SD card, the file name is "sdcard/my_file.txt"
|
||||||
|
*/
|
||||||
|
function FileReader() {
|
||||||
|
this.fileName = "";
|
||||||
|
|
||||||
|
this.readyState = 0;
|
||||||
|
|
||||||
|
// File data
|
||||||
|
this.result = null;
|
||||||
|
|
||||||
|
// Error
|
||||||
|
this.error = null;
|
||||||
|
|
||||||
|
// Event handlers
|
||||||
|
this.onloadstart = null; // When the read starts.
|
||||||
|
this.onprogress = null; // While reading (and decoding) file or fileBlob data, and reporting partial file data (progess.loaded/progress.total)
|
||||||
|
this.onload = null; // When the read has successfully completed.
|
||||||
|
this.onerror = null; // When the read has failed (see errors).
|
||||||
|
this.onloadend = null; // When the request has completed (either in success or failure).
|
||||||
|
this.onabort = null; // When the read has been aborted. For instance, by invoking the abort() method.
|
||||||
|
};
|
||||||
|
|
||||||
|
// States
|
||||||
|
FileReader.EMPTY = 0;
|
||||||
|
FileReader.LOADING = 1;
|
||||||
|
FileReader.DONE = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abort reading file.
|
||||||
|
*/
|
||||||
|
FileReader.prototype.abort = function() {
|
||||||
|
this.readyState = FileReader.DONE;
|
||||||
|
|
||||||
|
// If abort callback
|
||||||
|
if (typeof this.onabort == "function") {
|
||||||
|
var evt = File._createEvent("abort", this);
|
||||||
|
this.onabort(evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Anything else to do? Maybe sent to native?
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read text file.
|
||||||
|
*
|
||||||
|
* @param file The name of the file
|
||||||
|
* @param encoding [Optional] (see http://www.iana.org/assignments/character-sets)
|
||||||
|
*/
|
||||||
|
FileReader.prototype.readAsText = function(file, encoding) {
|
||||||
|
this.fileName = file;
|
||||||
|
|
||||||
|
// LOADING state
|
||||||
|
this.readyState = FileReader.LOADING;
|
||||||
|
|
||||||
|
// If loadstart callback
|
||||||
|
if (typeof this.onloadstart == "function") {
|
||||||
|
var evt = File._createEvent("loadstart", this);
|
||||||
|
this.onloadstart(evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default encoding is UTF-8
|
||||||
|
var enc = encoding ? encoding : "UTF-8";
|
||||||
|
|
||||||
|
var me = this;
|
||||||
|
|
||||||
|
// Read file
|
||||||
|
navigator.fileMgr.readAsText(file, enc,
|
||||||
|
|
||||||
|
// Success callback
|
||||||
|
function(r) {
|
||||||
|
|
||||||
|
// If DONE (cancelled), then don't do anything
|
||||||
|
if (me.readyState == FileReader.DONE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save result
|
||||||
|
me.result = r;
|
||||||
|
|
||||||
|
// DONE state
|
||||||
|
me.readyState = FileReader.DONE;
|
||||||
|
|
||||||
|
// If onload callback
|
||||||
|
if (typeof me.onload == "function") {
|
||||||
|
var evt = File._createEvent("load", me);
|
||||||
|
me.onload(evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If onloadend callback
|
||||||
|
if (typeof me.onloadend == "function") {
|
||||||
|
var evt = File._createEvent("loadend", me);
|
||||||
|
me.onloadend(evt);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Error callback
|
||||||
|
function(e) {
|
||||||
|
|
||||||
|
// If DONE (cancelled), then don't do anything
|
||||||
|
if (me.readyState == FileReader.DONE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save error
|
||||||
|
me.error = e;
|
||||||
|
|
||||||
|
// DONE state
|
||||||
|
me.readyState = FileReader.DONE;
|
||||||
|
|
||||||
|
// If onerror callback
|
||||||
|
if (typeof me.onerror == "function") {
|
||||||
|
var evt = File._createEvent("error", me);
|
||||||
|
me.onerror(evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If onloadend callback
|
||||||
|
if (typeof me.onloadend == "function") {
|
||||||
|
var evt = File._createEvent("loadend", me);
|
||||||
|
me.onloadend(evt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides iPhone read and write access to the mobile device file system.
|
* Read file and return data as a base64 encoded data url.
|
||||||
* Based loosely on http://www.w3.org/TR/2009/WD-FileAPI-20091117/#dfn-empty
|
* A data url is of the form:
|
||||||
*/
|
* data:[<mediatype>][;base64],<data>
|
||||||
function FileMgr()
|
|
||||||
{
|
|
||||||
this.fileWriters = {}; // empty maps
|
|
||||||
this.fileReaders = {};
|
|
||||||
|
|
||||||
this.docsFolderPath = "../../Documents";
|
|
||||||
this.tempFolderPath = "../../tmp";
|
|
||||||
this.freeDiskSpace = -1;
|
|
||||||
this.getFileBasePaths();
|
|
||||||
}
|
|
||||||
|
|
||||||
// private, called from Native Code
|
|
||||||
FileMgr.prototype._setPaths = function(docs,temp)
|
|
||||||
{
|
|
||||||
this.docsFolderPath = docs;
|
|
||||||
this.tempFolderPath = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// private, called from Native Code
|
|
||||||
FileMgr.prototype._setFreeDiskSpace = function(val)
|
|
||||||
{
|
|
||||||
this.freeDiskSpace = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// FileWriters add/remove
|
|
||||||
// called internally by writers
|
|
||||||
FileMgr.prototype.addFileWriter = function(filePath,fileWriter)
|
|
||||||
{
|
|
||||||
this.fileWriters[filePath] = fileWriter;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileMgr.prototype.removeFileWriter = function(filePath)
|
|
||||||
{
|
|
||||||
this.fileWriters[filePath] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// File readers add/remove
|
|
||||||
// called internally by readers
|
|
||||||
FileMgr.prototype.addFileReader = function(filePath,fileReader)
|
|
||||||
{
|
|
||||||
this.fileReaders[filePath] = fileReader;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileMgr.prototype.removeFileReader = function(filePath)
|
|
||||||
{
|
|
||||||
this.fileReaders[filePath] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************
|
|
||||||
*
|
*
|
||||||
* private reader callback delegation
|
* @param file The name of the file
|
||||||
* called from native code
|
|
||||||
*/
|
*/
|
||||||
FileMgr.prototype.reader_onloadstart = function(filePath,result)
|
FileReader.prototype.readAsDataURL = function(file) {
|
||||||
{
|
this.fileName = file;
|
||||||
this.fileReaders[filePath].onloadstart(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
FileMgr.prototype.reader_onprogress = function(filePath,result)
|
// LOADING state
|
||||||
{
|
this.readyState = FileReader.LOADING;
|
||||||
this.fileReaders[filePath].onprogress(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
FileMgr.prototype.reader_onload = function(filePath,result)
|
// If loadstart callback
|
||||||
{
|
if (typeof this.onloadstart == "function") {
|
||||||
this.fileReaders[filePath].result = unescape(result);
|
var evt = File._createEvent("loadstart", this);
|
||||||
this.fileReaders[filePath].onload(this.fileReaders[filePath].result);
|
this.onloadstart(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileMgr.prototype.reader_onerror = function(filePath,err)
|
var me = this;
|
||||||
{
|
|
||||||
this.fileReaders[filePath].result = err;
|
|
||||||
this.fileReaders[filePath].onerror(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
FileMgr.prototype.reader_onloadend = function(filePath,result)
|
// Read file
|
||||||
{
|
navigator.fileMgr.readAsDataURL(file,
|
||||||
this.fileReaders[filePath].onloadend(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************
|
// Success callback
|
||||||
|
function(r) {
|
||||||
|
|
||||||
|
// If DONE (cancelled), then don't do anything
|
||||||
|
if (me.readyState == FileReader.DONE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save result
|
||||||
|
me.result = r;
|
||||||
|
|
||||||
|
// DONE state
|
||||||
|
me.readyState = FileReader.DONE;
|
||||||
|
|
||||||
|
// If onload callback
|
||||||
|
if (typeof me.onload == "function") {
|
||||||
|
var evt = File._createEvent("load", me);
|
||||||
|
me.onload(evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If onloadend callback
|
||||||
|
if (typeof me.onloadend == "function") {
|
||||||
|
var evt = File._createEvent("loadend", me);
|
||||||
|
me.onloadend(evt);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Error callback
|
||||||
|
function(e) {
|
||||||
|
|
||||||
|
// If DONE (cancelled), then don't do anything
|
||||||
|
if (me.readyState == FileReader.DONE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save error
|
||||||
|
me.error = e;
|
||||||
|
|
||||||
|
// DONE state
|
||||||
|
me.readyState = FileReader.DONE;
|
||||||
|
|
||||||
|
// If onerror callback
|
||||||
|
if (typeof me.onerror == "function") {
|
||||||
|
var evt = File._createEvent("error", me);
|
||||||
|
me.onerror(evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If onloadend callback
|
||||||
|
if (typeof me.onloadend == "function") {
|
||||||
|
var evt = File._createEvent("loadend", me);
|
||||||
|
me.onloadend(evt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read file and return data as a binary data.
|
||||||
*
|
*
|
||||||
* private writer callback delegation
|
* @param file The name of the file
|
||||||
* called from native code
|
*/
|
||||||
*/
|
FileReader.prototype.readAsBinaryString = function(file) {
|
||||||
FileMgr.prototype.writer_onerror = function(filePath,err)
|
// TODO - Can't return binary data to browser.
|
||||||
{
|
this.fileName = file;
|
||||||
this.fileWriters[filePath].onerror(err);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
FileMgr.prototype.writer_oncomplete = function(filePath,result)
|
|
||||||
{
|
|
||||||
this.fileWriters[filePath].oncomplete(result); // result contains bytes written
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
FileMgr.prototype.getFileBasePaths = function()
|
|
||||||
{
|
|
||||||
//PhoneGap.exec("File.getFileBasePaths");
|
|
||||||
}
|
|
||||||
|
|
||||||
FileMgr.prototype.testFileExists = function(fileName, successCallback, errorCallback)
|
|
||||||
{
|
|
||||||
var test = FileUtil.testFileExists(fileName);
|
|
||||||
test ? successCallback() : errorCallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
FileMgr.prototype.testDirectoryExists = function(dirName, successCallback, errorCallback)
|
|
||||||
{
|
|
||||||
this.successCallback = successCallback;
|
|
||||||
this.errorCallback = errorCallback;
|
|
||||||
var test = FileUtil.testDirectoryExists(dirName);
|
|
||||||
test ? successCallback() : errorCallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
FileMgr.prototype.createDirectory = function(dirName, successCallback, errorCallback)
|
|
||||||
{
|
|
||||||
this.successCallback = successCallback;
|
|
||||||
this.errorCallback = errorCallback;
|
|
||||||
var test = FileUtil.createDirectory(dirName);
|
|
||||||
test ? successCallback() : errorCallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
FileMgr.prototype.deleteDirectory = function(dirName, successCallback, errorCallback)
|
|
||||||
{
|
|
||||||
this.successCallback = successCallback;
|
|
||||||
this.errorCallback = errorCallback;
|
|
||||||
var test = FileUtil.deleteDirectory(dirName);
|
|
||||||
test ? successCallback() : errorCallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
FileMgr.prototype.deleteFile = function(fileName, successCallback, errorCallback)
|
|
||||||
{
|
|
||||||
this.successCallback = successCallback;
|
|
||||||
this.errorCallback = errorCallback;
|
|
||||||
FileUtil.deleteFile(fileName);
|
|
||||||
test ? successCallback() : errorCallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
FileMgr.prototype.getFreeDiskSpace = function(successCallback, errorCallback)
|
|
||||||
{
|
|
||||||
if(this.freeDiskSpace > 0)
|
|
||||||
{
|
|
||||||
return this.freeDiskSpace;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.successCallback = successCallback;
|
|
||||||
this.errorCallback = errorCallback;
|
|
||||||
this.freeDiskSpace = FileUtil.getFreeDiskSpace();
|
|
||||||
(this.freeDiskSpace > 0) ? successCallback() : errorCallback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// File Reader
|
|
||||||
|
|
||||||
|
|
||||||
function FileReader()
|
|
||||||
{
|
|
||||||
this.fileName = "";
|
|
||||||
this.result = null;
|
|
||||||
this.onloadstart = null;
|
|
||||||
this.onprogress = null;
|
|
||||||
this.onload = null;
|
|
||||||
this.onerror = null;
|
|
||||||
this.onloadend = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
FileReader.prototype.abort = function()
|
|
||||||
{
|
|
||||||
// Not Implemented
|
|
||||||
}
|
|
||||||
|
|
||||||
FileReader.prototype.readAsText = function(file)
|
|
||||||
{
|
|
||||||
if(this.fileName && this.fileName.length > 0)
|
|
||||||
{
|
|
||||||
navigator.fileMgr.removeFileReader(this.fileName,this);
|
|
||||||
}
|
|
||||||
this.fileName = file;
|
|
||||||
navigator.fileMgr.addFileReader(this.fileName,this);
|
|
||||||
|
|
||||||
return FileUtil.read(this.fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
// File Writer
|
// File Writer
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
function FileWriter()
|
/**
|
||||||
{
|
* This class writes to the mobile device file system.
|
||||||
this.fileName = "";
|
*
|
||||||
this.result = null;
|
* For Android:
|
||||||
this.readyState = 0; // EMPTY
|
* The root directory is the root of the file system.
|
||||||
this.result = null;
|
* To write to the SD card, the file name is "sdcard/my_file.txt"
|
||||||
this.onerror = null;
|
*/
|
||||||
this.oncomplete = null;
|
function FileWriter() {
|
||||||
}
|
this.fileName = "";
|
||||||
|
this.result = null;
|
||||||
|
this.readyState = 0; // EMPTY
|
||||||
|
this.result = null;
|
||||||
|
this.onerror = null;
|
||||||
|
this.oncomplete = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// States
|
||||||
|
FileWriter.EMPTY = 0;
|
||||||
|
FileWriter.LOADING = 1;
|
||||||
|
FileWriter.DONE = 2;
|
||||||
|
|
||||||
|
FileWriter.prototype.writeAsText = function(file, text, bAppend) {
|
||||||
|
if (bAppend != true) {
|
||||||
|
bAppend = false; // for null values
|
||||||
|
}
|
||||||
|
|
||||||
|
this.fileName = file;
|
||||||
|
|
||||||
|
// LOADING state
|
||||||
|
this.readyState = FileWriter.LOADING;
|
||||||
|
|
||||||
|
var me = this;
|
||||||
|
|
||||||
|
// Read file
|
||||||
|
navigator.fileMgr.writeAsText(file, text, bAppend,
|
||||||
|
|
||||||
|
// Success callback
|
||||||
|
function(r) {
|
||||||
|
|
||||||
|
// If DONE (cancelled), then don't do anything
|
||||||
|
if (me.readyState == FileWriter.DONE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save result
|
||||||
|
me.result = r;
|
||||||
|
|
||||||
|
// DONE state
|
||||||
|
me.readyState = FileWriter.DONE;
|
||||||
|
|
||||||
|
// If oncomplete callback
|
||||||
|
if (typeof me.oncomplete == "function") {
|
||||||
|
var evt = File._createEvent("complete", me);
|
||||||
|
me.oncomplete(evt);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Error callback
|
||||||
|
function(e) {
|
||||||
|
|
||||||
|
// If DONE (cancelled), then don't do anything
|
||||||
|
if (me.readyState == FileWriter.DONE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save error
|
||||||
|
me.error = e;
|
||||||
|
|
||||||
|
// DONE state
|
||||||
|
me.readyState = FileWriter.DONE;
|
||||||
|
|
||||||
|
// If onerror callback
|
||||||
|
if (typeof me.onerror == "function") {
|
||||||
|
var evt = File._createEvent("error", me);
|
||||||
|
me.onerror(evt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
FileWriter.prototype.writeAsText = function(file,text,bAppend)
|
|
||||||
{
|
|
||||||
if(this.fileName && this.fileName.length > 0)
|
|
||||||
{
|
|
||||||
navigator.fileMgr.removeFileWriter(this.fileName,this);
|
|
||||||
}
|
|
||||||
this.fileName = file;
|
|
||||||
if(bAppend != true)
|
|
||||||
{
|
|
||||||
bAppend = false; // for null values
|
|
||||||
}
|
|
||||||
navigator.fileMgr.addFileWriter(file,this);
|
|
||||||
this.readyState = 0; // EMPTY
|
|
||||||
var call = FileUtil.write(file, text, bAppend);
|
|
||||||
this.result = null;
|
|
||||||
}
|
|
||||||
|
243
framework/assets/js/geolocation.js
Normal file → Executable file
243
framework/assets/js/geolocation.js
Normal file → Executable file
@ -3,85 +3,184 @@
|
|||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function Geolocation() {
|
function Geolocation() {
|
||||||
/**
|
|
||||||
* The last known GPS position.
|
// The last known GPS position.
|
||||||
*/
|
|
||||||
this.lastPosition = null;
|
this.lastPosition = null;
|
||||||
this.lastError = null;
|
|
||||||
this.listeners = null;
|
// Geolocation listeners
|
||||||
|
this.listeners = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
var geoListeners = [];
|
/**
|
||||||
|
* Position error object
|
||||||
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options)
|
|
||||||
{
|
|
||||||
var position = Geo.getCurrentLocation();
|
|
||||||
this.global_success = successCallback;
|
|
||||||
this.fail = errorCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run the global callback
|
|
||||||
Geolocation.prototype.gotCurrentPosition = function(lat, lng, alt, altacc, head, vel, stamp)
|
|
||||||
{
|
|
||||||
if (lat == "undefined" || lng == "undefined")
|
|
||||||
{
|
|
||||||
this.fail();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
coords = new Coordinates(lat, lng, alt, acc, head, vel);
|
|
||||||
loc = new Position(coords, stamp);
|
|
||||||
this.lastPosition = loc;
|
|
||||||
this.global_success(loc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This turns on the GeoLocator class, which has two listeners.
|
|
||||||
* The listeners have their own timeouts, and run independently of this process
|
|
||||||
* In this case, we return the key to the watch hash
|
|
||||||
*/
|
|
||||||
|
|
||||||
Geolocation.prototype.watchPosition = function(successCallback, errorCallback, options)
|
|
||||||
{
|
|
||||||
var frequency = (options != undefined)? options.frequency : 10000;
|
|
||||||
|
|
||||||
var key = geoListeners.push( {"success" : successCallback, "fail" : errorCallback }) - 1;
|
|
||||||
|
|
||||||
// TO-DO: Get the names of the method and pass them as strings to the Java.
|
|
||||||
return Geo.start(frequency, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Retrieve and stop this listener from listening to the GPS
|
|
||||||
*
|
*
|
||||||
|
* @param code
|
||||||
|
* @param message
|
||||||
*/
|
*/
|
||||||
Geolocation.prototype.success = function(key, lat, lng, alt, altacc, head, vel, stamp)
|
function PositionError(code, message) {
|
||||||
{
|
this.code = code;
|
||||||
var coords = new Coordinates(lat, lng, alt, acc, head, vel);
|
this.message = message;
|
||||||
var loc = new Position(coords, stamp);
|
};
|
||||||
geoListeners[key].success(loc);
|
|
||||||
|
PositionError.PERMISSION_DENIED = 1;
|
||||||
|
PositionError.POSITION_UNAVAILABLE = 2;
|
||||||
|
PositionError.TIMEOUT = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously aquires the current position.
|
||||||
|
*
|
||||||
|
* @param {Function} successCallback The function to call when the position data is available
|
||||||
|
* @param {Function} errorCallback The function to call when there is an error getting the heading position. (OPTIONAL)
|
||||||
|
* @param {PositionOptions} options The options for getting the position data. (OPTIONAL)
|
||||||
|
*/
|
||||||
|
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
|
||||||
|
if (navigator._geo.listeners["global"]) {
|
||||||
|
console.log("Geolocation Error: Still waiting for previous getCurrentPosition() request.");
|
||||||
|
try {
|
||||||
|
errorCallback(new PositionError(PositionError.TIMEOUT, "Geolocation Error: Still waiting for previous getCurrentPosition() request."));
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var maximumAge = 10000;
|
||||||
|
var enableHighAccuracy = false;
|
||||||
|
var timeout = 10000;
|
||||||
|
if (typeof options != "undefined") {
|
||||||
|
if (typeof options.maximumAge != "undefined") {
|
||||||
|
maximumAge = options.maximumAge;
|
||||||
|
}
|
||||||
|
if (typeof options.enableHighAccuracy != "undefined") {
|
||||||
|
enableHighAccuracy = options.enableHighAccuracy;
|
||||||
|
}
|
||||||
|
if (typeof options.timeout != "undefined") {
|
||||||
|
timeout = options.timeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
navigator._geo.listeners["global"] = {"success" : successCallback, "fail" : errorCallback };
|
||||||
|
PhoneGap.execAsync(null, null, "Geolocation", "getCurrentLocation", [enableHighAccuracy, timeout, maximumAge]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Geolocation.prototype.fail = function(key)
|
/**
|
||||||
{
|
* Asynchronously watches the geolocation for changes to geolocation. When a change occurs,
|
||||||
geoListeners[key].fail();
|
* the successCallback is called with the new location.
|
||||||
}
|
*
|
||||||
|
* @param {Function} successCallback The function to call each time the location data is available
|
||||||
Geolocation.prototype.clearWatch = function(watchId)
|
* @param {Function} errorCallback The function to call when there is an error getting the location data. (OPTIONAL)
|
||||||
{
|
* @param {PositionOptions} options The options for getting the location data such as frequency. (OPTIONAL)
|
||||||
Geo.stop(watchId);
|
* @return String The watch id that must be passed to #clearWatch to stop watching.
|
||||||
}
|
*/
|
||||||
|
Geolocation.prototype.watchPosition = function(successCallback, errorCallback, options) {
|
||||||
|
var maximumAge = 10000;
|
||||||
|
var enableHighAccuracy = false;
|
||||||
|
var timeout = 10000;
|
||||||
|
if (typeof options != "undefined") {
|
||||||
|
if (typeof options.frequency != "undefined") {
|
||||||
|
maximumAge = options.frequency;
|
||||||
|
}
|
||||||
|
if (typeof options.maximumAge != "undefined") {
|
||||||
|
maximumAge = options.maximumAge;
|
||||||
|
}
|
||||||
|
if (typeof options.enableHighAccuracy != "undefined") {
|
||||||
|
enableHighAccuracy = options.enableHighAccuracy;
|
||||||
|
}
|
||||||
|
if (typeof options.timeout != "undefined") {
|
||||||
|
timeout = options.timeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var id = PhoneGap.createUUID();
|
||||||
|
navigator._geo.listeners[id] = {"success" : successCallback, "fail" : errorCallback };
|
||||||
|
PhoneGap.execAsync(null, null, "Geolocation", "start", [id, enableHighAccuracy, timeout, maximumAge]);
|
||||||
|
return id;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Native callback when watch position has a new position.
|
||||||
|
* PRIVATE METHOD
|
||||||
|
*
|
||||||
|
* @param {String} id
|
||||||
|
* @param {Number} lat
|
||||||
|
* @param {Number} lng
|
||||||
|
* @param {Number} alt
|
||||||
|
* @param {Number} altacc
|
||||||
|
* @param {Number} head
|
||||||
|
* @param {Number} vel
|
||||||
|
* @param {Number} stamp
|
||||||
|
*/
|
||||||
|
Geolocation.prototype.success = function(id, lat, lng, alt, altacc, head, vel, stamp) {
|
||||||
|
var coords = new Coordinates(lat, lng, alt, altacc, head, vel);
|
||||||
|
var loc = new Position(coords, stamp);
|
||||||
|
try {
|
||||||
|
if (lat == "undefined" || lng == "undefined") {
|
||||||
|
navigator._geo.listeners[id].fail(new PositionError(PositionError.POSITION_UNAVAILABLE, "Lat/Lng are undefined."));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
navigator._geo.lastPosition = loc;
|
||||||
|
navigator._geo.listeners[id].success(loc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.log("Geolocation Error: Error calling success callback function.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id == "global") {
|
||||||
|
delete navigator._geo.listeners["global"];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native callback when watch position has an error.
|
||||||
|
* PRIVATE METHOD
|
||||||
|
*
|
||||||
|
* @param {String} id The ID of the watch
|
||||||
|
* @param {Number} code The error code
|
||||||
|
* @param {String} msg The error message
|
||||||
|
*/
|
||||||
|
Geolocation.prototype.fail = function(id, code, msg) {
|
||||||
|
try {
|
||||||
|
navigator._geo.listeners[id].fail(new PositionError(code, msg));
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.log("Geolocation Error: Error calling error callback function.");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the specified heading watch.
|
||||||
|
*
|
||||||
|
* @param {String} id The ID of the watch returned from #watchPosition
|
||||||
|
*/
|
||||||
|
Geolocation.prototype.clearWatch = function(id) {
|
||||||
|
PhoneGap.execAsync(null, null, "Geolocation", "stop", [id]);
|
||||||
|
delete navigator._geo.listeners[id];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force the PhoneGap geolocation to be used instead of built-in.
|
||||||
|
*/
|
||||||
|
Geolocation.usingPhoneGap = false;
|
||||||
|
Geolocation.usePhoneGap = function() {
|
||||||
|
if (Geolocation.usingPhoneGap) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Geolocation.usingPhoneGap = true;
|
||||||
|
|
||||||
|
// Set built-in geolocation methods to our own implementations
|
||||||
|
// (Cannot replace entire geolocation, but can replace individual methods)
|
||||||
|
navigator.geolocation.setLocation = navigator._geo.setLocation;
|
||||||
|
navigator.geolocation.getCurrentPosition = navigator._geo.getCurrentPosition;
|
||||||
|
navigator.geolocation.watchPosition = navigator._geo.watchPosition;
|
||||||
|
navigator.geolocation.clearWatch = navigator._geo.clearWatch;
|
||||||
|
navigator.geolocation.start = navigator._geo.start;
|
||||||
|
navigator.geolocation.stop = navigator._geo.stop;
|
||||||
|
};
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
// Taken from Jesse's geo fix (similar problem) in PhoneGap iPhone. Go figure, same browser!
|
navigator._geo = new Geolocation();
|
||||||
function __proxyObj(origObj, proxyObj, funkList) {
|
|
||||||
for (var v in funkList) {
|
// No native geolocation object for Android 1.x, so use PhoneGap geolocation
|
||||||
origObj[funkList[v]] = proxyObj[funkList[v]];
|
if (typeof navigator.geolocation == 'undefined') {
|
||||||
}
|
navigator.geolocation = navigator._geo;
|
||||||
}
|
Geolocation.usingPhoneGap = true;
|
||||||
// In the case of Android, we can use the Native Geolocation Object if it exists, so only load this on 1.x devices
|
}
|
||||||
if (typeof navigator.geolocation == 'undefined') {
|
|
||||||
navigator.geolocation = new Geolocation();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function NetworkStatus() {
|
function NetworkStatus() {
|
||||||
this.code = null;
|
//this.code = null;
|
||||||
this.message = "";
|
//this.message = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
NetworkStatus.NOT_REACHABLE = 0;
|
NetworkStatus.NOT_REACHABLE = 0;
|
||||||
@ -42,38 +42,11 @@ Network.prototype.updateReachability = function(reachability) {
|
|||||||
* @param {Object} options (isIpAddress:boolean)
|
* @param {Object} options (isIpAddress:boolean)
|
||||||
*/
|
*/
|
||||||
Network.prototype.isReachable = function(uri, callback, options) {
|
Network.prototype.isReachable = function(uri, callback, options) {
|
||||||
|
var isIpAddress = false;
|
||||||
// callback required
|
if (options && options.isIpAddress) {
|
||||||
if (typeof callback != "function") {
|
isIpAddress = options.isIpAddress;
|
||||||
console.log("Network Error: callback is not a function");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
PhoneGap.execAsync(callback, null, "Network Status", "isReachable", [uri, isIpAddress]);
|
||||||
PhoneGap.execAsync(
|
|
||||||
function(status) {
|
|
||||||
|
|
||||||
// If reachable, the check for wifi vs carrier
|
|
||||||
if (status) {
|
|
||||||
PhoneGap.execAsync(
|
|
||||||
function(wifi) {
|
|
||||||
var s = new NetworkStatus();
|
|
||||||
if (wifi) {
|
|
||||||
s.code = NetworkStatus.REACHABLE_VIA_WIFI_NETWORK;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
s.code = NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK;
|
|
||||||
}
|
|
||||||
callback(s);
|
|
||||||
}, null, "Network Status", "isWifiActive", []);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If not
|
|
||||||
else {
|
|
||||||
var s = new NetworkStatus();
|
|
||||||
s.code = NetworkStatus.NOT_REACHABLE;
|
|
||||||
callback(s);
|
|
||||||
}
|
|
||||||
}, null, "Network Status", "isReachable", [uri]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
|
@ -1,4 +1,25 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* The order of events during page load and PhoneGap startup is as follows:
|
||||||
|
*
|
||||||
|
* onDOMContentLoaded Internal event that is received when the web page is loaded and parsed.
|
||||||
|
* window.onload Body onload event.
|
||||||
|
* onNativeReady Internal event that indicates the PhoneGap native side is ready.
|
||||||
|
* onPhoneGapInit Internal event that kicks off creation of all PhoneGap JavaScript objects (runs constructors).
|
||||||
|
* onPhoneGapReady Internal event fired when all PhoneGap JavaScript objects have been created
|
||||||
|
* onPhoneGapInfoReady Internal event fired when device properties are available
|
||||||
|
* onDeviceReady User event fired to indicate that PhoneGap is ready
|
||||||
|
* onResume User event fired to indicate a start/resume lifecycle event
|
||||||
|
*
|
||||||
|
* The only PhoneGap events that user code should register for are:
|
||||||
|
* onDeviceReady
|
||||||
|
* onResume
|
||||||
|
*
|
||||||
|
* Listeners can be registered as:
|
||||||
|
* document.addEventListener("deviceready", myDeviceReadyListener, false);
|
||||||
|
* document.addEventListener("resume", myResumeListener, false);
|
||||||
|
*/
|
||||||
|
|
||||||
if (typeof(DeviceInfo) != 'object')
|
if (typeof(DeviceInfo) != 'object')
|
||||||
DeviceInfo = {};
|
DeviceInfo = {};
|
||||||
|
|
||||||
@ -124,7 +145,7 @@ PhoneGap.available = DeviceInfo.uuid != undefined;
|
|||||||
* @param {Function} func The function callback you want run once PhoneGap is initialized
|
* @param {Function} func The function callback you want run once PhoneGap is initialized
|
||||||
*/
|
*/
|
||||||
PhoneGap.addConstructor = function(func) {
|
PhoneGap.addConstructor = function(func) {
|
||||||
PhoneGap.onDeviceReady.subscribeOnce(function() {
|
PhoneGap.onPhoneGapInit.subscribeOnce(function() {
|
||||||
try {
|
try {
|
||||||
func();
|
func();
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
@ -162,6 +183,23 @@ PhoneGap.onDOMContentLoaded = new PhoneGap.Channel('onDOMContentLoaded');
|
|||||||
*/
|
*/
|
||||||
PhoneGap.onNativeReady = new PhoneGap.Channel('onNativeReady');
|
PhoneGap.onNativeReady = new PhoneGap.Channel('onNativeReady');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* onPhoneGapInit channel is fired when the web page is fully loaded and
|
||||||
|
* PhoneGap native code has been initialized.
|
||||||
|
*/
|
||||||
|
PhoneGap.onPhoneGapInit = new PhoneGap.Channel('onPhoneGapInit');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* onPhoneGapReady channel is fired when the JS PhoneGap objects have been created.
|
||||||
|
*/
|
||||||
|
PhoneGap.onPhoneGapReady = new PhoneGap.Channel('onPhoneGapReady');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* onPhoneGapInfoReady channel is fired when the PhoneGap device properties
|
||||||
|
* has been set.
|
||||||
|
*/
|
||||||
|
PhoneGap.onPhoneGapInfoReady = new PhoneGap.Channel('onPhoneGapInfoReady');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onResume channel is fired when the PhoneGap native code
|
* onResume channel is fired when the PhoneGap native code
|
||||||
* resumes.
|
* resumes.
|
||||||
@ -180,29 +218,44 @@ PhoneGap.onPause = new PhoneGap.Channel('onPause');
|
|||||||
if (typeof _nativeReady !== 'undefined') { PhoneGap.onNativeReady.fire(); }
|
if (typeof _nativeReady !== 'undefined') { PhoneGap.onNativeReady.fire(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onDeviceReady is fired only after both onDOMContentLoaded and
|
* onDeviceReady is fired only after all PhoneGap objects are created and
|
||||||
* onNativeReady have fired.
|
* the device properties are set.
|
||||||
*/
|
*/
|
||||||
PhoneGap.onDeviceReady = new PhoneGap.Channel('onDeviceReady');
|
PhoneGap.onDeviceReady = new PhoneGap.Channel('onDeviceReady');
|
||||||
|
|
||||||
PhoneGap.onDeviceReady.subscribeOnce(function() {
|
|
||||||
PhoneGap.JSCallback();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create all PhoneGap objects once page has fully loaded and native side is ready.
|
||||||
|
*/
|
||||||
|
PhoneGap.Channel.join(function() {
|
||||||
|
|
||||||
|
// Start listening for XHR callbacks
|
||||||
|
PhoneGap.JSCallback();
|
||||||
|
|
||||||
|
// Run PhoneGap constructors
|
||||||
|
PhoneGap.onPhoneGapInit.fire();
|
||||||
|
|
||||||
|
// Fire event to notify that all objects are created
|
||||||
|
PhoneGap.onPhoneGapReady.fire();
|
||||||
|
|
||||||
|
}, [ PhoneGap.onDOMContentLoaded, PhoneGap.onNativeReady ]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fire onDeviceReady event once all constructors have run and PhoneGap info has been
|
||||||
|
* received from native side.
|
||||||
|
*/
|
||||||
PhoneGap.Channel.join(function() {
|
PhoneGap.Channel.join(function() {
|
||||||
PhoneGap.onDeviceReady.fire();
|
PhoneGap.onDeviceReady.fire();
|
||||||
|
|
||||||
// Fire the onresume event, since first one happens before JavaScript is loaded
|
// Fire the onresume event, since first one happens before JavaScript is loaded
|
||||||
PhoneGap.onResume.fire();
|
PhoneGap.onResume.fire();
|
||||||
}, [ PhoneGap.onDOMContentLoaded, PhoneGap.onNativeReady ]);
|
}, [ PhoneGap.onPhoneGapReady, PhoneGap.onPhoneGapInfoReady]);
|
||||||
|
|
||||||
|
|
||||||
// Listen for DOMContentLoaded and notify our channel subscribers
|
// Listen for DOMContentLoaded and notify our channel subscribers
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
PhoneGap.onDOMContentLoaded.fire();
|
PhoneGap.onDOMContentLoaded.fire();
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
|
||||||
// Intercept calls to document.addEventListener and watch for deviceready
|
// Intercept calls to document.addEventListener and watch for deviceready
|
||||||
PhoneGap.m_document_addEventListener = document.addEventListener;
|
PhoneGap.m_document_addEventListener = document.addEventListener;
|
||||||
|
|
||||||
@ -281,6 +334,7 @@ PhoneGap.callbacks = {};
|
|||||||
* @param {String} command Command to be run in PhoneGap, e.g. "ClassName.method"
|
* @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
|
* @param {String[]} [args] Zero or more arguments to pass to the method
|
||||||
*/
|
*/
|
||||||
|
// TODO: Not used anymore, should be removed.
|
||||||
PhoneGap.exec = function(clazz, action, args) {
|
PhoneGap.exec = function(clazz, action, args) {
|
||||||
try {
|
try {
|
||||||
var callbackId = 0;
|
var callbackId = 0;
|
||||||
@ -302,16 +356,32 @@ PhoneGap.exec = function(clazz, action, args) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
PhoneGap.execAsync = function(success, fail, clazz, action, args) {
|
/**
|
||||||
|
* Execute a PhoneGap command. It is up to the native side whether this action is synch or async.
|
||||||
|
* The native side can return:
|
||||||
|
* Synchronous: PluginResult object as a JSON string
|
||||||
|
* Asynchrounous: Empty string ""
|
||||||
|
* If async, the native side will PhoneGap.callbackSuccess or PhoneGap.callbackError,
|
||||||
|
* depending upon the result of the action.
|
||||||
|
*
|
||||||
|
* @param {Function} success The success callback
|
||||||
|
* @param {Function} fail The fail callback
|
||||||
|
* @param {String} service The name of the service to use
|
||||||
|
* @param {String} action Action to be run in PhoneGap
|
||||||
|
* @param {String[]} [args] Zero or more arguments to pass to the method
|
||||||
|
*/
|
||||||
|
PhoneGap.execAsync = function(success, fail, service, action, args) {
|
||||||
try {
|
try {
|
||||||
var callbackId = clazz + PhoneGap.callbackId++;
|
var callbackId = service + PhoneGap.callbackId++;
|
||||||
if (success || fail) {
|
if (success || fail) {
|
||||||
PhoneGap.callbacks[callbackId] = {success:success, fail:fail};
|
PhoneGap.callbacks[callbackId] = {success:success, fail:fail};
|
||||||
}
|
}
|
||||||
var r = PluginManager.exec(clazz, action, callbackId, this.stringify(args), true);
|
|
||||||
|
// Note: Device returns string, but for some reason emulator returns object - so convert to string.
|
||||||
|
var r = ""+PluginManager.exec(service, action, callbackId, this.stringify(args), true);
|
||||||
|
|
||||||
// If a result was returned
|
// If a result was returned
|
||||||
if ((typeof r == "string") && (r.length > 0)) {
|
if (r.length > 0) {
|
||||||
eval("var v="+r+";");
|
eval("var v="+r+";");
|
||||||
|
|
||||||
// If status is OK, then return value back to caller
|
// If status is OK, then return value back to caller
|
||||||
@ -342,6 +412,12 @@ PhoneGap.execAsync = function(success, fail, clazz, action, args) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by native code when returning successful result from an action.
|
||||||
|
*
|
||||||
|
* @param callbackId
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
PhoneGap.callbackSuccess = function(callbackId, args) {
|
PhoneGap.callbackSuccess = function(callbackId, args) {
|
||||||
if (PhoneGap.callbacks[callbackId]) {
|
if (PhoneGap.callbacks[callbackId]) {
|
||||||
try {
|
try {
|
||||||
@ -356,6 +432,12 @@ PhoneGap.callbackSuccess = function(callbackId, args) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by native code when returning error result from an action.
|
||||||
|
*
|
||||||
|
* @param callbackId
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
PhoneGap.callbackError = function(callbackId, args) {
|
PhoneGap.callbackError = function(callbackId, args) {
|
||||||
if (PhoneGap.callbacks[callbackId]) {
|
if (PhoneGap.callbacks[callbackId]) {
|
||||||
try {
|
try {
|
||||||
@ -378,6 +460,7 @@ PhoneGap.callbackError = function(callbackId, args) {
|
|||||||
* url, which will be turned into a dictionary on the other end.
|
* url, which will be turned into a dictionary on the other end.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
// TODO: Is this used?
|
||||||
PhoneGap.run_command = function() {
|
PhoneGap.run_command = function() {
|
||||||
if (!PhoneGap.available || !PhoneGap.queue.ready)
|
if (!PhoneGap.available || !PhoneGap.queue.ready)
|
||||||
return;
|
return;
|
||||||
@ -417,6 +500,8 @@ PhoneGap.run_command = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This is only for Android.
|
||||||
|
*
|
||||||
* Internal function that uses XHR to call into PhoneGap Java code and retrieve
|
* Internal function that uses XHR to call into PhoneGap Java code and retrieve
|
||||||
* any JavaScript code that needs to be run. This is used for callbacks from
|
* any JavaScript code that needs to be run. This is used for callbacks from
|
||||||
* Java to JavaScript.
|
* Java to JavaScript.
|
||||||
|
@ -6,26 +6,47 @@ import android.os.Environment;
|
|||||||
import android.os.StatFs;
|
import android.os.StatFs;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class provides file directory utilities.
|
||||||
|
* All file operations are performed on the SD card.
|
||||||
|
*
|
||||||
|
* It is used by the FileUtils class.
|
||||||
|
*/
|
||||||
public class DirectoryManager {
|
public class DirectoryManager {
|
||||||
|
|
||||||
protected static boolean testFileExists (String name){
|
/**
|
||||||
|
* Determine if a file or directory exists.
|
||||||
|
*
|
||||||
|
* @param name The name of the file to check.
|
||||||
|
* @return T=exists, F=not found
|
||||||
|
*/
|
||||||
|
protected static boolean testFileExists(String name) {
|
||||||
boolean status;
|
boolean status;
|
||||||
if ((testSaveLocationExists())&&(!name.equals(""))){
|
|
||||||
|
// If SD card exists
|
||||||
|
if ((testSaveLocationExists()) && (!name.equals(""))) {
|
||||||
File path = Environment.getExternalStorageDirectory();
|
File path = Environment.getExternalStorageDirectory();
|
||||||
File newPath = constructFilePaths(path.toString(), name);
|
File newPath = constructFilePaths(path.toString(), name);
|
||||||
status = newPath.exists();
|
status = newPath.exists();
|
||||||
}else{
|
}
|
||||||
|
|
||||||
|
// If no SD card
|
||||||
|
else{
|
||||||
status = false;
|
status = false;
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static long getFreeDiskSpace(){
|
/**
|
||||||
/*
|
* Get the free disk space on the SD card
|
||||||
* gets the available SD card free space or returns -1 if the SD card is not mounted.
|
*
|
||||||
*/
|
* @return Size in KB or -1 if not available
|
||||||
|
*/
|
||||||
|
protected static long getFreeDiskSpace() {
|
||||||
String status = Environment.getExternalStorageState();
|
String status = Environment.getExternalStorageState();
|
||||||
long freeSpace = 0;
|
long freeSpace = 0;
|
||||||
|
|
||||||
|
// If SD card exists
|
||||||
if (status.equals(Environment.MEDIA_MOUNTED)) {
|
if (status.equals(Environment.MEDIA_MOUNTED)) {
|
||||||
try {
|
try {
|
||||||
File path = Environment.getExternalStorageDirectory();
|
File path = Environment.getExternalStorageDirectory();
|
||||||
@ -34,44 +55,82 @@ public class DirectoryManager {
|
|||||||
long availableBlocks = stat.getAvailableBlocks();
|
long availableBlocks = stat.getAvailableBlocks();
|
||||||
freeSpace = availableBlocks*blockSize/1024;
|
freeSpace = availableBlocks*blockSize/1024;
|
||||||
} catch (Exception e) {e.printStackTrace(); }
|
} catch (Exception e) {e.printStackTrace(); }
|
||||||
} else { return -1; }
|
}
|
||||||
|
|
||||||
|
// If no SD card, then return -1
|
||||||
|
else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return (freeSpace);
|
return (freeSpace);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean createDirectory(String directoryName){
|
/**
|
||||||
|
* Create directory on SD card.
|
||||||
|
*
|
||||||
|
* @param directoryName The name of the directory to create.
|
||||||
|
* @return T=successful, F=failed
|
||||||
|
*/
|
||||||
|
protected static boolean createDirectory(String directoryName) {
|
||||||
boolean status;
|
boolean status;
|
||||||
if ((testSaveLocationExists())&&(!directoryName.equals(""))){
|
|
||||||
|
// Make sure SD card exists
|
||||||
|
if ((testSaveLocationExists()) && (!directoryName.equals(""))) {
|
||||||
File path = Environment.getExternalStorageDirectory();
|
File path = Environment.getExternalStorageDirectory();
|
||||||
File newPath = constructFilePaths(path.toString(), directoryName);
|
File newPath = constructFilePaths(path.toString(), directoryName);
|
||||||
status = newPath.mkdir();
|
status = newPath.mkdir();
|
||||||
status = true;
|
status = true;
|
||||||
}else
|
}
|
||||||
|
|
||||||
|
// If no SD card or invalid dir name
|
||||||
|
else {
|
||||||
status = false;
|
status = false;
|
||||||
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean testSaveLocationExists(){
|
/**
|
||||||
|
* Determine if SD card exists.
|
||||||
|
*
|
||||||
|
* @return T=exists, F=not found
|
||||||
|
*/
|
||||||
|
protected static boolean testSaveLocationExists() {
|
||||||
String sDCardStatus = Environment.getExternalStorageState();
|
String sDCardStatus = Environment.getExternalStorageState();
|
||||||
boolean status;
|
boolean status;
|
||||||
if (sDCardStatus.equals(Environment.MEDIA_MOUNTED)){
|
|
||||||
|
// If SD card is mounted
|
||||||
|
if (sDCardStatus.equals(Environment.MEDIA_MOUNTED)) {
|
||||||
status = true;
|
status = true;
|
||||||
}else
|
}
|
||||||
|
|
||||||
|
// If no SD card
|
||||||
|
else {
|
||||||
status = false;
|
status = false;
|
||||||
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean deleteDirectory(String fileName){
|
/**
|
||||||
|
* Delete directory.
|
||||||
|
*
|
||||||
|
* @param fileName The name of the directory to delete
|
||||||
|
* @return T=deleted, F=could not delete
|
||||||
|
*/
|
||||||
|
protected static boolean deleteDirectory(String fileName) {
|
||||||
boolean status;
|
boolean status;
|
||||||
SecurityManager checker = new SecurityManager();
|
SecurityManager checker = new SecurityManager();
|
||||||
|
|
||||||
if ((testSaveLocationExists())&&(!fileName.equals(""))){
|
// Make sure SD card exists
|
||||||
|
if ((testSaveLocationExists()) && (!fileName.equals(""))) {
|
||||||
File path = Environment.getExternalStorageDirectory();
|
File path = Environment.getExternalStorageDirectory();
|
||||||
File newPath = constructFilePaths(path.toString(), fileName);
|
File newPath = constructFilePaths(path.toString(), fileName);
|
||||||
checker.checkDelete(newPath.toString());
|
checker.checkDelete(newPath.toString());
|
||||||
if(newPath.isDirectory()){
|
|
||||||
|
// If dir to delete is really a directory
|
||||||
|
if (newPath.isDirectory()) {
|
||||||
String[] listfile = newPath.list();
|
String[] listfile = newPath.list();
|
||||||
// delete all files within the specified directory and then delete the directory
|
|
||||||
|
// Delete all files within the specified directory and then delete the directory
|
||||||
try{
|
try{
|
||||||
for (int i=0; i < listfile.length; i++){
|
for (int i=0; i < listfile.length; i++){
|
||||||
File deletedFile = new File (newPath.toString()+"/"+listfile[i].toString());
|
File deletedFile = new File (newPath.toString()+"/"+listfile[i].toString());
|
||||||
@ -80,27 +139,43 @@ public class DirectoryManager {
|
|||||||
newPath.delete();
|
newPath.delete();
|
||||||
Log.i("DirectoryManager deleteDirectory", fileName);
|
Log.i("DirectoryManager deleteDirectory", fileName);
|
||||||
status = true;
|
status = true;
|
||||||
}catch (Exception e){
|
}
|
||||||
|
catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
status = false;
|
status = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}else
|
|
||||||
|
// If dir not a directory, then error
|
||||||
|
else {
|
||||||
status = false;
|
status = false;
|
||||||
}else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no SD card
|
||||||
|
else {
|
||||||
status = false;
|
status = false;
|
||||||
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean deleteFile(String fileName){
|
/**
|
||||||
|
* Delete file.
|
||||||
|
*
|
||||||
|
* @param fileName The name of the file to delete
|
||||||
|
* @return T=deleted, F=not deleted
|
||||||
|
*/
|
||||||
|
protected static boolean deleteFile(String fileName) {
|
||||||
boolean status;
|
boolean status;
|
||||||
SecurityManager checker = new SecurityManager();
|
SecurityManager checker = new SecurityManager();
|
||||||
|
|
||||||
if ((testSaveLocationExists())&&(!fileName.equals(""))){
|
// Make sure SD card exists
|
||||||
|
if ((testSaveLocationExists()) && (!fileName.equals(""))) {
|
||||||
File path = Environment.getExternalStorageDirectory();
|
File path = Environment.getExternalStorageDirectory();
|
||||||
File newPath = constructFilePaths(path.toString(), fileName);
|
File newPath = constructFilePaths(path.toString(), fileName);
|
||||||
checker.checkDelete(newPath.toString());
|
checker.checkDelete(newPath.toString());
|
||||||
|
|
||||||
|
// If file to delete is really a file
|
||||||
if (newPath.isFile()){
|
if (newPath.isFile()){
|
||||||
try {
|
try {
|
||||||
Log.i("DirectoryManager deleteFile", fileName);
|
Log.i("DirectoryManager deleteFile", fileName);
|
||||||
@ -110,14 +185,28 @@ public class DirectoryManager {
|
|||||||
se.printStackTrace();
|
se.printStackTrace();
|
||||||
status = false;
|
status = false;
|
||||||
}
|
}
|
||||||
}else
|
}
|
||||||
|
// If not a file, then error
|
||||||
|
else {
|
||||||
status = false;
|
status = false;
|
||||||
}else
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no SD card
|
||||||
|
else {
|
||||||
status = false;
|
status = false;
|
||||||
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File constructFilePaths (String file1, String file2){
|
/**
|
||||||
|
* Create a new file object from two file paths.
|
||||||
|
*
|
||||||
|
* @param file1 Base file path
|
||||||
|
* @param file2 Remaining file path
|
||||||
|
* @return File object
|
||||||
|
*/
|
||||||
|
private static File constructFilePaths (String file1, String file2) {
|
||||||
File newPath;
|
File newPath;
|
||||||
newPath = new File(file1+"/"+file2);
|
newPath = new File(file1+"/"+file2);
|
||||||
return newPath;
|
return newPath;
|
||||||
|
@ -82,7 +82,6 @@ public class DroidGap extends Activity {
|
|||||||
protected Boolean loadInWebView = false;
|
protected Boolean loadInWebView = false;
|
||||||
private LinearLayout root;
|
private LinearLayout root;
|
||||||
|
|
||||||
private FileUtils fs;
|
|
||||||
private BrowserKey mKey;
|
private BrowserKey mKey;
|
||||||
public CallbackServer callbackServer;
|
public CallbackServer callbackServer;
|
||||||
private PluginManager pluginManager;
|
private PluginManager pluginManager;
|
||||||
@ -266,13 +265,11 @@ public class DroidGap extends Activity {
|
|||||||
private void bindBrowser(WebView appView) {
|
private void bindBrowser(WebView appView) {
|
||||||
this.callbackServer = new CallbackServer();
|
this.callbackServer = new CallbackServer();
|
||||||
this.pluginManager = new PluginManager(appView, this);
|
this.pluginManager = new PluginManager(appView, this);
|
||||||
this.fs = new FileUtils(appView, this);
|
|
||||||
this.mKey = new BrowserKey(appView, this);
|
this.mKey = new BrowserKey(appView, this);
|
||||||
|
|
||||||
// This creates the new javascript interfaces for PhoneGap
|
// This creates the new javascript interfaces for PhoneGap
|
||||||
appView.addJavascriptInterface(this.pluginManager, "PluginManager");
|
appView.addJavascriptInterface(this.pluginManager, "PluginManager");
|
||||||
|
|
||||||
appView.addJavascriptInterface(this.fs, "FileUtil");
|
|
||||||
appView.addJavascriptInterface(this.mKey, "BackButton");
|
appView.addJavascriptInterface(this.mKey, "BackButton");
|
||||||
|
|
||||||
appView.addJavascriptInterface(this.callbackServer, "CallbackServer");
|
appView.addJavascriptInterface(this.callbackServer, "CallbackServer");
|
||||||
@ -285,10 +282,10 @@ public class DroidGap extends Activity {
|
|||||||
Storage cupcakeStorage = (Storage)this.pluginManager.addPlugin("com.phonegap.Storage");
|
Storage cupcakeStorage = (Storage)this.pluginManager.addPlugin("com.phonegap.Storage");
|
||||||
cupcakeStorage.setStorage(appPackage);
|
cupcakeStorage.setStorage(appPackage);
|
||||||
|
|
||||||
this.pluginManager.addPlugin("com.phonegap.GeoBroker");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.addService("Geolocation", "com.phonegap.GeoBroker");
|
||||||
this.addService("Device", "com.phonegap.Device");
|
this.addService("Device", "com.phonegap.Device");
|
||||||
this.addService("Accelerometer", "com.phonegap.AccelListener");
|
this.addService("Accelerometer", "com.phonegap.AccelListener");
|
||||||
this.addService("Compass", "com.phonegap.CompassListener");
|
this.addService("Compass", "com.phonegap.CompassListener");
|
||||||
@ -296,6 +293,7 @@ public class DroidGap extends Activity {
|
|||||||
this.addService("Camera", "com.phonegap.CameraLauncher");
|
this.addService("Camera", "com.phonegap.CameraLauncher");
|
||||||
this.addService("Contacts", "com.phonegap.ContactManager");
|
this.addService("Contacts", "com.phonegap.ContactManager");
|
||||||
this.addService("Crypto", "com.phonegap.CryptoHandler");
|
this.addService("Crypto", "com.phonegap.CryptoHandler");
|
||||||
|
this.addService("File", "com.phonegap.FileUtils");
|
||||||
this.addService("Location", "com.phonegap.GeoBroker");
|
this.addService("Location", "com.phonegap.GeoBroker");
|
||||||
this.addService("Network Status", "com.phonegap.NetworkManager");
|
this.addService("Network Status", "com.phonegap.NetworkManager");
|
||||||
this.addService("Storage", "com.phonegap.Storage");
|
this.addService("Storage", "com.phonegap.Storage");
|
||||||
|
339
framework/src/com/phonegap/FileUtils.java
Normal file → Executable file
339
framework/src/com/phonegap/FileUtils.java
Normal file → Executable file
@ -2,123 +2,264 @@ package com.phonegap;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
import com.phonegap.api.Plugin;
|
||||||
|
import com.phonegap.api.PluginResult;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
public class FileUtils {
|
/**
|
||||||
|
* This class provides SD card file and directory services to JavaScript.
|
||||||
|
* Only files on the SD card can be accessed.
|
||||||
|
*/
|
||||||
|
public class FileUtils implements Plugin {
|
||||||
|
|
||||||
|
public static int NOT_FOUND_ERR = 8;
|
||||||
|
public static int SECURITY_ERR = 18;
|
||||||
|
public static int ABORT_ERR = 20;
|
||||||
|
|
||||||
|
public static int NOT_READABLE_ERR = 24;
|
||||||
|
public static int ENCODING_ERR = 26;
|
||||||
|
|
||||||
|
|
||||||
WebView mView;
|
WebView webView; // WebView object
|
||||||
|
DroidGap ctx; // DroidGap object
|
||||||
|
|
||||||
FileReader f_in;
|
FileReader f_in;
|
||||||
FileWriter f_out;
|
FileWriter f_out;
|
||||||
|
|
||||||
public FileUtils(WebView view, DroidGap gap)
|
/**
|
||||||
{
|
* Constructor.
|
||||||
mView = view;
|
*/
|
||||||
|
public FileUtils() {
|
||||||
|
System.out.println("FileUtils()");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int testSaveLocationExists(){
|
|
||||||
if (DirectoryManager.testSaveLocationExists())
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getFreeDiskSpace(){
|
|
||||||
long freeDiskSpace=DirectoryManager.getFreeDiskSpace();
|
|
||||||
return freeDiskSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int testFileExists(String file){
|
/**
|
||||||
if (DirectoryManager.testFileExists(file))
|
* Sets the context of the Command. This can then be used to do things like
|
||||||
return 0;
|
* get file paths associated with the Activity.
|
||||||
else
|
*
|
||||||
return 1;
|
* @param ctx The context of the main Activity.
|
||||||
}
|
|
||||||
|
|
||||||
public int testDirectoryExists(String file){
|
|
||||||
if (DirectoryManager.testFileExists(file))
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a specific directory.
|
|
||||||
* Everyting in side the directory would be gone.
|
|
||||||
* TODO: JavaScript Call backs for success and error handling
|
|
||||||
*/
|
*/
|
||||||
public int deleteDirectory (String dir){
|
public void setContext(DroidGap ctx) {
|
||||||
if (DirectoryManager.deleteDirectory(dir))
|
this.ctx = ctx;
|
||||||
return 0;
|
}
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a specific file.
|
* Sets the main View of the application, this is the WebView within which
|
||||||
* TODO: JavaScript Call backs for success and error handling
|
* a PhoneGap app runs.
|
||||||
|
*
|
||||||
|
* @param webView The PhoneGap WebView
|
||||||
*/
|
*/
|
||||||
public int deleteFile (String file){
|
public void setView(WebView webView) {
|
||||||
if (DirectoryManager.deleteFile(file))
|
this.webView = webView;
|
||||||
return 0;
|
}
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new directory.
|
* Executes the request and returns CommandResult.
|
||||||
* TODO: JavaScript Call backs for success and error handling
|
*
|
||||||
|
* @param action The command to execute.
|
||||||
|
* @param args JSONArry of arguments for the command.
|
||||||
|
* @return A CommandResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
public int createDirectory(String dir){
|
public PluginResult execute(String action, JSONArray args) {
|
||||||
if (DirectoryManager.createDirectory(dir))
|
PluginResult.Status status = PluginResult.Status.OK;
|
||||||
return 0;
|
String result = "";
|
||||||
else
|
//System.out.println("FileUtils.execute("+action+")");
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String read(String filename)
|
|
||||||
{
|
|
||||||
String data = "";
|
|
||||||
String output = "";
|
|
||||||
try {
|
|
||||||
FileInputStream fstream = new FileInputStream(filename);
|
|
||||||
DataInputStream in = new DataInputStream(fstream);
|
|
||||||
while (in.available() !=0)
|
|
||||||
{
|
|
||||||
data += in.readLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
data = "FAIL: File not found";
|
|
||||||
} catch (IOException e) {
|
|
||||||
data = "FAIL: IO ERROR";
|
|
||||||
}
|
|
||||||
|
|
||||||
//mView.loadUrl("javascript:navigator.FileReader.hasRead('" + data + "')");
|
try {
|
||||||
|
if (action.equals("testSaveLocationExists")) {
|
||||||
|
boolean b = DirectoryManager.testSaveLocationExists();
|
||||||
|
return new PluginResult(status, b);
|
||||||
|
}
|
||||||
|
else if (action.equals("getFreeDiskSpace")) {
|
||||||
|
long l = DirectoryManager.getFreeDiskSpace();
|
||||||
|
return new PluginResult(status, l);
|
||||||
|
}
|
||||||
|
else if (action.equals("testFileExists")) {
|
||||||
|
boolean b = DirectoryManager.testFileExists(args.getString(0));
|
||||||
|
return new PluginResult(status, b);
|
||||||
|
}
|
||||||
|
else if (action.equals("testDirectoryExists")) {
|
||||||
|
boolean b = DirectoryManager.testFileExists(args.getString(0));
|
||||||
|
return new PluginResult(status, b);
|
||||||
|
}
|
||||||
|
else if (action.equals("deleteDirectory")) {
|
||||||
|
boolean b = DirectoryManager.deleteDirectory(args.getString(0));
|
||||||
|
return new PluginResult(status, b);
|
||||||
|
}
|
||||||
|
else if (action.equals("deleteFile")) {
|
||||||
|
boolean b = DirectoryManager.deleteFile(args.getString(0));
|
||||||
|
return new PluginResult(status, b);
|
||||||
|
}
|
||||||
|
else if (action.equals("createDirectory")) {
|
||||||
|
boolean b = DirectoryManager.createDirectory(args.getString(0));
|
||||||
|
return new PluginResult(status, b);
|
||||||
|
}
|
||||||
|
else if (action.equals("readAsText")) {
|
||||||
|
try {
|
||||||
|
String s = this.readAsText(args.getString(0), args.getString(1));
|
||||||
|
return new PluginResult(status, s);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_FOUND_ERR);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_READABLE_ERR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (action.equals("readAsDataURL")) {
|
||||||
|
try {
|
||||||
|
String s = this.readAsDataURL(args.getString(0));
|
||||||
|
return new PluginResult(status, s);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_FOUND_ERR);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_READABLE_ERR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (action.equals("writeAsText")) {
|
||||||
|
try {
|
||||||
|
this.writeAsText(args.getString(0), args.getString(1), args.getBoolean(2));
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_FOUND_ERR);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_READABLE_ERR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new PluginResult(status, result);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identifies if action to be executed returns a value and should be run synchronously.
|
||||||
|
*
|
||||||
|
* @param action The action to execute
|
||||||
|
* @return T=returns value
|
||||||
|
*/
|
||||||
|
public boolean isSynch(String action) {
|
||||||
|
if (action.equals("readAsText")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (action.equals("readAsDataURL")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (action.equals("writeAsText")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the system is about to start resuming a previous activity.
|
||||||
|
*/
|
||||||
|
public void onPause() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the activity will start interacting with the user.
|
||||||
|
*/
|
||||||
|
public void onResume() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by AccelBroker when listener is to be shut down.
|
||||||
|
* Stop listener.
|
||||||
|
*/
|
||||||
|
public void onDestroy() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when an activity you launched exits, giving you the requestCode you started it with,
|
||||||
|
* the resultCode it returned, and any additional data from it.
|
||||||
|
*
|
||||||
|
* @param requestCode The request code originally supplied to startActivityForResult(),
|
||||||
|
* allowing you to identify who this result came from.
|
||||||
|
* @param resultCode The integer result code returned by the child activity through its setResult().
|
||||||
|
* @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
|
||||||
|
*/
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
// LOCAL METHODS
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read content of text file.
|
||||||
|
*
|
||||||
|
* @param filename The name of the file.
|
||||||
|
* @param encoding The encoding to return contents as. Typical value is UTF-8.
|
||||||
|
* (see http://www.iana.org/assignments/character-sets)
|
||||||
|
* @return Contents of file.
|
||||||
|
* @throws FileNotFoundException, IOException
|
||||||
|
*/
|
||||||
|
public String readAsText(String filename, String encoding) throws FileNotFoundException, IOException {
|
||||||
|
System.out.println("FileUtils.readAsText("+filename+", "+encoding+")");
|
||||||
|
StringBuilder data = new StringBuilder();
|
||||||
|
FileInputStream fis = new FileInputStream(filename);
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(fis, encoding), 1024);
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
data.append(line);
|
||||||
|
}
|
||||||
|
return data.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read content of text file and return as base64 encoded data url.
|
||||||
|
*
|
||||||
|
* @param filename The name of the file.
|
||||||
|
* @return Contents of file = data:<media type>;base64,<data>
|
||||||
|
* @throws FileNotFoundException, IOException
|
||||||
|
*/
|
||||||
|
public String readAsDataURL(String filename) throws FileNotFoundException, IOException {
|
||||||
|
byte[] bytes = new byte[1000];
|
||||||
|
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(filename), 1024);
|
||||||
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
int numRead = 0;
|
||||||
|
while ((numRead = bis.read(bytes, 0, 1000)) >= 0) {
|
||||||
|
bos.write(bytes, 0, numRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine content type from file name
|
||||||
|
// TODO
|
||||||
|
String contentType = "";
|
||||||
|
|
||||||
|
byte[] base64 = Base64.encodeBase64(bos.toByteArray());
|
||||||
|
String data = "data:" + contentType + ";base64," + new String(base64);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int write(String filename, String data, boolean append)
|
/**
|
||||||
{
|
* Write contents of file.
|
||||||
String FilePath= filename;
|
*
|
||||||
try {
|
* @param filename The name of the file.
|
||||||
byte [] rawData = data.getBytes();
|
* @param data The contents of the file.
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(rawData);
|
* @param append T=append, F=overwrite
|
||||||
FileOutputStream out= new FileOutputStream(FilePath, append);
|
* @throws FileNotFoundException, IOException
|
||||||
byte buff[] = new byte[rawData.length];
|
*/
|
||||||
in.read(buff, 0, buff.length);
|
public void writeAsText(String filename, String data, boolean append) throws FileNotFoundException, IOException {
|
||||||
out.write(buff, 0, rawData.length);
|
String FilePath= filename;
|
||||||
out.flush();
|
byte [] rawData = data.getBytes();
|
||||||
out.close();
|
ByteArrayInputStream in = new ByteArrayInputStream(rawData);
|
||||||
//mView.loadUrl("javascript:navigator.FileReader.onsuccess('File written')");
|
FileOutputStream out= new FileOutputStream(FilePath, append);
|
||||||
} catch (Exception e) {
|
byte buff[] = new byte[rawData.length];
|
||||||
//mView.loadUrl("javascript:navigator.FileReader.onerror('Fail')");
|
in.read(buff, 0, buff.length);
|
||||||
// So, do we just return -1 at this point!
|
out.write(buff, 0, rawData.length);
|
||||||
return -1;
|
out.flush();
|
||||||
}
|
out.close();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
77
framework/src/com/phonegap/GeoBroker.java
Normal file → Executable file
77
framework/src/com/phonegap/GeoBroker.java
Normal file → Executable file
@ -1,6 +1,7 @@
|
|||||||
package com.phonegap;
|
package com.phonegap;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@ -22,6 +23,7 @@ public class GeoBroker implements Plugin {
|
|||||||
WebView webView; // WebView object
|
WebView webView; // WebView object
|
||||||
DroidGap ctx; // DroidGap object
|
DroidGap ctx; // DroidGap object
|
||||||
|
|
||||||
|
// List of gGeolocation listeners
|
||||||
private HashMap<String, GeoListener> geoListeners;
|
private HashMap<String, GeoListener> geoListeners;
|
||||||
private GeoListener global;
|
private GeoListener global;
|
||||||
|
|
||||||
@ -65,10 +67,10 @@ public class GeoBroker implements Plugin {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (action.equals("getCurrentLocation")) {
|
if (action.equals("getCurrentLocation")) {
|
||||||
this.getCurrentLocation();
|
this.getCurrentLocation(args.getBoolean(0), args.getInt(1), args.getInt(2));
|
||||||
}
|
}
|
||||||
else if (action.equals("start")) {
|
else if (action.equals("start")) {
|
||||||
String s = this.start(args.getInt(0), args.getString(1));
|
String s = this.start(args.getString(0), args.getBoolean(1), args.getInt(2), args.getInt(3));
|
||||||
return new PluginResult(status, s);
|
return new PluginResult(status, s);
|
||||||
}
|
}
|
||||||
else if (action.equals("stop")) {
|
else if (action.equals("stop")) {
|
||||||
@ -87,7 +89,8 @@ public class GeoBroker implements Plugin {
|
|||||||
* @return T=returns value
|
* @return T=returns value
|
||||||
*/
|
*/
|
||||||
public boolean isSynch(String action) {
|
public boolean isSynch(String action) {
|
||||||
return false;
|
// Starting listeners is easier to run on main thread, so don't run async.
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,10 +106,22 @@ public class GeoBroker implements Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by AccelBroker when listener is to be shut down.
|
* Called when the activity is to be shut down.
|
||||||
* Stop listener.
|
* Stop listener.
|
||||||
*/
|
*/
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
|
java.util.Set<Entry<String,GeoListener>> s = this.geoListeners.entrySet();
|
||||||
|
java.util.Iterator<Entry<String,GeoListener>> it = s.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Entry<String,GeoListener> entry = it.next();
|
||||||
|
GeoListener listener = entry.getValue();
|
||||||
|
listener.destroy();
|
||||||
|
}
|
||||||
|
this.geoListeners.clear();
|
||||||
|
if (this.global != null) {
|
||||||
|
this.global.destroy();
|
||||||
|
}
|
||||||
|
this.global = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,23 +140,57 @@ public class GeoBroker implements Plugin {
|
|||||||
// LOCAL METHODS
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
public void getCurrentLocation() {
|
/**
|
||||||
//It's supposed to run async!
|
* Get current location.
|
||||||
if (global == null) {
|
* The result is returned to JavaScript via a callback.
|
||||||
global = new GeoListener("global", this.ctx, 10000, this.webView);
|
*
|
||||||
|
* @param enableHighAccuracy
|
||||||
|
* @param timeout
|
||||||
|
* @param maximumAge
|
||||||
|
*/
|
||||||
|
public void getCurrentLocation(boolean enableHighAccuracy, int timeout, int maximumAge) {
|
||||||
|
|
||||||
|
// Create a geolocation listener just for getCurrentLocation and call it "global"
|
||||||
|
if (this.global == null) {
|
||||||
|
this.global = new GeoListener("global", this.ctx, maximumAge, this.webView);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
global.start(10000);
|
this.global.start(maximumAge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String start(int freq, String key) {
|
/**
|
||||||
GeoListener listener = new GeoListener(key, this.ctx, freq, this.webView);
|
* Start geolocation listener and add to listener list.
|
||||||
geoListeners.put(key, listener);
|
*
|
||||||
|
* @param key The listener id
|
||||||
|
* @param enableHighAccuracy
|
||||||
|
* @param timeout
|
||||||
|
* @param maximumAge
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String start(String key, boolean enableHighAccuracy, int timeout, int maximumAge) {
|
||||||
|
|
||||||
|
// Make sure this listener doesn't already exist
|
||||||
|
GeoListener listener = geoListeners.get(key);
|
||||||
|
if (listener == null) {
|
||||||
|
listener = new GeoListener(key, this.ctx, maximumAge, this.webView);
|
||||||
|
geoListeners.put(key, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start it
|
||||||
|
listener.start(maximumAge);
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop geolocation listener and remove from listener list.
|
||||||
|
*
|
||||||
|
* @param key The listener id
|
||||||
|
*/
|
||||||
public void stop(String key) {
|
public void stop(String key) {
|
||||||
GeoListener geo = geoListeners.get(key);
|
GeoListener listener = geoListeners.remove(key);
|
||||||
|
if (listener != null) {
|
||||||
|
listener.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
133
framework/src/com/phonegap/GeoListener.java
Normal file → Executable file
133
framework/src/com/phonegap/GeoListener.java
Normal file → Executable file
@ -6,83 +6,112 @@ import android.location.LocationManager;
|
|||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
public class GeoListener {
|
public class GeoListener {
|
||||||
String id;
|
public static int PERMISSION_DENIED = 1;
|
||||||
String successCallback;
|
public static int POSITION_UNAVAILABLE = 2;
|
||||||
|
public static int TIMEOUT = 3;
|
||||||
|
|
||||||
|
String id; // Listener ID
|
||||||
|
String successCallback; //
|
||||||
String failCallback;
|
String failCallback;
|
||||||
GpsListener mGps;
|
GpsListener mGps; // GPS listener
|
||||||
NetworkListener mNetwork;
|
NetworkListener mNetwork; // Network listener
|
||||||
LocationManager mLocMan;
|
LocationManager mLocMan; // Location manager
|
||||||
private DroidGap mCtx;
|
|
||||||
private WebView mAppView;
|
private DroidGap ctx; // DroidGap object
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private WebView mAppView; // Webview object
|
||||||
|
|
||||||
int interval;
|
int interval;
|
||||||
|
|
||||||
GeoListener(String i, DroidGap ctx, int time, WebView appView) {
|
/**
|
||||||
id = i;
|
* Constructor.
|
||||||
interval = time;
|
*
|
||||||
mCtx = ctx;
|
* @param id Listener id
|
||||||
mGps = null;
|
* @param ctx
|
||||||
mNetwork = null;
|
* @param time Sampling period in msec
|
||||||
mLocMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
|
* @param appView
|
||||||
|
*/
|
||||||
|
GeoListener(String id, DroidGap ctx, int time, WebView appView) {
|
||||||
|
this.id = id;
|
||||||
|
this.interval = time;
|
||||||
|
this.ctx = ctx;
|
||||||
|
this.mGps = null;
|
||||||
|
this.mNetwork = null;
|
||||||
|
this.mLocMan = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
|
||||||
if (mLocMan.getProvider(LocationManager.GPS_PROVIDER) != null) {
|
// If GPS provider, then create and start GPS listener
|
||||||
mGps = new GpsListener(mCtx, interval, this);
|
if (this.mLocMan.getProvider(LocationManager.GPS_PROVIDER) != null) {
|
||||||
|
this.mGps = new GpsListener(ctx, time, this);
|
||||||
}
|
}
|
||||||
if (mLocMan.getProvider(LocationManager.NETWORK_PROVIDER) != null) {
|
|
||||||
mNetwork = new NetworkListener(mCtx, interval, this);
|
// If network provider, then create and start network listener
|
||||||
|
if (this.mLocMan.getProvider(LocationManager.NETWORK_PROVIDER) != null) {
|
||||||
|
this.mNetwork = new NetworkListener(ctx, time, this);
|
||||||
}
|
}
|
||||||
mAppView = appView;
|
this.mAppView = appView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy listener.
|
||||||
|
*/
|
||||||
|
public void destroy() {
|
||||||
|
this.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Location found. Send location back to JavaScript.
|
||||||
|
*
|
||||||
|
* @param loc
|
||||||
|
*/
|
||||||
void success(Location loc) {
|
void success(Location loc) {
|
||||||
/*
|
|
||||||
* We only need to figure out what we do when we succeed!
|
|
||||||
*/
|
|
||||||
|
|
||||||
String params;
|
String params = loc.getLatitude() + "," + loc.getLongitude() + ", " + loc.getAltitude() +
|
||||||
/*
|
"," + loc.getAccuracy() + "," + loc.getBearing() +
|
||||||
* Build the giant string to send back to Javascript!
|
"," + loc.getSpeed() + "," + loc.getTime();
|
||||||
*/
|
|
||||||
params = loc.getLatitude() + "," + loc.getLongitude() + ", " + loc.getAltitude() + "," + loc.getAccuracy() + "," + loc.getBearing();
|
if (id == "global") {
|
||||||
params += "," + loc.getSpeed() + "," + loc.getTime();
|
|
||||||
if (id != "global") {
|
|
||||||
mCtx.sendJavascript("navigator._geo.success(" + id + "," + params + ");");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mCtx.sendJavascript("navigator.geolocation.gotCurrentPosition(" + params + ");");
|
|
||||||
this.stop();
|
this.stop();
|
||||||
}
|
}
|
||||||
|
this.ctx.sendJavascript("navigator._geo.success('" + id + "'," + params + ");");
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail() {
|
/**
|
||||||
// Do we need to know why? How would we handle this?
|
* Location failed. Send error back to JavaScript.
|
||||||
if (id != "global") {
|
*
|
||||||
mCtx.sendJavascript("navigator._geo.fail(" + id + ");");
|
* @param code The error code
|
||||||
} else {
|
* @param msg The error message
|
||||||
mCtx.sendJavascript("navigator._geo.fail();");
|
*/
|
||||||
}
|
void fail(int code, String msg) {
|
||||||
|
this.ctx.sendJavascript("navigator._geo.fail('" + this.id + "', " + ", " + code + ", '" + msg + "');");
|
||||||
|
this.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start retrieving location.
|
||||||
|
*
|
||||||
|
* @param interval
|
||||||
|
*/
|
||||||
void start(int interval) {
|
void start(int interval) {
|
||||||
if (mGps != null) {
|
if (this.mGps != null) {
|
||||||
mGps.start(interval);
|
this.mGps.start(interval);
|
||||||
}
|
}
|
||||||
if (mNetwork != null) {
|
if (this.mNetwork != null) {
|
||||||
mNetwork.start(interval);
|
this.mNetwork.start(interval);
|
||||||
}
|
}
|
||||||
if (mNetwork == null && mGps == null) {
|
if (this.mNetwork == null && this.mGps == null) {
|
||||||
// Really, how were you going to get the location???
|
this.fail(POSITION_UNAVAILABLE, "No location providers available.");
|
||||||
mCtx.sendJavascript("navigator._geo.fail();");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This stops the listener
|
/**
|
||||||
|
* Stop listening for location.
|
||||||
|
*/
|
||||||
void stop() {
|
void stop() {
|
||||||
if (mGps != null) {
|
if (this.mGps != null) {
|
||||||
mGps.stop();
|
this.mGps.stop();
|
||||||
}
|
}
|
||||||
if (mNetwork != null) {
|
if (this.mNetwork != null) {
|
||||||
mNetwork.stop();
|
this.mNetwork.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
149
framework/src/com/phonegap/GpsListener.java
Normal file → Executable file
149
framework/src/com/phonegap/GpsListener.java
Normal file → Executable file
@ -26,81 +26,138 @@ import android.location.Location;
|
|||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.location.LocationListener;
|
import android.location.LocationListener;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class handles requests for GPS location services.
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class GpsListener implements LocationListener {
|
public class GpsListener implements LocationListener {
|
||||||
|
|
||||||
private Context mCtx;
|
private DroidGap mCtx; // DroidGap object
|
||||||
private Location cLoc;
|
|
||||||
private LocationManager mLocMan;
|
|
||||||
private static final String LOG_TAG = "PhoneGap";
|
|
||||||
private GeoListener owner;
|
|
||||||
private boolean hasData = false;
|
|
||||||
|
|
||||||
public GpsListener(Context ctx, int interval, GeoListener m)
|
private LocationManager mLocMan; // Location manager object
|
||||||
{
|
private GeoListener owner; // Geolistener object (parent)
|
||||||
owner = m;
|
private boolean hasData = false; // Flag indicates if location data is available in cLoc
|
||||||
mCtx = ctx;
|
private Location cLoc; // Last recieved location
|
||||||
|
private boolean running = false; // Flag indicates if listener is running
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
* Automatically starts listening.
|
||||||
|
*
|
||||||
|
* @param ctx
|
||||||
|
* @param interval
|
||||||
|
* @param m
|
||||||
|
*/
|
||||||
|
public GpsListener(DroidGap ctx, int interval, GeoListener m) {
|
||||||
|
this.owner = m;
|
||||||
|
this.mCtx = ctx;
|
||||||
|
this.mLocMan = (LocationManager) this.mCtx.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
this.running = false;
|
||||||
this.start(interval);
|
this.start(interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getLocation()
|
/**
|
||||||
{
|
* Get last location.
|
||||||
cLoc = mLocMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
*
|
||||||
hasData = true;
|
* @return Location object
|
||||||
return cLoc;
|
*/
|
||||||
|
public Location getLocation() {
|
||||||
|
this.cLoc = this.mLocMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
||||||
|
if (this.cLoc != null) {
|
||||||
|
this.hasData = true;
|
||||||
|
}
|
||||||
|
return this.cLoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the provider is disabled by the user.
|
||||||
|
*
|
||||||
|
* @param provider
|
||||||
|
*/
|
||||||
public void onProviderDisabled(String provider) {
|
public void onProviderDisabled(String provider) {
|
||||||
// TODO Auto-generated method stub
|
this.owner.fail(GeoListener.POSITION_UNAVAILABLE, "GPS provider disabled.");
|
||||||
Log.d(LOG_TAG, "The provider " + provider + " is disabled");
|
|
||||||
owner.fail();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the provider is enabled by the user.
|
||||||
|
*
|
||||||
|
* @param provider
|
||||||
|
*/
|
||||||
public void onProviderEnabled(String provider) {
|
public void onProviderEnabled(String provider) {
|
||||||
// TODO Auto-generated method stub
|
System.out.println("GpsListener: The provider "+ provider + " is enabled");
|
||||||
Log.d(LOG_TAG, "The provider "+ provider + " is enabled");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the provider status changes. This method is called when a
|
||||||
|
* provider is unable to fetch a location or if the provider has recently
|
||||||
|
* become available after a period of unavailability.
|
||||||
|
*
|
||||||
|
* @param provider
|
||||||
|
* @param status
|
||||||
|
* @param extras
|
||||||
|
*/
|
||||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||||
// TODO Auto-generated method stub
|
System.out.println("GpsListener: The status of the provider " + provider + " has changed");
|
||||||
Log.d(LOG_TAG, "The status of the provider " + provider + " has changed");
|
if (status == 0) {
|
||||||
if(status == 0)
|
System.out.println("GpsListener: " + provider + " is OUT OF SERVICE");
|
||||||
{
|
this.owner.fail(GeoListener.POSITION_UNAVAILABLE, "GPS out of service.");
|
||||||
Log.d(LOG_TAG, provider + " is OUT OF SERVICE");
|
|
||||||
owner.fail();
|
|
||||||
}
|
}
|
||||||
else if(status == 1)
|
else if (status == 1) {
|
||||||
{
|
System.out.println("GpsListener: " + provider + " is TEMPORARILY_UNAVAILABLE");
|
||||||
Log.d(LOG_TAG, provider + " is TEMPORARILY_UNAVAILABLE");
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
System.out.println("GpsListener: " + provider + " is Available");
|
||||||
Log.d(LOG_TAG, provider + " is Available");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the location has changed.
|
||||||
|
*
|
||||||
|
* @param location
|
||||||
|
*/
|
||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
Log.d(LOG_TAG, "The location has been updated!");
|
System.out.println("GpsListener: The location has been updated!");
|
||||||
owner.success(location);
|
this.hasData = true;
|
||||||
|
this.cLoc = location;
|
||||||
|
this.owner.success(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if location data is available.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public boolean hasLocation() {
|
public boolean hasLocation() {
|
||||||
return hasData;
|
return this.hasData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(int interval)
|
/**
|
||||||
{
|
* Start requesting location updates.
|
||||||
mLocMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
|
*
|
||||||
mLocMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, interval, 0, this);
|
* @param interval
|
||||||
cLoc = mLocMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
*/
|
||||||
|
public void start(int interval) {
|
||||||
|
if (!this.running) {
|
||||||
|
this.running = true;
|
||||||
|
this.mLocMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, interval, 0, this);
|
||||||
|
this.getLocation();
|
||||||
|
|
||||||
|
// If GPS provider has data, then send now
|
||||||
|
if (this.hasData) {
|
||||||
|
this.owner.success(this.cLoc);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop()
|
/**
|
||||||
{
|
* Stop receiving location updates.
|
||||||
mLocMan.removeUpdates(this);
|
*/
|
||||||
|
public void stop() {
|
||||||
|
if (this.running) {
|
||||||
|
this.mLocMan.removeUpdates(this);
|
||||||
|
}
|
||||||
|
this.running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
145
framework/src/com/phonegap/NetworkListener.java
Normal file → Executable file
145
framework/src/com/phonegap/NetworkListener.java
Normal file → Executable file
@ -26,82 +26,129 @@ import android.location.Location;
|
|||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.location.LocationListener;
|
import android.location.LocationListener;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
public class NetworkListener implements LocationListener {
|
public class NetworkListener implements LocationListener {
|
||||||
|
|
||||||
private Context mCtx;
|
|
||||||
private Location cLoc;
|
|
||||||
private LocationManager mLocMan;
|
|
||||||
private static final String LOG_TAG = "PhoneGap";
|
|
||||||
GeoListener owner;
|
|
||||||
|
|
||||||
public NetworkListener(Context ctx, int interval, GeoListener m)
|
private DroidGap mCtx; // DroidGap object
|
||||||
{
|
|
||||||
owner = m;
|
private LocationManager mLocMan; // Location manager object
|
||||||
mCtx = ctx;
|
private GeoListener owner; // Geolistener object (parent)
|
||||||
|
private boolean hasData = false; // Flag indicates if location data is available in cLoc
|
||||||
|
private Location cLoc; // Last recieved location
|
||||||
|
private boolean running = false; // Flag indicates if listener is running
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
* Automatically starts listening.
|
||||||
|
*
|
||||||
|
* @param ctx
|
||||||
|
* @param interval
|
||||||
|
* @param m
|
||||||
|
*/
|
||||||
|
public NetworkListener(DroidGap ctx, int interval, GeoListener m) {
|
||||||
|
this.owner = m;
|
||||||
|
this.mCtx = ctx;
|
||||||
|
this.mLocMan = (LocationManager) this.mCtx.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
this.running = false;
|
||||||
this.start(interval);
|
this.start(interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getLocation()
|
/**
|
||||||
{
|
* Get last location.
|
||||||
cLoc = mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
|
*
|
||||||
return cLoc;
|
* @return Location object
|
||||||
|
*/
|
||||||
|
public Location getLocation() {
|
||||||
|
this.cLoc = this.mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
|
||||||
|
if (this.cLoc != null) {
|
||||||
|
this.hasData = true;
|
||||||
|
}
|
||||||
|
return this.cLoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the provider is disabled by the user.
|
||||||
|
*
|
||||||
|
* @param provider
|
||||||
|
*/
|
||||||
public void onProviderDisabled(String provider) {
|
public void onProviderDisabled(String provider) {
|
||||||
// TODO Auto-generated method stub
|
System.out.println("NetworkListener: The provider " + provider + " is disabled");
|
||||||
Log.d(LOG_TAG, "The provider " + provider + " is disabled");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the provider is enabled by the user.
|
||||||
|
*
|
||||||
|
* @param provider
|
||||||
|
*/
|
||||||
public void onProviderEnabled(String provider) {
|
public void onProviderEnabled(String provider) {
|
||||||
// TODO Auto-generated method stub
|
System.out.println("NetworkListener: The provider "+ provider + " is enabled");
|
||||||
Log.d(LOG_TAG, "The provider "+ provider + " is enabled");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the provider status changes. This method is called when a
|
||||||
|
* provider is unable to fetch a location or if the provider has recently
|
||||||
|
* become available after a period of unavailability.
|
||||||
|
*
|
||||||
|
* @param provider
|
||||||
|
* @param status
|
||||||
|
* @param extras
|
||||||
|
*/
|
||||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||||
// TODO Auto-generated method stub
|
System.out.println("NetworkListener: The status of the provider " + provider + " has changed");
|
||||||
Log.d(LOG_TAG, "The status of the provider " + provider + " has changed");
|
if (status == 0) {
|
||||||
if(status == 0)
|
System.out.println("NetworkListener: " + provider + " is OUT OF SERVICE");
|
||||||
{
|
|
||||||
Log.d(LOG_TAG, provider + " is OUT OF SERVICE");
|
|
||||||
}
|
}
|
||||||
else if(status == 1)
|
else if (status == 1) {
|
||||||
{
|
System.out.println("NetworkListener: " + provider + " is TEMPORARILY_UNAVAILABLE");
|
||||||
Log.d(LOG_TAG, provider + " is TEMPORARILY_UNAVAILABLE");
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
System.out.println("NetworkListener: " + provider + " is Available");
|
||||||
Log.d(LOG_TAG, provider + " is Available");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/*
|
* Called when the location has changed.
|
||||||
* The GPS is the primary form of Geolocation in PhoneGap. Only fire the success variables if the GPS is down
|
*
|
||||||
* for some reason
|
* @param location
|
||||||
*/
|
*/
|
||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
Log.d(LOG_TAG, "The location has been updated!");
|
System.out.println("NetworkListener: The location has been updated!");
|
||||||
if (!owner.mGps.hasLocation())
|
this.hasData = true;
|
||||||
{
|
this.cLoc = location;
|
||||||
owner.success(location);
|
|
||||||
|
// The GPS is the primary form of Geolocation in PhoneGap.
|
||||||
|
// Only fire the success variables if the GPS is down for some reason.
|
||||||
|
if (!this.owner.mGps.hasLocation()) {
|
||||||
|
this.owner.success(location);
|
||||||
}
|
}
|
||||||
cLoc = location;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(int interval)
|
/**
|
||||||
{
|
* Start requesting location updates.
|
||||||
mLocMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
|
*
|
||||||
mLocMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, interval, 0, this);
|
* @param interval
|
||||||
cLoc = mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
|
*/
|
||||||
|
public void start(int interval) {
|
||||||
|
if (!this.running) {
|
||||||
|
this.running = true;
|
||||||
|
this.mLocMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, interval, 0, this);
|
||||||
|
this.getLocation();
|
||||||
|
|
||||||
|
// If Network provider has data but GPS provider doesn't, then send ours
|
||||||
|
if (this.hasData && !this.owner.mGps.hasLocation()) {
|
||||||
|
this.owner.success(this.cLoc);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop()
|
/**
|
||||||
{
|
* Stop receiving location updates.
|
||||||
mLocMan.removeUpdates(this);
|
*/
|
||||||
|
public void stop() {
|
||||||
|
if (this.running) {
|
||||||
|
this.mLocMan.removeUpdates(this);
|
||||||
|
}
|
||||||
|
this.running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,11 @@ import android.net.*;
|
|||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
public class NetworkManager implements Plugin {
|
public class NetworkManager implements Plugin {
|
||||||
|
|
||||||
|
public static int NOT_REACHABLE = 0;
|
||||||
|
public static int REACHABLE_VIA_CARRIER_DATA_NETWORK = 1;
|
||||||
|
public static int REACHABLE_VIA_WIFI_NETWORK = 2;
|
||||||
|
|
||||||
|
|
||||||
WebView webView; // WebView object
|
WebView webView; // WebView object
|
||||||
DroidGap ctx; // DroidGap object
|
DroidGap ctx; // DroidGap object
|
||||||
@ -67,8 +72,8 @@ public class NetworkManager implements Plugin {
|
|||||||
return new PluginResult(status, b);
|
return new PluginResult(status, b);
|
||||||
}
|
}
|
||||||
else if (action.equals("isReachable")) {
|
else if (action.equals("isReachable")) {
|
||||||
boolean b = this.isReachable(args.getString(0));
|
int i = this.isReachable(args.getString(0), args.getBoolean(1));
|
||||||
return new PluginResult(status, b);
|
return new PluginResult(status, i);
|
||||||
}
|
}
|
||||||
return new PluginResult(status, result);
|
return new PluginResult(status, result);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
@ -122,6 +127,11 @@ public class NetworkManager implements Plugin {
|
|||||||
// LOCAL METHODS
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a network connection exists.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
NetworkInfo info = sockMan.getActiveNetworkInfo();
|
NetworkInfo info = sockMan.getActiveNetworkInfo();
|
||||||
boolean conn = false;
|
boolean conn = false;
|
||||||
@ -131,6 +141,11 @@ public class NetworkManager implements Plugin {
|
|||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a WIFI connection exists.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public boolean isWifiActive() {
|
public boolean isWifiActive() {
|
||||||
NetworkInfo info = sockMan.getActiveNetworkInfo();
|
NetworkInfo info = sockMan.getActiveNetworkInfo();
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
@ -140,18 +155,37 @@ public class NetworkManager implements Plugin {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isReachable(String uri) {
|
/**
|
||||||
|
* Determine if a URI is reachable over the network.
|
||||||
|
*
|
||||||
|
* @param uri
|
||||||
|
* @param isIpAddress
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int isReachable(String uri, boolean isIpAddress) {
|
||||||
|
int reachable = NOT_REACHABLE;
|
||||||
|
|
||||||
if (uri.indexOf("http://") == -1) {
|
if (uri.indexOf("http://") == -1) {
|
||||||
uri = "http://" + uri;
|
uri = "http://" + uri;
|
||||||
}
|
}
|
||||||
boolean reached = isAvailable();
|
|
||||||
try {
|
if (isAvailable()) {
|
||||||
DefaultHttpClient httpclient = new DefaultHttpClient();
|
try {
|
||||||
HttpGet httpget = new HttpGet(uri);
|
DefaultHttpClient httpclient = new DefaultHttpClient();
|
||||||
httpclient.execute(httpget);
|
HttpGet httpget = new HttpGet(uri);
|
||||||
} catch (Exception e) {
|
httpclient.execute(httpget);
|
||||||
reached = false;
|
|
||||||
|
if (isWifiActive()) {
|
||||||
|
reachable = REACHABLE_VIA_WIFI_NETWORK;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reachable = REACHABLE_VIA_CARRIER_DATA_NETWORK;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
reachable = NOT_REACHABLE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return reached;
|
|
||||||
|
return reachable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,8 @@ public class PluginResult {
|
|||||||
"Malformed url",
|
"Malformed url",
|
||||||
"IO error",
|
"IO error",
|
||||||
"Invalid action",
|
"Invalid action",
|
||||||
"JSON error"
|
"JSON error",
|
||||||
|
"Error"
|
||||||
};
|
};
|
||||||
|
|
||||||
public enum Status {
|
public enum Status {
|
||||||
@ -74,6 +75,7 @@ public class PluginResult {
|
|||||||
MALFORMED_URL_EXCEPTION,
|
MALFORMED_URL_EXCEPTION,
|
||||||
IO_EXCEPTION,
|
IO_EXCEPTION,
|
||||||
INVALID_ACTION,
|
INVALID_ACTION,
|
||||||
JSON_EXCEPTION
|
JSON_EXCEPTION,
|
||||||
|
ERROR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user