Address comments. Merge in Rodrigo's Changes.

This commit is contained in:
Sandor Dornbush
2011-04-11 19:24:36 -07:00
parent 8ba9b47141
commit 252f88e362
7 changed files with 37 additions and 26 deletions
@@ -362,6 +362,12 @@ public class MyTracks extends TabActivity implements OnTouchListener,
Log.d(TAG, "MyTracks.onStart");
super.onStart();
dataHub.start();
// Ensure that service is running if we're supposed to be recording
if (dataHub.isRecording()) {
Intent startIntent = new Intent(this, TrackRecordingService.class);
startService(startIntent);
}
}
/*
@@ -25,7 +25,6 @@ import com.google.android.apps.mytracks.content.TrackPointsColumns;
import com.google.android.apps.mytracks.content.TracksColumns;
import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.WaypointsColumns;
import com.google.android.apps.mytracks.services.TrackRecordingService;
import com.google.android.apps.mytracks.util.ApiFeatures;
import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.android.maps.mytracks.R;
@@ -281,17 +280,7 @@ public class TrackDataHub {
started = true;
sharedPreferences.registerOnSharedPreferenceChangeListener(preferenceListener);
selectedTrackId = sharedPreferences.getLong(SELECTED_TRACK_KEY, -1);
recordingTrackId = sharedPreferences.getLong(RECORDING_TRACK_KEY, -1);
useMetricUnits = sharedPreferences.getBoolean(METRIC_UNITS_KEY, true);
reportSpeed = sharedPreferences.getBoolean(SPEED_REPORTING_KEY, true);
minRequiredAccuracy = sharedPreferences.getInt(MIN_REQUIRED_ACCURACY_KEY,
Constants.DEFAULT_MIN_REQUIRED_ACCURACY);
if (recordingTrackId > 0) {
Intent startIntent = new Intent(context, TrackRecordingService.class);
context.startService(startIntent);
}
loadSharedPreferences();
// This may or may not register internal listeners, depending on whether
// we already had external listeners.
@@ -302,6 +291,15 @@ public class TrackDataHub {
reloadDataFor(getRegisteredListenerArray());
}
private void loadSharedPreferences() {
selectedTrackId = sharedPreferences.getLong(SELECTED_TRACK_KEY, -1);
recordingTrackId = sharedPreferences.getLong(RECORDING_TRACK_KEY, -1);
useMetricUnits = sharedPreferences.getBoolean(METRIC_UNITS_KEY, true);
reportSpeed = sharedPreferences.getBoolean(SPEED_REPORTING_KEY, true);
minRequiredAccuracy = sharedPreferences.getInt(MIN_REQUIRED_ACCURACY_KEY,
Constants.DEFAULT_MIN_REQUIRED_ACCURACY);
}
/**
* Stops listening to data sources and reporting the data to external
* listeners.
@@ -396,26 +394,31 @@ public class TrackDataHub {
/** Returns the ID of the currently-selected track. */
public long getSelectedTrackId() {
checkStarted();
if (!started) {
loadSharedPreferences();
}
return selectedTrackId;
}
/** Returns whether there's a track currently selected. */
public boolean isATrackSelected() {
checkStarted();
return selectedTrackId > 0;
return getSelectedTrackId() > 0;
}
/** Returns whether we're currently recording a track. */
public boolean isRecording() {
checkStarted();
if (!started) {
loadSharedPreferences();
}
return recordingTrackId > 0;
}
/** Returns whether the selected track is still being recorded. */
public boolean isRecordingSelected() {
checkStarted();
return isRecording() && recordingTrackId == selectedTrackId;
if (!started) {
loadSharedPreferences();
}
return recordingTrackId > 0 && recordingTrackId == selectedTrackId;
}
/**
@@ -696,8 +696,6 @@ public class TrackRecordingService extends Service implements LocationListener {
* Creates the periodic task executors.
*/
private void setUpTaskExecutors() {
Log.d(TAG, "TrackRecordingService.setUpTasks: "
+ announcementExecutor);
announcementExecutor = new PeriodicTaskExecutor(
this, new StatusAnnouncerFactory(ApiFeatures.getInstance()));
splitExecutor = new PeriodicTaskExecutor(this, new SplitTask.Factory());
@@ -29,6 +29,5 @@ public interface PeriodicTaskFactory {
*
* @return the task, or null if task is not supported
*/
abstract PeriodicTask create(Context context);
PeriodicTask create(Context context);
}
@@ -28,6 +28,9 @@ import android.content.Context;
*/
public class SplitTask implements PeriodicTask {
private SplitTask() {
}
@Override
public void run(TrackRecordingService service) {
service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
@@ -41,6 +44,9 @@ public class SplitTask implements PeriodicTask {
public void start() {
}
/**
* Create new SplitTasks.
*/
public static class Factory implements PeriodicTaskFactory {
@Override
@@ -34,9 +34,7 @@ public class StatusAnnouncerFactory implements PeriodicTaskFactory {
this.hasTts = apiFeatures.hasTextToSpeech();
}
/* (non-Javadoc)
* @see com.google.android.apps.mytracks.services.tasks.PeriodicTaskFactory#create(android.content.Context)
*/
@Override
public PeriodicTask create(Context context) {
if (hasTts) {
if (ApiFeatures.getInstance().isAudioFocusSupported()) {
@@ -102,7 +102,8 @@ public class StatusAnnouncerTask implements PeriodicTask {
*/
protected void onTtsInit(int status) {
Log.i(TAG, "TrackRecordingService.TTS init: " + status);
this.ready = status == TextToSpeech.SUCCESS;
// TTS should be valid here but NPE exceptions were reported to the market.
this.ready = status == TextToSpeech.SUCCESS && tts != null;
if (ready) {
// Force the language to be the same as the string we will be speaking,