mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-27 04:42:51 +08:00
Merge github.com:phonegap/phonegap-android
Conflicts: framework/assets/www/phonegap.js framework/src/com/phonegap/DroidGap.java
This commit is contained in:
commit
1e4dc1bf5d
@ -31,7 +31,7 @@ Commands:
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
help ...... See this message. Type help [command name] to see specific help topics.
|
help ...... See this message. Type help [command name] to see specific help topics.
|
||||||
gen ....... Generate an example PhoneGap application to current directory.
|
gen ....... Generate the example PhoneGap application to current directory (or optionally provide an output directory as parameter).
|
||||||
create .... Creates an Android compatible project from a WWW folder.
|
create .... Creates an Android compatible project from a WWW folder.
|
||||||
classic ... Backwards support for droidgap script. Run "droidgap help classic" for more info.
|
classic ... Backwards support for droidgap script. Run "droidgap help classic" for more info.
|
||||||
update .... Copy a fresh phonegap.jar and phonegap.js into a valid PhoneGap/Android project.
|
update .... Copy a fresh phonegap.jar and phonegap.js into a valid PhoneGap/Android project.
|
||||||
@ -41,8 +41,8 @@ Commands:
|
|||||||
Quickstart:
|
Quickstart:
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
$ droidgap gen example
|
$ droidgap gen exampleapp
|
||||||
$ cd example
|
$ cd exampleapp
|
||||||
$ ant debug install && adb logcat
|
$ ant debug install && adb logcat
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
12
bin/droidgap
12
bin/droidgap
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
ROOT = File.expand_path(File.dirname(__FILE__).gsub('bin',''))
|
ROOT = File.expand_path(File.dirname(__FILE__).gsub(/bin$/,''))
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require File.join(ROOT, "lib", "generate.rb")
|
require File.join(ROOT, "lib", "generate.rb")
|
||||||
require File.join(ROOT, "lib", "classic.rb")
|
require File.join(ROOT, "lib", "classic.rb")
|
||||||
@ -60,7 +60,7 @@ if ARGV.first.nil? || ARGV.first == 'help'
|
|||||||
Commands:
|
Commands:
|
||||||
|
|
||||||
help ...... See this message. Type help [command name] to see specific help topics.
|
help ...... See this message. Type help [command name] to see specific help topics.
|
||||||
gen ....... Generate an example PhoneGap application to current directory.
|
gen ....... Generate the example PhoneGap application to current directory (or optionally provide an output directory as parameter).
|
||||||
create .... Creates an Android compatible project from a WWW folder.
|
create .... Creates an Android compatible project from a WWW folder.
|
||||||
classic ... Backwards support for droidgap script. Run "droidgap help classic" for more info.
|
classic ... Backwards support for droidgap script. Run "droidgap help classic" for more info.
|
||||||
update .... Copy a fresh phonegap.jar and phonegap.js into a valid PhoneGap/Android project.
|
update .... Copy a fresh phonegap.jar and phonegap.js into a valid PhoneGap/Android project.
|
||||||
@ -68,8 +68,8 @@ if ARGV.first.nil? || ARGV.first == 'help'
|
|||||||
|
|
||||||
Quickstart:
|
Quickstart:
|
||||||
|
|
||||||
$ droidgap gen example
|
$ droidgap gen exampleapp
|
||||||
$ cd example
|
$ cd exampleapp
|
||||||
$ ant debug install && adb logcat
|
$ ant debug install && adb logcat
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
@ -79,11 +79,13 @@ if ARGV.first.nil? || ARGV.first == 'help'
|
|||||||
DroidGap Generate
|
DroidGap Generate
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
Generate an example PhoneGap application to path supplied or current working directory if none is supplied.
|
Generate the example PhoneGap application to path supplied or current working directory if none is supplied.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
droidgap gen [path]
|
droidgap gen [path]
|
||||||
|
|
||||||
|
NOTE: Do *not* run "droidgap gen example" - you will end up with a recursive directory problem.
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
@ -5,141 +5,32 @@
|
|||||||
<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.js"></script>
|
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.4.min.js"></script>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8" src="main.js"></script>
|
||||||
|
|
||||||
var deviceInfo = function(){
|
|
||||||
document.getElementById("platform").innerHTML = device.platform;
|
|
||||||
document.getElementById("version").innerHTML = device.version;
|
|
||||||
document.getElementById("uuid").innerHTML = device.uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
var getLocation = function() {
|
|
||||||
var suc = function(p){
|
|
||||||
alert(p.coords.latitude + " " + p.coords.longitude);
|
|
||||||
};
|
|
||||||
var fail = function(){};
|
|
||||||
navigator.geolocation.getCurrentPosition(suc,fail);
|
|
||||||
}
|
|
||||||
|
|
||||||
var beep = function(){
|
|
||||||
navigator.notification.beep(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
var vibrate = function(){
|
|
||||||
navigator.notification.vibrate(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
var getContact = function(){
|
|
||||||
var suc = function(c){ alert("Contact 4: " + c.contacts[3].name); };
|
|
||||||
var fail = function(){};
|
|
||||||
navigator.ContactManager.get(suc, fail);
|
|
||||||
}
|
|
||||||
|
|
||||||
var watchAccel = function() {
|
|
||||||
var suc = function(a){
|
|
||||||
document.getElementById('x').innerHTML = roundNumber(a.x);
|
|
||||||
document.getElementById('y').innerHTML = roundNumber(a.y);
|
|
||||||
document.getElementById('z').innerHTML = roundNumber(a.z);
|
|
||||||
};
|
|
||||||
var fail = function(){};
|
|
||||||
var opt = {};
|
|
||||||
opt.frequency = 100;
|
|
||||||
timer = navigator.accelerometer.watchAcceleration(suc,fail,opt);
|
|
||||||
}
|
|
||||||
|
|
||||||
function roundNumber(num) {
|
|
||||||
var dec = 3;
|
|
||||||
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var preventBehavior = function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
};
|
|
||||||
|
|
||||||
function show_pic()
|
|
||||||
{
|
|
||||||
var viewport = document.getElementById('viewport');
|
|
||||||
viewport.style.display = "";
|
|
||||||
navigator.camera.getPicture(dump_pic, fail, { quality: 50 });
|
|
||||||
}
|
|
||||||
|
|
||||||
function dump_pic(data)
|
|
||||||
{
|
|
||||||
var viewport = document.getElementById('viewport');
|
|
||||||
console.log(data);
|
|
||||||
viewport.style.display = "";
|
|
||||||
viewport.style.position = "absolute";
|
|
||||||
viewport.style.top = "10px";
|
|
||||||
viewport.style.left = "10px";
|
|
||||||
document.getElementById("test_img").src = "data:image/jpeg;base64," + data;
|
|
||||||
}
|
|
||||||
|
|
||||||
function close()
|
|
||||||
{
|
|
||||||
var viewport = document.getElementById('viewport');
|
|
||||||
viewport.style.position = "relative";
|
|
||||||
viewport.style.display = "none";
|
|
||||||
}
|
|
||||||
|
|
||||||
function fail(fail)
|
|
||||||
{
|
|
||||||
alert(fail);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is just to do this.
|
|
||||||
function readFile()
|
|
||||||
{
|
|
||||||
navigator.file.read('/sdcard/phonegap.txt', fail , fail);
|
|
||||||
}
|
|
||||||
|
|
||||||
function writeFile()
|
|
||||||
{
|
|
||||||
navigator.file.write('foo.txt', "This is a test of writing to a file", fail, fail);
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_contacts()
|
|
||||||
{
|
|
||||||
var obj = new ContactFindOptions();
|
|
||||||
obj.filter="";
|
|
||||||
obj.multiple=true;
|
|
||||||
obj.limit=5;
|
|
||||||
navigator.service.contacts.find(["displayName", "phoneNumbers", "emails"], count_contacts, fail, obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
function count_contacts(contacts)
|
|
||||||
{
|
|
||||||
alert(contacts.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
function init(){
|
|
||||||
document.addEventListener("touchmove", preventBehavior, false);
|
|
||||||
document.addEventListener("deviceready", deviceInfo, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</head>
|
</head>
|
||||||
<body onload="init();" id="stage" class="theme">
|
<body onload="init();" id="stage" class="theme">
|
||||||
<h1>Welcome to PhoneGap!</h1>
|
<h1>Welcome to PhoneGap!</h1>
|
||||||
<h2>this file is located at assets/index.html</h2>
|
<h2>this file is located at assets/www/index.html</h2>
|
||||||
<div id="info">
|
<div id="info">
|
||||||
<h4>Platform: <span id="platform"> </span></h4>
|
<h4>Platform: <span id="platform"> </span>, Version: <span id="version"> </span></h4>
|
||||||
<h4>Version: <span id="version"> </span></h4>
|
<h4>UUID: <span id="uuid"> </span>, Name: <span id="name"> </span></h4>
|
||||||
<h4>UUID: <span id="uuid"> </span></h4>
|
<h4>Width: <span id="width"> </span>, Height: <span id="height">
|
||||||
</div>
|
</span>, Color Depth: <span id="colorDepth"></span></h4>
|
||||||
|
</div>
|
||||||
<dl id="accel-data">
|
<dl id="accel-data">
|
||||||
<dt>X:</dt><dd id="x"> </dd>
|
<dt>X:</dt><dd id="x"> </dd>
|
||||||
<dt>Y:</dt><dd id="y"> </dd>
|
<dt>Y:</dt><dd id="y"> </dd>
|
||||||
<dt>Z:</dt><dd id="z"> </dd>
|
<dt>Z:</dt><dd id="z"> </dd>
|
||||||
</dl>
|
</dl>
|
||||||
<a href="#" class="btn large" onclick="watchAccel();">Watch Accelerometer</a>
|
<a href="#" class="btn large" onclick="toggleAccel();">Toggle Accelerometer</a>
|
||||||
<a href="#" class="btn large" onclick="getLocation();">Get Location</a>
|
<a href="#" class="btn large" onclick="getLocation();">Get Location</a>
|
||||||
<a href="tel://411" class="btn large">Call 411</a>
|
<a href="tel://411" class="btn large">Call 411</a>
|
||||||
<a href="#" class="btn large" onclick="beep();">Beep</a>
|
<a href="#" class="btn large" onclick="beep();">Beep</a>
|
||||||
<a href="#" class="btn large" onclick="vibrate();">Vibrate</a>
|
<a href="#" class="btn large" onclick="vibrate();">Vibrate</a>
|
||||||
<a href="#" class="btn large" onclick="show_pic();">Get a Picture</a>
|
<a href="#" class="btn large" onclick="show_pic();">Get a Picture</a>
|
||||||
<a href="#" class="btn large" onclick="get_contacts();">Get phone's contacts</a>
|
<a href="#" class="btn large" onclick="get_contacts();">Get Phone's Contacts</a>
|
||||||
|
<a href="#" class="btn large" onclick="check_network();">Check Network</a>
|
||||||
<div id="viewport" class="viewport" style="display: none;">
|
<div id="viewport" class="viewport" style="display: none;">
|
||||||
<img style="width:60px;height:60px" id="test_img" src="" />
|
<img style="width:60px;height:60px" id="test_img" src="" />
|
||||||
</div>
|
</div>
|
||||||
|
140
example/main.js
Normal file
140
example/main.js
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
var deviceInfo = function() {
|
||||||
|
document.getElementById("platform").innerHTML = device.platform;
|
||||||
|
document.getElementById("version").innerHTML = device.version;
|
||||||
|
document.getElementById("uuid").innerHTML = device.uuid;
|
||||||
|
document.getElementById("name").innerHTML = device.name;
|
||||||
|
document.getElementById("width").innerHTML = screen.width;
|
||||||
|
document.getElementById("height").innerHTML = screen.height;
|
||||||
|
document.getElementById("colorDepth").innerHTML = screen.colorDepth;
|
||||||
|
};
|
||||||
|
|
||||||
|
var getLocation = function() {
|
||||||
|
var suc = function(p) {
|
||||||
|
alert(p.coords.latitude + " " + p.coords.longitude);
|
||||||
|
};
|
||||||
|
var locFail = function() {
|
||||||
|
};
|
||||||
|
navigator.geolocation.getCurrentPosition(suc, locFail);
|
||||||
|
};
|
||||||
|
|
||||||
|
var beep = function() {
|
||||||
|
navigator.notification.beep(2);
|
||||||
|
};
|
||||||
|
|
||||||
|
var vibrate = function() {
|
||||||
|
navigator.notification.vibrate(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
function roundNumber(num) {
|
||||||
|
var dec = 3;
|
||||||
|
var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
var accelerationWatch = null;
|
||||||
|
|
||||||
|
function updateAcceleration(a) {
|
||||||
|
document.getElementById('x').innerHTML = roundNumber(a.x);
|
||||||
|
document.getElementById('y').innerHTML = roundNumber(a.y);
|
||||||
|
document.getElementById('z').innerHTML = roundNumber(a.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
var toggleAccel = function() {
|
||||||
|
if (accelerationWatch !== null) {
|
||||||
|
navigator.accelerometer.clearWatch(accelerationWatch);
|
||||||
|
updateAcceleration({
|
||||||
|
x : "",
|
||||||
|
y : "",
|
||||||
|
z : ""
|
||||||
|
});
|
||||||
|
accelerationWatch = null;
|
||||||
|
} else {
|
||||||
|
var options = {};
|
||||||
|
options.frequency = 1000;
|
||||||
|
accelerationWatch = navigator.accelerometer.watchAcceleration(
|
||||||
|
updateAcceleration, function(ex) {
|
||||||
|
alert("accel fail (" + ex.name + ": " + ex.message + ")");
|
||||||
|
}, options);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var preventBehavior = function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
};
|
||||||
|
|
||||||
|
function dump_pic(data) {
|
||||||
|
var viewport = document.getElementById('viewport');
|
||||||
|
console.log(data);
|
||||||
|
viewport.style.display = "";
|
||||||
|
viewport.style.position = "absolute";
|
||||||
|
viewport.style.top = "10px";
|
||||||
|
viewport.style.left = "10px";
|
||||||
|
document.getElementById("test_img").src = "data:image/jpeg;base64," + data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fail(msg) {
|
||||||
|
alert(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
function show_pic() {
|
||||||
|
navigator.camera.getPicture(dump_pic, fail, {
|
||||||
|
quality : 50
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
var viewport = document.getElementById('viewport');
|
||||||
|
viewport.style.position = "relative";
|
||||||
|
viewport.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is just to do this.
|
||||||
|
function readFile() {
|
||||||
|
navigator.file.read('/sdcard/phonegap.txt', fail, fail);
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeFile() {
|
||||||
|
navigator.file.write('foo.txt', "This is a test of writing to a file",
|
||||||
|
fail, fail);
|
||||||
|
}
|
||||||
|
|
||||||
|
function contacts_success(contacts) {
|
||||||
|
alert(contacts.length
|
||||||
|
+ ' contacts returned.'
|
||||||
|
+ (contacts[2] && contacts[2].name ? (' Third contact is ' + contacts[2].name.formatted)
|
||||||
|
: ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_contacts() {
|
||||||
|
var obj = new ContactFindOptions();
|
||||||
|
obj.filter = "";
|
||||||
|
obj.multiple = true;
|
||||||
|
obj.limit = 5;
|
||||||
|
navigator.service.contacts.find(
|
||||||
|
[ "displayName", "name" ], contacts_success,
|
||||||
|
fail, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
var networkReachableCallback = function(reachability) {
|
||||||
|
// There is no consistency on the format of reachability
|
||||||
|
var networkState = reachability.code || reachability;
|
||||||
|
|
||||||
|
var currentState = {};
|
||||||
|
currentState[NetworkStatus.NOT_REACHABLE] = 'No network connection';
|
||||||
|
currentState[NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK] = 'Carrier data connection';
|
||||||
|
currentState[NetworkStatus.REACHABLE_VIA_WIFI_NETWORK] = 'WiFi connection';
|
||||||
|
|
||||||
|
confirm("Connection type:\n" + currentState[networkState]);
|
||||||
|
};
|
||||||
|
|
||||||
|
function check_network() {
|
||||||
|
navigator.network.isReachable("www.mobiledevelopersolutions.com",
|
||||||
|
networkReachableCallback, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
// the next line makes it impossible to see Contacts on the HTC Evo since it
|
||||||
|
// doesn't have a scroll button
|
||||||
|
// document.addEventListener("touchmove", preventBehavior, false);
|
||||||
|
document.addEventListener("deviceready", deviceInfo, true);
|
||||||
|
}
|
@ -11,7 +11,7 @@ function Acceleration(x, y, z) {
|
|||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.timestamp = new Date().getTime();
|
this.timestamp = new Date().getTime();
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides access to device accelerometer data.
|
* This class provides access to device accelerometer data.
|
||||||
@ -28,7 +28,7 @@ function Accelerometer() {
|
|||||||
* List of accelerometer watch timers
|
* List of accelerometer watch timers
|
||||||
*/
|
*/
|
||||||
this.timers = {};
|
this.timers = {};
|
||||||
};
|
}
|
||||||
|
|
||||||
Accelerometer.ERROR_MSG = ["Not running", "Starting", "", "Failed to start"];
|
Accelerometer.ERROR_MSG = ["Not running", "Starting", "", "Failed to start"];
|
||||||
|
|
||||||
@ -40,16 +40,15 @@ Accelerometer.ERROR_MSG = ["Not running", "Starting", "", "Failed to start"];
|
|||||||
* @param {AccelerationOptions} options The options for getting the accelerometer data such as timeout. (OPTIONAL)
|
* @param {AccelerationOptions} options The options for getting the accelerometer data such as timeout. (OPTIONAL)
|
||||||
*/
|
*/
|
||||||
Accelerometer.prototype.getCurrentAcceleration = function(successCallback, errorCallback, options) {
|
Accelerometer.prototype.getCurrentAcceleration = function(successCallback, errorCallback, options) {
|
||||||
console.log("Accelerometer.getCurrentAcceleration()");
|
|
||||||
|
|
||||||
// successCallback required
|
// successCallback required
|
||||||
if (typeof successCallback != "function") {
|
if (typeof successCallback !== "function") {
|
||||||
console.log("Accelerometer Error: successCallback is not a function");
|
console.log("Accelerometer Error: successCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// errorCallback optional
|
// errorCallback optional
|
||||||
if (errorCallback && (typeof errorCallback != "function")) {
|
if (errorCallback && (typeof errorCallback !== "function")) {
|
||||||
console.log("Accelerometer Error: errorCallback is not a function");
|
console.log("Accelerometer Error: errorCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -69,16 +68,16 @@ Accelerometer.prototype.getCurrentAcceleration = function(successCallback, error
|
|||||||
Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallback, options) {
|
Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallback, options) {
|
||||||
|
|
||||||
// Default interval (10 sec)
|
// Default interval (10 sec)
|
||||||
var frequency = (options != undefined)? options.frequency : 10000;
|
var frequency = (options !== undefined)? options.frequency : 10000;
|
||||||
|
|
||||||
// successCallback required
|
// successCallback required
|
||||||
if (typeof successCallback != "function") {
|
if (typeof successCallback !== "function") {
|
||||||
console.log("Accelerometer Error: successCallback is not a function");
|
console.log("Accelerometer Error: successCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// errorCallback optional
|
// errorCallback optional
|
||||||
if (errorCallback && (typeof errorCallback != "function")) {
|
if (errorCallback && (typeof errorCallback !== "function")) {
|
||||||
console.log("Accelerometer Error: errorCallback is not a function");
|
console.log("Accelerometer Error: errorCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -109,12 +108,14 @@ Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallb
|
|||||||
Accelerometer.prototype.clearWatch = function(id) {
|
Accelerometer.prototype.clearWatch = function(id) {
|
||||||
|
|
||||||
// Stop javascript timer & remove from timer list
|
// Stop javascript timer & remove from timer list
|
||||||
if (id && navigator.accelerometer.timers[id] != undefined) {
|
if (id && navigator.accelerometer.timers[id] !== undefined) {
|
||||||
clearInterval(navigator.accelerometer.timers[id]);
|
clearInterval(navigator.accelerometer.timers[id]);
|
||||||
delete navigator.accelerometer.timers[id];
|
delete navigator.accelerometer.timers[id];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
if (typeof navigator.accelerometer == "undefined") navigator.accelerometer = new Accelerometer();
|
if (typeof navigator.accelerometer === "undefined") {
|
||||||
|
navigator.accelerometer = new Accelerometer();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
89
framework/assets/js/app.js
Executable file
89
framework/assets/js/app.js
Executable file
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
function App() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the resource cache.
|
||||||
|
*/
|
||||||
|
App.prototype.clearCache = function() {
|
||||||
|
PhoneGap.exec(null, null, "App", "clearCache", []);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the url into the webview.
|
||||||
|
*
|
||||||
|
* @param url The URL to load
|
||||||
|
* @param props Properties that can be passed in to the activity:
|
||||||
|
* wait: int => wait msec before loading URL
|
||||||
|
* loadingDialog: "Title,Message" => display a native loading dialog
|
||||||
|
* hideLoadingDialogOnPage: boolean => hide loadingDialog when page loaded instead of when deviceready event occurs.
|
||||||
|
* loadInWebView: boolean => cause all links on web page to be loaded into existing web view, instead of being loaded into new browser.
|
||||||
|
* loadUrlTimeoutValue: int => time in msec to wait before triggering a timeout error
|
||||||
|
* errorUrl: URL => URL to load if there's an error loading specified URL with loadUrl(). Should be a local URL such as file:///android_asset/www/error.html");
|
||||||
|
* keepRunning: boolean => enable app to keep running in background
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* App app = new App();
|
||||||
|
* app.loadUrl("http://server/myapp/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000});
|
||||||
|
*/
|
||||||
|
App.prototype.loadUrl = function(url, props) {
|
||||||
|
PhoneGap.exec(null, null, "App", "loadUrl", [url, props]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel loadUrl that is waiting to be loaded.
|
||||||
|
*/
|
||||||
|
App.prototype.cancelLoadUrl = function() {
|
||||||
|
PhoneGap.exec(null, null, "App", "cancelLoadUrl", []);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear web history in this web view.
|
||||||
|
* Instead of BACK button loading the previous web page, it will exit the app.
|
||||||
|
*/
|
||||||
|
App.prototype.clearHistory = function() {
|
||||||
|
PhoneGap.exec(null, null, "App", "clearHistory", []);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a class that implements a service.
|
||||||
|
*
|
||||||
|
* @param serviceType
|
||||||
|
* @param className
|
||||||
|
*/
|
||||||
|
App.prototype.addService = function(serviceType, className) {
|
||||||
|
PhoneGap.exec(null, null, "App", "addService", [serviceType, className]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override the default behavior of the Android back button.
|
||||||
|
* If overridden, when the back button is pressed, the "backKeyDown" JavaScript event will be fired.
|
||||||
|
*
|
||||||
|
* Note: The user should not have to call this method. Instead, when the user
|
||||||
|
* registers for the "backbutton" event, this is automatically done.
|
||||||
|
*
|
||||||
|
* @param override T=override, F=cancel override
|
||||||
|
*/
|
||||||
|
App.prototype.overrideBackbutton = function(override) {
|
||||||
|
PhoneGap.exec(null, null, "App", "overrideBackbutton", [override]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exit and terminate the application.
|
||||||
|
*/
|
||||||
|
App.prototype.exitApp = function() {
|
||||||
|
return PhoneGap.exec(null, null, "App", "exitApp", []);
|
||||||
|
};
|
||||||
|
|
||||||
|
PhoneGap.addConstructor(function() {
|
||||||
|
navigator.app = window.app = new App();
|
||||||
|
});
|
@ -59,19 +59,17 @@ Camera.prototype.PictureSourceType = Camera.PictureSourceType;
|
|||||||
Camera.prototype.getPicture = function(successCallback, errorCallback, options) {
|
Camera.prototype.getPicture = function(successCallback, errorCallback, options) {
|
||||||
|
|
||||||
// successCallback required
|
// successCallback required
|
||||||
if (typeof successCallback != "function") {
|
if (typeof successCallback !== "function") {
|
||||||
console.log("Camera Error: successCallback is not a function");
|
console.log("Camera Error: successCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// errorCallback optional
|
// errorCallback optional
|
||||||
if (errorCallback && (typeof errorCallback != "function")) {
|
if (errorCallback && (typeof errorCallback !== "function")) {
|
||||||
console.log("Camera Error: errorCallback is not a function");
|
console.log("Camera Error: errorCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.successCallback = successCallback;
|
|
||||||
this.errorCallback = errorCallback;
|
|
||||||
this.options = options;
|
this.options = options;
|
||||||
var quality = 80;
|
var quality = 80;
|
||||||
if (options.quality) {
|
if (options.quality) {
|
||||||
@ -82,45 +80,14 @@ Camera.prototype.getPicture = function(successCallback, errorCallback, options)
|
|||||||
destinationType = this.options.destinationType;
|
destinationType = this.options.destinationType;
|
||||||
}
|
}
|
||||||
var sourceType = Camera.PictureSourceType.CAMERA;
|
var sourceType = Camera.PictureSourceType.CAMERA;
|
||||||
if (typeof this.options.sourceType == "number") {
|
if (typeof this.options.sourceType === "number") {
|
||||||
sourceType = this.options.sourceType;
|
sourceType = this.options.sourceType;
|
||||||
}
|
}
|
||||||
PhoneGap.exec(null, null, "Camera", "takePicture", [quality, destinationType, sourceType]);
|
PhoneGap.exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType]);
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback function from native code that is called when image has been captured.
|
|
||||||
*
|
|
||||||
* @param picture The base64 encoded string of the image
|
|
||||||
*/
|
|
||||||
Camera.prototype.success = function(picture) {
|
|
||||||
if (this.successCallback) {
|
|
||||||
try {
|
|
||||||
this.successCallback(picture);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
console.log("Camera error calling user's success callback: " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback function from native code that is called when there is an error
|
|
||||||
* capturing an image, or the capture is cancelled.
|
|
||||||
*
|
|
||||||
* @param err The error message
|
|
||||||
*/
|
|
||||||
Camera.prototype.error = function(err) {
|
|
||||||
if (this.errorCallback) {
|
|
||||||
try {
|
|
||||||
this.errorCallback(err);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
console.log("Camera error calling user's error callback: " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
if (typeof navigator.camera == "undefined") navigator.camera = new Camera();
|
if (typeof navigator.camera === "undefined") {
|
||||||
|
navigator.camera = new Camera();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
@ -20,7 +20,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"];
|
||||||
|
|
||||||
@ -34,13 +34,13 @@ Compass.ERROR_MSG = ["Not running", "Starting", "", "Failed to start"];
|
|||||||
Compass.prototype.getCurrentHeading = function(successCallback, errorCallback, options) {
|
Compass.prototype.getCurrentHeading = function(successCallback, errorCallback, options) {
|
||||||
|
|
||||||
// successCallback required
|
// successCallback required
|
||||||
if (typeof successCallback != "function") {
|
if (typeof successCallback !== "function") {
|
||||||
console.log("Compass Error: successCallback is not a function");
|
console.log("Compass Error: successCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// errorCallback optional
|
// errorCallback optional
|
||||||
if (errorCallback && (typeof errorCallback != "function")) {
|
if (errorCallback && (typeof errorCallback !== "function")) {
|
||||||
console.log("Compass Error: errorCallback is not a function");
|
console.log("Compass Error: errorCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -60,16 +60,16 @@ Compass.prototype.getCurrentHeading = function(successCallback, errorCallback, o
|
|||||||
Compass.prototype.watchHeading= function(successCallback, errorCallback, options) {
|
Compass.prototype.watchHeading= function(successCallback, errorCallback, options) {
|
||||||
|
|
||||||
// Default interval (100 msec)
|
// Default interval (100 msec)
|
||||||
var frequency = (options != undefined) ? options.frequency : 100;
|
var frequency = (options !== undefined) ? options.frequency : 100;
|
||||||
|
|
||||||
// successCallback required
|
// successCallback required
|
||||||
if (typeof successCallback != "function") {
|
if (typeof successCallback !== "function") {
|
||||||
console.log("Compass Error: successCallback is not a function");
|
console.log("Compass Error: successCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// errorCallback optional
|
// errorCallback optional
|
||||||
if (errorCallback && (typeof errorCallback != "function")) {
|
if (errorCallback && (typeof errorCallback !== "function")) {
|
||||||
console.log("Compass Error: errorCallback is not a function");
|
console.log("Compass Error: errorCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -109,5 +109,7 @@ Compass.prototype.clearWatch = function(id) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
if (typeof navigator.compass == "undefined") navigator.compass = new Compass();
|
if (typeof navigator.compass === "undefined") {
|
||||||
|
navigator.compass = new Compass();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
@ -17,25 +17,19 @@
|
|||||||
* @param {ContactAddress[]} addresses array of addresses
|
* @param {ContactAddress[]} addresses array of addresses
|
||||||
* @param {ContactField[]} ims instant messaging user ids
|
* @param {ContactField[]} ims instant messaging user ids
|
||||||
* @param {ContactOrganization[]} organizations
|
* @param {ContactOrganization[]} organizations
|
||||||
* @param {DOMString} published date contact was first created
|
* @param {DOMString} revision date contact was last updated
|
||||||
* @param {DOMString} updated date contact was last updated
|
|
||||||
* @param {DOMString} birthday contact's birthday
|
* @param {DOMString} birthday contact's birthday
|
||||||
* @param (DOMString} anniversary contact's anniversary
|
|
||||||
* @param {DOMString} gender contact's gender
|
* @param {DOMString} gender contact's gender
|
||||||
* @param {DOMString} note user notes about contact
|
* @param {DOMString} note user notes about contact
|
||||||
* @param {DOMString} preferredUsername
|
|
||||||
* @param {ContactField[]} photos
|
* @param {ContactField[]} photos
|
||||||
* @param {ContactField[]} tags
|
* @param {ContactField[]} categories
|
||||||
* @param {ContactField[]} relationships
|
|
||||||
* @param {ContactField[]} urls contact's web sites
|
* @param {ContactField[]} urls contact's web sites
|
||||||
* @param {ContactAccounts[]} accounts contact's online accounts
|
* @param {DOMString} timezone the contacts time zone
|
||||||
* @param {DOMString} utcOffset UTC time zone offset
|
|
||||||
* @param {DOMString} connected
|
|
||||||
*/
|
*/
|
||||||
var Contact = function(id, displayName, name, nickname, phoneNumbers, emails, addresses,
|
var Contact = function (id, displayName, name, nickname, phoneNumbers, emails, addresses,
|
||||||
ims, organizations, published, updated, birthday, anniversary, gender, note,
|
ims, organizations, revision, birthday, gender, note, photos, categories, urls, timezone) {
|
||||||
preferredUsername, photos, tags, relationships, urls, accounts, utcOffset, connected) {
|
|
||||||
this.id = id || null;
|
this.id = id || null;
|
||||||
|
this.rawId = null;
|
||||||
this.displayName = displayName || null;
|
this.displayName = displayName || null;
|
||||||
this.name = name || null; // ContactName
|
this.name = name || null; // ContactName
|
||||||
this.nickname = nickname || null;
|
this.nickname = nickname || null;
|
||||||
@ -44,184 +38,14 @@ var Contact = function(id, displayName, name, nickname, phoneNumbers, emails, ad
|
|||||||
this.addresses = addresses || null; // ContactAddress[]
|
this.addresses = addresses || null; // ContactAddress[]
|
||||||
this.ims = ims || null; // ContactField[]
|
this.ims = ims || null; // ContactField[]
|
||||||
this.organizations = organizations || null; // ContactOrganization[]
|
this.organizations = organizations || null; // ContactOrganization[]
|
||||||
this.published = published || null;
|
this.revision = revision || null;
|
||||||
this.updated = updated || null;
|
|
||||||
this.birthday = birthday || null;
|
this.birthday = birthday || null;
|
||||||
this.anniversary = anniversary || null;
|
|
||||||
this.gender = gender || null;
|
this.gender = gender || null;
|
||||||
this.note = note || null;
|
this.note = note || null;
|
||||||
this.preferredUsername = preferredUsername || null;
|
|
||||||
this.photos = photos || null; // ContactField[]
|
this.photos = photos || null; // ContactField[]
|
||||||
this.tags = tags || null; // ContactField[]
|
this.categories = categories || null; // ContactField[]
|
||||||
this.relationships = relationships || null; // ContactField[]
|
|
||||||
this.urls = urls || null; // ContactField[]
|
this.urls = urls || null; // ContactField[]
|
||||||
this.accounts = accounts || null; // ContactAccount[]
|
this.timezone = timezone || null;
|
||||||
this.utcOffset = utcOffset || null;
|
|
||||||
this.connected = connected || null;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes contact from device storage.
|
|
||||||
* @param successCB success callback
|
|
||||||
* @param errorCB error callback
|
|
||||||
*/
|
|
||||||
Contact.prototype.remove = function(successCB, errorCB) {
|
|
||||||
if (this.id == null) {
|
|
||||||
var errorObj = new ContactError();
|
|
||||||
errorObj.code = ContactError.NOT_FOUND_ERROR;
|
|
||||||
errorCB(errorObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
PhoneGap.exec(successCB, errorCB, "Contacts", "remove", [this.id]);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a deep copy of this Contact.
|
|
||||||
* With the contact ID set to null.
|
|
||||||
* @return copy of this Contact
|
|
||||||
*/
|
|
||||||
Contact.prototype.clone = function() {
|
|
||||||
var clonedContact = PhoneGap.clone(this);
|
|
||||||
clonedContact.id = null;
|
|
||||||
return clonedContact;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Persists contact to device storage.
|
|
||||||
* @param successCB success callback
|
|
||||||
* @param errorCB error callback
|
|
||||||
*/
|
|
||||||
Contact.prototype.save = function(successCB, errorCB) {
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contact name.
|
|
||||||
* @param formatted
|
|
||||||
* @param familyName
|
|
||||||
* @param givenName
|
|
||||||
* @param middle
|
|
||||||
* @param prefix
|
|
||||||
* @param suffix
|
|
||||||
*/
|
|
||||||
var ContactName = function(formatted, familyName, givenName, middle, prefix, suffix) {
|
|
||||||
this.formatted = formatted || null;
|
|
||||||
this.familyName = familyName || null;
|
|
||||||
this.givenName = givenName || null;
|
|
||||||
this.middleName = middle || null;
|
|
||||||
this.honorificPrefix = prefix || null;
|
|
||||||
this.honorificSuffix = suffix || null;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic contact field.
|
|
||||||
* @param type
|
|
||||||
* @param value
|
|
||||||
* @param primary
|
|
||||||
*/
|
|
||||||
var ContactField = function(type, value, primary) {
|
|
||||||
this.type = type || null;
|
|
||||||
this.value = value || null;
|
|
||||||
this.primary = primary || null;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contact address.
|
|
||||||
* @param formatted
|
|
||||||
* @param streetAddress
|
|
||||||
* @param locality
|
|
||||||
* @param region
|
|
||||||
* @param postalCode
|
|
||||||
* @param country
|
|
||||||
*/
|
|
||||||
var ContactAddress = function(formatted, streetAddress, locality, region, postalCode, country) {
|
|
||||||
this.formatted = formatted || null;
|
|
||||||
this.streetAddress = streetAddress || null;
|
|
||||||
this.locality = locality || null;
|
|
||||||
this.region = region || null;
|
|
||||||
this.postalCode = postalCode || null;
|
|
||||||
this.country = country || null;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contact organization.
|
|
||||||
* @param name
|
|
||||||
* @param dept
|
|
||||||
* @param title
|
|
||||||
* @param startDate
|
|
||||||
* @param endDate
|
|
||||||
* @param location
|
|
||||||
* @param desc
|
|
||||||
*/
|
|
||||||
var ContactOrganization = function(name, dept, title, startDate, endDate, location, desc) {
|
|
||||||
this.name = name || null;
|
|
||||||
this.department = dept || null;
|
|
||||||
this.title = title || null;
|
|
||||||
this.startDate = startDate || null;
|
|
||||||
this.endDate = endDate || null;
|
|
||||||
this.location = location || null;
|
|
||||||
this.description = desc || null;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contact account.
|
|
||||||
* @param domain
|
|
||||||
* @param username
|
|
||||||
* @param userid
|
|
||||||
*/
|
|
||||||
var ContactAccount = function(domain, username, userid) {
|
|
||||||
this.domain = domain || null;
|
|
||||||
this.username = username || null;
|
|
||||||
this.userid = userid || null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a group of Contacts.
|
|
||||||
*/
|
|
||||||
var Contacts = function() {
|
|
||||||
this.inProgress = false;
|
|
||||||
this.records = new Array();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Returns an array of Contacts matching the search criteria.
|
|
||||||
* @param fields that should be searched
|
|
||||||
* @param successCB success callback
|
|
||||||
* @param errorCB error callback
|
|
||||||
* @param {ContactFindOptions} options that can be applied to contact searching
|
|
||||||
* @return array of Contacts matching search criteria
|
|
||||||
*/
|
|
||||||
Contacts.prototype.find = function(fields, successCB, errorCB, options) {
|
|
||||||
PhoneGap.exec(successCB, errorCB, "Contacts", "search", [fields, options]);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function creates a new contact, but it does not persist the contact
|
|
||||||
* to device storage. To persist the contact to device storage, invoke
|
|
||||||
* contact.save().
|
|
||||||
* @param properties an object who's properties will be examined to create a new Contact
|
|
||||||
* @returns new Contact object
|
|
||||||
*/
|
|
||||||
Contacts.prototype.create = function(properties) {
|
|
||||||
var contact = new Contact();
|
|
||||||
for (i in properties) {
|
|
||||||
if (contact[i]!='undefined') {
|
|
||||||
contact[i]=properties[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return contact;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ContactFindOptions.
|
|
||||||
* @param filter used to match contacts against
|
|
||||||
* @param multiple boolean used to determine if more than one contact should be returned
|
|
||||||
* @param limit maximum number of results to return from the contacts search
|
|
||||||
* @param updatedSince return only contact records that have been updated on or after the given time
|
|
||||||
*/
|
|
||||||
var ContactFindOptions = function(filter, multiple, limit, updatedSince) {
|
|
||||||
this.filter = filter || '';
|
|
||||||
this.multiple = multiple || false;
|
|
||||||
this.limit = limit || 1;
|
|
||||||
this.updatedSince = updatedSince || '';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -244,10 +68,230 @@ ContactError.IO_ERROR = 5;
|
|||||||
ContactError.NOT_SUPPORTED_ERROR = 6;
|
ContactError.NOT_SUPPORTED_ERROR = 6;
|
||||||
ContactError.PERMISSION_DENIED_ERROR = 20;
|
ContactError.PERMISSION_DENIED_ERROR = 20;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes contact from device storage.
|
||||||
|
* @param successCB success callback
|
||||||
|
* @param errorCB error callback
|
||||||
|
*/
|
||||||
|
Contact.prototype.remove = function(successCB, errorCB) {
|
||||||
|
if (this.id === null) {
|
||||||
|
var errorObj = new ContactError();
|
||||||
|
errorObj.code = ContactError.NOT_FOUND_ERROR;
|
||||||
|
errorCB(errorObj);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PhoneGap.exec(successCB, errorCB, "Contacts", "remove", [this.id]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a deep copy of this Contact.
|
||||||
|
* With the contact ID set to null.
|
||||||
|
* @return copy of this Contact
|
||||||
|
*/
|
||||||
|
Contact.prototype.clone = function() {
|
||||||
|
var clonedContact = PhoneGap.clone(this);
|
||||||
|
var i;
|
||||||
|
clonedContact.id = null;
|
||||||
|
clonedContact.rawId = null;
|
||||||
|
// Loop through and clear out any id's in phones, emails, etc.
|
||||||
|
if (clonedContact.phoneNumbers) {
|
||||||
|
for (i = 0; i < clonedContact.phoneNumbers.length; i++) {
|
||||||
|
clonedContact.phoneNumbers[i].id = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (clonedContact.emails) {
|
||||||
|
for (i = 0; i < clonedContact.emails.length; i++) {
|
||||||
|
clonedContact.emails[i].id = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (clonedContact.addresses) {
|
||||||
|
for (i = 0; i < clonedContact.addresses.length; i++) {
|
||||||
|
clonedContact.addresses[i].id = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (clonedContact.ims) {
|
||||||
|
for (i = 0; i < clonedContact.ims.length; i++) {
|
||||||
|
clonedContact.ims[i].id = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (clonedContact.organizations) {
|
||||||
|
for (i = 0; i < clonedContact.organizations.length; i++) {
|
||||||
|
clonedContact.organizations[i].id = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (clonedContact.tags) {
|
||||||
|
for (i = 0; i < clonedContact.tags.length; i++) {
|
||||||
|
clonedContact.tags[i].id = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (clonedContact.photos) {
|
||||||
|
for (i = 0; i < clonedContact.photos.length; i++) {
|
||||||
|
clonedContact.photos[i].id = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (clonedContact.urls) {
|
||||||
|
for (i = 0; i < clonedContact.urls.length; i++) {
|
||||||
|
clonedContact.urls[i].id = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return clonedContact;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Persists contact to device storage.
|
||||||
|
* @param successCB success callback
|
||||||
|
* @param errorCB error callback
|
||||||
|
*/
|
||||||
|
Contact.prototype.save = function(successCB, errorCB) {
|
||||||
|
PhoneGap.exec(successCB, errorCB, "Contacts", "save", [this]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contact name.
|
||||||
|
* @param formatted
|
||||||
|
* @param familyName
|
||||||
|
* @param givenName
|
||||||
|
* @param middle
|
||||||
|
* @param prefix
|
||||||
|
* @param suffix
|
||||||
|
*/
|
||||||
|
var ContactName = function(formatted, familyName, givenName, middle, prefix, suffix) {
|
||||||
|
this.formatted = formatted || null;
|
||||||
|
this.familyName = familyName || null;
|
||||||
|
this.givenName = givenName || null;
|
||||||
|
this.middleName = middle || null;
|
||||||
|
this.honorificPrefix = prefix || null;
|
||||||
|
this.honorificSuffix = suffix || null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic contact field.
|
||||||
|
* @param {DOMString} id unique identifier, should only be set by native code
|
||||||
|
* @param type
|
||||||
|
* @param value
|
||||||
|
* @param pref
|
||||||
|
*/
|
||||||
|
var ContactField = function(type, value, pref) {
|
||||||
|
this.id = null;
|
||||||
|
this.type = type || null;
|
||||||
|
this.value = value || null;
|
||||||
|
this.pref = pref || null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contact address.
|
||||||
|
* @param {DOMString} id unique identifier, should only be set by native code
|
||||||
|
* @param formatted
|
||||||
|
* @param streetAddress
|
||||||
|
* @param locality
|
||||||
|
* @param region
|
||||||
|
* @param postalCode
|
||||||
|
* @param country
|
||||||
|
*/
|
||||||
|
var ContactAddress = function(formatted, streetAddress, locality, region, postalCode, country) {
|
||||||
|
this.id = null;
|
||||||
|
this.formatted = formatted || null;
|
||||||
|
this.streetAddress = streetAddress || null;
|
||||||
|
this.locality = locality || null;
|
||||||
|
this.region = region || null;
|
||||||
|
this.postalCode = postalCode || null;
|
||||||
|
this.country = country || null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contact organization.
|
||||||
|
* @param {DOMString} id unique identifier, should only be set by native code
|
||||||
|
* @param name
|
||||||
|
* @param dept
|
||||||
|
* @param title
|
||||||
|
* @param startDate
|
||||||
|
* @param endDate
|
||||||
|
* @param location
|
||||||
|
* @param desc
|
||||||
|
*/
|
||||||
|
var ContactOrganization = function(name, dept, title) {
|
||||||
|
this.id = null;
|
||||||
|
this.name = name || null;
|
||||||
|
this.department = dept || null;
|
||||||
|
this.title = title || null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a group of Contacts.
|
||||||
|
*/
|
||||||
|
var Contacts = function() {
|
||||||
|
this.inProgress = false;
|
||||||
|
this.records = [];
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Returns an array of Contacts matching the search criteria.
|
||||||
|
* @param fields that should be searched
|
||||||
|
* @param successCB success callback
|
||||||
|
* @param errorCB error callback
|
||||||
|
* @param {ContactFindOptions} options that can be applied to contact searching
|
||||||
|
* @return array of Contacts matching search criteria
|
||||||
|
*/
|
||||||
|
Contacts.prototype.find = function(fields, successCB, errorCB, options) {
|
||||||
|
PhoneGap.exec(successCB, errorCB, "Contacts", "search", [fields, options]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function creates a new contact, but it does not persist the contact
|
||||||
|
* to device storage. To persist the contact to device storage, invoke
|
||||||
|
* contact.save().
|
||||||
|
* @param properties an object who's properties will be examined to create a new Contact
|
||||||
|
* @returns new Contact object
|
||||||
|
*/
|
||||||
|
Contacts.prototype.create = function(properties) {
|
||||||
|
var i;
|
||||||
|
var contact = new Contact();
|
||||||
|
for (i in properties) {
|
||||||
|
if (contact[i] !== 'undefined') {
|
||||||
|
contact[i] = properties[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return contact;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function returns and array of contacts. It is required as we need to convert raw
|
||||||
|
* JSON objects into concrete Contact objects. Currently this method is called after
|
||||||
|
* navigator.service.contacts.find but before the find methods success call back.
|
||||||
|
*
|
||||||
|
* @param jsonArray an array of JSON Objects that need to be converted to Contact objects.
|
||||||
|
* @returns an array of Contact objects
|
||||||
|
*/
|
||||||
|
Contacts.prototype.cast = function(pluginResult) {
|
||||||
|
var contacts = [];
|
||||||
|
var i;
|
||||||
|
for (i=0; i<pluginResult.message.length; i++) {
|
||||||
|
contacts.push(navigator.service.contacts.create(pluginResult.message[i]));
|
||||||
|
}
|
||||||
|
pluginResult.message = contacts;
|
||||||
|
return pluginResult;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ContactFindOptions.
|
||||||
|
* @param filter used to match contacts against
|
||||||
|
* @param multiple boolean used to determine if more than one contact should be returned
|
||||||
|
* @param updatedSince return only contact records that have been updated on or after the given time
|
||||||
|
*/
|
||||||
|
var ContactFindOptions = function(filter, multiple, updatedSince) {
|
||||||
|
this.filter = filter || '';
|
||||||
|
this.multiple = multiple || true;
|
||||||
|
this.updatedSince = updatedSince || '';
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the contact interface into the browser.
|
* Add the contact interface into the browser.
|
||||||
*/
|
*/
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
if(typeof navigator.service == "undefined") navigator.service = new Object();
|
if(typeof navigator.service === "undefined") {
|
||||||
if(typeof navigator.service.contacts == "undefined") navigator.service.contacts = new Contacts();
|
navigator.service = {};
|
||||||
|
}
|
||||||
|
if(typeof navigator.service.contacts === "undefined") {
|
||||||
|
navigator.service.contacts = new Contacts();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
@ -30,6 +30,8 @@ Crypto.prototype.getPlainString = function(string) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
if (typeof navigator.Crypto == "undefined") navigator.Crypto = new Crypto();
|
if (typeof navigator.Crypto === "undefined") {
|
||||||
|
navigator.Crypto = new Crypto();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,6 +25,7 @@ function Device() {
|
|||||||
me.available = true;
|
me.available = true;
|
||||||
me.platform = info.platform;
|
me.platform = info.platform;
|
||||||
me.version = info.version;
|
me.version = info.version;
|
||||||
|
me.name = info.name;
|
||||||
me.uuid = info.uuid;
|
me.uuid = info.uuid;
|
||||||
me.phonegap = info.phonegap;
|
me.phonegap = info.phonegap;
|
||||||
PhoneGap.onPhoneGapInfoReady.fire();
|
PhoneGap.onPhoneGapInfoReady.fire();
|
||||||
@ -45,13 +46,13 @@ function Device() {
|
|||||||
Device.prototype.getInfo = function(successCallback, errorCallback) {
|
Device.prototype.getInfo = function(successCallback, errorCallback) {
|
||||||
|
|
||||||
// successCallback required
|
// successCallback required
|
||||||
if (typeof successCallback != "function") {
|
if (typeof successCallback !== "function") {
|
||||||
console.log("Device Error: successCallback is not a function");
|
console.log("Device Error: successCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// errorCallback optional
|
// errorCallback optional
|
||||||
if (errorCallback && (typeof errorCallback != "function")) {
|
if (errorCallback && (typeof errorCallback !== "function")) {
|
||||||
console.log("Device Error: errorCallback is not a function");
|
console.log("Device Error: errorCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -61,31 +62,37 @@ Device.prototype.getInfo = function(successCallback, errorCallback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* DEPRECATED
|
||||||
* This is only for Android.
|
* This is only for Android.
|
||||||
*
|
*
|
||||||
* You must explicitly override the back button.
|
* You must explicitly override the back button.
|
||||||
*/
|
*/
|
||||||
Device.prototype.overrideBackButton = function() {
|
Device.prototype.overrideBackButton = function() {
|
||||||
BackButton.override();
|
console.log("Device.overrideBackButton() is deprecated. Use App.overrideBackbutton(true).");
|
||||||
}
|
app.overrideBackbutton(true);
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* DEPRECATED
|
||||||
* This is only for Android.
|
* This is only for Android.
|
||||||
*
|
*
|
||||||
* This resets the back button to the default behaviour
|
* This resets the back button to the default behaviour
|
||||||
*/
|
*/
|
||||||
Device.prototype.resetBackButton = function() {
|
Device.prototype.resetBackButton = function() {
|
||||||
BackButton.reset();
|
console.log("Device.resetBackButton() is deprecated. Use App.overrideBackbutton(false).");
|
||||||
}
|
app.overrideBackbutton(false);
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* DEPRECATED
|
||||||
* This is only for Android.
|
* This is only for Android.
|
||||||
*
|
*
|
||||||
* This terminates the activity!
|
* This terminates the activity!
|
||||||
*/
|
*/
|
||||||
Device.prototype.exitApp = function() {
|
Device.prototype.exitApp = function() {
|
||||||
BackButton.exitApp();
|
console.log("Device.exitApp() is deprecated. Use App.exitApp().");
|
||||||
}
|
app.exitApp();
|
||||||
|
};
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
navigator.device = window.device = new Device();
|
navigator.device = window.device = new Device();
|
||||||
|
File diff suppressed because it is too large
Load Diff
77
framework/assets/js/filetransfer.js
Normal file
77
framework/assets/js/filetransfer.js
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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, IBM Corporation
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileTransfer uploads a file to a remote server.
|
||||||
|
*/
|
||||||
|
function FileTransfer() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileUploadResult
|
||||||
|
*/
|
||||||
|
function FileUploadResult() {
|
||||||
|
this.bytesSent = 0;
|
||||||
|
this.responseCode = null;
|
||||||
|
this.response = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FileTransferError
|
||||||
|
*/
|
||||||
|
function FileTransferError() {
|
||||||
|
this.code = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileTransferError.FILE_NOT_FOUND_ERR = 1;
|
||||||
|
FileTransferError.INVALID_URL_ERR = 2;
|
||||||
|
FileTransferError.CONNECTION_ERR = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given an absolute file path, uploads a file on the device to a remote server
|
||||||
|
* using a multipart HTTP request.
|
||||||
|
* @param filePath {String} Full path of the file on the device
|
||||||
|
* @param server {String} URL of the server to receive the file
|
||||||
|
* @param successCallback (Function} Callback to be invoked when upload has completed
|
||||||
|
* @param errorCallback {Function} Callback to be invoked upon error
|
||||||
|
* @param options {FileUploadOptions} Optional parameters such as file name and mimetype
|
||||||
|
*/
|
||||||
|
FileTransfer.prototype.upload = function(filePath, server, successCallback, errorCallback, options, debug) {
|
||||||
|
|
||||||
|
// check for options
|
||||||
|
var fileKey = null;
|
||||||
|
var fileName = null;
|
||||||
|
var mimeType = null;
|
||||||
|
var params = null;
|
||||||
|
if (options) {
|
||||||
|
fileKey = options.fileKey;
|
||||||
|
fileName = options.fileName;
|
||||||
|
mimeType = options.mimeType;
|
||||||
|
if (options.params) {
|
||||||
|
params = options.params;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
params = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PhoneGap.exec(successCallback, errorCallback, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, debug]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options to customize the HTTP request used to upload files.
|
||||||
|
* @param fileKey {String} Name of file request parameter.
|
||||||
|
* @param fileName {String} Filename to be used by the server. Defaults to image.jpg.
|
||||||
|
* @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.
|
||||||
|
*/
|
||||||
|
function FileUploadOptions(fileKey, fileName, mimeType, params) {
|
||||||
|
this.fileKey = fileKey || null;
|
||||||
|
this.fileName = fileName || null;
|
||||||
|
this.mimeType = mimeType || null;
|
||||||
|
this.params = params || null;
|
||||||
|
}
|
@ -17,7 +17,7 @@ function Geolocation() {
|
|||||||
|
|
||||||
// Geolocation listeners
|
// Geolocation listeners
|
||||||
this.listeners = {};
|
this.listeners = {};
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Position error object
|
* Position error object
|
||||||
@ -28,7 +28,7 @@ function Geolocation() {
|
|||||||
function PositionError(code, message) {
|
function PositionError(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;
|
||||||
@ -42,7 +42,7 @@ PositionError.TIMEOUT = 3;
|
|||||||
* @param {PositionOptions} options The options for getting the position data. (OPTIONAL)
|
* @param {PositionOptions} options The options for getting the position data. (OPTIONAL)
|
||||||
*/
|
*/
|
||||||
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
|
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
|
||||||
if (navigator._geo.listeners["global"]) {
|
if (navigator._geo.listeners.global) {
|
||||||
console.log("Geolocation Error: Still waiting for previous getCurrentPosition() request.");
|
console.log("Geolocation Error: Still waiting for previous getCurrentPosition() request.");
|
||||||
try {
|
try {
|
||||||
errorCallback(new PositionError(PositionError.TIMEOUT, "Geolocation Error: Still waiting for previous getCurrentPosition() request."));
|
errorCallback(new PositionError(PositionError.TIMEOUT, "Geolocation Error: Still waiting for previous getCurrentPosition() request."));
|
||||||
@ -53,20 +53,20 @@ Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallba
|
|||||||
var maximumAge = 10000;
|
var maximumAge = 10000;
|
||||||
var enableHighAccuracy = false;
|
var enableHighAccuracy = false;
|
||||||
var timeout = 10000;
|
var timeout = 10000;
|
||||||
if (typeof options != "undefined") {
|
if (typeof options !== "undefined") {
|
||||||
if (typeof options.maximumAge != "undefined") {
|
if (typeof options.maximumAge !== "undefined") {
|
||||||
maximumAge = options.maximumAge;
|
maximumAge = options.maximumAge;
|
||||||
}
|
}
|
||||||
if (typeof options.enableHighAccuracy != "undefined") {
|
if (typeof options.enableHighAccuracy !== "undefined") {
|
||||||
enableHighAccuracy = options.enableHighAccuracy;
|
enableHighAccuracy = options.enableHighAccuracy;
|
||||||
}
|
}
|
||||||
if (typeof options.timeout != "undefined") {
|
if (typeof options.timeout !== "undefined") {
|
||||||
timeout = options.timeout;
|
timeout = options.timeout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
navigator._geo.listeners["global"] = {"success" : successCallback, "fail" : errorCallback };
|
navigator._geo.listeners.global = {"success" : successCallback, "fail" : errorCallback };
|
||||||
PhoneGap.exec(null, null, "Geolocation", "getCurrentLocation", [enableHighAccuracy, timeout, maximumAge]);
|
PhoneGap.exec(null, null, "Geolocation", "getCurrentLocation", [enableHighAccuracy, timeout, maximumAge]);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously watches the geolocation for changes to geolocation. When a change occurs,
|
* Asynchronously watches the geolocation for changes to geolocation. When a change occurs,
|
||||||
@ -81,17 +81,17 @@ Geolocation.prototype.watchPosition = function(successCallback, errorCallback, o
|
|||||||
var maximumAge = 10000;
|
var maximumAge = 10000;
|
||||||
var enableHighAccuracy = false;
|
var enableHighAccuracy = false;
|
||||||
var timeout = 10000;
|
var timeout = 10000;
|
||||||
if (typeof options != "undefined") {
|
if (typeof options !== "undefined") {
|
||||||
if (typeof options.frequency != "undefined") {
|
if (typeof options.frequency !== "undefined") {
|
||||||
maximumAge = options.frequency;
|
maximumAge = options.frequency;
|
||||||
}
|
}
|
||||||
if (typeof options.maximumAge != "undefined") {
|
if (typeof options.maximumAge !== "undefined") {
|
||||||
maximumAge = options.maximumAge;
|
maximumAge = options.maximumAge;
|
||||||
}
|
}
|
||||||
if (typeof options.enableHighAccuracy != "undefined") {
|
if (typeof options.enableHighAccuracy !== "undefined") {
|
||||||
enableHighAccuracy = options.enableHighAccuracy;
|
enableHighAccuracy = options.enableHighAccuracy;
|
||||||
}
|
}
|
||||||
if (typeof options.timeout != "undefined") {
|
if (typeof options.timeout !== "undefined") {
|
||||||
timeout = options.timeout;
|
timeout = options.timeout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ Geolocation.prototype.success = function(id, lat, lng, alt, altacc, head, vel, s
|
|||||||
var coords = new Coordinates(lat, lng, alt, altacc, head, vel);
|
var coords = new Coordinates(lat, lng, alt, altacc, head, vel);
|
||||||
var loc = new Position(coords, stamp);
|
var loc = new Position(coords, stamp);
|
||||||
try {
|
try {
|
||||||
if (lat == "undefined" || lng == "undefined") {
|
if (lat === "undefined" || lng === "undefined") {
|
||||||
navigator._geo.listeners[id].fail(new PositionError(PositionError.POSITION_UNAVAILABLE, "Lat/Lng are undefined."));
|
navigator._geo.listeners[id].fail(new PositionError(PositionError.POSITION_UNAVAILABLE, "Lat/Lng are undefined."));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -130,8 +130,8 @@ Geolocation.prototype.success = function(id, lat, lng, alt, altacc, head, vel, s
|
|||||||
console.log("Geolocation Error: Error calling success callback function.");
|
console.log("Geolocation Error: Error calling success callback function.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == "global") {
|
if (id === "global") {
|
||||||
delete navigator._geo.listeners["global"];
|
delete navigator._geo.listeners.global;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ PhoneGap.addConstructor(function() {
|
|||||||
navigator._geo = new Geolocation();
|
navigator._geo = new Geolocation();
|
||||||
|
|
||||||
// No native geolocation object for Android 1.x, so use PhoneGap geolocation
|
// No native geolocation object for Android 1.x, so use PhoneGap geolocation
|
||||||
if (typeof navigator.geolocation == 'undefined') {
|
if (typeof navigator.geolocation === 'undefined') {
|
||||||
navigator.geolocation = navigator._geo;
|
navigator.geolocation = navigator._geo;
|
||||||
Geolocation.usingPhoneGap = true;
|
Geolocation.usingPhoneGap = true;
|
||||||
}
|
}
|
||||||
|
7
framework/assets/js/header.txt
Executable file
7
framework/assets/js/header.txt
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* 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, IBM Corporation
|
||||||
|
*/
|
@ -1,23 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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, IBM Corporation
|
|
||||||
*/
|
|
||||||
|
|
||||||
function KeyEvent()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
KeyEvent.prototype.backTrigger = function()
|
|
||||||
{
|
|
||||||
var e = document.createEvent('Events');
|
|
||||||
e.initEvent('backKeyDown');
|
|
||||||
document.dispatchEvent(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.keyEvent == null || typeof document.keyEvent == 'undefined')
|
|
||||||
{
|
|
||||||
window.keyEvent = document.keyEvent = new KeyEvent();
|
|
||||||
}
|
|
@ -40,8 +40,8 @@ PhoneGap.Media.onStatus = function(id, msg, value) {
|
|||||||
var media = PhoneGap.mediaObjects[id];
|
var media = PhoneGap.mediaObjects[id];
|
||||||
|
|
||||||
// If state update
|
// If state update
|
||||||
if (msg == Media.MEDIA_STATE) {
|
if (msg === Media.MEDIA_STATE) {
|
||||||
if (value == Media.MEDIA_STOPPED) {
|
if (value === Media.MEDIA_STOPPED) {
|
||||||
if (media.successCallback) {
|
if (media.successCallback) {
|
||||||
media.successCallback();
|
media.successCallback();
|
||||||
}
|
}
|
||||||
@ -50,10 +50,10 @@ PhoneGap.Media.onStatus = function(id, msg, value) {
|
|||||||
media.statusCallback(value);
|
media.statusCallback(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (msg == Media.MEDIA_DURATION) {
|
else if (msg === Media.MEDIA_DURATION) {
|
||||||
media._duration = value;
|
media._duration = value;
|
||||||
}
|
}
|
||||||
else if (msg == Media.MEDIA_ERROR) {
|
else if (msg === Media.MEDIA_ERROR) {
|
||||||
if (media.errorCallback) {
|
if (media.errorCallback) {
|
||||||
media.errorCallback(value);
|
media.errorCallback(value);
|
||||||
}
|
}
|
||||||
@ -76,25 +76,25 @@ PhoneGap.Media.onStatus = function(id, msg, value) {
|
|||||||
Media = function(src, successCallback, errorCallback, statusCallback, positionCallback) {
|
Media = function(src, successCallback, errorCallback, statusCallback, positionCallback) {
|
||||||
|
|
||||||
// successCallback optional
|
// successCallback optional
|
||||||
if (successCallback && (typeof successCallback != "function")) {
|
if (successCallback && (typeof successCallback !== "function")) {
|
||||||
console.log("Media Error: successCallback is not a function");
|
console.log("Media Error: successCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// errorCallback optional
|
// errorCallback optional
|
||||||
if (errorCallback && (typeof errorCallback != "function")) {
|
if (errorCallback && (typeof errorCallback !== "function")) {
|
||||||
console.log("Media Error: errorCallback is not a function");
|
console.log("Media Error: errorCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// statusCallback optional
|
// statusCallback optional
|
||||||
if (statusCallback && (typeof statusCallback != "function")) {
|
if (statusCallback && (typeof statusCallback !== "function")) {
|
||||||
console.log("Media Error: statusCallback is not a function");
|
console.log("Media Error: statusCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// statusCallback optional
|
// statusCallback optional
|
||||||
if (positionCallback && (typeof positionCallback != "function")) {
|
if (positionCallback && (typeof positionCallback !== "function")) {
|
||||||
console.log("Media Error: positionCallback is not a function");
|
console.log("Media Error: positionCallback is not a function");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -129,9 +129,9 @@ Media.MEDIA_MSG = ["None", "Starting", "Running", "Paused", "Stopped"];
|
|||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function MediaError() {
|
function MediaError() {
|
||||||
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;
|
||||||
@ -192,3 +192,10 @@ Media.prototype.stopRecord = function() {
|
|||||||
PhoneGap.exec(null, null, "Media", "stopRecordingAudio", [this.id]);
|
PhoneGap.exec(null, null, "Media", "stopRecordingAudio", [this.id]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release the resources.
|
||||||
|
*/
|
||||||
|
Media.prototype.release = function() {
|
||||||
|
PhoneGap.exec(null, null, "Media", "release", [this.id]);
|
||||||
|
};
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
function NetworkStatus() {
|
function NetworkStatus() {
|
||||||
//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;
|
||||||
@ -30,7 +30,7 @@ function Network() {
|
|||||||
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.
|
||||||
@ -57,6 +57,8 @@ Network.prototype.isReachable = function(uri, callback, options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
if (typeof navigator.network == "undefined") navigator.network = new Network();
|
if (typeof navigator.network === "undefined") {
|
||||||
|
navigator.network = new Network();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -15,28 +15,30 @@ function Notification() {
|
|||||||
/**
|
/**
|
||||||
* Open a native alert dialog, with a customizable title and button text.
|
* Open a native alert dialog, with a customizable title and button text.
|
||||||
*
|
*
|
||||||
* @param {String} message Message to print in the body of the alert
|
* @param {String} message Message to print in the body of the alert
|
||||||
* @param {String} title Title of the alert dialog (default: Alert)
|
* @param {Function} completeCallback The callback that is called when user clicks on a button.
|
||||||
* @param {String} buttonLabel Label of the close button (default: OK)
|
* @param {String} title Title of the alert dialog (default: Alert)
|
||||||
|
* @param {String} buttonLabel Label of the close button (default: OK)
|
||||||
*/
|
*/
|
||||||
Notification.prototype.alert = function(message, title, buttonLabel) {
|
Notification.prototype.alert = function(message, completeCallback, title, buttonLabel) {
|
||||||
var _title = (title || "Alert");
|
var _title = (title || "Alert");
|
||||||
var _buttonLabel = (buttonLabel || "OK");
|
var _buttonLabel = (buttonLabel || "OK");
|
||||||
PhoneGap.exec(null, null, "Notification", "alert", [message,_title,_buttonLabel]);
|
PhoneGap.exec(completeCallback, null, "Notification", "alert", [message,_title,_buttonLabel]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a native confirm dialog, with a customizable title and button text.
|
* Open a native confirm dialog, with a customizable title and button text.
|
||||||
|
* The result that the user selects is returned to the result callback.
|
||||||
*
|
*
|
||||||
* @param {String} message Message to print in the body of the alert
|
* @param {String} message Message to print in the body of the alert
|
||||||
* @param {String} title Title of the alert dialog (default: Confirm)
|
* @param {Function} resultCallback The callback that is called when user clicks on a button.
|
||||||
* @param {String} buttonLabels Comma separated list of the labels of the buttons (default: 'OK,Cancel')
|
* @param {String} title Title of the alert dialog (default: Confirm)
|
||||||
* @return {Number} The index of the button clicked
|
* @param {String} buttonLabels Comma separated list of the labels of the buttons (default: 'OK,Cancel')
|
||||||
*/
|
*/
|
||||||
Notification.prototype.confirm = function(message, title, buttonLabels) {
|
Notification.prototype.confirm = function(message, resultCallback, title, buttonLabels) {
|
||||||
var _title = (title || "Confirm");
|
var _title = (title || "Confirm");
|
||||||
var _buttonLabels = (buttonLabels || "OK,Cancel");
|
var _buttonLabels = (buttonLabels || "OK,Cancel");
|
||||||
return PhoneGap.exec(null, null, "Notification", "confirm", [message,_title,_buttonLabels]);
|
PhoneGap.exec(resultCallback, null, "Notification", "confirm", [message,_title,_buttonLabels]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,6 +111,8 @@ Notification.prototype.beep = function(count) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
if (typeof navigator.notification == "undefined") navigator.notification = new Notification();
|
if (typeof navigator.notification === "undefined") {
|
||||||
|
navigator.notification = new Notification();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@ -28,8 +28,9 @@
|
|||||||
* document.addEventListener("resume", myResumeListener, false);
|
* document.addEventListener("resume", myResumeListener, false);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (typeof(DeviceInfo) != 'object')
|
if (typeof(DeviceInfo) !== 'object') {
|
||||||
DeviceInfo = {};
|
DeviceInfo = {};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This represents the PhoneGap API itself, and provides a global namespace for accessing
|
* This represents the PhoneGap API itself, and provides a global namespace for accessing
|
||||||
@ -48,7 +49,7 @@ var PhoneGap = {
|
|||||||
/**
|
/**
|
||||||
* Custom pub-sub channel that can have functions subscribed to it
|
* Custom pub-sub channel that can have functions subscribed to it
|
||||||
*/
|
*/
|
||||||
PhoneGap.Channel = function(type)
|
PhoneGap.Channel = function (type)
|
||||||
{
|
{
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.handlers = {};
|
this.handlers = {};
|
||||||
@ -66,10 +67,10 @@ PhoneGap.Channel = function(type)
|
|||||||
*/
|
*/
|
||||||
PhoneGap.Channel.prototype.subscribe = function(f, c, g) {
|
PhoneGap.Channel.prototype.subscribe = function(f, c, g) {
|
||||||
// need a function to call
|
// need a function to call
|
||||||
if (f == null) { return; }
|
if (f === null) { return; }
|
||||||
|
|
||||||
var func = f;
|
var func = f;
|
||||||
if (typeof c == "object" && f instanceof Function) { func = PhoneGap.close(c, f); }
|
if (typeof c === "object" && f instanceof Function) { func = PhoneGap.close(c, f); }
|
||||||
|
|
||||||
g = g || func.observer_guid || f.observer_guid || this.guid++;
|
g = g || func.observer_guid || f.observer_guid || this.guid++;
|
||||||
func.observer_guid = g;
|
func.observer_guid = g;
|
||||||
@ -88,9 +89,9 @@ PhoneGap.Channel.prototype.subscribeOnce = function(f, c) {
|
|||||||
var m = function() {
|
var m = function() {
|
||||||
f.apply(c || null, arguments);
|
f.apply(c || null, arguments);
|
||||||
_this.unsubscribe(g);
|
_this.unsubscribe(g);
|
||||||
}
|
};
|
||||||
if (this.fired) {
|
if (this.fired) {
|
||||||
if (typeof c == "object" && f instanceof Function) { f = PhoneGap.close(c, f); }
|
if (typeof c === "object" && f instanceof Function) { f = PhoneGap.close(c, f); }
|
||||||
f.apply(this, this.fireArgs);
|
f.apply(this, this.fireArgs);
|
||||||
} else {
|
} else {
|
||||||
g = this.subscribe(m);
|
g = this.subscribe(m);
|
||||||
@ -113,11 +114,14 @@ PhoneGap.Channel.prototype.unsubscribe = function(g) {
|
|||||||
PhoneGap.Channel.prototype.fire = function(e) {
|
PhoneGap.Channel.prototype.fire = function(e) {
|
||||||
if (this.enabled) {
|
if (this.enabled) {
|
||||||
var fail = false;
|
var fail = false;
|
||||||
for (var item in this.handlers) {
|
var item, handler, rv;
|
||||||
var handler = this.handlers[item];
|
for (item in this.handlers) {
|
||||||
if (handler instanceof Function) {
|
if (this.handlers.hasOwnProperty(item)) {
|
||||||
var rv = (handler.apply(this, arguments)==false);
|
handler = this.handlers[item];
|
||||||
fail = fail || rv;
|
if (handler instanceof Function) {
|
||||||
|
rv = (handler.apply(this, arguments) === false);
|
||||||
|
fail = fail || rv;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.fired = true;
|
this.fired = true;
|
||||||
@ -134,18 +138,29 @@ PhoneGap.Channel.prototype.fire = function(e) {
|
|||||||
PhoneGap.Channel.join = function(h, c) {
|
PhoneGap.Channel.join = function(h, c) {
|
||||||
var i = c.length;
|
var i = c.length;
|
||||||
var f = function() {
|
var f = function() {
|
||||||
if (!(--i)) h();
|
if (!(--i)) {
|
||||||
|
h();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var len = i;
|
||||||
|
var j;
|
||||||
|
for (j=0; j<len; j++) {
|
||||||
|
if (!c[j].fired) {
|
||||||
|
c[j].subscribeOnce(f);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
i--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (var j=0; j<i; j++) {
|
if (!i) {
|
||||||
(!c[j].fired?c[j].subscribeOnce(f):i--);
|
h();
|
||||||
}
|
}
|
||||||
if (!i) h();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boolean flag indicating if the PhoneGap API is available and initialized.
|
* Boolean flag indicating if the PhoneGap API is available and initialized.
|
||||||
*/ // TODO: Remove this, it is unused here ... -jm
|
*/ // TODO: Remove this, it is unused here ... -jm
|
||||||
PhoneGap.available = DeviceInfo.uuid != undefined;
|
PhoneGap.available = DeviceInfo.uuid !== undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an initialization function to a queue that ensures it will run and initialize
|
* Add an initialization function to a queue that ensures it will run and initialize
|
||||||
@ -157,27 +172,33 @@ PhoneGap.addConstructor = function(func) {
|
|||||||
try {
|
try {
|
||||||
func();
|
func();
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
if (typeof(debug['log']) == 'function') {
|
console.log("Failed to run constructor: " + e);
|
||||||
debug.log("Failed to run constructor: " + debug.processMessage(e));
|
|
||||||
} else {
|
|
||||||
alert("Failed to run constructor: " + e.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a plugin object to window.plugins
|
* Plugins object
|
||||||
|
*/
|
||||||
|
if (!window.plugins) {
|
||||||
|
window.plugins = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a plugin object to window.plugins.
|
||||||
|
* The plugin is accessed using window.plugins.<name>
|
||||||
|
*
|
||||||
|
* @param name The plugin name
|
||||||
|
* @param obj The plugin object
|
||||||
*/
|
*/
|
||||||
PhoneGap.addPlugin = function(name, obj) {
|
PhoneGap.addPlugin = function(name, obj) {
|
||||||
if ( !window.plugins ) {
|
if (!window.plugins[name]) {
|
||||||
window.plugins = {};
|
window.plugins[name] = obj;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if ( !window.plugins[name] ) {
|
console.log("Error: Plugin "+name+" already exists.");
|
||||||
window.plugins[name] = obj;
|
}
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onDOMContentLoaded channel is fired when the DOM content
|
* onDOMContentLoaded channel is fired when the DOM content
|
||||||
@ -232,13 +253,59 @@ if (typeof _nativeReady !== 'undefined') { PhoneGap.onNativeReady.fire(); }
|
|||||||
PhoneGap.onDeviceReady = new PhoneGap.Channel('onDeviceReady');
|
PhoneGap.onDeviceReady = new PhoneGap.Channel('onDeviceReady');
|
||||||
|
|
||||||
|
|
||||||
|
// Array of channels that must fire before "deviceready" is fired
|
||||||
|
PhoneGap.deviceReadyChannelsArray = [ PhoneGap.onPhoneGapReady, PhoneGap.onPhoneGapInfoReady];
|
||||||
|
|
||||||
|
// Hashtable of user defined channels that must also fire before "deviceready" is fired
|
||||||
|
PhoneGap.deviceReadyChannelsMap = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicate that a feature needs to be initialized before it is ready to be used.
|
||||||
|
* This holds up PhoneGap's "deviceready" event until the feature has been initialized
|
||||||
|
* and PhoneGap.initComplete(feature) is called.
|
||||||
|
*
|
||||||
|
* @param feature {String} The unique feature name
|
||||||
|
*/
|
||||||
|
PhoneGap.waitForInitialization = function(feature) {
|
||||||
|
if (feature) {
|
||||||
|
var channel = new PhoneGap.Channel(feature);
|
||||||
|
PhoneGap.deviceReadyChannelsMap[feature] = channel;
|
||||||
|
PhoneGap.deviceReadyChannelsArray.push(channel);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicate that initialization code has completed and the feature is ready to be used.
|
||||||
|
*
|
||||||
|
* @param feature {String} The unique feature name
|
||||||
|
*/
|
||||||
|
PhoneGap.initializationComplete = function(feature) {
|
||||||
|
var channel = PhoneGap.deviceReadyChannelsMap[feature];
|
||||||
|
if (channel) {
|
||||||
|
channel.fire();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create all PhoneGap objects once page has fully loaded and native side is ready.
|
* Create all PhoneGap objects once page has fully loaded and native side is ready.
|
||||||
*/
|
*/
|
||||||
PhoneGap.Channel.join(function() {
|
PhoneGap.Channel.join(function() {
|
||||||
|
|
||||||
// Start listening for XHR callbacks
|
// Start listening for XHR callbacks
|
||||||
PhoneGap.JSCallback();
|
setTimeout(function() {
|
||||||
|
if (PhoneGap.UsePolling) {
|
||||||
|
PhoneGap.JSCallbackPolling();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var polling = prompt("usePolling", "gap_callbackServer:");
|
||||||
|
if (polling == "true") {
|
||||||
|
PhoneGap.JSCallbackPolling();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PhoneGap.JSCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 1);
|
||||||
|
|
||||||
// Run PhoneGap constructors
|
// Run PhoneGap constructors
|
||||||
PhoneGap.onPhoneGapInit.fire();
|
PhoneGap.onPhoneGapInit.fire();
|
||||||
@ -246,22 +313,21 @@ PhoneGap.Channel.join(function() {
|
|||||||
// Fire event to notify that all objects are created
|
// Fire event to notify that all objects are created
|
||||||
PhoneGap.onPhoneGapReady.fire();
|
PhoneGap.onPhoneGapReady.fire();
|
||||||
|
|
||||||
|
// Fire onDeviceReady event once all constructors have run and PhoneGap info has been
|
||||||
|
// received from native side, and any user defined initialization channels.
|
||||||
|
PhoneGap.Channel.join(function() {
|
||||||
|
|
||||||
|
// Turn off app loading dialog
|
||||||
|
navigator.notification.activityStop();
|
||||||
|
|
||||||
|
PhoneGap.onDeviceReady.fire();
|
||||||
|
|
||||||
|
// Fire the onresume event, since first one happens before JavaScript is loaded
|
||||||
|
PhoneGap.onResume.fire();
|
||||||
|
}, PhoneGap.deviceReadyChannelsArray);
|
||||||
|
|
||||||
}, [ PhoneGap.onDOMContentLoaded, PhoneGap.onNativeReady ]);
|
}, [ PhoneGap.onDOMContentLoaded, PhoneGap.onNativeReady ]);
|
||||||
|
|
||||||
/**
|
|
||||||
* Fire onDeviceReady event once all constructors have run and PhoneGap info has been
|
|
||||||
* received from native side.
|
|
||||||
*/
|
|
||||||
PhoneGap.Channel.join(function() {
|
|
||||||
// Turn off app loading dialog
|
|
||||||
navigator.notification.activityStop();
|
|
||||||
|
|
||||||
PhoneGap.onDeviceReady.fire();
|
|
||||||
|
|
||||||
// Fire the onresume event, since first one happens before JavaScript is loaded
|
|
||||||
PhoneGap.onResume.fire();
|
|
||||||
}, [ PhoneGap.onPhoneGapReady, PhoneGap.onPhoneGapInfoReady]);
|
|
||||||
|
|
||||||
// Listen for DOMContentLoaded and notify our channel subscribers
|
// Listen for DOMContentLoaded and notify our channel subscribers
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
PhoneGap.onDOMContentLoaded.fire();
|
PhoneGap.onDOMContentLoaded.fire();
|
||||||
@ -272,17 +338,50 @@ PhoneGap.m_document_addEventListener = document.addEventListener;
|
|||||||
|
|
||||||
document.addEventListener = function(evt, handler, capture) {
|
document.addEventListener = function(evt, handler, capture) {
|
||||||
var e = evt.toLowerCase();
|
var e = evt.toLowerCase();
|
||||||
if (e == 'deviceready') {
|
if (e === 'deviceready') {
|
||||||
PhoneGap.onDeviceReady.subscribeOnce(handler);
|
PhoneGap.onDeviceReady.subscribeOnce(handler);
|
||||||
} else if (e == 'resume') {
|
} else if (e === 'resume') {
|
||||||
PhoneGap.onResume.subscribe(handler);
|
PhoneGap.onResume.subscribe(handler);
|
||||||
} else if (e == 'pause') {
|
if (PhoneGap.onDeviceReady.fired) {
|
||||||
|
PhoneGap.onResume.fire();
|
||||||
|
}
|
||||||
|
} else if (e === 'pause') {
|
||||||
PhoneGap.onPause.subscribe(handler);
|
PhoneGap.onPause.subscribe(handler);
|
||||||
} else {
|
}
|
||||||
PhoneGap.m_document_addEventListener.call(document, evt, handler);
|
else {
|
||||||
|
// If subscribing to Android backbutton
|
||||||
|
if (e === 'backbutton') {
|
||||||
|
PhoneGap.exec(null, null, "App", "overrideBackbutton", [true]);
|
||||||
|
}
|
||||||
|
|
||||||
|
PhoneGap.m_document_addEventListener.call(document, evt, handler, capture);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Intercept calls to document.removeEventListener and watch for events that
|
||||||
|
// are generated by PhoneGap native code
|
||||||
|
PhoneGap.m_document_removeEventListener = document.removeEventListener;
|
||||||
|
|
||||||
|
document.removeEventListener = function(evt, handler, capture) {
|
||||||
|
var e = evt.toLowerCase();
|
||||||
|
|
||||||
|
// If unsubscribing to Android backbutton
|
||||||
|
if (e === 'backbutton') {
|
||||||
|
PhoneGap.exec(null, null, "App", "overrideBackbutton", [false]);
|
||||||
|
}
|
||||||
|
|
||||||
|
PhoneGap.m_document_removeEventListener.call(document, evt, handler, capture);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to fire event from native code
|
||||||
|
*/
|
||||||
|
PhoneGap.fireEvent = function(type) {
|
||||||
|
var e = document.createEvent('Events');
|
||||||
|
e.initEvent(type);
|
||||||
|
document.dispatchEvent(e);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If JSON not included, use our own stringify. (Android 1.6)
|
* If JSON not included, use our own stringify. (Android 1.6)
|
||||||
* The restriction on ours is that it must be an array of simple types.
|
* The restriction on ours is that it must be an array of simple types.
|
||||||
@ -291,48 +390,53 @@ document.addEventListener = function(evt, handler, capture) {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
PhoneGap.stringify = function(args) {
|
PhoneGap.stringify = function(args) {
|
||||||
if (typeof JSON == "undefined") {
|
if (typeof JSON === "undefined") {
|
||||||
var s = "[";
|
var s = "[";
|
||||||
for (var i=0; i<args.length; i++) {
|
var i, type, start, name, nameType, a;
|
||||||
if (i > 0) {
|
for (i = 0; i < args.length; i++) {
|
||||||
s = s + ",";
|
if (args[i] != null) {
|
||||||
}
|
if (i > 0) {
|
||||||
var type = typeof args[i];
|
s = s + ",";
|
||||||
if ((type == "number") || (type == "boolean")) {
|
}
|
||||||
s = s + args[i];
|
type = typeof args[i];
|
||||||
}
|
if ((type === "number") || (type === "boolean")) {
|
||||||
else if (args[i] instanceof Array) {
|
s = s + args[i];
|
||||||
s = s + "[" + args[i] + "]";
|
} else if (args[i] instanceof Array) {
|
||||||
}
|
s = s + "[" + args[i] + "]";
|
||||||
else if (args[i] instanceof Object) {
|
} else if (args[i] instanceof Object) {
|
||||||
var start = true;
|
start = true;
|
||||||
s = s + '{';
|
s = s + '{';
|
||||||
for (var name in args[i]) {
|
for (name in args[i]) {
|
||||||
if (!start) {
|
if (args[i][name] !== null) {
|
||||||
s = s + ',';
|
if (!start) {
|
||||||
}
|
s = s + ',';
|
||||||
s = s + '"' + name + '":';
|
}
|
||||||
var nameType = typeof args[i][name];
|
s = s + '"' + name + '":';
|
||||||
if ((nameType == "number") || (nameType == "boolean")) {
|
nameType = typeof args[i][name];
|
||||||
s = s + args[i][name];
|
if ((nameType === "number") || (nameType === "boolean")) {
|
||||||
}
|
s = s + args[i][name];
|
||||||
else {
|
} else if ((typeof args[i][name]) === 'function') {
|
||||||
s = s + '"' + args[i][name] + '"';
|
// don't copy the functions
|
||||||
}
|
s = s + '""';
|
||||||
start=false;
|
} else if (args[i][name] instanceof Object) {
|
||||||
}
|
s = s + this.stringify(args[i][name]);
|
||||||
s = s + '}';
|
} else {
|
||||||
}
|
s = s + '"' + args[i][name] + '"';
|
||||||
else {
|
}
|
||||||
var a = args[i].replace(/\\/g, '\\\\');
|
start = false;
|
||||||
a = a.replace(/"/g, '\\"');
|
}
|
||||||
s = s + '"' + a + '"';
|
}
|
||||||
|
s = s + '}';
|
||||||
|
} else {
|
||||||
|
a = args[i].replace(/\\/g, '\\\\');
|
||||||
|
a = a.replace(/"/g, '\\"');
|
||||||
|
s = s + '"' + a + '"';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s = s + "]";
|
s = s + "]";
|
||||||
return s;
|
return s;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return JSON.stringify(args);
|
return JSON.stringify(args);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -344,13 +448,14 @@ PhoneGap.stringify = function(args) {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
PhoneGap.clone = function(obj) {
|
PhoneGap.clone = function(obj) {
|
||||||
|
var i, retVal;
|
||||||
if(!obj) {
|
if(!obj) {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(obj instanceof Array){
|
if(obj instanceof Array){
|
||||||
var retVal = new Array();
|
retVal = [];
|
||||||
for(var i = 0; i < obj.length; ++i){
|
for(i = 0; i < obj.length; ++i){
|
||||||
retVal.push(PhoneGap.clone(obj[i]));
|
retVal.push(PhoneGap.clone(obj[i]));
|
||||||
}
|
}
|
||||||
return retVal;
|
return retVal;
|
||||||
@ -363,10 +468,14 @@ PhoneGap.clone = function(obj) {
|
|||||||
if(!(obj instanceof Object)){
|
if(!(obj instanceof Object)){
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
retVal = new Object();
|
if (obj instanceof Date) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
retVal = {};
|
||||||
for(i in obj){
|
for(i in obj){
|
||||||
if(!(i in retVal) || retVal[i] != obj[i]) {
|
if(!(i in retVal) || retVal[i] !== obj[i]) {
|
||||||
retVal[i] = PhoneGap.clone(obj[i]);
|
retVal[i] = PhoneGap.clone(obj[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -375,6 +484,19 @@ PhoneGap.clone = function(obj) {
|
|||||||
|
|
||||||
PhoneGap.callbackId = 0;
|
PhoneGap.callbackId = 0;
|
||||||
PhoneGap.callbacks = {};
|
PhoneGap.callbacks = {};
|
||||||
|
PhoneGap.callbackStatus = {
|
||||||
|
NO_RESULT: 0,
|
||||||
|
OK: 1,
|
||||||
|
CLASS_NOT_FOUND_EXCEPTION: 2,
|
||||||
|
ILLEGAL_ACCESS_EXCEPTION: 3,
|
||||||
|
INSTANTIATION_EXCEPTION: 4,
|
||||||
|
MALFORMED_URL_EXCEPTION: 5,
|
||||||
|
IO_EXCEPTION: 6,
|
||||||
|
INVALID_ACTION: 7,
|
||||||
|
JSON_EXCEPTION: 8,
|
||||||
|
ERROR: 9
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute a PhoneGap command. It is up to the native side whether this action is synch or async.
|
* Execute a PhoneGap command. It is up to the native side whether this action is synch or async.
|
||||||
@ -397,38 +519,64 @@ PhoneGap.exec = function(success, fail, service, action, args) {
|
|||||||
PhoneGap.callbacks[callbackId] = {success:success, fail:fail};
|
PhoneGap.callbacks[callbackId] = {success:success, fail:fail};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: Device returns string, but for some reason emulator returns object - so convert to string.
|
var r = prompt(this.stringify(args), "gap:"+this.stringify([service, action, callbackId, true]));
|
||||||
var r = ""+PluginManager.exec(service, action, callbackId, this.stringify(args), true);
|
|
||||||
|
|
||||||
// If a result was returned
|
// If a result was returned
|
||||||
if (r.length > 0) {
|
if (r.length > 0) {
|
||||||
eval("var v="+r+";");
|
eval("var v="+r+";");
|
||||||
|
|
||||||
// If status is OK, then return value back to caller
|
// If status is OK, then return value back to caller
|
||||||
if (v.status == 0) {
|
if (v.status === PhoneGap.callbackStatus.OK) {
|
||||||
|
|
||||||
// If there is a success callback, then call it now with returned value
|
// If there is a success callback, then call it now with
|
||||||
|
// returned value
|
||||||
if (success) {
|
if (success) {
|
||||||
success(v.message);
|
try {
|
||||||
delete PhoneGap.callbacks[callbackId];
|
success(v.message);
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Error in success callback: " + callbackId + " = " + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear callback if not expecting any more results
|
||||||
|
if (!v.keepCallback) {
|
||||||
|
delete PhoneGap.callbacks[callbackId];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return v.message;
|
return v.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If no result
|
||||||
|
else if (v.status === PhoneGap.callbackStatus.NO_RESULT) {
|
||||||
|
|
||||||
|
// Clear callback if not expecting any more results
|
||||||
|
if (!v.keepCallback) {
|
||||||
|
delete PhoneGap.callbacks[callbackId];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If error, then display error
|
// If error, then display error
|
||||||
else {
|
else {
|
||||||
console.log("Error: Status="+r.status+" Message="+v.message);
|
console.log("Error: Status="+v.status+" Message="+v.message);
|
||||||
|
|
||||||
// If there is a fail callback, then call it now with returned value
|
// If there is a fail callback, then call it now with returned value
|
||||||
if (fail) {
|
if (fail) {
|
||||||
fail(v.message);
|
try {
|
||||||
delete PhoneGap.callbacks[callbackId];
|
fail(v.message);
|
||||||
|
}
|
||||||
|
catch (e1) {
|
||||||
|
console.log("Error in error callback: "+callbackId+" = "+e1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear callback if not expecting any more results
|
||||||
|
if (!v.keepCallback) {
|
||||||
|
delete PhoneGap.callbacks[callbackId];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e2) {
|
||||||
console.log("Error: "+e);
|
console.log("Error: "+e2);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -440,15 +588,23 @@ PhoneGap.exec = function(success, fail, service, action, args) {
|
|||||||
*/
|
*/
|
||||||
PhoneGap.callbackSuccess = function(callbackId, args) {
|
PhoneGap.callbackSuccess = function(callbackId, args) {
|
||||||
if (PhoneGap.callbacks[callbackId]) {
|
if (PhoneGap.callbacks[callbackId]) {
|
||||||
try {
|
|
||||||
if (PhoneGap.callbacks[callbackId].success) {
|
// If result is to be sent to callback
|
||||||
PhoneGap.callbacks[callbackId].success(args.message);
|
if (args.status === PhoneGap.callbackStatus.OK) {
|
||||||
|
try {
|
||||||
|
if (PhoneGap.callbacks[callbackId].success) {
|
||||||
|
PhoneGap.callbacks[callbackId].success(args.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.log("Error in success callback: "+callbackId+" = "+e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
|
||||||
console.log("Error in success callback: "+callbackId+" = "+e);
|
// Clear callback if not expecting any more results
|
||||||
|
if (!args.keepCallback) {
|
||||||
|
delete PhoneGap.callbacks[callbackId];
|
||||||
}
|
}
|
||||||
delete PhoneGap.callbacks[callbackId];
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -468,7 +624,11 @@ PhoneGap.callbackError = function(callbackId, args) {
|
|||||||
catch (e) {
|
catch (e) {
|
||||||
console.log("Error in error callback: "+callbackId+" = "+e);
|
console.log("Error in error callback: "+callbackId+" = "+e);
|
||||||
}
|
}
|
||||||
delete PhoneGap.callbacks[callbackId];
|
|
||||||
|
// Clear callback if not expecting any more results
|
||||||
|
if (!args.keepCallback) {
|
||||||
|
delete PhoneGap.callbacks[callbackId];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -482,43 +642,51 @@ PhoneGap.callbackError = function(callbackId, args) {
|
|||||||
*/
|
*/
|
||||||
// TODO: Is this used?
|
// TODO: Is this used?
|
||||||
PhoneGap.run_command = function() {
|
PhoneGap.run_command = function() {
|
||||||
if (!PhoneGap.available || !PhoneGap.queue.ready)
|
if (!PhoneGap.available || !PhoneGap.queue.ready) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
PhoneGap.queue.ready = false;
|
PhoneGap.queue.ready = false;
|
||||||
|
|
||||||
var args = PhoneGap.queue.commands.shift();
|
var args = PhoneGap.queue.commands.shift();
|
||||||
if (PhoneGap.queue.commands.length == 0) {
|
if (PhoneGap.queue.commands.length === 0) {
|
||||||
clearInterval(PhoneGap.queue.timer);
|
clearInterval(PhoneGap.queue.timer);
|
||||||
PhoneGap.queue.timer = null;
|
PhoneGap.queue.timer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var uri = [];
|
var uri = [];
|
||||||
var dict = null;
|
var dict = null;
|
||||||
for (var i = 1; i < args.length; i++) {
|
var i;
|
||||||
|
for (i = 1; i < args.length; i++) {
|
||||||
var arg = args[i];
|
var arg = args[i];
|
||||||
if (arg == undefined || arg == null)
|
if (arg === undefined || arg === null) {
|
||||||
arg = '';
|
arg = '';
|
||||||
if (typeof(arg) == 'object')
|
}
|
||||||
|
if (typeof(arg) === 'object') {
|
||||||
dict = arg;
|
dict = arg;
|
||||||
else
|
} else {
|
||||||
uri.push(encodeURIComponent(arg));
|
uri.push(encodeURIComponent(arg));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var url = "gap://" + args[0] + "/" + uri.join("/");
|
var url = "gap://" + args[0] + "/" + uri.join("/");
|
||||||
if (dict != null) {
|
if (dict !== null) {
|
||||||
|
var name;
|
||||||
var query_args = [];
|
var query_args = [];
|
||||||
for (var name in dict) {
|
for (name in dict) {
|
||||||
if (typeof(name) != 'string')
|
if (dict.hasOwnProperty(name) && (typeof (name) === 'string')) {
|
||||||
continue;
|
query_args.push(encodeURIComponent(name) + "=" + encodeURIComponent(dict[name]));
|
||||||
query_args.push(encodeURIComponent(name) + "=" + encodeURIComponent(dict[name]));
|
}
|
||||||
}
|
}
|
||||||
if (query_args.length > 0)
|
if (query_args.length > 0) {
|
||||||
url += "?" + query_args.join("&");
|
url += "?" + query_args.join("&");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
document.location = url;
|
document.location = url;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PhoneGap.JSCallbackPort = null;
|
||||||
|
PhoneGap.JSCallbackToken = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is only for Android.
|
* This is only for Android.
|
||||||
*
|
*
|
||||||
@ -527,14 +695,21 @@ PhoneGap.run_command = function() {
|
|||||||
* Java to JavaScript.
|
* Java to JavaScript.
|
||||||
*/
|
*/
|
||||||
PhoneGap.JSCallback = function() {
|
PhoneGap.JSCallback = function() {
|
||||||
|
|
||||||
|
// If polling flag was changed, start using polling from now on
|
||||||
|
if (PhoneGap.UsePolling) {
|
||||||
|
PhoneGap.JSCallbackPolling();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var xmlhttp = new XMLHttpRequest();
|
var xmlhttp = new XMLHttpRequest();
|
||||||
|
|
||||||
// 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){
|
||||||
|
|
||||||
// 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;
|
var msg = xmlhttp.responseText;
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
@ -542,6 +717,8 @@ PhoneGap.JSCallback = function() {
|
|||||||
var t = eval(msg);
|
var t = eval(msg);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
// If we're getting an error here, seeing the message will help in debugging
|
||||||
|
console.log("JSCallback: Message from Server: " + msg);
|
||||||
console.log("JSCallback Error: "+e);
|
console.log("JSCallback Error: "+e);
|
||||||
}
|
}
|
||||||
}, 1);
|
}, 1);
|
||||||
@ -549,21 +726,88 @@ PhoneGap.JSCallback = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If callback ping (used to keep XHR request from timing out)
|
// If callback ping (used to keep XHR request from timing out)
|
||||||
else if (xmlhttp.status == 404) {
|
else if (xmlhttp.status === 404) {
|
||||||
setTimeout(PhoneGap.JSCallback, 10);
|
setTimeout(PhoneGap.JSCallback, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If security error
|
||||||
|
else if (xmlhttp.status === 403) {
|
||||||
|
console.log("JSCallback Error: Invalid token. Stopping callbacks.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If server is stopping
|
||||||
|
else if (xmlhttp.status === 503) {
|
||||||
|
console.log("JSCallback Error: Service unavailable. Stopping callbacks.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If request wasn't GET
|
||||||
|
else if (xmlhttp.status === 400) {
|
||||||
|
console.log("JSCallback Error: Bad request. Stopping callbacks.");
|
||||||
|
}
|
||||||
|
|
||||||
// If error, restart callback server
|
// If error, restart callback server
|
||||||
else {
|
else {
|
||||||
console.log("JSCallback Error: Request failed.");
|
console.log("JSCallback Error: Request failed.");
|
||||||
CallbackServer.restartServer();
|
prompt("restartServer", "gap_callbackServer:");
|
||||||
|
PhoneGap.JSCallbackPort = null;
|
||||||
|
PhoneGap.JSCallbackToken = null;
|
||||||
setTimeout(PhoneGap.JSCallback, 100);
|
setTimeout(PhoneGap.JSCallback, 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (PhoneGap.JSCallbackPort === null) {
|
||||||
|
PhoneGap.JSCallbackPort = prompt("getPort", "gap_callbackServer:");
|
||||||
|
}
|
||||||
|
if (PhoneGap.JSCallbackToken === null) {
|
||||||
|
PhoneGap.JSCallbackToken = prompt("getToken", "gap_callbackServer:");
|
||||||
|
}
|
||||||
|
xmlhttp.open("GET", "http://127.0.0.1:"+PhoneGap.JSCallbackPort+"/"+PhoneGap.JSCallbackToken , true);
|
||||||
|
xmlhttp.send();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The polling period to use with JSCallbackPolling.
|
||||||
|
* This can be changed by the application. The default is 50ms.
|
||||||
|
*/
|
||||||
|
PhoneGap.JSCallbackPollingPeriod = 50;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag that can be set by the user to force polling to be used or force XHR to be used.
|
||||||
|
*/
|
||||||
|
PhoneGap.UsePolling = false; // T=use polling, F=use XHR
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is only for Android.
|
||||||
|
*
|
||||||
|
* Internal function that uses polling to call into PhoneGap Java code and retrieve
|
||||||
|
* any JavaScript code that needs to be run. This is used for callbacks from
|
||||||
|
* Java to JavaScript.
|
||||||
|
*/
|
||||||
|
PhoneGap.JSCallbackPolling = function() {
|
||||||
|
|
||||||
|
// If polling flag was changed, stop using polling from now on
|
||||||
|
if (!PhoneGap.UsePolling) {
|
||||||
|
PhoneGap.JSCallback();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlhttp.open("GET", "http://127.0.0.1:"+CallbackServer.getPort()+"/" , true);
|
var msg = prompt("", "gap_poll:");
|
||||||
xmlhttp.send();
|
if (msg) {
|
||||||
|
setTimeout(function() {
|
||||||
|
try {
|
||||||
|
var t = eval(""+msg);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.log("JSCallbackPolling: Message from Server: " + msg);
|
||||||
|
console.log("JSCallbackPolling Error: "+e);
|
||||||
|
}
|
||||||
|
}, 1);
|
||||||
|
setTimeout(PhoneGap.JSCallbackPolling, 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setTimeout(PhoneGap.JSCallbackPolling, PhoneGap.JSCallbackPollingPeriod);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -581,9 +825,10 @@ PhoneGap.createUUID = function() {
|
|||||||
|
|
||||||
PhoneGap.UUIDcreatePart = function(length) {
|
PhoneGap.UUIDcreatePart = function(length) {
|
||||||
var uuidpart = "";
|
var uuidpart = "";
|
||||||
for (var i=0; i<length; i++) {
|
var i, uuidchar;
|
||||||
var uuidchar = parseInt((Math.random() * 256)).toString(16);
|
for (i=0; i<length; i++) {
|
||||||
if (uuidchar.length == 1) {
|
uuidchar = parseInt((Math.random() * 256),0).toString(16);
|
||||||
|
if (uuidchar.length === 1) {
|
||||||
uuidchar = "0" + uuidchar;
|
uuidchar = "0" + uuidchar;
|
||||||
}
|
}
|
||||||
uuidpart += uuidchar;
|
uuidpart += uuidchar;
|
||||||
@ -595,11 +840,27 @@ PhoneGap.close = function(context, func, params) {
|
|||||||
if (typeof params === 'undefined') {
|
if (typeof params === 'undefined') {
|
||||||
return function() {
|
return function() {
|
||||||
return func.apply(context, arguments);
|
return func.apply(context, arguments);
|
||||||
}
|
};
|
||||||
} else {
|
} else {
|
||||||
return function() {
|
return function() {
|
||||||
return func.apply(context, params);
|
return func.apply(context, params);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a JavaScript file after page has loaded.
|
||||||
|
*
|
||||||
|
* @param {String} jsfile The url of the JavaScript file to load.
|
||||||
|
* @param {Function} successCallback The callback to call when the file has been loaded.
|
||||||
|
*/
|
||||||
|
PhoneGap.includeJavascript = function(jsfile, successCallback) {
|
||||||
|
var id = document.getElementsByTagName("head")[0];
|
||||||
|
var el = document.createElement('script');
|
||||||
|
el.type = 'text/javascript';
|
||||||
|
if (typeof successCallback === 'function') {
|
||||||
|
el.onload = successCallback;
|
||||||
|
}
|
||||||
|
el.src = jsfile;
|
||||||
|
id.appendChild(el);
|
||||||
|
};
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
function Position(coords, timestamp) {
|
function Position(coords, timestamp) {
|
||||||
this.coords = coords;
|
this.coords = coords;
|
||||||
this.timestamp = new Date().getTime();
|
this.timestamp = (timestamp !== 'undefined') ? timestamp : new Date().getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
function Coordinates(lat, lng, alt, acc, head, vel, altacc) {
|
function Coordinates(lat, lng, alt, acc, head, vel, altacc) {
|
||||||
@ -50,7 +50,7 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,30 +20,13 @@ var DroidDB = function() {
|
|||||||
this.queryQueue = {};
|
this.queryQueue = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback from native code when result from a query is available.
|
|
||||||
* PRIVATE METHOD
|
|
||||||
*
|
|
||||||
* @param rawdata JSON string of the row data
|
|
||||||
* @param id Query id
|
|
||||||
*/
|
|
||||||
DroidDB.prototype.addResult = function(rawdata, id) {
|
|
||||||
try {
|
|
||||||
eval("var data = " + rawdata + ";");
|
|
||||||
var query = this.queryQueue[id];
|
|
||||||
query.resultSet.push(data);
|
|
||||||
} catch (e) {
|
|
||||||
console.log("DroidDB.addResult(): Error="+e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback from native code when query is complete.
|
* Callback from native code when query is complete.
|
||||||
* PRIVATE METHOD
|
* PRIVATE METHOD
|
||||||
*
|
*
|
||||||
* @param id Query id
|
* @param id Query id
|
||||||
*/
|
*/
|
||||||
DroidDB.prototype.completeQuery = function(id) {
|
DroidDB.prototype.completeQuery = function(id, data) {
|
||||||
var query = this.queryQueue[id];
|
var query = this.queryQueue[id];
|
||||||
if (query) {
|
if (query) {
|
||||||
try {
|
try {
|
||||||
@ -59,10 +42,10 @@ DroidDB.prototype.completeQuery = function(id) {
|
|||||||
|
|
||||||
// Save query results
|
// Save query results
|
||||||
var r = new DroidDB_Result();
|
var r = new DroidDB_Result();
|
||||||
r.rows.resultSet = query.resultSet;
|
r.rows.resultSet = data;
|
||||||
r.rows.length = query.resultSet.length;
|
r.rows.length = data.length;
|
||||||
try {
|
try {
|
||||||
if (typeof query.successCallback == 'function') {
|
if (typeof query.successCallback === 'function') {
|
||||||
query.successCallback(query.tx, r);
|
query.successCallback(query.tx, r);
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@ -100,7 +83,7 @@ DroidDB.prototype.fail = function(reason, id) {
|
|||||||
tx.queryList = {};
|
tx.queryList = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (typeof query.errorCallback == 'function') {
|
if (typeof query.errorCallback === 'function') {
|
||||||
query.errorCallback(query.tx, reason);
|
query.errorCallback(query.tx, reason);
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@ -116,35 +99,6 @@ DroidDB.prototype.fail = function(reason, id) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var DatabaseShell = function() {
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start a transaction.
|
|
||||||
* Does not support rollback in event of failure.
|
|
||||||
*
|
|
||||||
* @param process {Function} The transaction function
|
|
||||||
* @param successCallback {Function}
|
|
||||||
* @param errorCallback {Function}
|
|
||||||
*/
|
|
||||||
DatabaseShell.prototype.transaction = function(process, successCallback, errorCallback) {
|
|
||||||
var tx = new DroidDB_Tx();
|
|
||||||
tx.successCallback = successCallback;
|
|
||||||
tx.errorCallback = errorCallback;
|
|
||||||
try {
|
|
||||||
process(tx);
|
|
||||||
} catch (e) {
|
|
||||||
console.log("Transaction error: "+e);
|
|
||||||
if (tx.errorCallback) {
|
|
||||||
try {
|
|
||||||
tx.errorCallback(e);
|
|
||||||
} catch (ex) {
|
|
||||||
console.log("Transaction error calling user error callback: "+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transaction object
|
* Transaction object
|
||||||
* PRIVATE METHOD
|
* PRIVATE METHOD
|
||||||
@ -162,6 +116,37 @@ var DroidDB_Tx = function() {
|
|||||||
this.queryList = {};
|
this.queryList = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var DatabaseShell = function() {
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start a transaction.
|
||||||
|
* Does not support rollback in event of failure.
|
||||||
|
*
|
||||||
|
* @param process {Function} The transaction function
|
||||||
|
* @param successCallback {Function}
|
||||||
|
* @param errorCallback {Function}
|
||||||
|
*/
|
||||||
|
DatabaseShell.prototype.transaction = function(process, errorCallback, successCallback) {
|
||||||
|
var tx = new DroidDB_Tx();
|
||||||
|
tx.successCallback = successCallback;
|
||||||
|
tx.errorCallback = errorCallback;
|
||||||
|
try {
|
||||||
|
process(tx);
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Transaction error: "+e);
|
||||||
|
if (tx.errorCallback) {
|
||||||
|
try {
|
||||||
|
tx.errorCallback(e);
|
||||||
|
} catch (ex) {
|
||||||
|
console.log("Transaction error calling user error callback: "+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark query in transaction as complete.
|
* Mark query in transaction as complete.
|
||||||
* If all queries are complete, call the user's transaction success callback.
|
* If all queries are complete, call the user's transaction success callback.
|
||||||
@ -174,10 +159,13 @@ DroidDB_Tx.prototype.queryComplete = function(id) {
|
|||||||
// If no more outstanding queries, then fire transaction success
|
// If no more outstanding queries, then fire transaction success
|
||||||
if (this.successCallback) {
|
if (this.successCallback) {
|
||||||
var count = 0;
|
var count = 0;
|
||||||
for (var i in this.queryList) {
|
var i;
|
||||||
count++;
|
for (i in this.queryList) {
|
||||||
|
if (this.queryList.hasOwnProperty(i)) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (count == 0) {
|
if (count === 0) {
|
||||||
try {
|
try {
|
||||||
this.successCallback();
|
this.successCallback();
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
@ -237,7 +225,7 @@ var DroidDB_Query = function(tx) {
|
|||||||
this.successCallback = null;
|
this.successCallback = null;
|
||||||
this.errorCallback = null;
|
this.errorCallback = null;
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute SQL statement
|
* Execute SQL statement
|
||||||
@ -250,7 +238,7 @@ var DroidDB_Query = function(tx) {
|
|||||||
DroidDB_Tx.prototype.executeSql = function(sql, params, successCallback, errorCallback) {
|
DroidDB_Tx.prototype.executeSql = function(sql, params, successCallback, errorCallback) {
|
||||||
|
|
||||||
// Init params array
|
// Init params array
|
||||||
if (typeof params == 'undefined') {
|
if (typeof params === 'undefined') {
|
||||||
params = [];
|
params = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,9 +296,100 @@ DroidDB_openDatabase = function(name, version, display_name, size) {
|
|||||||
return db;
|
return db;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For browsers with no localStorage we emulate it with SQLite. Follows the w3c api.
|
||||||
|
* TODO: Do similar for sessionStorage.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var CupcakeLocalStorage = function() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
this.db = openDatabase('localStorage', '1.0', 'localStorage', 2621440);
|
||||||
|
var storage = {};
|
||||||
|
this.length = 0;
|
||||||
|
function setLength (length) {
|
||||||
|
this.length = length;
|
||||||
|
localStorage.length = length;
|
||||||
|
}
|
||||||
|
this.db.transaction(
|
||||||
|
function (transaction) {
|
||||||
|
var i;
|
||||||
|
transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
|
||||||
|
transaction.executeSql('SELECT * FROM storage', [], function(tx, result) {
|
||||||
|
for(var i = 0; i < result.rows.length; i++) {
|
||||||
|
storage[result.rows.item(i)['id']] = result.rows.item(i)['body'];
|
||||||
|
}
|
||||||
|
setLength(result.rows.length);
|
||||||
|
PhoneGap.initializationComplete("cupcakeStorage");
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
function (err) {
|
||||||
|
alert(err.message);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
this.setItem = function(key, val) {
|
||||||
|
if (typeof(storage[key])=='undefined') {
|
||||||
|
this.length++;
|
||||||
|
}
|
||||||
|
storage[key] = val;
|
||||||
|
this.db.transaction(
|
||||||
|
function (transaction) {
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
this.getItem = function(key) {
|
||||||
|
return storage[key];
|
||||||
|
};
|
||||||
|
this.removeItem = function(key) {
|
||||||
|
delete storage[key];
|
||||||
|
this.length--;
|
||||||
|
this.db.transaction(
|
||||||
|
function (transaction) {
|
||||||
|
transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
|
||||||
|
transaction.executeSql('DELETE FROM storage where id=?', [key]);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
this.clear = function() {
|
||||||
|
storage = {};
|
||||||
|
this.length = 0;
|
||||||
|
this.db.transaction(
|
||||||
|
function (transaction) {
|
||||||
|
transaction.executeSql('CREATE TABLE IF NOT EXISTS storage (id NVARCHAR(40) PRIMARY KEY, body NVARCHAR(255))');
|
||||||
|
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) {
|
||||||
|
alert("Database error "+e+".");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
if (typeof window.openDatabase == "undefined") {
|
if (typeof window.openDatabase === "undefined") {
|
||||||
navigator.openDatabase = window.openDatabase = DroidDB_openDatabase;
|
navigator.openDatabase = window.openDatabase = DroidDB_openDatabase;
|
||||||
window.droiddb = new DroidDB();
|
window.droiddb = new DroidDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof window.localStorage === "undefined") {
|
||||||
|
navigator.localStorage = window.localStorage = new CupcakeLocalStorage();
|
||||||
|
PhoneGap.waitForInitialization("cupcakeStorage");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
9
framework/assets/www/index.html
Normal file
9
framework/assets/www/index.html
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title></title>
|
||||||
|
<script src="phonegap.0.9.4.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
File diff suppressed because it is too large
Load Diff
73
framework/build.xml
Normal file → Executable file
73
framework/build.xml
Normal file → Executable file
@ -1,6 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project name="PhoneGap" default="help">
|
<project name="PhoneGap" default="help">
|
||||||
|
|
||||||
|
<!-- LOAD VERSION -->
|
||||||
|
<loadfile property="version" srcFile="../VERSION">
|
||||||
|
<filterchain>
|
||||||
|
<striplinebreaks/>
|
||||||
|
</filterchain>
|
||||||
|
</loadfile>
|
||||||
|
|
||||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||||
It contains the path to the SDK. It should *NOT* be checked in in Version
|
It contains the path to the SDK. It should *NOT* be checked in in Version
|
||||||
Control Systems. -->
|
Control Systems. -->
|
||||||
@ -73,7 +80,7 @@
|
|||||||
<include name="lint.js" />
|
<include name="lint.js" />
|
||||||
</fileset>
|
</fileset>
|
||||||
<fileset dir="assets/www">
|
<fileset dir="assets/www">
|
||||||
<include name="phonegap.js" />
|
<include name="phonegap.${version}.js" />
|
||||||
</fileset>
|
</fileset>
|
||||||
</concat>
|
</concat>
|
||||||
|
|
||||||
@ -95,16 +102,72 @@
|
|||||||
</exec>
|
</exec>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="build-javascript">
|
<!-- Combine JavaScript files into one phonegap.js file.
|
||||||
<delete file="assets/www/phonegap.js"/>
|
This task does not create a compressed JavaScript file. -->
|
||||||
<concat destfile="assets/www/phonegap.js">
|
<target name="build-uncompressed-javascript">
|
||||||
|
|
||||||
|
<!-- Clean up existing files -->
|
||||||
|
<delete file="assets/www/phonegap.${version}.min.js"/>
|
||||||
|
<delete file="assets/www/phonegap-tmp.js"/>
|
||||||
|
<delete file="assets/www/phonegap.${version}.js"/>
|
||||||
|
|
||||||
|
<!-- Create uncompressed JS file -->
|
||||||
|
<concat destfile="assets/www/phonegap.${version}.js">
|
||||||
<fileset dir="assets/js" includes="phonegap.js.base" />
|
<fileset dir="assets/js" includes="phonegap.js.base" />
|
||||||
<fileset dir="assets/js" includes="*.js" />
|
<fileset dir="assets/js" includes="*.js" />
|
||||||
</concat>
|
</concat>
|
||||||
|
|
||||||
|
<!-- update project files to reference phonegap-x.x.x.js -->
|
||||||
|
<replaceregexp match="phonegap(.*)\.js" replace="phonegap.${version}.js" byline="true">
|
||||||
|
<fileset file="assets/www/index.html" />
|
||||||
|
<fileset file="../example/index.html" />
|
||||||
|
</replaceregexp>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- Combine JavaScript files into one phonegap-uncompressed.js file.
|
||||||
|
Compress this file using yuicompressor to create phonegap.js. -->
|
||||||
|
<target name="build-javascript">
|
||||||
|
|
||||||
|
<!-- Clean up existing files -->
|
||||||
|
<delete file="assets/www/phonegap_${version}.min.js"/>
|
||||||
|
<delete file="assets/www/phonegap-tmp.js"/>
|
||||||
|
<delete file="assets/www/phonegap_${version}.js"/>
|
||||||
|
|
||||||
|
<!-- Create uncompressed JS file -->
|
||||||
|
<concat destfile="assets/www/phonegap.${version}.js">
|
||||||
|
<fileset dir="assets/js" includes="phonegap.js.base" />
|
||||||
|
<fileset dir="assets/js" includes="*.js" />
|
||||||
|
</concat>
|
||||||
|
|
||||||
|
<!-- Compress JS file -->
|
||||||
|
<java jar="${basedir}/../util/yuicompressor/yuicompressor-2.4.2.jar" fork="true" failonerror="true">
|
||||||
|
<arg line="--nomunge -o assets/www/phonegap-tmp.js assets/www/phonegap.${version}.js"/>
|
||||||
|
</java>
|
||||||
|
<concat destfile="assets/www/phonegap.${version}.min.js">
|
||||||
|
<fileset dir="assets/js" includes="header.txt" />
|
||||||
|
<fileset dir="assets/www" includes="phonegap-tmp.js" />
|
||||||
|
</concat>
|
||||||
|
|
||||||
|
<!-- update project files to reference phonegap-x.x.x.min.js -->
|
||||||
|
<replaceregexp match="phonegap(.*)\.js" replace="phonegap.${version}.min.js" byline="true">
|
||||||
|
<fileset file="assets/www/index.html" />
|
||||||
|
<fileset file="../example/index.html" />
|
||||||
|
</replaceregexp>
|
||||||
|
|
||||||
|
<!-- Delete temp file -->
|
||||||
|
<delete file="assets/www/phonegap-tmp.js"/>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
<!-- Build PhoneGap jar file that includes all native code, and PhoneGap JS file
|
||||||
|
that includes all JavaScript code.
|
||||||
|
|
||||||
|
The default is to compress the JavaScript code using yuicompressor.
|
||||||
|
|
||||||
|
If you want uncompressed JavaScript, change
|
||||||
|
"build-javascript" => "build-uncompressed-javascript".
|
||||||
|
-->
|
||||||
<target name="jar" depends="build-javascript, compile">
|
<target name="jar" depends="build-javascript, compile">
|
||||||
<jar jarfile="phonegap.jar" basedir="bin/classes" excludes="**/R*.class" />
|
<jar jarfile="phonegap.${version}.jar" basedir="bin/classes" excludes="com/phonegap/R.class,com/phonegap/R$*.class"/>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="phonegap_debug" depends="build-javascript, debug">
|
<target name="phonegap_debug" depends="build-javascript, debug">
|
||||||
|
@ -13,6 +13,7 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.phonegap.api.PhonegapActivity;
|
||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ public class AccelListener extends Plugin implements SensorEventListener {
|
|||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public void setContext(PhonegapActivity ctx) {
|
||||||
super.setContext(ctx);
|
super.setContext(ctx);
|
||||||
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
||||||
}
|
}
|
||||||
|
173
framework/src/com/phonegap/App.java
Executable file
173
framework/src/com/phonegap/App.java
Executable file
@ -0,0 +1,173 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
package com.phonegap;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import com.phonegap.api.Plugin;
|
||||||
|
import com.phonegap.api.PluginResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class exposes methods in DroidGap that can be called from JavaScript.
|
||||||
|
*/
|
||||||
|
public class App extends Plugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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("clearCache")) {
|
||||||
|
this.clearCache();
|
||||||
|
}
|
||||||
|
else if (action.equals("loadUrl")) {
|
||||||
|
this.loadUrl(args.getString(0), args.optJSONObject(1));
|
||||||
|
}
|
||||||
|
else if (action.equals("cancelLoadUrl")) {
|
||||||
|
this.cancelLoadUrl();
|
||||||
|
}
|
||||||
|
else if (action.equals("clearHistory")) {
|
||||||
|
this.clearHistory();
|
||||||
|
}
|
||||||
|
else if (action.equals("addService")) {
|
||||||
|
this.addService(args.getString(0), args.getString(1));
|
||||||
|
}
|
||||||
|
else if (action.equals("overrideBackbutton")) {
|
||||||
|
this.overrideBackbutton(args.getBoolean(0));
|
||||||
|
}
|
||||||
|
else if (action.equals("isBackbuttonOverridden")) {
|
||||||
|
boolean b = this.isBackbuttonOverridden();
|
||||||
|
return new PluginResult(status, b);
|
||||||
|
}
|
||||||
|
else if (action.equals("exitApp")) {
|
||||||
|
this.exitApp();
|
||||||
|
}
|
||||||
|
return new PluginResult(status, result);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
// LOCAL METHODS
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the resource cache.
|
||||||
|
*/
|
||||||
|
public void clearCache() {
|
||||||
|
((DroidGap)this.ctx).clearCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the url into the webview.
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
* @param props Properties that can be passed in to the DroidGap activity (i.e. loadingDialog, wait, ...)
|
||||||
|
* @throws JSONException
|
||||||
|
*/
|
||||||
|
public void loadUrl(String url, JSONObject props) throws JSONException {
|
||||||
|
System.out.println("App.loadUrl("+url+","+props+")");
|
||||||
|
int wait = 0;
|
||||||
|
|
||||||
|
// If there are properties, then set them on the Activity
|
||||||
|
if (props != null) {
|
||||||
|
JSONArray keys = props.names();
|
||||||
|
for (int i=0; i<keys.length(); i++) {
|
||||||
|
String key = keys.getString(i);
|
||||||
|
if (key.equals("wait")) {
|
||||||
|
wait = props.getInt(key);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Object value = props.get(key);
|
||||||
|
if (value == null) {
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (value.getClass().equals(String.class)) {
|
||||||
|
this.ctx.getIntent().putExtra(key, (String)value);
|
||||||
|
}
|
||||||
|
else if (value.getClass().equals(Boolean.class)) {
|
||||||
|
this.ctx.getIntent().putExtra(key, (Boolean)value);
|
||||||
|
}
|
||||||
|
else if (value.getClass().equals(Integer.class)) {
|
||||||
|
this.ctx.getIntent().putExtra(key, (Integer)value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If wait property, then delay loading
|
||||||
|
if (wait > 0) {
|
||||||
|
((DroidGap)this.ctx).loadUrl(url, wait);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
((DroidGap)this.ctx).loadUrl(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel loadUrl before it has been loaded.
|
||||||
|
*/
|
||||||
|
public void cancelLoadUrl() {
|
||||||
|
((DroidGap)this.ctx).cancelLoadUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear web history in this web view.
|
||||||
|
*/
|
||||||
|
public void clearHistory() {
|
||||||
|
((DroidGap)this.ctx).clearHistory();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a class that implements a service.
|
||||||
|
*
|
||||||
|
* @param serviceType
|
||||||
|
* @param className
|
||||||
|
*/
|
||||||
|
public void addService(String serviceType, String className) {
|
||||||
|
this.ctx.addService(serviceType, className);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override the default behavior of the Android back button.
|
||||||
|
* If overridden, when the back button is pressed, the "backKeyDown" JavaScript event will be fired.
|
||||||
|
*
|
||||||
|
* @param override T=override, F=cancel override
|
||||||
|
*/
|
||||||
|
public void overrideBackbutton(boolean override) {
|
||||||
|
System.out.println("WARNING: Back Button Default Behaviour will be overridden. The backbutton event will be fired!");
|
||||||
|
((DroidGap)this.ctx).bound = override;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether the Android back button is overridden by the user.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean isBackbuttonOverridden() {
|
||||||
|
return ((DroidGap)this.ctx).bound;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exit the Android application.
|
||||||
|
*/
|
||||||
|
public void exitApp() {
|
||||||
|
((DroidGap)this.ctx).finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -20,7 +20,7 @@ import android.content.Context;
|
|||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class called by DroidGap to play and record audio.
|
* This class called by PhonegapActivity to play and record audio.
|
||||||
* The file can be local or over a network using http.
|
* The file can be local or over a network using http.
|
||||||
*
|
*
|
||||||
* Audio formats supported (tested):
|
* Audio formats supported (tested):
|
||||||
@ -77,13 +77,17 @@ public class AudioHandler extends Plugin {
|
|||||||
long l = this.getDurationAudio(args.getString(0), args.getString(1));
|
long l = this.getDurationAudio(args.getString(0), args.getString(1));
|
||||||
return new PluginResult(status, l);
|
return new PluginResult(status, l);
|
||||||
}
|
}
|
||||||
|
else if (action.equals("release")) {
|
||||||
|
boolean b = this.release(args.getString(0));
|
||||||
|
return new PluginResult(status, b);
|
||||||
|
}
|
||||||
return new PluginResult(status, result);
|
return new PluginResult(status, result);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*
|
*
|
||||||
@ -117,6 +121,21 @@ public class AudioHandler extends Plugin {
|
|||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
// LOCAL METHODS
|
// LOCAL METHODS
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release the audio player instance to save memory.
|
||||||
|
*
|
||||||
|
* @param id The id of the audio player
|
||||||
|
*/
|
||||||
|
private boolean release(String id) {
|
||||||
|
if (!this.players.containsKey(id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
AudioPlayer audio = this.players.get(id);
|
||||||
|
this.players.remove(id);
|
||||||
|
audio.destroy();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start recording and save the specified file.
|
* Start recording and save the specified file.
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
package com.phonegap;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.webkit.WebView;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This class literally exists to protect DroidGap from Javascript directly.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class BrowserKey {
|
|
||||||
|
|
||||||
DroidGap mAction;
|
|
||||||
boolean bound;
|
|
||||||
WebView mView;
|
|
||||||
|
|
||||||
BrowserKey(WebView view, DroidGap action)
|
|
||||||
{
|
|
||||||
bound = false;
|
|
||||||
mAction = action;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void override()
|
|
||||||
{
|
|
||||||
Log.d("PhoneGap", "WARNING: Back Button Default Behaviour will be overridden. The backKeyDown event will be fired!");
|
|
||||||
bound = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isBound()
|
|
||||||
{
|
|
||||||
return bound;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reset()
|
|
||||||
{
|
|
||||||
bound = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void exitApp()
|
|
||||||
{
|
|
||||||
mAction.finish();
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,10 +17,10 @@ import java.util.LinkedList;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides a way for Java to run JavaScript in the web page that has loaded PhoneGap.
|
* This class provides a way for Java to run JavaScript in the web page that has loaded PhoneGap.
|
||||||
* The CallbackServer class implements an XHR server and a list of JavaScript statements
|
* The CallbackServer class implements an XHR server and a polling server with a list of JavaScript
|
||||||
* that are to be executed on the web page.
|
* statements that are to be executed on the web page.
|
||||||
*
|
*
|
||||||
* The process flow is:
|
* The process flow for XHR is:
|
||||||
* 1. JavaScript makes an async XHR call.
|
* 1. JavaScript makes an async XHR call.
|
||||||
* 2. The server holds the connection open until data is available.
|
* 2. The server holds the connection open until data is available.
|
||||||
* 3. The server writes the data to the client and closes the connection.
|
* 3. The server writes the data to the client and closes the connection.
|
||||||
@ -30,6 +30,14 @@ import java.util.LinkedList;
|
|||||||
*
|
*
|
||||||
* The CallbackServer class requires the following permission in Android manifest file
|
* The CallbackServer class requires the following permission in Android manifest file
|
||||||
* <uses-permission android:name="android.permission.INTERNET" />
|
* <uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
*
|
||||||
|
* If the device has a proxy set, then XHR cannot be used, so polling must be used instead.
|
||||||
|
* This can be determined by the client by calling CallbackServer.usePolling().
|
||||||
|
*
|
||||||
|
* The process flow for polling is:
|
||||||
|
* 1. The client calls CallbackServer.getJavascript() to retrieve next statement.
|
||||||
|
* 2. If statement available, then client processes it.
|
||||||
|
* 3. The client repeats #1 in loop.
|
||||||
*/
|
*/
|
||||||
public class CallbackServer implements Runnable {
|
public class CallbackServer implements Runnable {
|
||||||
|
|
||||||
@ -58,6 +66,16 @@ public class CallbackServer implements Runnable {
|
|||||||
*/
|
*/
|
||||||
private boolean empty;
|
private boolean empty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that polling should be used instead of XHR.
|
||||||
|
*/
|
||||||
|
private boolean usePolling = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Security token to prevent other apps from accessing this callback server via XHR
|
||||||
|
*/
|
||||||
|
private String token;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
@ -66,8 +84,42 @@ public class CallbackServer implements Runnable {
|
|||||||
this.active = false;
|
this.active = false;
|
||||||
this.empty = true;
|
this.empty = true;
|
||||||
this.port = 0;
|
this.port = 0;
|
||||||
this.javascript = new LinkedList<String>();
|
this.javascript = new LinkedList<String>();
|
||||||
this.startServer();
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init callback server and start XHR if running local app.
|
||||||
|
*
|
||||||
|
* If PhoneGap app is loaded from file://, then we can use XHR
|
||||||
|
* otherwise we have to use polling due to cross-domain security restrictions.
|
||||||
|
*
|
||||||
|
* @param url The URL of the PhoneGap app being loaded
|
||||||
|
*/
|
||||||
|
public void init(String url) {
|
||||||
|
//System.out.println("CallbackServer.start("+url+")");
|
||||||
|
|
||||||
|
// Determine if XHR or polling is to be used
|
||||||
|
if ((url != null) && !url.startsWith("file://")) {
|
||||||
|
this.usePolling = true;
|
||||||
|
this.stopServer();
|
||||||
|
}
|
||||||
|
else if (android.net.Proxy.getDefaultHost() != null) {
|
||||||
|
this.usePolling = true;
|
||||||
|
this.stopServer();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.usePolling = false;
|
||||||
|
this.startServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return if polling is being used instead of XHR.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean usePolling() {
|
||||||
|
return this.usePolling;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,6 +131,15 @@ public class CallbackServer implements Runnable {
|
|||||||
return this.port;
|
return this.port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the security token that this server requires when calling getJavascript().
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getToken() {
|
||||||
|
return this.token;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the server on a new thread.
|
* Start the server on a new thread.
|
||||||
*/
|
*/
|
||||||
@ -115,7 +176,9 @@ public class CallbackServer implements Runnable {
|
|||||||
String request;
|
String request;
|
||||||
ServerSocket waitSocket = new ServerSocket(0);
|
ServerSocket waitSocket = new ServerSocket(0);
|
||||||
this.port = waitSocket.getLocalPort();
|
this.port = waitSocket.getLocalPort();
|
||||||
//System.out.println(" -- using port " +this.port);
|
//System.out.println("CallbackServer -- using port " +this.port);
|
||||||
|
this.token = java.util.UUID.randomUUID().toString();
|
||||||
|
//System.out.println("CallbackServer -- using token "+this.token);
|
||||||
|
|
||||||
while (this.active) {
|
while (this.active) {
|
||||||
//System.out.println("CallbackServer: Waiting for data on socket");
|
//System.out.println("CallbackServer: Waiting for data on socket");
|
||||||
@ -123,40 +186,62 @@ public class CallbackServer implements Runnable {
|
|||||||
BufferedReader xhrReader = new BufferedReader(new InputStreamReader(connection.getInputStream()),40);
|
BufferedReader xhrReader = new BufferedReader(new InputStreamReader(connection.getInputStream()),40);
|
||||||
DataOutputStream output = new DataOutputStream(connection.getOutputStream());
|
DataOutputStream output = new DataOutputStream(connection.getOutputStream());
|
||||||
request = xhrReader.readLine();
|
request = xhrReader.readLine();
|
||||||
//System.out.println("Request="+request);
|
String response = "";
|
||||||
if(request.contains("GET"))
|
//System.out.println("CallbackServerRequest="+request);
|
||||||
{
|
if (this.active && (request != null)) {
|
||||||
//System.out.println(" -- Processing GET request");
|
if (request.contains("GET")) {
|
||||||
|
|
||||||
// Wait until there is some data to send, or send empty data every 30 sec
|
// Get requested file
|
||||||
// to prevent XHR timeout on the client
|
String[] requestParts = request.split(" ");
|
||||||
synchronized (this) {
|
|
||||||
while (this.empty) {
|
// Must have security token
|
||||||
try {
|
if ((requestParts.length == 3) && (requestParts[1].substring(1).equals(this.token))) {
|
||||||
this.wait(30000); // prevent timeout from happening
|
//System.out.println("CallbackServer -- Processing GET request");
|
||||||
//System.out.println(">>> break <<<");
|
|
||||||
break;
|
// Wait until there is some data to send, or send empty data every 10 sec
|
||||||
}
|
// to prevent XHR timeout on the client
|
||||||
catch (Exception e) { }
|
synchronized (this) {
|
||||||
}
|
while (this.empty) {
|
||||||
}
|
try {
|
||||||
|
this.wait(10000); // prevent timeout from happening
|
||||||
// If server is still running
|
//System.out.println("CallbackServer>>> break <<<");
|
||||||
if (this.active) {
|
break;
|
||||||
|
}
|
||||||
// If no data, then send 404 back to client before it times out
|
catch (Exception e) { }
|
||||||
if (this.empty) {
|
}
|
||||||
//System.out.println(" -- sending data 0");
|
}
|
||||||
output.writeBytes("HTTP/1.1 404 NO DATA\r\n\r\n");
|
|
||||||
|
// If server is still running
|
||||||
|
if (this.active) {
|
||||||
|
|
||||||
|
// If no data, then send 404 back to client before it times out
|
||||||
|
if (this.empty) {
|
||||||
|
//System.out.println("CallbackServer -- sending data 0");
|
||||||
|
response = "HTTP/1.1 404 NO DATA\r\n\r\n "; // need to send content otherwise some Android devices fail, so send space
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//System.out.println("CallbackServer -- sending item");
|
||||||
|
response = "HTTP/1.1 200 OK\r\n\r\n"+this.getJavascript();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
response = "HTTP/1.1 503 Service Unavailable\r\n\r\n ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//System.out.println(" -- sending item");
|
response = "HTTP/1.1 403 Forbidden\r\n\r\n ";
|
||||||
output.writeBytes("HTTP/1.1 200 OK\r\n\r\n"+this.getJavascript());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
response = "HTTP/1.1 400 Bad Request\r\n\r\n ";
|
||||||
|
}
|
||||||
|
//System.out.println("CallbackServer: response="+response);
|
||||||
|
//System.out.println("CallbackServer: closing output");
|
||||||
|
output.writeBytes(response);
|
||||||
|
output.flush();
|
||||||
}
|
}
|
||||||
//System.out.println("CallbackServer: closing output");
|
output.close();
|
||||||
output.close();
|
xhrReader.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -171,11 +256,13 @@ public class CallbackServer implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public void stopServer() {
|
public void stopServer() {
|
||||||
//System.out.println("CallbackServer.stopServer()");
|
//System.out.println("CallbackServer.stopServer()");
|
||||||
this.active = false;
|
if (this.active) {
|
||||||
|
this.active = false;
|
||||||
|
|
||||||
// Break out of server wait
|
// Break out of server wait
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
this.notify();
|
this.notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ public class CameraLauncher extends Plugin {
|
|||||||
|
|
||||||
private int mQuality; // Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
|
private int mQuality; // Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
|
||||||
private Uri imageUri; // Uri of captured image
|
private Uri imageUri; // Uri of captured image
|
||||||
|
public String callbackId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -63,6 +64,7 @@ public class CameraLauncher extends Plugin {
|
|||||||
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 = "";
|
||||||
|
this.callbackId = callbackId;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (action.equals("takePicture")) {
|
if (action.equals("takePicture")) {
|
||||||
@ -78,8 +80,11 @@ public class CameraLauncher extends Plugin {
|
|||||||
this.takePicture(args.getInt(0), destType);
|
this.takePicture(args.getInt(0), destType);
|
||||||
}
|
}
|
||||||
else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
|
else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
|
||||||
this.getImage(srcType, destType);
|
this.getImage(args.getInt(0), srcType, destType);
|
||||||
}
|
}
|
||||||
|
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||||
|
r.setKeepCallback(true);
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
return new PluginResult(status, result);
|
return new PluginResult(status, result);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
@ -95,7 +100,7 @@ public class CameraLauncher extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* Take a picture with the camera.
|
* Take a picture with the camera.
|
||||||
* When an image is captured or the camera view is cancelled, the result is returned
|
* When an image is captured or the camera view is cancelled, the result is returned
|
||||||
* in DroidGap.onActivityResult, which forwards the result to this.onActivityResult.
|
* in PhonegapActivity.onActivityResult, which forwards the result to this.onActivityResult.
|
||||||
*
|
*
|
||||||
* The image can either be returned as a base64 string or a URI that points to the file.
|
* The image can either be returned as a base64 string or a URI that points to the file.
|
||||||
* To display base64 string in an img tag, set the source to:
|
* To display base64 string in an img tag, set the source to:
|
||||||
@ -124,10 +129,14 @@ public class CameraLauncher extends Plugin {
|
|||||||
/**
|
/**
|
||||||
* Get image from photo library.
|
* Get image from photo library.
|
||||||
*
|
*
|
||||||
* @param returnType
|
* @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
|
||||||
|
* @param srcType The album to get image from.
|
||||||
|
* @param returnType Set the type of image to return.
|
||||||
*/
|
*/
|
||||||
// TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do!
|
// TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do!
|
||||||
public void getImage(int srcType, int returnType) {
|
public void getImage(int quality, int srcType, int returnType) {
|
||||||
|
this.mQuality = quality;
|
||||||
|
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setType("image/*");
|
intent.setType("image/*");
|
||||||
intent.setAction(Intent.ACTION_GET_CONTENT);
|
intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||||
@ -190,8 +199,11 @@ public class CameraLauncher extends Plugin {
|
|||||||
os.close();
|
os.close();
|
||||||
|
|
||||||
// Send Uri back to JavaScript for viewing image
|
// Send Uri back to JavaScript for viewing image
|
||||||
this.sendJavascript("navigator.camera.success('" + uri.toString() + "');");
|
this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
|
||||||
}
|
}
|
||||||
|
bitmap.recycle();
|
||||||
|
bitmap = null;
|
||||||
|
System.gc();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
this.failPicture("Error capturing image.");
|
this.failPicture("Error capturing image.");
|
||||||
@ -219,6 +231,9 @@ public class CameraLauncher extends Plugin {
|
|||||||
try {
|
try {
|
||||||
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
|
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
|
||||||
this.processPicture(bitmap);
|
this.processPicture(bitmap);
|
||||||
|
bitmap.recycle();
|
||||||
|
bitmap = null;
|
||||||
|
System.gc();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
this.failPicture("Error retrieving image.");
|
this.failPicture("Error retrieving image.");
|
||||||
@ -227,7 +242,7 @@ public class CameraLauncher extends Plugin {
|
|||||||
|
|
||||||
// If sending filename back
|
// If sending filename back
|
||||||
else if (destType == FILE_URI) {
|
else if (destType == FILE_URI) {
|
||||||
this.sendJavascript("navigator.camera.success('" + uri + "');");
|
this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (resultCode == Activity.RESULT_CANCELED) {
|
else if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
@ -251,12 +266,16 @@ public class CameraLauncher extends Plugin {
|
|||||||
byte[] code = jpeg_data.toByteArray();
|
byte[] code = jpeg_data.toByteArray();
|
||||||
byte[] output = Base64.encodeBase64(code);
|
byte[] output = Base64.encodeBase64(code);
|
||||||
String js_out = new String(output);
|
String js_out = new String(output);
|
||||||
this.sendJavascript("navigator.camera.success('" + js_out + "');");
|
this.success(new PluginResult(PluginResult.Status.OK, js_out), this.callbackId);
|
||||||
|
js_out = null;
|
||||||
|
output = null;
|
||||||
|
code = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
catch(Exception e) {
|
||||||
this.failPicture("Error compressing image.");
|
this.failPicture("Error compressing image.");
|
||||||
}
|
}
|
||||||
|
jpeg_data = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -265,6 +284,6 @@ public class CameraLauncher extends Plugin {
|
|||||||
* @param err
|
* @param err
|
||||||
*/
|
*/
|
||||||
public void failPicture(String err) {
|
public void failPicture(String err) {
|
||||||
this.sendJavascript("navigator.camera.error('" + err + "');");
|
this.error(new PluginResult(PluginResult.Status.ERROR, err), this.callbackId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import java.util.List;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
import com.phonegap.api.PhonegapActivity;
|
||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
|
|||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public void setContext(PhonegapActivity ctx) {
|
||||||
super.setContext(ctx);
|
super.setContext(ctx);
|
||||||
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
||||||
}
|
}
|
||||||
|
@ -155,6 +155,9 @@ public abstract class ContactAccessor {
|
|||||||
else if (key.startsWith("urls")) {
|
else if (key.startsWith("urls")) {
|
||||||
map.put("urls", true);
|
map.put("urls", true);
|
||||||
}
|
}
|
||||||
|
else if (key.startsWith("photos")) {
|
||||||
|
map.put("photos", true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (JSONException e) {
|
catch (JSONException e) {
|
||||||
@ -162,11 +165,36 @@ public abstract class ContactAccessor {
|
|||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method to get a string from a JSON object. Saves a
|
||||||
|
* lot of try/catch writing.
|
||||||
|
* If the property is not found in the object null will be returned.
|
||||||
|
*
|
||||||
|
* @param obj contact object to search
|
||||||
|
* @param property to be looked up
|
||||||
|
* @return The value of the property
|
||||||
|
*/
|
||||||
|
protected String getJsonString(JSONObject obj, String property) {
|
||||||
|
String value = null;
|
||||||
|
try {
|
||||||
|
value = obj.getString(property);
|
||||||
|
if (value.equals("null")) {
|
||||||
|
Log.d(LOG_TAG, property + " is string called 'null'");
|
||||||
|
value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (JSONException e) {
|
||||||
|
Log.d(LOG_TAG, "Could not get = " + e.getMessage());
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles adding a JSON Contact object into the database.
|
* Handles adding a JSON Contact object into the database.
|
||||||
|
* @return TODO
|
||||||
*/
|
*/
|
||||||
public abstract void save(JSONObject contact);
|
public abstract boolean save(JSONObject contact);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles searching through SDK-specific contacts API.
|
* Handles searching through SDK-specific contacts API.
|
||||||
|
@ -36,6 +36,7 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
|
import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.Contacts;
|
import android.provider.Contacts;
|
||||||
@ -62,6 +63,7 @@ import android.webkit.WebView;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class ContactAccessorSdk3_4 extends ContactAccessor {
|
public class ContactAccessorSdk3_4 extends ContactAccessor {
|
||||||
|
private static final String PEOPLE_ID_EQUALS = "people._id = ?";
|
||||||
/**
|
/**
|
||||||
* A static map that converts the JavaScript property name to Android database column name.
|
* A static map that converts the JavaScript property name to Android database column name.
|
||||||
*/
|
*/
|
||||||
@ -102,22 +104,28 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
|||||||
*/
|
*/
|
||||||
public JSONArray search(JSONArray fields, JSONObject options) {
|
public JSONArray search(JSONArray fields, JSONObject options) {
|
||||||
String searchTerm = "";
|
String searchTerm = "";
|
||||||
int limit = 1;
|
int limit = Integer.MAX_VALUE;
|
||||||
boolean multiple = false;
|
boolean multiple = true;
|
||||||
try {
|
|
||||||
searchTerm = options.getString("filter");
|
if (options != null) {
|
||||||
|
searchTerm = options.optString("filter");
|
||||||
if (searchTerm.length()==0) {
|
if (searchTerm.length()==0) {
|
||||||
searchTerm = "%";
|
searchTerm = "%";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
searchTerm = "%" + searchTerm + "%";
|
searchTerm = "%" + searchTerm + "%";
|
||||||
}
|
}
|
||||||
multiple = options.getBoolean("multiple");
|
try {
|
||||||
if (multiple) {
|
multiple = options.getBoolean("multiple");
|
||||||
limit = options.getInt("limit");
|
if (!multiple) {
|
||||||
|
limit = 1;
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
// Multiple was not specified so we assume the default is true.
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
}
|
||||||
Log.e(LOG_TAG, e.getMessage(), e);
|
else {
|
||||||
|
searchTerm = "%";
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentResolver cr = mApp.getContentResolver();
|
ContentResolver cr = mApp.getContentResolver();
|
||||||
@ -140,7 +148,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
|||||||
// Do query for name and note
|
// Do query for name and note
|
||||||
Cursor cur = cr.query(People.CONTENT_URI,
|
Cursor cur = cr.query(People.CONTENT_URI,
|
||||||
new String[] {People.DISPLAY_NAME, People.NOTES},
|
new String[] {People.DISPLAY_NAME, People.NOTES},
|
||||||
"people._id = ?",
|
PEOPLE_ID_EQUALS,
|
||||||
new String[] {contactId},
|
new String[] {contactId},
|
||||||
null);
|
null);
|
||||||
cur.moveToFirst();
|
cur.moveToFirst();
|
||||||
@ -305,11 +313,13 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
|||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
im = new JSONObject();
|
im = new JSONObject();
|
||||||
try{
|
try{
|
||||||
im.put("primary", false);
|
im.put("id", cursor.getString(
|
||||||
|
cursor.getColumnIndex(ContactMethods._ID)));
|
||||||
|
im.put("perf", false);
|
||||||
im.put("value", cursor.getString(
|
im.put("value", cursor.getString(
|
||||||
cursor.getColumnIndex(ContactMethodsColumns.DATA)));
|
cursor.getColumnIndex(ContactMethodsColumns.DATA)));
|
||||||
im.put("type", cursor.getString(
|
im.put("type", getContactType(cursor.getInt(
|
||||||
cursor.getColumnIndex(ContactMethodsColumns.TYPE)));
|
cursor.getColumnIndex(ContactMethodsColumns.TYPE))));
|
||||||
ims.put(im);
|
ims.put(im);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(LOG_TAG, e.getMessage(), e);
|
Log.e(LOG_TAG, e.getMessage(), e);
|
||||||
@ -335,13 +345,10 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
|||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
organization = new JSONObject();
|
organization = new JSONObject();
|
||||||
try{
|
try{
|
||||||
|
organization.put("id", cursor.getString(cursor.getColumnIndex(Organizations._ID)));
|
||||||
organization.put("name", cursor.getString(cursor.getColumnIndex(Organizations.COMPANY)));
|
organization.put("name", cursor.getString(cursor.getColumnIndex(Organizations.COMPANY)));
|
||||||
organization.put("title", cursor.getString(cursor.getColumnIndex(Organizations.TITLE)));
|
organization.put("title", cursor.getString(cursor.getColumnIndex(Organizations.TITLE)));
|
||||||
// organization.put("department", cursor.getString(cursor.getColumnIndex(Organizations)));
|
// organization.put("department", cursor.getString(cursor.getColumnIndex(Organizations)));
|
||||||
// organization.put("description", cursor.getString(cursor.getColumnIndex(Organizations)));
|
|
||||||
// organization.put("endDate", cursor.getString(cursor.getColumnIndex(Organizations)));
|
|
||||||
// organization.put("location", cursor.getString(cursor.getColumnIndex(Organizations)));
|
|
||||||
// organization.put("startDate", cursor.getString(cursor.getColumnIndex(Organizations)));
|
|
||||||
organizations.put(organization);
|
organizations.put(organization);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(LOG_TAG, e.getMessage(), e);
|
Log.e(LOG_TAG, e.getMessage(), e);
|
||||||
@ -368,6 +375,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
|||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
address = new JSONObject();
|
address = new JSONObject();
|
||||||
try{
|
try{
|
||||||
|
address.put("id", cursor.getString(cursor.getColumnIndex(ContactMethods._ID)));
|
||||||
address.put("formatted", cursor.getString(cursor.getColumnIndex(ContactMethodsColumns.DATA)));
|
address.put("formatted", cursor.getString(cursor.getColumnIndex(ContactMethodsColumns.DATA)));
|
||||||
addresses.put(address);
|
addresses.put(address);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
@ -394,9 +402,10 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
|||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
phone = new JSONObject();
|
phone = new JSONObject();
|
||||||
try{
|
try{
|
||||||
phone.put("primary", false);
|
phone.put("id", cursor.getString(cursor.getColumnIndex(Phones._ID)));
|
||||||
|
phone.put("perf", false);
|
||||||
phone.put("value", cursor.getString(cursor.getColumnIndex(Phones.NUMBER)));
|
phone.put("value", cursor.getString(cursor.getColumnIndex(Phones.NUMBER)));
|
||||||
phone.put("type", cursor.getString(cursor.getColumnIndex(Phones.TYPE)));
|
phone.put("type", getPhoneType(cursor.getInt(cursor.getColumnIndex(Phones.TYPE))));
|
||||||
phones.put(phone);
|
phones.put(phone);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(LOG_TAG, e.getMessage(), e);
|
Log.e(LOG_TAG, e.getMessage(), e);
|
||||||
@ -422,7 +431,8 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
|||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
email = new JSONObject();
|
email = new JSONObject();
|
||||||
try{
|
try{
|
||||||
email.put("primary", false);
|
email.put("id", cursor.getString(cursor.getColumnIndex(ContactMethods._ID)));
|
||||||
|
email.put("perf", false);
|
||||||
email.put("value", cursor.getString(cursor.getColumnIndex(ContactMethods.DATA)));
|
email.put("value", cursor.getString(cursor.getColumnIndex(ContactMethods.DATA)));
|
||||||
// TODO Find out why adding an email type throws and exception
|
// TODO Find out why adding an email type throws and exception
|
||||||
//email.put("type", cursor.getString(cursor.getColumnIndex(ContactMethods.TYPE)));
|
//email.put("type", cursor.getString(cursor.getColumnIndex(ContactMethods.TYPE)));
|
||||||
@ -434,10 +444,372 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
|||||||
return emails;
|
return emails;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will save a contact object into the devices contacts database.
|
||||||
|
*
|
||||||
|
* @param contact the contact to be saved.
|
||||||
|
* @returns true if the contact is successfully saved, false otherwise.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void save(JSONObject contact) {
|
public boolean save(JSONObject contact) {
|
||||||
// TODO Auto-generated method stub
|
ContentValues personValues = new ContentValues();
|
||||||
|
|
||||||
|
String id = getJsonString(contact, "id");
|
||||||
|
|
||||||
|
String name = getJsonString(contact, "displayName");
|
||||||
|
if (name != null) {
|
||||||
|
personValues.put(Contacts.People.NAME, name);
|
||||||
|
}
|
||||||
|
String note = getJsonString(contact, "note");
|
||||||
|
if (note != null) {
|
||||||
|
personValues.put(Contacts.People.NOTES, note);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* STARRED 0 = Contacts, 1 = Favorites */
|
||||||
|
personValues.put(Contacts.People.STARRED, 0);
|
||||||
|
|
||||||
|
Uri newPersonUri;
|
||||||
|
// Add new contact
|
||||||
|
if (id == null) {
|
||||||
|
newPersonUri = Contacts.People.createPersonInMyContactsGroup(mApp.getContentResolver(), personValues);
|
||||||
|
}
|
||||||
|
// modify existing contact
|
||||||
|
else {
|
||||||
|
newPersonUri = Uri.withAppendedPath(Contacts.People.CONTENT_URI, id);
|
||||||
|
mApp.getContentResolver().update(newPersonUri, personValues, PEOPLE_ID_EQUALS, new String[]{id});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPersonUri != null) {
|
||||||
|
// phoneNumbers
|
||||||
|
savePhoneNumbers(contact, newPersonUri);
|
||||||
|
// emails
|
||||||
|
saveEntries(contact, newPersonUri, "emails", Contacts.KIND_EMAIL);
|
||||||
|
// addresses
|
||||||
|
saveAddresses(contact, newPersonUri);
|
||||||
|
// organizations
|
||||||
|
saveOrganizations(contact, newPersonUri);
|
||||||
|
// ims
|
||||||
|
saveEntries(contact, newPersonUri, "ims", Contacts.KIND_IM);
|
||||||
|
|
||||||
|
// Successfully create a Contact
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a JSON contact object and loops through the available organizations. If the
|
||||||
|
* organization has an id that is not equal to null the organization will be updated in the database.
|
||||||
|
* If the id is null then we treat it as a new organization.
|
||||||
|
*
|
||||||
|
* @param contact the contact to extract the organizations from
|
||||||
|
* @param uri the base URI for this contact.
|
||||||
|
*/
|
||||||
|
private void saveOrganizations(JSONObject contact, Uri newPersonUri) {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
Uri orgUri = Uri.withAppendedPath(newPersonUri,
|
||||||
|
Contacts.Organizations.CONTENT_DIRECTORY);
|
||||||
|
String id = null;
|
||||||
|
try {
|
||||||
|
JSONArray orgs = contact.getJSONArray("organizations");
|
||||||
|
if (orgs != null && orgs.length() > 0) {
|
||||||
|
JSONObject org;
|
||||||
|
for (int i=0; i<orgs.length(); i++) {
|
||||||
|
org = orgs.getJSONObject(i);
|
||||||
|
id = getJsonString(org, "id");
|
||||||
|
values.put(Contacts.Organizations.COMPANY, getJsonString(org, "name"));
|
||||||
|
values.put(Contacts.Organizations.TITLE, getJsonString(org, "title"));
|
||||||
|
if (id == null) {
|
||||||
|
Uri contactUpdate = mApp.getContentResolver().insert(orgUri, values);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Uri tempUri = Uri.withAppendedPath(orgUri, id);
|
||||||
|
mApp.getContentResolver().update(tempUri, values, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (JSONException e) {
|
||||||
|
Log.d(LOG_TAG, "Could not save organizations = " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a JSON contact object and loops through the available addresses. If the
|
||||||
|
* address has an id that is not equal to null the address will be updated in the database.
|
||||||
|
* If the id is null then we treat it as a new address.
|
||||||
|
*
|
||||||
|
* @param contact the contact to extract the addresses from
|
||||||
|
* @param uri the base URI for this contact.
|
||||||
|
*/
|
||||||
|
private void saveAddresses(JSONObject contact, Uri uri) {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
Uri newUri = Uri.withAppendedPath(uri,
|
||||||
|
Contacts.People.ContactMethods.CONTENT_DIRECTORY);
|
||||||
|
String id = null;
|
||||||
|
try {
|
||||||
|
JSONArray entries = contact.getJSONArray("addresses");
|
||||||
|
if (entries != null && entries.length() > 0) {
|
||||||
|
JSONObject entry;
|
||||||
|
values.put(Contacts.ContactMethods.KIND, Contacts.KIND_POSTAL);
|
||||||
|
for (int i=0; i<entries.length(); i++) {
|
||||||
|
entry = entries.getJSONObject(i);
|
||||||
|
id = getJsonString(entry, "id");
|
||||||
|
|
||||||
|
String address = getJsonString(entry, "formatted");
|
||||||
|
if (address != null) {
|
||||||
|
values.put(Contacts.ContactMethods.DATA, address);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
values.put(Contacts.ContactMethods.DATA, createAddressString(entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id == null) {
|
||||||
|
Uri contactUpdate = mApp.getContentResolver().insert(newUri, values);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Uri tempUri = Uri.withAppendedPath(newUri, id);
|
||||||
|
mApp.getContentResolver().update(tempUri, values, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (JSONException e) {
|
||||||
|
Log.d(LOG_TAG, "Could not save address = " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a ContactAddress JSON object and creates a fully
|
||||||
|
* formatted address string.
|
||||||
|
*
|
||||||
|
* @param entry the full address object
|
||||||
|
* @return a formatted address string
|
||||||
|
*/
|
||||||
|
private String createAddressString(JSONObject entry) {
|
||||||
|
StringBuffer buffer = new StringBuffer("");
|
||||||
|
if (getJsonString(entry, "locality") != null ) {
|
||||||
|
buffer.append(getJsonString(entry, "locality"));
|
||||||
|
}
|
||||||
|
if (getJsonString(entry, "region") != null ) {
|
||||||
|
if (buffer.length() > 0 ) {
|
||||||
|
buffer.append(", ");
|
||||||
|
}
|
||||||
|
buffer.append(getJsonString(entry, "region"));
|
||||||
|
}
|
||||||
|
if (getJsonString(entry, "postalCode") != null ) {
|
||||||
|
if (buffer.length() > 0 ) {
|
||||||
|
buffer.append(", ");
|
||||||
|
}
|
||||||
|
buffer.append(getJsonString(entry, "postalCode"));
|
||||||
|
}
|
||||||
|
if (getJsonString(entry, "country") != null ) {
|
||||||
|
if (buffer.length() > 0 ) {
|
||||||
|
buffer.append(", ");
|
||||||
|
}
|
||||||
|
buffer.append(getJsonString(entry, "country"));
|
||||||
|
}
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a JSON contact object and loops through the available entries (Emails/IM's). If the
|
||||||
|
* entry has an id that is not equal to null the entry will be updated in the database.
|
||||||
|
* If the id is null then we treat it as a new entry.
|
||||||
|
*
|
||||||
|
* @param contact the contact to extract the entries from
|
||||||
|
* @param uri the base URI for this contact.
|
||||||
|
*/
|
||||||
|
private void saveEntries(JSONObject contact, Uri uri, String dataType, int contactKind) {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
Uri newUri = Uri.withAppendedPath(uri,
|
||||||
|
Contacts.People.ContactMethods.CONTENT_DIRECTORY);
|
||||||
|
String id = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
JSONArray entries = contact.getJSONArray(dataType);
|
||||||
|
if (entries != null && entries.length() > 0) {
|
||||||
|
JSONObject entry;
|
||||||
|
values.put(Contacts.ContactMethods.KIND, contactKind);
|
||||||
|
for (int i=0; i<entries.length(); i++) {
|
||||||
|
entry = entries.getJSONObject(i);
|
||||||
|
id = getJsonString(entry, "id");
|
||||||
|
values.put(Contacts.ContactMethods.DATA, getJsonString(entry, "value"));
|
||||||
|
values.put(Contacts.ContactMethods.TYPE, getContactType(getJsonString(entry, "type")));
|
||||||
|
if (id==null) {
|
||||||
|
Uri contactUpdate = mApp.getContentResolver().insert(newUri, values);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Uri tempUri = Uri.withAppendedPath(newUri, id);
|
||||||
|
mApp.getContentResolver().update(tempUri, values, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (JSONException e) {
|
||||||
|
Log.d(LOG_TAG, "Could not save " + dataType + " = " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a string from the W3C Contact API to it's Android int value.
|
||||||
|
* @param string
|
||||||
|
* @return Android int value
|
||||||
|
*/
|
||||||
|
private int getContactType(String string) {
|
||||||
|
int type = Contacts.ContactMethods.TYPE_OTHER;
|
||||||
|
if (string!=null) {
|
||||||
|
if ("home".equals(string.toLowerCase())) {
|
||||||
|
return Contacts.ContactMethods.TYPE_HOME;
|
||||||
|
}
|
||||||
|
else if ("work".equals(string.toLowerCase())) {
|
||||||
|
return Contacts.ContactMethods.TYPE_WORK;
|
||||||
|
}
|
||||||
|
else if ("other".equals(string.toLowerCase())) {
|
||||||
|
return Contacts.ContactMethods.TYPE_OTHER;
|
||||||
|
}
|
||||||
|
else if ("custom".equals(string.toLowerCase())) {
|
||||||
|
return Contacts.ContactMethods.TYPE_CUSTOM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getPhoneType converts an Android phone type into a string
|
||||||
|
* @param type
|
||||||
|
* @return phone type as string.
|
||||||
|
*/
|
||||||
|
private String getContactType(int type) {
|
||||||
|
String stringType;
|
||||||
|
switch (type) {
|
||||||
|
case Contacts.ContactMethods.TYPE_CUSTOM:
|
||||||
|
stringType = "custom";
|
||||||
|
break;
|
||||||
|
case Contacts.ContactMethods.TYPE_HOME:
|
||||||
|
stringType = "home";
|
||||||
|
break;
|
||||||
|
case Contacts.ContactMethods.TYPE_WORK:
|
||||||
|
stringType = "work";
|
||||||
|
break;
|
||||||
|
case Contacts.ContactMethods.TYPE_OTHER:
|
||||||
|
default:
|
||||||
|
stringType = "other";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return stringType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a JSON contact object and loops through the available phone numbers. If the phone
|
||||||
|
* number has an id that is not equal to null the phone number will be updated in the database.
|
||||||
|
* If the id is null then we treat it as a new phone number.
|
||||||
|
*
|
||||||
|
* @param contact the contact to extract the phone numbers from
|
||||||
|
* @param uri the base URI for this contact.
|
||||||
|
*/
|
||||||
|
private void savePhoneNumbers(JSONObject contact, Uri uri) {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
Uri phonesUri = Uri.withAppendedPath(uri,
|
||||||
|
Contacts.People.Phones.CONTENT_DIRECTORY);
|
||||||
|
String id = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
JSONArray phones = contact.getJSONArray("phoneNumbers");
|
||||||
|
if (phones != null && phones.length() > 0) {
|
||||||
|
JSONObject phone;
|
||||||
|
for (int i=0; i<phones.length(); i++) {
|
||||||
|
phone = phones.getJSONObject(i);
|
||||||
|
id = getJsonString(phone, "id");
|
||||||
|
values.put(Contacts.Phones.NUMBER, getJsonString(phone, "value"));
|
||||||
|
values.put(Contacts.Phones.TYPE, getPhoneType(getJsonString(phone, "type")));
|
||||||
|
if (id==null) {
|
||||||
|
Uri phoneUpdate = mApp.getContentResolver().insert(phonesUri, values);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Uri newUri = Uri.withAppendedPath(phonesUri, id);
|
||||||
|
mApp.getContentResolver().update(newUri, values, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (JSONException e) {
|
||||||
|
Log.d(LOG_TAG, "Could not save phones = " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a string from the W3C Contact API to it's Android int value.
|
||||||
|
* @param string
|
||||||
|
* @return Android int value
|
||||||
|
*/
|
||||||
|
private int getPhoneType(String string) {
|
||||||
|
int type = Contacts.Phones.TYPE_OTHER;
|
||||||
|
if ("home".equals(string.toLowerCase())) {
|
||||||
|
return Contacts.Phones.TYPE_HOME;
|
||||||
|
}
|
||||||
|
else if ("mobile".equals(string.toLowerCase())) {
|
||||||
|
return Contacts.Phones.TYPE_MOBILE;
|
||||||
|
}
|
||||||
|
else if ("work".equals(string.toLowerCase())) {
|
||||||
|
return Contacts.Phones.TYPE_WORK;
|
||||||
|
}
|
||||||
|
else if ("work fax".equals(string.toLowerCase())) {
|
||||||
|
return Contacts.Phones.TYPE_FAX_WORK;
|
||||||
|
}
|
||||||
|
else if ("home fax".equals(string.toLowerCase())) {
|
||||||
|
return Contacts.Phones.TYPE_FAX_HOME;
|
||||||
|
}
|
||||||
|
else if ("fax".equals(string.toLowerCase())) {
|
||||||
|
return Contacts.Phones.TYPE_FAX_WORK;
|
||||||
|
}
|
||||||
|
else if ("pager".equals(string.toLowerCase())) {
|
||||||
|
return Contacts.Phones.TYPE_PAGER;
|
||||||
|
}
|
||||||
|
else if ("other".equals(string.toLowerCase())) {
|
||||||
|
return Contacts.Phones.TYPE_OTHER;
|
||||||
|
}
|
||||||
|
else if ("custom".equals(string.toLowerCase())) {
|
||||||
|
return Contacts.Phones.TYPE_CUSTOM;
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getPhoneType converts an Android phone type into a string
|
||||||
|
* @param type
|
||||||
|
* @return phone type as string.
|
||||||
|
*/
|
||||||
|
private String getPhoneType(int type) {
|
||||||
|
String stringType;
|
||||||
|
switch (type) {
|
||||||
|
case Contacts.Phones.TYPE_CUSTOM:
|
||||||
|
stringType = "custom";
|
||||||
|
break;
|
||||||
|
case Contacts.Phones.TYPE_FAX_HOME:
|
||||||
|
stringType = "home fax";
|
||||||
|
break;
|
||||||
|
case Contacts.Phones.TYPE_FAX_WORK:
|
||||||
|
stringType = "work fax";
|
||||||
|
break;
|
||||||
|
case Contacts.Phones.TYPE_HOME:
|
||||||
|
stringType = "home";
|
||||||
|
break;
|
||||||
|
case Contacts.Phones.TYPE_MOBILE:
|
||||||
|
stringType = "mobile";
|
||||||
|
break;
|
||||||
|
case Contacts.Phones.TYPE_PAGER:
|
||||||
|
stringType = "pager";
|
||||||
|
break;
|
||||||
|
case Contacts.Phones.TYPE_WORK:
|
||||||
|
stringType = "work";
|
||||||
|
break;
|
||||||
|
case Contacts.Phones.TYPE_OTHER:
|
||||||
|
default:
|
||||||
|
stringType = "custom";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return stringType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -447,7 +819,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
|||||||
*/
|
*/
|
||||||
public boolean remove(String id) {
|
public boolean remove(String id) {
|
||||||
int result = mApp.getContentResolver().delete(People.CONTENT_URI,
|
int result = mApp.getContentResolver().delete(People.CONTENT_URI,
|
||||||
"people._id = ?",
|
PEOPLE_ID_EQUALS,
|
||||||
new String[] {id});
|
new String[] {id});
|
||||||
|
|
||||||
return (result > 0) ? true : false;
|
return (result > 0) ? true : false;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -42,11 +42,11 @@ public class ContactManager extends Plugin {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (action.equals("search")) {
|
if (action.equals("search")) {
|
||||||
JSONArray res = contactAccessor.search(args.getJSONArray(0), args.getJSONObject(1));
|
JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1));
|
||||||
return new PluginResult(status, res);
|
return new PluginResult(status, res, "navigator.service.contacts.cast");
|
||||||
}
|
}
|
||||||
else if (action.equals("save")) {
|
else if (action.equals("save")) {
|
||||||
// TODO Coming soon!
|
return new PluginResult(status, contactAccessor.save(args.getJSONObject(0)));
|
||||||
}
|
}
|
||||||
else if (action.equals("remove")) {
|
else if (action.equals("remove")) {
|
||||||
if (contactAccessor.remove(args.getString(0))) {
|
if (contactAccessor.remove(args.getString(0))) {
|
||||||
|
@ -11,6 +11,7 @@ import java.util.TimeZone;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import com.phonegap.api.PhonegapActivity;
|
||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -19,7 +20,7 @@ import android.telephony.TelephonyManager;
|
|||||||
|
|
||||||
public class Device extends Plugin {
|
public class Device extends Plugin {
|
||||||
|
|
||||||
public static String phonegapVersion = "0.9.2"; // PhoneGap version
|
public static String phonegapVersion = "0.9.4"; // 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
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ public class Device extends Plugin {
|
|||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public void setContext(PhonegapActivity ctx) {
|
||||||
super.setContext(ctx);
|
super.setContext(ctx);
|
||||||
Device.uuid = getUuid();
|
Device.uuid = getUuid();
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import java.io.File;
|
|||||||
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.StatFs;
|
import android.os.StatFs;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides file directory utilities.
|
* This class provides file directory utilities.
|
||||||
@ -21,6 +20,8 @@ import android.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class DirectoryManager {
|
public class DirectoryManager {
|
||||||
|
|
||||||
|
private static final String LOG_TAG = "DirectoryManager";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a file or directory exists.
|
* Determine if a file or directory exists.
|
||||||
*
|
*
|
||||||
@ -36,7 +37,6 @@ public class DirectoryManager {
|
|||||||
File newPath = constructFilePaths(path.toString(), name);
|
File newPath = constructFilePaths(path.toString(), name);
|
||||||
status = newPath.exists();
|
status = newPath.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no SD card
|
// If no SD card
|
||||||
else{
|
else{
|
||||||
status = false;
|
status = false;
|
||||||
@ -72,29 +72,6 @@ public class DirectoryManager {
|
|||||||
return (freeSpace);
|
return (freeSpace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create directory on SD card.
|
|
||||||
*
|
|
||||||
* @param directoryName The name of the directory to create.
|
|
||||||
* @return T=successful, F=failed
|
|
||||||
*/
|
|
||||||
protected static boolean createDirectory(String directoryName) {
|
|
||||||
boolean status;
|
|
||||||
|
|
||||||
// Make sure SD card exists
|
|
||||||
if ((testSaveLocationExists()) && (!directoryName.equals(""))) {
|
|
||||||
File path = Environment.getExternalStorageDirectory();
|
|
||||||
File newPath = constructFilePaths(path.toString(), directoryName);
|
|
||||||
status = newPath.mkdir();
|
|
||||||
status = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no SD card or invalid dir name
|
|
||||||
else {
|
|
||||||
status = false;
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if SD card exists.
|
* Determine if SD card exists.
|
||||||
@ -117,95 +94,6 @@ public class DirectoryManager {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete directory.
|
|
||||||
*
|
|
||||||
* @param fileName The name of the directory to delete
|
|
||||||
* @return T=deleted, F=could not delete
|
|
||||||
*/
|
|
||||||
protected static boolean deleteDirectory(String fileName) {
|
|
||||||
boolean status;
|
|
||||||
SecurityManager checker = new SecurityManager();
|
|
||||||
|
|
||||||
// Make sure SD card exists
|
|
||||||
if ((testSaveLocationExists()) && (!fileName.equals(""))) {
|
|
||||||
File path = Environment.getExternalStorageDirectory();
|
|
||||||
File newPath = constructFilePaths(path.toString(), fileName);
|
|
||||||
checker.checkDelete(newPath.toString());
|
|
||||||
|
|
||||||
// If dir to delete is really a directory
|
|
||||||
if (newPath.isDirectory()) {
|
|
||||||
String[] listfile = newPath.list();
|
|
||||||
|
|
||||||
// Delete all files within the specified directory and then delete the directory
|
|
||||||
try{
|
|
||||||
for (int i=0; i < listfile.length; i++){
|
|
||||||
File deletedFile = new File (newPath.toString()+"/"+listfile[i].toString());
|
|
||||||
deletedFile.delete();
|
|
||||||
}
|
|
||||||
newPath.delete();
|
|
||||||
Log.i("DirectoryManager deleteDirectory", fileName);
|
|
||||||
status = true;
|
|
||||||
}
|
|
||||||
catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
status = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If dir not a directory, then error
|
|
||||||
else {
|
|
||||||
status = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no SD card
|
|
||||||
else {
|
|
||||||
status = false;
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete file.
|
|
||||||
*
|
|
||||||
* @param fileName The name of the file to delete
|
|
||||||
* @return T=deleted, F=not deleted
|
|
||||||
*/
|
|
||||||
protected static boolean deleteFile(String fileName) {
|
|
||||||
boolean status;
|
|
||||||
SecurityManager checker = new SecurityManager();
|
|
||||||
|
|
||||||
// Make sure SD card exists
|
|
||||||
if ((testSaveLocationExists()) && (!fileName.equals(""))) {
|
|
||||||
File path = Environment.getExternalStorageDirectory();
|
|
||||||
File newPath = constructFilePaths(path.toString(), fileName);
|
|
||||||
checker.checkDelete(newPath.toString());
|
|
||||||
|
|
||||||
// If file to delete is really a file
|
|
||||||
if (newPath.isFile()){
|
|
||||||
try {
|
|
||||||
Log.i("DirectoryManager deleteFile", fileName);
|
|
||||||
newPath.delete();
|
|
||||||
status = true;
|
|
||||||
}catch (SecurityException se){
|
|
||||||
se.printStackTrace();
|
|
||||||
status = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If not a file, then error
|
|
||||||
else {
|
|
||||||
status = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no SD card
|
|
||||||
else {
|
|
||||||
status = false;
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new file object from two file paths.
|
* Create a new file object from two file paths.
|
||||||
*
|
*
|
||||||
@ -215,8 +103,12 @@ public class DirectoryManager {
|
|||||||
*/
|
*/
|
||||||
private static File constructFilePaths (String file1, String file2) {
|
private static File constructFilePaths (String file1, String file2) {
|
||||||
File newPath;
|
File newPath;
|
||||||
newPath = new File(file1+"/"+file2);
|
if (file2.startsWith(file1)) {
|
||||||
|
newPath = new File(file2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newPath = new File(file1+"/"+file2);
|
||||||
|
}
|
||||||
return newPath;
|
return newPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
359
framework/src/com/phonegap/FileTransfer.java
Normal file
359
framework/src/com/phonegap/FileTransfer.java
Normal file
@ -0,0 +1,359 @@
|
|||||||
|
/*
|
||||||
|
* 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, IBM Corporation
|
||||||
|
*/
|
||||||
|
package com.phonegap;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.security.cert.CertificateException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import javax.net.ssl.HostnameVerifier;
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.SSLException;
|
||||||
|
import javax.net.ssl.SSLSession;
|
||||||
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
|
import javax.net.ssl.TrustManager;
|
||||||
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.webkit.CookieManager;
|
||||||
|
|
||||||
|
import com.phonegap.api.Plugin;
|
||||||
|
import com.phonegap.api.PluginResult;
|
||||||
|
|
||||||
|
public class FileTransfer extends Plugin {
|
||||||
|
|
||||||
|
private static final String LOG_TAG = "FileUploader";
|
||||||
|
private static final String LINE_START = "--";
|
||||||
|
private static final String LINE_END = "\r\n";
|
||||||
|
private static final String BOUNDRY = "*****";
|
||||||
|
|
||||||
|
public static int FILE_NOT_FOUND_ERR = 1;
|
||||||
|
public static int INVALID_URL_ERR = 2;
|
||||||
|
public static int CONNECTION_ERR = 3;
|
||||||
|
|
||||||
|
private SSLSocketFactory defaultSSLSocketFactory = null;
|
||||||
|
private HostnameVerifier defaultHostnameVerifier = null;
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see com.phonegap.api.Plugin#execute(java.lang.String, org.json.JSONArray, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
|
String file = null;
|
||||||
|
String server = null;
|
||||||
|
try {
|
||||||
|
file = args.getString(0);
|
||||||
|
server = args.getString(1);
|
||||||
|
}
|
||||||
|
catch (JSONException e) {
|
||||||
|
Log.d(LOG_TAG, "Missing filename or server name");
|
||||||
|
return new PluginResult(PluginResult.Status.JSON_EXCEPTION, "Missing filename or server name");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup the options
|
||||||
|
String fileKey = null;
|
||||||
|
String fileName = null;
|
||||||
|
String mimeType = null;
|
||||||
|
|
||||||
|
fileKey = getArgument(args, 2, "file");
|
||||||
|
fileName = getArgument(args, 3, "image.jpg");
|
||||||
|
mimeType = getArgument(args, 4, "image/jpeg");
|
||||||
|
|
||||||
|
try {
|
||||||
|
JSONObject params = args.optJSONObject(5);
|
||||||
|
boolean trustEveryone = args.optBoolean(6);
|
||||||
|
|
||||||
|
if (action.equals("upload")) {
|
||||||
|
FileUploadResult r = upload(file, server, fileKey, fileName, mimeType, params, trustEveryone);
|
||||||
|
Log.d(LOG_TAG, "****** About to return a result from upload");
|
||||||
|
return new PluginResult(PluginResult.Status.OK, r.toJSONObject());
|
||||||
|
} else {
|
||||||
|
return new PluginResult(PluginResult.Status.INVALID_ACTION);
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
Log.e(LOG_TAG, e.getMessage(), e);
|
||||||
|
JSONObject error = createFileUploadError(FILE_NOT_FOUND_ERR);
|
||||||
|
return new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
Log.e(LOG_TAG, e.getMessage(), e);
|
||||||
|
JSONObject error = createFileUploadError(INVALID_URL_ERR);
|
||||||
|
return new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
|
||||||
|
} catch (SSLException e) {
|
||||||
|
Log.e(LOG_TAG, e.getMessage(), e);
|
||||||
|
Log.d(LOG_TAG, "Got my ssl exception!!!");
|
||||||
|
JSONObject error = createFileUploadError(CONNECTION_ERR);
|
||||||
|
return new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(LOG_TAG, e.getMessage(), e);
|
||||||
|
JSONObject error = createFileUploadError(CONNECTION_ERR);
|
||||||
|
return new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e(LOG_TAG, e.getMessage(), e);
|
||||||
|
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// always verify the host - don't check for certificate
|
||||||
|
final static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
|
||||||
|
public boolean verify(String hostname, SSLSession session) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will install a trust manager that will blindly trust all SSL
|
||||||
|
* certificates. The reason this code is being added is to enable developers
|
||||||
|
* to do development using self signed SSL certificates on their web server.
|
||||||
|
*
|
||||||
|
* The standard HttpsURLConnection class will throw an exception on self
|
||||||
|
* signed certificates if this code is not run.
|
||||||
|
*/
|
||||||
|
private void trustAllHosts() {
|
||||||
|
// Create a trust manager that does not validate certificate chains
|
||||||
|
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
|
||||||
|
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||||||
|
return new java.security.cert.X509Certificate[] {};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkClientTrusted(X509Certificate[] chain,
|
||||||
|
String authType) throws CertificateException {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkServerTrusted(X509Certificate[] chain,
|
||||||
|
String authType) throws CertificateException {
|
||||||
|
}
|
||||||
|
} };
|
||||||
|
|
||||||
|
// Install the all-trusting trust manager
|
||||||
|
try {
|
||||||
|
// Backup the current SSL socket factory
|
||||||
|
defaultSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
|
||||||
|
// Install our all trusting manager
|
||||||
|
SSLContext sc = SSLContext.getInstance("TLS");
|
||||||
|
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||||
|
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(LOG_TAG, e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an error object based on the passed in errorCode
|
||||||
|
* @param errorCode the error
|
||||||
|
* @return JSONObject containing the error
|
||||||
|
*/
|
||||||
|
private JSONObject createFileUploadError(int errorCode) {
|
||||||
|
JSONObject error = null;
|
||||||
|
try {
|
||||||
|
error = new JSONObject();
|
||||||
|
error.put("code", errorCode);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e(LOG_TAG, e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method to read a parameter from the list of JSON args.
|
||||||
|
* @param args the args passed to the Plugin
|
||||||
|
* @param position the position to retrieve the arg from
|
||||||
|
* @param defaultString the default to be used if the arg does not exist
|
||||||
|
* @return String with the retrieved value
|
||||||
|
*/
|
||||||
|
private String getArgument(JSONArray args, int position, String defaultString) {
|
||||||
|
String arg = defaultString;
|
||||||
|
if(args.length() >= position) {
|
||||||
|
arg = args.optString(position);
|
||||||
|
if (arg == null || "null".equals(arg)) {
|
||||||
|
arg = defaultString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uploads the specified file to the server URL provided using an HTTP
|
||||||
|
* multipart request.
|
||||||
|
* @param file Full path of the file on the file system
|
||||||
|
* @param server URL of the server to receive the file
|
||||||
|
* @param fileKey Name of file request parameter
|
||||||
|
* @param fileName File name to be used on server
|
||||||
|
* @param mimeType Describes file content type
|
||||||
|
* @param params key:value pairs of user-defined parameters
|
||||||
|
* @return FileUploadResult containing result of upload request
|
||||||
|
*/
|
||||||
|
public FileUploadResult upload(String file, String server, final String fileKey, final String fileName,
|
||||||
|
final String mimeType, JSONObject params, boolean trustEveryone) throws IOException, SSLException {
|
||||||
|
// Create return object
|
||||||
|
FileUploadResult result = new FileUploadResult();
|
||||||
|
|
||||||
|
// Get a input stream of the file on the phone
|
||||||
|
InputStream fileInputStream = getPathFromUri(file);
|
||||||
|
|
||||||
|
HttpURLConnection conn = null;
|
||||||
|
DataOutputStream dos = null;
|
||||||
|
|
||||||
|
int bytesRead, bytesAvailable, bufferSize;
|
||||||
|
long totalBytes;
|
||||||
|
byte[] buffer;
|
||||||
|
int maxBufferSize = 8096;
|
||||||
|
|
||||||
|
//------------------ CLIENT REQUEST
|
||||||
|
// open a URL connection to the server
|
||||||
|
URL url = new URL(server);
|
||||||
|
|
||||||
|
// Open a HTTP connection to the URL based on protocol
|
||||||
|
if (url.getProtocol().toLowerCase().equals("https")) {
|
||||||
|
// Using standard HTTPS connection. Will not allow self signed certificate
|
||||||
|
if (!trustEveryone) {
|
||||||
|
conn = (HttpsURLConnection) url.openConnection();
|
||||||
|
}
|
||||||
|
// Use our HTTPS connection that blindly trusts everyone.
|
||||||
|
// This should only be used in debug environments
|
||||||
|
else {
|
||||||
|
// Setup the HTTPS connection class to trust everyone
|
||||||
|
trustAllHosts();
|
||||||
|
HttpsURLConnection https = (HttpsURLConnection) url.openConnection();
|
||||||
|
// Save the current hostnameVerifier
|
||||||
|
defaultHostnameVerifier = https.getHostnameVerifier();
|
||||||
|
// Setup the connection not to verify hostnames
|
||||||
|
https.setHostnameVerifier(DO_NOT_VERIFY);
|
||||||
|
conn = https;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Return a standard HTTP conneciton
|
||||||
|
else {
|
||||||
|
conn = (HttpURLConnection) url.openConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow Inputs
|
||||||
|
conn.setDoInput(true);
|
||||||
|
|
||||||
|
// Allow Outputs
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
|
||||||
|
// Don't use a cached copy.
|
||||||
|
conn.setUseCaches(false);
|
||||||
|
|
||||||
|
// Use a post method.
|
||||||
|
conn.setRequestMethod("POST");
|
||||||
|
conn.setRequestProperty("Connection", "Keep-Alive");
|
||||||
|
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+BOUNDRY);
|
||||||
|
|
||||||
|
// Set the cookies on the response
|
||||||
|
String cookie = CookieManager.getInstance().getCookie(server);
|
||||||
|
if (cookie != null) {
|
||||||
|
conn.setRequestProperty("Cookie", cookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
dos = new DataOutputStream( conn.getOutputStream() );
|
||||||
|
|
||||||
|
// Send any extra parameters
|
||||||
|
try {
|
||||||
|
for (Iterator iter = params.keys(); iter.hasNext();) {
|
||||||
|
Object key = iter.next();
|
||||||
|
dos.writeBytes(LINE_START + BOUNDRY + LINE_END);
|
||||||
|
dos.writeBytes("Content-Disposition: form-data; name=\"" + key.toString() + "\"; ");
|
||||||
|
dos.writeBytes(LINE_END + LINE_END);
|
||||||
|
dos.writeBytes(params.getString(key.toString()));
|
||||||
|
dos.writeBytes(LINE_END);
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e(LOG_TAG, e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
dos.writeBytes(LINE_START + BOUNDRY + LINE_END);
|
||||||
|
dos.writeBytes("Content-Disposition: form-data; name=\"" + fileKey + "\";" + " filename=\"" + fileName +"\"" + LINE_END);
|
||||||
|
dos.writeBytes("Content-Type: " + mimeType + LINE_END);
|
||||||
|
dos.writeBytes(LINE_END);
|
||||||
|
|
||||||
|
// create a buffer of maximum size
|
||||||
|
bytesAvailable = fileInputStream.available();
|
||||||
|
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
||||||
|
buffer = new byte[bufferSize];
|
||||||
|
|
||||||
|
// read file and write it into form...
|
||||||
|
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
||||||
|
totalBytes = 0;
|
||||||
|
|
||||||
|
while (bytesRead > 0) {
|
||||||
|
totalBytes += bytesRead;
|
||||||
|
result.setBytesSent(totalBytes);
|
||||||
|
dos.write(buffer, 0, bufferSize);
|
||||||
|
bytesAvailable = fileInputStream.available();
|
||||||
|
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
||||||
|
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
// send multipart form data necesssary after file data...
|
||||||
|
dos.writeBytes(LINE_END);
|
||||||
|
dos.writeBytes(LINE_START + BOUNDRY + LINE_START + LINE_END);
|
||||||
|
|
||||||
|
// close streams
|
||||||
|
fileInputStream.close();
|
||||||
|
dos.flush();
|
||||||
|
dos.close();
|
||||||
|
|
||||||
|
//------------------ read the SERVER RESPONSE
|
||||||
|
StringBuffer responseString = new StringBuffer("");
|
||||||
|
DataInputStream inStream = new DataInputStream ( conn.getInputStream() );
|
||||||
|
String line;
|
||||||
|
while (( line = inStream.readLine()) != null) {
|
||||||
|
responseString.append(line);
|
||||||
|
}
|
||||||
|
Log.d(LOG_TAG, "got response from server");
|
||||||
|
Log.d(LOG_TAG, responseString.toString());
|
||||||
|
|
||||||
|
// send request and retrieve response
|
||||||
|
result.setResponseCode(conn.getResponseCode());
|
||||||
|
result.setResponse(responseString.toString());
|
||||||
|
|
||||||
|
inStream.close();
|
||||||
|
conn.disconnect();
|
||||||
|
|
||||||
|
// Revert back to the proper verifier and socket factories
|
||||||
|
if (trustEveryone && url.getProtocol().toLowerCase().equals("https")) {
|
||||||
|
((HttpsURLConnection)conn).setHostnameVerifier(defaultHostnameVerifier);
|
||||||
|
HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLSocketFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an input stream based on file path or content:// uri
|
||||||
|
*
|
||||||
|
* @param path
|
||||||
|
* @return an input stream
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
*/
|
||||||
|
private InputStream getPathFromUri(String path) throws FileNotFoundException {
|
||||||
|
if (path.startsWith("content:")) {
|
||||||
|
Uri uri = Uri.parse(path);
|
||||||
|
return ctx.getContentResolver().openInputStream(uri);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return new FileInputStream(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
framework/src/com/phonegap/FileUploadResult.java
Normal file
52
framework/src/com/phonegap/FileUploadResult.java
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* Copyright (c) 2010, IBM Corporation
|
||||||
|
*/
|
||||||
|
package com.phonegap;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encapsulates the result and/or status of uploading a file to a remote server.
|
||||||
|
*/
|
||||||
|
public class FileUploadResult {
|
||||||
|
|
||||||
|
private long bytesSent = 0; // bytes sent
|
||||||
|
private int responseCode = -1; // HTTP response code
|
||||||
|
private String response = null; // HTTP response
|
||||||
|
|
||||||
|
public long getBytesSent() {
|
||||||
|
return bytesSent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBytesSent(long bytes) {
|
||||||
|
this.bytesSent = bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getResponseCode() {
|
||||||
|
return responseCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResponseCode(int responseCode) {
|
||||||
|
this.responseCode = responseCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResponse() {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResponse(String response) {
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject toJSONObject() throws JSONException {
|
||||||
|
return new JSONObject(
|
||||||
|
"{bytesSent:" + bytesSent +
|
||||||
|
",responseCode:" + responseCode +
|
||||||
|
",response:" + JSONObject.quote(response) + "}");
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -86,7 +86,7 @@ public class GeoListener {
|
|||||||
* @param msg The error message
|
* @param msg The error message
|
||||||
*/
|
*/
|
||||||
void fail(int code, String msg) {
|
void fail(int code, String msg) {
|
||||||
this.broker.sendJavascript("navigator._geo.fail('" + this.id + "', " + ", " + code + ", '" + msg + "');");
|
this.broker.sendJavascript("navigator._geo.fail('" + this.id + "', '" + code + "', '" + msg + "');");
|
||||||
this.stop();
|
this.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.phonegap;
|
package com.phonegap;
|
||||||
|
|
||||||
|
import com.phonegap.api.PhonegapActivity;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
@ -19,7 +21,7 @@ import android.os.Bundle;
|
|||||||
*/
|
*/
|
||||||
public class GpsListener implements LocationListener {
|
public class GpsListener implements LocationListener {
|
||||||
|
|
||||||
private DroidGap mCtx; // DroidGap object
|
private PhonegapActivity mCtx; // PhonegapActivity object
|
||||||
|
|
||||||
private LocationManager mLocMan; // Location manager object
|
private LocationManager mLocMan; // Location manager object
|
||||||
private GeoListener owner; // Geolistener object (parent)
|
private GeoListener owner; // Geolistener object (parent)
|
||||||
@ -35,7 +37,7 @@ public class GpsListener implements LocationListener {
|
|||||||
* @param interval
|
* @param interval
|
||||||
* @param m
|
* @param m
|
||||||
*/
|
*/
|
||||||
public GpsListener(DroidGap ctx, int interval, GeoListener m) {
|
public GpsListener(PhonegapActivity ctx, int interval, GeoListener m) {
|
||||||
this.owner = m;
|
this.owner = m;
|
||||||
this.mCtx = ctx;
|
this.mCtx = ctx;
|
||||||
this.mLocMan = (LocationManager) this.mCtx.getSystemService(Context.LOCATION_SERVICE);
|
this.mLocMan = (LocationManager) this.mCtx.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
1
framework/src/com/phonegap/HttpHandler.java
Normal file → Executable file
1
framework/src/com/phonegap/HttpHandler.java
Normal file → Executable file
@ -62,7 +62,6 @@ public class HttpHandler {
|
|||||||
if (numread <= 0)
|
if (numread <= 0)
|
||||||
break;
|
break;
|
||||||
out.write(buff, 0, numread);
|
out.write(buff, 0, numread);
|
||||||
System.out.println("numread" + numread);
|
|
||||||
i++;
|
i++;
|
||||||
} while (true);
|
} while (true);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.phonegap;
|
package com.phonegap;
|
||||||
|
|
||||||
|
import com.phonegap.api.PhonegapActivity;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
@ -15,7 +17,7 @@ import android.os.Bundle;
|
|||||||
|
|
||||||
public class NetworkListener implements LocationListener {
|
public class NetworkListener implements LocationListener {
|
||||||
|
|
||||||
private DroidGap mCtx; // DroidGap object
|
private PhonegapActivity mCtx; // PhonegapActivity object
|
||||||
|
|
||||||
private LocationManager mLocMan; // Location manager object
|
private LocationManager mLocMan; // Location manager object
|
||||||
private GeoListener owner; // Geolistener object (parent)
|
private GeoListener owner; // Geolistener object (parent)
|
||||||
@ -31,7 +33,7 @@ public class NetworkListener implements LocationListener {
|
|||||||
* @param interval
|
* @param interval
|
||||||
* @param m
|
* @param m
|
||||||
*/
|
*/
|
||||||
public NetworkListener(DroidGap ctx, int interval, GeoListener m) {
|
public NetworkListener(PhonegapActivity ctx, int interval, GeoListener m) {
|
||||||
this.owner = m;
|
this.owner = m;
|
||||||
this.mCtx = ctx;
|
this.mCtx = ctx;
|
||||||
this.mLocMan = (LocationManager) this.mCtx.getSystemService(Context.LOCATION_SERVICE);
|
this.mLocMan = (LocationManager) this.mCtx.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
@ -12,6 +12,7 @@ import org.apache.http.impl.client.DefaultHttpClient;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
import com.phonegap.api.PhonegapActivity;
|
||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ public class NetworkManager extends Plugin {
|
|||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public void setContext(PhonegapActivity ctx) {
|
||||||
super.setContext(ctx);
|
super.setContext(ctx);
|
||||||
this.sockMan = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
|
this.sockMan = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ package com.phonegap;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
|
import com.phonegap.api.PhonegapActivity;
|
||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
@ -55,11 +56,16 @@ public class Notification extends Plugin {
|
|||||||
this.vibrate(args.getLong(0));
|
this.vibrate(args.getLong(0));
|
||||||
}
|
}
|
||||||
else if (action.equals("alert")) {
|
else if (action.equals("alert")) {
|
||||||
this.alert(args.getString(0),args.getString(1),args.getString(2));
|
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")) {
|
else if (action.equals("confirm")) {
|
||||||
int i = this.confirm(args.getString(0),args.getString(1),args.getString(2));
|
this.confirm(args.getString(0),args.getString(1),args.getString(2), callbackId);
|
||||||
return new PluginResult(status, i);
|
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||||
|
r.setKeepCallback(true);
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
else if (action.equals("activityStart")) {
|
else if (action.equals("activityStart")) {
|
||||||
this.activityStart(args.getString(0),args.getString(1));
|
this.activityStart(args.getString(0),args.getString(1));
|
||||||
@ -160,105 +166,99 @@ public class Notification extends Plugin {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds and shows a native Android alert with given Strings
|
* Builds and shows a native Android alert with given Strings
|
||||||
* @param message The message the alert should display
|
* @param message The message the alert should display
|
||||||
* @param title The title of the alert
|
* @param title The title of the alert
|
||||||
* @param buttonLabel The label of the button
|
* @param buttonLabel The label of the button
|
||||||
|
* @param callbackId The callback id
|
||||||
*/
|
*/
|
||||||
public synchronized void alert(String message,String title,String buttonLabel){
|
public synchronized void alert(final String message, final String title, final String buttonLabel, final String callbackId) {
|
||||||
AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx);
|
|
||||||
dlg.setMessage(message);
|
final PhonegapActivity ctx = this.ctx;
|
||||||
dlg.setTitle(title);
|
final Notification notification = this;
|
||||||
dlg.setCancelable(false);
|
|
||||||
dlg.setPositiveButton(buttonLabel,
|
Runnable runnable = new Runnable() {
|
||||||
new AlertDialog.OnClickListener() {
|
public void run() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
dialog.dismiss();
|
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
|
||||||
}
|
dlg.setMessage(message);
|
||||||
});
|
dlg.setTitle(title);
|
||||||
dlg.create();
|
dlg.setCancelable(false);
|
||||||
dlg.show();
|
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.
|
* 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.
|
* 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 message The message the dialog should display
|
||||||
* @param title The title of the dialog
|
* @param title The title of the dialog
|
||||||
* @param buttonLabels A comma separated list of button labels (Up to 3 buttons)
|
* @param buttonLabels A comma separated list of button labels (Up to 3 buttons)
|
||||||
* @return The index of the button clicked (1,2 or 3)
|
* @param callbackId The callback id
|
||||||
*/
|
*/
|
||||||
public synchronized int confirm(final String message, final String title, String buttonLabels) {
|
public synchronized void confirm(final String message, final String title, String buttonLabels, final String callbackId) {
|
||||||
|
|
||||||
// Create dialog on UI thread
|
final PhonegapActivity ctx = this.ctx;
|
||||||
final DroidGap ctx = this.ctx;
|
|
||||||
final Notification notification = this;
|
final Notification notification = this;
|
||||||
final String[] fButtons = buttonLabels.split(",");
|
final String[] fButtons = buttonLabels.split(",");
|
||||||
|
|
||||||
Runnable runnable = new Runnable() {
|
Runnable runnable = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
|
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
|
||||||
dlg.setMessage(message);
|
dlg.setMessage(message);
|
||||||
dlg.setTitle(title);
|
dlg.setTitle(title);
|
||||||
dlg.setCancelable(false);
|
dlg.setCancelable(false);
|
||||||
|
|
||||||
// First button
|
// First button
|
||||||
if (fButtons.length > 0) {
|
if (fButtons.length > 0) {
|
||||||
dlg.setPositiveButton(fButtons[0],
|
dlg.setPositiveButton(fButtons[0],
|
||||||
new AlertDialog.OnClickListener() {
|
new AlertDialog.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
synchronized(notification) {
|
notification.success(new PluginResult(PluginResult.Status.OK, 1), callbackId);
|
||||||
notification.confirmResult = 1;
|
}
|
||||||
notification.notifyAll();
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second button
|
// Second button
|
||||||
if (fButtons.length > 1) {
|
if (fButtons.length > 1) {
|
||||||
dlg.setNeutralButton(fButtons[1],
|
dlg.setNeutralButton(fButtons[1],
|
||||||
new AlertDialog.OnClickListener() {
|
new AlertDialog.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
synchronized(notification) {
|
notification.success(new PluginResult(PluginResult.Status.OK, 2), callbackId);
|
||||||
notification.confirmResult = 2;
|
}
|
||||||
notification.notifyAll();
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Third button
|
// Third button
|
||||||
if (fButtons.length > 2) {
|
if (fButtons.length > 2) {
|
||||||
dlg.setNegativeButton(fButtons[2],
|
dlg.setNegativeButton(fButtons[2],
|
||||||
new AlertDialog.OnClickListener() {
|
new AlertDialog.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
synchronized(notification) {
|
notification.success(new PluginResult(PluginResult.Status.OK, 3), callbackId);
|
||||||
notification.confirmResult = 3;
|
|
||||||
notification.notifyAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
dlg.create();
|
dlg.create();
|
||||||
dlg.show();
|
dlg.show();
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
this.ctx.runOnUiThread(runnable);
|
this.ctx.runOnUiThread(runnable);
|
||||||
|
|
||||||
// Wait for dialog to close
|
|
||||||
synchronized(runnable) {
|
|
||||||
try {
|
|
||||||
this.wait();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.confirmResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -273,7 +273,7 @@ public class Notification extends Plugin {
|
|||||||
this.spinnerDialog = null;
|
this.spinnerDialog = null;
|
||||||
}
|
}
|
||||||
final Notification notification = this;
|
final Notification notification = this;
|
||||||
final DroidGap ctx = this.ctx;
|
final PhonegapActivity ctx = this.ctx;
|
||||||
Runnable runnable = new Runnable() {
|
Runnable runnable = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
notification.spinnerDialog = ProgressDialog.show(ctx, title , message, true, true,
|
notification.spinnerDialog = ProgressDialog.show(ctx, title , message, true, true,
|
||||||
@ -309,7 +309,7 @@ public class Notification extends Plugin {
|
|||||||
this.progressDialog = null;
|
this.progressDialog = null;
|
||||||
}
|
}
|
||||||
final Notification notification = this;
|
final Notification notification = this;
|
||||||
final DroidGap ctx = this.ctx;
|
final PhonegapActivity ctx = this.ctx;
|
||||||
Runnable runnable = new Runnable() {
|
Runnable runnable = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
notification.progressDialog = new ProgressDialog(ctx);
|
notification.progressDialog = new ProgressDialog(ctx);
|
||||||
|
@ -160,24 +160,25 @@ public class Storage extends Plugin {
|
|||||||
*/
|
*/
|
||||||
public void processResults(Cursor cur, String tx_id) {
|
public void processResults(Cursor cur, String tx_id) {
|
||||||
|
|
||||||
|
String result = "[]";
|
||||||
// If query result has rows
|
// If query result has rows
|
||||||
|
|
||||||
if (cur.moveToFirst()) {
|
if (cur.moveToFirst()) {
|
||||||
|
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 result = new JSONObject();
|
JSONObject row = new JSONObject();
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < colCount; ++i) {
|
for (int i = 0; i < colCount; ++i) {
|
||||||
key = cur.getColumnName(i);
|
key = cur.getColumnName(i);
|
||||||
value = cur.getString(i).replace("\"", "\\\""); // must escape " with \" for JavaScript
|
value = cur.getString(i);
|
||||||
result.put(key, value);
|
row.put(key, value);
|
||||||
}
|
}
|
||||||
|
fullresult.put(row);
|
||||||
// Send row back to JavaScript
|
|
||||||
this.sendJavascript("droiddb.addResult('" + result.toString() + "','" + tx_id + "');");
|
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -185,9 +186,11 @@ public class Storage extends Plugin {
|
|||||||
|
|
||||||
} while (cur.moveToNext());
|
} while (cur.moveToNext());
|
||||||
|
|
||||||
|
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 + "');");
|
this.sendJavascript("droiddb.completeQuery('" + tx_id + "', "+result+");");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
framework/src/com/phonegap/TempListener.java
Normal file → Executable file
3
framework/src/com/phonegap/TempListener.java
Normal file → Executable file
@ -11,6 +11,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
|
||||||
|
import com.phonegap.api.PhonegapActivity;
|
||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ public class TempListener extends Plugin implements SensorEventListener {
|
|||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public void setContext(PhonegapActivity ctx) {
|
||||||
super.setContext(ctx);
|
super.setContext(ctx);
|
||||||
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
package com.phonegap.api;
|
package com.phonegap.api;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import com.phonegap.DroidGap;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
@ -43,7 +42,7 @@ public interface IPlugin {
|
|||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
void setContext(DroidGap ctx);
|
void setContext(PhonegapActivity ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the main View of the application, this is the WebView within which
|
* Sets the main View of the application, this is the WebView within which
|
||||||
|
43
framework/src/com/phonegap/api/PhonegapActivity.java
Executable file
43
framework/src/com/phonegap/api/PhonegapActivity.java
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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, IBM Corporation
|
||||||
|
*/
|
||||||
|
package com.phonegap.api;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Phonegap activity abstract class that is extended by DroidGap.
|
||||||
|
* It is used to isolate plugin development, and remove dependency on entire Phonegap library.
|
||||||
|
*/
|
||||||
|
public abstract class PhonegapActivity extends Activity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a class that implements a service.
|
||||||
|
*
|
||||||
|
* @param serviceType
|
||||||
|
* @param className
|
||||||
|
*/
|
||||||
|
abstract public void addService(String serviceType, String className);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send JavaScript statement back to JavaScript.
|
||||||
|
*
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
abstract public void sendJavascript(String statement);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launch an activity for which you would like a result when it finished. When this activity exits,
|
||||||
|
* your onActivityResult() method will be called.
|
||||||
|
*
|
||||||
|
* @param command The command object
|
||||||
|
* @param intent The intent to start
|
||||||
|
* @param requestCode The request code that is passed to callback to identify the activity
|
||||||
|
*/
|
||||||
|
abstract public void startActivityForResult(Plugin command, Intent intent, int requestCode);
|
||||||
|
}
|
@ -8,7 +8,7 @@
|
|||||||
package com.phonegap.api;
|
package com.phonegap.api;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import com.phonegap.DroidGap;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ import android.webkit.WebView;
|
|||||||
public abstract class Plugin implements IPlugin {
|
public abstract class Plugin implements IPlugin {
|
||||||
|
|
||||||
public WebView webView; // WebView object
|
public WebView webView; // WebView object
|
||||||
public DroidGap ctx; // DroidGap object
|
public PhonegapActivity ctx; // PhonegapActivity object
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the request and returns PluginResult.
|
* Executes the request and returns PluginResult.
|
||||||
@ -48,7 +48,7 @@ public abstract class Plugin implements IPlugin {
|
|||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(DroidGap ctx) {
|
public void setContext(PhonegapActivity ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ public abstract class Plugin implements IPlugin {
|
|||||||
* @param statement
|
* @param statement
|
||||||
*/
|
*/
|
||||||
public void sendJavascript(String statement) {
|
public void sendJavascript(String statement) {
|
||||||
this.ctx.callbackServer.sendJavascript(statement);
|
this.ctx.sendJavascript(statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,7 +113,7 @@ public abstract class Plugin implements IPlugin {
|
|||||||
* @param callbackId The callback id used when calling back into JavaScript.
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
*/
|
*/
|
||||||
public void success(PluginResult pluginResult, String callbackId) {
|
public void success(PluginResult pluginResult, String callbackId) {
|
||||||
this.ctx.callbackServer.sendJavascript(pluginResult.toSuccessCallbackString(callbackId));
|
this.ctx.sendJavascript(pluginResult.toSuccessCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -123,6 +123,6 @@ public abstract class Plugin implements IPlugin {
|
|||||||
* @param callbackId The callback id used when calling back into JavaScript.
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
*/
|
*/
|
||||||
public void error(PluginResult pluginResult, String callbackId) {
|
public void error(PluginResult pluginResult, String callbackId) {
|
||||||
this.ctx.callbackServer.sendJavascript(pluginResult.toErrorCallbackString(callbackId));
|
this.ctx.sendJavascript(pluginResult.toErrorCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import com.phonegap.DroidGap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PluginManager is exposed to JavaScript in the PhoneGap WebView.
|
* PluginManager is exposed to JavaScript in the PhoneGap WebView.
|
||||||
@ -27,7 +26,7 @@ public final class PluginManager {
|
|||||||
private HashMap<String, Plugin> plugins = new HashMap<String,Plugin>();
|
private HashMap<String, Plugin> plugins = new HashMap<String,Plugin>();
|
||||||
private HashMap<String, String> services = new HashMap<String,String>();
|
private HashMap<String, String> services = new HashMap<String,String>();
|
||||||
|
|
||||||
private final DroidGap ctx;
|
private final PhonegapActivity ctx;
|
||||||
private final WebView app;
|
private final WebView app;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,8 +35,7 @@ public final class PluginManager {
|
|||||||
* @param app
|
* @param app
|
||||||
* @param ctx
|
* @param ctx
|
||||||
*/
|
*/
|
||||||
public PluginManager(WebView app, DroidGap ctx) {
|
public PluginManager(WebView app, PhonegapActivity ctx) {
|
||||||
System.out.println("PluginManager()");
|
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.app = app;
|
this.app = app;
|
||||||
}
|
}
|
||||||
@ -66,7 +64,6 @@ public final class PluginManager {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public String exec(final String service, final String action, final String callbackId, final String jsonArgs, final boolean async) {
|
public String exec(final String service, final String action, final String callbackId, final String jsonArgs, final boolean async) {
|
||||||
System.out.println("PluginManager.exec("+service+", "+action+", "+callbackId+", "+jsonArgs+", "+async+")");
|
|
||||||
PluginResult cr = null;
|
PluginResult cr = null;
|
||||||
boolean runAsync = async;
|
boolean runAsync = async;
|
||||||
try {
|
try {
|
||||||
@ -78,7 +75,7 @@ public final class PluginManager {
|
|||||||
}
|
}
|
||||||
if (isPhoneGapPlugin(c)) {
|
if (isPhoneGapPlugin(c)) {
|
||||||
final Plugin plugin = this.addPlugin(clazz, c);
|
final Plugin plugin = this.addPlugin(clazz, c);
|
||||||
final DroidGap ctx = this.ctx;
|
final PhonegapActivity ctx = this.ctx;
|
||||||
runAsync = async && !plugin.isSynch(action);
|
runAsync = async && !plugin.isSynch(action);
|
||||||
if (runAsync) {
|
if (runAsync) {
|
||||||
// Run this on a different thread so that this one can return back to JS
|
// Run this on a different thread so that this one can return back to JS
|
||||||
@ -87,10 +84,19 @@ public final class PluginManager {
|
|||||||
try {
|
try {
|
||||||
// Call execute on the plugin so that it can do it's thing
|
// Call execute on the plugin so that it can do it's thing
|
||||||
PluginResult cr = plugin.execute(action, args, callbackId);
|
PluginResult cr = plugin.execute(action, args, callbackId);
|
||||||
// Check the status for 0 (success) or otherwise
|
int status = cr.getStatus();
|
||||||
if (cr.getStatus() == 0) {
|
|
||||||
|
// If no result to be sent and keeping callback, then no need to sent back to JavaScript
|
||||||
|
if ((status == PluginResult.Status.NO_RESULT.ordinal()) && cr.getKeepCallback()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the success (OK, NO_RESULT & !KEEP_CALLBACK)
|
||||||
|
else if ((status == PluginResult.Status.OK.ordinal()) || (status == PluginResult.Status.NO_RESULT.ordinal())) {
|
||||||
ctx.sendJavascript(cr.toSuccessCallbackString(callbackId));
|
ctx.sendJavascript(cr.toSuccessCallbackString(callbackId));
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
// If error
|
||||||
|
else {
|
||||||
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -104,6 +110,11 @@ public final class PluginManager {
|
|||||||
} else {
|
} else {
|
||||||
// Call execute on the plugin so that it can do it's thing
|
// Call execute on the plugin so that it can do it's thing
|
||||||
cr = plugin.execute(action, args, callbackId);
|
cr = plugin.execute(action, args, callbackId);
|
||||||
|
|
||||||
|
// If no result to be sent and keeping callback, then no need to sent back to JavaScript
|
||||||
|
if ((cr.getStatus() == PluginResult.Status.NO_RESULT.ordinal()) && cr.getKeepCallback()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
@ -119,9 +130,6 @@ public final class PluginManager {
|
|||||||
}
|
}
|
||||||
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
if (cr != null) {
|
|
||||||
System.out.println(" -- returning result: "+cr.getJSONString());
|
|
||||||
}
|
|
||||||
return ( cr != null ? cr.getJSONString() : "{ status: 0, message: 'all good' }" );
|
return ( cr != null ? cr.getJSONString() : "{ status: 0, message: 'all good' }" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,11 +191,10 @@ public final class PluginManager {
|
|||||||
if (this.plugins.containsKey(className)) {
|
if (this.plugins.containsKey(className)) {
|
||||||
return this.getPlugin(className);
|
return this.getPlugin(className);
|
||||||
}
|
}
|
||||||
System.out.println("PluginManager.addPlugin("+className+")");
|
|
||||||
try {
|
try {
|
||||||
Plugin plugin = (Plugin)clazz.newInstance();
|
Plugin plugin = (Plugin)clazz.newInstance();
|
||||||
this.plugins.put(className, plugin);
|
this.plugins.put(className, plugin);
|
||||||
plugin.setContext((DroidGap)this.ctx);
|
plugin.setContext(this.ctx);
|
||||||
plugin.setView(this.app);
|
plugin.setView(this.app);
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
@ -219,7 +226,7 @@ public final class PluginManager {
|
|||||||
public void addService(String serviceType, String className) {
|
public void addService(String serviceType, String className) {
|
||||||
this.services.put(serviceType, className);
|
this.services.put(serviceType, className);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the system is about to start resuming a previous activity.
|
* Called when the system is about to start resuming a previous activity.
|
||||||
*/
|
*/
|
||||||
|
@ -10,18 +10,34 @@ package com.phonegap.api;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
public class PluginResult {
|
public class PluginResult {
|
||||||
private final int status;
|
private final int status;
|
||||||
private final String message;
|
private final String message;
|
||||||
|
private boolean keepCallback = false;
|
||||||
|
private String cast = null;
|
||||||
|
|
||||||
public PluginResult(Status status) {
|
public PluginResult(Status status) {
|
||||||
this.status = status.ordinal();
|
this.status = status.ordinal();
|
||||||
this.message = PluginResult.StatusMessages[this.status];
|
this.message = "'" + PluginResult.StatusMessages[this.status] + "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginResult(Status status, String message) {
|
public PluginResult(Status status, String message) {
|
||||||
this.status = status.ordinal();
|
this.status = status.ordinal();
|
||||||
this.message = "'" + message + "'";
|
this.message = JSONObject.quote(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PluginResult(Status status, JSONArray message, String cast) {
|
||||||
|
this.status = status.ordinal();
|
||||||
|
this.message = message.toString();
|
||||||
|
this.cast = cast;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PluginResult(Status status, JSONObject message, String cast) {
|
||||||
|
this.status = status.ordinal();
|
||||||
|
this.message = message.toString();
|
||||||
|
this.cast = cast;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginResult(Status status, JSONArray message) {
|
public PluginResult(Status status, JSONArray message) {
|
||||||
@ -33,21 +49,26 @@ public class PluginResult {
|
|||||||
this.status = status.ordinal();
|
this.status = status.ordinal();
|
||||||
this.message = message.toString();
|
this.message = message.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: BC: Added
|
|
||||||
public PluginResult(Status status, int i) {
|
public PluginResult(Status status, int i) {
|
||||||
this.status = status.ordinal();
|
this.status = status.ordinal();
|
||||||
this.message = ""+i;
|
this.message = ""+i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginResult(Status status, float f) {
|
public PluginResult(Status status, float f) {
|
||||||
this.status = status.ordinal();
|
this.status = status.ordinal();
|
||||||
this.message = ""+f;
|
this.message = ""+f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginResult(Status status, boolean b) {
|
public PluginResult(Status status, boolean b) {
|
||||||
this.status = status.ordinal();
|
this.status = status.ordinal();
|
||||||
this.message = ""+b;
|
this.message = ""+b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setKeepCallback(boolean b) {
|
||||||
|
this.keepCallback = b;
|
||||||
|
}
|
||||||
|
|
||||||
public int getStatus() {
|
public int getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -56,12 +77,24 @@ public class PluginResult {
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getKeepCallback() {
|
||||||
|
return this.keepCallback;
|
||||||
|
}
|
||||||
|
|
||||||
public String getJSONString() {
|
public String getJSONString() {
|
||||||
return "{ status: " + this.getStatus() + ", message: " + this.getMessage() + " }";
|
return "{status:" + this.status + ",message:" + this.message + ",keepCallback:" + this.keepCallback + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toSuccessCallbackString(String callbackId) {
|
public String toSuccessCallbackString(String callbackId) {
|
||||||
return "PhoneGap.callbackSuccess('"+callbackId+"', " + this.getJSONString() + " );";
|
StringBuffer buf = new StringBuffer("");
|
||||||
|
if (cast != null) {
|
||||||
|
buf.append("var temp = "+cast+"("+this.getJSONString() + ");\n");
|
||||||
|
buf.append("PhoneGap.callbackSuccess('"+callbackId+"',temp);");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
buf.append("PhoneGap.callbackSuccess('"+callbackId+"',"+this.getJSONString()+");");
|
||||||
|
}
|
||||||
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toErrorCallbackString(String callbackId) {
|
public String toErrorCallbackString(String callbackId) {
|
||||||
@ -69,6 +102,7 @@ public class PluginResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String[] StatusMessages = new String[] {
|
public static String[] StatusMessages = new String[] {
|
||||||
|
"No result",
|
||||||
"OK",
|
"OK",
|
||||||
"Class not found",
|
"Class not found",
|
||||||
"Illegal access",
|
"Illegal access",
|
||||||
@ -81,6 +115,7 @@ public class PluginResult {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public enum Status {
|
public enum Status {
|
||||||
|
NO_RESULT,
|
||||||
OK,
|
OK,
|
||||||
CLASS_NOT_FOUND_EXCEPTION,
|
CLASS_NOT_FOUND_EXCEPTION,
|
||||||
ILLEGAL_ACCESS_EXCEPTION,
|
ILLEGAL_ACCESS_EXCEPTION,
|
||||||
|
9
framework/src/com/phonegap/file/EncodingException.java
Normal file
9
framework/src/com/phonegap/file/EncodingException.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package com.phonegap.file;
|
||||||
|
|
||||||
|
public class EncodingException extends Exception {
|
||||||
|
|
||||||
|
public EncodingException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
9
framework/src/com/phonegap/file/FileExistsException.java
Normal file
9
framework/src/com/phonegap/file/FileExistsException.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package com.phonegap.file;
|
||||||
|
|
||||||
|
public class FileExistsException extends Exception {
|
||||||
|
|
||||||
|
public FileExistsException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.phonegap.file;
|
||||||
|
|
||||||
|
public class InvalidModificationException extends Exception {
|
||||||
|
|
||||||
|
public InvalidModificationException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.phonegap.file;
|
||||||
|
|
||||||
|
public class NoModificationAllowedException extends Exception {
|
||||||
|
|
||||||
|
public NoModificationAllowedException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.phonegap.file;
|
||||||
|
|
||||||
|
public class TypeMismatchException extends Exception {
|
||||||
|
|
||||||
|
public TypeMismatchException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
lib/classic.rb
Normal file → Executable file
32
lib/classic.rb
Normal file → Executable file
@ -19,9 +19,15 @@ class Classic
|
|||||||
end
|
end
|
||||||
|
|
||||||
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')
|
@icon = File.join(@www, 'icon.png') unless File.exists?(@icon)
|
||||||
|
# Hash that stores the location of icons for each resolution type. Uses the default icon for all resolutions as a baseline.
|
||||||
|
@icons = {
|
||||||
|
:"drawable-ldpi" => @icon,
|
||||||
|
:"drawable-mdpi" => @icon,
|
||||||
|
:"drawable-hdpi" => @icon
|
||||||
|
} if @icons.nil?
|
||||||
@app_js_dir = ''
|
@app_js_dir = ''
|
||||||
@content = 'index.html'
|
@content = 'index.html'
|
||||||
end
|
end
|
||||||
@ -82,11 +88,12 @@ class Classic
|
|||||||
|
|
||||||
# copies stuff from src directory into the android project directory (@path)
|
# copies stuff from src directory into the android project directory (@path)
|
||||||
def copy_libs
|
def copy_libs
|
||||||
|
version = IO.read(File.join(@framework_dir, '../VERSION'))
|
||||||
framework_res_dir = File.join(@framework_dir, "res")
|
framework_res_dir = File.join(@framework_dir, "res")
|
||||||
app_res_dir = File.join(@path, "res")
|
app_res_dir = File.join(@path, "res")
|
||||||
# copies in the jar
|
# copies in the jar
|
||||||
FileUtils.mkdir_p File.join(@path, "libs")
|
FileUtils.mkdir_p File.join(@path, "libs")
|
||||||
FileUtils.cp File.join(@framework_dir, "phonegap.jar"), File.join(@path, "libs")
|
FileUtils.cp File.join(@framework_dir, "phonegap.#{ version }.jar"), File.join(@path, "libs")
|
||||||
# copies in the strings.xml
|
# copies in the strings.xml
|
||||||
FileUtils.mkdir_p File.join(app_res_dir, "values")
|
FileUtils.mkdir_p File.join(app_res_dir, "values")
|
||||||
FileUtils.cp File.join(framework_res_dir, "values","strings.xml"), File.join(app_res_dir, "values", "strings.xml")
|
FileUtils.cp File.join(framework_res_dir, "values","strings.xml"), File.join(app_res_dir, "values", "strings.xml")
|
||||||
@ -96,11 +103,19 @@ class Classic
|
|||||||
FileUtils.cp File.join(framework_res_dir, "layout", f), File.join(app_res_dir, "layout", f)
|
FileUtils.cp File.join(framework_res_dir, "layout", f), File.join(app_res_dir, "layout", f)
|
||||||
end
|
end
|
||||||
# icon file copy
|
# icon file copy
|
||||||
# if it is not in the www directory use the default one in the src dir
|
|
||||||
@icon = File.join(framework_res_dir, "drawable", "icon.png") unless File.exists?(@icon)
|
|
||||||
%w(drawable-hdpi drawable-ldpi drawable-mdpi).each do |e|
|
%w(drawable-hdpi drawable-ldpi drawable-mdpi).each do |e|
|
||||||
|
# if specific resolution icons are specified, use those. if not, see if a general purpose icon was defined.
|
||||||
|
# finally, fall back to using the default PhoneGap one.
|
||||||
|
currentIcon = ""
|
||||||
|
if !@icons[e.to_sym].nil? && File.exists?(File.join(@www, @icons[e.to_sym]))
|
||||||
|
currentIcon = File.join(@www, @icons[e.to_sym])
|
||||||
|
elsif File.exists?(@icon)
|
||||||
|
currentIcon = @icon
|
||||||
|
else
|
||||||
|
currentIcon = File.join(framework_res_dir, "drawable", "icon.png")
|
||||||
|
end
|
||||||
FileUtils.mkdir_p(File.join(app_res_dir, e))
|
FileUtils.mkdir_p(File.join(app_res_dir, e))
|
||||||
FileUtils.cp(@icon, File.join(app_res_dir, e, "icon.png"))
|
FileUtils.cp(currentIcon, File.join(app_res_dir, e, "icon.png"))
|
||||||
end
|
end
|
||||||
# concat JS and put into www folder. this can be overridden in the config.xml via @app_js_dir
|
# concat JS and put into www folder. this can be overridden in the config.xml via @app_js_dir
|
||||||
js_dir = File.join(@framework_dir, "assets", "js")
|
js_dir = File.join(@framework_dir, "assets", "js")
|
||||||
@ -110,7 +125,7 @@ class Classic
|
|||||||
phonegapjs << IO.read(File.join(js_dir, script))
|
phonegapjs << IO.read(File.join(js_dir, script))
|
||||||
phonegapjs << "\n\n"
|
phonegapjs << "\n\n"
|
||||||
end
|
end
|
||||||
File.open(File.join(@path, "assets", "www", @app_js_dir, "phonegap.js"), 'w') {|f| f.write(phonegapjs) }
|
File.open(File.join(@path, "assets", "www", @app_js_dir, "phonegap.#{ version }.js"), 'w') {|f| f.write(phonegapjs) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# puts app name in strings
|
# puts app name in strings
|
||||||
@ -126,8 +141,7 @@ class Classic
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# this is so fucking unholy yet oddly beautiful
|
# create java source file
|
||||||
# not sure if I should thank Ruby or apologize for this abusive use of string interpolation
|
|
||||||
def write_java
|
def write_java
|
||||||
j = "
|
j = "
|
||||||
package #{ @pkg };
|
package #{ @pkg };
|
||||||
|
@ -29,7 +29,7 @@ class Create < Classic
|
|||||||
@content = 'index.html'
|
@content = 'index.html'
|
||||||
|
|
||||||
# stop executation on errors
|
# stop executation on errors
|
||||||
raise 'Expected index.html in the following folder #{ path }.\nThe path is expected to be the directory droidgap create is run from or specified as a command line arg like droidgap create my_path.' unless File.exists? File.join(path, 'index.html')
|
raise "Expected index.html in the following folder #{ path }.\nThe path is expected to be the directory droidgap create is run from or specified as a command line arg like droidgap create my_path." unless File.exists? File.join(path, 'index.html')
|
||||||
raise 'Could not find android in your PATH!' if @android_sdk_path.empty?
|
raise 'Could not find android in your PATH!' if @android_sdk_path.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -40,16 +40,40 @@ class Create < Classic
|
|||||||
if File.exists?(config_file)
|
if File.exists?(config_file)
|
||||||
require 'rexml/document'
|
require 'rexml/document'
|
||||||
f = File.new config_file
|
f = File.new config_file
|
||||||
doc = REXML::Document.new(f)
|
doc = REXML::Document.new(f)
|
||||||
@config = {}
|
@config = {}
|
||||||
@config[:id] = doc.root.attributes["id"]
|
@config[:id] = doc.root.attributes["id"]
|
||||||
@config[:version] = doc.root.attributes["version"]
|
@config[:version] = doc.root.attributes["version"]
|
||||||
|
@config[:icons] = {}
|
||||||
|
defaultIconSize = 0
|
||||||
doc.root.elements.each do |n|
|
doc.root.elements.each do |n|
|
||||||
@config[:name] = n.text.gsub('-','').gsub(' ','') if n.name == 'name'
|
@config[:name] = n.text.gsub('-','').gsub(' ','') if n.name == 'name'
|
||||||
@config[:description] = n.text if n.name == 'description'
|
@config[:description] = n.text if n.name == 'description'
|
||||||
@config[:icon] = n.attributes["src"] if n.name == 'icon'
|
@config[:content] = n.attributes["src"] if n.name == 'content'
|
||||||
@config[:content] = n.attributes["src"] if n.name == 'content'
|
if n.name == 'icon'
|
||||||
|
if n.attributes["width"] == '72' && n.attributes["height"] == '72'
|
||||||
|
@config[:icons]["drawable-hdpi".to_sym] = n.attributes["src"]
|
||||||
|
if 72 > defaultIconSize
|
||||||
|
@config[:icon] = n.attributes["src"]
|
||||||
|
defaultIconSize = 72
|
||||||
|
end
|
||||||
|
elsif n.attributes["width"] == '48' && n.attributes["height"] == '48'
|
||||||
|
@config[:icons]["drawable-mdpi".to_sym] = n.attributes["src"]
|
||||||
|
if 48 > defaultIconSize
|
||||||
|
@config[:icon] = n.attributes["src"]
|
||||||
|
defaultIconSize = 48
|
||||||
|
end
|
||||||
|
elsif n.attributes["width"] == '36' && n.attributes["height"] == '36'
|
||||||
|
@config[:icons]["drawable-ldpi".to_sym] = n.attributes["src"]
|
||||||
|
if 36 > defaultIconSize
|
||||||
|
@config[:icon] = n.attributes["src"]
|
||||||
|
defaultIconSize = 36
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@config[:icon] = n.attributes["src"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
if n.name == "preference" && n.attributes["name"] == 'javascript_folder'
|
if n.name == "preference" && n.attributes["name"] == 'javascript_folder'
|
||||||
@config[:js_dir] = n.attributes["value"]
|
@config[:js_dir] = n.attributes["value"]
|
||||||
@ -62,7 +86,8 @@ class Create < Classic
|
|||||||
# will change the name from the directory to the name element text
|
# will change the name from the directory to the name element text
|
||||||
@name = @config[:name] if @config[:name]
|
@name = @config[:name] if @config[:name]
|
||||||
# set the icon from the config
|
# set the icon from the config
|
||||||
@icon = File.join(@www, @config[:icon])
|
@icon = File.join(@www, @config[:icon]) if @config[:icon]
|
||||||
|
@icons = @config[:icons] if @config[:icons].length > 0
|
||||||
# sets the app js dir where phonegap.js gets copied
|
# sets the app js dir where phonegap.js gets copied
|
||||||
@app_js_dir = @config[:js_dir] ? @config[:js_dir] : ''
|
@app_js_dir = @config[:js_dir] ? @config[:js_dir] : ''
|
||||||
# sets the start page
|
# sets the start page
|
||||||
|
20
lib/update.rb
Normal file → Executable file
20
lib/update.rb
Normal file → Executable file
@ -15,9 +15,9 @@ class Update
|
|||||||
end
|
end
|
||||||
|
|
||||||
# removes local.properties and recreates based on android_sdk_path
|
# removes local.properties and recreates based on android_sdk_path
|
||||||
# then generates framework/phonegap.jar
|
# then generates framework/phonegap.jar & framework/assets/www/phonegap.js
|
||||||
def build_jar
|
def build_jar
|
||||||
puts "Building the JAR..."
|
puts "Building the JAR and combining JS files..."
|
||||||
%w(local.properties phonegap.js phonegap.jar).each do |f|
|
%w(local.properties phonegap.js phonegap.jar).each do |f|
|
||||||
FileUtils.rm File.join(@framework_dir, f) if File.exists? File.join(@framework_dir, f)
|
FileUtils.rm File.join(@framework_dir, f) if File.exists? File.join(@framework_dir, f)
|
||||||
end
|
end
|
||||||
@ -32,23 +32,13 @@ class Update
|
|||||||
# copies stuff from framework into the project
|
# copies stuff from framework into the project
|
||||||
# TODO need to allow for www import inc icon
|
# TODO need to allow for www import inc icon
|
||||||
def copy_libs
|
def copy_libs
|
||||||
puts "Copying over libraries and assets and creating phonegap.js..."
|
puts "Copying over libraries and assets..."
|
||||||
|
|
||||||
FileUtils.mkdir_p File.join(@path, "libs")
|
FileUtils.mkdir_p File.join(@path, "libs")
|
||||||
FileUtils.cp File.join(@framework_dir, "phonegap.jar"), File.join(@path, "libs")
|
FileUtils.cp File.join(@framework_dir, "phonegap.jar"), File.join(@path, "libs")
|
||||||
|
|
||||||
# concat JS and put into www folder.
|
FileUtils.mkdir_p File.join(@path, "assets", "www")
|
||||||
js_dir = File.join(@framework_dir, "assets", "js")
|
FileUtils.cp File.join(@framework_dir, "assets", "www", "phonegap.js"), File.join(@path, "assets", "www")
|
||||||
|
|
||||||
phonegapjs = IO.read(File.join(js_dir, 'phonegap.js.base'))
|
|
||||||
|
|
||||||
Dir.new(js_dir).entries.each do |script|
|
|
||||||
next if script[0].chr == "." or script == "phonegap.js.base"
|
|
||||||
phonegapjs << IO.read(File.join(js_dir, script))
|
|
||||||
phonegapjs << "\n\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
File.open(File.join(@path, "assets", "www", "phonegap.js"), 'w') {|f| f.write(phonegapjs) }
|
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
end
|
end
|
31
util/yuicompressor/LICENSE
Executable file
31
util/yuicompressor/LICENSE
Executable file
@ -0,0 +1,31 @@
|
|||||||
|
YUI is issued by Yahoo! under the BSD License below.
|
||||||
|
|
||||||
|
Copyright (c) 2010, Yahoo! Inc.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use of this software in source and binary forms, with or
|
||||||
|
without modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
* Neither the name of Yahoo! Inc. nor the names of its contributors may be
|
||||||
|
used to endorse or promote products derived from this software without
|
||||||
|
specific prior written permission of Yahoo! Inc.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
http://developer.yahoo.com/yui/license.html
|
||||||
|
|
140
util/yuicompressor/README
Executable file
140
util/yuicompressor/README
Executable file
@ -0,0 +1,140 @@
|
|||||||
|
==============================================================================
|
||||||
|
YUI Compressor
|
||||||
|
==============================================================================
|
||||||
|
|
||||||
|
NAME
|
||||||
|
|
||||||
|
YUI Compressor - The Yahoo! JavaScript and CSS Compressor
|
||||||
|
|
||||||
|
SYNOPSIS
|
||||||
|
|
||||||
|
Usage: java -jar yuicompressor-x.y.z.jar [options] [input file]
|
||||||
|
|
||||||
|
Global Options
|
||||||
|
-h, --help Displays this information
|
||||||
|
--type <js|css> Specifies the type of the input file
|
||||||
|
--charset <charset> Read the input file using <charset>
|
||||||
|
--line-break <column> Insert a line break after the specified column number
|
||||||
|
-v, --verbose Display informational messages and warnings
|
||||||
|
-o <file> Place the output into <file>. Defaults to stdout.
|
||||||
|
|
||||||
|
JavaScript Options
|
||||||
|
--nomunge Minify only, do not obfuscate
|
||||||
|
--preserve-semi Preserve all semicolons
|
||||||
|
--disable-optimizations Disable all micro optimizations
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
|
||||||
|
The YUI Compressor is a JavaScript compressor which, in addition to removing
|
||||||
|
comments and white-spaces, obfuscates local variables using the smallest
|
||||||
|
possible variable name. This obfuscation is safe, even when using constructs
|
||||||
|
such as 'eval' or 'with' (although the compression is not optimal is those
|
||||||
|
cases) Compared to jsmin, the average savings is around 20%.
|
||||||
|
|
||||||
|
The YUI Compressor is also able to safely compress CSS files. The decision
|
||||||
|
on which compressor is being used is made on the file extension (js or css)
|
||||||
|
|
||||||
|
GLOBAL OPTIONS
|
||||||
|
|
||||||
|
-h, --help
|
||||||
|
Prints help on how to use the YUI Compressor
|
||||||
|
|
||||||
|
--line-break
|
||||||
|
Some source control tools don't like files containing lines longer than,
|
||||||
|
say 8000 characters. The linebreak option is used in that case to split
|
||||||
|
long lines after a specific column. It can also be used to make the code
|
||||||
|
more readable, easier to debug (especially with the MS Script Debugger)
|
||||||
|
Specify 0 to get a line break after each semi-colon in JavaScript, and
|
||||||
|
after each rule in CSS.
|
||||||
|
|
||||||
|
--type js|css
|
||||||
|
The type of compressor (JavaScript or CSS) is chosen based on the
|
||||||
|
extension of the input file name (.js or .css) This option is required
|
||||||
|
if no input file has been specified. Otherwise, this option is only
|
||||||
|
required if the input file extension is neither 'js' nor 'css'.
|
||||||
|
|
||||||
|
--charset character-set
|
||||||
|
If a supported character set is specified, the YUI Compressor will use it
|
||||||
|
to read the input file. Otherwise, it will assume that the platform's
|
||||||
|
default character set is being used. The output file is encoded using
|
||||||
|
the same character set.
|
||||||
|
|
||||||
|
-o outfile
|
||||||
|
Place output in file outfile. If not specified, the YUI Compressor will
|
||||||
|
default to the standard output, which you can redirect to a file.
|
||||||
|
|
||||||
|
-v, --verbose
|
||||||
|
Display informational messages and warnings.
|
||||||
|
|
||||||
|
JAVASCRIPT ONLY OPTIONS
|
||||||
|
|
||||||
|
--nomunge
|
||||||
|
Minify only. Do not obfuscate local symbols.
|
||||||
|
|
||||||
|
--preserve-semi
|
||||||
|
Preserve unnecessary semicolons (such as right before a '}') This option
|
||||||
|
is useful when compressed code has to be run through JSLint (which is the
|
||||||
|
case of YUI for example)
|
||||||
|
|
||||||
|
--disable-optimizations
|
||||||
|
Disable all the built-in micro optimizations.
|
||||||
|
|
||||||
|
NOTES
|
||||||
|
|
||||||
|
+ If no input file is specified, it defaults to stdin.
|
||||||
|
|
||||||
|
+ The YUI Compressor requires Java version >= 1.4.
|
||||||
|
|
||||||
|
+ It is possible to prevent a local variable, nested function or function
|
||||||
|
argument from being obfuscated by using "hints". A hint is a string that
|
||||||
|
is located at the very beginning of a function body like so:
|
||||||
|
|
||||||
|
function fn (arg1, arg2, arg3) {
|
||||||
|
"arg2:nomunge, localVar:nomunge, nestedFn:nomunge";
|
||||||
|
|
||||||
|
...
|
||||||
|
var localVar;
|
||||||
|
...
|
||||||
|
|
||||||
|
function nestedFn () {
|
||||||
|
....
|
||||||
|
}
|
||||||
|
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
The hint itself disappears from the compressed file.
|
||||||
|
|
||||||
|
+ C-style comments starting with /*! are preserved. This is useful with
|
||||||
|
comments containing copyright/license information. For example:
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* TERMS OF USE - EASING EQUATIONS
|
||||||
|
* Open source under the BSD License.
|
||||||
|
* Copyright 2001 Robert Penner All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
becomes:
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TERMS OF USE - EASING EQUATIONS
|
||||||
|
* Open source under the BSD License.
|
||||||
|
* Copyright 2001 Robert Penner All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
AUTHOR
|
||||||
|
|
||||||
|
The YUI Compressor was written and is maintained by:
|
||||||
|
Julien Lecomte <jlecomte@yahoo-inc.com>
|
||||||
|
The CSS portion is a port of Isaac Schlueter's cssmin utility.
|
||||||
|
|
||||||
|
COPYRIGHT
|
||||||
|
|
||||||
|
Copyright (c) 2007-2009, Yahoo! Inc. All rights reserved.
|
||||||
|
|
||||||
|
LICENSE
|
||||||
|
|
||||||
|
All code specific to YUI Compressor is issued under a BSD license.
|
||||||
|
YUI Compressor extends and implements code from Mozilla's Rhino project.
|
||||||
|
Rhino is issued under the Mozilla Public License (MPL), and MPL applies
|
||||||
|
to the Rhino source and binaries that are distributed with YUI Compressor.
|
BIN
util/yuicompressor/yuicompressor-2.4.2.jar
Executable file
BIN
util/yuicompressor/yuicompressor-2.4.2.jar
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user