mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Move definitions and test in separate folders
This enables each definition to have a readme if necessary. Also a .json metadata file to help with package managers. And last, to have different versions of the definitions.
This commit is contained in:
Vendored
+394
@@ -0,0 +1,394 @@
|
||||
// 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 CaptureAudioOptions {
|
||||
limit?: number;
|
||||
duration?: number;
|
||||
mode?: number;
|
||||
}
|
||||
|
||||
interface MediaFile {
|
||||
name: string;
|
||||
fullPath: string;
|
||||
type: string;
|
||||
lastModifiedDate: Date;
|
||||
size: number;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
interface CompassOptions {
|
||||
frequency?: number;
|
||||
filter?: number;
|
||||
}
|
||||
|
||||
interface CompassHeading {
|
||||
magneticHeading?: number;
|
||||
trueHeading?: number;
|
||||
headingAccuracy?: number;
|
||||
timestamp?: number;
|
||||
}
|
||||
|
||||
interface CompassError {
|
||||
code: number;
|
||||
}
|
||||
|
||||
interface Compass {
|
||||
getCurrentHeading(compassSuccess: (heading: CompassHeading) => void , compassError: (error: CompassError) => void , compassOptions?: CompassOptions): void;
|
||||
watchHeading(compassSuccess: (heading: CompassHeading) => void , compassError: (error: CompassError) => void , compassOptions?: CompassOptions): void;
|
||||
clearWatch(watchID: number): void;
|
||||
}
|
||||
|
||||
interface Connection {
|
||||
type: number;
|
||||
}
|
||||
|
||||
interface ContactAddress {
|
||||
pref: bool;
|
||||
type: string;
|
||||
formatted: string;
|
||||
streetAddress: string;
|
||||
locality: string;
|
||||
region: string;
|
||||
postalCode: string;
|
||||
country: string;
|
||||
}
|
||||
|
||||
interface ContactField {
|
||||
type: string;
|
||||
value: string;
|
||||
pref: bool;
|
||||
}
|
||||
|
||||
interface Contact {
|
||||
id: string;
|
||||
displayName: string;
|
||||
name: ContactName;
|
||||
nickname: string;
|
||||
phoneNumbers: ContactField[];
|
||||
emails: ContactField[];
|
||||
addresses: ContactAddress[];
|
||||
ims: ContactField[];
|
||||
organizations: ContactOrganization[];
|
||||
birthday: Date;
|
||||
note: string;
|
||||
photos: ContactField[];
|
||||
categories: ContactField[];
|
||||
urls: ContactField[];
|
||||
}
|
||||
|
||||
interface ContactFindOptions {
|
||||
filter?: string;
|
||||
multiple?: bool;
|
||||
}
|
||||
|
||||
interface ContactName {
|
||||
formatted: string;
|
||||
familyName: string;
|
||||
givenName: string;
|
||||
middleName: string;
|
||||
honorificPrefix: string;
|
||||
honorificSuffix: string;
|
||||
}
|
||||
|
||||
interface ContactOrganization {
|
||||
pref: bool;
|
||||
type: string;
|
||||
name: string;
|
||||
department: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
interface ContactError {
|
||||
code: number;
|
||||
}
|
||||
|
||||
interface Contacts {
|
||||
create(properties: any): void;
|
||||
find(contactFields: string[], contactSuccess: (contacts: Contact[]) => void , contactError: (error: ContactError) => void , contactFindOptions?: ContactFindOptions): void;
|
||||
}
|
||||
|
||||
interface Device {
|
||||
name: string;
|
||||
cordova: string;
|
||||
platform: string;
|
||||
uuid: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
/* Defined in lib.d.ts
|
||||
interface File {
|
||||
fullPath: string;
|
||||
type: string;
|
||||
size: number;
|
||||
}
|
||||
*/
|
||||
|
||||
interface FileWriter {
|
||||
readyState: any;
|
||||
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 FileSystemEntry {
|
||||
isFile: bool;
|
||||
isDirectory: bool;
|
||||
name: string;
|
||||
fullPath: string;
|
||||
filesystem: FileSystem;
|
||||
|
||||
getMetadata();
|
||||
setMetadata();
|
||||
toURL();
|
||||
remove();
|
||||
getParent();
|
||||
}
|
||||
|
||||
interface FileEntry extends FileSystemEntry {
|
||||
moveTo();
|
||||
copyTo();
|
||||
createWriter();
|
||||
file();
|
||||
}
|
||||
|
||||
interface DirectoryEntry extends FileSystemEntry {
|
||||
createReader();
|
||||
getDirectory();
|
||||
getFile();
|
||||
removeRecursively();
|
||||
}
|
||||
|
||||
interface DirectoryReader {
|
||||
readEntries(successCallback: (entries: FileSystemEntry) => void , errorCallback: (error: FileError) => void );
|
||||
}
|
||||
|
||||
interface FileTransfer {
|
||||
onprogress: Function;
|
||||
|
||||
upload(filePath: string, server: string, successCallback: (metadata: Metadata) => void , errorCallback: (error: FileError) => void , options: any): 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;
|
||||
}
|
||||
|
||||
interface Geolocation {
|
||||
getCurrentPosition(geolocationSuccess: (position: Position) => void , geolocationError?: PositionErrorCallback, geolocationOptions?: GeolocationOptions): void;
|
||||
watchPosition(geolocationSuccess: (position: Position) => void , geolocationError?: PositionErrorCallback, geolocationOptions?: GeolocationOptions): void;
|
||||
clearWatch(watchID: number): void;
|
||||
}
|
||||
|
||||
interface GlobalizationError {
|
||||
code: number;
|
||||
message: string;
|
||||
}
|
||||
|
||||
interface Globalization {
|
||||
getPreferredLanguage(successCB, errorCB): void;
|
||||
getLocaleName(successCB, errorCB): void;
|
||||
dateToString(date, successCB, errorCB, options): void;
|
||||
stringToDate(dateString, successCB, errorCB, options): void;
|
||||
getDatePattern(successCB, errorCB, options): void;
|
||||
getDateNames(successCB, errorCB, options): void;
|
||||
isDayLightSavingsTime(date, successCB, errorCB): void;
|
||||
getFirstDayOfWeek(successCB, errorCB): void;
|
||||
numberToString(number, successCB, errorCB, options): void;
|
||||
stringToNumber(string, successCB, errorCB, options): void;
|
||||
getNumberPattern(successCB, errorCB, options): void;
|
||||
getCurrencyPattern(currencyCode, successCB, errorCB): void;
|
||||
}
|
||||
|
||||
interface Media {
|
||||
new (src: string, mediaSuccess: Function, mediaError?: MediaError, mediaStatus?: Function);
|
||||
getCurrentPosition(mediaSuccess: Function, mediaError?: MediaError): void;
|
||||
getDuration(): void;
|
||||
play(): void;
|
||||
pause(): void;
|
||||
release(): void;
|
||||
seekTo(milliseconds: number): void;
|
||||
startRecord(): void;
|
||||
stopRecord(): void;
|
||||
stop(): void;
|
||||
}
|
||||
|
||||
interface Notification {
|
||||
alert(message: string, alertCallback: Function, title?: string, buttonName?: string): void;
|
||||
confirm(message: string, confirmCallback: Function, title?: string, buttonLabels?: string): void;
|
||||
beep(times: number): void;
|
||||
vibrate(milliseconds: number): void;
|
||||
}
|
||||
|
||||
interface Splashscreen {
|
||||
show(): void;
|
||||
hide(): void;
|
||||
}
|
||||
|
||||
interface Database {
|
||||
transaction();
|
||||
changeVersion();
|
||||
}
|
||||
|
||||
interface SQLResultSetRowList {
|
||||
length: number;
|
||||
item(index: number): any;
|
||||
}
|
||||
|
||||
interface SQLError {
|
||||
code: number;
|
||||
message: string;
|
||||
}
|
||||
|
||||
interface SQLResultSet {
|
||||
insertId: number;
|
||||
rowsAffected: number;
|
||||
rows: SQLResultSetRowList;
|
||||
}
|
||||
|
||||
interface SQLTransaction {
|
||||
executeSql(sql: string): SQLResultSet;
|
||||
}
|
||||
|
||||
/* Defined in lib.d.ts
|
||||
|
||||
interface LocalStorage {
|
||||
key;
|
||||
getItem;
|
||||
setItem;
|
||||
removeItem;
|
||||
clear;
|
||||
}
|
||||
*/
|
||||
|
||||
interface Navigator {
|
||||
accelerometer: Accelerometer;
|
||||
camera: Camera;
|
||||
capture: Capture;
|
||||
compass: Compass;
|
||||
connection: Connection;
|
||||
contacts: Contacts;
|
||||
device: Device;
|
||||
geolocation: Geolocation;
|
||||
globalization: Globalization;
|
||||
notification: Notification;
|
||||
splashscreen: Splashscreen;
|
||||
}
|
||||
|
||||
interface Window {
|
||||
openDatabase(database_name: string, database_version: string, database_displayname: string, database_size: number): Database;
|
||||
}
|
||||
@@ -0,0 +1,735 @@
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
|
||||
function test_capture() {
|
||||
var capture = navigator.device.capture;
|
||||
function captureSuccess(mediaFiles) {
|
||||
var i, len;
|
||||
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
|
||||
uploadFile(mediaFiles[i]);
|
||||
}
|
||||
}
|
||||
function captureError(error) {
|
||||
var msg = 'An error occurred during capture: ' + error.code;
|
||||
navigator.notification.alert(msg, null, 'Uh oh!');
|
||||
}
|
||||
function captureAudio() {
|
||||
navigator.device.capture.captureAudio(captureSuccess, captureError, { limit: 2 });
|
||||
}
|
||||
function uploadFile(mediaFile) {
|
||||
var ft = new FileTransfer(),
|
||||
path = mediaFile.fullPath,
|
||||
name = mediaFile.name;
|
||||
ft.upload(path,
|
||||
"http://my.domain.com/upload.php",
|
||||
function (result) {
|
||||
console.log('Upload success: ' + result.responseCode);
|
||||
console.log(result.bytesSent + ' bytes sent');
|
||||
},
|
||||
function (error) {
|
||||
console.log('Error uploading file ' + path + ': ' + error.code);
|
||||
},
|
||||
{ fileName: name });
|
||||
}
|
||||
var options = { limit: 3, duration: 10 };
|
||||
navigator.device.capture.captureAudio(captureSuccess, captureError, options);
|
||||
var captureSuccess = function (mediaFiles) {
|
||||
var i, path, len;
|
||||
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
|
||||
path = mediaFiles[i].fullPath;
|
||||
}
|
||||
};
|
||||
var captureError = function (error) {
|
||||
navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
|
||||
};
|
||||
navigator.device.capture.captureImage(captureSuccess, captureError, { limit: 2 });
|
||||
function captureSuccess(mediaFiles) {
|
||||
var i, len;
|
||||
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
|
||||
uploadFile(mediaFiles[i]);
|
||||
}
|
||||
}
|
||||
function captureError(error) {
|
||||
var msg = 'An error occurred during capture: ' + error.code;
|
||||
navigator.notification.alert(msg, null, 'Uh oh!');
|
||||
}
|
||||
function captureImage() {
|
||||
navigator.device.capture.captureImage(captureSuccess, captureError, { limit: 2 });
|
||||
}
|
||||
function uploadFile(mediaFile) {
|
||||
var ft = new FileTransfer(),
|
||||
path = mediaFile.fullPath,
|
||||
name = mediaFile.name;
|
||||
|
||||
ft.upload(path,
|
||||
"http://my.domain.com/upload.php",
|
||||
function (result) {
|
||||
console.log('Upload success: ' + result.responseCode);
|
||||
console.log(result.bytesSent + ' bytes sent');
|
||||
},
|
||||
function (error) {
|
||||
console.log('Error uploading file ' + path + ': ' + error.code);
|
||||
},
|
||||
{ fileName: name });
|
||||
}
|
||||
function captureSuccess(mediaFiles) {
|
||||
var i, len;
|
||||
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
|
||||
uploadFile(mediaFiles[i]);
|
||||
}
|
||||
}
|
||||
function captureError(error) {
|
||||
var msg = 'An error occurred during capture: ' + error.code;
|
||||
navigator.notification.alert(msg, null, 'Uh oh!');
|
||||
}
|
||||
function captureVideo() {
|
||||
navigator.device.capture.captureVideo(captureSuccess, captureError, { limit: 2 });
|
||||
}
|
||||
function uploadFile(mediaFile) {
|
||||
var ft = new FileTransfer(),
|
||||
path = mediaFile.fullPath,
|
||||
name = mediaFile.name;
|
||||
|
||||
ft.upload(path,
|
||||
"http://my.domain.com/upload.php",
|
||||
function (result) {
|
||||
console.log('Upload success: ' + result.responseCode);
|
||||
console.log(result.bytesSent + ' bytes sent');
|
||||
},
|
||||
function (error) {
|
||||
console.log('Error uploading file ' + path + ': ' + error.code);
|
||||
},
|
||||
{ fileName: name });
|
||||
}
|
||||
}
|
||||
|
||||
function test_compass() {
|
||||
document.addEventListener("deviceready", onDeviceReady, false);
|
||||
function onDeviceReady() {
|
||||
navigator.compass.getCurrentHeading(onSuccess, onError);
|
||||
}
|
||||
function onSuccess(heading) {
|
||||
alert('Heading: ' + heading.magneticHeading);
|
||||
}
|
||||
function onError(compassError) {
|
||||
alert('Compass Error: ' + compassError.code);
|
||||
}
|
||||
var watchID = null;
|
||||
|
||||
|
||||
document.addEventListener("deviceready", onDeviceReady, false);
|
||||
function onDeviceReady() {
|
||||
startWatch();
|
||||
}
|
||||
function startWatch() {
|
||||
var options = { frequency: 3000 };
|
||||
watchID = navigator.compass.watchHeading(onSuccess, onError, options);
|
||||
}
|
||||
function stopWatch() {
|
||||
if (watchID) {
|
||||
navigator.compass.clearWatch(watchID);
|
||||
watchID = null;
|
||||
}
|
||||
}
|
||||
function onSuccess(heading) {
|
||||
var element = document.getElementById('heading');
|
||||
element.innerHTML = 'Heading: ' + heading.magneticHeading;
|
||||
}
|
||||
function onError(compassError) {
|
||||
alert('Compass error: ' + compassError.code);
|
||||
}
|
||||
|
||||
function startWatch() {
|
||||
var options = { frequency: 3000 };
|
||||
watchID = navigator.compass.watchHeading(onSuccess, onError, options);
|
||||
}
|
||||
function stopWatch() {
|
||||
if (watchID) {
|
||||
navigator.compass.clearWatch(watchID);
|
||||
watchID = null;
|
||||
}
|
||||
}
|
||||
function onSuccess(heading) {
|
||||
var element = document.getElementById('heading');
|
||||
element.innerHTML = 'Heading: ' + heading.magneticHeading;
|
||||
}
|
||||
function onError(compassError) {
|
||||
alert('Compass error: ' + compassError.code);
|
||||
}
|
||||
}
|
||||
|
||||
function test_connection() {
|
||||
var networkState = navigator.connection.type;
|
||||
var states = {};
|
||||
states[Connection.UNKNOWN] = 'Unknown connection';
|
||||
states[Connection.ETHERNET] = 'Ethernet connection';
|
||||
states[Connection.WIFI] = 'WiFi connection';
|
||||
states[Connection.CELL_2G] = 'Cell 2G connection';
|
||||
states[Connection.CELL_3G] = 'Cell 3G connection';
|
||||
states[Connection.CELL_4G] = 'Cell 4G connection';
|
||||
states[Connection.NONE] = 'No network connection';
|
||||
alert('Connection type: ' + states[networkState]);
|
||||
}
|
||||
|
||||
function test_contacts() {
|
||||
var myContact = navigator.contacts.create({ "displayName": "Test User" });
|
||||
myContact.note = "This contact has a note.";
|
||||
console.log("The contact, " + myContact.displayName + ", note: " + myContact.note);
|
||||
|
||||
function onDeviceReady() {
|
||||
var options = new ContactFindOptions();
|
||||
options.filter = "Bob";
|
||||
var fields = ["displayName", "name"];
|
||||
navigator.contacts.find(fields, onSuccess, onError, options);
|
||||
}
|
||||
function onSuccess(contacts) {
|
||||
for (var i = 0; i < contacts.length; i++) {
|
||||
console.log("Display Name = " + contacts[i].displayName);
|
||||
}
|
||||
}
|
||||
function onError(contactError) {
|
||||
alert('onError!');
|
||||
}
|
||||
|
||||
var contact = navigator.contacts.create();
|
||||
contact.displayName = "Plumber";
|
||||
contact.nickname = "Plumber";
|
||||
var name = new ContactName();
|
||||
name.givenName = "Jane";
|
||||
name.familyName = "Doe";
|
||||
contact.name = name;
|
||||
contact.save(onSuccess, onError);
|
||||
|
||||
var clone = contact.clone();
|
||||
clone.name.givenName = "John";
|
||||
console.log("Original contact name = " + contact.name.givenName);
|
||||
console.log("Cloned contact name = " + clone.name.givenName);
|
||||
contact.remove(onSuccess, onError);
|
||||
|
||||
function onDeviceReady() {
|
||||
var contact = navigator.contacts.create();
|
||||
contact.displayName = "Plumber";
|
||||
contact.nickname = "Plumber";
|
||||
var name = new ContactName();
|
||||
name.givenName = "Jane";
|
||||
name.familyName = "Doe";
|
||||
contact.name = name;
|
||||
contact.save(onSuccess, onError);
|
||||
var clone = contact.clone();
|
||||
clone.name.givenName = "John";
|
||||
console.log("Original contact name = " + contact.name.givenName);
|
||||
console.log("Cloned contact name = " + clone.name.givenName);
|
||||
contact.remove(onSuccess, onError);
|
||||
}
|
||||
|
||||
var options = new ContactFindOptions();
|
||||
options.filter = "";
|
||||
var filter = ["displayName", "addresses"];
|
||||
navigator.contacts.find(filter, onSuccess, onError, options);
|
||||
|
||||
for (var i = 0; i < contacts.length; i++) {
|
||||
for (var j = 0; j < contacts[i].addresses.length; j++) {
|
||||
alert("Pref: " + contacts[i].addresses[j].pref + "\n" +
|
||||
"Type: " + contacts[i].addresses[j].type + "\n" +
|
||||
"Formatted: " + contacts[i].addresses[j].formatted + "\n" +
|
||||
"Street Address: " + contacts[i].addresses[j].streetAddress + "\n" +
|
||||
"Locality: " + contacts[i].addresses[j].locality + "\n" +
|
||||
"Region: " + contacts[i].addresses[j].region + "\n" +
|
||||
"Postal Code: " + contacts[i].addresses[j].postalCode + "\n" +
|
||||
"Country: " + contacts[i].addresses[j].country);
|
||||
}
|
||||
}
|
||||
|
||||
var contact = navigator.contacts.create();
|
||||
var phoneNumbers = [];
|
||||
phoneNumbers[0] = new ContactField('work', '212-555-1234', false);
|
||||
phoneNumbers[1] = new ContactField('mobile', '917-555-5432', true); // preferred number
|
||||
phoneNumbers[2] = new ContactField('home', '203-555-7890', false);
|
||||
contact.phoneNumbers = phoneNumbers;
|
||||
contact.save();
|
||||
|
||||
var options = new ContactFindOptions();
|
||||
options.filter = "";
|
||||
options.multiple = true;
|
||||
filter = ["displayName"];
|
||||
navigator.contacts.find(filter, onSuccess, onError, options);
|
||||
}
|
||||
|
||||
function test_device() {
|
||||
element.innerHTML = 'Device Name: ' + device.name + '<br />' +
|
||||
'Device Cordova: ' + device.cordova + '<br />' +
|
||||
'Device Platform: ' + device.platform + '<br />' +
|
||||
'Device UUID: ' + device.uuid + '<br />' +
|
||||
'Device Version: ' + device.version + '<br />';
|
||||
}
|
||||
|
||||
function test_file() {
|
||||
function onDeviceReady() {
|
||||
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
|
||||
}
|
||||
function gotFS(fileSystem) {
|
||||
fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
|
||||
}
|
||||
function gotFileEntry(fileEntry) {
|
||||
fileEntry.file(gotFile, fail);
|
||||
}
|
||||
function gotFile(file) {
|
||||
readDataUrl(file);
|
||||
readAsText(file);
|
||||
}
|
||||
function readDataUrl(file) {
|
||||
var reader = new FileReader();
|
||||
reader.onloadend = function (evt) {
|
||||
console.log("Read as data URL");
|
||||
console.log(evt.target.result);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
function readAsText(file) {
|
||||
var reader = new FileReader();
|
||||
reader.onloadend = function (evt) {
|
||||
console.log("Read as text");
|
||||
console.log(evt.target.result);
|
||||
};
|
||||
reader.readAsText(file);
|
||||
}
|
||||
function fail(evt) {
|
||||
console.log(evt.target.error.code);
|
||||
}
|
||||
|
||||
function onDeviceReady() {
|
||||
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
|
||||
}
|
||||
function gotFS(fileSystem) {
|
||||
fileSystem.root.getFile("readme.txt", { create: true, exclusive: false }, gotFileEntry, fail);
|
||||
}
|
||||
function gotFileEntry(fileEntry) {
|
||||
fileEntry.createWriter(gotFileWriter, fail);
|
||||
}
|
||||
function gotFileWriter(writer) {
|
||||
writer.onwriteend = function (evt) {
|
||||
console.log("contents of file now 'some sample text'");
|
||||
writer.truncate(11);
|
||||
writer.onwriteend = function (evt) {
|
||||
console.log("contents of file now 'some sample'");
|
||||
writer.seek(4);
|
||||
writer.write(" different text");
|
||||
writer.onwriteend = function (evt) {
|
||||
console.log("contents of file now 'some different text'");
|
||||
}
|
||||
};
|
||||
};
|
||||
writer.write("some sample text");
|
||||
}
|
||||
function fail(error) {
|
||||
console.log(error.code);
|
||||
}
|
||||
|
||||
function onDeviceReady() {
|
||||
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
|
||||
}
|
||||
function onFileSystemSuccess(fileSystem) {
|
||||
console.log(fileSystem.name);
|
||||
console.log(fileSystem.root.name);
|
||||
}
|
||||
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 + '<br />' +
|
||||
'Longitude: ' + position.coords.longitude + '<br />' +
|
||||
'<hr />' + element.innerHTML;
|
||||
}
|
||||
function onError(error) {
|
||||
alert('code: ' + error.code + '\n' +
|
||||
'message: ' + error.message + '\n');
|
||||
}
|
||||
var watchID = navigator.geolocation.watchPosition(onSuccess, onError, { timeout: 30000 });
|
||||
|
||||
var watchID = navigator.geolocation.watchPosition(onSuccess, onError, { enableHighAccuracy: true });
|
||||
navigator.geolocation.clearWatch(watchID);
|
||||
}
|
||||
|
||||
function test_globalization() {
|
||||
navigator.globalization.getPreferredLanguage(
|
||||
function (language) { alert('language: ' + language.value + '\n'); },
|
||||
function () { alert('Error getting language\n'); }
|
||||
);
|
||||
navigator.globalization.getLocaleName(
|
||||
function (locale) { alert('locale: ' + locale.value + '\n'); },
|
||||
function () { alert('Error getting locale\n'); }
|
||||
);
|
||||
navigator.globalization.dateToString(
|
||||
new Date(),
|
||||
function (date) { alert('date:' + date.value + '\n'); },
|
||||
function () { alert('Error getting dateString\n'); },
|
||||
{ formatLength: 'short', selector: 'date and time' }
|
||||
);
|
||||
navigator.globalization.stringToDate(
|
||||
'9/25/2012',
|
||||
function (date) {
|
||||
alert('month:' + date.month +
|
||||
' day:' + date.day +
|
||||
' year:' + date.year + '\n');
|
||||
},
|
||||
function () { alert('Error getting date\n'); },
|
||||
{ selector: 'date' }
|
||||
);
|
||||
navigator.globalization.getDatePattern(
|
||||
function (date) { alert('pattern: ' + date.pattern + '\n'); },
|
||||
function () { alert('Error getting pattern\n'); },
|
||||
{ formatLength: 'short', selector: 'date and time' }
|
||||
);
|
||||
navigator.globalization.getDateNames(
|
||||
function (names) {
|
||||
for (var i = 0; i < names.value.length; i++) {
|
||||
alert('month: ' + names.value[i] + '\n');
|
||||
}
|
||||
},
|
||||
function () { alert('Error getting names\n'); },
|
||||
{ type: 'wide', item: 'months' }
|
||||
);
|
||||
navigator.globalization.isDayLightSavingsTime(
|
||||
new Date(),
|
||||
function (date) { alert('dst: ' + date.dst + '\n'); },
|
||||
function () { alert('Error getting names\n'); }
|
||||
);
|
||||
navigator.globalization.getFirstDayOfWeek(
|
||||
function (day) { alert('day: ' + day.value + '\n'); },
|
||||
function () { alert('Error getting day\n'); }
|
||||
);
|
||||
navigator.globalization.numberToString(
|
||||
3.1415926,
|
||||
function (number) { alert('number: ' + number.value + '\n'); },
|
||||
function () { alert('Error getting number\n'); },
|
||||
{ type: 'decimal' }
|
||||
);
|
||||
navigator.globalization.stringToNumber(
|
||||
'1234.56',
|
||||
function (number) { alert('number: ' + number.value + '\n'); },
|
||||
function () { alert('Error getting number\n'); },
|
||||
{ type: 'decimal' }
|
||||
);
|
||||
navigator.globalization.getNumberPattern(
|
||||
function (pattern) {
|
||||
alert('pattern: ' + pattern.pattern + '\n' +
|
||||
'symbol: ' + pattern.symbol + '\n' +
|
||||
'fraction: ' + pattern.fraction + '\n' +
|
||||
'rounding: ' + pattern.rounding + '\n' +
|
||||
'positive: ' + pattern.positive + '\n' +
|
||||
'negative: ' + pattern.negative + '\n' +
|
||||
'decimal: ' + pattern.decimal + '\n' +
|
||||
'grouping: ' + pattern.grouping);
|
||||
},
|
||||
function () { alert('Error getting pattern\n'); },
|
||||
{ type: 'decimal' }
|
||||
);
|
||||
navigator.globalization.getCurrencyPattern(
|
||||
'USD',
|
||||
function (pattern) {
|
||||
alert('pattern: ' + pattern.pattern + '\n' +
|
||||
'code: ' + pattern.code + '\n' +
|
||||
'fraction: ' + pattern.fraction + '\n' +
|
||||
'rounding: ' + pattern.rounding + '\n' +
|
||||
'decimal: ' + pattern.decimal + '\n' +
|
||||
'grouping: ' + pattern.grouping);
|
||||
},
|
||||
function () { alert('Error getting pattern\n'); }
|
||||
);
|
||||
}
|
||||
|
||||
function test_media() {
|
||||
var my_media = new Media(src, onSuccess, onError);
|
||||
var mediaTimer = setInterval(function () {
|
||||
my_media.getCurrentPosition(
|
||||
function (position) {
|
||||
if (position > -1) {
|
||||
console.log((position) + " sec");
|
||||
}
|
||||
},
|
||||
function (e) {
|
||||
console.log("Error getting pos=" + e);
|
||||
}
|
||||
);
|
||||
}, 1000);
|
||||
|
||||
var counter = 0;
|
||||
var timerDur = setInterval(function () {
|
||||
counter = counter + 100;
|
||||
if (counter > 2000) {
|
||||
clearInterval(timerDur);
|
||||
}
|
||||
var dur = my_media.getDuration();
|
||||
if (dur > 0) {
|
||||
clearInterval(timerDur);
|
||||
document.getElementById('audio_duration').innerHTML = (dur) + " sec";
|
||||
}
|
||||
}, 100);
|
||||
|
||||
function playAudio(url) {
|
||||
var my_media = new Media(url,
|
||||
function () {
|
||||
console.log("playAudio():Audio Success");
|
||||
},
|
||||
function (err) {
|
||||
console.log("playAudio():Audio Error: " + err);
|
||||
});
|
||||
my_media.play();
|
||||
setTimeout(function () {
|
||||
media.pause();
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
function playAudio(url) {
|
||||
var my_media = new Media(url,
|
||||
function () {
|
||||
console.log("playAudio():Audio Success");
|
||||
},
|
||||
function (err) {
|
||||
console.log("playAudio():Audio Error: " + err);
|
||||
});
|
||||
my_media.play();
|
||||
}
|
||||
|
||||
var my_media = new Media(src, onSuccess, onError);
|
||||
my_media.play();
|
||||
my_media.stop();
|
||||
my_media.release();
|
||||
setTimeout(function () {
|
||||
my_media.seekTo(10000);
|
||||
}, 5000);
|
||||
media.stopRecord();
|
||||
|
||||
var src = "myrecording.mp3";
|
||||
var mediaRec = new Media(src,
|
||||
function () {
|
||||
console.log("recordAudio():Audio Success");
|
||||
},
|
||||
function (err) {
|
||||
console.log("recordAudio():Audio Error: " + err.code);
|
||||
}
|
||||
);
|
||||
mediaRec.startRecord();
|
||||
}
|
||||
|
||||
function test_notification() {
|
||||
function alertDismissed() { }
|
||||
navigator.notification.alert(
|
||||
'You are the winner!',
|
||||
alertDismissed,
|
||||
'Game Over',
|
||||
'Done'
|
||||
);
|
||||
navigator.notification.confirm(
|
||||
'You are the winner!',
|
||||
onConfirm,
|
||||
'Game Over',
|
||||
'Restart,Exit'
|
||||
);
|
||||
navigator.notification.beep(2);
|
||||
navigator.notification.vibrate(2500);
|
||||
}
|
||||
|
||||
function test_splashscreen() {
|
||||
navigator.splashscreen.show();
|
||||
navigator.splashscreen.hide();
|
||||
}
|
||||
|
||||
function test_storage() {
|
||||
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
|
||||
db.transaction(populateDB, errorCB, successCB);
|
||||
function populateDB(tx: SQLTransaction) {
|
||||
tx.executeSql('DROP TABLE IF EXISTS DEMO');
|
||||
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
|
||||
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
|
||||
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
|
||||
}
|
||||
function errorCB(err) {
|
||||
alert("Error processing SQL: " + err);
|
||||
}
|
||||
function successCB() {
|
||||
alert("success!");
|
||||
}
|
||||
db.changeVersion("1.0", "1.1");
|
||||
|
||||
function queryDB(tx) {
|
||||
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
|
||||
}
|
||||
function querySuccess(tx, results) {
|
||||
console.log("Returned rows = " + results.rows.length);
|
||||
if (!resultSet.rowsAffected) {
|
||||
console.log('No rows affected!');
|
||||
return false;
|
||||
}
|
||||
console.log("Last inserted row ID = " + results.insertId);
|
||||
}
|
||||
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
|
||||
db.transaction(queryDB, errorCB);
|
||||
|
||||
function querySuccessSet(tx, results) {
|
||||
var len = results.rows.length;
|
||||
console.log("DEMO table: " + len + " rows found.");
|
||||
for (var i = 0; i < len; i++) {
|
||||
console.log("Row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).data);
|
||||
}
|
||||
}
|
||||
|
||||
var storage = window.localStorage;
|
||||
var keyName = window.localStorage.key(0);
|
||||
window.localStorage.setItem("key", "value");
|
||||
var value = window.localStorage.getItem("key");
|
||||
window.localStorage.removeItem("key");
|
||||
window.localStorage.clear();
|
||||
}
|
||||
Reference in New Issue
Block a user