Graphics Programs Reference
In-Depth Information
SensorEvent event
. You may wonder how frequently
SensorEvent
reports
new values. While registering a listener, we must also specify the delay or meas-
urement rate for the listener. These rates are defined as static constants inside the
SensorManager
class (
Listing 2-14
).
Listing
2-14.
SENSOR ROTATION/src/com/apress/android/sensorrotation/
Main.java
sm.registerListener(this,
sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
sm.registerListener(this,
sm.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
SensorManager.SENSOR_DELAY_NORMAL);
sm.registerListener(this,
sm.getDefaultSensor(Sensor.TYPE_GRAVITY),
SensorManager.SENSOR_DELAY_NORMAL);
Figure 2-17
.
Rotating arrow using motion and position sensors
Apart from reporting raw sensor data, the
SensorEvent
object also lets us know
about the accuracy of data returned, so we can stop processing the data if it cannot
be trusted (
Listing 2-15
).
Search WWH ::
Custom Search