showing a preliminary location if recording started with an old / imprecise location fix)

master
y20k 2018-09-05 17:35:01 +02:00
parent b448bb7f2d
commit b44e39667a
8 changed files with 46 additions and 20 deletions

View File

@ -209,7 +209,7 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
// mark user's location on map // mark user's location on map
if (mCurrentBestLocation != null && !mTrackerServiceRunning) { if (mCurrentBestLocation != null && !mTrackerServiceRunning) {
mMyLocationOverlay = MapHelper.createMyLocationOverlay(mActivity, mCurrentBestLocation, LocationHelper.isCurrent(mCurrentBestLocation)); mMyLocationOverlay = MapHelper.createMyLocationOverlay(mActivity, mCurrentBestLocation, LocationHelper.isCurrent(mCurrentBestLocation), false);
mMapView.getOverlays().add(mMyLocationOverlay); mMapView.getOverlays().add(mMyLocationOverlay);
} }
@ -510,7 +510,7 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
mMapView.getOverlays().remove(mMyLocationOverlay); mMapView.getOverlays().remove(mMyLocationOverlay);
// only update while not tracking // only update while not tracking
if (!mTrackerServiceRunning) { if (!mTrackerServiceRunning) {
mMyLocationOverlay = MapHelper.createMyLocationOverlay(mActivity, mCurrentBestLocation, LocationHelper.isCurrent(mCurrentBestLocation)); mMyLocationOverlay = MapHelper.createMyLocationOverlay(mActivity, mCurrentBestLocation, LocationHelper.isCurrent(mCurrentBestLocation), false);
mMapView.getOverlays().add(mMyLocationOverlay); mMapView.getOverlays().add(mMyLocationOverlay);
} }
} }
@ -520,11 +520,16 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
private void drawTrackOverlay(Track track) { private void drawTrackOverlay(Track track) {
mMapView.getOverlays().remove(mTrackOverlay); mMapView.getOverlays().remove(mTrackOverlay);
mTrackOverlay = null; mTrackOverlay = null;
if (track != null) { if (track == null || track.getSize() == 0) {
LogHelper.i(LOG_TAG, "Waiting for a track. Showing preliminary location.");
mTrackOverlay = MapHelper.createMyLocationOverlay(mActivity, mCurrentBestLocation, false, mTrackerServiceRunning);
Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_acquiring_location), Toast.LENGTH_LONG).show();
} else {
LogHelper.v(LOG_TAG, "Drawing track overlay."); LogHelper.v(LOG_TAG, "Drawing track overlay.");
mTrackOverlay = MapHelper.createTrackOverlay(mActivity, track, mTrackerServiceRunning); mTrackOverlay = MapHelper.createTrackOverlay(mActivity, track, mTrackerServiceRunning);
mMapView.getOverlays().add(mTrackOverlay);
} }
mMapView.getOverlays().add(mTrackOverlay);
} }

View File

@ -402,6 +402,9 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
if (LocationHelper.isAccurate(mCurrentBestLocation) && LocationHelper.isCurrent(mCurrentBestLocation)) { if (LocationHelper.isAccurate(mCurrentBestLocation) && LocationHelper.isCurrent(mCurrentBestLocation)) {
// add first location to track // add first location to track
success = mTrack.addWayPoint(previousLocation, mCurrentBestLocation); success = mTrack.addWayPoint(previousLocation, mCurrentBestLocation);
} else {
// just send a broadcast indicating that current location fix not not suited
broadcastTrackUpdate();
} }
} else { } else {
// get location of previous WayPoint // get location of previous WayPoint

View File

@ -276,7 +276,12 @@ public class Track implements TrackbookKeys, Parcelable {
/* Getter recorded distance */ /* Getter recorded distance */
public Double getTrackDistance() { public Double getTrackDistance() {
return (double) mWayPoints.get(mWayPoints.size()-1).getDistanceToStartingPoint(); int size = mWayPoints.size();
if (size > 0) {
return (double)mWayPoints.get(size - 1).getDistanceToStartingPoint();
} else {
return (double)0f;
}
} }

View File

@ -94,8 +94,8 @@ public final class LocationHelper implements TrackbookKeys {
// check whether the new location fix is newer or older // check whether the new location fix is newer or older
long timeDelta = location.getElapsedRealtimeNanos() - currentBestLocation.getElapsedRealtimeNanos(); long timeDelta = location.getElapsedRealtimeNanos() - currentBestLocation.getElapsedRealtimeNanos();
boolean isSignificantlyNewer = timeDelta > TWO_MINUTES_IN_NANOSECONDS; boolean isSignificantlyNewer = timeDelta > ONE_MINUTE_IN_NANOSECONDS;
boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES_IN_NANOSECONDS; boolean isSignificantlyOlder = timeDelta < -ONE_MINUTE_IN_NANOSECONDS;
boolean isNewer = timeDelta > 0; boolean isNewer = timeDelta > 0;
// if it's been more than two minutes since the current location, use the new location because the user has likely moved // if it's been more than two minutes since the current location, use the new location because the user has likely moved
@ -138,7 +138,7 @@ public final class LocationHelper implements TrackbookKeys {
return false; return false;
} else { } else {
long locationAge = SystemClock.elapsedRealtimeNanos() - location.getElapsedRealtimeNanos(); long locationAge = SystemClock.elapsedRealtimeNanos() - location.getElapsedRealtimeNanos();
return locationAge < TWO_MINUTES_IN_NANOSECONDS; return locationAge < ONE_MINUTE_IN_NANOSECONDS;
} }
} }

View File

@ -45,17 +45,20 @@ public final class MapHelper {
/* Creates icon overlay for current position (used in MainActivity Fragment) */ /* Creates icon overlay for current position (used in MainActivity Fragment) */
public static ItemizedIconOverlay createMyLocationOverlay(final Context context, Location currentBestLocation, boolean locationIsNew) { public static ItemizedIconOverlay createMyLocationOverlay(final Context context, Location currentBestLocation, boolean locationIsNew, boolean trackingActive) {
final ArrayList<OverlayItem> overlayItems = new ArrayList<>(); final ArrayList<OverlayItem> overlayItems = new ArrayList<>();
// create marker // create marker
Drawable newMarker; Drawable newMarker;
if (locationIsNew) { if (locationIsNew && !trackingActive) {
newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_dot_blue_24dp); newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_dot_blue_24dp);
} else if (!locationIsNew && trackingActive) {
newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_dot_red_grey_24dp);
} else { } else {
newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_dot_grey_24dp); newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_dot_blue_grey_24dp);
} }
OverlayItem overlayItem = createOverlayItem(context, currentBestLocation); OverlayItem overlayItem = createOverlayItem(context, currentBestLocation);
overlayItem.setMarker(newMarker); overlayItem.setMarker(newMarker);
@ -84,13 +87,14 @@ public final class MapHelper {
/* Creates icon overlay for track */ /* Creates icon overlay for track */
public static ItemizedIconOverlay createTrackOverlay(final Context context, Track track, boolean trackingActive){ public static ItemizedIconOverlay createTrackOverlay(final Context context, Track track, boolean trackingActive){
WayPoint wayPoint; final ArrayList<OverlayItem> overlayItems = new ArrayList<>();
boolean currentPosition; boolean currentPosition;
final int trackSize = track.getSize(); final int trackSize = track.getSize();
final List<WayPoint> wayPoints = track.getWayPoints(); final List<WayPoint> wayPoints = track.getWayPoints();
final ArrayList<OverlayItem> overlayItems = new ArrayList<>(); WayPoint wayPoint;
for (int i = 0; i < track.getSize(); i++) {
for (int i = 0 ; i < track.getSize() ; i++) {
// get WayPoint and check if it is current position // get WayPoint and check if it is current position
wayPoint = wayPoints.get(i); wayPoint = wayPoints.get(i);
currentPosition = i == trackSize - 1; currentPosition = i == trackSize - 1;
@ -113,7 +117,7 @@ public final class MapHelper {
else if (trackingActive && currentPosition) { else if (trackingActive && currentPosition) {
if (wayPoint.getIsStopOver()) { if (wayPoint.getIsStopOver()) {
// stop over marker // stop over marker
newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_dot_grey_24dp); newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_dot_blue_grey_24dp);
} else { } else {
// default marker for this case // default marker for this case
newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_dot_red_24dp); newMarker = ContextCompat.getDrawable(context, R.drawable.ic_my_location_dot_red_24dp);

View File

@ -75,10 +75,6 @@ public interface TrackbookKeys {
int FRAGMENT_ID_MAP = 0; int FRAGMENT_ID_MAP = 0;
int FRAGMENT_ID_TRACKS = 1; int FRAGMENT_ID_TRACKS = 1;
String FRAGMENT_TAG_MAP = "fragmentTagMap";
String FRAGMENT_TAG_TRACKS = "fragmentTagTracks";
/* RESULTS */ /* RESULTS */
int RESULT_SAVE_DIALOG = 1; int RESULT_SAVE_DIALOG = 1;
int RESULT_CLEAR_DIALOG = 2; int RESULT_CLEAR_DIALOG = 2;
@ -90,7 +86,7 @@ public interface TrackbookKeys {
long EIGHT_HOURS_IN_MILLISECONDS = 43200000; // maximum tracking duration long EIGHT_HOURS_IN_MILLISECONDS = 43200000; // maximum tracking duration
long FIFTEEN_SECONDS_IN_MILLISECONDS = 15000; // timer interval for tracking long FIFTEEN_SECONDS_IN_MILLISECONDS = 15000; // timer interval for tracking
long FIVE_MINUTES_IN_NANOSECONDS = 5L * 60000000000L; // determines a stop over long FIVE_MINUTES_IN_NANOSECONDS = 5L * 60000000000L; // determines a stop over
long TWO_MINUTES_IN_NANOSECONDS = 2L * 60000000000L; // defines an old location long ONE_MINUTE_IN_NANOSECONDS = 1L * 60000000000L; // defines an old location
int MAXIMUM_TRACK_FILES = 25; int MAXIMUM_TRACK_FILES = 25;
int FIFTY_METER_RADIUS = 50; int FIFTY_METER_RADIUS = 50;

View File

@ -0,0 +1,13 @@
<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:fillAlpha="0.33"
android:fillColor="@color/trackbook_red"
android:pathData="M48,48m-48,0a48,48 0,1 1,96 0a48,48 0,1 1,-96 0"/>
<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>