forked from upstream-mirrors/OpenTracks
Cleanup.
This commit is contained in:
@@ -88,7 +88,6 @@ public class TrackRecordingService extends Service {
|
|||||||
private Handler handler;
|
private Handler handler;
|
||||||
private LocationManagerConnector locationManagerConnector;
|
private LocationManagerConnector locationManagerConnector;
|
||||||
private PeriodicTaskExecutor voiceExecutor;
|
private PeriodicTaskExecutor voiceExecutor;
|
||||||
private SharedPreferences sharedPreferences;
|
|
||||||
private TrackRecordingServiceNotificationManager notificationManager;
|
private TrackRecordingServiceNotificationManager notificationManager;
|
||||||
private LocationListenerPolicy locationListenerPolicy;
|
private LocationListenerPolicy locationListenerPolicy;
|
||||||
|
|
||||||
@@ -144,9 +143,10 @@ public class TrackRecordingService extends Service {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// The following variables are set when recording:
|
// The following variables are set when recording:
|
||||||
private TripStatisticsUpdater trackTripStatisticsUpdater;
|
|
||||||
private WakeLock wakeLock;
|
private WakeLock wakeLock;
|
||||||
private BluetoothRemoteSensorManager remoteSensorManager;
|
private BluetoothRemoteSensorManager remoteSensorManager;
|
||||||
|
|
||||||
|
private TripStatisticsUpdater trackTripStatisticsUpdater;
|
||||||
private Location lastLocation;
|
private Location lastLocation;
|
||||||
private boolean currentSegmentHasLocation;
|
private boolean currentSegmentHasLocation;
|
||||||
private boolean isIdle;
|
private boolean isIdle;
|
||||||
@@ -204,15 +204,15 @@ public class TrackRecordingService extends Service {
|
|||||||
handler = new Handler();
|
handler = new Handler();
|
||||||
locationManagerConnector = new LocationManagerConnector(this, handler.getLooper());
|
locationManagerConnector = new LocationManagerConnector(this, handler.getLooper());
|
||||||
voiceExecutor = new PeriodicTaskExecutor(this, new AnnouncementPeriodicTaskFactory());
|
voiceExecutor = new PeriodicTaskExecutor(this, new AnnouncementPeriodicTaskFactory());
|
||||||
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
|
||||||
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
|
||||||
notificationManager = new TrackRecordingServiceNotificationManager(this);
|
notificationManager = new TrackRecordingServiceNotificationManager(this);
|
||||||
|
|
||||||
// onSharedPreferenceChanged might not set recordingTrackId.
|
// onSharedPreferenceChanged might not set recordingTrackId.
|
||||||
recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||||
|
|
||||||
// Require voiceExecutor and splitExecutor to be created.
|
PreferencesUtils.register(this, sharedPreferenceChangeListener);
|
||||||
sharedPreferenceChangeListener.onSharedPreferenceChanged(sharedPreferences, null);
|
sharedPreferenceChangeListener.onSharedPreferenceChanged(null, null);
|
||||||
|
|
||||||
handler.post(registerLocationRunnable);
|
handler.post(registerLocationRunnable);
|
||||||
|
|
||||||
@@ -252,8 +252,7 @@ public class TrackRecordingService extends Service {
|
|||||||
handler.removeCallbacks(registerLocationRunnable);
|
handler.removeCallbacks(registerLocationRunnable);
|
||||||
unregisterLocationListener();
|
unregisterLocationListener();
|
||||||
|
|
||||||
// unregister sharedPreferences before shutting down splitExecutor and voiceExecutor
|
PreferencesUtils.unregister(this, sharedPreferenceChangeListener);
|
||||||
sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
voiceExecutor.shutdown();
|
voiceExecutor.shutdown();
|
||||||
@@ -385,10 +384,7 @@ public class TrackRecordingService extends Service {
|
|||||||
trackTripStatisticsUpdater = new TripStatisticsUpdater(tripStatistics.getStartTime());
|
trackTripStatisticsUpdater = new TripStatisticsUpdater(tripStatistics.getStartTime());
|
||||||
|
|
||||||
try (TrackPointIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(track.getId(), -1L, false, TrackPointFactory.DEFAULT_LOCATION_FACTORY)) {
|
try (TrackPointIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(track.getId(), -1L, false, TrackPointFactory.DEFAULT_LOCATION_FACTORY)) {
|
||||||
while (locationIterator.hasNext()) {
|
trackTripStatisticsUpdater.addLocation(locationIterator, recordingDistanceInterval);
|
||||||
Location location = locationIterator.next();
|
|
||||||
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
|
|
||||||
}
|
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
Log.e(TAG, "RuntimeException", e);
|
Log.e(TAG, "RuntimeException", e);
|
||||||
}
|
}
|
||||||
@@ -435,7 +431,13 @@ public class TrackRecordingService extends Service {
|
|||||||
voiceExecutor.restore();
|
voiceExecutor.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void startGps() {
|
void tryStartGps() {
|
||||||
|
if (isRecording()) return;
|
||||||
|
|
||||||
|
startGps();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startGps() {
|
||||||
wakeLock = SystemUtils.acquireWakeLock(this, wakeLock);
|
wakeLock = SystemUtils.acquireWakeLock(this, wakeLock);
|
||||||
registerLocationListener();
|
registerLocationListener();
|
||||||
showNotification(true);
|
showNotification(true);
|
||||||
@@ -523,13 +525,15 @@ public class TrackRecordingService extends Service {
|
|||||||
/**
|
/**
|
||||||
* Stops gps.
|
* Stops gps.
|
||||||
*
|
*
|
||||||
* @param stop true to stop self
|
* @param shutdown true to shutdown self
|
||||||
*/
|
*/
|
||||||
void stopGps(boolean stop) {
|
void stopGps(boolean shutdown) {
|
||||||
|
if (!isRecording()) return;
|
||||||
|
|
||||||
unregisterLocationListener();
|
unregisterLocationListener();
|
||||||
showNotification(false);
|
showNotification(false);
|
||||||
wakeLock = SystemUtils.releaseWakeLock(wakeLock);
|
wakeLock = SystemUtils.releaseWakeLock(wakeLock);
|
||||||
if (stop) {
|
if (shutdown) {
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,15 +24,12 @@ class TrackRecordingServiceBinder extends android.os.Binder implements TrackReco
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startGps() {
|
public void startGps() {
|
||||||
if (!trackRecordingService.isRecording()) {
|
trackRecordingService.tryStartGps();
|
||||||
trackRecordingService.startGps();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopGps() {
|
public void stopGps() {
|
||||||
if (!trackRecordingService.isRecording()) {
|
trackRecordingService.stopGps(true);
|
||||||
trackRecordingService.stopGps(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.provider.TrackPointIterator;
|
||||||
import de.dennisguse.opentracks.util.LocationUtils;
|
import de.dennisguse.opentracks.util.LocationUtils;
|
||||||
|
|
||||||
import static de.dennisguse.opentracks.services.TrackRecordingService.MAX_NO_MOVEMENT_SPEED;
|
import static de.dennisguse.opentracks.services.TrackRecordingService.MAX_NO_MOVEMENT_SPEED;
|
||||||
@@ -178,6 +179,13 @@ public class TripStatisticsUpdater {
|
|||||||
lastMovingLocation = location;
|
lastMovingLocation = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addLocation(TrackPointIterator iterator, int minRecordingDistance) {
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Location location = iterator.next();
|
||||||
|
addLocation(location, minRecordingDistance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the smoothed elevation over several readings.
|
* Gets the smoothed elevation over several readings.
|
||||||
* The elevation readings is noisy so the smoothed elevation is better than the raw elevation for many tasks.
|
* The elevation readings is noisy so the smoothed elevation is better than the raw elevation for many tasks.
|
||||||
|
|||||||
Reference in New Issue
Block a user