Add initial PhoneGap definitions and tests

This commit is contained in:
Boris Yankov
2012-11-05 04:19:08 +02:00
parent 447dc6a203
commit 185f815b8b
2 changed files with 133 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
// Type definitions for PhoneGap 2.2
// Project: http://phonegap.com
// Definitions by: Boris Yankov <https://github.com/borisyankov/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
interface Acceleration {
x: number;
y: number;
z: number;
timestamp: number; //DOMTimeStamp;
}
interface AccelerometerOptions {
frequency?: number;
}
interface Accelerometer {
getCurrentAcceleration(accelerometerSuccess: (acceleration: Acceleration) => void , accelerometerError: () => void ): void;
watchAcceleration(accelerometerSuccess: (acceleration: Acceleration) => void , accelerometerError: () => void , accelerometerOptions?: AccelerometerOptions): void;
clearWatch(watchID: number): void;
}
interface CameraPopoverOptions {
x: number;
y: number;
width: number;
height: number;
arrowDir: number;
}
interface CameraOptions {
quality?: number;
destinationType?: number;
sourceType?: number;
allowEdit?: bool;
encodingType?: number;
targetWidth?: number;
targetHeight?: number;
mediaType?: number;
correctOrientation?: bool;
saveToPhotoAlbum?: bool;
popoverOptions?: number;
}
interface Camera {
getPicture(cameraSuccess: (imageData: string) => void , cameraError: (message: string) => void , cameraOptions?: CameraOptions): void;
cleanup(cameraSuccess: (imageData: string) => void , cameraError: (message: string) => void ): void;
}
interface NavigatorPhonegap {
accelerometer: Accelerometer;
camera: Camera;
}
+79
View File
@@ -0,0 +1,79 @@
/// <reference path="../Definitions/phonegap-2.2.d.ts" />
function test_accelerometer() {
var watchID = null;
var options = { frequency: 3000 };
watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
if (watchID) {
navigator.accelerometer.clearWatch(watchID);
watchID = null;
}
function onSuccess(acceleration: Acceleration) {
var element = document.getElementById('accelerometer');
element.innerHTML = 'Acceleration X: ' + acceleration.x + '<br />' +
'Acceleration Y: ' + acceleration.y + '<br />' +
'Acceleration Z: ' + acceleration.z + '<br />' +
'Timestamp: ' + acceleration.timestamp + '<br />';
}
function onError() {
alert('onError!');
}
}
function test_camera() {
var pictureSource;
var destinationType;
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
}
function onPhotoDataSuccess(imageData) {
var smallImage = <HTMLImageElement>document.getElementById('smallImage');
smallImage.style.display = 'block';
smallImage.src = "data:image/jpeg;base64," + imageData;
}
function onPhotoURISuccess(imageURI) {
var largeImage = <HTMLImageElement>document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.src = imageURI;
}
function capturePhoto() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
quality: 50,
destinationType: destinationType.DATA_URL
});
}
function capturePhotoEdit() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
quality: 20, allowEdit: true,
destinationType: destinationType.DATA_URL
});
}
function getPhoto(source) {
navigator.camera.getPicture(onPhotoURISuccess, onFail, {
quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source
});
}
function onFail(message) {
alert('Failed because: ' + message);
}
var popover = new CameraPopoverOptions(300, 300, 100, 100, 1);
var options = { quality: 50, destinationType: 1, sourceType: 1, popoverOptions: popover };
navigator.camera.getPicture(onSuccess, onFail, options);
function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}
function onFail(message) {
alert('Failed because: ' + message);
}
}