mirror of
https://github.com/apache/cordova-android.git
synced 2026-05-30 00:00:04 +08:00
Compare commits
29 Commits
WebSockets
...
0.9.5
| Author | SHA1 | Date | |
|---|---|---|---|
| 0aacfbdd50 | |||
| 2cd116e4e7 | |||
| 673a8871df | |||
| 44945f9d5e | |||
| 887f754014 | |||
| 674015460f | |||
| 40084293c3 | |||
| ed4c57e791 | |||
| bf164f4161 | |||
| 626119ae3b | |||
| e766188689 | |||
| d74569ffa7 | |||
| d424af03e4 | |||
| f6f80537c3 | |||
| 908485751b | |||
| b850d225f4 | |||
| 010c774988 | |||
| 969f0c87d7 | |||
| b3e9794189 | |||
| 935295c9b8 | |||
| 04de2052fd | |||
| 60eb60b4f5 | |||
| ec307fdda8 | |||
| 7344964c05 | |||
| 1fc56921aa | |||
| 21a34a8980 | |||
| 8d73b364f2 | |||
| fb2c25c6c6 | |||
| 47ca081f36 |
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||||
<title>PhoneGap</title>
|
<title>PhoneGap</title>
|
||||||
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" charset="utf-8">
|
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title" charset="utf-8">
|
||||||
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.4.min.js"></script>
|
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.min.js"></script>
|
||||||
<script type="text/javascript" charset="utf-8" src="main.js"></script>
|
<script type="text/javascript" charset="utf-8" src="main.js"></script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:windowSoftInputMode="adjustPan"
|
||||||
package="com.phonegap" android:versionName="1.1" android:versionCode="5">
|
package="com.phonegap" android:versionName="1.1" android:versionCode="5">
|
||||||
<supports-screens
|
<supports-screens
|
||||||
android:largeScreens="true"
|
android:largeScreens="true"
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
android:resizeable="true"
|
android:resizeable="true"
|
||||||
android:anyDensity="true"
|
android:anyDensity="true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.CAMERA" />
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
@@ -23,6 +24,9 @@
|
|||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
|
||||||
|
<uses-feature android:name="android.hardware.camera" />
|
||||||
|
<uses-feature android:name="android.hardware.camera.autofocus" />
|
||||||
|
|
||||||
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
||||||
android:debuggable="true">
|
android:debuggable="true">
|
||||||
<activity android:name=".StandAlone"
|
<activity android:name=".StandAlone"
|
||||||
@@ -33,6 +37,7 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
<uses-sdk android:minSdkVersion="2" />
|
|
||||||
|
<uses-sdk android:minSdkVersion="2" />
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -6,7 +6,10 @@
|
|||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function Acceleration(x, y, z) {
|
if (!PhoneGap.hasResource("accelerometer")) {
|
||||||
|
PhoneGap.addResource("accelerometer");
|
||||||
|
|
||||||
|
Acceleration = function(x, y, z) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
@@ -17,7 +20,7 @@ function Acceleration(x, y, z) {
|
|||||||
* This class provides access to device accelerometer data.
|
* This class provides access to device accelerometer data.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function Accelerometer() {
|
Accelerometer = function() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The last known acceleration. type=Acceleration()
|
* The last known acceleration. type=Acceleration()
|
||||||
@@ -119,3 +122,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.accelerometer = new Accelerometer();
|
navigator.accelerometer = new Accelerometer();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,10 +6,13 @@
|
|||||||
* Copyright (c) 2010-2011, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!PhoneGap.hasResource("app")) {
|
||||||
|
PhoneGap.addResource("app");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
function App() {}
|
App = function() {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the resource cache.
|
* Clear the resource cache.
|
||||||
@@ -87,3 +90,4 @@ App.prototype.exitApp = function() {
|
|||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
navigator.app = window.app = new App();
|
navigator.app = window.app = new App();
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!PhoneGap.hasResource("camera")) {
|
||||||
|
PhoneGap.addResource("camera");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides access to the device camera.
|
* This class provides access to the device camera.
|
||||||
*
|
*
|
||||||
@@ -91,3 +94,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.camera = new Camera();
|
navigator.camera = new Camera();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -0,0 +1,187 @@
|
|||||||
|
/*
|
||||||
|
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||||
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||||
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The CaptureError interface encapsulates all errors in the Capture API.
|
||||||
|
*/
|
||||||
|
function CaptureError() {
|
||||||
|
this.code = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Capture error codes
|
||||||
|
CaptureError.CAPTURE_INTERNAL_ERR = 0;
|
||||||
|
CaptureError.CAPTURE_APPLICATION_BUSY = 1;
|
||||||
|
CaptureError.CAPTURE_INVALID_ARGUMENT = 2;
|
||||||
|
CaptureError.CAPTURE_NO_MEDIA_FILES = 3;
|
||||||
|
CaptureError.CAPTURE_NOT_SUPPORTED = 20;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Capture interface exposes an interface to the camera and microphone of the hosting device.
|
||||||
|
*/
|
||||||
|
function Capture() {
|
||||||
|
this.supportedAudioFormats = [];
|
||||||
|
this.supportedImageFormats = [];
|
||||||
|
this.supportedVideoFormats = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launch audio recorder application for recording audio clip(s).
|
||||||
|
*
|
||||||
|
* @param {Function} successCB
|
||||||
|
* @param {Function} errorCB
|
||||||
|
* @param {CaptureAudioOptions} options
|
||||||
|
*/
|
||||||
|
Capture.prototype.captureAudio = function(successCallback, errorCallback, options) {
|
||||||
|
PhoneGap.exec(successCallback, errorCallback, "Capture", "captureAudio", [options]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launch camera application for taking image(s).
|
||||||
|
*
|
||||||
|
* @param {Function} successCB
|
||||||
|
* @param {Function} errorCB
|
||||||
|
* @param {CaptureImageOptions} options
|
||||||
|
*/
|
||||||
|
Capture.prototype.captureImage = function(successCallback, errorCallback, options) {
|
||||||
|
PhoneGap.exec(successCallback, errorCallback, "Capture", "captureImage", [options]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launch camera application for taking image(s).
|
||||||
|
*
|
||||||
|
* @param {Function} successCB
|
||||||
|
* @param {Function} errorCB
|
||||||
|
* @param {CaptureImageOptions} options
|
||||||
|
*/
|
||||||
|
Capture.prototype._castMediaFile = function(pluginResult) {
|
||||||
|
var mediaFiles = [];
|
||||||
|
var i;
|
||||||
|
for (i=0; i<pluginResult.message.length; i++) {
|
||||||
|
var mediaFile = new MediaFile();
|
||||||
|
mediaFile.name = pluginResult.message[i].name;
|
||||||
|
mediaFile.fullPath = pluginResult.message[i].fullPath;
|
||||||
|
mediaFile.type = pluginResult.message[i].type;
|
||||||
|
mediaFile.lastModifiedDate = pluginResult.message[i].lastModifiedDate;
|
||||||
|
mediaFile.size = pluginResult.message[i].size;
|
||||||
|
mediaFiles.push(mediaFile);
|
||||||
|
}
|
||||||
|
pluginResult.message = mediaFiles;
|
||||||
|
return pluginResult;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launch device camera application for recording video(s).
|
||||||
|
*
|
||||||
|
* @param {Function} successCB
|
||||||
|
* @param {Function} errorCB
|
||||||
|
* @param {CaptureVideoOptions} options
|
||||||
|
*/
|
||||||
|
Capture.prototype.captureVideo = function(successCallback, errorCallback, options) {
|
||||||
|
PhoneGap.exec(successCallback, errorCallback, "Capture", "captureVideo", [options]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encapsulates a set of parameters that the capture device supports.
|
||||||
|
*/
|
||||||
|
function ConfigurationData() {
|
||||||
|
// The ASCII-encoded string in lower case representing the media type.
|
||||||
|
this.type;
|
||||||
|
// The height attribute represents height of the image or video in pixels.
|
||||||
|
// In the case of a sound clip this attribute has value 0.
|
||||||
|
this.height = 0;
|
||||||
|
// The width attribute represents width of the image or video in pixels.
|
||||||
|
// In the case of a sound clip this attribute has value 0
|
||||||
|
this.width = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encapsulates all image capture operation configuration options.
|
||||||
|
*/
|
||||||
|
function CaptureImageOptions() {
|
||||||
|
// Upper limit of images user can take. Value must be equal or greater than 1.
|
||||||
|
this.limit = 1;
|
||||||
|
// The selected image mode. Must match with one of the elements in supportedImageModes array.
|
||||||
|
this.mode;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encapsulates all video capture operation configuration options.
|
||||||
|
*/
|
||||||
|
function CaptureVideoOptions() {
|
||||||
|
// Upper limit of videos user can record. Value must be equal or greater than 1.
|
||||||
|
this.limit;
|
||||||
|
// Maximum duration of a single video clip in seconds.
|
||||||
|
this.duration;
|
||||||
|
// The selected video mode. Must match with one of the elements in supportedVideoModes array.
|
||||||
|
this.mode;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encapsulates all audio capture operation configuration options.
|
||||||
|
*/
|
||||||
|
function CaptureAudioOptions() {
|
||||||
|
// Upper limit of sound clips user can record. Value must be equal or greater than 1.
|
||||||
|
this.limit;
|
||||||
|
// Maximum duration of a single sound clip in seconds.
|
||||||
|
this.duration;
|
||||||
|
// The selected audio mode. Must match with one of the elements in supportedAudioModes array.
|
||||||
|
this.mode;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a single file.
|
||||||
|
*
|
||||||
|
* name {DOMString} name of the file, without path information
|
||||||
|
* fullPath {DOMString} the full path of the file, including the name
|
||||||
|
* type {DOMString} mime type
|
||||||
|
* lastModifiedDate {Date} last modified date
|
||||||
|
* size {Number} size of the file in bytes
|
||||||
|
*/
|
||||||
|
function MediaFile(name, fullPath, type, lastModifiedDate, size) {
|
||||||
|
this.name = name || null;
|
||||||
|
this.fullPath = fullPath || null;
|
||||||
|
this.type = type || null;
|
||||||
|
this.lastModifiedDate = lastModifiedDate || null;
|
||||||
|
this.size = size || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launch device camera application for recording video(s).
|
||||||
|
*
|
||||||
|
* @param {Function} successCB
|
||||||
|
* @param {Function} errorCB
|
||||||
|
*/
|
||||||
|
MediaFile.prototype.getFormatData = function(successCallback, errorCallback) {
|
||||||
|
PhoneGap.exec(successCallback, errorCallback, "Capture", "getFormatData", [this.fullPath, this.type]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MediaFileData encapsulates format information of a media file.
|
||||||
|
*
|
||||||
|
* @param {DOMString} codecs
|
||||||
|
* @param {long} bitrate
|
||||||
|
* @param {long} height
|
||||||
|
* @param {long} width
|
||||||
|
* @param {float} duration
|
||||||
|
*/
|
||||||
|
function MediaFileData(codecs, bitrate, height, width, duration) {
|
||||||
|
this.codecs = codecs || null;
|
||||||
|
this.bitrate = bitrate || 0;
|
||||||
|
this.height = height || 0;
|
||||||
|
this.width = width || 0;
|
||||||
|
this.duration = duration || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
PhoneGap.addConstructor(function() {
|
||||||
|
if (typeof navigator.device === "undefined") {
|
||||||
|
navigator.device = window.device = new Device();
|
||||||
|
}
|
||||||
|
if (typeof navigator.device.capture === "undefined") {
|
||||||
|
navigator.device.capture = window.device.capture = new Capture();
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -6,11 +6,14 @@
|
|||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!PhoneGap.hasResource("compass")) {
|
||||||
|
PhoneGap.addResource("compass");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides access to device Compass data.
|
* This class provides access to device Compass data.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function Compass() {
|
Compass = function() {
|
||||||
/**
|
/**
|
||||||
* The last known Compass position.
|
* The last known Compass position.
|
||||||
*/
|
*/
|
||||||
@@ -20,7 +23,7 @@ function Compass() {
|
|||||||
* List of compass watch timers
|
* List of compass watch timers
|
||||||
*/
|
*/
|
||||||
this.timers = {};
|
this.timers = {};
|
||||||
}
|
};
|
||||||
|
|
||||||
Compass.ERROR_MSG = ["Not running", "Starting", "", "Failed to start"];
|
Compass.ERROR_MSG = ["Not running", "Starting", "", "Failed to start"];
|
||||||
|
|
||||||
@@ -113,3 +116,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.compass = new Compass();
|
navigator.compass = new Compass();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!PhoneGap.hasResource("contact")) {
|
||||||
|
PhoneGap.addResource("contact");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains information about a single contact.
|
* Contains information about a single contact.
|
||||||
* @param {DOMString} id unique identifier
|
* @param {DOMString} id unique identifier
|
||||||
@@ -295,3 +298,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.service.contacts = new Contacts();
|
navigator.service.contacts = new Contacts();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
// TODO: Needs to be commented
|
// TODO: Needs to be commented
|
||||||
|
|
||||||
|
if (!PhoneGap.hasResource("crypto")) {
|
||||||
|
PhoneGap.addResource("crypto");
|
||||||
|
|
||||||
var Crypto = function() {
|
var Crypto = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -34,4 +37,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.Crypto = new Crypto();
|
navigator.Crypto = new Crypto();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,12 +6,15 @@
|
|||||||
* Copyright (c) 2010-2011, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!PhoneGap.hasResource("device")) {
|
||||||
|
PhoneGap.addResource("device");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
|
* This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
|
||||||
* phone, etc.
|
* phone, etc.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function Device() {
|
Device = function() {
|
||||||
this.available = PhoneGap.available;
|
this.available = PhoneGap.available;
|
||||||
this.platform = null;
|
this.platform = null;
|
||||||
this.version = null;
|
this.version = null;
|
||||||
@@ -35,7 +38,7 @@ function Device() {
|
|||||||
console.log("Error initializing PhoneGap: " + e);
|
console.log("Error initializing PhoneGap: " + e);
|
||||||
alert("Error initializing PhoneGap: "+e);
|
alert("Error initializing PhoneGap: "+e);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get device info
|
* Get device info
|
||||||
@@ -95,5 +98,8 @@ Device.prototype.exitApp = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
navigator.device = window.device = new Device();
|
if (typeof navigator.device === "undefined") {
|
||||||
|
navigator.device = window.device = new Device();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|||||||
+59
-185
@@ -6,21 +6,19 @@
|
|||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
if (!PhoneGap.hasResource("file")) {
|
||||||
* This class provides generic read and write access to the mobile device file system.
|
PhoneGap.addResource("file");
|
||||||
* They are not used to read files from a server.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides some useful information about a file.
|
* This class provides some useful information about a file.
|
||||||
* This is the fields returned when navigator.fileMgr.getFileProperties()
|
* This is the fields returned when navigator.fileMgr.getFileProperties()
|
||||||
* is called.
|
* is called.
|
||||||
*/
|
*/
|
||||||
function FileProperties(filePath) {
|
FileProperties = function(filePath) {
|
||||||
this.filePath = filePath;
|
this.filePath = filePath;
|
||||||
this.size = 0;
|
this.size = 0;
|
||||||
this.lastModifiedDate = null;
|
this.lastModifiedDate = null;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a single file.
|
* Represents a single file.
|
||||||
@@ -31,33 +29,17 @@ function FileProperties(filePath) {
|
|||||||
* lastModifiedDate {Date} last modified date
|
* lastModifiedDate {Date} last modified date
|
||||||
* size {Number} size of the file in bytes
|
* size {Number} size of the file in bytes
|
||||||
*/
|
*/
|
||||||
function File(name, fullPath, type, lastModifiedDate, size) {
|
File = function(name, fullPath, type, lastModifiedDate, size) {
|
||||||
this.name = name || null;
|
this.name = name || null;
|
||||||
this.fullPath = fullPath || null;
|
this.fullPath = fullPath || null;
|
||||||
this.type = type || null;
|
this.type = type || null;
|
||||||
this.lastModifiedDate = lastModifiedDate || null;
|
this.lastModifiedDate = lastModifiedDate || null;
|
||||||
this.size = size || 0;
|
this.size = size || 0;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an event object since we can't set target on DOM event.
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
* @param target
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
File._createEvent = function(type, target) {
|
|
||||||
// Can't create event object, since we can't set target (its readonly)
|
|
||||||
//var evt = document.createEvent('Events');
|
|
||||||
//evt.initEvent("onload", false, false);
|
|
||||||
var evt = {"type": type};
|
|
||||||
evt.target = target;
|
|
||||||
return evt;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function FileError() {
|
FileError = function() {
|
||||||
this.code = null;
|
this.code = null;
|
||||||
}
|
};
|
||||||
|
|
||||||
// File error codes
|
// File error codes
|
||||||
// Found in DOMException
|
// Found in DOMException
|
||||||
@@ -80,8 +62,8 @@ FileError.PATH_EXISTS_ERR = 12;
|
|||||||
// File manager
|
// File manager
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
function FileMgr() {
|
FileMgr = function() {
|
||||||
}
|
};
|
||||||
|
|
||||||
FileMgr.prototype.getFileProperties = function(filePath) {
|
FileMgr.prototype.getFileProperties = function(filePath) {
|
||||||
return PhoneGap.exec(null, null, "File", "getFileProperties", [filePath]);
|
return PhoneGap.exec(null, null, "File", "getFileProperties", [filePath]);
|
||||||
@@ -145,7 +127,7 @@ PhoneGap.addConstructor(function() {
|
|||||||
* The root directory is the root of the file system.
|
* The root directory is the root of the file system.
|
||||||
* To read from the SD card, the file name is "sdcard/my_file.txt"
|
* To read from the SD card, the file name is "sdcard/my_file.txt"
|
||||||
*/
|
*/
|
||||||
function FileReader() {
|
FileReader = function() {
|
||||||
this.fileName = "";
|
this.fileName = "";
|
||||||
|
|
||||||
this.readyState = 0;
|
this.readyState = 0;
|
||||||
@@ -163,7 +145,7 @@ function FileReader() {
|
|||||||
this.onerror = null; // When the read has failed (see errors).
|
this.onerror = null; // When the read has failed (see errors).
|
||||||
this.onloadend = null; // When the request has completed (either in success or failure).
|
this.onloadend = null; // When the request has completed (either in success or failure).
|
||||||
this.onabort = null; // When the read has been aborted. For instance, by invoking the abort() method.
|
this.onabort = null; // When the read has been aborted. For instance, by invoking the abort() method.
|
||||||
}
|
};
|
||||||
|
|
||||||
// States
|
// States
|
||||||
FileReader.EMPTY = 0;
|
FileReader.EMPTY = 0;
|
||||||
@@ -185,18 +167,15 @@ FileReader.prototype.abort = function() {
|
|||||||
|
|
||||||
// If error callback
|
// If error callback
|
||||||
if (typeof this.onerror === "function") {
|
if (typeof this.onerror === "function") {
|
||||||
evt = File._createEvent("error", this);
|
this.onerror({"type":"error", "target":this});
|
||||||
this.onerror(evt);
|
|
||||||
}
|
}
|
||||||
// If abort callback
|
// If abort callback
|
||||||
if (typeof this.onabort === "function") {
|
if (typeof this.onabort === "function") {
|
||||||
evt = File._createEvent("abort", this);
|
this.oneabort({"type":"abort", "target":this});
|
||||||
this.onabort(evt);
|
|
||||||
}
|
}
|
||||||
// If load end callback
|
// If load end callback
|
||||||
if (typeof this.onloadend === "function") {
|
if (typeof this.onloadend === "function") {
|
||||||
evt = File._createEvent("loadend", this);
|
this.onloadend({"type":"loadend", "target":this});
|
||||||
this.onloadend(evt);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -219,8 +198,7 @@ FileReader.prototype.readAsText = function(file, encoding) {
|
|||||||
|
|
||||||
// If loadstart callback
|
// If loadstart callback
|
||||||
if (typeof this.onloadstart === "function") {
|
if (typeof this.onloadstart === "function") {
|
||||||
var evt = File._createEvent("loadstart", this);
|
this.onloadstart({"type":"loadstart", "target":this});
|
||||||
this.onloadstart(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default encoding is UTF-8
|
// Default encoding is UTF-8
|
||||||
@@ -245,8 +223,7 @@ FileReader.prototype.readAsText = function(file, encoding) {
|
|||||||
|
|
||||||
// If onload callback
|
// If onload callback
|
||||||
if (typeof me.onload === "function") {
|
if (typeof me.onload === "function") {
|
||||||
evt = File._createEvent("load", me);
|
me.onload({"type":"load", "target":me});
|
||||||
me.onload(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@@ -254,8 +231,7 @@ FileReader.prototype.readAsText = function(file, encoding) {
|
|||||||
|
|
||||||
// If onloadend callback
|
// If onloadend callback
|
||||||
if (typeof me.onloadend === "function") {
|
if (typeof me.onloadend === "function") {
|
||||||
evt = File._createEvent("loadend", me);
|
me.onloadend({"type":"loadend", "target":me});
|
||||||
me.onloadend(evt);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -268,12 +244,13 @@ FileReader.prototype.readAsText = function(file, encoding) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save error
|
// Save error
|
||||||
me.error = e;
|
var fileError = new FileError();
|
||||||
|
fileError.code = e;
|
||||||
|
me.error = fileError;
|
||||||
|
|
||||||
// If onerror callback
|
// If onerror callback
|
||||||
if (typeof me.onerror === "function") {
|
if (typeof me.onerror === "function") {
|
||||||
evt = File._createEvent("error", me);
|
me.onerror({"type":"error", "target":me});
|
||||||
me.onerror(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@@ -281,8 +258,7 @@ FileReader.prototype.readAsText = function(file, encoding) {
|
|||||||
|
|
||||||
// If onloadend callback
|
// If onloadend callback
|
||||||
if (typeof me.onloadend === "function") {
|
if (typeof me.onloadend === "function") {
|
||||||
evt = File._createEvent("loadend", me);
|
me.onloadend({"type":"loadend", "target":me});
|
||||||
me.onloadend(evt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -309,8 +285,7 @@ FileReader.prototype.readAsDataURL = function(file) {
|
|||||||
|
|
||||||
// If loadstart callback
|
// If loadstart callback
|
||||||
if (typeof this.onloadstart === "function") {
|
if (typeof this.onloadstart === "function") {
|
||||||
var evt = File._createEvent("loadstart", this);
|
this.onloadstart({"type":"loadstart", "target":this});
|
||||||
this.onloadstart(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var me = this;
|
var me = this;
|
||||||
@@ -332,8 +307,7 @@ FileReader.prototype.readAsDataURL = function(file) {
|
|||||||
|
|
||||||
// If onload callback
|
// If onload callback
|
||||||
if (typeof me.onload === "function") {
|
if (typeof me.onload === "function") {
|
||||||
evt = File._createEvent("load", me);
|
me.onload({"type":"load", "target":me});
|
||||||
me.onload(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@@ -341,8 +315,7 @@ FileReader.prototype.readAsDataURL = function(file) {
|
|||||||
|
|
||||||
// If onloadend callback
|
// If onloadend callback
|
||||||
if (typeof me.onloadend === "function") {
|
if (typeof me.onloadend === "function") {
|
||||||
evt = File._createEvent("loadend", me);
|
me.onloadend({"type":"loadend", "target":me});
|
||||||
me.onloadend(evt);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -355,12 +328,13 @@ FileReader.prototype.readAsDataURL = function(file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save error
|
// Save error
|
||||||
me.error = e;
|
var fileError = new FileError();
|
||||||
|
fileError.code = e;
|
||||||
|
me.error = fileError;
|
||||||
|
|
||||||
// If onerror callback
|
// If onerror callback
|
||||||
if (typeof me.onerror === "function") {
|
if (typeof me.onerror === "function") {
|
||||||
evt = File._createEvent("error", me);
|
me.onerror({"type":"error", "target":me});
|
||||||
me.onerror(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@@ -368,8 +342,7 @@ FileReader.prototype.readAsDataURL = function(file) {
|
|||||||
|
|
||||||
// If onloadend callback
|
// If onloadend callback
|
||||||
if (typeof me.onloadend === "function") {
|
if (typeof me.onloadend === "function") {
|
||||||
evt = File._createEvent("loadend", me);
|
me.onloadend({"type":"loadend", "target":me});
|
||||||
me.onloadend(evt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -409,7 +382,7 @@ FileReader.prototype.readAsArrayBuffer = function(file) {
|
|||||||
* @param file {File} File object containing file properties
|
* @param file {File} File object containing file properties
|
||||||
* @param append if true write to the end of the file, otherwise overwrite the file
|
* @param append if true write to the end of the file, otherwise overwrite the file
|
||||||
*/
|
*/
|
||||||
function FileWriter(file) {
|
FileWriter = function(file) {
|
||||||
this.fileName = "";
|
this.fileName = "";
|
||||||
this.length = 0;
|
this.length = 0;
|
||||||
if (file) {
|
if (file) {
|
||||||
@@ -433,7 +406,7 @@ function FileWriter(file) {
|
|||||||
this.onwriteend = null; // When the request has completed (either in success or failure).
|
this.onwriteend = null; // When the request has completed (either in success or failure).
|
||||||
this.onabort = null; // When the write has been aborted. For instance, by invoking the abort() method.
|
this.onabort = null; // When the write has been aborted. For instance, by invoking the abort() method.
|
||||||
this.onerror = null; // When the write has failed (see errors).
|
this.onerror = null; // When the write has failed (see errors).
|
||||||
}
|
};
|
||||||
|
|
||||||
// States
|
// States
|
||||||
FileWriter.INIT = 0;
|
FileWriter.INIT = 0;
|
||||||
@@ -456,115 +429,21 @@ FileWriter.prototype.abort = function() {
|
|||||||
|
|
||||||
// If error callback
|
// If error callback
|
||||||
if (typeof this.onerror === "function") {
|
if (typeof this.onerror === "function") {
|
||||||
evt = File._createEvent("error", this);
|
this.onerror({"type":"error", "target":this});
|
||||||
this.onerror(evt);
|
|
||||||
}
|
}
|
||||||
// If abort callback
|
// If abort callback
|
||||||
if (typeof this.onabort === "function") {
|
if (typeof this.onabort === "function") {
|
||||||
evt = File._createEvent("abort", this);
|
this.oneabort({"type":"abort", "target":this});
|
||||||
this.onabort(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.readyState = FileWriter.DONE;
|
this.readyState = FileWriter.DONE;
|
||||||
|
|
||||||
// If write end callback
|
// If write end callback
|
||||||
if (typeof this.onwriteend == "function") {
|
if (typeof this.onwriteend == "function") {
|
||||||
evt = File._createEvent("writeend", this);
|
this.onwriteend({"type":"writeend", "target":this});
|
||||||
this.onwriteend(evt);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @Deprecated: use write instead
|
|
||||||
*
|
|
||||||
* @param file to write the data to
|
|
||||||
* @param text to be written
|
|
||||||
* @param bAppend if true write to end of file, otherwise overwrite the file
|
|
||||||
*/
|
|
||||||
FileWriter.prototype.writeAsText = function(file, text, bAppend) {
|
|
||||||
// Throw an exception if we are already writing a file
|
|
||||||
if (this.readyState === FileWriter.WRITING) {
|
|
||||||
throw FileError.INVALID_STATE_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bAppend !== true) {
|
|
||||||
bAppend = false; // for null values
|
|
||||||
}
|
|
||||||
|
|
||||||
this.fileName = file;
|
|
||||||
|
|
||||||
// WRITING state
|
|
||||||
this.readyState = FileWriter.WRITING;
|
|
||||||
|
|
||||||
var me = this;
|
|
||||||
|
|
||||||
// If onwritestart callback
|
|
||||||
if (typeof me.onwritestart === "function") {
|
|
||||||
var evt = File._createEvent("writestart", me);
|
|
||||||
me.onwritestart(evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write file
|
|
||||||
navigator.fileMgr.writeAsText(file, text, bAppend,
|
|
||||||
|
|
||||||
// Success callback
|
|
||||||
function(r) {
|
|
||||||
var evt;
|
|
||||||
|
|
||||||
// If DONE (cancelled), then don't do anything
|
|
||||||
if (me.readyState === FileWriter.DONE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save result
|
|
||||||
me.result = r;
|
|
||||||
|
|
||||||
// If onwrite callback
|
|
||||||
if (typeof me.onwrite === "function") {
|
|
||||||
evt = File._createEvent("write", me);
|
|
||||||
me.onwrite(evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DONE state
|
|
||||||
me.readyState = FileWriter.DONE;
|
|
||||||
|
|
||||||
// If onwriteend callback
|
|
||||||
if (typeof me.onwriteend === "function") {
|
|
||||||
evt = File._createEvent("writeend", me);
|
|
||||||
me.onwriteend(evt);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// Error callback
|
|
||||||
function(e) {
|
|
||||||
var evt;
|
|
||||||
|
|
||||||
// If DONE (cancelled), then don't do anything
|
|
||||||
if (me.readyState === FileWriter.DONE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save error
|
|
||||||
me.error = e;
|
|
||||||
|
|
||||||
// If onerror callback
|
|
||||||
if (typeof me.onerror === "function") {
|
|
||||||
evt = File._createEvent("error", me);
|
|
||||||
me.onerror(evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DONE state
|
|
||||||
me.readyState = FileWriter.DONE;
|
|
||||||
|
|
||||||
// If onwriteend callback
|
|
||||||
if (typeof me.onwriteend === "function") {
|
|
||||||
evt = File._createEvent("writeend", me);
|
|
||||||
me.onwriteend(evt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes data to the file
|
* Writes data to the file
|
||||||
*
|
*
|
||||||
@@ -583,8 +462,7 @@ FileWriter.prototype.write = function(text) {
|
|||||||
|
|
||||||
// If onwritestart callback
|
// If onwritestart callback
|
||||||
if (typeof me.onwritestart === "function") {
|
if (typeof me.onwritestart === "function") {
|
||||||
var evt = File._createEvent("writestart", me);
|
me.onwritestart({"type":"writestart", "target":me});
|
||||||
me.onwritestart(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write file
|
// Write file
|
||||||
@@ -605,8 +483,7 @@ FileWriter.prototype.write = function(text) {
|
|||||||
|
|
||||||
// If onwrite callback
|
// If onwrite callback
|
||||||
if (typeof me.onwrite === "function") {
|
if (typeof me.onwrite === "function") {
|
||||||
evt = File._createEvent("write", me);
|
me.onwrite({"type":"write", "target":me});
|
||||||
me.onwrite(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@@ -614,8 +491,7 @@ FileWriter.prototype.write = function(text) {
|
|||||||
|
|
||||||
// If onwriteend callback
|
// If onwriteend callback
|
||||||
if (typeof me.onwriteend === "function") {
|
if (typeof me.onwriteend === "function") {
|
||||||
evt = File._createEvent("writeend", me);
|
me.onwriteend({"type":"writeend", "target":me});
|
||||||
me.onwriteend(evt);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -629,12 +505,13 @@ FileWriter.prototype.write = function(text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save error
|
// Save error
|
||||||
me.error = e;
|
var fileError = new FileError();
|
||||||
|
fileError.code = e;
|
||||||
|
me.error = fileError;
|
||||||
|
|
||||||
// If onerror callback
|
// If onerror callback
|
||||||
if (typeof me.onerror === "function") {
|
if (typeof me.onerror === "function") {
|
||||||
evt = File._createEvent("error", me);
|
me.onerror({"type":"error", "target":me});
|
||||||
me.onerror(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@@ -642,8 +519,7 @@ FileWriter.prototype.write = function(text) {
|
|||||||
|
|
||||||
// If onwriteend callback
|
// If onwriteend callback
|
||||||
if (typeof me.onwriteend === "function") {
|
if (typeof me.onwriteend === "function") {
|
||||||
evt = File._createEvent("writeend", me);
|
me.onwriteend({"type":"writeend", "target":me});
|
||||||
me.onwriteend(evt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -703,8 +579,7 @@ FileWriter.prototype.truncate = function(size) {
|
|||||||
|
|
||||||
// If onwritestart callback
|
// If onwritestart callback
|
||||||
if (typeof me.onwritestart === "function") {
|
if (typeof me.onwritestart === "function") {
|
||||||
var evt = File._createEvent("writestart", me);
|
me.onwritestart({"type":"writestart", "target":this});
|
||||||
me.onwritestart(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write file
|
// Write file
|
||||||
@@ -724,8 +599,7 @@ FileWriter.prototype.truncate = function(size) {
|
|||||||
|
|
||||||
// If onwrite callback
|
// If onwrite callback
|
||||||
if (typeof me.onwrite === "function") {
|
if (typeof me.onwrite === "function") {
|
||||||
evt = File._createEvent("write", me);
|
me.onwrite({"type":"write", "target":me});
|
||||||
me.onwrite(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@@ -733,8 +607,7 @@ FileWriter.prototype.truncate = function(size) {
|
|||||||
|
|
||||||
// If onwriteend callback
|
// If onwriteend callback
|
||||||
if (typeof me.onwriteend === "function") {
|
if (typeof me.onwriteend === "function") {
|
||||||
evt = File._createEvent("writeend", me);
|
me.onwriteend({"type":"writeend", "target":me});
|
||||||
me.onwriteend(evt);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -747,12 +620,13 @@ FileWriter.prototype.truncate = function(size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save error
|
// Save error
|
||||||
me.error = e;
|
var fileError = new FileError();
|
||||||
|
fileError.code = e;
|
||||||
|
me.error = fileError;
|
||||||
|
|
||||||
// If onerror callback
|
// If onerror callback
|
||||||
if (typeof me.onerror === "function") {
|
if (typeof me.onerror === "function") {
|
||||||
evt = File._createEvent("error", me);
|
me.onerror({"type":"error", "target":me});
|
||||||
me.onerror(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DONE state
|
// DONE state
|
||||||
@@ -760,14 +634,13 @@ FileWriter.prototype.truncate = function(size) {
|
|||||||
|
|
||||||
// If onwriteend callback
|
// If onwriteend callback
|
||||||
if (typeof me.onwriteend === "function") {
|
if (typeof me.onwriteend === "function") {
|
||||||
evt = File._createEvent("writeend", me);
|
me.onwriteend({"type":"writeend", "target":me});
|
||||||
me.onwriteend(evt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
function LocalFileSystem() {
|
LocalFileSystem = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
// File error codes
|
// File error codes
|
||||||
@@ -894,7 +767,7 @@ LocalFileSystem.prototype._castDate = function(pluginResult) {
|
|||||||
*
|
*
|
||||||
* {Date} modificationTime (readonly)
|
* {Date} modificationTime (readonly)
|
||||||
*/
|
*/
|
||||||
function Metadata() {
|
Metadata = function() {
|
||||||
this.modificationTime=null;
|
this.modificationTime=null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -904,7 +777,7 @@ function Metadata() {
|
|||||||
* @param {boolean} create file or directory if it doesn't exist
|
* @param {boolean} create file or directory if it doesn't exist
|
||||||
* @param {boolean} exclusive if true the command will fail if the file or directory exists
|
* @param {boolean} exclusive if true the command will fail if the file or directory exists
|
||||||
*/
|
*/
|
||||||
function Flags(create, exclusive) {
|
Flags = function(create, exclusive) {
|
||||||
this.create = create || false;
|
this.create = create || false;
|
||||||
this.exclusive = exclusive || false;
|
this.exclusive = exclusive || false;
|
||||||
};
|
};
|
||||||
@@ -915,7 +788,7 @@ function Flags(create, exclusive) {
|
|||||||
* {DOMString} name the unique name of the file system (readonly)
|
* {DOMString} name the unique name of the file system (readonly)
|
||||||
* {DirectoryEntry} root directory of the file system (readonly)
|
* {DirectoryEntry} root directory of the file system (readonly)
|
||||||
*/
|
*/
|
||||||
function FileSystem() {
|
FileSystem = function() {
|
||||||
this.name = null;
|
this.name = null;
|
||||||
this.root = null;
|
this.root = null;
|
||||||
};
|
};
|
||||||
@@ -929,7 +802,7 @@ function FileSystem() {
|
|||||||
* {DOMString} fullPath the absolute full path to the directory (readonly)
|
* {DOMString} fullPath the absolute full path to the directory (readonly)
|
||||||
* {FileSystem} filesystem on which the directory resides (readonly)
|
* {FileSystem} filesystem on which the directory resides (readonly)
|
||||||
*/
|
*/
|
||||||
function DirectoryEntry() {
|
DirectoryEntry = function() {
|
||||||
this.isFile = false;
|
this.isFile = false;
|
||||||
this.isDirectory = true;
|
this.isDirectory = true;
|
||||||
this.name = null;
|
this.name = null;
|
||||||
@@ -1045,7 +918,7 @@ DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCall
|
|||||||
/**
|
/**
|
||||||
* An interface that lists the files and directories in a directory.
|
* An interface that lists the files and directories in a directory.
|
||||||
*/
|
*/
|
||||||
function DirectoryReader(fullPath){
|
DirectoryReader = function(fullPath){
|
||||||
this.fullPath = fullPath || null;
|
this.fullPath = fullPath || null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1068,7 +941,7 @@ DirectoryReader.prototype.readEntries = function(successCallback, errorCallback)
|
|||||||
* {DOMString} fullPath the absolute full path to the file (readonly)
|
* {DOMString} fullPath the absolute full path to the file (readonly)
|
||||||
* {FileSystem} filesystem on which the directory resides (readonly)
|
* {FileSystem} filesystem on which the directory resides (readonly)
|
||||||
*/
|
*/
|
||||||
function FileEntry() {
|
FileEntry = function() {
|
||||||
this.isFile = true;
|
this.isFile = true;
|
||||||
this.isDirectory = false;
|
this.isDirectory = false;
|
||||||
this.name = null;
|
this.name = null;
|
||||||
@@ -1182,3 +1055,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
if(typeof window.requestFileSystem == "undefined") window.requestFileSystem = pgLocalFileSystem.requestFileSystem;
|
if(typeof window.requestFileSystem == "undefined") window.requestFileSystem = pgLocalFileSystem.requestFileSystem;
|
||||||
if(typeof window.resolveLocalFileSystemURI == "undefined") window.resolveLocalFileSystemURI = pgLocalFileSystem.resolveLocalFileSystemURI;
|
if(typeof window.resolveLocalFileSystemURI == "undefined") window.resolveLocalFileSystemURI = pgLocalFileSystem.resolveLocalFileSystemURI;
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,26 +6,29 @@
|
|||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!PhoneGap.hasResource("filetransfer")) {
|
||||||
|
PhoneGap.addResource("filetransfer");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FileTransfer uploads a file to a remote server.
|
* FileTransfer uploads a file to a remote server.
|
||||||
*/
|
*/
|
||||||
function FileTransfer() {}
|
FileTransfer = function() {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FileUploadResult
|
* FileUploadResult
|
||||||
*/
|
*/
|
||||||
function FileUploadResult() {
|
FileUploadResult = function() {
|
||||||
this.bytesSent = 0;
|
this.bytesSent = 0;
|
||||||
this.responseCode = null;
|
this.responseCode = null;
|
||||||
this.response = null;
|
this.response = null;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FileTransferError
|
* FileTransferError
|
||||||
*/
|
*/
|
||||||
function FileTransferError() {
|
FileTransferError = function() {
|
||||||
this.code = null;
|
this.code = null;
|
||||||
}
|
};
|
||||||
|
|
||||||
FileTransferError.FILE_NOT_FOUND_ERR = 1;
|
FileTransferError.FILE_NOT_FOUND_ERR = 1;
|
||||||
FileTransferError.INVALID_URL_ERR = 2;
|
FileTransferError.INVALID_URL_ERR = 2;
|
||||||
@@ -69,9 +72,10 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
|
|||||||
* @param mimeType {String} Mimetype of the uploaded file. Defaults to image/jpeg.
|
* @param mimeType {String} Mimetype of the uploaded file. Defaults to image/jpeg.
|
||||||
* @param params {Object} Object with key: value params to send to the server.
|
* @param params {Object} Object with key: value params to send to the server.
|
||||||
*/
|
*/
|
||||||
function FileUploadOptions(fileKey, fileName, mimeType, params) {
|
FileUploadOptions = function(fileKey, fileName, mimeType, params) {
|
||||||
this.fileKey = fileKey || null;
|
this.fileKey = fileKey || null;
|
||||||
this.fileName = fileName || null;
|
this.fileName = fileName || null;
|
||||||
this.mimeType = mimeType || null;
|
this.mimeType = mimeType || null;
|
||||||
this.params = params || null;
|
this.params = params || null;
|
||||||
}
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,18 +6,21 @@
|
|||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!PhoneGap.hasResource("geolocation")) {
|
||||||
|
PhoneGap.addResource("geolocation");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides access to device GPS data.
|
* This class provides access to device GPS data.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function Geolocation() {
|
Geolocation = function() {
|
||||||
|
|
||||||
// The last known GPS position.
|
// The last known GPS position.
|
||||||
this.lastPosition = null;
|
this.lastPosition = null;
|
||||||
|
|
||||||
// Geolocation listeners
|
// Geolocation listeners
|
||||||
this.listeners = {};
|
this.listeners = {};
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Position error object
|
* Position error object
|
||||||
@@ -25,10 +28,10 @@ function Geolocation() {
|
|||||||
* @param code
|
* @param code
|
||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
function PositionError(code, message) {
|
PositionError = function(code, message) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
};
|
||||||
|
|
||||||
PositionError.PERMISSION_DENIED = 1;
|
PositionError.PERMISSION_DENIED = 1;
|
||||||
PositionError.POSITION_UNAVAILABLE = 2;
|
PositionError.POSITION_UNAVAILABLE = 2;
|
||||||
@@ -191,4 +194,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
Geolocation.usingPhoneGap = true;
|
Geolocation.usingPhoneGap = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!PhoneGap.hasResource("media")) {
|
||||||
|
PhoneGap.addResource("media");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of media objects.
|
* List of media objects.
|
||||||
* PRIVATE
|
* PRIVATE
|
||||||
@@ -128,10 +131,10 @@ Media.MEDIA_MSG = ["None", "Starting", "Running", "Paused", "Stopped"];
|
|||||||
* This class contains information about any Media errors.
|
* This class contains information about any Media errors.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function MediaError() {
|
MediaError = function() {
|
||||||
this.code = null;
|
this.code = null;
|
||||||
this.message = "";
|
this.message = "";
|
||||||
}
|
};
|
||||||
|
|
||||||
MediaError.MEDIA_ERR_ABORTED = 1;
|
MediaError.MEDIA_ERR_ABORTED = 1;
|
||||||
MediaError.MEDIA_ERR_NETWORK = 2;
|
MediaError.MEDIA_ERR_NETWORK = 2;
|
||||||
@@ -198,4 +201,4 @@ Media.prototype.stopRecord = function() {
|
|||||||
Media.prototype.release = function() {
|
Media.prototype.release = function() {
|
||||||
PhoneGap.exec(null, null, "Media", "release", [this.id]);
|
PhoneGap.exec(null, null, "Media", "release", [this.id]);
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,14 +6,17 @@
|
|||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!PhoneGap.hasResource("network")) {
|
||||||
|
PhoneGap.addResource("network");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class contains information about any NetworkStatus.
|
* This class contains information about any NetworkStatus.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function NetworkStatus() {
|
NetworkStatus = function() {
|
||||||
//this.code = null;
|
//this.code = null;
|
||||||
//this.message = "";
|
//this.message = "";
|
||||||
}
|
};
|
||||||
|
|
||||||
NetworkStatus.NOT_REACHABLE = 0;
|
NetworkStatus.NOT_REACHABLE = 0;
|
||||||
NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK = 1;
|
NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK = 1;
|
||||||
@@ -23,14 +26,14 @@ NetworkStatus.REACHABLE_VIA_WIFI_NETWORK = 2;
|
|||||||
* This class provides access to device Network data (reachability).
|
* This class provides access to device Network data (reachability).
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function Network() {
|
Network = function() {
|
||||||
/**
|
/**
|
||||||
* The last known Network status.
|
* The last known Network status.
|
||||||
* { hostName: string, ipAddress: string,
|
* { hostName: string, ipAddress: string,
|
||||||
remoteHostStatus: int(0/1/2), internetConnectionStatus: int(0/1/2), localWiFiConnectionStatus: int (0/2) }
|
remoteHostStatus: int(0/1/2), internetConnectionStatus: int(0/1/2), localWiFiConnectionStatus: int (0/2) }
|
||||||
*/
|
*/
|
||||||
this.lastReachability = null;
|
this.lastReachability = null;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the geolocation framework when the reachability status has changed.
|
* Called by the geolocation framework when the reachability status has changed.
|
||||||
@@ -61,4 +64,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.network = new Network();
|
navigator.network = new Network();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,11 +6,14 @@
|
|||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!PhoneGap.hasResource("notification")) {
|
||||||
|
PhoneGap.addResource("notification");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides access to notifications on the device.
|
* This class provides access to notifications on the device.
|
||||||
*/
|
*/
|
||||||
function Notification() {
|
Notification = function() {
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a native alert dialog, with a customizable title and button text.
|
* Open a native alert dialog, with a customizable title and button text.
|
||||||
@@ -115,4 +118,4 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator.notification = new Notification();
|
navigator.notification = new Notification();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
* Copyright (c) 2010-2011, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (typeof PhoneGap === "undefined") {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The order of events during page load and PhoneGap startup is as follows:
|
* The order of events during page load and PhoneGap startup is as follows:
|
||||||
@@ -18,6 +19,8 @@
|
|||||||
* onPhoneGapInfoReady Internal event fired when device properties are available
|
* onPhoneGapInfoReady Internal event fired when device properties are available
|
||||||
* onDeviceReady User event fired to indicate that PhoneGap is ready
|
* onDeviceReady User event fired to indicate that PhoneGap is ready
|
||||||
* onResume User event fired to indicate a start/resume lifecycle event
|
* onResume User event fired to indicate a start/resume lifecycle event
|
||||||
|
* onPause User event fired to indicate a pause lifecycle event
|
||||||
|
* onDestroy Internal event fired when app is being destroyed (User should use window.onunload event, not this one).
|
||||||
*
|
*
|
||||||
* The only PhoneGap events that user code should register for are:
|
* The only PhoneGap events that user code should register for are:
|
||||||
* onDeviceReady
|
* onDeviceReady
|
||||||
@@ -26,6 +29,7 @@
|
|||||||
* Listeners can be registered as:
|
* Listeners can be registered as:
|
||||||
* document.addEventListener("deviceready", myDeviceReadyListener, false);
|
* document.addEventListener("deviceready", myDeviceReadyListener, false);
|
||||||
* document.addEventListener("resume", myResumeListener, false);
|
* document.addEventListener("resume", myResumeListener, false);
|
||||||
|
* document.addEventListener("pause", myPauseListener, false);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (typeof(DeviceInfo) !== 'object') {
|
if (typeof(DeviceInfo) !== 'object') {
|
||||||
@@ -45,6 +49,30 @@ var PhoneGap = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of resource files loaded by PhoneGap.
|
||||||
|
* This is used to ensure JS and other files are loaded only once.
|
||||||
|
*/
|
||||||
|
PhoneGap.resources = {base: true};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if resource has been loaded by PhoneGap
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PhoneGap.hasResource = function(name) {
|
||||||
|
return PhoneGap.resources[name];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a resource to list of loaded resources by PhoneGap
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
PhoneGap.addResource = function(name) {
|
||||||
|
PhoneGap.resources[name] = true;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom pub-sub channel that can have functions subscribed to it
|
* Custom pub-sub channel that can have functions subscribed to it
|
||||||
@@ -241,6 +269,17 @@ PhoneGap.onResume = new PhoneGap.Channel('onResume');
|
|||||||
*/
|
*/
|
||||||
PhoneGap.onPause = new PhoneGap.Channel('onPause');
|
PhoneGap.onPause = new PhoneGap.Channel('onPause');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* onDestroy channel is fired when the PhoneGap native code
|
||||||
|
* is destroyed. It is used internally.
|
||||||
|
* Window.onunload should be used by the user.
|
||||||
|
*/
|
||||||
|
PhoneGap.onDestroy = new PhoneGap.Channel('onDestroy');
|
||||||
|
PhoneGap.onDestroy.subscribeOnce(function() {
|
||||||
|
PhoneGap.shuttingDown = true;
|
||||||
|
});
|
||||||
|
PhoneGap.shuttingDown = false;
|
||||||
|
|
||||||
// _nativeReady is global variable that the native side can set
|
// _nativeReady is global variable that the native side can set
|
||||||
// to signify that the native code is ready. It is a global since
|
// to signify that the native code is ready. It is a global since
|
||||||
// it may be called before any PhoneGap JS is ready.
|
// it may be called before any PhoneGap JS is ready.
|
||||||
@@ -696,6 +735,11 @@ PhoneGap.JSCallbackToken = null;
|
|||||||
*/
|
*/
|
||||||
PhoneGap.JSCallback = function() {
|
PhoneGap.JSCallback = function() {
|
||||||
|
|
||||||
|
// Exit if shutting down app
|
||||||
|
if (PhoneGap.shuttingDown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If polling flag was changed, start using polling from now on
|
// If polling flag was changed, start using polling from now on
|
||||||
if (PhoneGap.UsePolling) {
|
if (PhoneGap.UsePolling) {
|
||||||
PhoneGap.JSCallbackPolling();
|
PhoneGap.JSCallbackPolling();
|
||||||
@@ -707,11 +751,17 @@ PhoneGap.JSCallback = function() {
|
|||||||
// Callback function when XMLHttpRequest is ready
|
// Callback function when XMLHttpRequest is ready
|
||||||
xmlhttp.onreadystatechange=function(){
|
xmlhttp.onreadystatechange=function(){
|
||||||
if(xmlhttp.readyState === 4){
|
if(xmlhttp.readyState === 4){
|
||||||
|
|
||||||
|
// Exit if shutting down app
|
||||||
|
if (PhoneGap.shuttingDown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If callback has JavaScript statement to execute
|
// If callback has JavaScript statement to execute
|
||||||
if (xmlhttp.status === 200) {
|
if (xmlhttp.status === 200) {
|
||||||
|
|
||||||
var msg = xmlhttp.responseText;
|
// Need to url decode the response and replace %20 with a space
|
||||||
|
var msg = decodeURIComponent(xmlhttp.responseText.replace(/\+/g, '%20'));
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
try {
|
try {
|
||||||
var t = eval(msg);
|
var t = eval(msg);
|
||||||
@@ -786,6 +836,11 @@ PhoneGap.UsePolling = false; // T=use polling, F=use XHR
|
|||||||
*/
|
*/
|
||||||
PhoneGap.JSCallbackPolling = function() {
|
PhoneGap.JSCallbackPolling = function() {
|
||||||
|
|
||||||
|
// Exit if shutting down app
|
||||||
|
if (PhoneGap.shuttingDown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If polling flag was changed, stop using polling from now on
|
// If polling flag was changed, stop using polling from now on
|
||||||
if (!PhoneGap.UsePolling) {
|
if (!PhoneGap.UsePolling) {
|
||||||
PhoneGap.JSCallback();
|
PhoneGap.JSCallback();
|
||||||
@@ -864,3 +919,17 @@ PhoneGap.includeJavascript = function(jsfile, successCallback) {
|
|||||||
el.src = jsfile;
|
el.src = jsfile;
|
||||||
id.appendChild(el);
|
id.appendChild(el);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is provided to bridge the gap between the way plugins were setup in 0.9.3 and 0.9.4.
|
||||||
|
* Users should be calling navigator.add.addService() instead of PluginManager.addService().
|
||||||
|
* @class
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
var PluginManager = {
|
||||||
|
addService: function(serviceType, className) {
|
||||||
|
navigator.app.addService(serviceType, className);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010, IBM Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!PhoneGap.hasResource("position")) {
|
||||||
|
PhoneGap.addResource("position");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class contains position information.
|
* This class contains position information.
|
||||||
* @param {Object} lat
|
* @param {Object} lat
|
||||||
@@ -17,12 +20,12 @@
|
|||||||
* @param {Object} vel
|
* @param {Object} vel
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function Position(coords, timestamp) {
|
Position = function(coords, timestamp) {
|
||||||
this.coords = coords;
|
this.coords = coords;
|
||||||
this.timestamp = (timestamp !== 'undefined') ? timestamp : new Date().getTime();
|
this.timestamp = (timestamp !== 'undefined') ? timestamp : new Date().getTime();
|
||||||
}
|
};
|
||||||
|
|
||||||
function Coordinates(lat, lng, alt, acc, head, vel, altacc) {
|
Coordinates = function(lat, lng, alt, acc, head, vel, altacc) {
|
||||||
/**
|
/**
|
||||||
* The latitude of the position.
|
* The latitude of the position.
|
||||||
*/
|
*/
|
||||||
@@ -51,13 +54,13 @@ function Coordinates(lat, lng, alt, acc, head, vel, altacc) {
|
|||||||
* The altitude accuracy of the position.
|
* The altitude accuracy of the position.
|
||||||
*/
|
*/
|
||||||
this.altitudeAccuracy = (altacc !== 'undefined') ? altacc : null;
|
this.altitudeAccuracy = (altacc !== 'undefined') ? altacc : null;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class specifies the options for requesting position data.
|
* This class specifies the options for requesting position data.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function PositionOptions() {
|
PositionOptions = function() {
|
||||||
/**
|
/**
|
||||||
* Specifies the desired position accuracy.
|
* Specifies the desired position accuracy.
|
||||||
*/
|
*/
|
||||||
@@ -67,18 +70,19 @@ function PositionOptions() {
|
|||||||
* is called.
|
* is called.
|
||||||
*/
|
*/
|
||||||
this.timeout = 10000;
|
this.timeout = 10000;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class contains information about any GSP errors.
|
* This class contains information about any GSP errors.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function PositionError() {
|
PositionError = function() {
|
||||||
this.code = null;
|
this.code = null;
|
||||||
this.message = "";
|
this.message = "";
|
||||||
}
|
};
|
||||||
|
|
||||||
PositionError.UNKNOWN_ERROR = 0;
|
PositionError.UNKNOWN_ERROR = 0;
|
||||||
PositionError.PERMISSION_DENIED = 1;
|
PositionError.PERMISSION_DENIED = 1;
|
||||||
PositionError.POSITION_UNAVAILABLE = 2;
|
PositionError.POSITION_UNAVAILABLE = 2;
|
||||||
PositionError.TIMEOUT = 3;
|
PositionError.TIMEOUT = 3;
|
||||||
|
};
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
* most manufacturers ship with Android 1.5 and do not do OTA Updates, this is required
|
* most manufacturers ship with Android 1.5 and do not do OTA Updates, this is required
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!PhoneGap.hasResource("storage")) {
|
||||||
|
PhoneGap.addResource("storage");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Storage object that is called by native code when performing queries.
|
* Storage object that is called by native code when performing queries.
|
||||||
* PRIVATE METHOD
|
* PRIVATE METHOD
|
||||||
@@ -307,15 +310,21 @@ var CupcakeLocalStorage = function() {
|
|||||||
|
|
||||||
this.db = openDatabase('localStorage', '1.0', 'localStorage', 2621440);
|
this.db = openDatabase('localStorage', '1.0', 'localStorage', 2621440);
|
||||||
var storage = {};
|
var storage = {};
|
||||||
|
this.length = 0;
|
||||||
|
function setLength (length) {
|
||||||
|
this.length = length;
|
||||||
|
localStorage.length = length;
|
||||||
|
}
|
||||||
this.db.transaction(
|
this.db.transaction(
|
||||||
function (transaction) {
|
function (transaction) {
|
||||||
var i;
|
var i;
|
||||||
transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
|
transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
|
||||||
transaction.executeSql('SELECT * FROM storage', [], function(tx, result) {
|
transaction.executeSql('SELECT * FROM storage', [], function(tx, result) {
|
||||||
for(i = 0; i < result.rows.length; i++) {
|
for(var i = 0; i < result.rows.length; i++) {
|
||||||
storage[result.rows.item(i).id] = result.rows.item(i).body;
|
storage[result.rows.item(i)['id']] = result.rows.item(i)['body'];
|
||||||
}
|
}
|
||||||
PhoneGap.initializationComplete("cupcakeStorage");
|
setLength(result.rows.length);
|
||||||
|
PhoneGap.initializationComplete("cupcakeStorage");
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
@@ -324,13 +333,13 @@ var CupcakeLocalStorage = function() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
this.setItem = function(key, val) {
|
this.setItem = function(key, val) {
|
||||||
//console.log('set');
|
if (typeof(storage[key])=='undefined') {
|
||||||
|
this.length++;
|
||||||
|
}
|
||||||
storage[key] = val;
|
storage[key] = val;
|
||||||
|
|
||||||
this.db.transaction(
|
this.db.transaction(
|
||||||
function (transaction) {
|
function (transaction) {
|
||||||
transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
|
transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
|
||||||
|
|
||||||
transaction.executeSql('REPLACE INTO storage (id, body) values(?,?)', [key,val]);
|
transaction.executeSql('REPLACE INTO storage (id, body) values(?,?)', [key,val]);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -340,38 +349,62 @@ var CupcakeLocalStorage = function() {
|
|||||||
};
|
};
|
||||||
this.removeItem = function(key) {
|
this.removeItem = function(key) {
|
||||||
delete storage[key];
|
delete storage[key];
|
||||||
|
this.length--;
|
||||||
this.db.transaction(
|
this.db.transaction(
|
||||||
function (transaction) {
|
function (transaction) {
|
||||||
transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
|
transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
|
||||||
|
|
||||||
transaction.executeSql('DELETE FROM storage where id=?', [key]);
|
transaction.executeSql('DELETE FROM storage where id=?', [key]);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
this.clear = function() {
|
this.clear = function() {
|
||||||
storage = {};
|
storage = {};
|
||||||
|
this.length = 0;
|
||||||
this.db.transaction(
|
this.db.transaction(
|
||||||
function (transaction) {
|
function (transaction) {
|
||||||
transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
|
transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
|
||||||
|
|
||||||
transaction.executeSql('DELETE FROM storage', []);
|
transaction.executeSql('DELETE FROM storage', []);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
this.key = function(index) {
|
||||||
|
var i = 0;
|
||||||
|
for (var j in storage) {
|
||||||
|
if (i==index) {
|
||||||
|
return j;
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
alert("Database error "+e+".");
|
alert("Database error "+e+".");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
if (typeof window.openDatabase === "undefined") {
|
var setupDroidDB = function() {
|
||||||
navigator.openDatabase = window.openDatabase = DroidDB_openDatabase;
|
navigator.openDatabase = window.openDatabase = DroidDB_openDatabase;
|
||||||
window.droiddb = new DroidDB();
|
window.droiddb = new DroidDB();
|
||||||
}
|
}
|
||||||
|
if ((typeof window.openDatabase === "undefined") || (navigator.userAgent.indexOf("Android 3.0") != -1)) {
|
||||||
|
setupDroidDB();
|
||||||
|
} else {
|
||||||
|
window.openDatabase_orig = window.openDatabase;
|
||||||
|
window.openDatabase = function(name, version, desc, size) {
|
||||||
|
var db = window.openDatabase_orig(name, version, desc, size);
|
||||||
|
if (db == null) {
|
||||||
|
setupDroidDB();
|
||||||
|
return DroidDB_openDatabase(name, version, desc, size);
|
||||||
|
} else return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof window.localStorage === "undefined") {
|
if (typeof window.localStorage === "undefined") {
|
||||||
navigator.localStorage = window.localStorage = new CupcakeLocalStorage();
|
navigator.localStorage = window.localStorage = new CupcakeLocalStorage();
|
||||||
PhoneGap.waitForInitialization("cupcakeStorage");
|
PhoneGap.waitForInitialization("cupcakeStorage");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title></title>
|
<title></title>
|
||||||
<script src="phonegap.0.9.4.min.js"></script>
|
<script src="phonegap.0.9.5.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -221,7 +222,10 @@ public class CallbackServer implements Runnable {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//System.out.println("CallbackServer -- sending item");
|
//System.out.println("CallbackServer -- sending item");
|
||||||
response = "HTTP/1.1 200 OK\r\n\r\n"+this.getJavascript();
|
response = "HTTP/1.1 200 OK\r\n\r\n";
|
||||||
|
String js = this.getJavascript();
|
||||||
|
if (js != null)
|
||||||
|
response += URLEncoder.encode(js, "UTF-8");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -0,0 +1,346 @@
|
|||||||
|
package com.phonegap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.media.MediaPlayer;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.phonegap.api.Plugin;
|
||||||
|
import com.phonegap.api.PluginResult;
|
||||||
|
|
||||||
|
public class Capture extends Plugin {
|
||||||
|
|
||||||
|
private static final String _DATA = "_data"; // The column name where the file path is stored
|
||||||
|
private static final int CAPTURE_AUDIO = 0; // Constant for capture audio
|
||||||
|
private static final int CAPTURE_IMAGE = 1; // Constant for capture image
|
||||||
|
private static final int CAPTURE_VIDEO = 2; // Constant for capture video
|
||||||
|
private static final String LOG_TAG = "Capture";
|
||||||
|
private String callbackId; // The ID of the callback to be invoked with our result
|
||||||
|
private long limit; // the number of pics/vids/clips to take
|
||||||
|
private double duration; // optional duration parameter for video recording
|
||||||
|
private JSONArray results; // The array of results to be returned to the user
|
||||||
|
private Uri imageUri; // Uri of captured image
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
|
this.callbackId = callbackId;
|
||||||
|
this.limit = 1;
|
||||||
|
this.duration = 0.0f;
|
||||||
|
this.results = new JSONArray();
|
||||||
|
|
||||||
|
JSONObject options = args.optJSONObject(0);
|
||||||
|
if (options != null) {
|
||||||
|
limit = options.optLong("limit", 1);
|
||||||
|
duration = options.optDouble("duration", 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action.equals("getFormatData")) {
|
||||||
|
try {
|
||||||
|
JSONObject obj = getFormatData(args.getString(0), args.getString(1));
|
||||||
|
return new PluginResult(PluginResult.Status.OK, obj);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
return new PluginResult(PluginResult.Status.ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (action.equals("captureAudio")) {
|
||||||
|
this.captureAudio();
|
||||||
|
}
|
||||||
|
else if (action.equals("captureImage")) {
|
||||||
|
this.captureImage();
|
||||||
|
}
|
||||||
|
else if (action.equals("captureVideo")) {
|
||||||
|
this.captureVideo(duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||||
|
r.setKeepCallback(true);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides the media data file data depending on it's mime type
|
||||||
|
*
|
||||||
|
* @param filePath path to the file
|
||||||
|
* @param mimeType of the file
|
||||||
|
* @return a MediaFileData object
|
||||||
|
*/
|
||||||
|
private JSONObject getFormatData(String filePath, String mimeType) {
|
||||||
|
JSONObject obj = new JSONObject();
|
||||||
|
try {
|
||||||
|
// setup defaults
|
||||||
|
obj.put("height", 0);
|
||||||
|
obj.put("width", 0);
|
||||||
|
obj.put("bitrate", 0);
|
||||||
|
obj.put("duration", 0);
|
||||||
|
obj.put("codecs", "");
|
||||||
|
|
||||||
|
if (mimeType.equals("image/jpeg")) {
|
||||||
|
obj = getImageData(filePath, obj);
|
||||||
|
}
|
||||||
|
else if (filePath.endsWith("audio/3gpp")) {
|
||||||
|
obj = getAudioVideoData(filePath, obj, false);
|
||||||
|
}
|
||||||
|
else if (mimeType.equals("video/3gpp")) {
|
||||||
|
obj = getAudioVideoData(filePath, obj, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (JSONException e) {
|
||||||
|
Log.d(LOG_TAG, "Error: setting media file data object");
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Image specific attributes
|
||||||
|
*
|
||||||
|
* @param filePath path to the file
|
||||||
|
* @param obj represents the Media File Data
|
||||||
|
* @return a JSONObject that represents the Media File Data
|
||||||
|
* @throws JSONException
|
||||||
|
*/
|
||||||
|
private JSONObject getImageData(String filePath, JSONObject obj) throws JSONException {
|
||||||
|
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
|
||||||
|
obj.put("height", bitmap.getHeight());
|
||||||
|
obj.put("width", bitmap.getWidth());
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Image specific attributes
|
||||||
|
*
|
||||||
|
* @param filePath path to the file
|
||||||
|
* @param obj represents the Media File Data
|
||||||
|
* @param video if true get video attributes as well
|
||||||
|
* @return a JSONObject that represents the Media File Data
|
||||||
|
* @throws JSONException
|
||||||
|
*/
|
||||||
|
private JSONObject getAudioVideoData(String filePath, JSONObject obj, boolean video) throws JSONException {
|
||||||
|
MediaPlayer player = new MediaPlayer();
|
||||||
|
try {
|
||||||
|
player.setDataSource(filePath);
|
||||||
|
player.prepare();
|
||||||
|
obj.put("duration", player.getDuration());
|
||||||
|
if (video) {
|
||||||
|
obj.put("height", player.getVideoHeight());
|
||||||
|
obj.put("width", player.getVideoWidth());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
Log.d(LOG_TAG, "Error: loading video file");
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up an intent to capture audio. Result handled by onActivityResult()
|
||||||
|
*/
|
||||||
|
private void captureAudio() {
|
||||||
|
Intent intent = new Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION);
|
||||||
|
|
||||||
|
this.ctx.startActivityForResult((Plugin) this, intent, CAPTURE_AUDIO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up an intent to capture images. Result handled by onActivityResult()
|
||||||
|
*/
|
||||||
|
private void captureImage() {
|
||||||
|
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
|
|
||||||
|
// Specify file so that large image is captured and returned
|
||||||
|
File photo = new File(Environment.getExternalStorageDirectory(), "Capture.jpg");
|
||||||
|
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
|
||||||
|
this.imageUri = Uri.fromFile(photo);
|
||||||
|
|
||||||
|
this.ctx.startActivityForResult((Plugin) this, intent, CAPTURE_IMAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up an intent to capture video. Result handled by onActivityResult()
|
||||||
|
*/
|
||||||
|
private void captureVideo(double duration) {
|
||||||
|
Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
|
||||||
|
// Introduced in API 8
|
||||||
|
//intent.putExtra(android.provider.MediaStore.EXTRA_DURATION_LIMIT, duration);
|
||||||
|
|
||||||
|
this.ctx.startActivityForResult((Plugin) this, intent, CAPTURE_VIDEO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the video view exits.
|
||||||
|
*
|
||||||
|
* @param requestCode The request code originally supplied to startActivityForResult(),
|
||||||
|
* allowing you to identify who this result came from.
|
||||||
|
* @param resultCode The integer result code returned by the child activity through its setResult().
|
||||||
|
* @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
|
||||||
|
* @throws JSONException
|
||||||
|
*/
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||||
|
|
||||||
|
// Result received okay
|
||||||
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
|
// An audio clip was requested
|
||||||
|
if (requestCode == CAPTURE_AUDIO) {
|
||||||
|
// Get the uri of the audio clip
|
||||||
|
Uri data = intent.getData();
|
||||||
|
// create a file object from the uri
|
||||||
|
results.put(createMediaFile(data));
|
||||||
|
|
||||||
|
if (results.length() >= limit) {
|
||||||
|
// Send Uri back to JavaScript for listening to audio
|
||||||
|
this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId);
|
||||||
|
} else {
|
||||||
|
// still need to capture more audio clips
|
||||||
|
captureAudio();
|
||||||
|
}
|
||||||
|
} else if (requestCode == CAPTURE_IMAGE) {
|
||||||
|
// For some reason if I try to do:
|
||||||
|
// Uri data = intent.getData();
|
||||||
|
// It crashes in the emulator and on my phone with a null pointer exception
|
||||||
|
// To work around it I had to grab the code from CameraLauncher.java
|
||||||
|
try {
|
||||||
|
// Read in bitmap of captured image
|
||||||
|
Bitmap bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getContentResolver(), imageUri);
|
||||||
|
|
||||||
|
// Create entry in media store for image
|
||||||
|
// (Don't use insertImage() because it uses default compression setting of 50 - no way to change it)
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
|
||||||
|
Uri uri = null;
|
||||||
|
try {
|
||||||
|
uri = this.ctx.getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
||||||
|
} catch (UnsupportedOperationException e) {
|
||||||
|
System.out.println("Can't write to external media storage.");
|
||||||
|
try {
|
||||||
|
uri = this.ctx.getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
|
||||||
|
} catch (UnsupportedOperationException ex) {
|
||||||
|
System.out.println("Can't write to internal media storage.");
|
||||||
|
this.fail("Error capturing image - no media storage found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add compressed version of captured image to returned media store Uri
|
||||||
|
OutputStream os = this.ctx.getContentResolver().openOutputStream(uri);
|
||||||
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
|
||||||
|
os.close();
|
||||||
|
|
||||||
|
bitmap.recycle();
|
||||||
|
bitmap = null;
|
||||||
|
System.gc();
|
||||||
|
|
||||||
|
// Add image to results
|
||||||
|
results.put(createMediaFile(uri));
|
||||||
|
|
||||||
|
if (results.length() >= limit) {
|
||||||
|
// Send Uri back to JavaScript for viewing image
|
||||||
|
this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId);
|
||||||
|
} else {
|
||||||
|
// still need to capture more images
|
||||||
|
captureImage();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
this.fail("Error capturing image.");
|
||||||
|
}
|
||||||
|
} else if (requestCode == CAPTURE_VIDEO) {
|
||||||
|
// Get the uri of the video clip
|
||||||
|
Uri data = intent.getData();
|
||||||
|
// create a file object from the uri
|
||||||
|
results.put(createMediaFile(data));
|
||||||
|
|
||||||
|
if (results.length() >= limit) {
|
||||||
|
// Send Uri back to JavaScript for viewing video
|
||||||
|
this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId);
|
||||||
|
} else {
|
||||||
|
// still need to capture more video clips
|
||||||
|
captureVideo(duration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If canceled
|
||||||
|
else if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
|
// If we have partial results send them back to the user
|
||||||
|
if (results.length() > 0) {
|
||||||
|
this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId);
|
||||||
|
}
|
||||||
|
// user canceled the action
|
||||||
|
else {
|
||||||
|
this.fail("Canceled.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If something else
|
||||||
|
else {
|
||||||
|
// If we have partial results send them back to the user
|
||||||
|
if (results.length() > 0) {
|
||||||
|
this.success(new PluginResult(PluginResult.Status.OK, results, "navigator.device.capture._castMediaFile"), this.callbackId);
|
||||||
|
}
|
||||||
|
// something bad happened
|
||||||
|
else {
|
||||||
|
this.fail("Did not complete!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a JSONObject that represents a File from the Uri
|
||||||
|
*
|
||||||
|
* @param data the Uri of the audio/image/video
|
||||||
|
* @return a JSONObject that represents a File
|
||||||
|
*/
|
||||||
|
private JSONObject createMediaFile(Uri data) {
|
||||||
|
File fp = new File(getRealPathFromURI(data));
|
||||||
|
|
||||||
|
JSONObject obj = new JSONObject();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// File properties
|
||||||
|
obj.put("name", fp.getName());
|
||||||
|
obj.put("fullPath", fp.getAbsolutePath());
|
||||||
|
obj.put("type", FileUtils.getMimeType(fp.getAbsolutePath()));
|
||||||
|
obj.put("lastModifiedDate", fp.lastModified());
|
||||||
|
obj.put("size", fp.length());
|
||||||
|
} catch (JSONException e) {
|
||||||
|
// this will never happen
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries the media store to find out what the file path is for the Uri we supply
|
||||||
|
*
|
||||||
|
* @param contentUri the Uri of the audio/image/video
|
||||||
|
* @return the full path to the file
|
||||||
|
*/
|
||||||
|
private String getRealPathFromURI(Uri contentUri) {
|
||||||
|
String[] proj = { _DATA };
|
||||||
|
Cursor cursor = this.ctx.managedQuery(contentUri, proj, null, null, null);
|
||||||
|
int column_index = cursor.getColumnIndexOrThrow(_DATA);
|
||||||
|
cursor.moveToFirst();
|
||||||
|
return cursor.getString(column_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send error message to JavaScript.
|
||||||
|
*
|
||||||
|
* @param err
|
||||||
|
*/
|
||||||
|
public void fail(String err) {
|
||||||
|
this.error(new PluginResult(PluginResult.Status.ERROR, err), this.callbackId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ import android.telephony.TelephonyManager;
|
|||||||
|
|
||||||
public class Device extends Plugin {
|
public class Device extends Plugin {
|
||||||
|
|
||||||
public static String phonegapVersion = "0.9.4"; // PhoneGap version
|
public static String phonegapVersion = "0.9.5"; // PhoneGap version
|
||||||
public static String platform = "Android"; // Device OS
|
public static String platform = "Android"; // Device OS
|
||||||
public static String uuid; // Device UUID
|
public static String uuid; // Device UUID
|
||||||
|
|
||||||
|
|||||||
@@ -10,18 +10,19 @@ package com.phonegap;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Picture;
|
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
@@ -31,7 +32,6 @@ import android.webkit.JsPromptResult;
|
|||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebStorage;
|
import android.webkit.WebStorage;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebView.PictureListener;
|
|
||||||
import android.webkit.WebViewClient;
|
import android.webkit.WebViewClient;
|
||||||
import android.webkit.GeolocationPermissions.Callback;
|
import android.webkit.GeolocationPermissions.Callback;
|
||||||
import android.webkit.WebSettings.LayoutAlgorithm;
|
import android.webkit.WebSettings.LayoutAlgorithm;
|
||||||
@@ -111,8 +111,8 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
protected WebView appView;
|
protected WebView appView;
|
||||||
protected WebViewClient webViewClient;
|
protected WebViewClient webViewClient;
|
||||||
|
|
||||||
private LinearLayout root;
|
protected LinearLayout root;
|
||||||
boolean bound = false;
|
public boolean bound = false;
|
||||||
public CallbackServer callbackServer;
|
public CallbackServer callbackServer;
|
||||||
protected PluginManager pluginManager;
|
protected PluginManager pluginManager;
|
||||||
protected boolean cancelLoadUrl = false;
|
protected boolean cancelLoadUrl = false;
|
||||||
@@ -235,7 +235,8 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
// Bind PhoneGap objects to JavaScript
|
// Bind PhoneGap objects to JavaScript
|
||||||
this.bindBrowser(this.appView);
|
this.bindBrowser(this.appView);
|
||||||
|
|
||||||
// Add web view
|
// Add web view but make it invisible while loading URL
|
||||||
|
this.appView.setVisibility(View.INVISIBLE);
|
||||||
root.addView(this.appView);
|
root.addView(this.appView);
|
||||||
setContentView(root);
|
setContentView(root);
|
||||||
|
|
||||||
@@ -286,6 +287,7 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
this.addService("Storage", "com.phonegap.Storage");
|
this.addService("Storage", "com.phonegap.Storage");
|
||||||
this.addService("Temperature", "com.phonegap.TempListener");
|
this.addService("Temperature", "com.phonegap.TempListener");
|
||||||
this.addService("FileTransfer", "com.phonegap.FileTransfer");
|
this.addService("FileTransfer", "com.phonegap.FileTransfer");
|
||||||
|
this.addService("Capture", "com.phonegap.Capture");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -302,8 +304,7 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
// If spashscreen
|
// If spashscreen
|
||||||
this.splashscreen = this.getIntegerProperty("splashscreen", 0);
|
this.splashscreen = this.getIntegerProperty("splashscreen", 0);
|
||||||
if (this.splashscreen != 0) {
|
if (this.splashscreen != 0) {
|
||||||
this.appView.setBackgroundColor(0);
|
root.setBackgroundResource(this.splashscreen);
|
||||||
this.appView.setBackgroundResource(splashscreen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If hideLoadingDialogOnPageLoad
|
// If hideLoadingDialogOnPageLoad
|
||||||
@@ -600,16 +601,19 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
*/
|
*/
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
if (this.appView == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send pause event to JavaScript
|
||||||
|
this.appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};");
|
||||||
|
|
||||||
// If app doesn't want to run in background
|
// If app doesn't want to run in background
|
||||||
if (!this.keepRunning) {
|
if (!this.keepRunning) {
|
||||||
|
|
||||||
// Forward to plugins
|
// Forward to plugins
|
||||||
this.pluginManager.onPause();
|
this.pluginManager.onPause();
|
||||||
|
|
||||||
// Send pause event to JavaScript
|
|
||||||
this.appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};");
|
|
||||||
|
|
||||||
// Pause JavaScript timers (including setInterval)
|
// Pause JavaScript timers (including setInterval)
|
||||||
this.appView.pauseTimers();
|
this.appView.pauseTimers();
|
||||||
}
|
}
|
||||||
@@ -621,6 +625,12 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
*/
|
*/
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
if (this.appView == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send resume event to JavaScript
|
||||||
|
this.appView.loadUrl("javascript:try{PhoneGap.onResume.fire();}catch(e){};");
|
||||||
|
|
||||||
// If app doesn't want to run in background
|
// If app doesn't want to run in background
|
||||||
if (!this.keepRunning || this.activityResultKeepRunning) {
|
if (!this.keepRunning || this.activityResultKeepRunning) {
|
||||||
@@ -634,9 +644,6 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
// Forward to plugins
|
// Forward to plugins
|
||||||
this.pluginManager.onResume();
|
this.pluginManager.onResume();
|
||||||
|
|
||||||
// Send resume event to JavaScript
|
|
||||||
this.appView.loadUrl("javascript:try{PhoneGap.onResume.fire();}catch(e){};");
|
|
||||||
|
|
||||||
// Resume JavaScript timers (including setInterval)
|
// Resume JavaScript timers (including setInterval)
|
||||||
this.appView.resumeTimers();
|
this.appView.resumeTimers();
|
||||||
}
|
}
|
||||||
@@ -649,9 +656,14 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|
||||||
|
if (this.appView != null) {
|
||||||
|
|
||||||
// Make sure pause event is sent if onPause hasn't been called before onDestroy
|
// Make sure pause event is sent if onPause hasn't been called before onDestroy
|
||||||
this.appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};");
|
this.appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};");
|
||||||
|
|
||||||
|
// Send destroy event to JavaScript
|
||||||
|
this.appView.loadUrl("javascript:try{PhoneGap.onDestroy.fire();}catch(e){};");
|
||||||
|
|
||||||
// Load blank page so that JavaScript onunload is called
|
// Load blank page so that JavaScript onunload is called
|
||||||
this.appView.loadUrl("about:blank");
|
this.appView.loadUrl("about:blank");
|
||||||
|
|
||||||
@@ -661,6 +673,7 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
if (this.callbackServer != null) {
|
if (this.callbackServer != null) {
|
||||||
this.callbackServer.destroy();
|
this.callbackServer.destroy();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -772,7 +785,7 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
|
|
||||||
// Calling PluginManager.exec() to call a native service using
|
// Calling PluginManager.exec() to call a native service using
|
||||||
// prompt(this.stringify(args), "gap:"+this.stringify([service, action, callbackId, true]));
|
// prompt(this.stringify(args), "gap:"+this.stringify([service, action, callbackId, true]));
|
||||||
if (defaultValue.substring(0, 4).equals("gap:")) {
|
if (defaultValue != null && defaultValue.length() > 3 && defaultValue.substring(0, 4).equals("gap:")) {
|
||||||
JSONArray array;
|
JSONArray array;
|
||||||
try {
|
try {
|
||||||
array = new JSONArray(defaultValue.substring(4));
|
array = new JSONArray(defaultValue.substring(4));
|
||||||
@@ -813,9 +826,28 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
|
|
||||||
// Show dialog
|
// Show dialog
|
||||||
else {
|
else {
|
||||||
//@TODO:
|
final JsPromptResult res = result;
|
||||||
result.confirm("");
|
AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx);
|
||||||
}
|
dlg.setMessage(message);
|
||||||
|
final EditText input = new EditText(this.ctx);
|
||||||
|
dlg.setView(input);
|
||||||
|
dlg.setCancelable(false);
|
||||||
|
dlg.setPositiveButton(android.R.string.ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
String usertext = input.getText().toString();
|
||||||
|
res.confirm(usertext);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dlg.setNegativeButton(android.R.string.cancel,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
res.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dlg.create();
|
||||||
|
dlg.show();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -948,19 +980,38 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If sms:5551212
|
// If sms:5551212?body=This is the message
|
||||||
else if (url.startsWith("sms:")) {
|
else if (url.startsWith("sms:")) {
|
||||||
try {
|
try {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.setData(Uri.parse(url));
|
|
||||||
intent.putExtra("address", url.substring(4));
|
// Get address
|
||||||
intent.setType("vnd.android-dir/mms-sms");
|
String address = null;
|
||||||
startActivity(intent);
|
int parmIndex = url.indexOf('?');
|
||||||
} catch (android.content.ActivityNotFoundException e) {
|
if (parmIndex == -1) {
|
||||||
System.out.println("Error sending sms "+url+":"+ e.toString());
|
address = url.substring(4);
|
||||||
}
|
}
|
||||||
return true;
|
else {
|
||||||
}
|
address = url.substring(4, parmIndex);
|
||||||
|
|
||||||
|
// If body, then set sms body
|
||||||
|
Uri uri = Uri.parse(url);
|
||||||
|
String query = uri.getQuery();
|
||||||
|
if (query != null) {
|
||||||
|
if (query.startsWith("body=")) {
|
||||||
|
intent.putExtra("sms_body", query.substring(5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
intent.setData(Uri.parse("sms:"+address));
|
||||||
|
intent.putExtra("address", address);
|
||||||
|
intent.setType("vnd.android-dir/mms-sms");
|
||||||
|
startActivity(intent);
|
||||||
|
} catch (android.content.ActivityNotFoundException e) {
|
||||||
|
System.out.println("Error sending sms "+url+":"+ e.toString());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// All else
|
// All else
|
||||||
else {
|
else {
|
||||||
@@ -1010,16 +1061,8 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
// from the JS side when the JS gets to that code.
|
// from the JS side when the JS gets to that code.
|
||||||
appView.loadUrl("javascript:try{ PhoneGap.onNativeReady.fire();}catch(e){_nativeReady = true;}");
|
appView.loadUrl("javascript:try{ PhoneGap.onNativeReady.fire();}catch(e){_nativeReady = true;}");
|
||||||
|
|
||||||
// If splash screen is showing, clear it
|
// Make app view visible
|
||||||
if (this.ctx.splashscreen != 0) {
|
appView.setVisibility(View.VISIBLE);
|
||||||
this.ctx.splashscreen = 0;
|
|
||||||
appView.setPictureListener(new PictureListener(){
|
|
||||||
public void onNewPicture(WebView viewtwo, Picture picture) {
|
|
||||||
appView.setBackgroundResource(0);
|
|
||||||
appView.setPictureListener(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop "app loading" spinner if showing
|
// Stop "app loading" spinner if showing
|
||||||
if (this.ctx.hideLoadingDialogOnPageLoad) {
|
if (this.ctx.hideLoadingDialogOnPageLoad) {
|
||||||
@@ -1066,6 +1109,9 @@ public class DroidGap extends PhonegapActivity {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
|
if (this.appView == null) {
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
|
}
|
||||||
|
|
||||||
// If back key
|
// If back key
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ public class FileTransfer extends Plugin {
|
|||||||
for (Iterator iter = params.keys(); iter.hasNext();) {
|
for (Iterator iter = params.keys(); iter.hasNext();) {
|
||||||
Object key = iter.next();
|
Object key = iter.next();
|
||||||
dos.writeBytes(LINE_START + BOUNDRY + LINE_END);
|
dos.writeBytes(LINE_START + BOUNDRY + LINE_END);
|
||||||
dos.writeBytes("Content-Disposition: form-data; name=\"" + key.toString() + "\"; ");
|
dos.writeBytes("Content-Disposition: form-data; name=\"" + key.toString() + "\";");
|
||||||
dos.writeBytes(LINE_END + LINE_END);
|
dos.writeBytes(LINE_END + LINE_END);
|
||||||
dos.writeBytes(params.getString(key.toString()));
|
dos.writeBytes(params.getString(key.toString()));
|
||||||
dos.writeBytes(LINE_END);
|
dos.writeBytes(LINE_END);
|
||||||
@@ -315,7 +315,13 @@ public class FileTransfer extends Plugin {
|
|||||||
|
|
||||||
//------------------ read the SERVER RESPONSE
|
//------------------ read the SERVER RESPONSE
|
||||||
StringBuffer responseString = new StringBuffer("");
|
StringBuffer responseString = new StringBuffer("");
|
||||||
DataInputStream inStream = new DataInputStream ( conn.getInputStream() );
|
DataInputStream inStream;
|
||||||
|
try {
|
||||||
|
inStream = new DataInputStream ( conn.getInputStream() );
|
||||||
|
} catch(FileNotFoundException e) {
|
||||||
|
throw new IOException("Received error from server");
|
||||||
|
}
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
while (( line = inStream.readLine()) != null) {
|
while (( line = inStream.readLine()) != null) {
|
||||||
responseString.append(line);
|
responseString.append(line);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||||
* Copyright (c) 2010, IBM Corporation
|
* Copyright (c) 2010-2011, IBM Corporation
|
||||||
*/
|
*/
|
||||||
package com.phonegap;
|
package com.phonegap;
|
||||||
|
|
||||||
@@ -836,49 +836,19 @@ public class FileUtils extends Plugin {
|
|||||||
* @return T=returns value
|
* @return T=returns value
|
||||||
*/
|
*/
|
||||||
public boolean isSynch(String action) {
|
public boolean isSynch(String action) {
|
||||||
if (action.equals("readAsText")) {
|
if (action.equals("testSaveLocationExists")) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
else if (action.equals("readAsDataURL")) {
|
else if (action.equals("getFreeDiskSpace")) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
else if (action.equals("writeAsText")) {
|
else if (action.equals("testFileExists")) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
else if (action.equals("requestFileSystem")) {
|
else if (action.equals("testDirectoryExists")) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
else if (action.equals("getMetadata")) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (action.equals("toURI")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (action.equals("getParent")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (action.equals("getFile")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (action.equals("getDirectory")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (action.equals("remove")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (action.equals("removeRecursively")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (action.equals("readEntries")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (action.equals("getFileMetadata")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (action.equals("resolveLocalFileSystemURI")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@@ -942,7 +912,7 @@ public class FileUtils extends Plugin {
|
|||||||
* @param filename
|
* @param filename
|
||||||
* @return a mime type
|
* @return a mime type
|
||||||
*/
|
*/
|
||||||
private String getMimeType(String filename) {
|
public static String getMimeType(String filename) {
|
||||||
MimeTypeMap map = MimeTypeMap.getSingleton();
|
MimeTypeMap map = MimeTypeMap.getSingleton();
|
||||||
return map.getMimeTypeFromExtension(map.getFileExtensionFromUrl(filename));
|
return map.getMimeTypeFromExtension(map.getFileExtensionFromUrl(filename));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,15 +16,21 @@ import android.database.Cursor;
|
|||||||
import android.database.sqlite.*;
|
import android.database.sqlite.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class implements the HTML5 database support for Android 1.X devices.
|
* This class implements the HTML5 database support for Android 1.X devices. It
|
||||||
* It is not used for Android 2.X, since HTML5 database is built in to the browser.
|
* is not used for Android 2.X, since HTML5 database is built in to the browser.
|
||||||
*/
|
*/
|
||||||
public class Storage extends Plugin {
|
public class Storage extends Plugin {
|
||||||
|
|
||||||
|
// Data Definition Language
|
||||||
|
private static final String ALTER = "alter";
|
||||||
|
private static final String CREATE = "create";
|
||||||
|
private static final String DROP = "drop";
|
||||||
|
private static final String TRUNCATE = "truncate";
|
||||||
|
|
||||||
SQLiteDatabase myDb = null; // Database object
|
SQLiteDatabase myDb = null; // Database object
|
||||||
String path = null; // Database path
|
String path = null; // Database path
|
||||||
String dbName = null; // Database name
|
String dbName = null; // Database name
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
@@ -34,29 +40,37 @@ public class Storage extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* Executes the request and returns PluginResult.
|
* Executes the request and returns PluginResult.
|
||||||
*
|
*
|
||||||
* @param action The action to execute.
|
* @param action
|
||||||
* @param args JSONArry of arguments for the plugin.
|
* The action to execute.
|
||||||
* @param callbackId The callback id used when calling back into JavaScript.
|
* @param args
|
||||||
* @return A PluginResult object with a status and message.
|
* JSONArry of arguments for the plugin.
|
||||||
|
* @param callbackId
|
||||||
|
* The callback id used when calling back into JavaScript.
|
||||||
|
* @return A PluginResult object with a status and message.
|
||||||
*/
|
*/
|
||||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
PluginResult.Status status = PluginResult.Status.OK;
|
PluginResult.Status status = PluginResult.Status.OK;
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO: Do we want to allow a user to do this, since they could get to other app databases?
|
// TODO: Do we want to allow a user to do this, since they could get
|
||||||
|
// to other app databases?
|
||||||
if (action.equals("setStorage")) {
|
if (action.equals("setStorage")) {
|
||||||
this.setStorage(args.getString(0));
|
this.setStorage(args.getString(0));
|
||||||
}
|
} else if (action.equals("openDatabase")) {
|
||||||
else if (action.equals("openDatabase")) {
|
this.openDatabase(args.getString(0), args.getString(1),
|
||||||
this.openDatabase(args.getString(0), args.getString(1), args.getString(2), args.getLong(3));
|
args.getString(2), args.getLong(3));
|
||||||
}
|
} else if (action.equals("executeSql")) {
|
||||||
else if (action.equals("executeSql")) {
|
String[] s = null;
|
||||||
JSONArray a = args.getJSONArray(1);
|
if (args.isNull(1)) {
|
||||||
int len = a.length();
|
s = new String[0];
|
||||||
String[] s = new String[len];
|
} else {
|
||||||
for (int i=0; i<len; i++) {
|
JSONArray a = args.getJSONArray(1);
|
||||||
s[i] = a.getString(i);
|
int len = a.length();
|
||||||
|
s = new String[len];
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
s[i] = a.getString(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.executeSql(args.getString(0), s, args.getString(2));
|
this.executeSql(args.getString(0), s, args.getString(2));
|
||||||
}
|
}
|
||||||
@@ -67,15 +81,17 @@ public class Storage extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifies if action to be executed returns a value and should be run synchronously.
|
* Identifies if action to be executed returns a value and should be run
|
||||||
|
* synchronously.
|
||||||
*
|
*
|
||||||
* @param action The action to execute
|
* @param action
|
||||||
* @return T=returns value
|
* The action to execute
|
||||||
|
* @return T=returns value
|
||||||
*/
|
*/
|
||||||
public boolean isSynch(String action) {
|
public boolean isSynch(String action) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean up and close database.
|
* Clean up and close database.
|
||||||
*/
|
*/
|
||||||
@@ -87,33 +103,40 @@ public class Storage extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// LOCAL METHODS
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the application package for the database. Each application saves its
|
* Set the application package for the database. Each application saves its
|
||||||
* database files in a directory with the application package as part of the file name.
|
* database files in a directory with the application package as part of the
|
||||||
|
* file name.
|
||||||
*
|
*
|
||||||
* For example, application "com.phonegap.demo.Demo" would save its database
|
* For example, application "com.phonegap.demo.Demo" would save its database
|
||||||
* files in "/data/data/com.phonegap.demo/databases/" directory.
|
* files in "/data/data/com.phonegap.demo/databases/" directory.
|
||||||
*
|
*
|
||||||
* @param appPackage The application package.
|
* @param appPackage
|
||||||
|
* The application package.
|
||||||
*/
|
*/
|
||||||
public void setStorage(String appPackage) {
|
public void setStorage(String appPackage) {
|
||||||
this.path = "/data/data/" + appPackage + "/databases/";
|
this.path = "/data/data/" + appPackage + "/databases/";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open database.
|
* Open database.
|
||||||
*
|
*
|
||||||
* @param db The name of the database
|
* @param db
|
||||||
* @param version The version
|
* The name of the database
|
||||||
* @param display_name The display name
|
* @param version
|
||||||
* @param size The size in bytes
|
* The version
|
||||||
|
* @param display_name
|
||||||
|
* The display name
|
||||||
|
* @param size
|
||||||
|
* The size in bytes
|
||||||
*/
|
*/
|
||||||
public void openDatabase(String db, String version, String display_name, long size) {
|
public void openDatabase(String db, String version, String display_name,
|
||||||
|
long size) {
|
||||||
|
|
||||||
// If database is open, then close it
|
// If database is open, then close it
|
||||||
if (this.myDb != null) {
|
if (this.myDb != null) {
|
||||||
this.myDb.close();
|
this.myDb.close();
|
||||||
@@ -121,27 +144,36 @@ public class Storage extends Plugin {
|
|||||||
|
|
||||||
// If no database path, generate from application package
|
// If no database path, generate from application package
|
||||||
if (this.path == null) {
|
if (this.path == null) {
|
||||||
Package pack = this.ctx.getClass().getPackage();
|
Package pack = this.ctx.getClass().getPackage();
|
||||||
String appPackage = pack.getName();
|
String appPackage = pack.getName();
|
||||||
this.setStorage(appPackage);
|
this.setStorage(appPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dbName = this.path + db + ".db";
|
this.dbName = this.path + db + ".db";
|
||||||
this.myDb = SQLiteDatabase.openOrCreateDatabase(this.dbName, null);
|
this.myDb = SQLiteDatabase.openOrCreateDatabase(this.dbName, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute SQL statement.
|
* Execute SQL statement.
|
||||||
*
|
*
|
||||||
* @param query The SQL query
|
* @param query
|
||||||
* @param params Parameters for the query
|
* The SQL query
|
||||||
* @param tx_id Transaction id
|
* @param params
|
||||||
|
* Parameters for the query
|
||||||
|
* @param tx_id
|
||||||
|
* Transaction id
|
||||||
*/
|
*/
|
||||||
public void executeSql(String query, String[] params, String tx_id) {
|
public void executeSql(String query, String[] params, String tx_id) {
|
||||||
try {
|
try {
|
||||||
Cursor myCursor = this.myDb.rawQuery(query, params);
|
if (isDDL(query)) {
|
||||||
this.processResults(myCursor, tx_id);
|
this.myDb.execSQL(query);
|
||||||
myCursor.close();
|
this.sendJavascript("droiddb.completeQuery('" + tx_id + "', '');");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Cursor myCursor = this.myDb.rawQuery(query, params);
|
||||||
|
this.processResults(myCursor, tx_id);
|
||||||
|
myCursor.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (SQLiteException ex) {
|
catch (SQLiteException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@@ -151,24 +183,40 @@ public class Storage extends Plugin {
|
|||||||
this.sendJavascript("droiddb.fail('" + ex.getMessage() + "','" + tx_id + "');");
|
this.sendJavascript("droiddb.fail('" + ex.getMessage() + "','" + tx_id + "');");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to see the the query is a Data Definintion command
|
||||||
|
*
|
||||||
|
* @param query to be executed
|
||||||
|
* @return true if it is a DDL command, false otherwise
|
||||||
|
*/
|
||||||
|
private boolean isDDL(String query) {
|
||||||
|
String cmd = query.toLowerCase();
|
||||||
|
if (cmd.startsWith(DROP) || cmd.startsWith(CREATE) || cmd.startsWith(ALTER) || cmd.startsWith(TRUNCATE)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process query results.
|
* Process query results.
|
||||||
*
|
*
|
||||||
* @param cur Cursor into query results
|
* @param cur
|
||||||
* @param tx_id Transaction id
|
* Cursor into query results
|
||||||
|
* @param tx_id
|
||||||
|
* Transaction id
|
||||||
*/
|
*/
|
||||||
public void processResults(Cursor cur, String tx_id) {
|
public void processResults(Cursor cur, String tx_id) {
|
||||||
|
|
||||||
String result = "[]";
|
String result = "[]";
|
||||||
// If query result has rows
|
// If query result has rows
|
||||||
|
|
||||||
if (cur.moveToFirst()) {
|
if (cur.moveToFirst()) {
|
||||||
JSONArray fullresult = new JSONArray();
|
JSONArray fullresult = new JSONArray();
|
||||||
String key = "";
|
String key = "";
|
||||||
String value = "";
|
String value = "";
|
||||||
int colCount = cur.getColumnCount();
|
int colCount = cur.getColumnCount();
|
||||||
|
|
||||||
// Build up JSON result object for each row
|
// Build up JSON result object for each row
|
||||||
do {
|
do {
|
||||||
JSONObject row = new JSONObject();
|
JSONObject row = new JSONObject();
|
||||||
@@ -179,19 +227,20 @@ public class Storage extends Plugin {
|
|||||||
row.put(key, value);
|
row.put(key, value);
|
||||||
}
|
}
|
||||||
fullresult.put(row);
|
fullresult.put(row);
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (cur.moveToNext());
|
} while (cur.moveToNext());
|
||||||
|
|
||||||
result = fullresult.toString();
|
result = fullresult.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let JavaScript know that there are no more rows
|
// Let JavaScript know that there are no more rows
|
||||||
this.sendJavascript("droiddb.completeQuery('" + tx_id + "', "+result+");");
|
this.sendJavascript("droiddb.completeQuery('" + tx_id + "', " + result
|
||||||
|
+ ");");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -21,7 +21,7 @@ class Classic
|
|||||||
def setup
|
def setup
|
||||||
@android_dir = File.expand_path(File.dirname(__FILE__).gsub(/lib$/,''))
|
@android_dir = File.expand_path(File.dirname(__FILE__).gsub(/lib$/,''))
|
||||||
@framework_dir = File.join(@android_dir, "framework")
|
@framework_dir = File.join(@android_dir, "framework")
|
||||||
@icon = File.join(@www, 'icon.png') unless File.exists?(@icon)
|
@icon = File.join(@www, 'icon.png') unless !@icon.nil? && File.exists?(@icon)
|
||||||
# Hash that stores the location of icons for each resolution type. Uses the default icon for all resolutions as a baseline.
|
# Hash that stores the location of icons for each resolution type. Uses the default icon for all resolutions as a baseline.
|
||||||
@icons = {
|
@icons = {
|
||||||
:"drawable-ldpi" => @icon,
|
:"drawable-ldpi" => @icon,
|
||||||
|
|||||||
Reference in New Issue
Block a user