FLX will provide an API for using and utilising Android sensors. The following sensors are currently supported:
- Acceleration Sensor
- Ambient Temperature Sensor (air temperature sensor)
- Gravity Sensor
- Light Sensor
- Linear Acceleration Sensor
- Pressure sensor
- Significant Motion Sensor
Integration to sensors is based on Observer pattern. Sensors are used as Observables and Callbacks are used as observers. Observers subscribe to sensors as Observables. Subscribing produces a Subscription which can be used to start/pause/resume/stop receiving of sensor events via the callback. The following is an example of how to subscribe to the acceleration sensor that produces three values: acceleration along x, y, and z axis.

- A reference to AccelerationObservable, which wraps the acceleration Sensor, is obtained and stored as value sensor.
- A Callback is created with callback Code (see below) and three callback variables: x, y, z.
- Callback subscribes as an observer to sensor observable. A reference to a Subscription instance is returned and it is stored to value subscription so that the instance functions of Subscription instance can be invoked later on.
- Receiving of acceleration events via callback is started by invoking instance function (Subscription .start). Other control functions are:
- (Subscription .pause): pause receiving
- (Subscription .resume): resume receiving
- (Subscription .stop): stop receiving (and unsubscribe)

- The code of the accelerator sensor callback-
- Callback parameter x: Acceleration along x-axis as a Float value.
- Callback parameter y: Acceleration along y-axis as a Float value.
- Callback parameter z: Acceleration along z-axis as a Float value.
- Received values are printed
Sensor API Functions
FLX’s current Sensor API consists of the following sensor specific functions and of some more generic Observer pattern related functions:

Creates an AccelerationObservable
that wraps the SensorListener
for acceleration sensor.
Returns: An AccelerationObservable
which can be subscribed with a Callback
.

Creates an AmbientTemperatureObservable
that wraps the SensorListener
for ambient temperature (air temperature) sensor.
Returns: An AmbientTemperatureObservable
which can be subscribed with a Callback
.

Creates an GravityObservable
that wraps the SensorListener
for gravity sensor.
Returns: An GravityObservable
which can be subscribed with a Callback
.

Creates an LightObservable
that wraps the SensorListener
for light sensor.
Returns: An LightObservable
which can be subscribed with a Callback
.

Creates an LinearAccelerationObservable
that wraps the SensorListener
for linear acceleration sensor.
Returns: An LinearAccelerationObservable
which can be subscribed with a Callback
.

Creates an PressureObservable
that wraps the SensorListener
for linear acceleration sensor.
Returns: An PressureObservable
which can be subscribed with a Callback
.

Creates an SignificantMotionObservable
that wraps the SensorListener
for linear acceleration sensor.
Returns: An SignificantMotionObservable
which can be subscribed with a Callback
.

Subscribes the given observer
to receive a stream of values from the given observable
. This function is not exactly part of Sensors API, but more generic, Observer pattern related function.
observable
– anObservable
, e.g.,AccelerationObservable
observer
– aCallback
which needs to have a callback parameter declared for each individual value produced by the observable in a single event. For instance,AccelerationObservable
produces three values for each sensor event: acceleration along x-, y-, and z-axis.
Returns: A Subscription
which can be started, paused, resumed, stopped, and unsubsribed.

Unsubscribes the given subscription
so that the Callback
based observer will no longer receive a stream of values from the subscriber Observer
. This function is not exactly part of Sensors API, but more generic, Observer pattern related function.
subscription
– aSubscription

Starts the receiving of events from the observable referenced by the given subscription
. This function is not exactly part of Sensors API, but more generic, Observer pattern related function.
subscription
– aSubscription

Pauses the receiving of events from the observable referenced by the given subscription
. This function is not exactly part of Sensors API, but more generic, Observer pattern related function.
subscription
– aSubscription

Resumes the receiving of events from the observable referenced by the given subscription
. This function is not exactly part of Sensors API, but more generic, Observer pattern related function.
subscription
– aSubscription

Stops the receiving of events from the observable referenced by the given subscription
. Invocation of this function also implicitly invokes the (Subscription .unsubscribe) function. This function is not exactly part of Sensors API, but more generic, Observer pattern related function.
subscription
– aSubscription