diff --git a/ng-cordova/actionSheet-tests.ts b/ng-cordova/actionSheet-tests.ts new file mode 100644 index 000000000..07d105b54 --- /dev/null +++ b/ng-cordova/actionSheet-tests.ts @@ -0,0 +1,27 @@ +/// +/// + +module ngCordova { + 'use strict'; + + angular.module('test') + // Adapted from http://ngcordova.com/docs/plugins/actionSheet/ + .controller('ThisCtrl', function($cordovaActionSheet: ngCordova.IActionSheetService) { + + var options = { + title: 'What do you want with this image?', + buttonLabels: ['Share via Facebook', 'Share via Twitter'], + addCancelButtonWithLabel: 'Cancel', + androidEnableCancelButton: true, + winphoneEnableCancelButton: true, + addDestructiveButtonWithLabel: 'Delete it' + }; + + document.addEventListener("deviceready", function() { + $cordovaActionSheet.show(options) + .then(function(btnIndex) { + var index: number = btnIndex; + }); + }, false); + }); +} diff --git a/ng-cordova/actionSheet.d.ts b/ng-cordova/actionSheet.d.ts new file mode 100644 index 000000000..1809d7fb0 --- /dev/null +++ b/ng-cordova/actionSheet.d.ts @@ -0,0 +1,22 @@ +// Type definitions for ngCordova Action Sheet plugin +// Project: https://github.com/driftyco/ng-cordova +// Definitions by: Phil McCloghry-Laing +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module ngCordova { + export interface IActionSheetService { + show(options: ShowOptions): ng.IPromise; + hide(): ng.IPromise; + } + + export interface ShowOptions { + title?: string; + buttonLabels?: string[]; + addCancelButtonWithLabel?: string; + addDestructiveButtonWithLabel?: string; + androidEnableCancelButton?: boolean; + winphoneEnableCancelButton?: boolean; + } +} diff --git a/ng-cordova/badge-tests.ts b/ng-cordova/badge-tests.ts new file mode 100644 index 000000000..854f66b39 --- /dev/null +++ b/ng-cordova/badge-tests.ts @@ -0,0 +1,59 @@ +/// +/// + +module ngCordova { + 'use strict'; + + angular.module('test') + // Adapted from http://ngcordova.com/docs/plugins/badge/ + .controller('ThisCtrl', function($cordovaBadge: ngCordova.IBadgeService) { + + $cordovaBadge.hasPermission().then(function(yes) { + // You have permission + }, function(no) { + // You do not have permission + }); + + $cordovaBadge.set(3).then(function() { + // You have permission, badge set. + }, function(err) { + // You do not have permission. + }); + + $cordovaBadge.get().then(function(badge) { + // You have permission, badge returned. + var badgeNo: number = badge; + }, function(err) { + // You do not have permission. + }); + + $cordovaBadge.clear().then(function() { + // You have permission, badge cleared. + }, function(err) { + // You do not have permission. + }); + + $cordovaBadge.increase().then(function() { + // You have permission, badge increased. + }, function(err) { + // You do not have permission. + }); + $cordovaBadge.increase(3).then(function() { + // You have permission, badge increased. + }, function(err) { + // You do not have permission. + }); + + $cordovaBadge.decrease().then(function() { + // You have permission, badge increased. + }, function(err) { + // You do not have permission. + }); + $cordovaBadge.decrease(2).then(function() { + // You have permission, badge increased. + }, function(err) { + // You do not have permission. + }); + + }); +} diff --git a/ng-cordova/badge.d.ts b/ng-cordova/badge.d.ts new file mode 100644 index 000000000..b73b3182c --- /dev/null +++ b/ng-cordova/badge.d.ts @@ -0,0 +1,18 @@ +// Type definitions for ngCordova badge plugin +// Project: https://github.com/driftyco/ng-cordova +// Definitions by: Phil McCloghry-Laing +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module ngCordova { + export interface IBadgeService { + hasPermission(): ng.IPromise; + promptForPermission(): ng.IPromise; + set(badge: number, callback?: Function, scope?: {}): ng.IPromise; + get(): ng.IPromise; + clear(callback?: Function, scope?: {}): ng.IPromise; + increase(count?: number, callback?: Function, scope?: {}): ng.IPromise; + decrease(count?: number, callback?: Function, scope?: {}): ng.IPromise; + } +} diff --git a/ng-cordova/file-tests.ts b/ng-cordova/file-tests.ts new file mode 100644 index 000000000..6a4297394 --- /dev/null +++ b/ng-cordova/file-tests.ts @@ -0,0 +1,184 @@ +/// +/// +/// + +module ngCordova { + 'use strict'; + + + angular.module('test') + // Adapted from http://ngcordova.com/docs/plugins/file/ + .controller('MyCtrl', function($scope: ng.IScope, $cordovaFile: ngCordova.IFileService) { + + document.addEventListener('deviceready', function() { + + $cordovaFile.getFreeDiskSpace() + .then(function(success) { + // success in kilobytes + var freeSpace: number = success; + }, function(error) { + // error + }); + + + // CHECK + $cordovaFile.checkDir(cordova.file.dataDirectory, "dir/other_dir") + .then(function(success) { + // success + var dir: DirectoryEntry = success; + }, function(error) { + // error + }); + + + $cordovaFile.checkFile(cordova.file.dataDirectory, "some_file.txt") + .then(function(success) { + // success + var fileResult: FileEntry = success; + }, function(error) { + // error + }); + + + // CREATE + $cordovaFile.createDir(cordova.file.dataDirectory, "new_dir", false) + .then(function(success) { + // success + var dir: DirectoryEntry = success; + }, function(error) { + // error + }); + + $cordovaFile.createFile(cordova.file.dataDirectory, "new_file.txt", true) + .then(function(success) { + // success + var fileResult: FileEntry = success; + }, function(error) { + // error + }); + + + // REMOVE + $cordovaFile.removeDir(cordova.file.dataDirectory, "some_dir") + .then(function(success) { + // success + if (success.success) { + var dirResult: DirectoryEntry = success.fileRemoved; + } + }, function(error) { + // error + }); + + $cordovaFile.removeFile(cordova.file.dataDirectory, "some_file.txt") + .then(function(success) { + // success + if (success.success) { + var fileResult: FileEntry = success.fileRemoved; + } + }, function(error) { + // error + }); + + $cordovaFile.removeRecursively(cordova.file.dataDirectory, "") + .then(function(success) { + // success + if (success.success) { + var dirResult: DirectoryEntry = success.fileRemoved; + } + }, function(error) { + // error + }); + + + // WRITE + $cordovaFile.writeFile(cordova.file.dataDirectory, "file.txt", "text", true) + .then(function(success) { + // success + var endEvent: ProgressEvent = success; + }, function(error) { + // error + }); + + $cordovaFile.writeExistingFile(cordova.file.dataDirectory, "file.txt", "text") + .then(function(success) { + // success + var endEvent: ProgressEvent = success; + }, function(error) { + // error + }); + + + // READ + $cordovaFile.readAsText(cordova.file.dataDirectory, "file.txt") + .then(function(success) { + // success + var text: string = success; + }, function(error) { + // error + }); + + $cordovaFile.readAsDataURL(cordova.file.dataDirectory, "file.txt") + .then(function(success) { + // success + var text: string = success; + }, function(error) { + // error + }); + + $cordovaFile.readAsBinaryString(cordova.file.dataDirectory, "file.txt") + .then(function(success) { + // success + var text: string = success; + }, function(error) { + // error + }); + + $cordovaFile.readAsArrayBuffer(cordova.file.dataDirectory, "file.txt") + .then(function(success) { + // success + var buffer: ArrayBuffer = success; + }, function(error) { + // error + }); + + + // MOVE + $cordovaFile.moveDir(cordova.file.dataDirectory, "dir", cordova.file.tempDirectory, "new_dir") + .then(function(success) { + // success + var dirResult: DirectoryEntry = success; + }, function(error) { + // error + }); + + $cordovaFile.moveFile(cordova.file.dataDirectory, "file.txt", cordova.file.tempDirectory) + .then(function(success) { + // success + var fileResult: FileEntry = success; + }, function(error) { + // error + }); + + + // COPY + $cordovaFile.copyDir(cordova.file.dataDirectory, "dir", cordova.file.tempDirectory, "new_dir") + .then(function(success) { + // success + var dirResult: DirectoryEntry = success; + }, function(error) { + // error + }); + + $cordovaFile.copyFile(cordova.file.dataDirectory, "file.txt", cordova.file.tempDirectory, "new_file.txt") + .then(function(success) { + // success + var fileResult: FileEntry = success; + }, function(error) { + // error + }); + + + }); + + }); +} diff --git a/ng-cordova/file.d.ts b/ng-cordova/file.d.ts new file mode 100644 index 000000000..04f19080a --- /dev/null +++ b/ng-cordova/file.d.ts @@ -0,0 +1,51 @@ +// Type definitions for ngCordova file plugin +// Project: https://github.com/driftyco/ng-cordova +// Definitions by: Phil McCloghry-Laing +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/// + +declare module ngCordova { + export interface IFileService { + getFreeDiskSpace(): IFilePromise; + + checkDir(path: string, directory: string): IFilePromise; + checkFile(path: string, file: string): IFilePromise; + + createDir(path: string, directory: string, replace?: boolean): IFilePromise; + createFile(path: string, file: string, replace?: boolean): IFilePromise; + + removeDir(path: string, directory: string): IFilePromise>; + removeFile(path: string, file: string): IFilePromise>; + removeRecursively(path: string, directory: string): IFilePromise>; + + writeFile(path: string, file: string, text: string | Blob, replace?: boolean): IFilePromise; + writeExistingFile(path: string, file: string, text: string | Blob): IFilePromise; + + readAsText(path: string, file: string): ng.IPromise; + readAsDataURL(path: string, file: string): ng.IPromise; + readAsBinaryString(path: string, file: string): ng.IPromise; + readAsArrayBuffer(path: string, file: string): ng.IPromise; + + moveDir(path: string, directory: string, newPath: string, newDirectory?: string): IFilePromise; + moveFile(path: string, file: string, newPath: string, newFile?: string): IFilePromise; + + copyDir(path: string, directory: string, newPath: string, newDirectory?: string): IFilePromise; + copyFile(path: string, file: string, newPath: string, newFile?: string): IFilePromise; + } + + export interface IFilePromise extends ng.IPromise { + then(successCallback: (promiseValue: T) => ng.IPromise | TResult, errorCallback?: (error: IFileError) => ng.IPromise | TResult): ng.IPromise; + catch(onRejected: (error: IFileError) => ng.IPromise | TResult): ng.IPromise; + } + + export interface IFileRemoveResult { + success: boolean; + fileRemoved: TEntry; + } + + export interface IFileError extends FileError { + message: string; + } +} diff --git a/ng-cordova/fileTransfer-tests.ts b/ng-cordova/fileTransfer-tests.ts new file mode 100644 index 000000000..0c188f239 --- /dev/null +++ b/ng-cordova/fileTransfer-tests.ts @@ -0,0 +1,53 @@ +/// +/// +/// + +module ngCordova { + 'use strict'; + + angular.module('test') + // Adapted from http://ngcordova.com/docs/plugins/fileTransfer/ + .controller('MyCtrl', function($scope: ng.IScope & { downloadProgress: number; }, $timeout: ng.ITimeoutService, $cordovaFileTransfer: ngCordova.IFileTransferService) { + + document.addEventListener('deviceready', function() { + + var url = "http://cdn.wall-pix.net/albums/art-space/00030109.jpg"; + var targetPath = cordova.file.documentsDirectory + "testImage.png"; + var trustHosts = true + var options = {}; + + $cordovaFileTransfer.download(url, targetPath, options, trustHosts) + .then(function(result) { + // Success! + var file: FileEntry = result; + }, function(err) { + // Error + }, function(progress) { + $timeout(function() { + $scope.downloadProgress = (progress.loaded / progress.total) * 100; + }) + }); + + }, false); + + + document.addEventListener('deviceready', function() { + + var url = "http://cdn.wall-pix.net/uploads"; + var filePath = cordova.file.documentsDirectory + "testImage.png"; + var trustHosts = true + var options = {}; + + $cordovaFileTransfer.upload(url, filePath, options, trustHosts) + .then(function(result) { + // Success! + var file: FileUploadResult = result; + }, function(err) { + // Error + }, function(progress) { + // constant progress updates + }); + + }, false); + }); +} diff --git a/ng-cordova/fileTransfer.d.ts b/ng-cordova/fileTransfer.d.ts new file mode 100644 index 000000000..838302e10 --- /dev/null +++ b/ng-cordova/fileTransfer.d.ts @@ -0,0 +1,30 @@ +// Type definitions for ngCordova file-transfer plugin +// Project: https://github.com/driftyco/ng-cordova +// Definitions by: Phil McCloghry-Laing +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/// +/// + +declare module ngCordova { + export interface IFileTransferService { + download(url: string, filePath: string, options?: IFileDownloadOptions, trustAllHosts?: boolean): IFileTransferPromise; + upload(url: string, filePath: string, options?: IFileUploadOptions, trustAllHosts?: boolean): IFileTransferPromise; + } + + export interface IFileTransferPromise extends ng.IPromise { + then(successCallback: (promiseValue: T) => ng.IPromise | TResult, errorCallback?: (error: FileTransferError) => ng.IPromise | TResult, notifyCallback?: (state: any) => any): ng.IPromise; + catch(onRejected: (error: FileTransferError) => ng.IPromise | TResult): ng.IPromise; + } + + export interface IFileDownloadOptions extends FileDownloadOptions { + encodeURI?: boolean; + timeout?: number; + } + + export interface IFileUploadOptions extends FileUploadOptions { + encodeURI?: boolean; + timeout?: number; + } +} diff --git a/ng-cordova/tsd.d.ts b/ng-cordova/tsd.d.ts index 5f17dd706..791b61144 100644 --- a/ng-cordova/tsd.d.ts +++ b/ng-cordova/tsd.d.ts @@ -15,3 +15,7 @@ /// /// /// +/// +/// +/// +///