Getting rid of insertWaypoint singleton dependency.

This commit is contained in:
Rodrigo Damazio
2011-05-31 03:16:14 -03:00
parent 6a1b2861f3
commit 111adc917b
2 changed files with 30 additions and 11 deletions
@@ -390,10 +390,12 @@ public class MyTracks extends TabActivity implements OnTouchListener {
/** /**
* Inserts a waypoint marker. * Inserts a waypoint marker.
* *
* TODO: Merge with WaypointsList#insertWaypoint.
*
* @return Id of the inserted statistics marker. * @return Id of the inserted statistics marker.
* @throws RemoteException If the call on the service failed. * @throws RemoteException If the call on the service failed.
*/ */
public long insertWaypoint(WaypointCreationRequest request) throws RemoteException { private long insertWaypoint(WaypointCreationRequest request) throws RemoteException {
ITrackRecordingService trackRecordingService = serviceBinder.getServiceIfBound(); ITrackRecordingService trackRecordingService = serviceBinder.getServiceIfBound();
if (trackRecordingService == null) { if (trackRecordingService == null) {
throw new IllegalStateException("The recording service is not bound."); throw new IllegalStateException("The recording service is not bound.");
@@ -19,6 +19,8 @@ import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.WaypointCreationRequest; import com.google.android.apps.mytracks.content.WaypointCreationRequest;
import com.google.android.apps.mytracks.content.WaypointsColumns; import com.google.android.apps.mytracks.content.WaypointsColumns;
import com.google.android.apps.mytracks.services.ITrackRecordingService;
import com.google.android.apps.mytracks.services.TrackRecordingServiceBinder;
import com.google.android.apps.mytracks.util.StringUtils; import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
@@ -43,6 +45,7 @@ import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.SimpleCursorAdapter; import android.widget.SimpleCursorAdapter;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
/** /**
* Activity which shows the list of waypoints in a track. * Activity which shows the list of waypoints in a track.
@@ -181,17 +184,10 @@ public class WaypointsList extends ListActivity
default: default:
return; return;
} }
long id; long id = insertWaypoint(request);
try {
id = MyTracks.getInstance().insertWaypoint(request);
} catch (RemoteException e) {
Log.e(Constants.TAG, "Cannot insert marker.", e);
return;
} catch (IllegalStateException e) {
Log.e(Constants.TAG, "Cannot insert marker.", e);
return;
}
if (id < 0) { if (id < 0) {
Toast.makeText(this, R.string.error_unable_to_insert_marker,
Toast.LENGTH_LONG).show();
Log.e(Constants.TAG, "Failed to insert marker."); Log.e(Constants.TAG, "Failed to insert marker.");
return; return;
} }
@@ -200,6 +196,27 @@ public class WaypointsList extends ListActivity
startActivity(intent); startActivity(intent);
} }
private long insertWaypoint(WaypointCreationRequest request) {
try {
ITrackRecordingService trackRecordingService =
TrackRecordingServiceBinder.getInstance(this).getServiceIfBound();
if (trackRecordingService != null) {
long waypointId = trackRecordingService.insertWaypoint(request);
if (waypointId >= 0) {
Toast.makeText(this, R.string.status_statistics_inserted,
Toast.LENGTH_LONG).show();
return waypointId;
}
}
} catch (RemoteException e) {
Log.e(Constants.TAG, "Cannot insert marker.", e);
} catch (IllegalStateException e) {
Log.e(Constants.TAG, "Cannot insert marker.", e);
}
return -1;
}
private void setListAdapter() { private void setListAdapter() {
// Get a cursor with all tracks // Get a cursor with all tracks
SimpleCursorAdapter adapter = new SimpleCursorAdapter( SimpleCursorAdapter adapter = new SimpleCursorAdapter(