Added marker type "stopOver crumb".
This commit is contained in:
parent
c636886e90
commit
c68c6bc32e
5 changed files with 44 additions and 23 deletions
|
@ -142,18 +142,19 @@ public class TrackerService extends Service implements TrackbookKeys {
|
|||
// get number of previously tracked WayPoints
|
||||
int trackSize = mTrack.getWayPoints().size();
|
||||
|
||||
if (trackSize > 0) {
|
||||
// get last waypoint and compare it to current location
|
||||
Location lastWayPoint = mTrack.getWayPointLocation(trackSize-1);
|
||||
if (LocationHelper.isNewWayPoint(lastWayPoint, mCurrentBestLocation)) {
|
||||
LogHelper.v(LOG_TAG, "!!! Ding. " + mTrack.getSize());
|
||||
// if new, add current best location to track
|
||||
newWayPoint = mTrack.addWayPoint(mCurrentBestLocation);
|
||||
}
|
||||
} else {
|
||||
if (trackSize == 0) {
|
||||
// add first location to track
|
||||
newWayPoint = mTrack.addWayPoint(mCurrentBestLocation);
|
||||
LogHelper.v(LOG_TAG, "!!! Dong. " + mTrack.getSize());
|
||||
LogHelper.v(LOG_TAG, "mTrack.addWayPoint. Tracksize: " + trackSize); // TODO remove
|
||||
} else {
|
||||
// get last waypoint and compare it to current location
|
||||
Location lastWayPoint = mTrack.getWayPointLocation(trackSize - 1);
|
||||
if (LocationHelper.isNewWayPoint(lastWayPoint, mCurrentBestLocation)) {
|
||||
// if new, add current best location to track
|
||||
newWayPoint = mTrack.addWayPoint(mCurrentBestLocation);
|
||||
LogHelper.v(LOG_TAG, "mTrack.addWayPoint. Tracksize: " + trackSize); // TODO remove
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// send local broadcast if new WayPoint added
|
||||
|
|
|
@ -83,8 +83,17 @@ public class Track implements TrackbookKeys, Parcelable {
|
|||
// add up distance
|
||||
mTrackLength = addDistanceToTrack(location);
|
||||
|
||||
boolean stopOver;
|
||||
int wayPointCount = mWayPoints.size();
|
||||
if (wayPointCount == 0) {
|
||||
stopOver = false;
|
||||
} else {
|
||||
Location lastLocation = mWayPoints.get(wayPointCount - 1).getLocation();
|
||||
stopOver = LocationHelper.isStopOver(lastLocation, location);
|
||||
}
|
||||
|
||||
// create new waypoint
|
||||
WayPoint wayPoint = new WayPoint(location, LocationHelper.isStopOver(location), mTrackLength);
|
||||
WayPoint wayPoint = new WayPoint(location, stopOver, mTrackLength);
|
||||
|
||||
// add new waypoint to track
|
||||
mWayPoints.add(wayPoint);
|
||||
|
@ -120,13 +129,13 @@ public class Track implements TrackbookKeys, Parcelable {
|
|||
int wayPointCount = mWayPoints.size();
|
||||
|
||||
// at least two data points are needed
|
||||
if (wayPointCount >= 2) {
|
||||
if (wayPointCount >= 1) {
|
||||
// add up distance
|
||||
Location lastLocation = mWayPoints.get(wayPointCount-2).getLocation();
|
||||
mTrackLength = mTrackLength + lastLocation.distanceTo(location);
|
||||
Location lastLocation = mWayPoints.get(wayPointCount - 1).getLocation();
|
||||
return mTrackLength + lastLocation.distanceTo(location);
|
||||
}
|
||||
|
||||
return mTrackLength;
|
||||
return 0f;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ public final class LocationHelper {
|
|||
|
||||
/* Main class variables */
|
||||
// private static final int TWO_MINUTES = 1000 * 1000 * 60 * 2;
|
||||
private static final long FIVE_MINUTES = 5L * 60000000000L; // 2 minutes
|
||||
private static final long TWO_MINUTES = 2L * 60000000000L; // 2 minutes
|
||||
private static final long TWENTY_SECONDS = 20000000000L; // 20 seconds
|
||||
|
||||
|
@ -142,10 +143,10 @@ public final class LocationHelper {
|
|||
}
|
||||
|
||||
|
||||
/* Checks if given location is a new waypoint over */
|
||||
public static boolean isNewWayPoint(Location lastWayPoint, Location newLocation) {
|
||||
float distance = newLocation.distanceTo(lastWayPoint);
|
||||
long timeDifference = newLocation.getElapsedRealtimeNanos() - lastWayPoint.getElapsedRealtimeNanos();
|
||||
/* Checks if given location is a new waypoint */
|
||||
public static boolean isNewWayPoint(Location lastLocation, Location newLocation) {
|
||||
float distance = newLocation.distanceTo(lastLocation);
|
||||
long timeDifference = newLocation.getElapsedRealtimeNanos() - lastLocation.getElapsedRealtimeNanos();
|
||||
|
||||
// distance is bigger than 10 meters and time difference bigger than 20 seconds
|
||||
return distance > 10 && timeDifference >= TWENTY_SECONDS;
|
||||
|
@ -153,9 +154,9 @@ public final class LocationHelper {
|
|||
|
||||
|
||||
/* Checks if given location is a stop over */
|
||||
public static boolean isStopOver(Location location) {
|
||||
// TODO determine, if location is stopover
|
||||
return false;
|
||||
public static boolean isStopOver(Location lastLocation, Location newLocation) {
|
||||
long timeDifference = newLocation.getElapsedRealtimeNanos() - lastLocation.getElapsedRealtimeNanos();
|
||||
return timeDifference >= FIVE_MINUTES;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ public final class MapHelper {
|
|||
// create marker
|
||||
Drawable newMarker;
|
||||
if (wayPoint.getIsStopOver()) {
|
||||
newMarker = AppCompatDrawableManager.get().getDrawable(context, R.drawable.ic_my_location_crumb_blue_24dp);
|
||||
newMarker = AppCompatDrawableManager.get().getDrawable(context, R.drawable.ic_my_location_crumb_grey_24dp);
|
||||
} else {
|
||||
newMarker = AppCompatDrawableManager.get().getDrawable(context, R.drawable.ic_my_location_crumb_blue_24dp);
|
||||
}
|
||||
|
|
10
app/src/main/res/drawable/ic_my_location_crumb_grey_24dp.xml
Normal file
10
app/src/main/res/drawable/ic_my_location_crumb_grey_24dp.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="96.0"
|
||||
android:viewportWidth="96.0"
|
||||
android:width="24dp">
|
||||
|
||||
<path
|
||||
android:fillColor="@color/trackbook_grey_light"
|
||||
android:pathData="M48,48m-24,0a24,24 0,1 1,48 0a24,24 0,1 1,-48 0"/>
|
||||
</vector>
|
Loading…
Reference in a new issue