You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/08/09 05:39:50 UTC

[2/2] android commit: GeoBroker checks if location service avialable for device first.

GeoBroker checks if location service avialable for device first.


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/e575212c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/e575212c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/e575212c

Branch: refs/heads/master
Commit: e575212c49da72ac3abc238bfd968289e2154a4d
Parents: c52dc10
Author: Evgeni Petrov <ev...@gmail.com>
Authored: Wed Aug 8 11:23:08 2012 +0300
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Aug 8 23:23:01 2012 -0400

----------------------------------------------------------------------
 framework/src/org/apache/cordova/GeoBroker.java |   59 ++++++++++--------
 1 files changed, 33 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/e575212c/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 499d446..05c427d 100755
--- a/framework/src/org/apache/cordova/GeoBroker.java
+++ b/framework/src/org/apache/cordova/GeoBroker.java
@@ -59,36 +59,43 @@ public class GeoBroker extends Plugin {
             this.networkListener = new NetworkListener(this.locationManager, this);
             this.gpsListener = new GPSListener(this.locationManager, this);
         }
+        
         PluginResult.Status status = PluginResult.Status.NO_RESULT;
-        String message = "";
+        String message = "Location API is not available for this device.";
         PluginResult result = new PluginResult(status, message);
-        result.setKeepCallback(true);
-
-        try {
-            if (action.equals("getLocation")) {
-                boolean enableHighAccuracy = args.getBoolean(0);
-                int maximumAge = args.getInt(1);
-                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, this.returnLocationJSON(last));
-                } else {
-                    this.getCurrentLocation(callbackId, enableHighAccuracy);
-                }
-            }
-            else if (action.equals("addWatch")) {
-                String id = args.getString(0);
-                boolean enableHighAccuracy = args.getBoolean(1);
-                this.addWatch(id, callbackId, enableHighAccuracy);
-            }
-            else if (action.equals("clearWatch")) {
-                String id = args.getString(0);
-                this.clearWatch(id);
-            }
-        } catch (JSONException e) {
-            result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
+        
+        if ( locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ||
+        	 locationManager.isProviderEnabled( LocationManager.NETWORK_PROVIDER )) {
+    		
+	        result.setKeepCallback(true);
+	
+	        try {
+	            if (action.equals("getLocation")) {
+	                boolean enableHighAccuracy = args.getBoolean(0);
+	                int maximumAge = args.getInt(1);
+	                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, this.returnLocationJSON(last));
+	                } else {
+	                    this.getCurrentLocation(callbackId, enableHighAccuracy);
+	                }
+	            }
+	            else if (action.equals("addWatch")) {
+	                String id = args.getString(0);
+	                boolean enableHighAccuracy = args.getBoolean(1);
+	                this.addWatch(id, callbackId, enableHighAccuracy);
+	            }
+	            else if (action.equals("clearWatch")) {
+	                String id = args.getString(0);
+	                this.clearWatch(id);
+	            }
+	        } catch (JSONException e) {
+	            result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
+	        }
         }
         return result;
+        
     }
 
     private void clearWatch(String id) {