From e01dfec4001c4681f556d8d5ea62492905a49804 Mon Sep 17 00:00:00 2001 From: Brock Whitten Date: Fri, 29 Jan 2010 16:02:20 -0800 Subject: [PATCH 1/8] Hacky fix for GeoLocation on the 2.1 Emulator --- framework/src/com/phonegap/GeoListener.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/framework/src/com/phonegap/GeoListener.java b/framework/src/com/phonegap/GeoListener.java index 98dc3001..45267b6b 100644 --- a/framework/src/com/phonegap/GeoListener.java +++ b/framework/src/com/phonegap/GeoListener.java @@ -2,6 +2,7 @@ package com.phonegap; import android.content.Context; import android.location.Location; +import android.location.LocationManager; import android.webkit.WebView; public class GeoListener { @@ -10,6 +11,7 @@ public class GeoListener { String failCallback; GpsListener mGps; NetworkListener mNetwork; + LocationManager mLocMan; Context mCtx; private WebView mAppView; @@ -20,8 +22,14 @@ public class GeoListener { id = i; interval = time; mCtx = ctx; - mGps = new GpsListener(mCtx, interval, this); - mNetwork = new NetworkListener(mCtx, interval, this); + mGps = null; + mNetwork = null; + mLocMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE); + + if (mLocMan.getProvider(LocationManager.GPS_PROVIDER) != null) + mGps = new GpsListener(mCtx, interval, this); + if (mLocMan.getProvider(LocationManager.NETWORK_PROVIDER) != null) + mNetwork = new NetworkListener(mCtx, interval, this); mAppView = appView; } @@ -63,9 +71,13 @@ public class GeoListener { } public Location getCurrentLocation() { - Location loc = mGps.getLocation(); - if (loc == null) + Location loc = null; + if (mGps != null) + loc = mGps.getLocation(); + if (loc == null && mNetwork != null) loc = mNetwork.getLocation(); + else + loc = new Location(LocationManager.NETWORK_PROVIDER); return loc; } } From 4c0da8e241b579dd2d049e44c358b37cf93671af Mon Sep 17 00:00:00 2001 From: Brock Whitten Date: Wed, 3 Feb 2010 10:27:49 -0800 Subject: [PATCH 2/8] Fixing Build --- framework/build.xml | 60 +++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/framework/build.xml b/framework/build.xml index 8f306c76..ce0af6a5 100644 --- a/framework/build.xml +++ b/framework/build.xml @@ -1,23 +1,23 @@ - + - + - + - + - - - - - + + + + + + classpathref="android.antlibs" /> + and import the build rules files. + The rules file is imported from + /platforms//templates/android_rules.xml + + To customize some build steps for your project: + - copy the content of the main node from android_rules.xml + - paste it in this build.xml below the task. + - disable the import by changing the setup task below to + + This will ensure that the properties are setup correctly but that your customized + build steps are used. + --> - - @@ -75,9 +76,10 @@ - + + From c023c3d8cce4e93cfd5c94ec0c777dfd2e192eb8 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 3 Feb 2010 16:41:39 -0800 Subject: [PATCH 3/8] Updated the Ruby build script so that this shiat works on Windows! --- droidgap | 55 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/droidgap b/droidgap index 2f4d1b06..66a19440 100755 --- a/droidgap +++ b/droidgap @@ -1,31 +1,44 @@ #!/usr/bin/env ruby - +require 'fileutils' class Build - attr_reader :android_sdk_path, :name, :pkg, :www, :path + attr_reader :android_sdk_path, :name, :pkg, :www, :path, :dir def initialize(*a) @android_sdk_path, @name, @pkg, @www, @path = a + @s = File::SEPARATOR + @dir = Dir.pwd + @s end # runs the build script def run + puts "Building the JAR..." build_jar + puts "Creating Android project..." create_android + puts "Generating manifest..." generate_manifest + puts "Copying over libraries and assets..." copy_libs + puts "Adding some application name to strings.xml..." add_name_to_strings + puts "Writing application Java code..." write_java + puts "Complete!" end # removes local.properties and recreates based on android_sdk_path # then generates framework/phonegap.jar def build_jar - `rm framework/local.properties` if File.exists? 'framework/local.properties' - `rm framework/phonegap.jar` if File.exists? 'framework/phonegap.jar' - `rm framework/phonegap.js` if File.exists? 'framework/phonegap.js' - `ECHO 'sdk-location=#{ @android_sdk_path }' > framework/local.properties` - `cd framework; ant jar` - end + FileUtils.rm "#{ @dir }framework#{@s}local.properties" if File.exists? "#{ @dir }framework#{@s}local.properties" + FileUtils.rm "#{ @dir }framework#{@s}phonegap.js" if File.exists? "#{ @dir }framework#{@s}phonegap.js" + FileUtils.rm "#{ @dir }framework#{@s}phonegap.jar" if File.exists? "#{ @dir }framework#{@s}phonegap.jar" + open("#{ @dir }framework#{@s}local.properties", 'w') do |f| + f.puts "sdk.dir=#{ @android_sdk_path }" + end + Dir.chdir(@dir + "framework") + `ant jar` + Dir.chdir(@dir) + end # runs android create project # TODO need to allow more flexible SDK targetting @@ -37,29 +50,29 @@ class Build # creates an AndroidManifest.xml for the project def generate_manifest manifest = "" - open('framework/AndroidManifest.xml', 'r') do |old| + open(@dir + 'framework/AndroidManifest.xml', 'r') do |old| manifest = old.read manifest.gsub! 'android:versionCode="5"', 'android:versionCode="1"' manifest.gsub! 'package="com.phonegap"', "package=\"#{ @pkg }\"" manifest.gsub! 'android:name=".StandAlone"', "android:name=\".#{ @name }\"" manifest.gsub! 'android:minSdkVersion="5"', 'android:minSdkVersion="3"' end - open("#{ @path }/AndroidManifest.xml", 'w') { |x| x.puts manifest } + open("#{ @path }#{@s}AndroidManifest.xml", 'w') { |x| x.puts manifest } end # copies stuff from framework into the project # TODO need to allow for www import inc icon def copy_libs - `mkdir -p #{ @path }/assets/wwww` - `cp framework/phonegap.jar #{ @path }/libs` - `cp framework/res/values/strings.xml #{ @path }/res/values/strings.xml` - `cp framework/res/layout/main.xml #{ @path }/res/layout/main.xml` - `cp framework/res/layout/preview.xml #{ @path }/res/layout/preview.xml` + FileUtils.mkdir_p "#{ @path }#{@s}assets#{@s}www" + FileUtils.cp "#{ @dir }framework#{@s}phonegap.jar", "#{ @path }#{@s}libs" + FileUtils.cp "#{ @dir }framework#{@s}res#{@s}values#{@s}strings.xml", "#{ @path }#{@s}res#{@s}values#{@s}strings.xml" + FileUtils.cp "#{ @dir }framework#{@s}res#{@s}layout#{@s}main.xml", "#{ @path }#{@s}res#{@s}layout#{@s}main.xml" + FileUtils.cp "#{ @dir }framework#{@s}res#{@s}layout#{@s}preview.xml", "#{ @path }#{@s}res#{@s}layout#{@s}preview.xml" %w(drawable-hdpi drawable-ldpi drawable-mdpi).each do |e| - `cp framework/res/drawable/icon.png #{ @path }/res/#{ e }/icon.png` - end - `cp -R example #{ @path }/assets` - `mv #{ @path }/assets/example #{ @path }/assets/www` + FileUtils.cp "#{ @dir }framework#{@s}res#{@s}drawable#{@s}icon.png", "#{ @path }#{@s}res#{@s}#{ e }#{@s}icon.png" + end + FileUtils.cp_r "#{ @www }#{ @s }", "#{ @path }#{ @s }assets#{ @s }" + FileUtils.mv "#{ @path }#{ @s }assets#{ @s }#{ @www }", "#{ @path }#{ @s }assets#{ @s }www" end # puts app name in strings @@ -70,7 +83,7 @@ class Build Snap " - open("#{ @path }/res/values/strings.xml", 'w') do |f| + open("#{ @path }#{@s}res#{@s}values#{@s}strings.xml", 'w') do |f| f.puts x.gsub(' ','') end end @@ -95,7 +108,7 @@ class Build } } " - dir = "#{ @path }/src/#{ @pkg.gsub '.', '/' }"; + dir = "#{ @path }#{@s}src#{@s}#{ @pkg.gsub '.', '/' }"; cls = "#{ @name }.java" pth = File.join(dir,cls) open(pth,'w') { |f| f.puts j.gsub(' ','') } From 3862632af1dbcdb1dae081abb77dbb0400843c00 Mon Sep 17 00:00:00 2001 From: Thorsten Rinne Date: Wed, 10 Feb 2010 08:19:36 +0100 Subject: [PATCH 4/8] Fixed paths and project generation --- droidgap | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/droidgap b/droidgap index 2f4d1b06..74c94ca5 100755 --- a/droidgap +++ b/droidgap @@ -23,7 +23,7 @@ class Build `rm framework/local.properties` if File.exists? 'framework/local.properties' `rm framework/phonegap.jar` if File.exists? 'framework/phonegap.jar' `rm framework/phonegap.js` if File.exists? 'framework/phonegap.js' - `ECHO 'sdk-location=#{ @android_sdk_path }' > framework/local.properties` + `ECHO 'sdk.dir=#{ @android_sdk_path }' > framework/local.properties` `cd framework; ant jar` end @@ -31,7 +31,9 @@ class Build # TODO need to allow more flexible SDK targetting # TODO validate Android SDK def create_android - `android create project -t 5 -k #{ @pkg } -a #{ @name } -n #{ @name } -p #{ @path }` + `#{ @android_sdk_path }/tools/android create project -t 5 -k #{ @pkg } -a #{ @name } -n #{ @name } -p #{ @path }` + `mkdir -p #{ @path }/assets/www` + `cp -R #{ @www } #{ @path }/assets/www` end # creates an AndroidManifest.xml for the project @@ -50,7 +52,6 @@ class Build # copies stuff from framework into the project # TODO need to allow for www import inc icon def copy_libs - `mkdir -p #{ @path }/assets/wwww` `cp framework/phonegap.jar #{ @path }/libs` `cp framework/res/values/strings.xml #{ @path }/res/values/strings.xml` `cp framework/res/layout/main.xml #{ @path }/res/layout/main.xml` From edd0a2caf6939d1de61ed00af45a898d43f24f8b Mon Sep 17 00:00:00 2001 From: filmaj Date: Wed, 10 Feb 2010 13:09:39 -0800 Subject: [PATCH 5/8] Updated build file after mergin in thorstens changes. --- droidgap | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/droidgap b/droidgap index 92843aa2..a7094cd8 100755 --- a/droidgap +++ b/droidgap @@ -29,7 +29,6 @@ class Build # removes local.properties and recreates based on android_sdk_path # then generates framework/phonegap.jar def build_jar -<<<<<<< HEAD FileUtils.rm "#{ @dir }framework#{@s}local.properties" if File.exists? "#{ @dir }framework#{@s}local.properties" FileUtils.rm "#{ @dir }framework#{@s}phonegap.js" if File.exists? "#{ @dir }framework#{@s}phonegap.js" FileUtils.rm "#{ @dir }framework#{@s}phonegap.jar" if File.exists? "#{ @dir }framework#{@s}phonegap.jar" @@ -40,22 +39,14 @@ class Build `ant jar` Dir.chdir(@dir) end -======= - `rm framework/local.properties` if File.exists? 'framework/local.properties' - `rm framework/phonegap.jar` if File.exists? 'framework/phonegap.jar' - `rm framework/phonegap.js` if File.exists? 'framework/phonegap.js' - `ECHO 'sdk.dir=#{ @android_sdk_path }' > framework/local.properties` - `cd framework; ant jar` - end ->>>>>>> 3862632af1dbcdb1dae081abb77dbb0400843c00 # runs android create project # TODO need to allow more flexible SDK targetting # TODO validate Android SDK def create_android - `#{ @android_sdk_path }/tools/android create project -t 5 -k #{ @pkg } -a #{ @name } -n #{ @name } -p #{ @path }` - `mkdir -p #{ @path }/assets/www` - `cp -R #{ @www } #{ @path }/assets/www` + `android create project -t 5 -k #{ @pkg } -a #{ @name } -n #{ @name } -p #{ @path }` + FileUtils.mkdir_p "#{ @path }#{@s}assets#{@s}www" + FileUtils.cp_r "#{ @www }#{ @s }.", "#{ @path }#{ @s }assets#{ @s }www#{ @s }" end # creates an AndroidManifest.xml for the project @@ -74,23 +65,13 @@ class Build # copies stuff from framework into the project # TODO need to allow for www import inc icon def copy_libs -<<<<<<< HEAD - FileUtils.mkdir_p "#{ @path }#{@s}assets#{@s}www" FileUtils.cp "#{ @dir }framework#{@s}phonegap.jar", "#{ @path }#{@s}libs" FileUtils.cp "#{ @dir }framework#{@s}res#{@s}values#{@s}strings.xml", "#{ @path }#{@s}res#{@s}values#{@s}strings.xml" FileUtils.cp "#{ @dir }framework#{@s}res#{@s}layout#{@s}main.xml", "#{ @path }#{@s}res#{@s}layout#{@s}main.xml" FileUtils.cp "#{ @dir }framework#{@s}res#{@s}layout#{@s}preview.xml", "#{ @path }#{@s}res#{@s}layout#{@s}preview.xml" -======= - `cp framework/phonegap.jar #{ @path }/libs` - `cp framework/res/values/strings.xml #{ @path }/res/values/strings.xml` - `cp framework/res/layout/main.xml #{ @path }/res/layout/main.xml` - `cp framework/res/layout/preview.xml #{ @path }/res/layout/preview.xml` ->>>>>>> 3862632af1dbcdb1dae081abb77dbb0400843c00 %w(drawable-hdpi drawable-ldpi drawable-mdpi).each do |e| FileUtils.cp "#{ @dir }framework#{@s}res#{@s}drawable#{@s}icon.png", "#{ @path }#{@s}res#{@s}#{ e }#{@s}icon.png" end - FileUtils.cp_r "#{ @www }#{ @s }", "#{ @path }#{ @s }assets#{ @s }" - FileUtils.mv "#{ @path }#{ @s }assets#{ @s }#{ @www }", "#{ @path }#{ @s }assets#{ @s }www" end # puts app name in strings From 0c585b741635c383f9e455987b5c1212ae84b566 Mon Sep 17 00:00:00 2001 From: filmaj Date: Sat, 13 Feb 2010 15:01:10 -0800 Subject: [PATCH 6/8] Added JS concatenation and copy over to assets/www to build script. --- droidgap | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/droidgap b/droidgap index a7094cd8..4efc8e92 100755 --- a/droidgap +++ b/droidgap @@ -1,5 +1,6 @@ #!/usr/bin/env ruby require 'fileutils' + class Build attr_reader :android_sdk_path, :name, :pkg, :www, :path, :dir @@ -11,17 +12,11 @@ class Build # runs the build script def run - puts "Building the JAR..." build_jar - puts "Creating Android project..." create_android - puts "Generating manifest..." generate_manifest - puts "Copying over libraries and assets..." copy_libs - puts "Adding some application name to strings.xml..." add_name_to_strings - puts "Writing application Java code..." write_java puts "Complete!" end @@ -29,6 +24,7 @@ class Build # removes local.properties and recreates based on android_sdk_path # then generates framework/phonegap.jar def build_jar + puts "Building the JAR..." FileUtils.rm "#{ @dir }framework#{@s}local.properties" if File.exists? "#{ @dir }framework#{@s}local.properties" FileUtils.rm "#{ @dir }framework#{@s}phonegap.js" if File.exists? "#{ @dir }framework#{@s}phonegap.js" FileUtils.rm "#{ @dir }framework#{@s}phonegap.jar" if File.exists? "#{ @dir }framework#{@s}phonegap.jar" @@ -44,6 +40,7 @@ class Build # TODO need to allow more flexible SDK targetting # TODO validate Android SDK def create_android + puts "Creating Android project..." `android create project -t 5 -k #{ @pkg } -a #{ @name } -n #{ @name } -p #{ @path }` FileUtils.mkdir_p "#{ @path }#{@s}assets#{@s}www" FileUtils.cp_r "#{ @www }#{ @s }.", "#{ @path }#{ @s }assets#{ @s }www#{ @s }" @@ -51,13 +48,14 @@ class Build # creates an AndroidManifest.xml for the project def generate_manifest + puts "Generating manifest..." manifest = "" open(@dir + 'framework/AndroidManifest.xml', 'r') do |old| - manifest = old.read - manifest.gsub! 'android:versionCode="5"', 'android:versionCode="1"' - manifest.gsub! 'package="com.phonegap"', "package=\"#{ @pkg }\"" - manifest.gsub! 'android:name=".StandAlone"', "android:name=\".#{ @name }\"" - manifest.gsub! 'android:minSdkVersion="5"', 'android:minSdkVersion="3"' + manifest = old.read + manifest.gsub! 'android:versionCode="5"', 'android:versionCode="1"' + manifest.gsub! 'package="com.phonegap"', "package=\"#{ @pkg }\"" + manifest.gsub! 'android:name=".StandAlone"', "android:name=\".#{ @name }\"" + manifest.gsub! 'android:minSdkVersion="5"', 'android:minSdkVersion="3"' end open("#{ @path }#{@s}AndroidManifest.xml", 'w') { |x| x.puts manifest } end @@ -65,17 +63,31 @@ class Build # copies stuff from framework into the project # TODO need to allow for www import inc icon def copy_libs + puts "Copying over libraries and assets and creating phonegap.js..." FileUtils.cp "#{ @dir }framework#{@s}phonegap.jar", "#{ @path }#{@s}libs" FileUtils.cp "#{ @dir }framework#{@s}res#{@s}values#{@s}strings.xml", "#{ @path }#{@s}res#{@s}values#{@s}strings.xml" FileUtils.cp "#{ @dir }framework#{@s}res#{@s}layout#{@s}main.xml", "#{ @path }#{@s}res#{@s}layout#{@s}main.xml" FileUtils.cp "#{ @dir }framework#{@s}res#{@s}layout#{@s}preview.xml", "#{ @path }#{@s}res#{@s}layout#{@s}preview.xml" %w(drawable-hdpi drawable-ldpi drawable-mdpi).each do |e| - FileUtils.cp "#{ @dir }framework#{@s}res#{@s}drawable#{@s}icon.png", "#{ @path }#{@s}res#{@s}#{ e }#{@s}icon.png" + FileUtils.cp "#{ @dir }framework#{@s}res#{@s}drawable#{@s}icon.png", "#{ @path }#{@s}res#{@s}#{ e }#{@s}icon.png" end + # concat JS and put into www folder. + Dir.chdir("#{ @dir }framework#{ @s }assets#{ @s }js") + basedir = "." + js = Dir.new(basedir).entries + phonegapjs = "" + js.each do |script| + next if script[0].chr == "." + phonegapjs += IO.read(script) + phonegapjs += "\n\n" + end + Dir.chdir("#{ @dir}") + File.open("#{ @path }#{ @s }assets#{ @s }www#{ @s }phonegap.js", 'w') {|f| f.write(phonegapjs) } end # puts app name in strings def add_name_to_strings + puts "Adding some application name to strings.xml..." x = " #{ @name } @@ -90,6 +102,7 @@ class Build # this is so fucking unholy yet oddly beautiful # not sure if I should thank Ruby or apologize for this abusive use of string interpolation def write_java + puts "Writing application Java code..." j = " package #{ @pkg }; From 5255f632377c36beb0b4d2620940f33b6d02b2c7 Mon Sep 17 00:00:00 2001 From: filmaj Date: Sat, 13 Feb 2010 17:09:02 -0800 Subject: [PATCH 7/8] Fixed building of phonegap.js in build script. Fixed GPS on Android 2.0+ - I guess they updated the version of WebKit being used on Android (similar now to how it works on iPhone) and thus the browser has a native navigator.geolocation object. Employed Jesse`s approach to proxying an object`s method since we can`t directly overwrite it. --- droidgap | 4 +- framework/assets/js/geolocation.js | 76 ++++++++---------------------- 2 files changed, 21 insertions(+), 59 deletions(-) diff --git a/droidgap b/droidgap index 4efc8e92..86a7469c 100755 --- a/droidgap +++ b/droidgap @@ -75,9 +75,9 @@ class Build Dir.chdir("#{ @dir }framework#{ @s }assets#{ @s }js") basedir = "." js = Dir.new(basedir).entries - phonegapjs = "" + phonegapjs = IO.read('phonegap.js.base'); js.each do |script| - next if script[0].chr == "." + next if script[0].chr == "." or script == "phonegap.js.base" phonegapjs += IO.read(script) phonegapjs += "\n\n" end diff --git a/framework/assets/js/geolocation.js b/framework/assets/js/geolocation.js index e16fccfe..b9b4ac68 100644 --- a/framework/assets/js/geolocation.js +++ b/framework/assets/js/geolocation.js @@ -14,46 +14,12 @@ function Geolocation() { }; }; -/** - * Asynchronously aquires the current position. - * @param {Function} successCallback The function to call when the position - * data is available - * @param {Function} errorCallback The function to call when there is an error - * 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); -}; +Geolocation.prototype.getCurrentPosition = function(successCallback, errorCallback, options) +{ + var position = Geo.getCurrentLocation(); + this.global_success = successCallback; + this.fail = errorCallback; +} /** * Asynchronously aquires the position repeatedly at a given interval. @@ -111,23 +77,6 @@ Geolocation.prototype.setError = function(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 Geolocation.prototype.gotCurrentPosition = function(lat, lng, alt, altacc, head, vel, stamp) @@ -185,3 +134,16 @@ Geolocation.prototype.clearWatch = function(watchId) { Geo.stop(watchId); } +// 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"] + ); +}); \ No newline at end of file From 76a8203176132684b61be30b9d9ad4d2f29c39be Mon Sep 17 00:00:00 2001 From: filmaj Date: Sat, 13 Feb 2010 18:58:45 -0800 Subject: [PATCH 8/8] Fixed small contacts and accelerometer object instantiation bugs. Added a bit more delay to PhoneGap constructor, 1ms caused issues sometimes I *think*. --- framework/assets/js/accelerometer.js | 3 ++- framework/assets/js/contact.js | 15 +++++++++++++-- framework/assets/js/geolocation.js | 1 + framework/assets/js/phonegap.js.base | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/framework/assets/js/accelerometer.js b/framework/assets/js/accelerometer.js index d0b40a6b..f6820157 100644 --- a/framework/assets/js/accelerometer.js +++ b/framework/assets/js/accelerometer.js @@ -3,10 +3,11 @@ function Acceleration(x, y, z) this.x = x; this.y = y; this.z = z; + this.timestamp = new Date().getTime(); } // Need to define these for android -_accel = {} +_accel = {}; _accel.x = 0; _accel.y = 0; _accel.z = 0; diff --git a/framework/assets/js/contact.js b/framework/assets/js/contact.js index 402b21cf..30e26a6d 100644 --- a/framework/assets/js/contact.js +++ b/framework/assets/js/contact.js @@ -1,5 +1,5 @@ var Contact = function(){ - this.name = null; + this.name = new ContactName(); this.emails = []; this.phones = []; } @@ -37,7 +37,18 @@ Contacts.prototype.find = function(obj, win, fail) { 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.fail = fail; diff --git a/framework/assets/js/geolocation.js b/framework/assets/js/geolocation.js index b9b4ac68..df942251 100644 --- a/framework/assets/js/geolocation.js +++ b/framework/assets/js/geolocation.js @@ -89,6 +89,7 @@ Geolocation.prototype.gotCurrentPosition = function(lat, lng, alt, altacc, head, { coords = new Coordinates(lat, lng, alt, altacc, head, vel); loc = new Position(coords, stamp); + this.lastPosition = loc; this.global_success(loc); } } diff --git a/framework/assets/js/phonegap.js.base b/framework/assets/js/phonegap.js.base index a3310882..d971b939 100644 --- a/framework/assets/js/phonegap.js.base +++ b/framework/assets/js/phonegap.js.base @@ -72,7 +72,7 @@ PhoneGap.addConstructor = function(func) { e.initEvent('deviceready'); document.dispatchEvent(e); } - }, 1); + }, 5); })();