incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [4/6] android commit: Fixes for new geo stuff
Date Mon, 07 May 2012 23:06:39 GMT
Fixes for new geo stuff


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/1ee484f7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/1ee484f7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/1ee484f7

Branch: refs/heads/master
Commit: 1ee484f70d73eb392953f859772ab4c2671b3305
Parents: 724ea49
Author: Fil Maj <maj.fil@gmail.com>
Authored: Fri Mar 30 02:32:43 2012 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Mon May 7 16:09:20 2012 -0700

----------------------------------------------------------------------
 framework/.settings/org.eclipse.jdt.core.prefs     |    4 ++
 .../apache/cordova/CordovaLocationListener.java    |    2 +-
 framework/src/org/apache/cordova/GeoBroker.java    |   40 +++++++++------
 framework/src/org/apache/cordova/GpsListener.java  |    9 +---
 .../src/org/apache/cordova/NetworkListener.java    |    6 --
 5 files changed, 32 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1ee484f7/framework/.settings/org.eclipse.jdt.core.prefs
----------------------------------------------------------------------
diff --git a/framework/.settings/org.eclipse.jdt.core.prefs b/framework/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..f77b31c
--- /dev/null
+++ b/framework/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.source=1.5

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1ee484f7/framework/src/org/apache/cordova/CordovaLocationListener.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaLocationListener.java b/framework/src/org/apache/cordova/CordovaLocationListener.java
index 6eccfb4..3daa211 100755
--- a/framework/src/org/apache/cordova/CordovaLocationListener.java
+++ b/framework/src/org/apache/cordova/CordovaLocationListener.java
@@ -175,7 +175,7 @@ public class CordovaLocationListener implements LocationListener {
 	 * 
 	 * @param interval
 	 */
-	private void start() {
+	protected void start() {
 		if (!this.running) {
 			if (this.locationManager.getProvider(LocationManager.NETWORK_PROVIDER) != null) {
 				this.running = true;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1ee484f7/framework/src/org/apache/cordova/GeoBroker.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/GeoBroker.java b/framework/src/org/apache/cordova/GeoBroker.java
index b8cfe4e..6a150b3 100755
--- a/framework/src/org/apache/cordova/GeoBroker.java
+++ b/framework/src/org/apache/cordova/GeoBroker.java
@@ -43,9 +43,6 @@ public class GeoBroker extends Plugin {
      * Constructor.
      */
     public GeoBroker() {
-    	this.locationManager = (LocationManager) this.ctx.getSystemService(Context.LOCATION_SERVICE);
-    	this.networkListener = new NetworkListener(this.locationManager, this);
-    	this.gpsListener = new GPSListener(this.locationManager, this);
     }
 
     /**
@@ -57,6 +54,11 @@ public class GeoBroker extends Plugin {
      * @return 				A PluginResult object with a status and message.
      */
     public PluginResult execute(String action, JSONArray args, String callbackId) {
+    	if (this.locationManager == null) {
+        	this.locationManager = (LocationManager) this.ctx.getSystemService(Context.LOCATION_SERVICE);
+        	this.networkListener = new NetworkListener(this.locationManager, this);
+        	this.gpsListener = new GPSListener(this.locationManager, this);
+    	}
         PluginResult.Status status = PluginResult.Status.NO_RESULT;
         String message = "";
         PluginResult result = new PluginResult(status, message);
@@ -69,7 +71,7 @@ public class GeoBroker extends Plugin {
             	Location last = this.locationManager.getLastKnownLocation((enableHighAccuracy
? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER));
             	// Check if we can use lastKnownLocation to get a quick reading and use less
battery
             	if ((System.currentTimeMillis() - last.getTime()) <= maximumAge) {
-            		result = new PluginResult(PluginResult.Status.OK, GeoBroker.returnLocationJSON(last));
+            		result = new PluginResult(PluginResult.Status.OK, this.returnLocationJSON(last));
             	} else {
             		this.getCurrentLocation(callbackId, enableHighAccuracy);
             	}
@@ -132,19 +134,27 @@ public class GeoBroker extends Plugin {
         this.gpsListener = null;
     }
 
-    public static String returnLocationJSON(Location loc) {
-        return "{" + 
-      		  "'latitude':" + loc.getLatitude() + "," + 
-      		  "'longitude':" + loc.getLongitude() + "," + 
-      		  "'altitude':" + (loc.hasAltitude() ? loc.getAltitude() : "null") + "," + 
-      		  "'accuracy':" + loc.getAccuracy() + "," + 
-      		  "'heading':" + (loc.hasBearing() ? (loc.hasSpeed() ? loc.getBearing() : "NaN")
: "null") + "," + 
-      		  "'speed':" + loc.getSpeed() + "," + 
-      		  "'timestamp':" + loc.getTime() + 
-      		"}"; 
+    public JSONObject returnLocationJSON(Location loc) {
+    	JSONObject o = new JSONObject();
+    	
+    	try {
+			o.put("latitude", loc.getLatitude());
+			o.put("longitude", loc.getLongitude());
+	    	o.put("altitude", (loc.hasAltitude() ? loc.getAltitude() : null));
+	  	  	o.put("accuracy", loc.getAccuracy());
+	  	  	o.put("heading", (loc.hasBearing() ? (loc.hasSpeed() ? loc.getBearing() : null) :
null));
+	  	  	o.put("speed", loc.getSpeed()); 
+			o.put("timestamp", loc.getTime()); 
+		} catch (JSONException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+    	
+    	
+    	return o;
       }
       public void win(Location loc, String callbackId) {
-    	  PluginResult result = new PluginResult(PluginResult.Status.OK, GeoBroker.returnLocationJSON(loc));
+    	  PluginResult result = new PluginResult(PluginResult.Status.OK, this.returnLocationJSON(loc));
     	  this.success(result, callbackId);
       }
       /**

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1ee484f7/framework/src/org/apache/cordova/GpsListener.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/GpsListener.java b/framework/src/org/apache/cordova/GpsListener.java
index 5010736..2b46c7c 100755
--- a/framework/src/org/apache/cordova/GpsListener.java
+++ b/framework/src/org/apache/cordova/GpsListener.java
@@ -28,12 +28,6 @@ import android.location.LocationManager;
 public class GPSListener extends CordovaLocationListener {
 	public GPSListener(LocationManager locationManager, GeoBroker m) {
 		super(locationManager, m, "[Cordova GPSListener]");
-		if (this.locationManager.getProvider(LocationManager.GPS_PROVIDER) != null) {
-	        // If network provider, then create and start network listener
-            this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000,
0, this);
-        } else {
-        	this.fail(CordovaLocationListener.POSITION_UNAVAILABLE, "GPS provider is not available.");
-        }
 	}
 
 	
@@ -42,7 +36,8 @@ public class GPSListener extends CordovaLocationListener {
 	 * 
 	 * @param interval
 	 */
-	public void start() {
+	@Override
+	protected void start() {
 		if (!this.running) {
 			if (this.locationManager.getProvider(LocationManager.GPS_PROVIDER) != null) {
 				this.running = true;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1ee484f7/framework/src/org/apache/cordova/NetworkListener.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/NetworkListener.java b/framework/src/org/apache/cordova/NetworkListener.java
index 050560a..6eaa8ac 100755
--- a/framework/src/org/apache/cordova/NetworkListener.java
+++ b/framework/src/org/apache/cordova/NetworkListener.java
@@ -28,11 +28,5 @@ import android.location.LocationManager;
 public class NetworkListener extends CordovaLocationListener {
 	public NetworkListener(LocationManager locationManager, GeoBroker m) {
 		super(locationManager, m, "[Cordova NetworkListener]");
-		if (this.locationManager.getProvider(LocationManager.NETWORK_PROVIDER) != null) {
-	        // If network provider, then create and start network listener
-            this.locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
60000, 10, this);
-        } else {
-        	this.fail(CordovaLocationListener.POSITION_UNAVAILABLE, "Network provider is not
available.");
-        }
 	}
 }


Mime
View raw message