forked from upstream-mirrors/OpenTracks
Address comments.
This commit is contained in:
@@ -26,7 +26,7 @@ import com.google.android.apps.mymaps.MyMapsList;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.content.WaypointType;
|
||||
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
||||
import com.google.android.apps.mytracks.io.AuthManager;
|
||||
import com.google.android.apps.mytracks.io.AuthManagerFactory;
|
||||
import com.google.android.apps.mytracks.io.GpxImporter;
|
||||
@@ -63,6 +63,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@@ -428,8 +429,10 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
if (isRecording()) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
try {
|
||||
insertWaypoint(WaypointType.STATISTICS);
|
||||
} catch (Exception e) {
|
||||
insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(MyTracksConstants.TAG, "Cannot insert statistics marker.", e);
|
||||
} catch (IllegalStateException e) {
|
||||
Log.e(MyTracksConstants.TAG, "Cannot insert statistics marker.", e);
|
||||
}
|
||||
return true;
|
||||
@@ -888,25 +891,20 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
* Inserts a waypoint marker.
|
||||
*
|
||||
* @return Id of the inserted statistics marker.
|
||||
* @throws Exception If the insertion failed.
|
||||
* @throws RemoteException
|
||||
*/
|
||||
public long insertWaypoint(WaypointType type) throws Exception {
|
||||
public long insertWaypoint(WaypointCreationRequest request) throws RemoteException {
|
||||
if (trackRecordingService == null) {
|
||||
throw new IllegalStateException("The recording service is not bound.");
|
||||
}
|
||||
try {
|
||||
long waypointId =
|
||||
trackRecordingService.insertWaypoint(type);
|
||||
long waypointId = trackRecordingService.insertWaypoint(request);
|
||||
if (waypointId >= 0) {
|
||||
Toast.makeText(this, R.string.status_statistics_inserted,
|
||||
Toast.LENGTH_LONG).show();
|
||||
return waypointId;
|
||||
} else {
|
||||
Toast.makeText(this, R.string.error_unable_to_insert_marker,
|
||||
Toast.LENGTH_LONG).show();
|
||||
throw new Exception("Insertion failed.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return waypointId;
|
||||
} catch (RemoteException e) {
|
||||
Toast.makeText(this, R.string.error_unable_to_insert_marker,
|
||||
Toast.LENGTH_LONG).show();
|
||||
throw e;
|
||||
|
||||
@@ -42,6 +42,8 @@ import android.widget.ImageView;
|
||||
public class MyTracksWaypointDetails extends Activity
|
||||
implements OnClickListener {
|
||||
|
||||
public static final String WAYPOINT_ID_EXTRA = "waypointid";
|
||||
|
||||
/**
|
||||
* The id of the way point being edited (taken from bundle, "waypointid")
|
||||
*/
|
||||
@@ -78,7 +80,7 @@ public class MyTracksWaypointDetails extends Activity
|
||||
}
|
||||
|
||||
// Required extra when launching this intent:
|
||||
waypointId = getIntent().getLongExtra("waypointid", -1);
|
||||
waypointId = getIntent().getLongExtra(WAYPOINT_ID_EXTRA, -1);
|
||||
if (waypointId < 0) {
|
||||
Log.d(MyTracksConstants.TAG,
|
||||
"MyTracksWaypointsDetails intent was launched w/o waypoint id.");
|
||||
|
||||
@@ -17,7 +17,7 @@ package com.google.android.apps.mytracks;
|
||||
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.content.WaypointType;
|
||||
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
||||
import com.google.android.apps.mytracks.content.WaypointsColumns;
|
||||
import com.google.android.apps.mytracks.util.StringUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
@@ -29,6 +29,7 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
@@ -89,7 +90,7 @@ public class MyTracksWaypointsList extends ListActivity
|
||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
Intent result = new Intent();
|
||||
result.putExtra("trackid", trackId);
|
||||
result.putExtra("waypointid", id);
|
||||
result.putExtra(MyTracksWaypointDetails.WAYPOINT_ID_EXTRA, id);
|
||||
setResult(MyTracksConstants.EDIT_WAYPOINT, result);
|
||||
finish();
|
||||
}
|
||||
@@ -105,7 +106,7 @@ public class MyTracksWaypointsList extends ListActivity
|
||||
case MyTracksConstants.MENU_EDIT: {
|
||||
Intent intent = new Intent(this, MyTracksWaypointDetails.class);
|
||||
intent.putExtra("trackid", trackId);
|
||||
intent.putExtra("waypointid", waypointId);
|
||||
intent.putExtra(MyTracksWaypointDetails.WAYPOINT_ID_EXTRA, waypointId);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
@@ -167,28 +168,30 @@ public class MyTracksWaypointsList extends ListActivity
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
WaypointType type;
|
||||
WaypointCreationRequest request;
|
||||
switch (v.getId()) {
|
||||
case R.id.waypointslist_btn_insert_waypoint:
|
||||
type = WaypointType.MARKER;
|
||||
request = WaypointCreationRequest.DEFAULT_MARKER;
|
||||
break;
|
||||
case R.id.waypointslist_btn_insert_statistics:
|
||||
type = WaypointType.MARKER;
|
||||
request = WaypointCreationRequest.DEFAULT_STATISTICS;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
long id;
|
||||
try {
|
||||
id = MyTracks.getInstance().insertWaypoint(type);
|
||||
} catch (Exception e) {
|
||||
Log.e(MyTracksConstants.TAG, "Cannot insert statistics marker.", e);
|
||||
e.printStackTrace();
|
||||
id = MyTracks.getInstance().insertWaypoint(request);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(MyTracksConstants.TAG, "Cannot insert marker.", e);
|
||||
return;
|
||||
} catch (IllegalStateException e) {
|
||||
Log.e(MyTracksConstants.TAG, "Cannot insert marker.", e);
|
||||
return;
|
||||
}
|
||||
if (id >= 0) {
|
||||
Intent intent = new Intent(this, MyTracksWaypointDetails.class);
|
||||
intent.putExtra("waypointid", id);
|
||||
intent.putExtra(MyTracksWaypointDetails.WAYPOINT_ID_EXTRA, id);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package com.google.android.apps.mytracks.services;
|
||||
|
||||
import com.google.android.apps.mytracks.MyTracksConstants;
|
||||
import com.google.android.apps.mytracks.content.WaypointType;
|
||||
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
||||
|
||||
import android.util.Log;
|
||||
@@ -112,7 +112,7 @@ public class SplitManager {
|
||||
}
|
||||
|
||||
if (distance > this.nextSplitDistance) {
|
||||
service.insertWaypoint(WaypointType.STATISTICS);
|
||||
service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
|
||||
calculateNextSplit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
|
||||
package com.google.android.apps.mytracks.services;
|
||||
|
||||
import com.google.android.apps.mytracks.content.WaypointType;
|
||||
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
||||
|
||||
|
||||
/**
|
||||
* A simple task to insert statistics markers every n minutes.
|
||||
@@ -26,7 +27,7 @@ public class TimeSplitTask implements PeriodicTask {
|
||||
|
||||
@Override
|
||||
public void run(TrackRecordingService service) {
|
||||
service.insertWaypoint(WaypointType.STATISTICS);
|
||||
service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.google.android.apps.mytracks.content.Sensor;
|
||||
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.WaypointType;
|
||||
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
|
||||
import com.google.android.apps.mytracks.content.WaypointsColumns;
|
||||
import com.google.android.apps.mytracks.content.Sensor.SensorDataSet;
|
||||
import com.google.android.apps.mytracks.services.sensors.SensorManager;
|
||||
@@ -858,26 +858,23 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
return isRecording;
|
||||
}
|
||||
|
||||
public long insertWaypoint(WaypointType type) {
|
||||
public long insertWaypoint(WaypointCreationRequest request) {
|
||||
if (!isRecording()) {
|
||||
throw new IllegalStateException(
|
||||
"Unable to insert waypoint marker while not recording!");
|
||||
}
|
||||
if (request == null) {
|
||||
request = WaypointCreationRequest.DEFAULT_MARKER;
|
||||
}
|
||||
Waypoint wpt = new Waypoint();
|
||||
switch (type) {
|
||||
switch (request.getType()) {
|
||||
case MARKER:
|
||||
wpt.setIcon(getString(R.string.waypoint_icon_url));
|
||||
wpt.setName(getString(R.string.waypoint));
|
||||
wpt.setType(Waypoint.TYPE_WAYPOINT);
|
||||
buildMarker(wpt, request);
|
||||
break;
|
||||
case STATISTICS:
|
||||
buildStatisticsMarker(wpt);
|
||||
break;
|
||||
}
|
||||
if (!isRecording()) {
|
||||
throw new IllegalStateException(
|
||||
"Unable to insert waypoint marker while not recording!");
|
||||
}
|
||||
wpt.setTrackId(recordingTrackId);
|
||||
wpt.setLength(length);
|
||||
if (lastValidLocation != null) {
|
||||
@@ -890,6 +887,23 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
return Long.parseLong(uri.getLastPathSegment());
|
||||
}
|
||||
|
||||
private void buildMarker(Waypoint wpt, WaypointCreationRequest request) {
|
||||
wpt.setType(Waypoint.TYPE_WAYPOINT);
|
||||
if (request.getIcon() == null) {
|
||||
wpt.setIcon(getString(R.string.waypoint_icon_url));
|
||||
} else {
|
||||
wpt.setIcon(request.getIcon());
|
||||
}
|
||||
if (request.getName() == null) {
|
||||
wpt.setName(getString(R.string.waypoint));
|
||||
} else {
|
||||
wpt.setName(request.getName());
|
||||
}
|
||||
if (request.getDescription() != null) {
|
||||
wpt.setDescription(request.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a statistics marker.
|
||||
* A statistics marker holds the stats for the* last segment up to this marker.
|
||||
@@ -898,11 +912,6 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
* @return the unique id of the inserted marker
|
||||
*/
|
||||
private void buildStatisticsMarker(Waypoint waypoint) {
|
||||
if (!isRecording()) {
|
||||
throw new IllegalStateException(
|
||||
"Unable to insert statistics marker while not recording!");
|
||||
}
|
||||
|
||||
StringUtils utils = new StringUtils(TrackRecordingService.this);
|
||||
|
||||
// Set stop and total time in the stats data
|
||||
@@ -989,14 +998,14 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
/**
|
||||
* Inserts a waypoint marker in the track being recorded.
|
||||
*
|
||||
* @param type of the waypoint to insert
|
||||
* @param request Details of the waypoint to insert
|
||||
* @return the unique ID of the inserted marker
|
||||
*/
|
||||
public long insertWaypoint(WaypointType type) {
|
||||
public long insertWaypoint(WaypointCreationRequest request) {
|
||||
if (service == null) {
|
||||
throw new IllegalStateException("The service has been already detached!");
|
||||
}
|
||||
return service.insertWaypoint(type);
|
||||
return service.insertWaypoint(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1073,7 +1082,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
providerUtils.updateTrack(track);
|
||||
statsBuilder = new TripStatisticsBuilder(startTime);
|
||||
waypointStatsBuilder = new TripStatisticsBuilder(startTime);
|
||||
currentWaypointId = insertWaypoint(WaypointType.STATISTICS);
|
||||
currentWaypointId = insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
|
||||
setUpAnnouncer();
|
||||
length = 0;
|
||||
showNotification();
|
||||
|
||||
Reference in New Issue
Block a user