de.unikassel.android.sdcframework.devices
Class AbstractLocationDevice

Package class diagram package AbstractLocationDevice
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.AbstractLocationDevice
All Implemented Interfaces:
SampleProvidingSensorDevice, SensorDevice, VisitableDevice
Direct Known Subclasses:
GPSDevice, NetworkLocationDevice

public abstract class AbstractLocationDevice
extends ScannerStateAwareSensorDevice
implements SampleProvidingSensorDevice

Implementation of an abstract location provider based sensor device as sample providing device.

See Also:
ScannerStateAwareSensorDevice, SampleProvidingSensorDevice

Nested Class Summary
private  class AbstractLocationDevice.ProviderLocationListener
          Internal location listener implementation
private  class AbstractLocationDevice.ProviderStateListener
          Internal location provider state listener implementation
 
Field Summary
private  Context context
          The service application context
private  LocationSampleData currentSampleData
          The current available sample
private  boolean isLocationListenerRegistered
          Flag if location listener is registered
private  boolean isStateListenerRegistered
          Flag if state listener is registered
private  AbstractLocationDevice.ProviderLocationListener locationListener
          The GPS location listener used for sampling
private static int LOWER_FREQUENCY
          The lower frequency to avoid battery drain
private  String provider
          The location provider
private  AbstractLocationDevice.ProviderStateListener stateListener
          The GPS state listener used for adding/removal of location listener
 
Constructor Summary
AbstractLocationDevice(Context context, SensorDeviceIdentifier id, String provider)
          Constructor
 
Method Summary
 void doHandleLocationChanged(Location location)
          Handler for the location changed event
protected  void doSignalDeviceNotEnabledInSystem(Context applicationContext)
          Method to signal the user that the device is disabled in the system and needed by this service.
private  Context getContext()
          Getter for the context
protected abstract  SampleData getCurrentSampleData()
          Method to get the current sample data
protected abstract  int getDeviceDisabledMessageID()
          Method to get the device disabled message
protected  LocationSampleData getLocationData()
          Getter for the currentSampleData
private  AbstractLocationDevice.ProviderLocationListener getLocationListener()
          Getter for the locationListener
private  LocationManager getLocationManager()
          Getter for the locationManager
protected  int getLowerFrequency()
          The minimum frequency for location updates
protected  float getMinDistance()
          The minimum distance in meters for location updates
 Sample getSample()
          Getter for a device sample
private  AbstractLocationDevice.ProviderStateListener getStateListener()
          Getter for the stateListener
 boolean hasSample()
          Test method for a sample available
 boolean isAirplaneModeOn(Context applicationContext)
          Getter for the state of the airplaine mode
 boolean isDeviceInSystemEnabled(Context context)
          Test method for the system wide enabled state of the device
 boolean isLocationListenerRegistered()
          Getter for the isLocationListenerRegistered flag
 boolean isStateListenerRegistered()
          Getter for the isStateListenerRegistered flag
protected  void onConfigurationChanged()
          Callback to signal configuration of device has changed
 void onCreate(Context context)
          Is called when this device is created
 void onDestroy(Context context)
          Is called when the owner destroys this device
protected  void onScannerRunningStateChange(boolean isRunning, Context context)
          Handler to react on scanner state changes.
private  void registerLocationListener()
          Does register the location listener
private  void registerStateListener()
          Does register the GPS state listener
private  void setContext(Context context)
          Setter for the context
private  void setLocationListener(AbstractLocationDevice.ProviderLocationListener locationListener)
          Setter for the locationListener
private  void setLocationListenerRegistered(boolean isLocationListenerRegistered)
          Setter for the isLocationListenerRegistered flag
private  void setStateListener(AbstractLocationDevice.ProviderStateListener stateListener)
          Setter for the stateListener
 void setStateListenerRegistered(boolean isStateListenerRegistered)
          Setter for the isStateListenerRegistered flag
private  void unregisterLocationListener()
          Does unregister the location listener
private  void unregisterStateListener()
          Does unregister the GPS state listener
 
Methods inherited from class de.unikassel.android.sdcframework.devices.ScannerStateAwareSensorDevice
enableDeviceScanning
 
Methods inherited from class de.unikassel.android.sdcframework.devices.AbstractSensorDevice
accept, doHandleDeviceDisabledBySystem, doHandleDeviceEnabledBySystem, getConfiguration, getDeviceIdentifier, getScanner, isDeviceScanningEnabled, setDeviceIdentifier, setScanner, updateConfiguration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOWER_FREQUENCY

private static final int LOWER_FREQUENCY
The lower frequency to avoid battery drain

See Also:
Constant Field Values

context

private Context context
The service application context


locationListener

private AbstractLocationDevice.ProviderLocationListener locationListener
The GPS location listener used for sampling


stateListener

private AbstractLocationDevice.ProviderStateListener stateListener
The GPS state listener used for adding/removal of location listener


currentSampleData

private final LocationSampleData currentSampleData
The current available sample


isLocationListenerRegistered

private boolean isLocationListenerRegistered
Flag if location listener is registered


isStateListenerRegistered

private boolean isStateListenerRegistered
Flag if state listener is registered


provider

private final String provider
The location provider

Constructor Detail

AbstractLocationDevice

public AbstractLocationDevice(Context context,
                              SensorDeviceIdentifier id,
                              String provider)
Constructor

Parameters:
context - the context
id - the sensor device identifier
provider - the network provider
Method Detail

setContext

private final void setContext(Context context)
Setter for the context

Parameters:
context - the context to set

getContext

private final Context getContext()
Getter for the context

Returns:
the context

getLocationManager

private final LocationManager getLocationManager()
Getter for the locationManager

Returns:
the locationManager

getLocationListener

private final AbstractLocationDevice.ProviderLocationListener getLocationListener()
Getter for the locationListener

Returns:
the locationListener

setLocationListener

private final void setLocationListener(AbstractLocationDevice.ProviderLocationListener locationListener)
Setter for the locationListener

Parameters:
locationListener - the locationListener to set

setStateListener

private final void setStateListener(AbstractLocationDevice.ProviderStateListener stateListener)
Setter for the stateListener

Parameters:
stateListener - the stateListener to set

getStateListener

private final AbstractLocationDevice.ProviderStateListener getStateListener()
Getter for the stateListener

Returns:
the stateListener

isLocationListenerRegistered

public final boolean isLocationListenerRegistered()
Getter for the isLocationListenerRegistered flag

Returns:
the isLocationListenerRegistered flag

setLocationListenerRegistered

private final void setLocationListenerRegistered(boolean isLocationListenerRegistered)
Setter for the isLocationListenerRegistered flag

Parameters:
isLocationListenerRegistered - the isLocationListenerRegistered flag to set

isStateListenerRegistered

public boolean isStateListenerRegistered()
Getter for the isStateListenerRegistered flag

Returns:
the isStateListenerRegistered flag

setStateListenerRegistered

public void setStateListenerRegistered(boolean isStateListenerRegistered)
Setter for the isStateListenerRegistered flag

Parameters:
isStateListenerRegistered - the isStateListenerRegistered flag to set

registerLocationListener

private final void registerLocationListener()
Does register the location listener


getLowerFrequency

protected int getLowerFrequency()
The minimum frequency for location updates

Returns:
the minimum frequency for location updates

getMinDistance

protected float getMinDistance()
The minimum distance in meters for location updates

Returns:
the minimum distance in meters

unregisterLocationListener

private final void unregisterLocationListener()
Does unregister the location listener


registerStateListener

private final void registerStateListener()
Does register the GPS state listener


unregisterStateListener

private final void unregisterStateListener()
Does unregister the GPS state listener


doHandleLocationChanged

public final void doHandleLocationChanged(Location location)
Handler for the location changed event

Parameters:
location - the changed location

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

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

onConfigurationChanged

protected final void onConfigurationChanged()
Description copied from class: AbstractSensorDevice
Callback to signal configuration of device has changed

Overrides:
onConfigurationChanged in class ScannerStateAwareSensorDevice

onCreate

public final void onCreate(Context context)
Description copied from interface: SensorDevice
Is called when this device is created

Specified by:
onCreate in interface SensorDevice
Overrides:
onCreate in class AbstractSensorDevice
Parameters:
context - the application context

onDestroy

public final void onDestroy(Context context)
Description copied from interface: SensorDevice
Is called when the owner destroys this device

Specified by:
onDestroy in interface SensorDevice
Overrides:
onDestroy in class AbstractSensorDevice
Parameters:
context - the application context

isAirplaneModeOn

public final boolean isAirplaneModeOn(Context applicationContext)
Description copied from class: AbstractSensorDevice
Getter for the state of the airplaine mode

Overrides:
isAirplaneModeOn in class AbstractSensorDevice
Parameters:
applicationContext - the application contex
Returns:
true if enabled, false otherwise

hasSample

public boolean hasSample()
Description copied from interface: SampleProvidingSensorDevice
Test method for a sample available

Specified by:
hasSample in interface SampleProvidingSensorDevice
Returns:
true if a sample is available

getLocationData

protected LocationSampleData getLocationData()
Getter for the currentSampleData

Returns:
the currentSampleData

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()
Method to get the current sample data

Returns:
the current sample data

getDeviceDisabledMessageID

protected abstract int getDeviceDisabledMessageID()
Method to get the device disabled message

Returns:
the device disabled message