I need to check if the phone is moving too fast while capturing a series of images ( like the panorama option in Google Camera).
I have tried this:
public void onSensorChanged(SensorEvent event) {
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
//System.out.println("X: "+ x + ", Y: " +y);
if (!mInitialized) {
mLastX = x;
mLastY = y;
mLastZ = z;
mInitialized = true;
}else{
float deltaX = Math.abs(mLastX - x);
float deltaY = Math.abs(mLastY - y);
float deltaZ = Math.abs(mLastZ - z);
if (deltaX < NOISE) deltaX = (float)0.0;
if (deltaY < NOISE) deltaY = (float)0.0;
if (deltaZ < NOISE) deltaZ = (float)0.0;
mLastX = x;
mLastY = y;
mLastZ = z;
if (deltaX > deltaY) {
//Log.e("TEST","HORIZONTAL "+deltaX + " :X, " +deltaY +" :Y");
//horizontal
} else if (deltaY > deltaX) {
//vertical
// didShake = true;
//Log.e("TEST","TOO MUCH "+deltaX + " :X, " +deltaY +" :Y");
} else {
}
}
}
Where NOISE is a threshold I keep experimenting with.
Now, this gets triggered only when there is a sudden jerk (Copied from a shake listener tutorial). This is not exactly what I want. If I move the phone too fast without a sudden jerk, then this does not get triggered.
I have gone through this:
finding speed of device movement
which led me to this:
http://maephv.blogspot.in/2011/10/android-computing-speed-and-distance.html
But this looks like its calculating speed of the device like GPS. I only need to detect if the phone is being waved around too fast.