Not in line with HTML5 spec, editing

This commit is contained in:
Joe Bowser 2010-07-06 13:37:19 -07:00
parent c75e66a2fc
commit 88eef5df66
4 changed files with 42 additions and 24 deletions

View File

@ -16,6 +16,7 @@ public class GeoBroker {
private WebView mAppView;
private Context mCtx;
private HashMap<String, GeoListener> geoListeners;
private GeoListener global;
public GeoBroker(WebView view, Context ctx)
{
@ -25,13 +26,12 @@ public class GeoBroker {
}
public void getCurrentLocation()
{
GeoListener listener = new GeoListener("global", mCtx, 10000, mAppView);
Location loc = listener.getCurrentLocation();
String params = loc.getLatitude() + "," + loc.getLongitude() + ", " + loc.getAltitude() + "," + loc.getAccuracy() + "," + loc.getBearing();
params += "," + loc.getSpeed() + "," + loc.getTime();
mAppView.loadUrl("javascript:navigator.geolocation.gotCurrentPosition(" + params + ")");
listener.stop();
{
//It's supposed to run async!
if(global == null)
global = new GeoListener("global", mCtx, 10000, mAppView);
else
global.start(10000);
}
public String start(int freq, String key)

View File

@ -48,7 +48,12 @@ public class GeoListener {
if(id != "global")
{
mAppView.loadUrl("javascript:navigator._geo.success(" + id + "," + params + ")");
}
}
else
{
mAppView.loadUrl("javascript:navigator.geolocation.gotCurrentPosition(" + params + ")");
this.stop();
}
}
void fail()
@ -63,6 +68,19 @@ public class GeoListener {
}
}
void start(int interval)
{
if(mGps != null)
mGps.start(interval);
if(mNetwork != null)
mNetwork.start(interval);
if(mNetwork == null && mGps == null)
{
// Really, how the hell were you going to get the location???
mAppView.loadUrl("javascript:navigator._geo.fail()");
}
}
// This stops the listener
void stop()
{
@ -72,14 +90,4 @@ public class GeoListener {
mNetwork.stop();
}
public Location getCurrentLocation() {
Location loc = null;
if (mGps != null)
loc = mGps.getLocation();
if (loc == null && mNetwork != null)
loc = mNetwork.getLocation();
if(loc == null)
loc = new Location(LocationManager.NETWORK_PROVIDER);
return loc;
}
}

View File

@ -41,9 +41,7 @@ public class GpsListener implements LocationListener {
{
owner = m;
mCtx = ctx;
mLocMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
mLocMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, interval, 0, this);
cLoc = mLocMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);
this.start(interval);
}
public Location getLocation()
@ -92,6 +90,13 @@ public class GpsListener implements LocationListener {
public boolean hasLocation() {
return hasData;
}
public void start(int interval)
{
mLocMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
mLocMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, interval, 0, this);
cLoc = mLocMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
public void stop()
{

View File

@ -40,9 +40,7 @@ public class NetworkListener implements LocationListener {
{
owner = m;
mCtx = ctx;
mLocMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
mLocMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, interval, 0, this);
cLoc = mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
this.start(interval);
}
public Location getLocation()
@ -94,6 +92,13 @@ public class NetworkListener implements LocationListener {
cLoc = location;
}
public void start(int interval)
{
mLocMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
mLocMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, interval, 0, this);
cLoc = mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
public void stop()
{
mLocMan.removeUpdates(this);