Initial Commit - Fixing Accelerometer

This commit is contained in:
Joe Bowser
2010-04-28 15:46:15 -07:00
parent 36e90c9e22
commit 64671184a6
4 changed files with 77 additions and 29 deletions
@@ -0,0 +1,33 @@
package com.phonegap;
import java.util.HashMap;
import android.content.Context;
import android.webkit.WebView;
public class AccelBroker {
private WebView mAppView;
private Context mCtx;
private HashMap<String, AccelListener> accelListeners;
public AccelBroker(WebView view, Context ctx)
{
mCtx = ctx;
mAppView = view;
accelListeners = new HashMap<String, AccelListener>();
}
public String start(int freq, String key)
{
AccelListener listener = new AccelListener(key, freq, mCtx, mAppView);
accelListeners.put(key, listener);
return key;
}
public void stop(String key)
{
AccelListener acc = accelListeners.get(key);
acc.stop();
}
}
@@ -15,7 +15,7 @@ public class AccelListener implements SensorEventListener{
WebView mAppView;
Context mCtx;
String mKey;
Sensor mSensor;
Sensor mSensor;
int mTime = 10000;
boolean started = false;
@@ -23,10 +23,12 @@ public class AccelListener implements SensorEventListener{
private long lastUpdate = -1;
public AccelListener(Context ctx, WebView appView)
public AccelListener(String key, int freq, Context ctx, WebView appView)
{
mCtx = ctx;
mAppView = appView;
mKey = key;
mTime = freq;
sensorManager = (SensorManager) mCtx.getSystemService(Context.SENSOR_SERVICE);
}
@@ -42,7 +44,7 @@ public class AccelListener implements SensorEventListener{
}
else
{
// Call fail
mAppView.loadUrl("javascript:navigator.accelerometer.epicFail(" + mKey + ", 'Failed to start')");
}
}
@@ -68,8 +70,9 @@ public class AccelListener implements SensorEventListener{
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
mAppView.loadUrl("javascript:gotAccel(" + x + ", " + y + "," + z + " )");
float z = event.values[2];
//mAppView.loadUrl("javascript:gotAccel(" + x + ", " + y + "," + z + " )");
mAppView.loadUrl("javascript:navigator.accelerometer.gotAccel(" + mKey + "," + x + "," + y + "," + z + ")");
}
}
+2 -2
View File
@@ -55,7 +55,7 @@ public class DroidGap extends Activity {
private PhoneGap gap;
private GeoBroker geo;
private AccelListener accel;
private AccelBroker accel;
private CameraLauncher launcher;
private ContactManager mContacts;
private FileUtils fs;
@@ -135,7 +135,7 @@ public class DroidGap extends Activity {
{
gap = new PhoneGap(this, appView);
geo = new GeoBroker(appView, this);
accel = new AccelListener(this, appView);
accel = new AccelBroker(appView, this);
launcher = new CameraLauncher(appView, this);
mContacts = new ContactManager(this, appView);
fs = new FileUtils(appView);