de.unikassel.android.sdcframework.devices
Class AbstractAndroidSensorDevice

Package class diagram package AbstractAndroidSensorDevice
java.lang.Object
  extended by de.unikassel.android.sdcframework.devices.AbstractSensorDevice
      extended by de.unikassel.android.sdcframework.devices.ScannerStateAwareSensorDevice
          extended by de.unikassel.android.sdcframework.devices.AbstractAndroidSensorDevice
All Implemented Interfaces:
SampleProvidingSensorDevice, SensorDevice, VisitableDevice
Direct Known Subclasses:
AccelerometerDevice, GyroscopeDevice, MagneticFieldDevice, OrientationDevice, PressureDevice, SamplingCausingAndroidSensorDevice

public abstract class AbstractAndroidSensorDevice
extends ScannerStateAwareSensorDevice
implements SampleProvidingSensorDevice

Base class for an Android Sensor type.

Does provide the sensor listener and the logic for listener registration depending on the scanner running state. Any extending class has just to implement the abstract handler methods for sensor changes and the methods from the SampleProvidingSensorDevice interface.

See Also:
AccelerometerDevice

Field Summary
private  Sensor sensor
          The corresponding Android sensor
private  int sensorDelay
          The sensor delay
private  SensorEventListener sensorListener
          The sensor listener
 
Constructor Summary
AbstractAndroidSensorDevice(SensorDeviceIdentifier deviceId, int androidSensorType, Context context, int sensorDelay)
          Constructor
 
Method Summary
protected  void doHandleSensorAccuracyChanged(Sensor sensor, int accuracy)
          Handler for the sensor accuracy changed event
protected abstract  void doHandleSensorChanged(SensorEvent event)
          Handler for the sensor changed event ( with incoming updated sensor data )
protected  void doSignalDeviceNotEnabledInSystem(Context applicationContext)
          Method to signal the user that the device is disabled in the system and needed by this service.
protected abstract  SampleData getCurrentSampleData()
          Getter for the current sample data
 SensorEventListener getListener()
          Getter for the sensor listener
 Sample getSample()
          Getter for a device sample
 Sensor getSensor()
          Getter for the sensor
 boolean isDeviceInSystemEnabled(Context context)
          Test method for the system wide enabled state of the device
protected  void onScannerRunningStateChange(boolean isRunning, Context context)
          Handler to react on scanner state changes.
private  void registerListener(Context context)
          Does register the sensor listener for the device type
private  void setListener(SensorEventListener sensorListener)
          Setter for the sensor event listener
private  void unregisterListener(Context context)
          Does unregister the sensor listener for the device type
 
Methods inherited from class de.unikassel.android.sdcframework.devices.ScannerStateAwareSensorDevice
enableDeviceScanning, onConfigurationChanged
 
Methods inherited from class de.unikassel.android.sdcframework.devices.AbstractSensorDevice
accept, doHandleDeviceDisabledBySystem, doHandleDeviceEnabledBySystem, getConfiguration, getDeviceIdentifier, getScanner, isAirplaneModeOn, isDeviceScanningEnabled, onCreate, onDestroy, setDeviceIdentifier, setScanner, updateConfiguration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.unikassel.android.sdcframework.devices.facade.SampleProvidingSensorDevice
hasSample
 

Field Detail

sensorListener

private SensorEventListener sensorListener
The sensor listener


sensor

private final Sensor sensor
The corresponding Android sensor


sensorDelay

private final int sensorDelay
The sensor delay

Constructor Detail

AbstractAndroidSensorDevice

public AbstractAndroidSensorDevice(SensorDeviceIdentifier deviceId,
                                   int androidSensorType,
                                   Context context,
                                   int sensorDelay)
                            throws InvalidParameterException
Constructor

Parameters:
deviceId - the device identifier
androidSensorType - the Android sensor type
context - the application context
sensorDelay - the sensor delay
Throws:
InvalidParameterException - if sensor type is unavailable or unknown
Method Detail

setListener

private final void setListener(SensorEventListener sensorListener)
Setter for the sensor event listener

Parameters:
sensorListener - the sensor event listener

getListener

public final SensorEventListener getListener()
Getter for the sensor listener

Returns:
the sensor listener

getSensor

public final Sensor getSensor()
Getter for the sensor

Returns:
the sensor

isDeviceInSystemEnabled

public final boolean isDeviceInSystemEnabled(Context context)
Description copied from interface: SensorDevice
Test method for the system wide enabled state of the device

Specified by:
isDeviceInSystemEnabled in interface SensorDevice
Parameters:
context - the application context
Returns:
true if device is enabled in system, false otherwise

doSignalDeviceNotEnabledInSystem

protected final void doSignalDeviceNotEnabledInSystem(Context applicationContext)
Description copied from class: AbstractSensorDevice
Method to signal the user that the device is disabled in the system and needed by this service.
This method is called from the handler AbstractSensorDevice.doHandleDeviceDisabledBySystem(android.content.Context) to react on system state changes from enabled to disabled.
The implementation depends on the concrete device.

Specified by:
doSignalDeviceNotEnabledInSystem in class AbstractSensorDevice
Parameters:
applicationContext - the application context

registerListener

private final void registerListener(Context context)
Does register the sensor listener for the device type

Parameters:
context - the application context

unregisterListener

private final void unregisterListener(Context context)
Does unregister the sensor listener for the device type

Parameters:
context - the application context

onScannerRunningStateChange

protected final void onScannerRunningStateChange(boolean isRunning,
                                                 Context context)
Description copied from class: ScannerStateAwareSensorDevice
Handler to react on scanner state changes. It is called after each state change and signals the new running state

Specified by:
onScannerRunningStateChange in class ScannerStateAwareSensorDevice
Parameters:
isRunning - the current scanner state after state change
context - the context

doHandleSensorChanged

protected abstract void doHandleSensorChanged(SensorEvent event)
Handler for the sensor changed event ( with incoming updated sensor data )

Parameters:
event - the sensor event to handle

doHandleSensorAccuracyChanged

protected void doHandleSensorAccuracyChanged(Sensor sensor,
                                             int accuracy)
Handler for the sensor accuracy changed event

Parameters:
sensor - the sensor
accuracy - the accuracy

getSample

public final Sample getSample()
Description copied from interface: SampleProvidingSensorDevice
Getter for a device sample

Specified by:
getSample in interface SampleProvidingSensorDevice
Returns:
a sample of the device

getCurrentSampleData

protected abstract SampleData getCurrentSampleData()
Getter for the current sample data

Returns:
the current sample data