org.j4me.bluetoothgps
Class MockLocationProvider

java.lang.Object
  extended by org.j4me.bluetoothgps.LocationProvider
      extended by org.j4me.bluetoothgps.MockLocationProvider

public class MockLocationProvider
extends LocationProvider

A LocationProvider for testing MIDlets. Methods on this class can set locations manually.

Make sure the MockLocationProvider is not referenced in anything but your test code. Then the obfuscator will remove this class from the final Jar.

See Also:
LocationProvider

Field Summary
 
Fields inherited from class org.j4me.bluetoothgps.LocationProvider
AVAILABLE, OUT_OF_SERVICE, TEMPORARILY_UNAVAILABLE
 
Constructor Summary
MockLocationProvider()
          Constructs a mock location provider.
 
Method Summary
 void close()
          This is a no-op for the mock location provider.
protected  Location getLastKnownLocationToProvider()
          Returns the last known location by the provider.
 Location getLocation(int timeout)
          Gets the last location set.
 int getState()
          Returns the state of this mock provider.
 void reset()
          Resets the LocationProvider.
 void setLocation(QualifiedCoordinates coordinates, float speed)
          Sets a new location.
 void setLocationListener(LocationListener locationlistener, int interval, int timeout, int maxAge)
          Sets the listener that gets called when the setLocation and setState methods are called.
 void setState(int state)
          Sets the state of the mock location provider.
 
Methods inherited from class org.j4me.bluetoothgps.LocationProvider
discoverBluetoothDevices, getInstance, getLastKnownLocation, supportsBluetoothAPI, supportsLocationAPI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockLocationProvider

public MockLocationProvider()
Constructs a mock location provider.

Method Detail

setState

public void setState(int state)
Sets the state of the mock location provider. If a listener has been registered with the setLocationListener method, it will get notified of the state change. If state is the same as getState this method has no effect.

The initial provider state is OUT_OF_SERVICE. If setLocation is called it will automatically make the state AVAILABLE and call the registered listener's providerStateChanged method before calling its locationUpdated.

Parameters:
state - is the new provider state. It must be one of OUT_OF_SERVICE, TEMPORARILY_UNAVAILABLE, or AVAILABLE.

setLocation

public void setLocation(QualifiedCoordinates coordinates,
                        float speed)
Sets a new location. If a listener has been registered with the setLocationListener method, it will get notified of the locationUpdated method.

Parameters:
coordinates - is the new location.
speed - is the new speed in meters per second.

getState

public int getState()
Returns the state of this mock provider. The state is initially OUT_OF_SERVICE, but can be set using the setState method. After the setLocation method is called this automatically becomes AVAILABLE

Specified by:
getState in class LocationProvider
Returns:
the availability state of this LocationProvider
See Also:
LocationProvider.getState()

getLocation

public Location getLocation(int timeout)
                     throws LocationException,
                            java.lang.InterruptedException
Gets the last location set.

Specified by:
getLocation in class LocationProvider
Parameters:
timeout - - a timeout value in seconds. -1 is used to indicate that the implementation shall use its default timeout value for this provider.
Returns:
a Location object
Throws:
LocationException - - if the location couldn't be retrieved or if the timeout period expired
java.lang.InterruptedException - - if the operation is interrupted by calling reset() from another thread
See Also:
LocationProvider.getLocation(int)

getLastKnownLocationToProvider

protected Location getLastKnownLocationToProvider()
Returns the last known location by the provider.

Specified by:
getLastKnownLocationToProvider in class LocationProvider
Returns:
a location object. null is returned if the implementation doesn't have any previous location information.
Throws:
java.lang.SecurityException - - if the calling application does not have a permission to query the location information
See Also:
LocationProvider.getLastKnownLocationToProvider()

setLocationListener

public void setLocationListener(LocationListener locationlistener,
                                int interval,
                                int timeout,
                                int maxAge)
Sets the listener that gets called when the setLocation and setState methods are called.

Specified by:
setLocationListener in class LocationProvider
Parameters:
locationlistener - - the listener to be registered. If set to null the registration of any previously set listener is cancelled.
interval - - the interval in seconds. -1 is used for the default interval of this provider. 0 is used to indicate that the application wants to receive only provider status updates and not location updates at all.
timeout - - timeout value in seconds, must be greater than 0. if the value is -1, the default timeout for this provider is used. Also, if the interval is -1 to indicate the default, the value of this parameter has no effect and the default timeout for this provider is used. If the interval is 0, this parameter has no effect.
maxAge - - maximum age of the returned location in seconds, must be greater than 0 or equal to -1 to indicate that the default maximum age for this provider is used. Also, if the interval is -1 to indicate the default, the value of this parameter has no effect and the default maximum age for this provider is used. If the interval is 0, this parameter has no effect.
See Also:
LocationProvider.setLocationListener(org.j4me.bluetoothgps.LocationListener, int, int, int)

reset

public void reset()
Description copied from class: LocationProvider
Resets the LocationProvider.

All pending synchronous location requests will be aborted and any blocked getLocation method calls will terminate with InterruptedException.

Applications can use this method e.g. when exiting to have its threads freed from blocking synchronous operations.

Specified by:
reset in class LocationProvider
See Also:
LocationProvider.reset()

close

public void close()
This is a no-op for the mock location provider.

Specified by:
close in class LocationProvider
See Also:
LocationProvider.close()