diff --git a/MyTracks/res/values/strings.xml b/MyTracks/res/values/strings.xml
index e22dc468c..902d14397 100644
--- a/MyTracks/res/values/strings.xml
+++ b/MyTracks/res/values/strings.xml
@@ -934,8 +934,9 @@ limitations under the License.
- Unable to insert a marker. Try again.
+ translation_description="When adding a marker, the message indicating error due to no GPS
+ signal.">
+ Unable to insert a marker. No GPS signal. Try again.
diff --git a/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java b/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java
index 60cda06ae..a44a3b01d 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java
@@ -160,6 +160,7 @@ public class MarkerEditActivity extends AbstractMyTracksActivity {
private void addMarker() {
WaypointCreationRequest waypointCreationRequest = new WaypointCreationRequest(
WaypointType.WAYPOINT,
+ false,
waypointName.getText().toString(),
waypointMarkerType.getText().toString(),
waypointDescription.getText().toString(),
diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java
index 0653be1e3..e630547c7 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/TrackDetailActivity.java
@@ -346,7 +346,7 @@ public class TrackDetailActivity extends AbstractMyTracksActivity implements Del
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (TrackRecordingServiceConnectionUtils.isRecording(this, trackRecordingServiceConnection)) {
TrackRecordingServiceConnectionUtils.addMarker(
- this, trackRecordingServiceConnection, WaypointCreationRequest.DEFAULT_STATISTICS);
+ this, trackRecordingServiceConnection, WaypointCreationRequest.DEFAULT_WAYPOINT);
return true;
}
}
diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java
index 4e9d83a9b..61f34e52b 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java
@@ -30,6 +30,7 @@ import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.TracksColumns;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
+import com.google.android.apps.mytracks.content.WaypointCreationRequest.WaypointType;
import com.google.android.apps.mytracks.content.WaypointsColumns;
import com.google.android.apps.mytracks.services.sensors.SensorManager;
import com.google.android.apps.mytracks.services.sensors.SensorManagerFactory;
@@ -589,7 +590,7 @@ public class TrackRecordingService extends Service {
statsBuilder.setMinRecordingDistance(minRecordingDistance);
waypointStatsBuilder = new TripStatisticsBuilder(startTime);
waypointStatsBuilder.setMinRecordingDistance(minRecordingDistance);
- currentWaypointId = insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
+ currentWaypointId = insertWaypoint(WaypointCreationRequest.DEFAULT_START_TRACK);
length = 0;
showNotification();
registerLocationListener();
@@ -916,37 +917,33 @@ public class TrackRecordingService extends Service {
public long insertWaypoint(WaypointCreationRequest request) {
if (!isRecording()) {
- throw new IllegalStateException(
- "Unable to insert waypoint marker while not recording!");
+ throw new IllegalStateException("Unable to insert marker while not recording!");
}
- if (request == null) {
- request = WaypointCreationRequest.DEFAULT_WAYPOINT;
- }
- Waypoint wpt = new Waypoint();
- switch (request.getType()) {
- case WAYPOINT:
- buildWaypointMarker(wpt, request);
- break;
- case STATISTICS:
- buildStatisticsMarker(wpt, request);
- break;
- }
- wpt.setTrackId(recordingTrackId);
- wpt.setLength(length);
- if (lastLocation == null
- || statsBuilder == null || statsBuilder.getStatistics() == null) {
- // A null location is ok, and expected on track start.
- // Make it an impossible location.
- Location l = new Location("");
- l.setLatitude(100);
- l.setLongitude(180);
- wpt.setLocation(l);
+ Waypoint waypoint = new Waypoint();
+ if (request.getType() == WaypointType.WAYPOINT) {
+ buildWaypointMarker(waypoint, request);
} else {
- wpt.setLocation(lastLocation);
- wpt.setDuration(lastLocation.getTime()
- - statsBuilder.getStatistics().getStartTime());
+ buildStatisticsMarker(waypoint, request);
}
- Uri uri = providerUtils.insertWaypoint(wpt);
+ waypoint.setTrackId(recordingTrackId);
+ waypoint.setLength(length);
+ if (lastLocation == null || statsBuilder == null || statsBuilder.getStatistics() == null) {
+ if (!request.isTrackStatistics()) {
+ return -1L;
+ }
+ /*
+ * For track statistics, a null location is OK. Make it an impossible
+ * location.
+ */
+ Location location = new Location("");
+ location.setLatitude(100);
+ location.setLongitude(180);
+ waypoint.setLocation(location);
+ } else {
+ waypoint.setLocation(lastLocation);
+ waypoint.setDuration(lastLocation.getTime() - statsBuilder.getStatistics().getStartTime());
+ }
+ Uri uri = providerUtils.insertWaypoint(waypoint);
return Long.parseLong(uri.getLastPathSegment());
}
diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/content/WaypointCreationRequest.java b/MyTracksLib/src/com/google/android/apps/mytracks/content/WaypointCreationRequest.java
index c2145e030..aabf08c97 100644
--- a/MyTracksLib/src/com/google/android/apps/mytracks/content/WaypointCreationRequest.java
+++ b/MyTracksLib/src/com/google/android/apps/mytracks/content/WaypointCreationRequest.java
@@ -20,34 +20,38 @@ import android.os.Parcelable;
/**
* A request for the service to create a waypoint at the current location.
- *
+ *
* @author Sandor Dornbush
*/
public class WaypointCreationRequest implements Parcelable {
public static enum WaypointType {
- WAYPOINT,
- STATISTICS;
+ WAYPOINT, STATISTICS;
}
-
+
private WaypointType type;
+ // true if this marker contains the track statistics
+ private boolean isTrackStatistics;
private String name;
private String category;
private String description;
private String iconUrl;
- public final static WaypointCreationRequest DEFAULT_WAYPOINT =
- new WaypointCreationRequest(WaypointType.WAYPOINT);
- public final static WaypointCreationRequest DEFAULT_STATISTICS =
- new WaypointCreationRequest(WaypointType.STATISTICS);
-
- private WaypointCreationRequest(WaypointType type) {
- this.type = type;
+ public final static WaypointCreationRequest DEFAULT_WAYPOINT = new WaypointCreationRequest(
+ WaypointType.WAYPOINT, false);
+ public final static WaypointCreationRequest DEFAULT_STATISTICS = new WaypointCreationRequest(
+ WaypointType.STATISTICS, false);
+ public final static WaypointCreationRequest DEFAULT_START_TRACK = new WaypointCreationRequest(
+ WaypointType.STATISTICS, true);
+
+ private WaypointCreationRequest(WaypointType type, boolean isTrackStatistics) {
+ this(type, isTrackStatistics, null, null, null, null);
}
- public WaypointCreationRequest(WaypointType type, String name, String category,
- String description, String iconUrl) {
+ public WaypointCreationRequest(WaypointType type, boolean isTrackStatistics, String name,
+ String category, String description, String iconUrl) {
this.type = type;
+ this.isTrackStatistics = isTrackStatistics;
this.name = name;
this.category = category;
this.description = description;
@@ -58,15 +62,13 @@ public class WaypointCreationRequest implements Parcelable {
@Override
public WaypointCreationRequest createFromParcel(Parcel source) {
- int i = source.readInt();
- if (i > WaypointType.values().length) {
- throw new IllegalArgumentException("Could not find waypoint type: " + i);
- }
- WaypointCreationRequest request = new WaypointCreationRequest(WaypointType.values()[i]);
- request.name = source.readString();
- request.category = source.readString();
- request.description = source.readString();
- request.iconUrl = source.readString();
+ WaypointCreationRequest request = new WaypointCreationRequest(
+ WaypointType.values()[source.readInt()],
+ source.readByte() == 1,
+ source.readString(),
+ source.readString(),
+ source.readString(),
+ source.readString());
return request;
}
@@ -76,7 +78,7 @@ public class WaypointCreationRequest implements Parcelable {
}
public static final Creator CREATOR = new Creator();
-
+
@Override
public int describeContents() {
return 0;
@@ -85,16 +87,21 @@ public class WaypointCreationRequest implements Parcelable {
@Override
public void writeToParcel(Parcel parcel, int arg1) {
parcel.writeInt(type.ordinal());
+ parcel.writeByte((byte) (isTrackStatistics ? 1 : 0));
parcel.writeString(name);
parcel.writeString(category);
parcel.writeString(description);
parcel.writeString(iconUrl);
}
-
+
public WaypointType getType() {
return type;
}
+ public boolean isTrackStatistics() {
+ return isTrackStatistics;
+ }
+
public String getName() {
return name;
}
@@ -102,7 +109,7 @@ public class WaypointCreationRequest implements Parcelable {
public String getCategory() {
return category;
}
-
+
public String getDescription() {
return description;
}
diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/content/WaypointCreationRequestTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/content/WaypointCreationRequestTest.java
index 38d32b700..cfe308cf7 100644
--- a/MyTracksTest/src/com/google/android/apps/mytracks/content/WaypointCreationRequestTest.java
+++ b/MyTracksTest/src/com/google/android/apps/mytracks/content/WaypointCreationRequestTest.java
@@ -35,19 +35,21 @@ public class WaypointCreationRequestTest extends AndroidTestCase {
p.setDataPosition(0);
WaypointCreationRequest copy = WaypointCreationRequest.CREATOR.createFromParcel(p);
assertEquals(original.getType(), copy.getType());
+ assertFalse(copy.isTrackStatistics());
assertNull(copy.getName());
assertNull(copy.getDescription());
assertNull(copy.getIconUrl());
}
public void testAllAttributesParceling() {
- WaypointCreationRequest original =
- new WaypointCreationRequest(WaypointType.WAYPOINT, "name", "category", "description", "img.png");
+ WaypointCreationRequest original = new WaypointCreationRequest(
+ WaypointType.WAYPOINT, false, "name", "category", "description", "img.png");
Parcel p = Parcel.obtain();
original.writeToParcel(p, 0);
p.setDataPosition(0);
WaypointCreationRequest copy = WaypointCreationRequest.CREATOR.createFromParcel(p);
assertEquals(original.getType(), copy.getType());
+ assertFalse(copy.isTrackStatistics());
assertEquals("name", copy.getName());
assertEquals("category", copy.getCategory());
assertEquals("description", copy.getDescription());
diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java
index 3ed280c32..7208605d2 100644
--- a/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java
+++ b/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java
@@ -39,6 +39,7 @@ import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
+import android.os.RemoteException;
import android.provider.Settings;
import android.test.RenamingDelegatingContext;
import android.test.ServiceTestCase;
@@ -494,6 +495,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase 0);
assertTrue(tripStatistics.getStopTime() >= tripStatistics.getStartTime());
}
+
+ /**
+ * Inserts a location and waits for 100ms.
+ *
+ * @param trackRecordingService the track recording service
+ */
+ private void insertLocation(ITrackRecordingService trackRecordingService)
+ throws RemoteException, InterruptedException {
+ Location location = new Location("gps");
+ location.setLongitude(35.0f);
+ location.setLatitude(45.0f);
+ location.setAccuracy(5);
+ location.setSpeed(10);
+ location.setTime(System.currentTimeMillis());
+ location.setBearing(3.0f);
+ trackRecordingService.recordLocation(location);
+ Thread.sleep(100);
+ }
}