forked from upstream-mirrors/OpenTracks
Addressed Sandor's comments.
This commit is contained in:
@@ -313,9 +313,6 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
|||||||
SharedPreferences prefs =
|
SharedPreferences prefs =
|
||||||
getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0);
|
getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0);
|
||||||
if (prefs != null) {
|
if (prefs != null) {
|
||||||
// Dump all preferences.
|
|
||||||
Log.i(MyTracksConstants.TAG, "Shared preferences:" + prefs.getAll());
|
|
||||||
|
|
||||||
selectedTrackId =
|
selectedTrackId =
|
||||||
prefs.getLong(getString(R.string.selected_track_key), -1);
|
prefs.getLong(getString(R.string.selected_track_key), -1);
|
||||||
recordingTrackId =
|
recordingTrackId =
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ public class MyTracksMap extends MapActivity
|
|||||||
private double variation;
|
private double variation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* From the shared preferences:
|
* From the shared preferences.
|
||||||
*/
|
*/
|
||||||
private int minRequiredAccuracy =
|
private int minRequiredAccuracy =
|
||||||
MyTracksSettings.DEFAULT_MIN_REQUIRED_ACCURACY;
|
MyTracksSettings.DEFAULT_MIN_REQUIRED_ACCURACY;
|
||||||
@@ -135,8 +135,8 @@ public class MyTracksMap extends MapActivity
|
|||||||
private Location currentLocation;
|
private Location currentLocation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A thread with a looper. Post to updateTrackHandler to execute Runnables on
|
* A thread with a looper. Post to updateTrackHandler to execute
|
||||||
* this thread.
|
* {@link Runnable}s on this thread.
|
||||||
*/
|
*/
|
||||||
private HandlerThread updateTrackThread;
|
private HandlerThread updateTrackThread;
|
||||||
|
|
||||||
@@ -146,6 +146,8 @@ public class MyTracksMap extends MapActivity
|
|||||||
private Handler updateTrackHandler;
|
private Handler updateTrackHandler;
|
||||||
|
|
||||||
private MyTracksProviderUtils providerUtils;
|
private MyTracksProviderUtils providerUtils;
|
||||||
|
|
||||||
|
private SharedPreferences sharedPreferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A runnable that updates the track from the provider (looking for points
|
* A runnable that updates the track from the provider (looking for points
|
||||||
@@ -331,7 +333,6 @@ public class MyTracksMap extends MapActivity
|
|||||||
@Override
|
@Override
|
||||||
public void onChange(boolean selfChange) {
|
public void onChange(boolean selfChange) {
|
||||||
Log.d(MyTracksConstants.TAG, "MyTracksMap: ContentObserver.onChange");
|
Log.d(MyTracksConstants.TAG, "MyTracksMap: ContentObserver.onChange");
|
||||||
|
|
||||||
if (!isRecordingSelected()) {
|
if (!isRecordingSelected()) {
|
||||||
// No track, or one other than the recording track is selected,
|
// No track, or one other than the recording track is selected,
|
||||||
// don't bother.
|
// don't bother.
|
||||||
@@ -356,32 +357,26 @@ public class MyTracksMap extends MapActivity
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Read shared preferences and register change listener:
|
// Read shared preferences and register change listener.
|
||||||
SharedPreferences preferences =
|
sharedPreferences = getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0);
|
||||||
getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0);
|
if (sharedPreferences != null) {
|
||||||
if (preferences != null) {
|
reloadSharedPreferences(sharedPreferences, null);
|
||||||
minRequiredAccuracy = preferences.getInt(
|
|
||||||
getString(R.string.min_required_accuracy_key),
|
|
||||||
MyTracksSettings.DEFAULT_MIN_REQUIRED_ACCURACY);
|
|
||||||
recordingTrackId =
|
|
||||||
preferences.getLong(getString(R.string.recording_track_key), -1);
|
|
||||||
long selectedTrackId =
|
|
||||||
preferences.getLong(getString(R.string.selected_track_key), -1);
|
|
||||||
if (selectedTrackId >= 0) {
|
|
||||||
setSelectedTrack(selectedTrackId);
|
|
||||||
}
|
|
||||||
updateOptionsButton();
|
updateOptionsButton();
|
||||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
Log.d(MyTracksConstants.TAG, "MyTracksMap.onDestroy");
|
Log.d(MyTracksConstants.TAG, "MyTracksMap.onDestroy");
|
||||||
|
|
||||||
if (updateTrackThread != null) {
|
if (updateTrackThread != null) {
|
||||||
ApiFeatures.getInstance().getApiPlatformAdapter().stopHandlerThread(
|
ApiFeatures.getInstance().getApiPlatformAdapter().stopHandlerThread(
|
||||||
updateTrackThread);
|
updateTrackThread);
|
||||||
}
|
}
|
||||||
|
if (sharedPreferences != null) {
|
||||||
|
sharedPreferences.unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
@@ -447,9 +442,8 @@ public class MyTracksMap extends MapActivity
|
|||||||
Log.d(MyTracksConstants.TAG, "MyTracksMap.onResume");
|
Log.d(MyTracksConstants.TAG, "MyTracksMap.onResume");
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
// Reload all preferences as they might have changed meanwhile.
|
// Reload all preferences as they might have changed since last run.
|
||||||
reloadSharedPreferences(
|
reloadSharedPreferences(sharedPreferences, null);
|
||||||
getSharedPreferences(MyTracksSettings.SETTINGS_NAME, 0), null);
|
|
||||||
|
|
||||||
// Make sure any updates that might have happened are propagated to the
|
// Make sure any updates that might have happened are propagated to the
|
||||||
// Map overlay:
|
// Map overlay:
|
||||||
@@ -707,11 +701,14 @@ public class MyTracksMap extends MapActivity
|
|||||||
* @param trackId a given track id
|
* @param trackId a given track id
|
||||||
*/
|
*/
|
||||||
public void setSelectedTrack(final long trackId) {
|
public void setSelectedTrack(final long trackId) {
|
||||||
|
Log.d(MyTracksConstants.TAG, "MyTracksMap.setSelectedTrack: "
|
||||||
|
+ "id = " + trackId + ", selectedTrackId = " + selectedTrackId);
|
||||||
|
|
||||||
if (selectedTrackId == trackId) {
|
if (selectedTrackId == trackId) {
|
||||||
// Selected track did not change, nothing to do.
|
// Selected track did not change, nothing to do.
|
||||||
mapOverlay.setTrackDrawingEnabled(isATrackSelected());
|
mapOverlay.setTrackDrawingEnabled(isATrackSelected());
|
||||||
mapView.invalidate();
|
|
||||||
updateOptionsButton();
|
updateOptionsButton();
|
||||||
|
mapView.invalidate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -906,6 +903,8 @@ public class MyTracksMap extends MapActivity
|
|||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(
|
public void onSharedPreferenceChanged(
|
||||||
final SharedPreferences sharedPreferences, final String key) {
|
final SharedPreferences sharedPreferences, final String key) {
|
||||||
|
Log.d(MyTracksConstants.TAG,
|
||||||
|
"MyTracksMap.onSharedPreferenceChanged: " + key);
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
uiHandler.post(new Runnable() {
|
uiHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@@ -998,11 +997,6 @@ public class MyTracksMap extends MapActivity
|
|||||||
getString(R.string.min_required_accuracy_key),
|
getString(R.string.min_required_accuracy_key),
|
||||||
MyTracksSettings.DEFAULT_MIN_REQUIRED_ACCURACY);
|
MyTracksSettings.DEFAULT_MIN_REQUIRED_ACCURACY);
|
||||||
}
|
}
|
||||||
if (key == null || key.equals(getString(R.string.selected_track_key))) {
|
|
||||||
long selectedTrackId = sharedPreferences.getLong(
|
|
||||||
getString(R.string.selected_track_key), -1);
|
|
||||||
setSelectedTrack(selectedTrackId);
|
|
||||||
}
|
|
||||||
if (key == null || key.equals(getString(R.string.recording_track_key))) {
|
if (key == null || key.equals(getString(R.string.recording_track_key))) {
|
||||||
recordingTrackId = sharedPreferences.getLong(
|
recordingTrackId = sharedPreferences.getLong(
|
||||||
getString(R.string.recording_track_key), -1);
|
getString(R.string.recording_track_key), -1);
|
||||||
@@ -1011,6 +1005,10 @@ public class MyTracksMap extends MapActivity
|
|||||||
mapView.postInvalidate();
|
mapView.postInvalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (key == null || key.equals(getString(R.string.selected_track_key))) {
|
||||||
|
setSelectedTrack(sharedPreferences.getLong(
|
||||||
|
getString(R.string.selected_track_key), -1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readAllNewTrackPoints() {
|
private void readAllNewTrackPoints() {
|
||||||
|
|||||||
+13
-7
@@ -135,12 +135,13 @@ public class TrackRecordingServiceTest
|
|||||||
// Clear the number of attempts and set the timeout to 10 min.
|
// Clear the number of attempts and set the timeout to 10 min.
|
||||||
updateAutoResumePrefs(0, 10);
|
updateAutoResumePrefs(0, 10);
|
||||||
|
|
||||||
// Resume the service. It should resume recording of the previous track.
|
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||||
Intent startIntent = createStartIntent();
|
Intent startIntent = createStartIntent();
|
||||||
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true);
|
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true);
|
||||||
startService(startIntent);
|
startService(startIntent);
|
||||||
assertNotNull(getService());
|
assertNotNull(getService());
|
||||||
|
|
||||||
|
// We expect to resume the previous track.
|
||||||
assertTrue(getService().isRecording());
|
assertTrue(getService().isRecording());
|
||||||
ITrackRecordingService service = bindAndGetService(createStartIntent());
|
ITrackRecordingService service = bindAndGetService(createStartIntent());
|
||||||
assertEquals(123, service.getRecordingTrackId());
|
assertEquals(123, service.getRecordingTrackId());
|
||||||
@@ -160,13 +161,14 @@ public class TrackRecordingServiceTest
|
|||||||
assertEquals(id, sharedPreferences.getLong(
|
assertEquals(id, sharedPreferences.getLong(
|
||||||
context.getString(R.string.recording_track_key), -1));
|
context.getString(R.string.recording_track_key), -1));
|
||||||
|
|
||||||
|
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||||
Intent startIntent = createStartIntent();
|
Intent startIntent = createStartIntent();
|
||||||
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true);
|
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true);
|
||||||
startService(startIntent);
|
startService(startIntent);
|
||||||
assertNotNull(getService());
|
assertNotNull(getService());
|
||||||
|
|
||||||
// TODO: shutdownService() has a bug and doesn't set mServiceCreated
|
// TODO: shutdownService() has a bug and doesn't set mServiceCreated
|
||||||
// to false, thus preventing from second call to onCreate().
|
// to false, thus preventing from a second call to onCreate().
|
||||||
// Report the bug to Android team. Until then, the following check
|
// Report the bug to Android team. Until then, the following check
|
||||||
// must be commented out.
|
// must be commented out.
|
||||||
|
|
||||||
@@ -181,12 +183,13 @@ public class TrackRecordingServiceTest
|
|||||||
// Clear the number of attempts and set the timeout to 10 min.
|
// Clear the number of attempts and set the timeout to 10 min.
|
||||||
updateAutoResumePrefs(0, 10);
|
updateAutoResumePrefs(0, 10);
|
||||||
|
|
||||||
// Resume the service. It should resume recording of the previous track.
|
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||||
Intent startIntent = createStartIntent();
|
Intent startIntent = createStartIntent();
|
||||||
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true);
|
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true);
|
||||||
startService(startIntent);
|
startService(startIntent);
|
||||||
assertNotNull(getService());
|
assertNotNull(getService());
|
||||||
|
|
||||||
|
// We don't expect to resume the previous track, because it was stopped.
|
||||||
assertFalse(getService().isRecording());
|
assertFalse(getService().isRecording());
|
||||||
ITrackRecordingService service = bindAndGetService(createStartIntent());
|
ITrackRecordingService service = bindAndGetService(createStartIntent());
|
||||||
assertEquals(-1, service.getRecordingTrackId());
|
assertEquals(-1, service.getRecordingTrackId());
|
||||||
@@ -200,12 +203,13 @@ public class TrackRecordingServiceTest
|
|||||||
// Clear the number of attempts and set the timeout to 10 min.
|
// Clear the number of attempts and set the timeout to 10 min.
|
||||||
updateAutoResumePrefs(0, 10);
|
updateAutoResumePrefs(0, 10);
|
||||||
|
|
||||||
// Resume the service. It should resume recording of the previous track.
|
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||||
Intent startIntent = createStartIntent();
|
Intent startIntent = createStartIntent();
|
||||||
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true);
|
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true);
|
||||||
startService(startIntent);
|
startService(startIntent);
|
||||||
assertNotNull(getService());
|
assertNotNull(getService());
|
||||||
|
|
||||||
|
// We don't expect to resume the previous track, because it has expired.
|
||||||
assertFalse(getService().isRecording());
|
assertFalse(getService().isRecording());
|
||||||
ITrackRecordingService service = bindAndGetService(createStartIntent());
|
ITrackRecordingService service = bindAndGetService(createStartIntent());
|
||||||
assertEquals(-1, service.getRecordingTrackId());
|
assertEquals(-1, service.getRecordingTrackId());
|
||||||
@@ -220,12 +224,14 @@ public class TrackRecordingServiceTest
|
|||||||
updateAutoResumePrefs(
|
updateAutoResumePrefs(
|
||||||
TrackRecordingService.MAX_AUTO_RESUME_TRACK_RETRY_ATTEMPTS, 10);
|
TrackRecordingService.MAX_AUTO_RESUME_TRACK_RETRY_ATTEMPTS, 10);
|
||||||
|
|
||||||
// Resume the service. It should resume recording of the previous track.
|
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||||
Intent startIntent = createStartIntent();
|
Intent startIntent = createStartIntent();
|
||||||
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true);
|
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true);
|
||||||
startService(startIntent);
|
startService(startIntent);
|
||||||
assertNotNull(getService());
|
assertNotNull(getService());
|
||||||
|
|
||||||
|
// We don't expect to resume the previous track, because there were already
|
||||||
|
// too many attempts.
|
||||||
assertFalse(getService().isRecording());
|
assertFalse(getService().isRecording());
|
||||||
ITrackRecordingService service = bindAndGetService(createStartIntent());
|
ITrackRecordingService service = bindAndGetService(createStartIntent());
|
||||||
assertEquals(-1, service.getRecordingTrackId());
|
assertEquals(-1, service.getRecordingTrackId());
|
||||||
|
|||||||
Reference in New Issue
Block a user