From 6a002cfbb3cdab2328d6d5c77d1a50c11fa2db9e Mon Sep 17 00:00:00 2001 From: Vladimir Kotikov Date: Mon, 1 Sep 2014 18:20:06 +0400 Subject: [PATCH] Updates definitions and tests according to 3.6.0 changes. --- cordova/.gitignore | 1 + cordova/cordova-tests.ts | 80 +++++++++++++++++--- cordova/cordova.d.ts | 27 +++++++ cordova/plugins/Camera.d.ts | 17 +++-- cordova/plugins/Contacts.d.ts | 13 +++- cordova/plugins/Dialogs.d.ts | 5 +- cordova/plugins/FileSystem.d.ts | 120 +++++++++++++++++++++++++----- cordova/plugins/FileTransfer.d.ts | 7 +- cordova/plugins/Vibration.d.ts | 13 ++++ 9 files changed, 245 insertions(+), 38 deletions(-) create mode 100644 cordova/.gitignore diff --git a/cordova/.gitignore b/cordova/.gitignore new file mode 100644 index 0000000000..3be8493bd7 --- /dev/null +++ b/cordova/.gitignore @@ -0,0 +1 @@ +cordova-tests.js \ No newline at end of file diff --git a/cordova/cordova-tests.ts b/cordova/cordova-tests.ts index 4cd95e694c..dfaa25cc3d 100644 --- a/cordova/cordova-tests.ts +++ b/cordova/cordova-tests.ts @@ -10,19 +10,33 @@ console.log('cordova.version: ' + cordova.version + ', cordova.platformId: ' + c cordova.exec(null, null, "NativeClassName", "MethodName"); -cordova.define('mymodule', (require, exports, module) => { }); +cordova.define('mymodule', (req, exp, mod)=> { + mod.exports = { dummy: () => { console.log("i'm a dummy"); }}; +}); + var myModule = cordova.require('mymodule'); +myModule.dummy(); var argsCheck: ArgsCheck = cordova.require('cordova/argcheck'); argsCheck.checkArgs('ssA', 'cordova.exec', [() => { }, () => { }, 'window', 'openDatabase']); +class Application { + start() { console.log("Starting app"); } + pause() { console.log('app paused'); } +} + +declare var app: Application; + +document.addEventListener('deviceready', () => { app.start(); }); +document.addEventListener('pause', ()=> { app.pause(); }); + // Battery status plugin //---------------------------------------------------------------------- window.addEventListener('batterystatus', (ev: BatteryStatusEvent) => { console.log('Battery level is ' + ev.level); }); window.addEventListener('batterycritical', - ()=> { alert('Battery is critical low!'); }); + () => { alert('Battery is critical low!'); }); // Camera plugin //---------------------------------------------------------------------- @@ -51,10 +65,12 @@ var contact: Contact = navigator.contacts.create({ navigator.contacts.find(["phoneNumbers"], (contacts: Contact[])=> { alert('Find ' + contacts.length + ' contacts'); }, (error: ContactError) => { alert('Error: ' + error.message); }, - { - filter: "+1", - multiple: true - } + new ContactFindOptions("+1", true) +); + +navigator.contacts.pickContact( + (contact: Contact)=> { console.log(contact); }, + (err: ContactError)=> { console.log(err.message); } ); // Device API @@ -105,26 +121,64 @@ function fsaccessor(fs: FileSystem) { var fsreader: DirectoryReader = fs.root.createReader(); fsreader.readEntries( (entries: Entry[]) => { console.log(fs.root.name + ' has ' + entries.length + ' child elements'); }, - (err: Error)=> { alert('Error: ' + err.message); }); + (err: FileError)=> { alert('Error: ' + err.code); }); } window.requestFileSystem( window.TEMPORARY, 1024 * 1024 * 5, fsaccessor, - (err: Error) => { alert('Error: ' + err.message); }); + (err: FileError) => { alert('Error: ' + err.code); } +); + +window.resolveLocalFileSystemURI(cordova.file.applicationDirectory, + (entry: Entry)=> { + if (entry.isDirectory) { + console.log('successfully resolved ' + entry.fullPath + 'directory'); + console.log(entry.toURL()); + console.log(entry.toInternalURL()); + } else { + var fentry = entry; + fentry.file((f: File) => { console.log(f.slice(f.size - 10, f.size)); }); + fentry.createWriter((writer: FileWriter)=> { + if (writer.readyState == FileWriter.INIT) { + console.log('Init FileWriter'); + writer.write(new Blob(['sdfdsfsdf'])); + writer.onprogress = function(ev: ProgressEvent) { + console.log('Writing ' + ev.target); + }; + } + }); + } + }, + (error: FileError) => { console.log(error.code); } +); // FileTransfer plugin //---------------------------------------------------------------------- var file = new FileTransfer(); + +file.onprogress = (ev: ProgressEvent) => { + if (ev.lengthComputable) { + console.log(ev.loaded + '/' + ev.total); + } +}; + file.download('http://some.server.com/download.php', 'cdvfile://localhost/persistent/path/to/downloads/', (file: FileEntry)=> { console.log('File Downloaded to ' + file.fullPath); }, - (err: FileTransferError)=> { alert('Error ' + err.code); }, + (err: FileTransferError) => { + console.error('Error ' + err.code); + if (err.exception) { + console.error('Failed with exception ' + err.exception); + } + }, { headers: null }, true); +file.abort(); + // InAppBrowser plugin //---------------------------------------------------------------------- @@ -135,6 +189,10 @@ file.download('http://some.server.com/download.php', var iab = window.open('google.com', '_self'); iab.addEventListener('loadstart', (ev: InAppBrowserEvent) => { console.log('Start opening ' + ev.url); }); iab.show(); +iab.executeScript( + { code: "console.log('Injected script in action')" }, + ()=> { console.log('Script is executed'); } +); // Globalization plugin //---------------------------------------------------------------------- @@ -226,4 +284,6 @@ db.transaction( // Vibration plugin //---------------------------------------------------------------------- -navigator.notification.vibrate(100); \ No newline at end of file +navigator.notification.vibrate(100); +navigator.notification.vibrateWithPattern([100, 200, 200, 150, 50], 3); +setTimeout(navigator.notification.cancelVibration, 1000); \ No newline at end of file diff --git a/cordova/cordova.d.ts b/cordova/cordova.d.ts index 9377912b00..06d13e8cfd 100644 --- a/cordova/cordova.d.ts +++ b/cordova/cordova.d.ts @@ -44,6 +44,33 @@ interface Cordova { require(moduleName: string): any; } +interface Document { + addEventListener(type: "deviceready", listener: (ev: Event) => any, useCapture?: boolean): void; + addEventListener(type: "pause", listener: (ev: Event) => any, useCapture?: boolean): void; + addEventListener(type: "resume", listener: (ev: Event) => any, useCapture?: boolean): void; + addEventListener(type: "backbutton", listener: (ev: Event) => any, useCapture?: boolean): void; + addEventListener(type: "menubutton", listener: (ev: Event) => any, useCapture?: boolean): void; + addEventListener(type: "searchbutton", listener: (ev: Event) => any, useCapture?: boolean): void; + addEventListener(type: "startcallbutton", listener: (ev: Event) => any, useCapture?: boolean): void; + addEventListener(type: "endcallbutton", listener: (ev: Event) => any, useCapture?: boolean): void; + addEventListener(type: "volumedownbutton", listener: (ev: Event) => any, useCapture?: boolean): void; + addEventListener(type: "volumeupbutton", listener: (ev: Event) => any, useCapture?: boolean): void; + + removeEventListener(type: "deviceready", listener: (ev: Event) => any, useCapture?: boolean): void; + removeEventListener(type: "pause", listener: (ev: Event) => any, useCapture?: boolean): void; + removeEventListener(type: "resume", listener: (ev: Event) => any, useCapture?: boolean): void; + removeEventListener(type: "backbutton", listener: (ev: Event) => any, useCapture?: boolean): void; + removeEventListener(type: "menubutton", listener: (ev: Event) => any, useCapture?: boolean): void; + removeEventListener(type: "searchbutton", listener: (ev: Event) => any, useCapture?: boolean): void; + removeEventListener(type: "startcallbutton", listener: (ev: Event) => any, useCapture?: boolean): void; + removeEventListener(type: "endcallbutton", listener: (ev: Event) => any, useCapture?: boolean): void; + removeEventListener(type: "volumedownbutton", listener: (ev: Event) => any, useCapture?: boolean): void; + removeEventListener(type: "volumeupbutton", listener: (ev: Event) => any, useCapture?: boolean): void; + + addEventListener(type: string, listener: (ev: Event) => any, useCapture?: boolean): void; + removeEventListener(type: string, listener: (ev: Event) => any, useCapture?: boolean): void; +} + // cordova/argscheck module interface ArgsCheck { checkArgs(argsSpec: string, functionName: string, args: any[], callee?: any): void; diff --git a/cordova/plugins/Camera.d.ts b/cordova/plugins/Camera.d.ts index eb0c971475..126b329ff6 100644 --- a/cordova/plugins/Camera.d.ts +++ b/cordova/plugins/Camera.d.ts @@ -44,11 +44,11 @@ interface Camera { } interface CameraOptions { - /** Picture quality in range o-100 */ + /** Picture quality in range 0-100. Default is 50 */ quality?: number; /** * Choose the format of the return value. - * Defined in navigator.camera.DestinationType + * Defined in navigator.camera.DestinationType. Default is FILE_URI. * DATA_URL : 0, Return image as base64-encoded string * FILE_URI : 1, Return image file URI * NATIVE_URI : 2 Return image native URI @@ -56,7 +56,8 @@ interface CameraOptions { */ destinationType?: number; /** - * Set the source of the picture. Defined in navigator.camera.PictureSourceType + * Set the source of the picture. + * Defined in navigator.camera.PictureSourceType. Default is CAMERA. * PHOTOLIBRARY : 0, * CAMERA : 1, * SAVEDPHOTOALBUM : 2 @@ -65,7 +66,8 @@ interface CameraOptions { /** Allow simple editing of image before selection. */ allowEdit?: boolean; /** - * Choose the returned image file's encoding. Defined in navigator.camera.EncodingType + * Choose the returned image file's encoding. + * Defined in navigator.camera.EncodingType. Default is JPEG * JPEG : 0 Return JPEG encoded image * PNG : 1 Return PNG encoded image */ @@ -93,7 +95,12 @@ interface CameraOptions { correctOrientation?: boolean; /** Save the image to the photo album on the device after capture. */ saveToPhotoAlbum?: boolean; - /** Choose the camera to use (front- or back-facing). Defined in navigator.camera.Direction */ + /** + * Choose the camera to use (front- or back-facing). + * Defined in navigator.camera.Direction. Default is BACK. + * FRONT: 0 + * BACK: 1 + */ cameraDirection?: number; /** iOS-only options that specify popover location in iPad. Defined in CameraPopoverOptions. */ popoverOptions?: CameraPopoverOptions; diff --git a/cordova/plugins/Contacts.d.ts b/cordova/plugins/Contacts.d.ts index f054c12d09..29a9a596cf 100644 --- a/cordova/plugins/Contacts.d.ts +++ b/cordova/plugins/Contacts.d.ts @@ -34,6 +34,14 @@ interface Contacts { onSuccess: (contacts: Contact[]) => void, onError: (error: ContactError) => void, options?: ContactFindOptions): void; + /** + * The navigator.contacts.pickContact method launches the Contact Picker to select a single contact. + * The resulting object is passed to the contactSuccess callback function specified by the contactSuccess parameter. + * @param onSuccess Success callback function invoked with the array of Contact objects returned from the database + * @param onError Error callback function, invoked when an error occurs. + */ + pickContact(onSuccess: (contact: Contact) => void, + onError: (error: ContactError) => void): void } interface ContactProperties { @@ -253,10 +261,13 @@ interface ContactFindOptions { filter?: string; /** Determines if the find operation returns multiple navigator.contacts. */ multiple?: boolean; + /* Contact fields to be returned back. If specified, the resulting Contact object only features values for these fields. */ + desiredFields?: string[]; } declare var ContactFindOptions: { /** Constructor for ContactFindOptions object */ new(filter?: string, - multiple?: boolean): ContactFindOptions + multiple?: boolean, + desiredFields?: string[]): ContactFindOptions }; \ No newline at end of file diff --git a/cordova/plugins/Dialogs.d.ts b/cordova/plugins/Dialogs.d.ts index 5e2a7416dc..6d86c6228e 100644 --- a/cordova/plugins/Dialogs.d.ts +++ b/cordova/plugins/Dialogs.d.ts @@ -59,7 +59,10 @@ interface Notification { /** Object, passed to promptCallback */ interface NotificationPromptResult { - /** The index of the pressed button. Note that the index uses one-based indexing, so the value is 1, 2, 3, etc. */ + /** + * The index of the pressed button. Note that the index uses one-based indexing, so the value is 1, 2, 3, etc. + * 0 is the result when the dialog is dismissed without a button press. + */ buttonIndex: number; /** The text entered in the prompt dialog box. */ input1: string; diff --git a/cordova/plugins/FileSystem.d.ts b/cordova/plugins/FileSystem.d.ts index 569f9a2096..1e1476b398 100644 --- a/cordova/plugins/FileSystem.d.ts +++ b/cordova/plugins/FileSystem.d.ts @@ -18,7 +18,16 @@ interface Window { type: number, size: number, successCallback: (fileSystem: FileSystem) => void, - errorCallback?: (fileError: Error) => void): void; + errorCallback?: (fileError: FileError) => void): void; + /** + * Look up file system Entry referred to by local URI. + * @param string uri URI referring to a local file or directory + * @param successCallback invoked with Entry object corresponding to URI + * @param errorCallback invoked if error occurs retrieving file system entry + */ + resolveLocalFileSystemURI(uri: string, + successCallback: (entry: Entry) => void, + errorCallback?: (error: FileError) => void): void; TEMPORARY: number; PERSISTENT: number; } @@ -54,7 +63,7 @@ interface Entry { */ getMetadata( successCallback: (metadata: Metadata) => void, - errorCallback?: (error: Error) => void): void; + errorCallback?: (error: FileError) => void): void; /** * Move an entry to a different location on the file system. It is an error to try to: * move a directory inside itself or to any child at any depth;move an entry into its parent if a name different from its current one isn't provided; @@ -69,9 +78,9 @@ interface Entry { * @param errorCallback A callback that is called when errors happen. */ moveTo(parent: DirectoryEntry, - newName?: string, - successCallback?: (entry: Entry) => void , - errorCallback?: (error: Error) => void ): void; + newName?: string, + successCallback?: (entry: Entry) => void, + errorCallback?: (error: FileError) => void): void; /** * Copy an entry to a different location on the file system. It is an error to try to: * copy a directory inside itself or to any child at any depth; @@ -88,24 +97,34 @@ interface Entry { * @param errorCallback A callback that is called when errors happen. */ copyTo(parent: DirectoryEntry, - newName?: string, - successCallback?: (entry: Entry) => void , - errorCallback?: (error: Error) => void ): void; + newName?: string, + successCallback?: (entry: Entry) => void, + errorCallback?: (error: FileError) => void): void; + /** + * Returns a URL that can be used as the src attribute of a