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"); Log.d(TAG, "MyTracks.onStart");
super.onStart(); super.onStart();
dataHub.start(); 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.TracksColumns;
import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.WaypointsColumns; 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.ApiFeatures;
import com.google.android.apps.mytracks.util.LocationUtils; import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
@@ -281,17 +280,7 @@ public class TrackDataHub {
started = true; started = true;
sharedPreferences.registerOnSharedPreferenceChangeListener(preferenceListener); sharedPreferences.registerOnSharedPreferenceChangeListener(preferenceListener);
selectedTrackId = sharedPreferences.getLong(SELECTED_TRACK_KEY, -1); loadSharedPreferences();
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);
}
// This may or may not register internal listeners, depending on whether // This may or may not register internal listeners, depending on whether
// we already had external listeners. // we already had external listeners.
@@ -302,6 +291,15 @@ public class TrackDataHub {
reloadDataFor(getRegisteredListenerArray()); 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 * Stops listening to data sources and reporting the data to external
* listeners. * listeners.
@@ -396,26 +394,31 @@ public class TrackDataHub {
/** Returns the ID of the currently-selected track. */ /** Returns the ID of the currently-selected track. */
public long getSelectedTrackId() { public long getSelectedTrackId() {
checkStarted(); if (!started) {
loadSharedPreferences();
}
return selectedTrackId; return selectedTrackId;
} }
/** Returns whether there's a track currently selected. */ /** Returns whether there's a track currently selected. */
public boolean isATrackSelected() { public boolean isATrackSelected() {
checkStarted(); return getSelectedTrackId() > 0;
return selectedTrackId > 0;
} }
/** Returns whether we're currently recording a track. */ /** Returns whether we're currently recording a track. */
public boolean isRecording() { public boolean isRecording() {
checkStarted(); if (!started) {
loadSharedPreferences();
}
return recordingTrackId > 0; return recordingTrackId > 0;
} }
/** Returns whether the selected track is still being recorded. */ /** Returns whether the selected track is still being recorded. */
public boolean isRecordingSelected() { public boolean isRecordingSelected() {
checkStarted(); if (!started) {
return isRecording() && recordingTrackId == selectedTrackId; loadSharedPreferences();
}
return recordingTrackId > 0 && recordingTrackId == selectedTrackId;
} }
/** /**
@@ -696,8 +696,6 @@ public class TrackRecordingService extends Service implements LocationListener {
* Creates the periodic task executors. * Creates the periodic task executors.
*/ */
private void setUpTaskExecutors() { private void setUpTaskExecutors() {
Log.d(TAG, "TrackRecordingService.setUpTasks: "
+ announcementExecutor);
announcementExecutor = new PeriodicTaskExecutor( announcementExecutor = new PeriodicTaskExecutor(
this, new StatusAnnouncerFactory(ApiFeatures.getInstance())); this, new StatusAnnouncerFactory(ApiFeatures.getInstance()));
splitExecutor = new PeriodicTaskExecutor(this, new SplitTask.Factory()); splitExecutor = new PeriodicTaskExecutor(this, new SplitTask.Factory());
@@ -29,6 +29,5 @@ public interface PeriodicTaskFactory {
* *
* @return the task, or null if task is not supported * @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 { public class SplitTask implements PeriodicTask {
private SplitTask() {
}
@Override @Override
public void run(TrackRecordingService service) { public void run(TrackRecordingService service) {
service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS); service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
@@ -41,6 +44,9 @@ public class SplitTask implements PeriodicTask {
public void start() { public void start() {
} }
/**
* Create new SplitTasks.
*/
public static class Factory implements PeriodicTaskFactory { public static class Factory implements PeriodicTaskFactory {
@Override @Override
@@ -34,9 +34,7 @@ public class StatusAnnouncerFactory implements PeriodicTaskFactory {
this.hasTts = apiFeatures.hasTextToSpeech(); this.hasTts = apiFeatures.hasTextToSpeech();
} }
/* (non-Javadoc) @Override
* @see com.google.android.apps.mytracks.services.tasks.PeriodicTaskFactory#create(android.content.Context)
*/
public PeriodicTask create(Context context) { public PeriodicTask create(Context context) {
if (hasTts) { if (hasTts) {
if (ApiFeatures.getInstance().isAudioFocusSupported()) { if (ApiFeatures.getInstance().isAudioFocusSupported()) {
@@ -102,7 +102,8 @@ public class StatusAnnouncerTask implements PeriodicTask {
*/ */
protected void onTtsInit(int status) { protected void onTtsInit(int status) {
Log.i(TAG, "TrackRecordingService.TTS init: " + 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) { if (ready) {
// Force the language to be the same as the string we will be speaking, // Force the language to be the same as the string we will be speaking,