forked from upstream-mirrors/OpenTracks
Organized code in handleStartCommand into smaller methods to better see the code
paths and for eaier maintainability.
This commit is contained in:
@@ -283,30 +283,46 @@ public class TrackRecordingService extends Service {
|
|||||||
Log.d(TAG,
|
Log.d(TAG,
|
||||||
"TrackRecordingService.handleStartCommand: " + startId);
|
"TrackRecordingService.handleStartCommand: " + startId);
|
||||||
|
|
||||||
|
if (intent == null)
|
||||||
|
return;
|
||||||
|
|
||||||
// Check if called on phone reboot with resume intent.
|
// Check if called on phone reboot with resume intent.
|
||||||
if (intent != null) {
|
if (intent.getBooleanExtra(RESUME_TRACK_EXTRA_NAME, false)) {
|
||||||
if (intent.getBooleanExtra(RESUME_TRACK_EXTRA_NAME, false)) {
|
resumeTrack(startId);
|
||||||
resumeTrack(startId);
|
} else {
|
||||||
} else {
|
try {
|
||||||
// Process actions for controlling the service.
|
// Process actions for controlling the service.
|
||||||
|
processStartStopIntent(intent);
|
||||||
String action = intent.getAction();
|
} catch (IllegalStateException e) {
|
||||||
try {
|
/* Eat the exception if our sender says to ignore it, e.g., the Widget. */
|
||||||
if (getString(R.string.start_new_track_action).equals(action)) {
|
if (!intent.getBooleanExtra(getString(R.string.ignore_illegal_state), false))
|
||||||
startNewTrack();
|
throw e;
|
||||||
if (intent.getBooleanExtra(getString(R.string.select_new_track_extra), false)) {
|
|
||||||
prefManager.setSelectedTrack(recordingTrackId);
|
|
||||||
}
|
|
||||||
} else if (getString(R.string.end_current_track_action).equals(action)) {
|
|
||||||
endCurrentTrack();
|
|
||||||
}
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
if (!intent.getBooleanExtra(getString(R.string.ignore_illegal_state), false))
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void processStartStopIntent(Intent intent) {
|
||||||
|
String action = intent.getAction();
|
||||||
|
|
||||||
|
if (isNewTrackAction(action)) {
|
||||||
|
boolean selectNewTrack = intent.getBooleanExtra(getString(R.string.select_new_track_extra), false);
|
||||||
|
|
||||||
|
startNewTrack();
|
||||||
|
if (selectNewTrack) {
|
||||||
|
prefManager.setSelectedTrack(recordingTrackId);
|
||||||
|
}
|
||||||
|
} else if (isEndTrackAction(action)) {
|
||||||
|
endCurrentTrack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isNewTrackAction(String action) {
|
||||||
|
return getString(R.string.start_new_track_action).equals(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isEndTrackAction(String action) {
|
||||||
|
return getString(R.string.end_current_track_action).equals(action);
|
||||||
|
}
|
||||||
|
|
||||||
private void resumeTrack(int startId) {
|
private void resumeTrack(int startId) {
|
||||||
Log.d(TAG, "TrackRecordingService: requested resume");
|
Log.d(TAG, "TrackRecordingService: requested resume");
|
||||||
|
|||||||
Reference in New Issue
Block a user