diff --git a/Definitions/phonegap-2.2.d.ts b/Definitions/phonegap-2.2.d.ts
index 8b2e30791..46997cfea 100644
--- a/Definitions/phonegap-2.2.d.ts
+++ b/Definitions/phonegap-2.2.d.ts
@@ -22,11 +22,11 @@ interface Accelerometer {
}
interface CameraPopoverOptions {
- x: number;
- y: number;
- width: number;
- height: number;
- arrowDir: number;
+ x?: number;
+ y?: number;
+ width?: number;
+ height?: number;
+ arrowDir?: number;
}
interface CameraOptions {
@@ -49,9 +49,9 @@ interface Camera {
}
interface CaptureAudioOptions {
- limit: number;
- duration: number;
- mode: number;
+ limit?: number;
+ duration?: number;
+ mode?: number;
}
interface MediaFile {
@@ -64,6 +64,11 @@ interface MediaFile {
getFormatData(successCallback: Function, errorCallback?: Function): void;
}
+interface CaptureError {
+ code: number;
+ message: string;
+}
+
interface Capture {
captureAudio(captureSuccess: (mediaFiles: MediaFile[]) => void , captureError: (error: CaptureError) =>void , options?: CaptureAudioOptions);
}
@@ -168,12 +173,147 @@ interface Device {
}
interface File {
+ name: string;
+ fullPath: string;
+ type: string;
+ lastModifiedDate: Date;
+ size: number;
+}
+
+interface FileReader {
+ readyState: One of the three states the reader can be in EMPTY, LOADING or DONE.
+ result: string;
+ error: FileError;
+
+ onloadstart: Function;
+ onprogress: Function;
+ onload: Function;
+ onabort: Function;
+ onerror: Function;
+ onloadend: Function;
+
+ abort(): void;
+ readAsDataURL();
+ readAsText();
+}
+
+interface FileWriter {
+ readyState: One of the three states the reader can be in INIT, WRITING or DONE.
+ fileName: string;
+ length: number;
+ position: number;
+ error: FileError;
+
+ onwritestart: Function;
+ onprogress: Function;
+ onwrite: Function;
+ onabort: Function;
+ onerror: Function;
+ onwriteend: Function;
+
+ abort();
+ seek();
+ truncate();
+ write();
+}
+
+interface FileSystem {
+ name: string;
+ root: DirectoryEntry;
+}
+
+interface FileEntry {
+ isFile: bool;
+ isDirectory: bool;
+ name: string;
+ fullPath: string;
+ //filesystem: FileSystem
+
+ getMetadata();
+ setMetadata();
+ moveTo();
+ copyTo();
+ toURL();
+ remove();
+ getParent();
+ createWriter();
+ file();
+}
+
+interface DirectoryEntry {
+ isFile: bool;
+ isDirectory: bool;
+ name: string;
+ fullPath: string;
+
+ filesystem: FileSystem;
+
+ getMetadata();
+ setMetadata();
+ moveTo();
+ copyTo();
+ toURL();
+ remove();
+ getParent();
+ createReader();
+ getDirectory();
+ getFile();
+ removeRecursively();
+}
+
+interface DirectoryReader {
+ readEntries(successCallback: (entries: FileDirectoryEntry) => void , errorCallback: (error: FileError) => void );
+}
+
+interface FileTransfer {
+ onprogress: Function;
+
+ upload(filePath: string; server: string; successCallback: (metadata: Metadata) =>void; errorCallback: (error: FileError) =>void; options: SomeOptions): void;
+ download(source: string; target: string; successCallback (fileEntry: FileEntry) => void; errorCallback: (error: FileError) => void ): void;
+ abort(): void;
+}
+
+interface FileUploadOptions {
+ fileKey?: string;
+ fileName?: string;
+ mimeType?: string;
+ params?: any;
+ chunkedMode?: bool;
+ headers?: any;
+}
+
+interface FileUploadResult {
+ bytesSent: number;
+ responseCode: number;
+ response: string;
+}
+
+// TODO Flags
+
+interface LocalFileSystem {
+ requestFileSystem: Function;
+ resolveLocalFileSystemURI: Function;
+}
+
+interface Metadata {
+ modificationTime: Date;
+}
+
+interface FileError {
+ code: number;
+}
+
+interface FileTransferError {
+ code: number;
+ source: string;
+ target: string;
+ http_status: number;
}
interface GeolocationOptions {
- enableHighAccuracy: bool;
- timeout: number;
- maximumAge: number;
+ enableHighAccuracy?: bool;
+ timeout?: number;
+ maximumAge?: number;
}
interface Geolocation {
diff --git a/Tests/phonegap-tests.ts b/Tests/phonegap-tests.ts
index 3e5fdd397..212bb6536 100644
--- a/Tests/phonegap-tests.ts
+++ b/Tests/phonegap-tests.ts
@@ -412,4 +412,324 @@ function test_file() {
function fail(evt) {
console.log(evt.target.error.code);
}
+
+ var onSetMetadataWin = function () {
+ console.log("success setting metadata")
+ }
+ var onSetMetadataFail = function () {
+ console.log("error setting metadata")
+ }
+ var onGetFileWin = function (parent) {
+ var data = {};
+ data[metadataKey] = metadataValue;
+ parent.setMetadata(onSetMetadataWin, onSetMetadataFail, data);
+ }
+ var onGetFileFail = function () {
+ console.log("error getting file")
+ }
+ var onFSWin = function (fileSystem) {
+ fileSystem.root.getFile(filePath, { create: true, exclusive: false }, onGetFileWin, onGetFileFail);
+ }
+ var onFSFail = function (evt) {
+ console.log(evt.target.error.code);
+ }
+ window.requestFileSystem(localFileSystem, 0, onFSWin, onFSFail);
+
+ var entry: FileEntry;
+ var parent = document.getElementById('parent').value,
+ parentName = parent.substring(parent.lastIndexOf('/') + 1),
+ parentEntry = new DirectoryEntry(parentName, parent);
+ entry.moveTo(parentEntry, "newFile.txt", success, fail);
+ entry.remove(success, fail);
+ entry.getParent(success, fail);
+ entry.createWriter(success, fail);
+ entry.file(success, fail);
+ entry.getMetadata(success, fail);
+ entry.setMetadata(success, fail, { "com.apple.MobileBackup": 1 });
+
+ function win(r) {
+ console.log("Code = " + r.responseCode);
+ console.log("Response = " + r.response);
+ console.log("Sent = " + r.bytesSent);
+ }
+ function fail(error) {
+ alert("An error has occurred: Code = " + error.code);
+ console.log("upload error source " + error.source);
+ console.log("upload error target " + error.target);
+ }
+ var uri = encodeURI("http://some.server.com/upload.php");
+ var options = new FileUploadOptions();
+ options.fileKey = "file";
+ options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);
+ options.mimeType = "text/plain";
+ var params = {};
+ params.headers = { 'headerParam': 'headerValue' };
+ options.params = params;
+ var ft = new FileTransfer();
+ ft.upload(fileURI, uri, win, fail, options);
+}
+
+function test_geolocation() {
+ var onSuccess = function (position) {
+ alert('Latitude: ' + position.coords.latitude + '\n' +
+ 'Longitude: ' + position.coords.longitude + '\n' +
+ 'Altitude: ' + position.coords.altitude + '\n' +
+ 'Accuracy: ' + position.coords.accuracy + '\n' +
+ 'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' +
+ 'Heading: ' + position.coords.heading + '\n' +
+ 'Speed: ' + position.coords.speed + '\n' +
+ 'Timestamp: ' + position.timestamp + '\n');
+ };
+ function onError(error: GeolocationError) {
+ alert('code: ' + error.code + '\n' +
+ 'message: ' + error.message + '\n');
+ }
+ navigator.geolocation.getCurrentPosition(onSuccess, onError);
+
+ function onSuccess(position) {
+ var element = document.getElementById('geolocation');
+ element.innerHTML = 'Latitude: ' + position.coords.latitude + '
' +
+ 'Longitude: ' + position.coords.longitude + '
' +
+ '