Merge "More improvements to the SensorManager documentation" into gingerbread

This commit is contained in:
Mathias Agopian
2010-07-07 13:06:57 -07:00
committed by Android (Google) Code Review
5 changed files with 307 additions and 192 deletions

View File

@@ -20,24 +20,32 @@ package android.hardware;
/** /**
* Class representing a sensor. Use {@link SensorManager#getSensorList} to get * Class representing a sensor. Use {@link SensorManager#getSensorList} to get
* the list of available Sensors. * the list of available Sensors.
*
* @see SensorManager
* @see SensorEventListener
* @see SensorEvent
*
*/ */
public class Sensor { public class Sensor {
/** /**
* A constant describing an accelerometer sensor type. See * A constant describing an accelerometer sensor type. See
* {@link android.hardware.SensorEvent SensorEvent} for more details. * {@link android.hardware.SensorEvent#values SensorEvent.values} for more
* details.
*/ */
public static final int TYPE_ACCELEROMETER = 1; public static final int TYPE_ACCELEROMETER = 1;
/** /**
* A constant describing a magnetic field sensor type. See * A constant describing a magnetic field sensor type. See
* {@link android.hardware.SensorEvent SensorEvent} for more details. * {@link android.hardware.SensorEvent#values SensorEvent.values} for more
* details.
*/ */
public static final int TYPE_MAGNETIC_FIELD = 2; public static final int TYPE_MAGNETIC_FIELD = 2;
/** /**
* A constant describing an orientation sensor type. See * A constant describing an orientation sensor type. See
* {@link android.hardware.SensorEvent SensorEvent} for more details. * {@link android.hardware.SensorEvent#values SensorEvent.values} for more
* details.
* *
* @deprecated use {@link android.hardware.SensorManager#getOrientation * @deprecated use {@link android.hardware.SensorManager#getOrientation
* SensorManager.getOrientation()} instead. * SensorManager.getOrientation()} instead.
@@ -50,7 +58,8 @@ public class Sensor {
/** /**
* A constant describing an light sensor type. See * A constant describing an light sensor type. See
* {@link android.hardware.SensorEvent SensorEvent} for more details. * {@link android.hardware.SensorEvent#values SensorEvent.values} for more
* details.
*/ */
public static final int TYPE_LIGHT = 5; public static final int TYPE_LIGHT = 5;
@@ -62,7 +71,8 @@ public class Sensor {
/** /**
* A constant describing an proximity sensor type. See * A constant describing an proximity sensor type. See
* {@link android.hardware.SensorEvent SensorEvent} for more details. * {@link android.hardware.SensorEvent#values SensorEvent.values} for more
* details.
*/ */
public static final int TYPE_PROXIMITY = 8; public static final int TYPE_PROXIMITY = 8;

View File

@@ -28,17 +28,20 @@ package android.hardware;
* </p> * </p>
* *
* <p> * <p>
* The coordinate space is defined relative to the screen of the phone in its * The coordinate-system is defined relative to the screen of the phone in its
* default orientation. The axes are not swapped when the device's screen * default orientation. The axes are not swapped when the device's screen
* orientation changes. * orientation changes.
* </p> * </p>
* *
* <p> * <p>
* The OpenGL ES coordinate system is used. The origin is in the lower-left * The X axis is horizontal and points to the right, the Y axis is vertical and
* corner with respect to the screen, with the X axis horizontal and pointing * points up and the Z axis points towards the outside of the front face of the
* right, the Y axis vertical and pointing up and the Z axis pointing outside * screen. In this system, coordinates behind the screen have negative Z values.
* the front face of the screen. In this system, coordinates behind the screen * </p>
* have negative Z values. *
* <p>
* <center><img src="../../../images/axis_device.png"
* alt="Sensors coordinate-system diagram." border="0" /></center>
* </p> * </p>
* *
* <p> * <p>
@@ -46,63 +49,139 @@ package android.hardware;
* Android 2D APIs where the origin is in the top-left corner. * Android 2D APIs where the origin is in the top-left corner.
* </p> * </p>
* *
* <pre> * @see SensorManager
* x<0 x>0 * @see SensorEvent
* ^ * @see Sensor
* |
* +-----------+--> y>0
* | |
* | |
* | |
* | | / z<0
* | | /
* | | /
* O-----------+/
* |[] [ ] []/
* +----------/+ y<0
* /
* /
* |/ z>0 (toward the sky)
* *
* O: Origin (x=0,y=0,z=0)
* </pre>
*/ */
public class SensorEvent { public class SensorEvent {
/** /**
* <p> * <p>
* The length and contents of the values array vary depending on which * The length and contents of the {@link #values values} array depends on
* {@link android.hardware.Sensor sensor} type is being monitored (see also * which {@link android.hardware.Sensor sensor} type is being monitored (see
* {@link SensorEvent} for a definition of the coordinate system used): * also {@link SensorEvent} for a definition of the coordinate system used).
* </p> * </p>
* *
* <h3>{@link android.hardware.Sensor#TYPE_ORIENTATION * <h4>{@link android.hardware.Sensor#TYPE_ACCELEROMETER
* Sensor.TYPE_ORIENTATION}:</h3> All values are angles in degrees. * Sensor.TYPE_ACCELEROMETER}:</h4> All values are in SI units (m/s^2)
* *
* <ul> * <ul>
* <p> * <p>
* values[0]: Azimuth, angle between the magnetic north direction and the Y * values[0]: Acceleration minus Gx on the x-axis
* axis, around the Z axis (0 to 359). 0=North, 90=East, 180=South, 270=West * </p>
*
* <p> * <p>
* values[1]: Pitch, rotation around X axis (-180 to 180), with positive * values[1]: Acceleration minus Gy on the y-axis
* values when the z-axis moves <b>toward</b> the y-axis. * </p>
*
* <p> * <p>
* values[2]: Roll, rotation around Y axis (-90 to 90), with positive values * values[2]: Acceleration minus Gz on the z-axis
* when the x-axis moves <b>toward</b> the z-axis. * </p>
* </ul> * </ul>
* *
* <p> * <p>
* <b>Important note:</b> For historical reasons the roll angle is positive * A sensor of this type measures the acceleration applied to the device
* in the clockwise direction (mathematically speaking, it should be * (<b>Ad</b>). Conceptually, it does so by measuring forces applied to the
* positive in the counter-clockwise direction). * sensor itself (<b>Fs</b>) using the relation:
* * </p>
*
* <b><center>Ad = - <20>Fs / mass</center></b>
*
* <p>
* In particular, the force of gravity is always influencing the measured
* acceleration:
* </p>
*
* <b><center>Ad = -g - <20>F / mass</center></b>
*
* <p>
* For this reason, when the device is sitting on a table (and obviously not
* accelerating), the accelerometer reads a magnitude of <b>g</b> = 9.81
* m/s^2
* </p>
*
* <p>
* Similarly, when the device is in free-fall and therefore dangerously
* accelerating towards to ground at 9.81 m/s^2, its accelerometer reads a
* magnitude of 0 m/s^2.
* </p>
*
* <p>
* It should be apparent that in order to measure the real acceleration of
* the device, the contribution of the force of gravity must be eliminated.
* This can be achieved by applying a <i>high-pass</i> filter. Conversely, a
* <i>low-pass</i> filter can be used to isolate the force of gravity.
* </p>
* <p>
* <u>Examples</u>:
* <ul>
* <li>When the device lies flat on a table and is pushed on its left side
* toward the right, the x acceleration value is positive.</li>
*
* <li>When the device lies flat on a table, the acceleration value is
* +9.81, which correspond to the acceleration of the device (0 m/s^2) minus
* the force of gravity (-9.81 m/s^2).</li>
*
* <li>When the device lies flat on a table and is pushed toward the sky
* with an acceleration of A m/s^2, the acceleration value is equal to
* A+9.81 which correspond to the acceleration of the device (+A m/s^2)
* minus the force of gravity (-9.81 m/s^2).</li>
* </ul>
*
*
* <h4>{@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD
* Sensor.TYPE_MAGNETIC_FIELD}:</h4>
* All values are in micro-Tesla (uT) and measure the ambient magnetic field
* in the X, Y and Z axis.
*
* <h4>{@link android.hardware.Sensor#TYPE_LIGHT Sensor.TYPE_LIGHT}:</h4>
*
* <ul>
* <p>
* values[0]: Ambient light level in SI lux units
* </ul>
*
* <h4>{@link android.hardware.Sensor#TYPE_PROXIMITY Sensor.TYPE_PROXIMITY}:
* </h4>
*
* <ul>
* <p>
* values[0]: Proximity sensor distance measured in centimeters
* </ul>
*
* <p>
* <b>Note:</b> Some proximity sensors only support a binary <i>near</i> or
* <i>far</i> measurement. In this case, the sensor should report its
* {@link android.hardware.Sensor#getMaximumRange() maximum range} value in
* the <i>far</i> state and a lesser value in the <i>near</i> state.
* </p>
*
* <h4>{@link android.hardware.Sensor#TYPE_ORIENTATION
* Sensor.TYPE_ORIENTATION}:</h4> All values are angles in degrees.
*
* <ul>
* <p>
* values[0]: Azimuth, angle between the magnetic north direction and the
* y-axis, around the z-axis (0 to 359). 0=North, 90=East, 180=South,
* 270=West
* </p>
*
* <p>
* values[1]: Pitch, rotation around x-axis (-180 to 180), with positive
* values when the z-axis moves <b>toward</b> the y-axis.
* </p>
*
* <p>
* values[2]: Roll, rotation around y-axis (-90 to 90), with positive values
* when the x-axis moves <b>toward</b> the z-axis.
* </p>
* </ul>
*
* <p> * <p>
* <b>Note:</b> This definition is different from <b>yaw, pitch and roll</b> * <b>Note:</b> This definition is different from <b>yaw, pitch and roll</b>
* used in aviation where the X axis is along the long side of the plane * used in aviation where the X axis is along the long side of the plane
* (tail to nose). * (tail to nose).
* * </p>
*
* <p> * <p>
* <b>Note:</b> This sensor type exists for legacy reasons, please use * <b>Note:</b> This sensor type exists for legacy reasons, please use
* {@link android.hardware.SensorManager#getRotationMatrix * {@link android.hardware.SensorManager#getRotationMatrix
@@ -111,62 +190,16 @@ public class SensorEvent {
* remapCoordinateSystem()} and * remapCoordinateSystem()} and
* {@link android.hardware.SensorManager#getOrientation getOrientation()} to * {@link android.hardware.SensorManager#getOrientation getOrientation()} to
* compute these values instead. * compute these values instead.
* * </p>
* <h3>{@link android.hardware.Sensor#TYPE_ACCELEROMETER *
* Sensor.TYPE_ACCELEROMETER}:</h3>
* All values are in SI units (m/s^2) and measure the acceleration applied
* to the phone minus the force of gravity.
*
* <ul>
* <p> * <p>
* values[0]: Acceleration minus Gx on the x-axis * <b>Important note:</b> For historical reasons the roll angle is positive
* <p> * in the clockwise direction (mathematically speaking, it should be
* values[1]: Acceleration minus Gy on the y-axis * positive in the counter-clockwise direction).
* <p> * </p>
* values[2]: Acceleration minus Gz on the z-axis *
* </ul> * @see SensorEvent
* * @see GeomagneticField
* <p>
* <u>Examples</u>:
* <ul>
* <li>When the device lies flat on a table and is pushed on its left side
* toward the right, the x acceleration value is positive.</li>
*
* <li>When the device lies flat on a table, the acceleration value is
* +9.81, which correspond to the acceleration of the device (0 m/s^2) minus
* the force of gravity (-9.81 m/s^2).</li>
*
* <li>When the device lies flat on a table and is pushed toward the sky
* with an acceleration of A m/s^2, the acceleration value is equal to
* A+9.81 which correspond to the acceleration of the device (+A m/s^2)
* minus the force of gravity (-9.81 m/s^2).</li>
* </ul>
*
*
* <h3>{@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD
* Sensor.TYPE_MAGNETIC_FIELD}:</h3>
* All values are in micro-Tesla (uT) and measure the ambient magnetic field
* in the X, Y and Z axis.
*
* <h3>{@link android.hardware.Sensor#TYPE_LIGHT Sensor.TYPE_LIGHT}:</h3>
*
* <ul>
* <p>
* values[0]: Ambient light level in SI lux units
* </ul>
*
* <h3>{@link android.hardware.Sensor#TYPE_PROXIMITY Sensor.TYPE_PROXIMITY}:
* </h3>
*
* <ul>
* <p>
* values[0]: Proximity sensor distance measured in centimeters
* </ul>
*
* <p>
* Note that some proximity sensors only support a binary "close" or "far"
* measurement. In this case, the sensor should report its maxRange value in
* the "far" state and a value less than maxRange in the "near" state.
*/ */
public final float[] values; public final float[] values;

View File

@@ -46,6 +46,30 @@ import java.util.List;
* {@link android.content.Context#getSystemService(java.lang.String) * {@link android.content.Context#getSystemService(java.lang.String)
* Context.getSystemService()} with the argument * Context.getSystemService()} with the argument
* {@link android.content.Context#SENSOR_SERVICE}. * {@link android.content.Context#SENSOR_SERVICE}.
*
* <pre class="prettyprint">
* public class SensorActivity extends Activity, implements SensorEventListener {
* private final SensorManager mSensorManager;
* private final Sensor mAccelerometer;
*
* public SensorActivity() {
* mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
* mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
* mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
* }
*
* public void onAccuracyChanged(Sensor sensor, int accuracy) {
* }
*
* public abstract void onSensorChanged(SensorEvent event) {
* }
* }
* </pre>
*
* @see SensorEventListener
* @see SensorEvent
* @see Sensor
*
*/ */
public class SensorManager public class SensorManager
{ {
@@ -57,7 +81,7 @@ public class SensorManager
/** /**
* A constant describing an orientation sensor. See * A constant describing an orientation sensor. See
* {@link android.hardware.SensorListener SensorListener} for more details. * {@link android.hardware.SensorListener SensorListener} for more details.
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -66,7 +90,7 @@ public class SensorManager
/** /**
* A constant describing an accelerometer. See * A constant describing an accelerometer. See
* {@link android.hardware.SensorListener SensorListener} for more details. * {@link android.hardware.SensorListener SensorListener} for more details.
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -75,7 +99,7 @@ public class SensorManager
/** /**
* A constant describing a temperature sensor See * A constant describing a temperature sensor See
* {@link android.hardware.SensorListener SensorListener} for more details. * {@link android.hardware.SensorListener SensorListener} for more details.
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -84,7 +108,7 @@ public class SensorManager
/** /**
* A constant describing a magnetic sensor See * A constant describing a magnetic sensor See
* {@link android.hardware.SensorListener SensorListener} for more details. * {@link android.hardware.SensorListener SensorListener} for more details.
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -93,7 +117,7 @@ public class SensorManager
/** /**
* A constant describing an ambient light sensor See * A constant describing an ambient light sensor See
* {@link android.hardware.SensorListener SensorListener} for more details. * {@link android.hardware.SensorListener SensorListener} for more details.
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -102,7 +126,7 @@ public class SensorManager
/** /**
* A constant describing a proximity sensor See * A constant describing a proximity sensor See
* {@link android.hardware.SensorListener SensorListener} for more details. * {@link android.hardware.SensorListener SensorListener} for more details.
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -111,7 +135,7 @@ public class SensorManager
/** /**
* A constant describing a Tricorder See * A constant describing a Tricorder See
* {@link android.hardware.SensorListener SensorListener} for more details. * {@link android.hardware.SensorListener SensorListener} for more details.
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -120,7 +144,7 @@ public class SensorManager
/** /**
* A constant describing an orientation sensor. See * A constant describing an orientation sensor. See
* {@link android.hardware.SensorListener SensorListener} for more details. * {@link android.hardware.SensorListener SensorListener} for more details.
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -128,7 +152,7 @@ public class SensorManager
/** /**
* A constant that includes all sensors * A constant that includes all sensors
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -136,7 +160,7 @@ public class SensorManager
/** /**
* Smallest sensor ID * Smallest sensor ID
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -144,7 +168,7 @@ public class SensorManager
/** /**
* Largest sensor ID * Largest sensor ID
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -154,7 +178,7 @@ public class SensorManager
/** /**
* Index of the X value in the array returned by * Index of the X value in the array returned by
* {@link android.hardware.SensorListener#onSensorChanged} * {@link android.hardware.SensorListener#onSensorChanged}
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -163,7 +187,7 @@ public class SensorManager
/** /**
* Index of the Y value in the array returned by * Index of the Y value in the array returned by
* {@link android.hardware.SensorListener#onSensorChanged} * {@link android.hardware.SensorListener#onSensorChanged}
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -172,7 +196,7 @@ public class SensorManager
/** /**
* Index of the Z value in the array returned by * Index of the Z value in the array returned by
* {@link android.hardware.SensorListener#onSensorChanged} * {@link android.hardware.SensorListener#onSensorChanged}
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -181,7 +205,7 @@ public class SensorManager
/** /**
* Offset to the untransformed values in the array returned by * Offset to the untransformed values in the array returned by
* {@link android.hardware.SensorListener#onSensorChanged} * {@link android.hardware.SensorListener#onSensorChanged}
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -190,7 +214,7 @@ public class SensorManager
/** /**
* Index of the untransformed X value in the array returned by * Index of the untransformed X value in the array returned by
* {@link android.hardware.SensorListener#onSensorChanged} * {@link android.hardware.SensorListener#onSensorChanged}
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -199,7 +223,7 @@ public class SensorManager
/** /**
* Index of the untransformed Y value in the array returned by * Index of the untransformed Y value in the array returned by
* {@link android.hardware.SensorListener#onSensorChanged} * {@link android.hardware.SensorListener#onSensorChanged}
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -208,7 +232,7 @@ public class SensorManager
/** /**
* Index of the untransformed Z value in the array returned by * Index of the untransformed Z value in the array returned by
* {@link android.hardware.SensorListener#onSensorChanged} * {@link android.hardware.SensorListener#onSensorChanged}
* *
* @deprecated use {@link android.hardware.Sensor Sensor} instead. * @deprecated use {@link android.hardware.Sensor Sensor} instead.
*/ */
@Deprecated @Deprecated
@@ -250,7 +274,7 @@ public class SensorManager
/** Minimum magnetic field on Earth's surface */ /** Minimum magnetic field on Earth's surface */
public static final float MAGNETIC_FIELD_EARTH_MIN = 30.0f; public static final float MAGNETIC_FIELD_EARTH_MIN = 30.0f;
/** Maximum luminance of sunlight in lux */ /** Maximum luminance of sunlight in lux */
public static final float LIGHT_SUNLIGHT_MAX = 120000.0f; public static final float LIGHT_SUNLIGHT_MAX = 120000.0f;
/** luminance of sunlight in lux */ /** luminance of sunlight in lux */
@@ -268,7 +292,7 @@ public class SensorManager
/** luminance at night with no moon in lux*/ /** luminance at night with no moon in lux*/
public static final float LIGHT_NO_MOON = 0.001f; public static final float LIGHT_NO_MOON = 0.001f;
/** get sensor data as fast as possible */ /** get sensor data as fast as possible */
public static final int SENSOR_DELAY_FASTEST = 0; public static final int SENSOR_DELAY_FASTEST = 0;
/** rate suitable for games */ /** rate suitable for games */
@@ -673,11 +697,14 @@ public class SensorManager
* Make multiple calls to get sensors of different types or use * Make multiple calls to get sensors of different types or use
* {@link android.hardware.Sensor#TYPE_ALL Sensor.TYPE_ALL} to get all the * {@link android.hardware.Sensor#TYPE_ALL Sensor.TYPE_ALL} to get all the
* sensors. * sensors.
* *
* @param type * @param type
* of sensors requested * of sensors requested
* *
* @return a list of sensors matching the asked type. * @return a list of sensors matching the asked type.
*
* @see #getDefaultSensor(int)
* @see Sensor
*/ */
public List<Sensor> getSensorList(int type) { public List<Sensor> getSensorList(int type) {
// cache the returned lists the first time // cache the returned lists the first time
@@ -707,11 +734,14 @@ public class SensorManager
* returned sensor could be a composite sensor, and its data could be * returned sensor could be a composite sensor, and its data could be
* averaged or filtered. If you need to access the raw sensors use * averaged or filtered. If you need to access the raw sensors use
* {@link SensorManager#getSensorList(int) getSensorList}. * {@link SensorManager#getSensorList(int) getSensorList}.
* *
* @param type * @param type
* of sensors requested * of sensors requested
* *
* @return the default sensors matching the asked type. * @return the default sensors matching the asked type.
*
* @see #getSensorList(int)
* @see Sensor
*/ */
public Sensor getDefaultSensor(int type) { public Sensor getDefaultSensor(int type) {
// TODO: need to be smarter, for now, just return the 1st sensor // TODO: need to be smarter, for now, just return the 1st sensor
@@ -721,17 +751,17 @@ public class SensorManager
/** /**
* Registers a listener for given sensors. * Registers a listener for given sensors.
* *
* @deprecated This method is deprecated, use * @deprecated This method is deprecated, use
* {@link SensorManager#registerListener(SensorEventListener, Sensor, int)} * {@link SensorManager#registerListener(SensorEventListener, Sensor, int)}
* instead. * instead.
* *
* @param listener * @param listener
* sensor listener object * sensor listener object
* *
* @param sensors * @param sensors
* a bit masks of the sensors to register to * a bit masks of the sensors to register to
* *
* @return <code>true</code> if the sensor is supported and successfully * @return <code>true</code> if the sensor is supported and successfully
* enabled * enabled
*/ */
@@ -742,24 +772,24 @@ public class SensorManager
/** /**
* Registers a SensorListener for given sensors. * Registers a SensorListener for given sensors.
* *
* @deprecated This method is deprecated, use * @deprecated This method is deprecated, use
* {@link SensorManager#registerListener(SensorEventListener, Sensor, int)} * {@link SensorManager#registerListener(SensorEventListener, Sensor, int)}
* instead. * instead.
* *
* @param listener * @param listener
* sensor listener object * sensor listener object
* *
* @param sensors * @param sensors
* a bit masks of the sensors to register to * a bit masks of the sensors to register to
* *
* @param rate * @param rate
* rate of events. This is only a hint to the system. events may be * rate of events. This is only a hint to the system. events may be
* received faster or slower than the specified rate. Usually events * received faster or slower than the specified rate. Usually events
* are received faster. The value must be one of * are received faster. The value must be one of
* {@link #SENSOR_DELAY_NORMAL}, {@link #SENSOR_DELAY_UI}, * {@link #SENSOR_DELAY_NORMAL}, {@link #SENSOR_DELAY_UI},
* {@link #SENSOR_DELAY_GAME}, or {@link #SENSOR_DELAY_FASTEST}. * {@link #SENSOR_DELAY_GAME}, or {@link #SENSOR_DELAY_FASTEST}.
* *
* @return <code>true</code> if the sensor is supported and successfully * @return <code>true</code> if the sensor is supported and successfully
* enabled * enabled
*/ */
@@ -819,14 +849,14 @@ public class SensorManager
/** /**
* Unregisters a listener for the sensors with which it is registered. * Unregisters a listener for the sensors with which it is registered.
* *
* @deprecated This method is deprecated, use * @deprecated This method is deprecated, use
* {@link SensorManager#unregisterListener(SensorEventListener, Sensor)} * {@link SensorManager#unregisterListener(SensorEventListener, Sensor)}
* instead. * instead.
* *
* @param listener * @param listener
* a SensorListener object * a SensorListener object
* *
* @param sensors * @param sensors
* a bit masks of the sensors to unregister from * a bit masks of the sensors to unregister from
*/ */
@@ -891,11 +921,11 @@ public class SensorManager
/** /**
* Unregisters a listener for all sensors. * Unregisters a listener for all sensors.
* *
* @deprecated This method is deprecated, use * @deprecated This method is deprecated, use
* {@link SensorManager#unregisterListener(SensorEventListener)} * {@link SensorManager#unregisterListener(SensorEventListener)}
* instead. * instead.
* *
* @param listener * @param listener
* a SensorListener object * a SensorListener object
*/ */
@@ -906,12 +936,16 @@ public class SensorManager
/** /**
* Unregisters a listener for the sensors with which it is registered. * Unregisters a listener for the sensors with which it is registered.
* *
* @param listener * @param listener
* a SensorEventListener object * a SensorEventListener object
*
* @param sensor * @param sensor
* the sensor to unregister from * the sensor to unregister from
* *
* @see #unregisterListener(SensorEventListener)
* @see #registerListener(SensorEventListener, Sensor, int)
*
*/ */
public void unregisterListener(SensorEventListener listener, Sensor sensor) { public void unregisterListener(SensorEventListener listener, Sensor sensor) {
unregisterListener((Object)listener, sensor); unregisterListener((Object)listener, sensor);
@@ -919,10 +953,13 @@ public class SensorManager
/** /**
* Unregisters a listener for all sensors. * Unregisters a listener for all sensors.
* *
* @param listener * @param listener
* a SensorListener object * a SensorListener object
* *
* @see #unregisterListener(SensorEventListener, Sensor)
* @see #registerListener(SensorEventListener, Sensor, int)
*
*/ */
public void unregisterListener(SensorEventListener listener) { public void unregisterListener(SensorEventListener listener) {
unregisterListener((Object)listener); unregisterListener((Object)listener);
@@ -931,14 +968,14 @@ public class SensorManager
/** /**
* Registers a {@link android.hardware.SensorEventListener * Registers a {@link android.hardware.SensorEventListener
* SensorEventListener} for the given sensor. * SensorEventListener} for the given sensor.
* *
* @param listener * @param listener
* A {@link android.hardware.SensorEventListener SensorEventListener} * A {@link android.hardware.SensorEventListener SensorEventListener}
* object. * object.
* *
* @param sensor * @param sensor
* The {@link android.hardware.Sensor Sensor} to register to. * The {@link android.hardware.Sensor Sensor} to register to.
* *
* @param rate * @param rate
* The rate {@link android.hardware.SensorEvent sensor events} are * The rate {@link android.hardware.SensorEvent sensor events} are
* delivered at. This is only a hint to the system. Events may be * delivered at. This is only a hint to the system. Events may be
@@ -946,10 +983,14 @@ public class SensorManager
* are received faster. The value must be one of * are received faster. The value must be one of
* {@link #SENSOR_DELAY_NORMAL}, {@link #SENSOR_DELAY_UI}, * {@link #SENSOR_DELAY_NORMAL}, {@link #SENSOR_DELAY_UI},
* {@link #SENSOR_DELAY_GAME}, or {@link #SENSOR_DELAY_FASTEST}. * {@link #SENSOR_DELAY_GAME}, or {@link #SENSOR_DELAY_FASTEST}.
* *
* @return <code>true</code> if the sensor is supported and successfully * @return <code>true</code> if the sensor is supported and successfully
* enabled. * enabled.
* *
* @see #registerListener(SensorEventListener, Sensor, int, Handler)
* @see #unregisterListener(SensorEventListener)
* @see #unregisterListener(SensorEventListener, Sensor)
*
*/ */
public boolean registerListener(SensorEventListener listener, Sensor sensor, int rate) { public boolean registerListener(SensorEventListener listener, Sensor sensor, int rate) {
return registerListener(listener, sensor, rate, null); return registerListener(listener, sensor, rate, null);
@@ -958,14 +999,14 @@ public class SensorManager
/** /**
* Registers a {@link android.hardware.SensorEventListener * Registers a {@link android.hardware.SensorEventListener
* SensorEventListener} for the given sensor. * SensorEventListener} for the given sensor.
* *
* @param listener * @param listener
* A {@link android.hardware.SensorEventListener SensorEventListener} * A {@link android.hardware.SensorEventListener SensorEventListener}
* object. * object.
* *
* @param sensor * @param sensor
* The {@link android.hardware.Sensor Sensor} to register to. * The {@link android.hardware.Sensor Sensor} to register to.
* *
* @param rate * @param rate
* The rate {@link android.hardware.SensorEvent sensor events} are * The rate {@link android.hardware.SensorEvent sensor events} are
* delivered at. This is only a hint to the system. Events may be * delivered at. This is only a hint to the system. Events may be
@@ -973,14 +1014,18 @@ public class SensorManager
* are received faster. The value must be one of * are received faster. The value must be one of
* {@link #SENSOR_DELAY_NORMAL}, {@link #SENSOR_DELAY_UI}, * {@link #SENSOR_DELAY_NORMAL}, {@link #SENSOR_DELAY_UI},
* {@link #SENSOR_DELAY_GAME}, or {@link #SENSOR_DELAY_FASTEST}. * {@link #SENSOR_DELAY_GAME}, or {@link #SENSOR_DELAY_FASTEST}.
* *
* @param handler * @param handler
* The {@link android.os.Handler Handler} the * The {@link android.os.Handler Handler} the
* {@link android.hardware.SensorEvent sensor events} will be * {@link android.hardware.SensorEvent sensor events} will be
* delivered to. * delivered to.
* *
* @return true if the sensor is supported and successfully enabled. * @return true if the sensor is supported and successfully enabled.
* *
* @see #registerListener(SensorEventListener, Sensor, int)
* @see #unregisterListener(SensorEventListener)
* @see #unregisterListener(SensorEventListener, Sensor)
*
*/ */
public boolean registerListener(SensorEventListener listener, Sensor sensor, int rate, public boolean registerListener(SensorEventListener listener, Sensor sensor, int rate,
Handler handler) { Handler handler) {
@@ -1107,7 +1152,7 @@ public class SensorManager
* world's coordinate system which is defined as a direct orthonormal basis, * world's coordinate system which is defined as a direct orthonormal basis,
* where: * where:
* </p> * </p>
* *
* <ul> * <ul>
* <li>X is defined as the vector product <b>Y.Z</b> (It is tangential to * <li>X is defined as the vector product <b>Y.Z</b> (It is tangential to
* the ground at the device's current location and roughly points East).</li> * the ground at the device's current location and roughly points East).</li>
@@ -1115,6 +1160,12 @@ public class SensorManager
* points towards the magnetic North Pole.</li> * points towards the magnetic North Pole.</li>
* <li>Z points towards the sky and is perpendicular to the ground.</li> * <li>Z points towards the sky and is perpendicular to the ground.</li>
* </ul> * </ul>
*
* <p>
* <center><img src="../../../images/axis_globe.png"
* alt="Sensors coordinate-system diagram." border="0" /></center>
* </p>
*
* <p> * <p>
* <hr> * <hr>
* <p> * <p>
@@ -1129,27 +1180,27 @@ public class SensorManager
* world's coordinate system, that is, when the device's X axis points * world's coordinate system, that is, when the device's X axis points
* toward East, the Y axis points to the North Pole and the device is facing * toward East, the Y axis points to the North Pole and the device is facing
* the sky. * the sky.
* *
* <p> * <p>
* <b>I</b> is a rotation matrix transforming the geomagnetic vector into * <b>I</b> is a rotation matrix transforming the geomagnetic vector into
* the same coordinate space as gravity (the world's coordinate space). * the same coordinate space as gravity (the world's coordinate space).
* <b>I</b> is a simple rotation around the X axis. The inclination angle in * <b>I</b> is a simple rotation around the X axis. The inclination angle in
* radians can be computed with {@link #getInclination}. * radians can be computed with {@link #getInclination}.
* <hr> * <hr>
* *
* <p> * <p>
* Each matrix is returned either as a 3x3 or 4x4 row-major matrix depending * Each matrix is returned either as a 3x3 or 4x4 row-major matrix depending
* on the length of the passed array: * on the length of the passed array:
* <p> * <p>
* <u>If the array length is 16:</u> * <u>If the array length is 16:</u>
* *
* <pre> * <pre>
* / M[ 0] M[ 1] M[ 2] M[ 3] \ * / M[ 0] M[ 1] M[ 2] M[ 3] \
* | M[ 4] M[ 5] M[ 6] M[ 7] | * | M[ 4] M[ 5] M[ 6] M[ 7] |
* | M[ 8] M[ 9] M[10] M[11] | * | M[ 8] M[ 9] M[10] M[11] |
* \ M[12] M[13] M[14] M[15] / * \ M[12] M[13] M[14] M[15] /
*</pre> *</pre>
* *
* This matrix is ready to be used by OpenGL ES's * This matrix is ready to be used by OpenGL ES's
* {@link javax.microedition.khronos.opengles.GL10#glLoadMatrixf(float[], int) * {@link javax.microedition.khronos.opengles.GL10#glLoadMatrixf(float[], int)
* glLoadMatrixf(float[], int)}. * glLoadMatrixf(float[], int)}.
@@ -1161,44 +1212,44 @@ public class SensorManager
* therefore be used with OpenGL ES directly. * therefore be used with OpenGL ES directly.
* <p> * <p>
* Also note that the returned matrices always have this form: * Also note that the returned matrices always have this form:
* *
* <pre> * <pre>
* / M[ 0] M[ 1] M[ 2] 0 \ * / M[ 0] M[ 1] M[ 2] 0 \
* | M[ 4] M[ 5] M[ 6] 0 | * | M[ 4] M[ 5] M[ 6] 0 |
* | M[ 8] M[ 9] M[10] 0 | * | M[ 8] M[ 9] M[10] 0 |
* \ 0 0 0 1 / * \ 0 0 0 1 /
*</pre> *</pre>
* *
* <p> * <p>
* <u>If the array length is 9:</u> * <u>If the array length is 9:</u>
* *
* <pre> * <pre>
* / M[ 0] M[ 1] M[ 2] \ * / M[ 0] M[ 1] M[ 2] \
* | M[ 3] M[ 4] M[ 5] | * | M[ 3] M[ 4] M[ 5] |
* \ M[ 6] M[ 7] M[ 8] / * \ M[ 6] M[ 7] M[ 8] /
*</pre> *</pre>
* *
* <hr> * <hr>
* <p> * <p>
* The inverse of each matrix can be computed easily by taking its * The inverse of each matrix can be computed easily by taking its
* transpose. * transpose.
* *
* <p> * <p>
* The matrices returned by this function are meaningful only when the * The matrices returned by this function are meaningful only when the
* device is not free-falling and it is not close to the magnetic north. If * device is not free-falling and it is not close to the magnetic north. If
* the device is accelerating, or placed into a strong magnetic field, the * the device is accelerating, or placed into a strong magnetic field, the
* returned matrices may be inaccurate. * returned matrices may be inaccurate.
* *
* @param R * @param R
* is an array of 9 floats holding the rotation matrix <b>R</b> when * is an array of 9 floats holding the rotation matrix <b>R</b> when
* this function returns. R can be null. * this function returns. R can be null.
* <p> * <p>
* *
* @param I * @param I
* is an array of 9 floats holding the rotation matrix <b>I</b> when * is an array of 9 floats holding the rotation matrix <b>I</b> when
* this function returns. I can be null. * this function returns. I can be null.
* <p> * <p>
* *
* @param gravity * @param gravity
* is an array of 3 floats containing the gravity vector expressed in * is an array of 3 floats containing the gravity vector expressed in
* the device's coordinate. You can simply use the * the device's coordinate. You can simply use the
@@ -1208,7 +1259,7 @@ public class SensorManager
* {@link android.hardware.Sensor#TYPE_ACCELEROMETER * {@link android.hardware.Sensor#TYPE_ACCELEROMETER
* TYPE_ACCELEROMETER}. * TYPE_ACCELEROMETER}.
* <p> * <p>
* *
* @param geomagnetic * @param geomagnetic
* is an array of 3 floats containing the geomagnetic vector * is an array of 3 floats containing the geomagnetic vector
* expressed in the device's coordinate. You can simply use the * expressed in the device's coordinate. You can simply use the
@@ -1217,10 +1268,14 @@ public class SensorManager
* {@link android.hardware.Sensor Sensor} of type * {@link android.hardware.Sensor Sensor} of type
* {@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD * {@link android.hardware.Sensor#TYPE_MAGNETIC_FIELD
* TYPE_MAGNETIC_FIELD}. * TYPE_MAGNETIC_FIELD}.
* *
* @return <code>true</code> on success, <code>false</code> on failure (for * @return <code>true</code> on success, <code>false</code> on failure (for
* instance, if the device is in free fall). On failure the output * instance, if the device is in free fall). On failure the output
* matrices are not modified. * matrices are not modified.
*
* @see #getInclination(float[])
* @see #getOrientation(float[], float[])
* @see #remapCoordinateSystem(float[], int, int, float[])
*/ */
public static boolean getRotationMatrix(float[] R, float[] I, public static boolean getRotationMatrix(float[] R, float[] I,
@@ -1289,16 +1344,22 @@ public class SensorManager
/** /**
* Computes the geomagnetic inclination angle in radians from the * Computes the geomagnetic inclination angle in radians from the
* inclination matrix <b>I</b> returned by {@link #getRotationMatrix}. * inclination matrix <b>I</b> returned by {@link #getRotationMatrix}.
* *
* @param I * @param I
* inclination matrix see {@link #getRotationMatrix}. * inclination matrix see {@link #getRotationMatrix}.
*
* @return The geomagnetic inclination angle in radians. * @return The geomagnetic inclination angle in radians.
*
* @see #getRotationMatrix(float[], float[], float[], float[])
* @see #getOrientation(float[], float[])
* @see GeomagneticField
*
*/ */
public static float getInclination(float[] I) { public static float getInclination(float[] I) {
if (I.length == 9) { if (I.length == 9) {
return (float)Math.atan2(I[5], I[4]); return (float)Math.atan2(I[5], I[4]);
} else { } else {
return (float)Math.atan2(I[6], I[5]); return (float)Math.atan2(I[6], I[5]);
} }
} }
@@ -1309,7 +1370,7 @@ public class SensorManager
* compute the three orientation angles of the device (see * compute the three orientation angles of the device (see
* {@link #getOrientation}) in a different coordinate system. * {@link #getOrientation}) in a different coordinate system.
* </p> * </p>
* *
* <p> * <p>
* When the rotation matrix is used for drawing (for instance with OpenGL * When the rotation matrix is used for drawing (for instance with OpenGL
* ES), it usually <b>doesn't need</b> to be transformed by this function, * ES), it usually <b>doesn't need</b> to be transformed by this function,
@@ -1319,60 +1380,62 @@ public class SensorManager
* is generally free to rotate their screen, you often should consider the * is generally free to rotate their screen, you often should consider the
* rotation in deciding the parameters to use here. * rotation in deciding the parameters to use here.
* </p> * </p>
* *
* <p> * <p>
* <u>Examples:</u> * <u>Examples:</u>
* <p> * <p>
* *
* <ul> * <ul>
* <li>Using the camera (Y axis along the camera's axis) for an augmented * <li>Using the camera (Y axis along the camera's axis) for an augmented
* reality application where the rotation angles are needed:</li> * reality application where the rotation angles are needed:</li>
* *
* <p> * <p>
* <ul> * <ul>
* <code>remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR);</code> * <code>remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR);</code>
* </ul> * </ul>
* </p> * </p>
* *
* <li>Using the device as a mechanical compass when rotation is * <li>Using the device as a mechanical compass when rotation is
* {@link android.view.Surface#ROTATION_90 Surface.ROTATION_90}:</li> * {@link android.view.Surface#ROTATION_90 Surface.ROTATION_90}:</li>
* *
* <p> * <p>
* <ul> * <ul>
* <code>remapCoordinateSystem(inR, AXIS_Y, AXIS_MINUS_X, outR);</code> * <code>remapCoordinateSystem(inR, AXIS_Y, AXIS_MINUS_X, outR);</code>
* </ul> * </ul>
* </p> * </p>
* *
* Beware of the above example. This call is needed only to account for a * Beware of the above example. This call is needed only to account for a
* rotation from its natural orientation when calculating the rotation * rotation from its natural orientation when calculating the rotation
* angles (see {@link #getOrientation}). If the rotation matrix is also used * angles (see {@link #getOrientation}). If the rotation matrix is also used
* for rendering, it may not need to be transformed, for instance if your * for rendering, it may not need to be transformed, for instance if your
* {@link android.app.Activity Activity} is running in landscape mode. * {@link android.app.Activity Activity} is running in landscape mode.
* </ul> * </ul>
* *
* <p> * <p>
* Since the resulting coordinate system is orthonormal, only two axes need * Since the resulting coordinate system is orthonormal, only two axes need
* to be specified. * to be specified.
* *
* @param inR * @param inR
* the rotation matrix to be transformed. Usually it is the matrix * the rotation matrix to be transformed. Usually it is the matrix
* returned by {@link #getRotationMatrix}. * returned by {@link #getRotationMatrix}.
* *
* @param X * @param X
* defines on which world axis and direction the X axis of the device * defines on which world axis and direction the X axis of the device
* is mapped. * is mapped.
* *
* @param Y * @param Y
* defines on which world axis and direction the Y axis of the device * defines on which world axis and direction the Y axis of the device
* is mapped. * is mapped.
* *
* @param outR * @param outR
* the transformed rotation matrix. inR and outR can be the same * the transformed rotation matrix. inR and outR can be the same
* array, but it is not recommended for performance reason. * array, but it is not recommended for performance reason.
* *
* @return <code>true</code> on success. <code>false</code> if the input * @return <code>true</code> on success. <code>false</code> if the input
* parameters are incorrect, for instance if X and Y define the same * parameters are incorrect, for instance if X and Y define the same
* axis. Or if inR and outR don't have the same length. * axis. Or if inR and outR don't have the same length.
*
* @see #getRotationMatrix(float[], float[], float[], float[])
*/ */
public static boolean remapCoordinateSystem(float[] inR, int X, int Y, public static boolean remapCoordinateSystem(float[] inR, int X, int Y,
@@ -1464,14 +1527,23 @@ public class SensorManager
* <li>values[2]: <i>roll</i>, rotation around the Y axis.</li> * <li>values[2]: <i>roll</i>, rotation around the Y axis.</li>
* </ul> * </ul>
* <p> * <p>
* <center><img src="../../../images/axis_device.png"
* alt="Sensors coordinate-system diagram." border="0" /></center>
* </p>
* <p>
* All three angles above are in <b>radians</b> and <b>positive</b> in the * All three angles above are in <b>radians</b> and <b>positive</b> in the
* <b>counter-clockwise</b> direction. * <b>counter-clockwise</b> direction.
* *
* @param R * @param R
* rotation matrix see {@link #getRotationMatrix}. * rotation matrix see {@link #getRotationMatrix}.
*
* @param values * @param values
* an array of 3 floats to hold the result. * an array of 3 floats to hold the result.
*
* @return The array values passed as argument. * @return The array values passed as argument.
*
* @see #getRotationMatrix(float[], float[], float[], float[])
* @see GeomagneticField
*/ */
public static float[] getOrientation(float[] R, float values[]) { public static float[] getOrientation(float[] R, float values[]) {
/* /*
@@ -1480,12 +1552,12 @@ public class SensorManager
* | R[ 4] R[ 5] R[ 6] 0 | * | R[ 4] R[ 5] R[ 6] 0 |
* | R[ 8] R[ 9] R[10] 0 | * | R[ 8] R[ 9] R[10] 0 |
* \ 0 0 0 1 / * \ 0 0 0 1 /
* *
* 3x3 (length=9) case: * 3x3 (length=9) case:
* / R[ 0] R[ 1] R[ 2] \ * / R[ 0] R[ 1] R[ 2] \
* | R[ 3] R[ 4] R[ 5] | * | R[ 3] R[ 4] R[ 5] |
* \ R[ 6] R[ 7] R[ 8] / * \ R[ 6] R[ 7] R[ 8] /
* *
*/ */
if (R.length == 9) { if (R.length == 9) {
values[0] = (float)Math.atan2(R[1], R[4]); values[0] = (float)Math.atan2(R[1], R[4]);
@@ -1647,7 +1719,7 @@ public class SensorManager
} }
} }
} }
class LmsFilter { class LmsFilter {
private static final int SENSORS_RATE_MS = 20; private static final int SENSORS_RATE_MS = 20;
private static final int COUNT = 12; private static final int COUNT = 12;
@@ -1715,7 +1787,7 @@ public class SensorManager
} }
} }
private static native void nativeClassInit(); private static native void nativeClassInit();
private static native int sensors_module_init(); private static native int sensors_module_init();

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB