com.sony.csl.j2me.locationapitools.tracking
Class TrackWriter

java.lang.Object
  extended by com.sony.csl.j2me.locationapitools.tracking.TrackWriter
All Implemented Interfaces:
LocationProxyListener
Direct Known Subclasses:
CSVTrackWriter, KMLTrackWriter, TXTTrackWriter

public abstract class TrackWriter
extends java.lang.Object
implements LocationProxyListener

An abstract class that implements a location tracker. Instances of subclasses of this class act a listeners on LocationProxy class and write received location updates to file.

Author:
mstevens (Sony CSL Paris / Vrije Universiteit Brussel)

Field Summary
protected  java.lang.String characterEncoding
           
protected  float coveredDistance
           
protected  Location firstLocation
           
protected  long firstLocationReceivalTime
           
protected  Location firstValidLocation
           
protected  Location lastLocation
           
protected  long lastLocationReceivalTime
           
protected  Location lastValidLocation
           
protected  LocationProxy locationProxy
           
protected  float maxAltitude
           
protected  double maxLatitude
           
protected  double maxLongitude
           
protected  float minAltitude
           
protected  double minLatitude
           
protected  double minLongitude
           
protected  int numberOfLocations
           
protected  int numberOfValidLocations
           
private  boolean paused
           
protected  java.lang.String trackFileFolderPath
           
protected  java.lang.String trackFilePath
           
private  boolean tracking
           
protected  java.lang.String trackName
           
protected  boolean tracksInvalids
           
protected  long trackStartTime
           
private  java.io.OutputStreamWriter trackWriter
           
 
Constructor Summary
TrackWriter(LocationProxy locationProxy, java.lang.String trackFileFolderPath, java.lang.String trackName)
           
TrackWriter(LocationProxy locationProxy, java.lang.String trackFileFolderPath, java.lang.String trackName, boolean tracksInvalids)
           
 
Method Summary
 void firstLocationFound(LocationProxy proxy, LocationProvider provider, Location location)
           
 java.lang.String getCharacterEncoding()
           
 float getCoveredDistance()
           
protected abstract  java.lang.String getFileExtension()
          Gets the file extension (e.g.: "txt") that is used on the files the TrackWriter creates
 Location getFirstLocation()
           
 long getFirstLocationReceivalTime()
           
 Location getFirstValidLocation()
           
 Location getLastLocation()
           
 long getLastLocationReceivalTime()
           
 Location getLastValidLocation()
           
 LocationProxy getLocationProxy()
           
 float getMaxAltitude()
           
 double getMaxLatitude()
           
 double getMaxLongitude()
           
 float getMinAltitude()
           
 double getMinLatitude()
           
 double getMinLongitude()
           
 int getNumberOfLocations()
           
 int getNumberOfValidLocations()
           
 java.lang.String getTrackFilePath()
           
 java.lang.String getTrackName()
           
protected abstract  void initializeBeforeStart()
          Allows subclasses to add initializations that should take place before tracking starts.
 boolean isPaused()
           
 boolean isTracking()
           
 boolean isTracksInvalids()
           
 void locationProviderStateChanged(LocationProxy proxy, LocationProvider provider, int newState)
           
 void locationUpdated(LocationProxy proxy, LocationProvider provider, Location location)
           
 void pauseTracking()
           
 void pauseTracking(java.lang.String reason)
           
 void proxyConnected(LocationProxy proxy, LocationProvider provider)
           
 void proxyDisconnected(LocationProxy proxy)
           
 boolean receivesInvalidLocations()
           
protected  void reset()
           
 void resumeTracking()
           
 void setCharacterEncoding(java.lang.String characterEncoding)
           
 void startTracking()
           
 void stopTracking()
           
protected abstract  void writeFooter()
          Writes the footer of the file.
protected abstract  void writeHeader()
          Writes the header of the file.
protected abstract  void writeLocation(Location location)
          Writes a new location to the file.
protected abstract  void writePaused(java.lang.String reason)
           
protected abstract  void writeProviderStateChanged(LocationProvider provider, int newState)
           
protected abstract  void writeResumed()
           
protected  void writeToFile(java.lang.String stringToWrite)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

characterEncoding

protected java.lang.String characterEncoding

trackName

protected java.lang.String trackName

trackFileFolderPath

protected java.lang.String trackFileFolderPath

trackFilePath

protected java.lang.String trackFilePath

tracksInvalids

protected boolean tracksInvalids

locationProxy

protected LocationProxy locationProxy

tracking

private boolean tracking

paused

private boolean paused

trackStartTime

protected long trackStartTime

firstLocation

protected Location firstLocation

firstLocationReceivalTime

protected long firstLocationReceivalTime

firstValidLocation

protected Location firstValidLocation

lastLocation

protected Location lastLocation

lastLocationReceivalTime

protected long lastLocationReceivalTime

lastValidLocation

protected Location lastValidLocation

numberOfLocations

protected int numberOfLocations

numberOfValidLocations

protected int numberOfValidLocations

coveredDistance

protected float coveredDistance

minLongitude

protected double minLongitude

maxLongitude

protected double maxLongitude

minLatitude

protected double minLatitude

maxLatitude

protected double maxLatitude

minAltitude

protected float minAltitude

maxAltitude

protected float maxAltitude

trackWriter

private java.io.OutputStreamWriter trackWriter
Constructor Detail

TrackWriter

public TrackWriter(LocationProxy locationProxy,
                   java.lang.String trackFileFolderPath,
                   java.lang.String trackName)
            throws java.lang.Exception
Throws:
java.lang.Exception

TrackWriter

public TrackWriter(LocationProxy locationProxy,
                   java.lang.String trackFileFolderPath,
                   java.lang.String trackName,
                   boolean tracksInvalids)
            throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Returns:
the characterEncoding

setCharacterEncoding

public void setCharacterEncoding(java.lang.String characterEncoding)
Parameters:
characterEncoding - the characterEncoding to set

getTrackFilePath

public java.lang.String getTrackFilePath()
Returns:
the trackFilePath

getTrackName

public java.lang.String getTrackName()
Returns:
the trackName

isTracksInvalids

public boolean isTracksInvalids()
Returns:
the tracksInvalids

getLocationProxy

public LocationProxy getLocationProxy()
Returns:
the locationProxy

isTracking

public boolean isTracking()
Returns:
the tracking

isPaused

public boolean isPaused()
Returns:
the paused

getFirstLocation

public Location getFirstLocation()
Returns:
the firstLocation

getFirstLocationReceivalTime

public long getFirstLocationReceivalTime()
Returns:
the firstLocationReceivalTime

getFirstValidLocation

public Location getFirstValidLocation()
Returns:
the firstValidLocation

getLastLocation

public Location getLastLocation()
Returns:
the lastLocation

getLastLocationReceivalTime

public long getLastLocationReceivalTime()
Returns:
the lastLocationReceivalTime

getLastValidLocation

public Location getLastValidLocation()
Returns:
the lastValidLocation

getNumberOfLocations

public int getNumberOfLocations()
Returns:
the numberOfLocations

getNumberOfValidLocations

public int getNumberOfValidLocations()
Returns:
the numberOfValidLocations

getCoveredDistance

public float getCoveredDistance()
Returns:
the coveredDistance

getMinLongitude

public double getMinLongitude()
Returns:
the minLongitude

getMaxLongitude

public double getMaxLongitude()
Returns:
the maxLongitude

getMinLatitude

public double getMinLatitude()
Returns:
the minLatitude

getMaxLatitude

public double getMaxLatitude()
Returns:
the maxLatitude

getMinAltitude

public float getMinAltitude()
Returns:
the minAltitude

getMaxAltitude

public float getMaxAltitude()
Returns:
the maxAltitude

reset

protected void reset()

startTracking

public final void startTracking()
                         throws java.lang.Exception
Throws:
java.lang.Exception

pauseTracking

public final void pauseTracking()

pauseTracking

public final void pauseTracking(java.lang.String reason)

writePaused

protected abstract void writePaused(java.lang.String reason)

resumeTracking

public final void resumeTracking()

writeResumed

protected abstract void writeResumed()

stopTracking

public final void stopTracking()

writeToFile

protected final void writeToFile(java.lang.String stringToWrite)

getFileExtension

protected abstract java.lang.String getFileExtension()
Gets the file extension (e.g.: "txt") that is used on the files the TrackWriter creates

Returns:
a String containing the file extension (without the '.')

initializeBeforeStart

protected abstract void initializeBeforeStart()
Allows subclasses to add initializations that should take place before tracking starts.


writeHeader

protected abstract void writeHeader()
Writes the header of the file.


writeLocation

protected abstract void writeLocation(Location location)
Writes a new location to the file.


writeFooter

protected abstract void writeFooter()
Writes the footer of the file.


locationUpdated

public final void locationUpdated(LocationProxy proxy,
                                  LocationProvider provider,
                                  Location location)
Specified by:
locationUpdated in interface LocationProxyListener
See Also:
LocationProxyListener.locationUpdated(com.sony.csl.j2me.locationapitools.LocationProxy, javax.microedition.location.LocationProvider, javax.microedition.location.Location)

proxyConnected

public void proxyConnected(LocationProxy proxy,
                           LocationProvider provider)
Specified by:
proxyConnected in interface LocationProxyListener
See Also:
LocationProxyListener.proxyConnected(com.sony.csl.j2me.locationapitools.LocationProxy, javax.microedition.location.LocationProvider)

proxyDisconnected

public final void proxyDisconnected(LocationProxy proxy)
Specified by:
proxyDisconnected in interface LocationProxyListener
See Also:
LocationProxyListener.proxyDisconnected(com.sony.csl.j2me.locationapitools.LocationProxy)

locationProviderStateChanged

public void locationProviderStateChanged(LocationProxy proxy,
                                         LocationProvider provider,
                                         int newState)
Specified by:
locationProviderStateChanged in interface LocationProxyListener
See Also:
LocationProxyListener.locationProviderStateChanged(com.sony.csl.j2me.locationapitools.LocationProxy, javax.microedition.location.LocationProvider, int)

writeProviderStateChanged

protected abstract void writeProviderStateChanged(LocationProvider provider,
                                                  int newState)

firstLocationFound

public void firstLocationFound(LocationProxy proxy,
                               LocationProvider provider,
                               Location location)
Specified by:
firstLocationFound in interface LocationProxyListener
See Also:
LocationProxyListener.firstLocationFound(com.sony.csl.j2me.locationapitools.LocationProxy, javax.microedition.location.LocationProvider, javax.microedition.location.Location)

receivesInvalidLocations

public boolean receivesInvalidLocations()
Specified by:
receivesInvalidLocations in interface LocationProxyListener