You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/05/18 23:12:43 UTC
[3/9] android commit: [CB-463] added accuracy checking to native
accel implementation,
this way getCurrentAcceleration returns fairly accurate results
[CB-463] added accuracy checking to native accel implementation, this way getCurrentAcceleration returns fairly accurate results
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/ce21dc71
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/ce21dc71
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/ce21dc71
Branch: refs/heads/463
Commit: ce21dc714580e54f424f013ed5b6f7e06e4ccc36
Parents: f9dc310
Author: Fil Maj <ma...@gmail.com>
Authored: Mon May 14 15:21:41 2012 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Thu May 17 11:38:14 2012 -0700
----------------------------------------------------------------------
.../src/org/apache/cordova/AccelListener.java | 36 +++++++++++----
1 files changed, 26 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/ce21dc71/framework/src/org/apache/cordova/AccelListener.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/AccelListener.java b/framework/src/org/apache/cordova/AccelListener.java
index 40ddec4..7596045 100755
--- a/framework/src/org/apache/cordova/AccelListener.java
+++ b/framework/src/org/apache/cordova/AccelListener.java
@@ -54,6 +54,7 @@ public class AccelListener extends Plugin implements SensorEventListener {
private float x,y,z; // most recent acceleration values
private long timestamp; // time of most recent value
private int status; // status of listener
+ private int accuracy = SensorManager.SENSOR_STATUS_UNRELIABLE;
private SensorManager sensorManager; // Sensor manager
private Sensor mSensor; // Acceleration sensor returned by sensor manager
@@ -184,7 +185,7 @@ public class AccelListener extends Plugin implements SensorEventListener {
// If found, then register as listener
if ((list != null) && (list.size() > 0)) {
this.mSensor = list.get(0);
- this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_FASTEST);
+ this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_UI);
this.setStatus(AccelListener.STARTING);
} else {
this.setStatus(AccelListener.ERROR_FAILED_TO_START);
@@ -217,6 +218,7 @@ public class AccelListener extends Plugin implements SensorEventListener {
this.sensorManager.unregisterListener(this);
}
this.setStatus(AccelListener.STOPPED);
+ this.accuracy = SensorManager.SENSOR_STATUS_UNRELIABLE;
}
/**
@@ -226,6 +228,17 @@ public class AccelListener extends Plugin implements SensorEventListener {
* @param accuracy
*/
public void onAccuracyChanged(Sensor sensor, int accuracy) {
+ // Only look at accelerometer events
+ if (sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
+ return;
+ }
+
+ // If not running, then just return
+ if (this.status == AccelListener.STOPPED) {
+ return;
+ }
+ Log.d("ACCEL", "accuracy is now " + accuracy);
+ this.accuracy = accuracy;
}
/**
@@ -246,16 +259,19 @@ public class AccelListener extends Plugin implements SensorEventListener {
this.setStatus(AccelListener.RUNNING);
- // Save time that event was received
- this.timestamp = System.currentTimeMillis();
- this.x = event.values[0];
- this.y = event.values[1];
- this.z = event.values[2];
+ if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) {
- this.win();
-
- if (this.size() == 0) {
- this.stop();
+ // Save time that event was received
+ this.timestamp = System.currentTimeMillis();
+ this.x = event.values[0];
+ this.y = event.values[1];
+ this.z = event.values[2];
+
+ this.win();
+
+ if (this.size() == 0) {
+ this.stop();
+ }
}
}