Remove use of PluginResult.Status.NO_RESULT in GeoBroker.

It resolves to a no-op when KEEP_CALLBACK is set, and is therefore
confusing to use it with the new CordovaPlugin setup.
This commit is contained in:
Andrew Grieve 2012-10-15 14:49:47 -04:00
parent dc5078306d
commit 6a5cddd907

View File

@ -61,22 +61,17 @@ public class GeoBroker extends CordovaPlugin {
this.gpsListener = new GPSListener(this.locationManager, this); this.gpsListener = new GPSListener(this.locationManager, this);
} }
PluginResult.Status status = PluginResult.Status.NO_RESULT;
String message = "Location API is not available for this device.";
PluginResult result = new PluginResult(status, message);
if ( locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER ) || if ( locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ||
locationManager.isProviderEnabled( LocationManager.NETWORK_PROVIDER )) { locationManager.isProviderEnabled( LocationManager.NETWORK_PROVIDER )) {
result.setKeepCallback(true);
if (action.equals("getLocation")) { if (action.equals("getLocation")) {
boolean enableHighAccuracy = args.getBoolean(0); boolean enableHighAccuracy = args.getBoolean(0);
int maximumAge = args.getInt(1); int maximumAge = args.getInt(1);
Location last = this.locationManager.getLastKnownLocation((enableHighAccuracy ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER)); 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 // Check if we can use lastKnownLocation to get a quick reading and use less battery
if (last != null && (System.currentTimeMillis() - last.getTime()) <= maximumAge) { if (last != null && (System.currentTimeMillis() - last.getTime()) <= maximumAge) {
result = new PluginResult(PluginResult.Status.OK, this.returnLocationJSON(last)); PluginResult result = new PluginResult(PluginResult.Status.OK, this.returnLocationJSON(last));
callbackContext.sendPluginResult(result);
} else { } else {
this.getCurrentLocation(callbackContext, enableHighAccuracy); this.getCurrentLocation(callbackContext, enableHighAccuracy);
} }
@ -93,10 +88,13 @@ public class GeoBroker extends CordovaPlugin {
else { else {
return false; return false;
} }
} } else {
PluginResult.Status status = PluginResult.Status.NO_RESULT;
String message = "Location API is not available for this device.";
PluginResult result = new PluginResult(status, message);
callbackContext.sendPluginResult(result); callbackContext.sendPluginResult(result);
}
return true; return true;
} }
private void clearWatch(String id) { private void clearWatch(String id) {