com.drismo.logic
Class LocationHandler

java.lang.Object
  extended by com.drismo.logic.LocationHandler
All Implemented Interfaces:
android.location.GpsStatus.Listener, android.location.LocationListener

public class LocationHandler
extends java.lang.Object
implements android.location.LocationListener, android.location.GpsStatus.Listener

This class handles everything related to receiving and distributing location updates to listeners which requires this service. To receive location updates, add a NewLocationListener via the registerNewLocationListener method. Don't forget to unregisterNewLocationListener the listener when finished.

See Also:
NewLocationListener, registerNewLocationListener(NewLocationListener)

Field Summary
private  android.location.LocationManager locationManager
           
private  java.util.ArrayList<NewLocationListener> newLocationListeners
           
 
Constructor Summary
LocationHandler(android.location.LocationManager lm)
          Constructor.
 
Method Summary
 void onGpsStatusChanged(int event)
          Required but not used.
 void onLocationChanged(android.location.Location loc)
          On location change, update all the listeners!
 void onProviderDisabled(java.lang.String provider)
          Required but not used.
 void onProviderEnabled(java.lang.String provider)
          Required but not used.
 void onStatusChanged(java.lang.String provider, int status, android.os.Bundle arg)
          Required but not used.
 void registerNewLocationListener(NewLocationListener listener)
          Registers a new listeners, which requires location updates.
 void startListening()
          Stars listening for GPS updates, if required.
 void stopListening()
          Stops the GPS updates.
 void unregisterNewLocationListener(NewLocationListener listener)
          Removes a listener from the update-list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

locationManager

private android.location.LocationManager locationManager

newLocationListeners

private final java.util.ArrayList<NewLocationListener> newLocationListeners
Constructor Detail

LocationHandler

public LocationHandler(android.location.LocationManager lm)
Constructor. Sets the location manager.

Parameters:
lm - Location manager.
Method Detail

startListening

public void startListening()
Stars listening for GPS updates, if required.


stopListening

public void stopListening()
Stops the GPS updates.


registerNewLocationListener

public void registerNewLocationListener(NewLocationListener listener)
Registers a new listeners, which requires location updates.

Parameters:
listener - The listener to add.

unregisterNewLocationListener

public void unregisterNewLocationListener(NewLocationListener listener)
Removes a listener from the update-list. The subject stops listening if no other listeners are present.

Parameters:
listener - The listener to remove.

onLocationChanged

public void onLocationChanged(android.location.Location loc)
On location change, update all the listeners!

Specified by:
onLocationChanged in interface android.location.LocationListener
Parameters:
loc - The new location provided.
See Also:
NewLocationListener.onNewLocation(android.location.Location)

onGpsStatusChanged

public void onGpsStatusChanged(int event)
Required but not used.

Specified by:
onGpsStatusChanged in interface android.location.GpsStatus.Listener
Parameters:
event - not used.

onProviderDisabled

public void onProviderDisabled(java.lang.String provider)
Required but not used.

Specified by:
onProviderDisabled in interface android.location.LocationListener
Parameters:
provider - not used.

onProviderEnabled

public void onProviderEnabled(java.lang.String provider)
Required but not used.

Specified by:
onProviderEnabled in interface android.location.LocationListener
Parameters:
provider - not used.

onStatusChanged

public void onStatusChanged(java.lang.String provider,
                            int status,
                            android.os.Bundle arg)
Required but not used.

Specified by:
onStatusChanged in interface android.location.LocationListener
Parameters:
provider - not used.