mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 12:03:28 +08:00
Merge branch 'master' of git://github.com/brianleroux/phonegap-android
This commit is contained in:
commit
c4ac7e5383
@ -42,5 +42,5 @@ Importing a PhoneGap/Android app into Eclipse
|
|||||||
|
|
||||||
For more info see
|
For more info see
|
||||||
-----------------
|
-----------------
|
||||||
http://docs.phonegap.com
|
- [http://docs.phonegap.com](http://docs.phonegap.com)
|
||||||
http://wiki.phonegap.com
|
- [http://wiki.phonegap.com](http://wiki.phonegap.com)
|
26
droidgap
26
droidgap
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
|
||||||
|
# ./droidgap /Users/brianleroux/Code/android-sdk-mac MyApp com.westcoastlogic example /Users/brianleroux/Desktop/MyApp
|
||||||
class Build
|
class Build
|
||||||
attr_reader :android_sdk_path, :name, :pkg, :www, :path
|
attr_reader :android_sdk_path, :name, :pkg, :www, :path
|
||||||
|
|
||||||
@ -14,26 +15,24 @@ class Build
|
|||||||
def run
|
def run
|
||||||
build_jar
|
build_jar
|
||||||
create_android
|
create_android
|
||||||
|
include_www
|
||||||
generate_manifest
|
generate_manifest
|
||||||
copy_libs
|
copy_libs
|
||||||
add_name_to_strings
|
add_name_to_strings
|
||||||
write_java
|
write_java
|
||||||
puts "Complete!"
|
puts "Complete!"
|
||||||
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
|
||||||
def build_jar
|
def build_jar
|
||||||
puts "Building the JAR..."
|
puts "Building the JAR..."
|
||||||
|
|
||||||
%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
|
||||||
|
|
||||||
open(File.join(@framework_dir, "local.properties"), 'w') do |f|
|
open(File.join(@framework_dir, "local.properties"), 'w') do |f|
|
||||||
f.puts "sdk.dir=#{ @android_sdk_path }"
|
f.puts "sdk.dir=#{ @android_sdk_path }"
|
||||||
end
|
end
|
||||||
|
|
||||||
Dir.chdir(@framework_dir)
|
Dir.chdir(@framework_dir)
|
||||||
`ant jar`
|
`ant jar`
|
||||||
Dir.chdir(@android_dir)
|
Dir.chdir(@android_dir)
|
||||||
@ -43,11 +42,13 @@ class Build
|
|||||||
# TODO need to allow more flexible SDK targetting
|
# TODO need to allow more flexible SDK targetting
|
||||||
# TODO validate Android SDK
|
# TODO validate Android SDK
|
||||||
def create_android
|
def create_android
|
||||||
puts "Creating Android project..."
|
target_id = 5 # `android list targets` =~ /id:\s*(\d+).*android-5/ ? $1 : 5
|
||||||
|
puts "Creating Android project... #{ target_id }"
|
||||||
target_id = `android list targets` =~ /id:\s*(\d+).*android-5/ ? $1 : 5
|
`android create project -t #{ target_id } -k #{ @pkg } -a #{ @name } -n #{ @name } -p #{ @path }`
|
||||||
|
end
|
||||||
`android create project -t #{target_id} -k #{ @pkg } -a #{ @name } -n #{ @name } -p #{ @path }`
|
|
||||||
|
def include_www
|
||||||
|
puts "Adding www folder to project..."
|
||||||
|
|
||||||
FileUtils.mkdir_p File.join(@path, "assets", "www")
|
FileUtils.mkdir_p File.join(@path, "assets", "www")
|
||||||
FileUtils.cp_r File.join(@www, "."), File.join(@path, "assets", "www")
|
FileUtils.cp_r File.join(@www, "."), File.join(@path, "assets", "www")
|
||||||
@ -98,7 +99,6 @@ class Build
|
|||||||
|
|
||||||
Dir.new(js_dir).entries.each do |script|
|
Dir.new(js_dir).entries.each do |script|
|
||||||
next if script[0].chr == "." or script == "phonegap.js.base"
|
next if script[0].chr == "." or script == "phonegap.js.base"
|
||||||
|
|
||||||
phonegapjs << IO.read(File.join(js_dir, script))
|
phonegapjs << IO.read(File.join(js_dir, script))
|
||||||
phonegapjs << "\n\n"
|
phonegapjs << "\n\n"
|
||||||
end
|
end
|
||||||
@ -123,7 +123,7 @@ class Build
|
|||||||
# this is so fucking unholy yet oddly beautiful
|
# this is so fucking unholy yet oddly beautiful
|
||||||
# not sure if I should thank Ruby or apologize for this abusive use of string interpolation
|
# not sure if I should thank Ruby or apologize for this abusive use of string interpolation
|
||||||
def write_java
|
def write_java
|
||||||
puts "Writing application Java code..."
|
puts "Writing application Java code..."
|
||||||
j = "
|
j = "
|
||||||
package #{ @pkg };
|
package #{ @pkg };
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ else
|
|||||||
name ............... The name of your application.
|
name ............... The name of your application.
|
||||||
package_name ....... The name of your package (For example: com.nitobi.demo)
|
package_name ....... The name of your package (For example: com.nitobi.demo)
|
||||||
www ................ The path to your www folder. (Wherein your HTML, CSS and JS app is.)
|
www ................ The path to your www folder. (Wherein your HTML, CSS and JS app is.)
|
||||||
path ............... The path to generate the application.
|
path ............... The path to generate the Android application.
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
|
@ -72,7 +72,7 @@ PhoneGap.addConstructor = function(func) {
|
|||||||
e.initEvent('deviceready');
|
e.initEvent('deviceready');
|
||||||
document.dispatchEvent(e);
|
document.dispatchEvent(e);
|
||||||
}
|
}
|
||||||
}, 1);
|
}, 5);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
@ -138,10 +138,11 @@ function Acceleration(x, y, z)
|
|||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
|
this.timestamp = new Date().getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to define these for android
|
// Need to define these for android
|
||||||
_accel = {}
|
_accel = {};
|
||||||
_accel.x = 0;
|
_accel.x = 0;
|
||||||
_accel.y = 0;
|
_accel.y = 0;
|
||||||
_accel.z = 0;
|
_accel.z = 0;
|
||||||
@ -355,7 +356,7 @@ PhoneGap.addConstructor(function() {
|
|||||||
if (typeof navigator.compass == "undefined") navigator.compass = new Compass();
|
if (typeof navigator.compass == "undefined") navigator.compass = new Compass();
|
||||||
});
|
});
|
||||||
var Contact = function(){
|
var Contact = function(){
|
||||||
this.name = null;
|
this.name = new ContactName();
|
||||||
this.emails = [];
|
this.emails = [];
|
||||||
this.phones = [];
|
this.phones = [];
|
||||||
}
|
}
|
||||||
@ -393,7 +394,18 @@ Contacts.prototype.find = function(obj, win, fail)
|
|||||||
{
|
{
|
||||||
if(obj.name != null)
|
if(obj.name != null)
|
||||||
{
|
{
|
||||||
ContactHook.search(name, "", "");
|
// Build up the search term that we'll use in SQL, based on the structure/contents of the contact object passed into find.
|
||||||
|
var searchTerm = '';
|
||||||
|
if (obj.name.givenName && obj.name.givenName.length > 0) {
|
||||||
|
searchTerm = obj.name.givenName.split(' ').join('%');
|
||||||
|
}
|
||||||
|
if (obj.name.familyName && obj.name.familyName.length > 0) {
|
||||||
|
searchTerm += obj.name.familyName.split(' ').join('%');
|
||||||
|
}
|
||||||
|
if (!obj.name.familyName && !obj.name.givenName && obj.name.formatted) {
|
||||||
|
searchTerm = obj.name.formatted;
|
||||||
|
}
|
||||||
|
ContactHook.search(searchTerm, "", "");
|
||||||
}
|
}
|
||||||
this.win = win;
|
this.win = win;
|
||||||
this.fail = fail;
|
this.fail = fail;
|
||||||
@ -578,46 +590,12 @@ function Geolocation() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options)
|
||||||
* Asynchronously aquires the current position.
|
{
|
||||||
* @param {Function} successCallback The function to call when the position
|
var position = Geo.getCurrentLocation();
|
||||||
* data is available
|
this.global_success = successCallback;
|
||||||
* @param {Function} errorCallback The function to call when there is an error
|
this.fail = errorCallback;
|
||||||
* getting the position data.
|
}
|
||||||
* @param {PositionOptions} options The options for getting the position data
|
|
||||||
* such as timeout.
|
|
||||||
*/
|
|
||||||
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) {
|
|
||||||
var referenceTime = 0;
|
|
||||||
if (this.lastPosition)
|
|
||||||
referenceTime = this.lastPosition.timeout;
|
|
||||||
else
|
|
||||||
this.start(options);
|
|
||||||
|
|
||||||
var timeout = 20000;
|
|
||||||
var interval = 500;
|
|
||||||
if (typeof(options) == 'object' && options.interval)
|
|
||||||
interval = options.interval;
|
|
||||||
|
|
||||||
if (typeof(successCallback) != 'function')
|
|
||||||
successCallback = function() {};
|
|
||||||
if (typeof(errorCallback) != 'function')
|
|
||||||
errorCallback = function() {};
|
|
||||||
|
|
||||||
var dis = this;
|
|
||||||
var delay = 0;
|
|
||||||
var timer = setInterval(function() {
|
|
||||||
delay += interval;
|
|
||||||
|
|
||||||
if (typeof(dis.lastPosition) == 'object' && dis.lastPosition.timestamp > referenceTime) {
|
|
||||||
successCallback(dis.lastPosition);
|
|
||||||
clearInterval(timer);
|
|
||||||
} else if (delay >= timeout) {
|
|
||||||
errorCallback();
|
|
||||||
clearInterval(timer);
|
|
||||||
}
|
|
||||||
}, interval);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously aquires the position repeatedly at a given interval.
|
* Asynchronously aquires the position repeatedly at a given interval.
|
||||||
@ -675,23 +653,6 @@ Geolocation.prototype.setError = function(message) {
|
|||||||
f(message);
|
f(message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
|
||||||
if (typeof navigator.geolocation == "undefined") navigator.geolocation = new Geolocation();
|
|
||||||
});
|
|
||||||
/*
|
|
||||||
* Since we can't guarantee that we will have the most recent, we just try our best!
|
|
||||||
*
|
|
||||||
* Also, the API doesn't specify which version is the best version of the API
|
|
||||||
*/
|
|
||||||
|
|
||||||
Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options)
|
|
||||||
{
|
|
||||||
var position = Geo.getCurrentLocation();
|
|
||||||
this.global_success = successCallback;
|
|
||||||
this.fail = errorCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Run the global callback
|
// Run the global callback
|
||||||
Geolocation.prototype.gotCurrentPosition = function(lat, lng, alt, altacc, head, vel, stamp)
|
Geolocation.prototype.gotCurrentPosition = function(lat, lng, alt, altacc, head, vel, stamp)
|
||||||
@ -704,6 +665,7 @@ Geolocation.prototype.gotCurrentPosition = function(lat, lng, alt, altacc, head,
|
|||||||
{
|
{
|
||||||
coords = new Coordinates(lat, lng, alt, altacc, head, vel);
|
coords = new Coordinates(lat, lng, alt, altacc, head, vel);
|
||||||
loc = new Position(coords, stamp);
|
loc = new Position(coords, stamp);
|
||||||
|
this.lastPosition = loc;
|
||||||
this.global_success(loc);
|
this.global_success(loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -749,7 +711,19 @@ Geolocation.prototype.clearWatch = function(watchId)
|
|||||||
{
|
{
|
||||||
Geo.stop(watchId);
|
Geo.stop(watchId);
|
||||||
}
|
}
|
||||||
function KeyEvent()
|
// Taken from Jesse's geo fix (similar problem) in PhoneGap iPhone. Go figure, same browser!
|
||||||
|
function __proxyObj(origObj, proxyObj, funkList) {
|
||||||
|
for (var v in funkList) {
|
||||||
|
origObj[funkList[v]] = proxyObj[funkList[v]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PhoneGap.addConstructor(function() {
|
||||||
|
navigator._geo = new Geolocation();
|
||||||
|
__proxyObj(navigator.geolocation, navigator._geo,
|
||||||
|
["setLocation", "getCurrentPosition", "watchPosition",
|
||||||
|
"clearWatch", "setError", "start", "stop", "gotCurrentPosition"]
|
||||||
|
);
|
||||||
|
});function KeyEvent()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,10 +3,11 @@ function Acceleration(x, y, z)
|
|||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
|
this.timestamp = new Date().getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to define these for android
|
// Need to define these for android
|
||||||
_accel = {}
|
_accel = {};
|
||||||
_accel.x = 0;
|
_accel.x = 0;
|
||||||
_accel.y = 0;
|
_accel.y = 0;
|
||||||
_accel.z = 0;
|
_accel.z = 0;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
var Contact = function(){
|
var Contact = function(){
|
||||||
this.name = null;
|
this.name = new ContactName();
|
||||||
this.emails = [];
|
this.emails = [];
|
||||||
this.phones = [];
|
this.phones = [];
|
||||||
}
|
}
|
||||||
@ -37,7 +37,18 @@ Contacts.prototype.find = function(obj, win, fail)
|
|||||||
{
|
{
|
||||||
if(obj.name != null)
|
if(obj.name != null)
|
||||||
{
|
{
|
||||||
ContactHook.search(name, "", "");
|
// Build up the search term that we'll use in SQL, based on the structure/contents of the contact object passed into find.
|
||||||
|
var searchTerm = '';
|
||||||
|
if (obj.name.givenName && obj.name.givenName.length > 0) {
|
||||||
|
searchTerm = obj.name.givenName.split(' ').join('%');
|
||||||
|
}
|
||||||
|
if (obj.name.familyName && obj.name.familyName.length > 0) {
|
||||||
|
searchTerm += obj.name.familyName.split(' ').join('%');
|
||||||
|
}
|
||||||
|
if (!obj.name.familyName && !obj.name.givenName && obj.name.formatted) {
|
||||||
|
searchTerm = obj.name.formatted;
|
||||||
|
}
|
||||||
|
ContactHook.search(searchTerm, "", "");
|
||||||
}
|
}
|
||||||
this.win = win;
|
this.win = win;
|
||||||
this.fail = fail;
|
this.fail = fail;
|
||||||
|
@ -89,6 +89,7 @@ Geolocation.prototype.gotCurrentPosition = function(lat, lng, alt, altacc, head,
|
|||||||
{
|
{
|
||||||
coords = new Coordinates(lat, lng, alt, altacc, head, vel);
|
coords = new Coordinates(lat, lng, alt, altacc, head, vel);
|
||||||
loc = new Position(coords, stamp);
|
loc = new Position(coords, stamp);
|
||||||
|
this.lastPosition = loc;
|
||||||
this.global_success(loc);
|
this.global_success(loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ PhoneGap.addConstructor = function(func) {
|
|||||||
e.initEvent('deviceready');
|
e.initEvent('deviceready');
|
||||||
document.dispatchEvent(e);
|
document.dispatchEvent(e);
|
||||||
}
|
}
|
||||||
}, 1);
|
}, 5);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user