org.android.activityminer.logic.devices
Class LocationDataSource

Package class diagram package LocationDataSource
java.lang.Object
  extended by org.android.activityminer.logic.util.AbstractActivatableComponentImpl
      extended by org.android.activityminer.logic.devices.LocationDataSource
All Implemented Interfaces:
SensorDataSource<NetworkLocationData>, ActivatableComponent

public final class LocationDataSource
extends AbstractActivatableComponentImpl
implements SensorDataSource<NetworkLocationData>

Implementation of the location data source, using the location manager to get location information form the gps or network provider.


Nested Class Summary
private  class LocationDataSource.InternalLoactionListener
          The location listener.
 
Field Summary
private  LocationDataSource.InternalLoactionListener activeLocationListener
          The listener for active location providers.
private  List<String> activeProviders
          The list of available providers
private  LocationDataCache cache
          The data cache to hold samples for scan access.
private  Context context
          The Android context
private  Location currentSample
          The most recent sample
private  long lowerFrequency
          The lower frequency for location updates (depends on the sample rate )
private  LocationDataSource.InternalLoactionListener passiveLocationListener
          The listener for the passive location provider.
private  Object waitLock
          The wait lock for synchronization on new location fixes on activation.
 
Constructor Summary
LocationDataSource(Context context, long sampleRate)
          Constructor
 
Method Summary
 int getAvailableProviderCount()
          Getter for the count of available active providers.
protected  Location getBestLocation(Location location, Location currentBestLocation)
          Determines whether one Location reading is better than the current Location fix.
private  boolean isPassiveProvider(String provider)
          Test method for the passive provider
private  boolean isProviderEnabled(LocationManager locationManager, String provider)
          Test method for availability of a provider.
private  boolean isSameProvider(String provider1, String provider2)
          Checks whether two providers are the same.
protected  void onActivationStateChange(boolean active)
          Handler for activation state changes
 void onDestroy()
          This method is for cleanup in case of termination.
private  void onLocationChanged(Location location)
          Handler for location changes
private  void onProviderDisabled(String provider)
          Handler for provider disabled events.
private  void onProviderEnabled(String provider)
          Handler for provider enabled events
private  void registerListener(LocationManager locationManager, String provider)
          Does register the active provider listener for the given provider.
private  void registerProviderListeners()
          Does register the sensor listener for the device type
 void setSampleRate(long sampleRate)
          Setter for the actual sample rate
 NetworkLocationData takeSample(Long ts)
          Getter for the current sample
private  void unregisterProviderListeners()
          Does unregister the sensor listener for the device type
private  void updateAvailableProviders()
          Does update the list of available providers.
 void waitForActualLocationFix()
          This method can be called from the sample taking process to synchronize for the next new location fix.
 
Methods inherited from class org.android.activityminer.logic.util.AbstractActivatableComponentImpl
isActive, setActivationState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

activeLocationListener

private final LocationDataSource.InternalLoactionListener activeLocationListener
The listener for active location providers.


passiveLocationListener

private final LocationDataSource.InternalLoactionListener passiveLocationListener
The listener for the passive location provider.


context

private final Context context
The Android context


currentSample

private Location currentSample
The most recent sample


waitLock

private final Object waitLock
The wait lock for synchronization on new location fixes on activation.


lowerFrequency

private long lowerFrequency
The lower frequency for location updates (depends on the sample rate )


activeProviders

private final List<String> activeProviders
The list of available providers


cache

private final LocationDataCache cache
The data cache to hold samples for scan access.

Constructor Detail

LocationDataSource

public LocationDataSource(Context context,
                          long sampleRate)
Constructor

Parameters:
context - the context
sampleRate - the sample rate
Method Detail

setSampleRate

public final void setSampleRate(long sampleRate)
Setter for the actual sample rate

Parameters:
sampleRate - the actual sample rate to set

registerProviderListeners

private final void registerProviderListeners()
Does register the sensor listener for the device type


registerListener

private final void registerListener(LocationManager locationManager,
                                    String provider)
Does register the active provider listener for the given provider.

Parameters:
locationManager - the location manager instance
provider - the provider

updateAvailableProviders

private final void updateAvailableProviders()
Does update the list of available providers.


isProviderEnabled

private final boolean isProviderEnabled(LocationManager locationManager,
                                        String provider)
Test method for availability of a provider.

Parameters:
locationManager - the location manager
provider - the provider to test for
Returns:
true if provider is available and enabled

unregisterProviderListeners

private final void unregisterProviderListeners()
Does unregister the sensor listener for the device type


getBestLocation

protected final Location getBestLocation(Location location,
                                         Location currentBestLocation)
Determines whether one Location reading is better than the current Location fix. (source: http://developer.android.com/guide/topics/location/obtaining-user- location.html)

Parameters:
location - The new Location that you want to evaluate
currentBestLocation - The current Location fix, to which you want to compare the new one
Returns:
true if the location is better

isSameProvider

private final boolean isSameProvider(String provider1,
                                     String provider2)
Checks whether two providers are the same.

Parameters:
provider1 - first provider
provider2 - second provider
Returns:
true of both are the same

onLocationChanged

private final void onLocationChanged(Location location)
Handler for location changes

Parameters:
location - the location

takeSample

public final NetworkLocationData takeSample(Long ts)
Description copied from interface: SensorDataSource
Getter for the current sample

Specified by:
takeSample in interface SensorDataSource<NetworkLocationData>
Parameters:
ts - the requested time stamp
Returns:
the current sample

onProviderEnabled

private final void onProviderEnabled(String provider)
Handler for provider enabled events

Parameters:
provider - the provider

onProviderDisabled

private final void onProviderDisabled(String provider)
Handler for provider disabled events.

Parameters:
provider - the provider

isPassiveProvider

private final boolean isPassiveProvider(String provider)
Test method for the passive provider

Parameters:
provider - the provider
Returns:
true if the provider is the passive provider, false otherwise

onActivationStateChange

protected final void onActivationStateChange(boolean active)
Description copied from class: AbstractActivatableComponentImpl
Handler for activation state changes

Specified by:
onActivationStateChange in class AbstractActivatableComponentImpl
Parameters:
active - the new activation state

getAvailableProviderCount

public final int getAvailableProviderCount()
Getter for the count of available active providers.

Returns:
the count of available active providers

waitForActualLocationFix

public final void waitForActualLocationFix()
This method can be called from the sample taking process to synchronize for the next new location fix.


onDestroy

public final void onDestroy()
Description copied from interface: SensorDataSource
This method is for cleanup in case of termination.

Specified by:
onDestroy in interface SensorDataSource<NetworkLocationData>