Fixes to bring PhoneGap Android closer to spec

This commit is contained in:
Joe Bowser
2009-07-17 13:23:51 -07:00
parent 0344665c79
commit 08c42eac97
10 changed files with 1011 additions and 1292 deletions
+14 -5
View File
@@ -12,6 +12,10 @@ public class AccelListener implements SensorListener{
WebView mAppView;
Context mCtx;
String mKey;
int mTime = 10000;
boolean started = false;
private SensorManager sensorManager;
private long lastUpdate = -1;
@@ -19,20 +23,25 @@ public class AccelListener implements SensorListener{
AccelListener(Context ctx, WebView appView)
{
mCtx = ctx;
mAppView = appView;
mAppView = appView;
sensorManager = (SensorManager) mCtx.getSystemService(Context.SENSOR_SERVICE);
}
public void start()
public void start(int time)
{
sensorManager.registerListener(this,
mTime = time;
if (!started)
{
sensorManager.registerListener(this,
SensorManager.SENSOR_ACCELEROMETER,
SensorManager.SENSOR_DELAY_GAME);
}
}
public void stop()
{
sensorManager.unregisterListener(this);
if(started)
sensorManager.unregisterListener(this);
}
public void onAccuracyChanged(int sensor, int accuracy) {
@@ -43,7 +52,7 @@ public class AccelListener implements SensorListener{
if (sensor != SensorManager.SENSOR_ACCELEROMETER || values.length < 3)
return;
long curTime = System.currentTimeMillis();
if (lastUpdate == -1 || (curTime - lastUpdate) > 1000) {
if (lastUpdate == -1 || (curTime - lastUpdate) > mTime) {
lastUpdate = curTime;
+3 -2
View File
@@ -94,9 +94,10 @@ public class DroidGap extends Activity {
// The PhoneGap class handles the Notification and Android Specific crap
this.gap = new PhoneGap(this, appView);
this.geo = new GeoBroker(appView, this);
this.accel = new AccelListener(this, appView);
this.accel = new AccelListener(this, appView);
// This creates the new javascript interfaces for PhoneGap
appView.addJavascriptInterface(gap, "Device");
// Ewww - It's called DroidGap again. :(
appView.addJavascriptInterface(gap, "DroidGap");
appView.addJavascriptInterface(geo, "Geo");
appView.addJavascriptInterface(accel, "Accel");
}
+10 -3
View File
@@ -30,13 +30,20 @@ public class GeoListener {
/*
* We only need to figure out what we do when we succeed!
*/
String params;
/*
* Build the giant string to send back to Javascript!
*/
params = loc.getLatitude() + "," + loc.getLongitude() + ", " + loc.getAltitude() + "," + loc.getAccuracy() + "," + loc.getBearing();
params += "," + loc.getSpeed() + "," + loc.getTime();
if(id != "global")
{
mAppView.loadUrl("javascript:Geolocation.success(" + id + ", " + loc.getLatitude() + ", " + loc.getLongitude() + ")");
mAppView.loadUrl("javascript:navigator.geolocation.success(" + id + "," + params + ")");
}
else
{
mAppView.loadUrl("javascript:Geolocation.gotCurrentPosition(" + loc.getLatitude() + ", " + loc.getLongitude() + ")");
mAppView.loadUrl("javascript:navigator.geolocation.gotCurrentPosition(" + params + ")");
this.stop();
}
}
@@ -44,7 +51,7 @@ public class GeoListener {
void fail()
{
// Do we need to know why? How would we handle this?
mAppView.loadUrl("javascript:GeoLocation.fail(" + id + ")");
mAppView.loadUrl("javascript:navigator.geolocation.fail(" + id + ")");
}
// This stops the listener
+4 -1
View File
@@ -65,7 +65,10 @@ public class PhoneGap{
RingtoneManager beeper = new RingtoneManager(mCtx);
Uri ringtone = beeper.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone notification = beeper.getRingtone(mCtx, ringtone);
notification.play();
for (long i = 0; i < pattern; ++i)
{
notification.play();
}
}
public void vibrate(long pattern){