Fixing up Geolocation and Alerts

This commit is contained in:
Joe Bowser 2009-12-16 11:09:32 -08:00
parent 9276729be5
commit 17bcda6c10
4 changed files with 37 additions and 11 deletions

View File

@ -49,6 +49,6 @@ public class CompassListener implements SensorEventListener{
public void onSensorChanged(SensorEvent event) { public void onSensorChanged(SensorEvent event) {
// We only care about the orientation as far as it refers to Magnetic North // We only care about the orientation as far as it refers to Magnetic North
float heading = event.values[0]; float heading = event.values[0];
mAppView.loadUrl("javascript:gotBearing(" + heading + ")"); mAppView.loadUrl("javascript:navigator.compass.setHeading(" + heading + ")");
} }
} }

View File

@ -26,6 +26,7 @@ package com.phonegap;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Color; import android.graphics.Color;
@ -172,13 +173,39 @@ public class DroidGap extends Activity {
Log.d(LOG_TAG, message); Log.d(LOG_TAG, message);
// This shows the dialog box. This can be commented out for dev // This shows the dialog box. This can be commented out for dev
AlertDialog.Builder alertBldr = new AlertDialog.Builder(mCtx); AlertDialog.Builder alertBldr = new AlertDialog.Builder(mCtx);
GapOKDialog okHook = new GapOKDialog();
GapCancelDialog cancelHook = new GapCancelDialog();
alertBldr.setMessage(message); alertBldr.setMessage(message);
alertBldr.setTitle("Alert"); alertBldr.setTitle("Alert");
alertBldr.setCancelable(true);
alertBldr.setPositiveButton("OK", okHook);
alertBldr.setNegativeButton("Cancel", cancelHook);
alertBldr.show(); alertBldr.show();
result.confirm(); result.confirm();
return true; return true;
} }
/*
* This is the Code for the OK Button
*/
public class GapOKDialog implements DialogInterface.OnClickListener {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.dismiss();
}
}
public class GapCancelDialog implements DialogInterface.OnClickListener {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.dismiss();
}
}
} }

View File

@ -3,6 +3,7 @@ package com.phonegap;
import java.util.HashMap; import java.util.HashMap;
import android.content.Context; import android.content.Context;
import android.location.Location;
import android.webkit.WebView; import android.webkit.WebView;
/* /*
@ -15,7 +16,6 @@ public class GeoBroker {
private WebView mAppView; private WebView mAppView;
private Context mCtx; private Context mCtx;
private HashMap<String, GeoListener> geoListeners; private HashMap<String, GeoListener> geoListeners;
private GeoListener listener;
public GeoBroker(WebView view, Context ctx) public GeoBroker(WebView view, Context ctx)
{ {
@ -24,9 +24,13 @@ public class GeoBroker {
} }
public void getCurrentLocation() public void getCurrentLocation()
{ {
if (listener == null) GeoListener listener = new GeoListener("global", mCtx, 10000, mAppView);
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();
} }
public String start(int freq, String key) public String start(int freq, String key)

View File

@ -40,12 +40,7 @@ public class GeoListener {
if(id != "global") if(id != "global")
{ {
mAppView.loadUrl("javascript:navigator.geolocation.success(" + id + "," + params + ")"); mAppView.loadUrl("javascript:navigator.geolocation.success(" + id + "," + params + ")");
} }
else
{
mAppView.loadUrl("javascript:navigator.geolocation.gotCurrentPosition(" + params + ")");
this.stop();
}
} }
void fail() void fail()