mirror of
https://github.com/apache/cordova-android.git
synced 2026-05-30 00:00:04 +08:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8923e52a5e | |||
| aa4f2cc4d9 | |||
| 4a23f86411 | |||
| a69bd65152 | |||
| 7392b63b99 | |||
| 73aa5cc7c3 | |||
| 7bf35e9c83 | |||
| adb871f9e1 | |||
| 21b7346277 | |||
| 79935d31ef | |||
| d2fc08959a | |||
| 3ebc1d71df | |||
| f6503f8476 | |||
| d593448182 | |||
| 403b87b68b | |||
| bf69362709 | |||
| c00fb987f6 | |||
| 7c6450de50 | |||
| 10cbcd7f5a |
@@ -5,7 +5,7 @@
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||
<title>PhoneGap</title>
|
||||
<link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title">
|
||||
<script type="text/javascript" charset="utf-8" src="cordova-1.4.1.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="cordova-1.5.0.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="main.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
Executable → Regular
+356
-223
@@ -356,7 +356,8 @@ define('cordova/channel', function(require, exports, module) {
|
||||
*/
|
||||
var Channel = function(type, opts) {
|
||||
this.type = type;
|
||||
this.handlers = [];
|
||||
this.handlers = {};
|
||||
this.numHandlers = 0;
|
||||
this.guid = 0;
|
||||
this.fired = false;
|
||||
this.enabled = true;
|
||||
@@ -401,7 +402,7 @@ var Channel = function(type, opts) {
|
||||
*/
|
||||
Channel.prototype.subscribe = function(f, c, g) {
|
||||
// need a function to call
|
||||
if (f === null) { return; }
|
||||
if (f === null || f === undefined) { return; }
|
||||
|
||||
var func = f;
|
||||
if (typeof c == "object" && f instanceof Function) { func = utils.close(c, f); }
|
||||
@@ -410,6 +411,7 @@ Channel.prototype.subscribe = function(f, c, g) {
|
||||
func.observer_guid = g;
|
||||
f.observer_guid = g;
|
||||
this.handlers[g] = func;
|
||||
this.numHandlers++;
|
||||
if (this.events.onSubscribe) this.events.onSubscribe.call(this);
|
||||
return g;
|
||||
};
|
||||
@@ -419,6 +421,9 @@ Channel.prototype.subscribe = function(f, c, g) {
|
||||
* auto-unsubscribes itself.
|
||||
*/
|
||||
Channel.prototype.subscribeOnce = function(f, c) {
|
||||
// need a function to call
|
||||
if (f === null || f === undefined) { return; }
|
||||
|
||||
var g = null;
|
||||
var _this = this;
|
||||
var m = function() {
|
||||
@@ -438,9 +443,13 @@ Channel.prototype.subscribeOnce = function(f, c) {
|
||||
* Unsubscribes the function with the given guid from the channel.
|
||||
*/
|
||||
Channel.prototype.unsubscribe = function(g) {
|
||||
// need a function to unsubscribe
|
||||
if (g === null || g === undefined) { return; }
|
||||
|
||||
if (g instanceof Function) { g = g.observer_guid; }
|
||||
this.handlers[g] = null;
|
||||
delete this.handlers[g];
|
||||
this.numHandlers--;
|
||||
if (this.events.onUnsubscribe) this.events.onUnsubscribe.call(this);
|
||||
};
|
||||
|
||||
@@ -523,7 +532,7 @@ window.addEventListener = function(evt, handler, capture) {
|
||||
}
|
||||
};
|
||||
|
||||
document.removeEventListener = function(evt, handler) {
|
||||
document.removeEventListener = function(evt, handler, capture) {
|
||||
var e = evt.toLowerCase();
|
||||
// If unsubcribing from an event that is handled by a plugin
|
||||
if (typeof documentEventHandlers[e] != "undefined") {
|
||||
@@ -595,6 +604,15 @@ var cordova = {
|
||||
shuttingDown:false,
|
||||
UsePolling:false,
|
||||
// END TODO
|
||||
|
||||
// TODO: iOS only
|
||||
// This queue holds the currently executing command and all pending
|
||||
// commands executed with cordova.exec().
|
||||
commandQueue:[],
|
||||
// Indicates if we're currently in the middle of flushing the command
|
||||
// queue on the native side.
|
||||
commandQueueFlushing:false,
|
||||
// END TODO
|
||||
/**
|
||||
* Plugin callback mechanism.
|
||||
*/
|
||||
@@ -663,9 +681,42 @@ var cordova = {
|
||||
delete cordova.callbacks[callbackId];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
addPlugin: function(name, obj) {
|
||||
if (!window.plugins[name]) {
|
||||
window.plugins[name] = obj;
|
||||
}
|
||||
else {
|
||||
console.log("Error: Plugin "+name+" already exists.");
|
||||
}
|
||||
},
|
||||
|
||||
addConstructor: function(func) {
|
||||
channel.onCordovaReady.subscribeOnce(function() {
|
||||
try {
|
||||
func();
|
||||
} catch(e) {
|
||||
console.log("Failed to run constructor: " + e);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Legacy variable for plugin support
|
||||
*/
|
||||
if (!window.PhoneGap) {
|
||||
window.PhoneGap = cordova;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugins object
|
||||
*/
|
||||
if (!window.plugins) {
|
||||
window.plugins = {};
|
||||
}
|
||||
|
||||
module.exports = cordova;
|
||||
|
||||
});
|
||||
@@ -826,7 +877,7 @@ module.exports = {
|
||||
path: 'cordova/plugin/CompassHeading'
|
||||
},
|
||||
CompassError:{
|
||||
path: 'cordova/plugin/CompassConstants'
|
||||
path: 'cordova/plugin/CompassError'
|
||||
},
|
||||
ConfigurationData: {
|
||||
path: 'cordova/plugin/ConfigurationData'
|
||||
@@ -975,13 +1026,13 @@ module.exports = {
|
||||
var backButtonChannel = cordova.addDocumentEventHandler('backbutton', {
|
||||
onSubscribe:function() {
|
||||
// If we just attached the first handler, let native know we need to override the back button.
|
||||
if (this.handlers.length === 1) {
|
||||
if (this.numHandlers === 1) {
|
||||
exec(null, null, "App", "overrideBackbutton", [true]);
|
||||
}
|
||||
},
|
||||
onUnsubscribe:function() {
|
||||
// If we just detached the last handler, let native know we no longer override the back button.
|
||||
if (this.handlers.length === 0) {
|
||||
if (this.numHandlers === 0) {
|
||||
exec(null, null, "App", "overrideBackbutton", [false]);
|
||||
}
|
||||
}
|
||||
@@ -1020,8 +1071,6 @@ module.exports = {
|
||||
}
|
||||
|
||||
if (db === null) {
|
||||
// TOOD: this is wrong
|
||||
setupDroidDB();
|
||||
return storage.openDatabase(name, version, desc, size);
|
||||
}
|
||||
else {
|
||||
@@ -1060,6 +1109,9 @@ module.exports = {
|
||||
File: { // exists natively on Android WebView, override
|
||||
path: "cordova/plugin/File"
|
||||
},
|
||||
FileReader: { // exists natively on Android WebView, override
|
||||
path: "cordova/plugin/FileReader"
|
||||
},
|
||||
FileError: { //exists natively on Android WebView on Android 4.x
|
||||
path: "cordova/plugin/FileError"
|
||||
}
|
||||
@@ -1279,7 +1331,7 @@ var accelerometer = {
|
||||
watchAcceleration: function(successCallback, errorCallback, options) {
|
||||
|
||||
// Default interval (10 sec)
|
||||
var frequency = (options !== undefined)? options.frequency : 10000;
|
||||
var frequency = (options !== undefined && options.frequency !== undefined)? options.frequency : 10000;
|
||||
|
||||
// successCallback required
|
||||
if (typeof successCallback !== "function") {
|
||||
@@ -1293,7 +1345,6 @@ var accelerometer = {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: srsly wtf is this
|
||||
// Make sure accelerometer timeout > frequency + 10 sec
|
||||
exec(
|
||||
function(timeout) {
|
||||
@@ -1341,13 +1392,9 @@ var cordova = require('cordova'),
|
||||
exec = require('cordova/exec');
|
||||
|
||||
function handlers() {
|
||||
var count = function (a) {
|
||||
return a.filter(function (v) {return !!v;}).length;
|
||||
};
|
||||
|
||||
return count(module.exports.channels.batterystatus.handlers) +
|
||||
count(module.exports.channels.batterylow.handlers) +
|
||||
count(module.exports.channels.batterycritical.handlers);
|
||||
return battery.channels.batterystatus.numHandlers +
|
||||
battery.channels.batterylow.numHandlers +
|
||||
battery.channels.batterycritical.numHandlers;
|
||||
}
|
||||
|
||||
var Battery = function() {
|
||||
@@ -1370,7 +1417,7 @@ var Battery = function() {
|
||||
* appropriately (and hopefully save on battery life!).
|
||||
*/
|
||||
Battery.prototype.onSubscribe = function() {
|
||||
var me = module.exports; // TODO: i dont like this reference
|
||||
var me = battery;
|
||||
// If we just registered the first handler, make sure native listener is started.
|
||||
if (handlers() === 1) {
|
||||
exec(me._status, me._error, "Battery", "start", []);
|
||||
@@ -1378,10 +1425,8 @@ Battery.prototype.onSubscribe = function() {
|
||||
};
|
||||
|
||||
Battery.prototype.onUnsubscribe = function() {
|
||||
var me = module.exports,
|
||||
empty = function (a) {
|
||||
return a.filter(function (v, i) {return v && !!i;});
|
||||
};
|
||||
var me = battery;
|
||||
|
||||
// If we just unregistered the last handler, make sure native listener is stopped.
|
||||
if (handlers() === 0) {
|
||||
exec(null, null, "Battery", "stop", []);
|
||||
@@ -1395,7 +1440,7 @@ Battery.prototype.onUnsubscribe = function() {
|
||||
*/
|
||||
Battery.prototype._status = function(info) {
|
||||
if (info) {
|
||||
var me = module.exports;//TODO: can we eliminate this global ref?
|
||||
var me = battery;
|
||||
var level = info.level;
|
||||
if (me._level !== level || me._isPlugged !== info.isPlugged) {
|
||||
// Fire batterystatus event
|
||||
@@ -1423,7 +1468,9 @@ Battery.prototype._error = function(e) {
|
||||
console.log("Error initializing Battery: " + e);
|
||||
};
|
||||
|
||||
module.exports = new Battery();
|
||||
var battery = new Battery();
|
||||
|
||||
module.exports = battery;
|
||||
|
||||
});
|
||||
|
||||
@@ -1432,78 +1479,87 @@ define('cordova/plugin/Camera', function(require, exports, module) {
|
||||
var exec = require('cordova/exec'),
|
||||
Camera = require('cordova/plugin/CameraConstants');
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Gets a picture from source defined by "options.sourceType", and returns the
|
||||
* image as defined by the "options.destinationType" option.
|
||||
var cameraExport = {};
|
||||
|
||||
* The defaults are sourceType=CAMERA and destinationType=FILE_URL.
|
||||
*
|
||||
* @param {Function} successCallback
|
||||
* @param {Function} errorCallback
|
||||
* @param {Object} options
|
||||
*/
|
||||
getPicture: function (successCallback, errorCallback, options) {
|
||||
// Tack on the Camera Constants to the base camera plugin.
|
||||
for (var key in Camera) {
|
||||
cameraExport[key] = Camera[key];
|
||||
}
|
||||
|
||||
// successCallback required
|
||||
if (typeof successCallback != "function") {
|
||||
console.log("Camera Error: successCallback is not a function");
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Gets a picture from source defined by "options.sourceType", and returns the
|
||||
* image as defined by the "options.destinationType" option.
|
||||
|
||||
// errorCallback optional
|
||||
if (errorCallback && (typeof errorCallback != "function")) {
|
||||
console.log("Camera Error: errorCallback is not a function");
|
||||
return;
|
||||
}
|
||||
|
||||
if (options && typeof options.quality == "number") {
|
||||
quality = options.quality;
|
||||
} else if (options && typeof options.quality == "string") {
|
||||
var qlity = parseInt(options.quality, 10);
|
||||
if (isNaN(qlity) === false) {
|
||||
quality = qlity.valueOf();
|
||||
}
|
||||
}
|
||||
|
||||
var destinationType = Camera.DestinationType.FILE_URL;
|
||||
if (options.destinationType) {
|
||||
destinationType = options.destinationType;
|
||||
}
|
||||
|
||||
var sourceType = Camera.PictureSourceType.CAMERA;
|
||||
if (typeof options.sourceType == "number") {
|
||||
sourceType = options.sourceType;
|
||||
}
|
||||
|
||||
var targetWidth = -1;
|
||||
if (typeof options.targetWidth == "number") {
|
||||
targetWidth = options.targetWidth;
|
||||
} else if (typeof options.targetWidth == "string") {
|
||||
var width = parseInt(options.targetWidth, 10);
|
||||
if (isNaN(width) === false) {
|
||||
targetWidth = width.valueOf();
|
||||
}
|
||||
}
|
||||
|
||||
var targetHeight = -1;
|
||||
if (typeof options.targetHeight == "number") {
|
||||
targetHeight = options.targetHeight;
|
||||
} else if (typeof options.targetHeight == "string") {
|
||||
var height = parseInt(options.targetHeight, 10);
|
||||
if (isNaN(height) === false) {
|
||||
targetHeight = height.valueOf();
|
||||
}
|
||||
}
|
||||
|
||||
var encodingType = Camera.EncodingType.JPEG;
|
||||
if (typeof options.encodingType == "number") {
|
||||
encodingType = options.encodingType;
|
||||
}
|
||||
|
||||
exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType]);
|
||||
* The defaults are sourceType=CAMERA and destinationType=FILE_URL.
|
||||
*
|
||||
* @param {Function} successCallback
|
||||
* @param {Function} errorCallback
|
||||
* @param {Object} options
|
||||
*/
|
||||
cameraExport.getPicture = function(successCallback, errorCallback, options) {
|
||||
// successCallback required
|
||||
if (typeof successCallback != "function") {
|
||||
console.log("Camera Error: successCallback is not a function");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// errorCallback optional
|
||||
if (errorCallback && (typeof errorCallback != "function")) {
|
||||
console.log("Camera Error: errorCallback is not a function");
|
||||
return;
|
||||
}
|
||||
|
||||
var quality = 50;
|
||||
if (options && typeof options.quality == "number") {
|
||||
quality = options.quality;
|
||||
} else if (options && typeof options.quality == "string") {
|
||||
var qlity = parseInt(options.quality, 10);
|
||||
if (isNaN(qlity) === false) {
|
||||
quality = qlity.valueOf();
|
||||
}
|
||||
}
|
||||
|
||||
var destinationType = Camera.DestinationType.FILE_URL;
|
||||
if (typeof options.destinationType == "number") {
|
||||
destinationType = options.destinationType;
|
||||
}
|
||||
|
||||
var sourceType = Camera.PictureSourceType.CAMERA;
|
||||
if (typeof options.sourceType == "number") {
|
||||
sourceType = options.sourceType;
|
||||
}
|
||||
|
||||
var targetWidth = -1;
|
||||
if (typeof options.targetWidth == "number") {
|
||||
targetWidth = options.targetWidth;
|
||||
} else if (typeof options.targetWidth == "string") {
|
||||
var width = parseInt(options.targetWidth, 10);
|
||||
if (isNaN(width) === false) {
|
||||
targetWidth = width.valueOf();
|
||||
}
|
||||
}
|
||||
|
||||
var targetHeight = -1;
|
||||
if (typeof options.targetHeight == "number") {
|
||||
targetHeight = options.targetHeight;
|
||||
} else if (typeof options.targetHeight == "string") {
|
||||
var height = parseInt(options.targetHeight, 10);
|
||||
if (isNaN(height) === false) {
|
||||
targetHeight = height.valueOf();
|
||||
}
|
||||
}
|
||||
|
||||
var encodingType = Camera.EncodingType.JPEG;
|
||||
if (typeof options.encodingType == "number") {
|
||||
encodingType = options.encodingType;
|
||||
}
|
||||
// TODO: parse MediaType
|
||||
// TODO: enable allow edit?
|
||||
|
||||
exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType]);
|
||||
}
|
||||
|
||||
module.exports = cameraExport;
|
||||
|
||||
});
|
||||
|
||||
@@ -1544,16 +1600,16 @@ var exec = require('cordova/exec'),
|
||||
* @param {CaptureVideoOptions} options
|
||||
*/
|
||||
function _capture(type, successCallback, errorCallback, options) {
|
||||
var win = function(result) {
|
||||
var win = function(pluginResult) {
|
||||
var mediaFiles = [];
|
||||
var i;
|
||||
for (i = 0; i < pluginResult.message.length; i++) {
|
||||
for (i = 0; i < pluginResult.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;
|
||||
mediaFile.name = pluginResult[i].name;
|
||||
mediaFile.fullPath = pluginResult[i].fullPath;
|
||||
mediaFile.type = pluginResult[i].type;
|
||||
mediaFile.lastModifiedDate = pluginResult[i].lastModifiedDate;
|
||||
mediaFile.size = pluginResult[i].size;
|
||||
mediaFiles.push(mediaFile);
|
||||
}
|
||||
successCallback(mediaFiles);
|
||||
@@ -1682,6 +1738,8 @@ module.exports = CaptureVideoOptions;
|
||||
define('cordova/plugin/compass', function(require, exports, module) {
|
||||
var exec = require('cordova/exec'),
|
||||
utils = require('cordova/utils'),
|
||||
CompassHeading = require('cordova/plugin/CompassHeading'),
|
||||
CompassError = require('cordova/plugin/CompassError'),
|
||||
timers = {},
|
||||
compass = {
|
||||
/**
|
||||
@@ -1706,15 +1764,16 @@ var exec = require('cordova/exec'),
|
||||
}
|
||||
|
||||
var win = function(result) {
|
||||
if (result.timestamp) {
|
||||
var timestamp = new Date(result.timestamp);
|
||||
result.timestamp = timestamp;
|
||||
}
|
||||
successCallback(result);
|
||||
var ch = new CompassHeading(result.magneticHeading, result.trueHeading, result.headingAccuracy, result.timestamp);
|
||||
successCallback(ch);
|
||||
};
|
||||
var fail = function(code) {
|
||||
var ce = new CompassError(code);
|
||||
errorCallback(ce);
|
||||
}
|
||||
|
||||
// Get heading
|
||||
exec(win, errorCallback, "Compass", "getHeading", []);
|
||||
exec(win, fail, "Compass", "getHeading", []);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1745,14 +1804,16 @@ var exec = require('cordova/exec'),
|
||||
// Start watch timer to get headings
|
||||
var id = utils.createUUID();
|
||||
var win = function(result) {
|
||||
if (result.timestamp) {
|
||||
var timestamp = new Date(result.timestamp);
|
||||
result.timestamp = timestamp;
|
||||
}
|
||||
successCallback(result);
|
||||
var ch = new CompassHeading(result.magneticHeading, result.trueHeading, result.headingAccuracy, result.timestamp);
|
||||
successCallback(ch);
|
||||
};
|
||||
var fail = function(code) {
|
||||
var ce = new CompassError(code);
|
||||
errorCallback(ce);
|
||||
};
|
||||
|
||||
timers[id] = window.setInterval(function() {
|
||||
exec(win, errorCallback, "Compass", "getHeading", []);
|
||||
exec(win, fail, "Compass", "getHeading", []);
|
||||
}, frequency);
|
||||
|
||||
return id;
|
||||
@@ -1769,26 +1830,40 @@ var exec = require('cordova/exec'),
|
||||
delete timers[id];
|
||||
}
|
||||
}
|
||||
// TODO: add the filter-based iOS-only methods
|
||||
};
|
||||
|
||||
module.exports = compass;
|
||||
|
||||
});
|
||||
|
||||
define('cordova/plugin/CompassConstants', function(require, exports, module) {
|
||||
module.exports = {
|
||||
COMPASS_INTERNAL_ERR:0,
|
||||
COMPASS_NOT_SUPPORTED:20
|
||||
define('cordova/plugin/CompassError', function(require, exports, module) {
|
||||
/**
|
||||
* CompassError.
|
||||
* An error code assigned by an implementation when an error has occured
|
||||
* @constructor
|
||||
*/
|
||||
var CompassError = function(err) {
|
||||
this.code = (typeof err != 'undefined' ? err : null);
|
||||
};
|
||||
|
||||
/**
|
||||
* Error codes
|
||||
*/
|
||||
CompassError.COMPASS_INTERNAL_ERR = 0;
|
||||
CompassError.COMPASS_NOT_SUPPORTED = 20;
|
||||
|
||||
module.exports = CompassError;
|
||||
|
||||
|
||||
});
|
||||
|
||||
define('cordova/plugin/CompassHeading', function(require, exports, module) {
|
||||
var CompassHeading = function() {
|
||||
this.magneticHeading = null;
|
||||
this.trueHeading = null;
|
||||
this.headingAccuracy = null;
|
||||
this.timestamp = new Date();
|
||||
var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, timestamp) {
|
||||
this.magneticHeading = magneticHeading !== undefined ? magneticHeading : null;
|
||||
this.trueHeading = trueHeading !== undefined ? trueHeading : null;
|
||||
this.headingAccuracy = headingAccuracy !== undefined ? headingAccuracy : null;
|
||||
this.timestamp = timestamp !== undefined ? new Date(timestamp) : new Date();
|
||||
};
|
||||
|
||||
module.exports = CompassHeading;
|
||||
@@ -2213,7 +2288,7 @@ var utils = require('cordova/utils'),
|
||||
|
||||
/**
|
||||
* An interface representing a directory on the file system.
|
||||
*
|
||||
*
|
||||
* {boolean} isFile always false (readonly)
|
||||
* {boolean} isDirectory always true (readonly)
|
||||
* {DOMString} name of the directory, excluding the path leading to it (readonly)
|
||||
@@ -2242,11 +2317,11 @@ DirectoryEntry.prototype.createReader = function() {
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback) {
|
||||
var win = function(result) {
|
||||
var win = typeof successCallback !== 'function' ? null : function(result) {
|
||||
var entry = new DirectoryEntry(result.name, result.fullPath);
|
||||
successCallback(entry);
|
||||
};
|
||||
var fail = function(code) {
|
||||
var fail = typeof errorCallback !== 'function' ? null : function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, "File", "getDirectory", [this.fullPath, path, options]);
|
||||
@@ -2259,7 +2334,10 @@ DirectoryEntry.prototype.getDirectory = function(path, options, successCallback,
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCallback) {
|
||||
exec(successCallback, errorCallback, "File", "removeRecursively", [this.fullPath]);
|
||||
var fail = typeof errorCallback !== 'function' ? null : function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(successCallback, fail, "File", "removeRecursively", [this.fullPath]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -2271,12 +2349,12 @@ DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCall
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) {
|
||||
var win = function(result) {
|
||||
var win = typeof successCallback !== 'function' ? null : function(result) {
|
||||
var FileEntry = require('cordova/plugin/FileEntry');
|
||||
var entry = new FileEntry(result.name, result.fullPath);
|
||||
successCallback(entry);
|
||||
};
|
||||
var fail = function(code) {
|
||||
var fail = typeof errorCallback !== 'function' ? null : function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, "File", "getFile", [this.fullPath, path, options]);
|
||||
@@ -2303,7 +2381,7 @@ function DirectoryReader(path) {
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) {
|
||||
var win = function(result) {
|
||||
var win = typeof successCallback !== 'function' ? null : function(result) {
|
||||
var retVal = [];
|
||||
for (var i=0; i<result.length; i++) {
|
||||
var entry = null;
|
||||
@@ -2321,7 +2399,10 @@ DirectoryReader.prototype.readEntries = function(successCallback, errorCallback)
|
||||
}
|
||||
successCallback(retVal);
|
||||
};
|
||||
exec(win, errorCallback, "File", "readEntries", [this.path]);
|
||||
var fail = typeof errorCallback !== 'function' ? null : function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, "File", "readEntries", [this.path]);
|
||||
};
|
||||
|
||||
module.exports = DirectoryReader;
|
||||
@@ -2335,7 +2416,7 @@ var exec = require('cordova/exec'),
|
||||
|
||||
/**
|
||||
* Represents a file or directory on the local file system.
|
||||
*
|
||||
*
|
||||
* @param isFile
|
||||
* {boolean} true if Entry is a file (readonly)
|
||||
* @param isDirectory
|
||||
@@ -2357,24 +2438,27 @@ function Entry(isFile, isDirectory, name, fullPath, fileSystem) {
|
||||
|
||||
/**
|
||||
* Look up the metadata of the entry.
|
||||
*
|
||||
*
|
||||
* @param successCallback
|
||||
* {Function} is called with a Metadata object
|
||||
* @param errorCallback
|
||||
* {Function} is called with a FileError
|
||||
*/
|
||||
Entry.prototype.getMetadata = function(successCallback, errorCallback) {
|
||||
var success = function(lastModified) {
|
||||
var success = typeof successCallback !== 'function' ? null : function(lastModified) {
|
||||
var metadata = new Metadata(lastModified);
|
||||
successCallback(metadata);
|
||||
};
|
||||
var fail = typeof errorCallback !== 'function' ? null : function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
|
||||
exec(success, errorCallback, "File", "getMetadata", [this.fullPath]);
|
||||
exec(success, fail, "File", "getMetadata", [this.fullPath]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Move a file or directory to a new location.
|
||||
*
|
||||
*
|
||||
* @param parent
|
||||
* {DirectoryEntry} the directory to which to move this entry
|
||||
* @param newName
|
||||
@@ -2385,50 +2469,49 @@ Entry.prototype.getMetadata = function(successCallback, errorCallback) {
|
||||
* {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) {
|
||||
var fail = function(code) {
|
||||
if (typeof errorCallback === 'function') {
|
||||
errorCallback(new FileError(code));
|
||||
}
|
||||
};
|
||||
// user must specify parent Entry
|
||||
if (!parent) {
|
||||
errorCallback(new FileError(FileError.NOT_FOUND_ERR));
|
||||
fail(FileError.NOT_FOUND_ERR);
|
||||
return;
|
||||
}
|
||||
// source path
|
||||
var srcPath = this.fullPath,
|
||||
// entry name
|
||||
name = newName || this.name,
|
||||
// destination path
|
||||
dstPath,
|
||||
success = function(entry) {
|
||||
var result;
|
||||
|
||||
if (entry) {
|
||||
// create appropriate Entry object
|
||||
result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath);
|
||||
try {
|
||||
successCallback(result);
|
||||
if (typeof successCallback === 'function') {
|
||||
// create appropriate Entry object
|
||||
var result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath);
|
||||
try {
|
||||
successCallback(result);
|
||||
}
|
||||
catch (e) {
|
||||
console.log('Error invoking callback: ' + e);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.log('Error invoking callback: ' + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// no Entry object returned
|
||||
errorCallback(new FileError(FileError.NOT_FOUND_ERR));
|
||||
fail(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
},
|
||||
fail = function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
|
||||
|
||||
// copy
|
||||
exec(success, fail, "File", "moveTo", [srcPath, parent.fullPath, name]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Copy a directory to a different location.
|
||||
*
|
||||
* @param parent
|
||||
*
|
||||
* @param parent
|
||||
* {DirectoryEntry} the directory to which to copy the entry
|
||||
* @param newName
|
||||
* @param newName
|
||||
* {DOMString} new name of the entry, defaults to the current name
|
||||
* @param successCallback
|
||||
* {Function} called with the new Entry object
|
||||
@@ -2436,9 +2519,15 @@ Entry.prototype.moveTo = function(parent, newName, successCallback, errorCallbac
|
||||
* {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) {
|
||||
var fail = function(code) {
|
||||
if (typeof errorCallback === 'function') {
|
||||
errorCallback(new FileError(code));
|
||||
}
|
||||
};
|
||||
|
||||
// user must specify parent Entry
|
||||
if (!parent) {
|
||||
errorCallback(new FileError(FileError.NOT_FOUND_ERR));
|
||||
fail(FileError.NOT_FOUND_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2448,25 +2537,22 @@ Entry.prototype.copyTo = function(parent, newName, successCallback, errorCallbac
|
||||
name = newName || this.name,
|
||||
// success callback
|
||||
success = function(entry) {
|
||||
var result;
|
||||
|
||||
if (entry) {
|
||||
// create appropriate Entry object
|
||||
result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath);
|
||||
try {
|
||||
successCallback(result);
|
||||
}
|
||||
catch (e) {
|
||||
console.log('Error invoking callback: ' + e);
|
||||
if (typeof successCallback === 'function') {
|
||||
// create appropriate Entry object
|
||||
var result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath);
|
||||
try {
|
||||
successCallback(result);
|
||||
}
|
||||
catch (e) {
|
||||
console.log('Error invoking callback: ' + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// no Entry object returned
|
||||
errorCallback(new FileError(FileError.NOT_FOUND_ERR));
|
||||
fail(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
},
|
||||
fail = function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
|
||||
// copy
|
||||
@@ -2497,13 +2583,13 @@ Entry.prototype.toURI = function(mimeType) {
|
||||
* Remove a file or directory. It is an error to attempt to delete a
|
||||
* directory that is not empty. It is an error to attempt to delete a
|
||||
* root directory of a file system.
|
||||
*
|
||||
*
|
||||
* @param successCallback {Function} called with no parameters
|
||||
* @param errorCallback {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.remove = function(successCallback, errorCallback) {
|
||||
var fail = function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
var fail = typeof errorCallback !== 'function' ? null : function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(successCallback, fail, "File", "remove", [this.fullPath]);
|
||||
};
|
||||
@@ -2515,7 +2601,10 @@ Entry.prototype.remove = function(successCallback, errorCallback) {
|
||||
* @param errorCallback {Function} called with a FileError
|
||||
*/
|
||||
Entry.prototype.getParent = function(successCallback, errorCallback) {
|
||||
exec(successCallback, errorCallback, "File", "getParent", [this.fullPath]);
|
||||
var fail = typeof errorCallback !== 'function' ? null : function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(successCallback, fail, "File", "getParent", [this.fullPath]);
|
||||
};
|
||||
|
||||
module.exports = Entry;
|
||||
@@ -2554,7 +2643,7 @@ var utils = require('cordova/utils'),
|
||||
|
||||
/**
|
||||
* An interface representing a file on the file system.
|
||||
*
|
||||
*
|
||||
* {boolean} isFile always true (readonly)
|
||||
* {boolean} isDirectory always false (readonly)
|
||||
* {DOMString} name of the file, excluding the path leading to it (readonly)
|
||||
@@ -2596,12 +2685,12 @@ FileEntry.prototype.createWriter = function(successCallback, errorCallback) {
|
||||
* @param {Function} errorCallback is called with a FileError
|
||||
*/
|
||||
FileEntry.prototype.file = function(successCallback, errorCallback) {
|
||||
var win = function(f) {
|
||||
var win = typeof successCallback !== 'function' ? null : function(f) {
|
||||
var file = new File(f.name, f.fullPath, f.type, f.lastModifiedDate, f.size);
|
||||
successCallback(file);
|
||||
};
|
||||
var fail = function(e) {
|
||||
errorCallback(new FileError(e));
|
||||
var fail = typeof errorCallback !== 'function' ? null : function(code) {
|
||||
errorCallback(new FileError(code));
|
||||
};
|
||||
exec(win, fail, "File", "getFileMetadata", [this.fullPath]);
|
||||
};
|
||||
@@ -2843,7 +2932,6 @@ FileReader.prototype.readAsDataURL = function(file) {
|
||||
},
|
||||
// Error callback
|
||||
function(e) {
|
||||
var evt;
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me.readyState === FileReader.DONE) {
|
||||
return;
|
||||
@@ -2906,7 +2994,7 @@ var DirectoryEntry = require('cordova/plugin/DirectoryEntry');
|
||||
var FileSystem = function(name, root) {
|
||||
this.name = name || null;
|
||||
if (root) {
|
||||
this.root = new DirectoryEntry(name, root);
|
||||
this.root = new DirectoryEntry(root.name, root.fullPath);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3135,7 +3223,6 @@ FileWriter.prototype.write = function(text) {
|
||||
exec(
|
||||
// Success callback
|
||||
function(r) {
|
||||
var evt;
|
||||
// If DONE (cancelled), then don't do anything
|
||||
if (me.readyState === FileWriter.DONE) {
|
||||
return;
|
||||
@@ -3403,11 +3490,6 @@ var LocalFileSystem = function() {
|
||||
|
||||
};
|
||||
|
||||
// Non-standard function
|
||||
LocalFileSystem.prototype.isFileSystemRoot = function(path) {
|
||||
return exec(null, null, "File", "isFileSystemRoot", [path]);
|
||||
};
|
||||
|
||||
LocalFileSystem.TEMPORARY = 0; //temporary, with no guarantee of persistence
|
||||
LocalFileSystem.PERSISTENT = 1; //persistent
|
||||
|
||||
@@ -3453,12 +3535,6 @@ var Media = function(src, successCallback, errorCallback, statusCallback) {
|
||||
return;
|
||||
}
|
||||
|
||||
// statusCallback optional
|
||||
if (positionCallback && (typeof positionCallback !== "function")) {
|
||||
console.log("Media Error: positionCallback is not a function");
|
||||
return;
|
||||
}
|
||||
|
||||
this.id = utils.createUUID();
|
||||
mediaObjects[this.id] = this;
|
||||
this.src = src;
|
||||
@@ -3573,6 +3649,40 @@ Media.prototype.setVolume = function(volume) {
|
||||
exec(null, null, "Media", "setVolume", [this.id, volume]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Audio has status update.
|
||||
* PRIVATE
|
||||
*
|
||||
* @param id The media object id (string)
|
||||
* @param status The status code (int)
|
||||
* @param msg The status message (string)
|
||||
*/
|
||||
Media.onStatus = function(id, msg, value) {
|
||||
var media = mediaObjects[id];
|
||||
// If state update
|
||||
if (msg === Media.MEDIA_STATE) {
|
||||
if (value === Media.MEDIA_STOPPED) {
|
||||
if (media.successCallback) {
|
||||
media.successCallback();
|
||||
}
|
||||
}
|
||||
if (media.statusCallback) {
|
||||
media.statusCallback(value);
|
||||
}
|
||||
}
|
||||
else if (msg === Media.MEDIA_DURATION) {
|
||||
media._duration = value;
|
||||
}
|
||||
else if (msg === Media.MEDIA_ERROR) {
|
||||
if (media.errorCallback) {
|
||||
media.errorCallback({"code":value});
|
||||
}
|
||||
}
|
||||
else if (msg === Media.MEDIA_POSITION) {
|
||||
media._position = value;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Media;
|
||||
|
||||
});
|
||||
@@ -3695,20 +3805,33 @@ module.exports = Metadata;
|
||||
|
||||
define('cordova/plugin/network', function(require, exports, module) {
|
||||
var exec = require('cordova/exec'),
|
||||
cordova = require('cordova');
|
||||
cordova = require('cordova'),
|
||||
channel = require('cordova/channel');
|
||||
|
||||
var NetworkConnection = function () {
|
||||
this.type = null;
|
||||
this._firstRun = true;
|
||||
this._timer = null;
|
||||
this.timeout = 500;
|
||||
|
||||
var me = this,
|
||||
channel = require('cordova/channel');
|
||||
var me = this;
|
||||
|
||||
this.getInfo(
|
||||
function (info) {
|
||||
me.type = info.type;
|
||||
if (typeof info.event !== "undefined") {
|
||||
cordova.fireWindowEvent(info.event);
|
||||
me.type = info;
|
||||
if (info === "none") {
|
||||
// set a timer if still offline at the end of timer send the offline event
|
||||
me._timer = setTimeout(function(){
|
||||
cordova.fireWindowEvent("offline");
|
||||
me._timer = null;
|
||||
}, me.timeout);
|
||||
} else {
|
||||
// If there is a current offline event pending clear it
|
||||
if (me._timer !== null) {
|
||||
clearTimeout(me._timer);
|
||||
me._timer = null;
|
||||
}
|
||||
cordova.fireWindowEvent("online");
|
||||
}
|
||||
|
||||
// should only fire this once
|
||||
@@ -3898,25 +4021,31 @@ var FileError = require('cordova/plugin/FileError'),
|
||||
* @param errorCallback invoked if error occurs retrieving file system
|
||||
*/
|
||||
var requestFileSystem = function(type, size, successCallback, errorCallback) {
|
||||
if (type < 0 || type > 3) {
|
||||
if (typeof errorCallback === "function") {
|
||||
errorCallback(new FileError(FileError.SYNTAX_ERR));
|
||||
}
|
||||
} else {
|
||||
// if successful, return a FileSystem object
|
||||
var success = function(file_system) {
|
||||
if (file_system) {
|
||||
// grab the name and root from the file system object
|
||||
var result = new FileSystem(file_system.name, file_system.root);
|
||||
successCallback(result);
|
||||
}
|
||||
else {
|
||||
// no FileSystem object returned
|
||||
errorCallback(new FileError(FileError.NOT_FOUND_ERR));
|
||||
}
|
||||
var fail = function(code) {
|
||||
if (typeof errorCallback === 'function') {
|
||||
errorCallback(new FileError(code));
|
||||
}
|
||||
};
|
||||
exec(success, errorCallback, "File", "requestFileSystem", [type, size]);
|
||||
}
|
||||
|
||||
if (type < 0 || type > 3) {
|
||||
fail(FileError.SYNTAX_ERR);
|
||||
} else {
|
||||
// if successful, return a FileSystem object
|
||||
var success = function(file_system) {
|
||||
if (file_system) {
|
||||
if (typeof successCallback === 'function') {
|
||||
// grab the name and root from the file system object
|
||||
var result = new FileSystem(file_system.name, file_system.root);
|
||||
successCallback(result);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// no FileSystem object returned
|
||||
fail(FileError.NOT_FOUND_ERR);
|
||||
}
|
||||
};
|
||||
exec(success, fail, "File", "requestFileSystem", [type, size]);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = requestFileSystem;
|
||||
@@ -3930,27 +4059,31 @@ var DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
|
||||
|
||||
/**
|
||||
* Look up file system Entry referred to by local URI.
|
||||
* @param {DOMString} uri URI referring to a local file or directory
|
||||
* @param {DOMString} uri URI referring to a local file or directory
|
||||
* @param successCallback invoked with Entry object corresponding to URI
|
||||
* @param errorCallback invoked if error occurs retrieving file system entry
|
||||
*/
|
||||
module.exports = function(uri, successCallback, errorCallback) {
|
||||
// error callback
|
||||
var fail = function(error) {
|
||||
errorCallback(new FileError(error));
|
||||
if (typeof errorCallback === 'function') {
|
||||
errorCallback(new FileError(error));
|
||||
}
|
||||
};
|
||||
// if successful, return either a file or directory entry
|
||||
var success = function(entry) {
|
||||
var result;
|
||||
|
||||
if (entry) {
|
||||
// create appropriate Entry object
|
||||
result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath) : new FileEntry(entry.name, entry.fullPath);
|
||||
try {
|
||||
successCallback(result);
|
||||
}
|
||||
catch (e) {
|
||||
console.log('Error invoking callback: ' + e);
|
||||
if (typeof successCallback === 'function') {
|
||||
// create appropriate Entry object
|
||||
result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath) : new FileEntry(entry.name, entry.fullPath);
|
||||
try {
|
||||
successCallback(result);
|
||||
}
|
||||
catch (e) {
|
||||
console.log('Error invoking callback: ' + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
<script src="cordova-1.5.0rc1.js"></script>
|
||||
<script src="cordova-1.5.0.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
+1
-1
@@ -143,7 +143,7 @@
|
||||
</target>
|
||||
|
||||
<!-- Combine JavaScript files into one cordova-uncompressed.js file. -->
|
||||
<target name="build-javascript">
|
||||
<target name="build-javascript" depends="clean">
|
||||
|
||||
<!-- Clean up existing files -->
|
||||
<!--<delete file="assets/www/cordova_${version}.js"/>-->
|
||||
|
||||
@@ -116,7 +116,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
public void startRecording(String file) {
|
||||
if (this.mPlayer != null) {
|
||||
Log.d(LOG_TAG, "AudioPlayer Error: Can't record in play mode.");
|
||||
this.handler.sendJavascript("Cordova.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
}
|
||||
|
||||
// Make sure we're not already recording
|
||||
@@ -137,11 +137,11 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.handler.sendJavascript("Cordova.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
}
|
||||
else {
|
||||
Log.d(LOG_TAG, "AudioPlayer Error: Already recording.");
|
||||
this.handler.sendJavascript("Cordova.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
public void startPlaying(String file) {
|
||||
if (this.recorder != null) {
|
||||
Log.d(LOG_TAG, "AudioPlayer Error: Can't play in record mode.");
|
||||
this.handler.sendJavascript("Cordova.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
}
|
||||
|
||||
// If this is a new request to play audio, or stopped
|
||||
@@ -228,7 +228,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
this.handler.sendJavascript("Cordova.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
}
|
||||
else {
|
||||
Log.d(LOG_TAG, "AudioPlayer Error: startPlaying() called during invalid state: "+this.state);
|
||||
this.handler.sendJavascript("Cordova.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,7 +254,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
if (this.mPlayer != null) {
|
||||
this.mPlayer.seekTo(milliseconds);
|
||||
Log.d(LOG_TAG, "Send a onStatus update for the new seek");
|
||||
this.handler.sendJavascript("Cordova.Media.onStatus('" + this.id + "', "+MEDIA_POSITION+", "+milliseconds/1000.0f+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_POSITION+", "+milliseconds/1000.0f+");");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
}
|
||||
else {
|
||||
Log.d(LOG_TAG, "AudioPlayer Error: pausePlaying() called during invalid state: "+this.state);
|
||||
this.handler.sendJavascript("Cordova.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_NONE_ACTIVE+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_NONE_ACTIVE+");");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
}
|
||||
else {
|
||||
Log.d(LOG_TAG, "AudioPlayer Error: stopPlaying() called during invalid state: "+this.state);
|
||||
this.handler.sendJavascript("Cordova.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_NONE_ACTIVE+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_NONE_ACTIVE+");");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
public long getCurrentPosition() {
|
||||
if ((this.state == MEDIA_RUNNING) || (this.state == MEDIA_PAUSED)) {
|
||||
int curPos = this.mPlayer.getCurrentPosition();
|
||||
this.handler.sendJavascript("Cordova.Media.onStatus('" + this.id + "', "+MEDIA_POSITION+", "+curPos/1000.0f+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_POSITION+", "+curPos/1000.0f+");");
|
||||
return curPos;
|
||||
}
|
||||
else {
|
||||
@@ -384,7 +384,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
this.prepareOnly = false;
|
||||
|
||||
// Send status notification to JavaScript
|
||||
this.handler.sendJavascript("Cordova.Media.onStatus('" + this.id + "', "+MEDIA_DURATION+","+this.duration+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_DURATION+","+this.duration+");");
|
||||
|
||||
}
|
||||
|
||||
@@ -413,7 +413,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
this.mPlayer.release();
|
||||
|
||||
// Send error notification to JavaScript
|
||||
this.handler.sendJavascript("Cordova.Media.onStatus('" + this.id + "', "+MEDIA_ERROR+", "+arg1+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+arg1+");");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
*/
|
||||
private void setState(int state) {
|
||||
if (this.state != state) {
|
||||
this.handler.sendJavascript("Cordova.Media.onStatus('" + this.id + "', "+MEDIA_STATE+", "+state+");");
|
||||
this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_STATE+", "+state+");");
|
||||
}
|
||||
|
||||
this.state = state;
|
||||
|
||||
@@ -497,4 +497,4 @@ public class CameraLauncher extends Plugin {
|
||||
public void failPicture(String err) {
|
||||
this.error(new PluginResult(PluginResult.Status.ERROR, err), this.callbackId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,34 +26,34 @@ import org.json.JSONObject;
|
||||
import android.util.Log;
|
||||
|
||||
public class ContactManager extends Plugin {
|
||||
|
||||
|
||||
private ContactAccessor contactAccessor;
|
||||
private static final String LOG_TAG = "Contact Query";
|
||||
private static final String LOG_TAG = "Contact Query";
|
||||
|
||||
public static final int UNKNOWN_ERROR = 0;
|
||||
public static final int INVALID_ARGUMENT_ERROR = 1;
|
||||
public static final int TIMEOUT_ERROR = 2;
|
||||
public static final int PENDING_OPERATION_ERROR = 3;
|
||||
public static final int IO_ERROR = 4;
|
||||
public static final int NOT_SUPPORTED_ERROR = 5;
|
||||
public static final int PERMISSION_DENIED_ERROR = 20;
|
||||
public static final int UNKNOWN_ERROR = 0;
|
||||
public static final int INVALID_ARGUMENT_ERROR = 1;
|
||||
public static final int TIMEOUT_ERROR = 2;
|
||||
public static final int PENDING_OPERATION_ERROR = 3;
|
||||
public static final int IO_ERROR = 4;
|
||||
public static final int NOT_SUPPORTED_ERROR = 5;
|
||||
public static final int PERMISSION_DENIED_ERROR = 20;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public ContactManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args 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) {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public ContactManager() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args 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) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
@@ -82,32 +82,32 @@ public class ContactManager extends Plugin {
|
||||
this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx.getContext());
|
||||
}
|
||||
|
||||
try {
|
||||
if (action.equals("search")) {
|
||||
JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1));
|
||||
return new PluginResult(status, res);
|
||||
}
|
||||
else if (action.equals("save")) {
|
||||
String id = contactAccessor.save(args.getJSONObject(0));
|
||||
if (id != null) {
|
||||
JSONObject res = contactAccessor.getContactById(id);
|
||||
if (res != null) {
|
||||
return new PluginResult(status, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (action.equals("remove")) {
|
||||
if (contactAccessor.remove(args.getString(0))) {
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
}
|
||||
// If we get to this point an error has occurred
|
||||
try {
|
||||
if (action.equals("search")) {
|
||||
JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1));
|
||||
return new PluginResult(status, res);
|
||||
}
|
||||
else if (action.equals("save")) {
|
||||
String id = contactAccessor.save(args.getJSONObject(0));
|
||||
if (id != null) {
|
||||
JSONObject res = contactAccessor.getContactById(id);
|
||||
if (res != null) {
|
||||
return new PluginResult(status, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (action.equals("remove")) {
|
||||
if (contactAccessor.remove(args.getString(0))) {
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
}
|
||||
// If we get to this point an error has occurred
|
||||
JSONObject r = new JSONObject();
|
||||
r.put("code", UNKNOWN_ERROR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, r);
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOG_TAG, e.getMessage(), e);
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOG_TAG, e.getMessage(), e);
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import android.telephony.TelephonyManager;
|
||||
public class Device extends Plugin {
|
||||
public static final String TAG = "Device";
|
||||
|
||||
public static String cordovaVersion = "1.5.0rc1"; // Cordova version
|
||||
public static String cordovaVersion = "1.5.0"; // Cordova version
|
||||
public static String platform = "Android"; // Device OS
|
||||
public static String uuid; // Device UUID
|
||||
|
||||
|
||||
@@ -1404,18 +1404,14 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Cursor managedQuery(Uri parse, String[] strings, Object object,
|
||||
Object object2, Object object3) {
|
||||
return this.managedQuery(parse, strings, object, object2, object3);
|
||||
}
|
||||
|
||||
public void bindBackButton(boolean override) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
this.bound = override;
|
||||
}
|
||||
|
||||
public boolean isBackButtonBound() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return this.bound;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -131,8 +131,7 @@ public class FileUtils extends Plugin {
|
||||
long size = args.optLong(1);
|
||||
if (size != 0) {
|
||||
if (size > (DirectoryManager.getFreeDiskSpace(true)*1024)) {
|
||||
JSONObject error = new JSONObject().put("code", FileUtils.QUOTA_EXCEEDED_ERR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
return new PluginResult(PluginResult.Status.ERROR, FileUtils.QUOTA_EXCEEDED_ERR);
|
||||
}
|
||||
}
|
||||
JSONObject obj = requestFileSystem(args.getInt(0));
|
||||
@@ -171,8 +170,7 @@ public class FileUtils extends Plugin {
|
||||
notifyDelete(args.getString(0));
|
||||
return new PluginResult(status);
|
||||
} else {
|
||||
JSONObject error = new JSONObject().put("code", FileUtils.NO_MODIFICATION_ALLOWED_ERR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
return new PluginResult(PluginResult.Status.ERROR, FileUtils.NO_MODIFICATION_ALLOWED_ERR);
|
||||
}
|
||||
}
|
||||
else if (action.equals("removeRecursively")) {
|
||||
@@ -180,8 +178,7 @@ public class FileUtils extends Plugin {
|
||||
if (success) {
|
||||
return new PluginResult(status);
|
||||
} else {
|
||||
JSONObject error = new JSONObject().put("code", FileUtils.NO_MODIFICATION_ALLOWED_ERR);
|
||||
return new PluginResult(PluginResult.Status.ERROR, error);
|
||||
return new PluginResult(PluginResult.Status.ERROR, FileUtils.NO_MODIFICATION_ALLOWED_ERR);
|
||||
}
|
||||
}
|
||||
else if (action.equals("moveTo")) {
|
||||
@@ -818,27 +815,31 @@ public class FileUtils extends Plugin {
|
||||
File fp;
|
||||
fs.put("name", "temporary");
|
||||
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
fs.put("root", "file://" + Environment.getExternalStorageDirectory().getAbsolutePath() +
|
||||
"/Android/data/" + ctx.getPackageName() + "/cache/");
|
||||
|
||||
// Create the cache dir if it doesn't exist.
|
||||
fp = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
|
||||
"/Android/data/" + ctx.getPackageName() + "/cache/");
|
||||
} else {
|
||||
fs.put("root", "file:///data/data/" + ctx.getPackageName() + "/cache/");
|
||||
// Create the cache dir if it doesn't exist.
|
||||
fp.mkdirs();
|
||||
fs.put("root", getEntry(Environment.getExternalStorageDirectory().getAbsolutePath() +
|
||||
"/Android/data/" + ctx.getPackageName() + "/cache/"));
|
||||
} else {
|
||||
fp = new File("/data/data/" + ctx.getPackageName() + "/cache/");
|
||||
// Create the cache dir if it doesn't exist.
|
||||
fp.mkdirs();
|
||||
fs.put("root", getEntry("/data/data/" + ctx.getPackageName() + "/cache/"));
|
||||
}
|
||||
fp.mkdirs();
|
||||
}
|
||||
else if (type == PERSISTENT) {
|
||||
fs.put("name", "persistent");
|
||||
fs.put("root", "file:///data/data/" + ctx.getPackageName());
|
||||
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
fs.put("root", getEntry(Environment.getExternalStorageDirectory()));
|
||||
} else {
|
||||
fs.put("root", getEntry("/data/data/" + ctx.getPackageName()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IOException("No filesystem of type requested");
|
||||
}
|
||||
|
||||
|
||||
return fs;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,331 +36,331 @@ import android.os.Vibrator;
|
||||
* This class provides access to notifications on the device.
|
||||
*/
|
||||
public class Notification extends Plugin {
|
||||
|
||||
public int confirmResult = -1;
|
||||
public ProgressDialog spinnerDialog = null;
|
||||
public ProgressDialog progressDialog = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Notification() {
|
||||
}
|
||||
|
||||
public int confirmResult = -1;
|
||||
public ProgressDialog spinnerDialog = null;
|
||||
public ProgressDialog progressDialog = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Notification() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args 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) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
if (action.equals("beep")) {
|
||||
this.beep(args.getLong(0));
|
||||
}
|
||||
else if (action.equals("vibrate")) {
|
||||
this.vibrate(args.getLong(0));
|
||||
}
|
||||
else if (action.equals("alert")) {
|
||||
this.alert(args.getString(0),args.getString(1),args.getString(2), callbackId);
|
||||
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||
r.setKeepCallback(true);
|
||||
return r;
|
||||
}
|
||||
else if (action.equals("confirm")) {
|
||||
this.confirm(args.getString(0),args.getString(1),args.getString(2), callbackId);
|
||||
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||
r.setKeepCallback(true);
|
||||
return r;
|
||||
}
|
||||
else if (action.equals("activityStart")) {
|
||||
this.activityStart(args.getString(0),args.getString(1));
|
||||
}
|
||||
else if (action.equals("activityStop")) {
|
||||
this.activityStop();
|
||||
}
|
||||
else if (action.equals("progressStart")) {
|
||||
this.progressStart(args.getString(0),args.getString(1));
|
||||
}
|
||||
else if (action.equals("progressValue")) {
|
||||
this.progressValue(args.getInt(0));
|
||||
}
|
||||
else if (action.equals("progressStop")) {
|
||||
this.progressStop();
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
} catch (JSONException e) {
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args 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) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
if (action.equals("beep")) {
|
||||
this.beep(args.getLong(0));
|
||||
}
|
||||
else if (action.equals("vibrate")) {
|
||||
this.vibrate(args.getLong(0));
|
||||
}
|
||||
else if (action.equals("alert")) {
|
||||
this.alert(args.getString(0),args.getString(1),args.getString(2), callbackId);
|
||||
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||
r.setKeepCallback(true);
|
||||
return r;
|
||||
}
|
||||
else if (action.equals("confirm")) {
|
||||
this.confirm(args.getString(0),args.getString(1),args.getString(2), callbackId);
|
||||
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||
r.setKeepCallback(true);
|
||||
return r;
|
||||
}
|
||||
else if (action.equals("activityStart")) {
|
||||
this.activityStart(args.getString(0),args.getString(1));
|
||||
}
|
||||
else if (action.equals("activityStop")) {
|
||||
this.activityStop();
|
||||
}
|
||||
else if (action.equals("progressStart")) {
|
||||
this.progressStart(args.getString(0),args.getString(1));
|
||||
}
|
||||
else if (action.equals("progressValue")) {
|
||||
this.progressValue(args.getInt(0));
|
||||
}
|
||||
else if (action.equals("progressStop")) {
|
||||
this.progressStop();
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
} catch (JSONException e) {
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifies if action to be executed returns a value and should be run synchronously.
|
||||
*
|
||||
* @param action The action to execute
|
||||
* @return T=returns value
|
||||
*/
|
||||
public boolean isSynch(String action) {
|
||||
if (action.equals("alert")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("confirm")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("activityStart")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("activityStop")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("progressStart")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("progressValue")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("progressStop")) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Identifies if action to be executed returns a value and should be run synchronously.
|
||||
*
|
||||
* @param action The action to execute
|
||||
* @return T=returns value
|
||||
*/
|
||||
public boolean isSynch(String action) {
|
||||
if (action.equals("alert")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("confirm")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("activityStart")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("activityStop")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("progressStart")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("progressValue")) {
|
||||
return true;
|
||||
}
|
||||
else if (action.equals("progressStop")) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// LOCAL METHODS
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Beep plays the default notification ringtone.
|
||||
*
|
||||
* @param count Number of times to play notification
|
||||
*/
|
||||
public void beep(long count) {
|
||||
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||
Ringtone notification = RingtoneManager.getRingtone(this.ctx.getContext(), ringtone);
|
||||
|
||||
// If phone is not set to silent mode
|
||||
if (notification != null) {
|
||||
for (long i = 0; i < count; ++i) {
|
||||
notification.play();
|
||||
long timeout = 5000;
|
||||
while (notification.isPlaying() && (timeout > 0)) {
|
||||
timeout = timeout - 100;
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Vibrates the device for the specified amount of time.
|
||||
*
|
||||
* @param time Time to vibrate in ms.
|
||||
*/
|
||||
public void vibrate(long time){
|
||||
/**
|
||||
* Beep plays the default notification ringtone.
|
||||
*
|
||||
* @param count Number of times to play notification
|
||||
*/
|
||||
public void beep(long count) {
|
||||
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||
Ringtone notification = RingtoneManager.getRingtone(this.ctx.getContext(), ringtone);
|
||||
|
||||
// If phone is not set to silent mode
|
||||
if (notification != null) {
|
||||
for (long i = 0; i < count; ++i) {
|
||||
notification.play();
|
||||
long timeout = 5000;
|
||||
while (notification.isPlaying() && (timeout > 0)) {
|
||||
timeout = timeout - 100;
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Vibrates the device for the specified amount of time.
|
||||
*
|
||||
* @param time Time to vibrate in ms.
|
||||
*/
|
||||
public void vibrate(long time){
|
||||
// Start the vibration, 0 defaults to half a second.
|
||||
if (time == 0) {
|
||||
time = 500;
|
||||
}
|
||||
if (time == 0) {
|
||||
time = 500;
|
||||
}
|
||||
Vibrator vibrator = (Vibrator) this.ctx.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
vibrator.vibrate(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and shows a native Android alert with given Strings
|
||||
* @param message The message the alert should display
|
||||
* @param title The title of the alert
|
||||
* @param buttonLabel The label of the button
|
||||
* @param callbackId The callback id
|
||||
*/
|
||||
public synchronized void alert(final String message, final String title, final String buttonLabel, final String callbackId) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and shows a native Android alert with given Strings
|
||||
* @param message The message the alert should display
|
||||
* @param title The title of the alert
|
||||
* @param buttonLabel The label of the button
|
||||
* @param callbackId The callback id
|
||||
*/
|
||||
public synchronized void alert(final String message, final String title, final String buttonLabel, final String callbackId) {
|
||||
|
||||
final CordovaInterface ctx = this.ctx;
|
||||
final Notification notification = this;
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
|
||||
dlg.setMessage(message);
|
||||
dlg.setTitle(title);
|
||||
dlg.setCancelable(false);
|
||||
dlg.setPositiveButton(buttonLabel,
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 0), callbackId);
|
||||
}
|
||||
});
|
||||
dlg.create();
|
||||
dlg.show();
|
||||
};
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
final CordovaInterface ctx = this.ctx;
|
||||
final Notification notification = this;
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
|
||||
dlg.setMessage(message);
|
||||
dlg.setTitle(title);
|
||||
dlg.setCancelable(false);
|
||||
dlg.setPositiveButton(buttonLabel,
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 0), callbackId);
|
||||
}
|
||||
});
|
||||
dlg.create();
|
||||
dlg.show();
|
||||
};
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and shows a native Android confirm dialog with given title, message, buttons.
|
||||
* This dialog only shows up to 3 buttons. Any labels after that will be ignored.
|
||||
* The index of the button pressed will be returned to the JavaScript callback identified by callbackId.
|
||||
*
|
||||
* @param message The message the dialog should display
|
||||
* @param title The title of the dialog
|
||||
* @param buttonLabels A comma separated list of button labels (Up to 3 buttons)
|
||||
* @param callbackId The callback id
|
||||
*/
|
||||
public synchronized void confirm(final String message, final String title, String buttonLabels, final String callbackId) {
|
||||
/**
|
||||
* Builds and shows a native Android confirm dialog with given title, message, buttons.
|
||||
* This dialog only shows up to 3 buttons. Any labels after that will be ignored.
|
||||
* The index of the button pressed will be returned to the JavaScript callback identified by callbackId.
|
||||
*
|
||||
* @param message The message the dialog should display
|
||||
* @param title The title of the dialog
|
||||
* @param buttonLabels A comma separated list of button labels (Up to 3 buttons)
|
||||
* @param callbackId The callback id
|
||||
*/
|
||||
public synchronized void confirm(final String message, final String title, String buttonLabels, final String callbackId) {
|
||||
|
||||
final CordovaInterface ctx = this.ctx;
|
||||
final Notification notification = this;
|
||||
final String[] fButtons = buttonLabels.split(",");
|
||||
final CordovaInterface ctx = this.ctx;
|
||||
final Notification notification = this;
|
||||
final String[] fButtons = buttonLabels.split(",");
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
|
||||
dlg.setMessage(message);
|
||||
dlg.setTitle(title);
|
||||
dlg.setCancelable(false);
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
|
||||
dlg.setMessage(message);
|
||||
dlg.setTitle(title);
|
||||
dlg.setCancelable(false);
|
||||
|
||||
// First button
|
||||
if (fButtons.length > 0) {
|
||||
dlg.setPositiveButton(fButtons[0],
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 1), callbackId);
|
||||
}
|
||||
});
|
||||
}
|
||||
// First button
|
||||
if (fButtons.length > 0) {
|
||||
dlg.setPositiveButton(fButtons[0],
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 1), callbackId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Second button
|
||||
if (fButtons.length > 1) {
|
||||
dlg.setNeutralButton(fButtons[1],
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 2), callbackId);
|
||||
}
|
||||
});
|
||||
}
|
||||
// Second button
|
||||
if (fButtons.length > 1) {
|
||||
dlg.setNeutralButton(fButtons[1],
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 2), callbackId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Third button
|
||||
if (fButtons.length > 2) {
|
||||
dlg.setNegativeButton(fButtons[2],
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 3), callbackId);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
// Third button
|
||||
if (fButtons.length > 2) {
|
||||
dlg.setNegativeButton(fButtons[2],
|
||||
new AlertDialog.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
notification.success(new PluginResult(PluginResult.Status.OK, 3), callbackId);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
dlg.create();
|
||||
dlg.show();
|
||||
};
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
dlg.create();
|
||||
dlg.show();
|
||||
};
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the spinner.
|
||||
*
|
||||
* @param title Title of the dialog
|
||||
* @param message The message of the dialog
|
||||
*/
|
||||
public synchronized void activityStart(final String title, final String message) {
|
||||
if (this.spinnerDialog != null) {
|
||||
this.spinnerDialog.dismiss();
|
||||
this.spinnerDialog = null;
|
||||
}
|
||||
final Notification notification = this;
|
||||
final CordovaInterface ctx = this.ctx;
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
notification.spinnerDialog = ProgressDialog.show(ctx.getContext(), title , message, true, true,
|
||||
new DialogInterface.OnCancelListener() {
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
notification.spinnerDialog = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop spinner.
|
||||
*/
|
||||
public synchronized void activityStop() {
|
||||
if (this.spinnerDialog != null) {
|
||||
this.spinnerDialog.dismiss();
|
||||
this.spinnerDialog = null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Show the spinner.
|
||||
*
|
||||
* @param title Title of the dialog
|
||||
* @param message The message of the dialog
|
||||
*/
|
||||
public synchronized void activityStart(final String title, final String message) {
|
||||
if (this.spinnerDialog != null) {
|
||||
this.spinnerDialog.dismiss();
|
||||
this.spinnerDialog = null;
|
||||
}
|
||||
final Notification notification = this;
|
||||
final CordovaInterface ctx = this.ctx;
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
notification.spinnerDialog = ProgressDialog.show(ctx.getContext(), title , message, true, true,
|
||||
new DialogInterface.OnCancelListener() {
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
notification.spinnerDialog = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop spinner.
|
||||
*/
|
||||
public synchronized void activityStop() {
|
||||
if (this.spinnerDialog != null) {
|
||||
this.spinnerDialog.dismiss();
|
||||
this.spinnerDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the progress dialog.
|
||||
*
|
||||
* @param title Title of the dialog
|
||||
* @param message The message of the dialog
|
||||
*/
|
||||
public synchronized void progressStart(final String title, final String message) {
|
||||
if (this.progressDialog != null) {
|
||||
this.progressDialog.dismiss();
|
||||
this.progressDialog = null;
|
||||
}
|
||||
final Notification notification = this;
|
||||
final CordovaInterface ctx = this.ctx;
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
notification.progressDialog = new ProgressDialog(ctx.getContext());
|
||||
notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
notification.progressDialog.setTitle(title);
|
||||
notification.progressDialog.setMessage(message);
|
||||
notification.progressDialog.setCancelable(true);
|
||||
notification.progressDialog.setMax(100);
|
||||
notification.progressDialog.setProgress(0);
|
||||
notification.progressDialog.setOnCancelListener(
|
||||
new DialogInterface.OnCancelListener() {
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
notification.progressDialog = null;
|
||||
}
|
||||
});
|
||||
notification.progressDialog.show();
|
||||
}
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value of progress bar.
|
||||
*
|
||||
* @param value 0-100
|
||||
*/
|
||||
public synchronized void progressValue(int value) {
|
||||
if (this.progressDialog != null) {
|
||||
this.progressDialog.setProgress(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop progress dialog.
|
||||
*/
|
||||
public synchronized void progressStop() {
|
||||
if (this.progressDialog != null) {
|
||||
this.progressDialog.dismiss();
|
||||
this.progressDialog = null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Show the progress dialog.
|
||||
*
|
||||
* @param title Title of the dialog
|
||||
* @param message The message of the dialog
|
||||
*/
|
||||
public synchronized void progressStart(final String title, final String message) {
|
||||
if (this.progressDialog != null) {
|
||||
this.progressDialog.dismiss();
|
||||
this.progressDialog = null;
|
||||
}
|
||||
final Notification notification = this;
|
||||
final CordovaInterface ctx = this.ctx;
|
||||
Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
notification.progressDialog = new ProgressDialog(ctx.getContext());
|
||||
notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
notification.progressDialog.setTitle(title);
|
||||
notification.progressDialog.setMessage(message);
|
||||
notification.progressDialog.setCancelable(true);
|
||||
notification.progressDialog.setMax(100);
|
||||
notification.progressDialog.setProgress(0);
|
||||
notification.progressDialog.setOnCancelListener(
|
||||
new DialogInterface.OnCancelListener() {
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
notification.progressDialog = null;
|
||||
}
|
||||
});
|
||||
notification.progressDialog.show();
|
||||
}
|
||||
};
|
||||
this.ctx.runOnUiThread(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value of progress bar.
|
||||
*
|
||||
* @param value 0-100
|
||||
*/
|
||||
public synchronized void progressValue(int value) {
|
||||
if (this.progressDialog != null) {
|
||||
this.progressDialog.setProgress(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop progress dialog.
|
||||
*/
|
||||
public synchronized void progressStop() {
|
||||
if (this.progressDialog != null) {
|
||||
this.progressDialog.dismiss();
|
||||
this.progressDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ public class Storage extends Plugin {
|
||||
try {
|
||||
if (isDDL(query)) {
|
||||
this.myDb.execSQL(query);
|
||||
this.sendJavascript("droiddb.completeQuery('" + tx_id + "', '');");
|
||||
this.sendJavascript("require('cordova/plugin/android/storage').completeQuery('" + tx_id + "', '');");
|
||||
}
|
||||
else {
|
||||
Cursor myCursor = this.myDb.rawQuery(query, params);
|
||||
@@ -175,7 +175,7 @@ public class Storage extends Plugin {
|
||||
System.out.println("Storage.executeSql(): Error=" + ex.getMessage());
|
||||
|
||||
// Send error message back to JavaScript
|
||||
this.sendJavascript("droiddb.fail('" + ex.getMessage() + "','" + tx_id + "');");
|
||||
this.sendJavascript("require('cordova/plugin/android/storage').fail('" + ex.getMessage() + "','" + tx_id + "');");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ public class Storage extends Plugin {
|
||||
}
|
||||
|
||||
// Let JavaScript know that there are no more rows
|
||||
this.sendJavascript("droiddb.completeQuery('" + tx_id + "', " + result + ");");
|
||||
this.sendJavascript("require('cordova/plugin/android/storage').completeQuery('" + tx_id + "', " + result + ");");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,7 +68,14 @@ public interface CordovaInterface {
|
||||
* @param requestCode The request code that is passed to callback to identify the activity
|
||||
*/
|
||||
abstract public void startActivityForResult(IPlugin command, Intent intent, int requestCode);
|
||||
|
||||
|
||||
/**
|
||||
* Launch an activity for which you would not like a result when it finished.
|
||||
*
|
||||
* @param intent The intent to start
|
||||
*/
|
||||
abstract public void startActivity(Intent intent);
|
||||
|
||||
/**
|
||||
* Set the plugin to be called when a sub-activity exits.
|
||||
*
|
||||
@@ -91,6 +98,7 @@ public interface CordovaInterface {
|
||||
*/
|
||||
abstract public void postMessage(String id, Object data);
|
||||
|
||||
|
||||
public abstract Resources getResources();
|
||||
|
||||
public abstract String getPackageName();
|
||||
@@ -108,9 +116,9 @@ public interface CordovaInterface {
|
||||
|
||||
public abstract void unregisterReceiver(BroadcastReceiver receiver);
|
||||
|
||||
public abstract Cursor managedQuery(Uri parse, String[] strings,
|
||||
Object object, Object object2, Object object3);
|
||||
|
||||
public abstract Cursor managedQuery(Uri uri, String[] projection, String selection,
|
||||
String[] selectionArgs, String sortOrder);
|
||||
|
||||
public abstract void runOnUiThread(Runnable runnable);
|
||||
|
||||
public abstract AssetManager getAssets();
|
||||
@@ -133,4 +141,5 @@ public interface CordovaInterface {
|
||||
boolean clearHistory, HashMap<String, Object> params);
|
||||
|
||||
public abstract Context getApplicationContext();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user