Merge pull request #6510 from ksachdeva/master

Add the ngCordova type definitions
This commit is contained in:
Masahiro Wakame
2015-11-04 20:10:54 +09:00
19 changed files with 739 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
/// <reference path="tsd.d.ts" />
/// <reference path="../angularjs/angular.d.ts" />
/// <reference path="../ionic/ionic.d.ts" />
// For the full application demo please see following repo :
// https://github.com/ksachdeva/ngCordova-typescript-demo
namespace demo.appavailability {
'use strict';
export class AppAvailabilityController {
isAvailable:boolean;
static $inject:Array<string> = ["$ionicPlatform", "$cordovaDevice", "$cordovaAppAvailability"];
constructor($ionicPlatform:ionic.platform.IonicPlatformService,
private $cordovaDevice:ngCordova.IDeviceService,
private $cordovaAppAvailability:ngCordova.IAppAvailabilityService) {
this.isAvailable = false;
var scheme = "com.twitter.android";
if ($cordovaDevice.getPlatform() == 'iOS') {
scheme = "twitter://";
}
$ionicPlatform.ready(() => {
$cordovaAppAvailability.check(scheme).then(() => {
this.isAvailable = true;
}, (err) => {
// bad api design in plugin as well as in ngCordova !!
this.isAvailable = false;
})
});
}
}
angular.module("demo.appavailability").controller("AppAvailabilityController", AppAvailabilityController);
}
+14
View File
@@ -0,0 +1,14 @@
// Type definitions for ngCordova AppAvailability plugin
// Project: https://github.com/driftyco/ng-cordova
// Definitions by: Kapil Sachdeva <https://github.com/ksachdeva>
// Definitions: https://github.com/ksachdeva/DefinitelyTyped
/// <reference path="../angularjs/angular.d.ts" />
declare module ngCordova {
export interface IAppAvailabilityService {
check(urlScheme: string): ng.IPromise<any>;
}
}
+42
View File
@@ -0,0 +1,42 @@
/// <reference path="device.d.ts" />
/// <reference path="../angularjs/angular.d.ts" />
/// <reference path="../ionic/ionic.d.ts" />
// For the full application demo please see following repo :
// https://github.com/ksachdeva/ngCordova-typescript-demo
namespace demo.device {
'use strict';
interface IDeviceViewModel {
available:boolean;
cordova:string;
model:string;
platform:string;
uuid:string;
version:string;
}
export class DeviceController {
public vm:IDeviceViewModel;
static $inject:Array<string> = ["$ionicPlatform", "$cordovaDevice"];
constructor($ionicPlatform:ionic.platform.IonicPlatformService, $cordovaDevice:ngCordova.IDeviceService) {
$ionicPlatform.ready(() => {
this.vm = {
available : $cordovaDevice.getDevice().available,
cordova : $cordovaDevice.getCordova(),
model : $cordovaDevice.getModel(),
platform : $cordovaDevice.getPlatform(),
uuid : $cordovaDevice.getUUID(),
version : $cordovaDevice.getVersion()
};
});
}
}
angular.module("demo.device").controller("DeviceController", DeviceController);
}
+78
View File
@@ -0,0 +1,78 @@
// Type definitions for ngCordova device plugin
// Project: https://github.com/driftyco/ng-cordova
// Definitions by: Kapil Sachdeva <https://github.com/ksachdeva>
// Definitions: https://github.com/ksachdeva/DefinitelyTyped
declare module ngCordova {
interface IDeviceInfo {
available:boolean;
platform:string;
version:string;
uuid:string;
cordova:string;
model:string;
manufacturer:string;
isVirtual:boolean;
serial:string;
}
interface IDeviceService {
/**
* Returns the whole device object.
* @see https://github.com/apache/cordova-plugin-device
* @returns {Object} The device object.
*/
getDevice():IDeviceInfo;
/**
* Returns the Cordova version.
* @see https://github.com/apache/cordova-plugin-device#devicecordova
* @returns {String} The Cordova version.
*/
getCordova():string;
/**
* Returns the name of the device's model or product.
* @see https://github.com/apache/cordova-plugin-device#devicemodel
* @returns {String} The name of the device's model or product.
*/
getModel():string;
/**
* @deprecated device.name is deprecated as of version 2.3.0. Use device.model instead.
* @returns {String}
*/
getName():string;
/**
* Returns the device's operating system name.
* @see https://github.com/apache/cordova-plugin-device#deviceplatform
* @returns {String} The device's operating system name.
*/
getPlatform():string;
/**
* Returns the device's Universally Unique Identifier.
* @see https://github.com/apache/cordova-plugin-device#deviceuuid
* @returns {String} The device's Universally Unique Identifier
*/
getUUID():string;
/**
* Returns the operating system version.
* @see https://github.com/apache/cordova-plugin-device#deviceversion
* @returns {String}
*/
getVersion():string;
/**
* Returns the device manufacturer.
* @returns {String}
*/
getManufacturer():string;
}
}
+58
View File
@@ -0,0 +1,58 @@
/// <reference path="tsd.d.ts" />
/// <reference path="../angularjs/angular.d.ts" />
/// <reference path="../ionic/ionic.d.ts" />
// For the full application demo please see following repo :
// https://github.com/ksachdeva/ngCordova-typescript-demo
namespace demo.devicemotion {
'use strict';
export class DeviceMotionController {
motion:ngCordova.IDeviceMotionAcceleration;
this_watch:ngCordova.IDeviceMotionWatchPromise;
msg:string;
static $inject:Array<string> = ["$ionicPlatform", "$cordovaDeviceMotion"];
constructor($ionicPlatform:ionic.platform.IonicPlatformService, private $cordovaDeviceMotion:ngCordova.IDeviceMotionService) {
$ionicPlatform.ready(() => {
this.getAcceleration();
});
}
getAcceleration () {
this.$cordovaDeviceMotion.getCurrentAcceleration().then( (motion) => {
this.motion = motion;
console.log(motion);
}, function (err) {
this.msg = err.message;
console.log(err);
});
}
watchAcceleration () {
var options = { frequency: 3000 }; // Update every 3 seconds
this.this_watch = this.$cordovaDeviceMotion.watchAcceleration(options);
this.this_watch.then(
() => { /* unused */
},
(err) => {
this.msg = err.message;
},
(motion) => {
this.motion = motion;
});
};
clearWatch () {
// use watchID from watchAccelaration()
this.$cordovaDeviceMotion.clearWatch(this.this_watch.watchID);
};
}
angular.module("demo.devicemotion").controller("DeviceMotionController", DeviceMotionController);
}
+33
View File
@@ -0,0 +1,33 @@
// Type definitions for ngCordova device motion plugin
// Project: https://github.com/driftyco/ng-cordova
// Definitions by: Michel Vidailhet <https://github.com/mvidailhet>, Kapil Sachdeva <https://github.com/ksachdeva>
// Definitions: https://github.com/ksachdeva/DefinitelyTyped
/// <reference path="../angularjs/angular.d.ts" />
declare module ngCordova {
export interface IDeviceMotionAcceleration {
x: number;
y: number;
z: number;
timestamp: number;
}
export interface IDeviceMotionAccelerometerOptions {
frequency: number;
}
export interface IDeviceMotionWatchPromise extends ng.IPromise<IDeviceMotionAcceleration> {
watchID: number;
cancel: () => void;
clearWatch: (watchId?: number) => void;
}
export interface IDeviceMotionService {
getCurrentAcceleration(): ng.IPromise<IDeviceMotionAcceleration>;
watchAcceleration(options: IDeviceMotionAccelerometerOptions): IDeviceMotionWatchPromise;
clearWatch(watchId: number): void;
}
}
+65
View File
@@ -0,0 +1,65 @@
/// <reference path="tsd.d.ts" />
/// <reference path="../angularjs/angular.d.ts" />
/// <reference path="../ionic/ionic.d.ts" />
// For the full application demo please see following repo :
// https://github.com/ksachdeva/ngCordova-typescript-demo
namespace demo.deviceorientation {
'use strict';
export class DeviceOrientationController {
msg:string;
heading:ngCordova.IDeviceOrientationHeading;
this_watch:ngCordova.IDeviceOrientationWatchPromise;
static $inject:Array<string> = ["$ionicPlatform", "$timeout", "$cordovaDeviceOrientation"];
constructor($ionicPlatform:ionic.platform.IonicPlatformService,
private $timeout:ng.ITimeoutService,
private $cordovaDeviceOrientation:ngCordova.IDeviceOrientationService) {
$ionicPlatform.ready(() => {
this.getHeading();
});
}
getHeading() {
this.$cordovaDeviceOrientation
.getCurrentHeading()
.then((position) => {
this.heading = position;
}, (err) => {
this.msg = err.message;
});
};
watchHeading () {
this.this_watch = this.$cordovaDeviceOrientation.watchHeading({frequency: 1000});
this.this_watch.then(
() => {
/* unused */
},
(err) => {
this.msg = err.message;
},
(position) => {
this.$timeout(() => {
this.heading = position;
});
}
);
};
clearWatch () {
this.$cordovaDeviceOrientation.clearWatch(this.this_watch.watchID);
};
}
angular.module("demo.deviceorientation").controller("DeviceOrientationController", DeviceOrientationController);
}
+34
View File
@@ -0,0 +1,34 @@
// Type definitions for ngCordova device orientation plugin
// Project: https://github.com/driftyco/ng-cordova
// Definitions by: Michel Vidailhet <https://github.com/mvidailhet>, Kapil Sachdeva <https://github.com/ksachdeva>
// Definitions: https://github.com/ksachdeva/DefinitelyTyped
/// <reference path="../angularjs/angular.d.ts" />
declare module ngCordova {
export interface IDeviceOrientationHeading {
magneticHeading: number;
trueHeading?: number;
headingAccuracy?: number;
timestamp?: number;
}
export interface IDeviceOrientationWatchOptions {
frequency?: number;
filter?: number;
}
export interface IDeviceOrientationWatchPromise extends ng.IPromise<IDeviceOrientationHeading> {
watchID: number;
cancel: () => void;
clearWatch: (watchId?: number) => void;
}
export interface IDeviceOrientationService {
getCurrentHeading(): ng.IPromise<IDeviceOrientationHeading>;
watchHeading(options: IDeviceOrientationWatchOptions): IDeviceOrientationWatchPromise;
clearWatch(watchID: number): void;
}
}
+47
View File
@@ -0,0 +1,47 @@
/// <reference path="tsd.d.ts" />
/// <reference path="../angularjs/angular.d.ts" />
/// <reference path="../ionic/ionic.d.ts" />
// For the full application demo please see following repo :
// https://github.com/ksachdeva/ngCordova-typescript-demo
namespace demo.dialog {
'use strict';
export class DialogController {
action:string;
static $inject:Array<string> = ["$ionicPlatform", "$cordovaDialogs"];
constructor($ionicPlatform:ionic.platform.IonicPlatformService, private $cordovaDialogs:ngCordova.IDialogsService) {
this.action = "Press any button !";
}
alert() {
this.action = "Alert";
this.$cordovaDialogs.alert('Wow!');
}
confirm() {
this.action = "Confirm";
this.$cordovaDialogs.confirm('Are you sure?', "Custom title").then(function (buttonIndex) {
this.$cordovaDialogs.alert("Button index : " + buttonIndex);
});
}
prompt() {
this.action = "Prompt";
this.$cordovaDialogs.prompt('Please Login', "Custom title").then(function (result) {
this.$cordovaDialogs.alert("Input: " + result.input1 + "\n Button index : " + result.buttonIndex);
});
}
beep() {
this.action = "Beep";
this.$cordovaDialogs.beep(3);
}
}
angular.module("demo.dialog").controller("DialogController", DialogController);
}
+22
View File
@@ -0,0 +1,22 @@
// Type definitions for ngCordova dialogs plugin
// Project: https://github.com/driftyco/ng-cordova
// Definitions by: Michel Vidailhet <https://github.com/mvidailhet>, Kapil Sachdeva <https://github.com/ksachdeva>
// Definitions: https://github.com/ksachdeva/DefinitelyTyped
/// <reference path="../angularjs/angular.d.ts" />
declare module ngCordova {
export interface IDialogsPromptResult {
input1: string;
buttonIndex: number;
}
export interface IDialogsService {
alert(message: string, title?: string, buttonName?: string): ng.IPromise<void>;
confirm(message: string, title?: string, buttonArray?: Array<string>): ng.IPromise<number>;
prompt(message: string, title?: string, buttonArray?: Array<string>, defaultText?: string): ng.IPromise<IDialogsPromptResult>;
beep(repetitions: number): void;
}
}
+47
View File
@@ -0,0 +1,47 @@
/// <reference path="tsd.d.ts" />
/// <reference path="../angularjs/angular.d.ts" />
/// <reference path="../ionic/ionic.d.ts" />
// For the full application demo please see following repo :
// https://github.com/ksachdeva/ngCordova-typescript-demo
namespace demo.email {
'use strict';
export class EmailComposerController {
isAvailable:boolean;
status:string;
static $inject:Array<string> = ["$ionicPlatform", "$cordovaEmailComposer"];
constructor($ionicPlatform:ionic.platform.IonicPlatformService, $cordovaEmailComposer:ngCordova.IEmailComposerService) {
this.status = "";
$ionicPlatform.ready(() => {
$cordovaEmailComposer.isAvailable().then((available) => {
this.isAvailable = available;
});
let email = <ngCordova.IEmailComposerOptions>{
to: 'max@mustermann.de',
cc: 'erika@mustermann.de',
bcc: ['john@doe.com', 'jane@doe.com'],
subject: 'Cordova Icons',
body: 'How are you? Nice greetings from Leipzig',
isHtml: true
};
$cordovaEmailComposer.open(email).then(null, () => {
// user cancelled email
this.status = "User Cancelled Email";
});
});
}
}
angular.module("demo.email").controller("EmailComposerController", EmailComposerController);
}
+28
View File
@@ -0,0 +1,28 @@
// Type definitions for ngCordova emailComposer plugin
// Project: https://github.com/driftyco/ng-cordova
// Definitions by: Kapil Sachdeva <https://github.com/ksachdeva>
// Definitions: https://github.com/ksachdeva/DefinitelyTyped
/// <reference path="../angularjs/angular.d.ts" />
declare module ngCordova {
export interface IEmailComposerOptions {
to: string | Array<string>;
cc?: string | Array<string>;
bcc?: string | Array<string>;
attachments?: Array<any>;
subject?: string;
body?: string;
isHtml?: boolean;
}
export interface IEmailComposerService {
isAvailable(): ng.IPromise<boolean>;
open(properties: IEmailComposerOptions) : ng.IPromise<any>;
addAlias(app: string, schema: string) : void;
}
}
+39
View File
@@ -0,0 +1,39 @@
/// <reference path="tsd.d.ts" />
/// <reference path="../angularjs/angular.d.ts" />
/// <reference path="../ionic/ionic.d.ts" />
// For the full application demo please see following repo :
// https://github.com/ksachdeva/ngCordova-typescript-demo
namespace demo.geolocation {
'use strict';
export class GeolocationController {
erroMsg:string;
position:ngCordova.IGeoPosition;
static $inject:Array<string> = ["$ionicPlatform", "$cordovaGeolocation"];
constructor($ionicPlatform:ionic.platform.IonicPlatformService, private $cordovaGeolocation:ngCordova.IGeolocationService) {
}
getLocation = function () {
this.$cordovaGeolocation
.getCurrentPosition(<ngCordova.IGeolocationOptions>{timeout: 10000, enableHighAccuracy: false})
.then((position:ngCordova.IGeoPosition) => {
console.log("position found");
this.position = position;
// long = position.coords.longitude
// lat = position.coords.latitude
}, (err:ngCordova.IGeoPositionError) => {
console.log("unable to find location");
this.errorMsg = "Error : " + err.message;
});
};
}
angular.module("demo.geolocation").controller("GeolocationController", GeolocationController);
}
+42
View File
@@ -0,0 +1,42 @@
// Type definitions for ngCordova geolocation plugin
// Project: https://github.com/driftyco/ng-cordova
// Definitions by: Kapil Sachdeva <https://github.com/ksachdeva>
// Definitions: https://github.com/ksachdeva/DefinitelyTyped
/// <reference path="../angularjs/angular.d.ts" />
declare module ngCordova {
export interface IGeoPositionError {
code:number;
message:string;
}
export interface IGeoCoordinates {
latitude?:number;
longitude?:number;
accuracy?:number;
altitude?:number;
heading?:number;
speed?:number;
altitudeAccuracy?:number;
}
export interface IGeoPosition {
coords:IGeoCoordinates;
timestamp:Date;
}
export interface IGeolocationOptions {
timeout?: number;
maximumAge?: number;
enableHighAccuracy?: boolean;
}
export interface IGeolocationService {
getCurrentPosition(options?: IGeolocationOptions) : ng.IPromise<IGeoPosition>;
watchPosition(options?: IGeolocationOptions) : ng.IPromise<IGeoPosition>;
clearWatch(watchID: {[key: string]: any}) : void;
}
}
+43
View File
@@ -0,0 +1,43 @@
/// <reference path="tsd.d.ts" />
/// <reference path="../angularjs/angular.d.ts" />
/// <reference path="../ionic/ionic.d.ts" />
// For the full application demo please see following repo :
// https://github.com/ksachdeva/ngCordova-typescript-demo
namespace demo.network {
'use strict';
export class NetworkController {
networkType:string;
connectionType:string;
errorMsg:string;
static $inject:Array<string> = ["$ionicPlatform", "$cordovaNetwork"];
constructor($ionicPlatform:ionic.platform.IonicPlatformService, private $cordovaNetwork:ngCordova.INetworkInformationService) {
$ionicPlatform.ready(() => {
this.refresh();
});
}
refresh() {
this.networkType = this.$cordovaNetwork.getNetwork();
if (this.$cordovaNetwork.isOnline()) {
this.connectionType = 'Online';
}
else if (this.$cordovaNetwork.isOffline()) {
this.connectionType = 'Offline';
}
else {
this.errorMsg = 'Error getting isOffline / isOnline methods';
}
}
}
angular.module("demo.network").controller("NetworkController", NetworkController);
}
+19
View File
@@ -0,0 +1,19 @@
// Type definitions for ngCordova network plugin
// Project: https://github.com/driftyco/ng-cordova
// Definitions by: Kapil Sachdeva <https://github.com/ksachdeva>
// Definitions: https://github.com/ksachdeva/DefinitelyTyped
/// <reference path="../angularjs/angular.d.ts" />
declare module ngCordova {
export interface INetworkInformationService {
getNetwork(): string;
isOnline(): boolean;
isOffline(): boolean;
clearOfflineWatch(): void;
clearOnlineWatch(): void;
}
}
+51
View File
@@ -0,0 +1,51 @@
/// <reference path="toast.d.ts" />
/// <reference path="../angularjs/angular.d.ts" />
/// <reference path="../ionic/ionic.d.ts" />
// For the full application demo please see following repo :
// https://github.com/ksachdeva/ngCordova-typescript-demo
namespace demo.toast {
'use strict';
export class ToastController {
toastMessage:string = 'enter a message';
msg:string;
static $inject:Array<string> = ["$cordovaToast"];
constructor(private $cordovaToast:ngCordova.IToastService) {
}
center() {
this.$cordovaToast.show(this.toastMessage, 'long', 'center')
.then((success) => {
console.log("center msg displayed");
}, (error) => {
this.msg = error.message;
});
}
top() {
this.$cordovaToast.showShortTop(this.toastMessage)
.then((success) => {
console.log("short top msg displayed");
}, (error) => {
this.msg = error.message;
});
}
bottom() {
this.$cordovaToast.showLongBottom(this.toastMessage)
.then((success) => {
console.log("long bottom msg displayed");
}, (error) => {
this.msg = error.message;
});
}
}
angular.module("demo.toast").controller("ToastController", ToastController);
}
+22
View File
@@ -0,0 +1,22 @@
// Type definitions for ngCordova toast plugin
// Project: https://github.com/driftyco/ng-cordova
// Definitions by: Kapil Sachdeva <https://github.com/ksachdeva>
// Definitions: https://github.com/ksachdeva/DefinitelyTyped
/// <reference path="../angularjs/angular.d.ts" />
declare module ngCordova {
interface IToastService {
showShortTop(message:string):angular.IPromise<any>;
showShortCenter(message:string):angular.IPromise<any>;
showShortBottom(message:string):angular.IPromise<any>;
showLongTop(message:string):angular.IPromise<any>;
showLongCenter(message:string):angular.IPromise<any>;
showLongBottom(message:string):angular.IPromise<any>;
show(message:string, duration:string, position:string):angular.IPromise<any>;
}
}
+14
View File
@@ -0,0 +1,14 @@
// Type definitions for ngCordova plugins
// Project: https://github.com/driftyco/ng-cordova
// Definitions by: Kapil Sachdeva <https://github.com/ksachdeva>
// Definitions: https://github.com/ksachdeva/DefinitelyTyped
/// <reference path="device.d.ts"/>
/// <reference path="toast.d.ts"/>
/// <reference path="network.d.ts"/>
/// <reference path="emailComposer.d.ts"/>
/// <reference path="dialogs.d.ts"/>
/// <reference path="geolocation.d.ts"/>
/// <reference path="deviceMotion.d.ts"/>
/// <reference path="deviceOrientation.d.ts"/>
/// <reference path="appAvailability.d.ts"/>