Skip to content

Commit

Permalink
merged joe
Browse files Browse the repository at this point in the history
  • Loading branch information
brianleroux committed Mar 16, 2010
2 parents 73c25aa + 57a41b7 commit b288fb7
Show file tree
Hide file tree
Showing 33 changed files with 238 additions and 2,638 deletions.
298 changes: 224 additions & 74 deletions example/phonegap.js
Expand Up @@ -436,6 +436,39 @@ Contacts.prototype.droidDone = function()
PhoneGap.addConstructor(function() {
if(typeof navigator.contacts == "undefined") navigator.contacts = new Contacts();
});
var Crypto = function()
{
}

Crypto.prototype.encrypt = function(seed, string, callback)
{
GapCrypto.encrypt(seed, string);
this.encryptWin = callback;
}

Crypto.prototype.decrypt = function(seed, string, callback)
{
GapCrypto.decrypt(seed, string);
this.decryptWin = callback;
}

Crypto.prototype.gotCryptedString = function(string)
{
this.encryptWin(string);
}

Crypto.prototype.getPlainString = function(string)
{
this.decryptWin(string);
}

PhoneGap.addConstructor(function() {
if (typeof navigator.Crypto == "undefined")
{
navigator.Crypto = new Crypto();
}
});

/**
* this represents the mobile device, and provides properties for inspecting the model, version, UUID of the
* phone, etc.
Expand Down Expand Up @@ -465,114 +498,231 @@ function Device() {
PhoneGap.addConstructor(function() {
navigator.device = window.device = new Device();
});



PhoneGap.addConstructor(function() { if (typeof navigator.fileMgr == "undefined") navigator.fileMgr = new FileMgr();});


/**
* This class provides generic read and write access to the mobile device file system.
* This class provides iPhone read and write access to the mobile device file system.
* Based loosely on http://www.w3.org/TR/2009/WD-FileAPI-20091117/#dfn-empty
*/
function File() {
/**
* The data of a file.
*/
this.data = "";
/**
* The name of the file.
*/
this.name = "";
function FileMgr()
{
this.fileWriters = {}; // empty maps
this.fileReaders = {};

this.docsFolderPath = "../../Documents";
this.tempFolderPath = "../../tmp";
this.freeDiskSpace = -1;
this.getFileBasePaths();
}

/**
* Reads a file from the mobile device. This function is asyncronous.
* @param {String} fileName The name (including the path) to the file on the mobile device.
* The file name will likely be device dependent.
* @param {Function} successCallback The function to call when the file is successfully read.
* @param {Function} errorCallback The function to call when there is an error reading the file from the device.
*/
File.prototype.read = function(fileName, successCallback, errorCallback) {

// private, called from Native Code
FileMgr.prototype._setPaths = function(docs,temp)
{
this.docsFolderPath = docs;
this.tempFolderPath = temp;
}

/**
* Writes a file to the mobile device.
* @param {File} file The file to write to the device.
*/
File.prototype.write = function(file) {

// private, called from Native Code
FileMgr.prototype._setFreeDiskSpace = function(val)
{
this.freeDiskSpace = val;
}

PhoneGap.addConstructor(function() {
if (typeof navigator.file == "undefined") navigator.file = new File();
});

File.prototype.read = function(fileName, successCallback, errorCallback) {
this.failCallback = errorCallback;
this.winCallback = successCallback;
// FileWriters add/remove
// called internally by writers
FileMgr.prototype.addFileWriter = function(filePath,fileWriter)
{
this.fileWriters[filePath] = fileWriter;
}

return FileUtil.read(fileName);
FileMgr.prototype.removeFileWriter = function(filePath)
{
this.fileWriters[filePath] = null;
}

File.prototype.hasRead = function(data)
// File readers add/remove
// called internally by readers
FileMgr.prototype.addFileReader = function(filePath,fileReader)
{
if(data.substr("FAIL"))
this.failCallback(data);
else
this.winCallback(data);
this.fileReaders[filePath] = fileReader;
}

/**
* Writes a file to the mobile device.
* @param {File} file The file to write to the device.
FileMgr.prototype.removeFileReader = function(filePath)
{
this.fileReaders[filePath] = null;
}

/*******************************************
*
* private reader callback delegation
* called from native code
*/
File.prototype.write = function(file, str, mode, successCallback, failCallback) {
this.winCallback = successCallback;
this.failCallback = failCallback;
var call = FileUtil.write(file, str, mode);
FileMgr.prototype.reader_onloadstart = function(filePath,result)
{
this.fileReaders[filePath].onloadstart(result);
}

File.prototype.testFileExists = function(file, successCallback, failCallback)
FileMgr.prototype.reader_onprogress = function(filePath,result)
{
var exists = FileUtil.testFileExists(file);
if(exists)
successCallback();
else
failCallback();
return exists;
this.fileReaders[filePath].onprogress(result);
}

File.prototype.testDirectoryExists = function(file, successCallback, failCallback)
FileMgr.prototype.reader_onload = function(filePath,result)
{
var exists = FileUtil.testDirectoryExists(file);
if(exists)
successCallback();
else
failCallback();
return exists;
this.fileReaders[filePath].result = unescape(result);
this.fileReaders[filePath].onload(this.fileReaders[filePath].result);
}

File.prototype.createDirectory = function(dir, successCallback, failCallback)
FileMgr.prototype.reader_onerror = function(filePath,err)
{
var good = FileUtils.createDirectory(dir);
good ? successCallback() : failCallback();
this.fileReaders[filePath].result = err;
this.fileReaders[filePath].onerror(err);
}

File.prototype.deleteDirectory = function(dir, successCallback, failCallback)
FileMgr.prototype.reader_onloadend = function(filePath,result)
{
var good = FileUtils.deleteDirectory(dir);
good ? successCallback() : failCallback();
this.fileReaders[filePath].onloadend(result);
}

File.prototype.deleteFile = function(dir, successCallback, failCallback)
/*******************************************
*
* private writer callback delegation
* called from native code
*/
FileMgr.prototype.writer_onerror = function(filePath,err)
{
var good = FileUtils.deleteFile(dir);
good ? successCallback() : failCallback();
this.fileWriters[filePath].onerror(err);
}

File.prototype.getFreeDiskSpace = function(successCallback, failCallback)
FileMgr.prototype.writer_oncomplete = function(filePath,result)
{
var diskSpace = FileUtils.getFreeDiskSpace();
if(diskSpace > 0)
successCallback();
else
failCallback();
return diskSpace;
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 = FileUtils.createDirectory(dirName);
test ? successCallback() : errorCallback();
}

FileMgr.prototype.deleteDirectory = function(dirName, successCallback, errorCallback)
{
this.successCallback = successCallback;
this.errorCallback = errorCallback;
var test = FileUtils.deleteDirectory(dirName);
test ? successCallback() : errorCallback();
}

FileMgr.prototype.deleteFile = function(fileName, successCallback, errorCallback)
{
this.successCallback = successCallback;
this.errorCallback = errorCallback;
FileUtils.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 = FileUtils.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(fileName);
}

// File Writer

function FileWriter()
{
this.fileName = "";
this.result = null;
this.readyState = 0; // EMPTY
this.result = null;
this.onerror = null;
this.oncomplete = null;
}

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;
}
/**
* This class provides access to device GPS data.
Expand Down
2 changes: 1 addition & 1 deletion framework/AndroidManifest.xml
Expand Up @@ -38,6 +38,6 @@
<action android:name="android.intent.action.PICK" />
</activity>
</application>
<uses-sdk android:minSdkVersion="5" />
<uses-sdk android:minSdkVersion="3" />

</manifest>
4 changes: 2 additions & 2 deletions framework/assets/js/geolocation.js
Expand Up @@ -109,7 +109,7 @@ Geolocation.prototype.watchPosition = function(successCallback, errorCallback, o
this.listeners = [];
}

var key = this.listeners.push( {"success" : successCallback, "fail" : failCallback }) - 1;
var key = this.listeners.push( {"success" : successCallback, "fail" : errorCallback }) - 1;

// TO-DO: Get the names of the method and pass them as strings to the Java.
return Geolocation.start(frequency, key);
Expand Down Expand Up @@ -147,4 +147,4 @@ PhoneGap.addConstructor(function() {
["setLocation", "getCurrentPosition", "watchPosition",
"clearWatch", "setError", "start", "stop", "gotCurrentPosition"]
);
});
});
6 changes: 3 additions & 3 deletions framework/default.properties
Expand Up @@ -7,8 +7,8 @@
# "build.properties", and override values to adapt the script to your
# project structure.

apk-configurations=
# Project target.
target=android-5
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-7
apk-configurations=

0 comments on commit b288fb7

Please sign in to comment.