Allowing certain data hub operations to work even if not started yet.

This commit is contained in:
Rodrigo Damazio
2011-03-26 03:26:57 -07:00
parent e2548ac9e2
commit 6ff39be4bf
2 changed files with 27 additions and 18 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;
} }
/** /**