mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Address comments. Merge in Rodrigo's Changes.
This commit is contained in:
@@ -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());
|
||||
|
||||
+1
-2
@@ -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
|
||||
|
||||
+1
-3
@@ -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()) {
|
||||
|
||||
+2
-1
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user