I have started coding for Google Glass. I am developing a sample application which will detect whether a user is nodding or not. More preciously, I want to detect whether it is nod "Yes" or nod "NO" so that I can perform some action.
What's the best way of detecting it since ORIENTATION_SENSOR is deprecated?
I would suggest taking a look at the Level or Compass samples that make use of the sensors.
The Level sample uses the GRAVITY_SENSOR
to compute the head orientation on the desired axis. The logic resides in the LevelRenderer
class:
/**
* Compute the orientation angle.
*
* @param event Gravity values.
*/
private void computeOrientation(SensorEvent event) {
float angle = (float) -Math.atan(event.values[0]
/ Math.sqrt(event.values[1] * event.values[1] + event.values[2] * event.values[2]));
mLevelView.setAngle(angle);
}
Simply change the vectors used in the angle computation to change axis.