JumpingJack
Wearable
com.example.android.wearable.jumpingjack
25
PUBLISHED
Wearable
Android
Java
Mobile
INTERMEDIATE
screenshots/web-icon.png
screenshots/jumping_jack.gif
android.hardware.SensorEvent
android.hardware.SensorEventManager
GRAVITY_THRESHOLD)) {
if(timestamp - mLastTime < TIME_THRESHOLD_NS && mUp != (xValue > 0)) {
onJumpDetected(!mUp);
}
mUp = xValue > 0;
mLastTime = timestamp;
}
}
```
The detectJump method above assumes that when a person is wearing the watch, the x-component of gravity
as measured by the Gravity Sensor is +9.8 when the hand is downward and -9.8 when the hand
is upward (signs are reversed if the watch is worn on the right hand). Since the upward or
downward may not be completely accurate, we leave some room and instead of 9.8, we use
GRAVITY_THRESHOLD (7.0f). We also consider the up <-> down movement successful if it takes less than
TIME_THRESHOLD_NS (2000000000 nanoseconds).
[1]: http://developer.android.com/reference/android/hardware/SensorEventListener.html
[2]: http://developer.android.com/reference/android/hardware/SensorManager.html
]]>