mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
Cleanup: Renamed HandlerServer to TrackPointCreator.
This commit is contained in:
+7
-7
@@ -1,5 +1,9 @@
|
||||
package de.dennisguse.opentracks.io.file.importer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -51,15 +55,11 @@ import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
||||
import de.dennisguse.opentracks.io.file.exporter.TrackExporter;
|
||||
import de.dennisguse.opentracks.services.TrackRecordingService;
|
||||
import de.dennisguse.opentracks.services.handlers.HandlerServer;
|
||||
import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
|
||||
import de.dennisguse.opentracks.services.sensors.AltitudeSumManager;
|
||||
import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager;
|
||||
import de.dennisguse.opentracks.stats.TrackStatistics;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Export a track to {@link TrackFileFormat} and verify that the import is identical.
|
||||
*/
|
||||
@@ -119,7 +119,7 @@ public class ExportImportTest {
|
||||
TrackRecordingService service = ((TrackRecordingService.Binder) mServiceRule.bindService(new Intent(context, TrackRecordingService.class)))
|
||||
.getService();
|
||||
|
||||
HandlerServer handlerServer = service.getHandlerServer();
|
||||
TrackPointCreator handlerServer = service.getHandlerServer();
|
||||
|
||||
handlerServer.setClock(Clock.fixed(Instant.parse("2020-02-02T02:02:02Z"), ZoneId.of("CET")));
|
||||
trackId = service.startNewTrack();
|
||||
@@ -380,7 +380,7 @@ public class ExportImportTest {
|
||||
}
|
||||
}
|
||||
|
||||
private void sendLocation(HandlerServer handlerServer, Instant time, double latitude, double longitude, float accuracy, float speed, float altitude, float altitudeGain, float heartRate, float cyclingCadence, float power, Distance distance) {
|
||||
private void sendLocation(TrackPointCreator handlerServer, Instant time, double latitude, double longitude, float accuracy, float speed, float altitude, float altitudeGain, float heartRate, float cyclingCadence, float power, Distance distance) {
|
||||
Location location = new Location("mock");
|
||||
location.setLatitude(latitude);
|
||||
location.setLongitude(longitude);
|
||||
|
||||
+6
-6
@@ -63,7 +63,7 @@ import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
||||
import de.dennisguse.opentracks.content.provider.CustomContentProvider;
|
||||
import de.dennisguse.opentracks.io.file.importer.TrackPointAssert;
|
||||
import de.dennisguse.opentracks.services.handlers.HandlerServer;
|
||||
import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
|
||||
import de.dennisguse.opentracks.services.sensors.AltitudeSumManager;
|
||||
import de.dennisguse.opentracks.stats.TrackStatistics;
|
||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||
@@ -212,7 +212,7 @@ public class TrackRecordingServiceTest {
|
||||
TrackRecordingService service = ((TrackRecordingService.Binder) mServiceRule.bindService(createStartIntent(context)))
|
||||
.getService();
|
||||
|
||||
HandlerServer handlerServer = service.getHandlerServer();
|
||||
TrackPointCreator handlerServer = service.getHandlerServer();
|
||||
|
||||
handlerServer.setClock(Clock.fixed(Instant.parse("2020-02-02T02:02:02Z"), ZoneId.of("CET")));
|
||||
Track.Id trackId = service.startNewTrack();
|
||||
@@ -242,7 +242,7 @@ public class TrackRecordingServiceTest {
|
||||
TrackRecordingService service = ((TrackRecordingService.Binder) mServiceRule.bindService(createStartIntent(context)))
|
||||
.getService();
|
||||
|
||||
HandlerServer handlerServer = service.getHandlerServer();
|
||||
TrackPointCreator handlerServer = service.getHandlerServer();
|
||||
|
||||
handlerServer.setClock(Clock.fixed(Instant.parse("2020-02-02T02:02:02Z"), ZoneId.of("CET")));
|
||||
Track.Id trackId = service.startNewTrack();
|
||||
@@ -281,7 +281,7 @@ public class TrackRecordingServiceTest {
|
||||
TrackRecordingService service = ((TrackRecordingService.Binder) mServiceRule.bindService(createStartIntent(context)))
|
||||
.getService();
|
||||
|
||||
HandlerServer handlerServer = service.getHandlerServer();
|
||||
TrackPointCreator handlerServer = service.getHandlerServer();
|
||||
|
||||
handlerServer.setClock(Clock.fixed(Instant.parse("2020-02-02T02:02:02Z"), ZoneId.of("CET")));
|
||||
Track.Id trackId = service.startNewTrack();
|
||||
@@ -323,7 +323,7 @@ public class TrackRecordingServiceTest {
|
||||
TrackRecordingService service = ((TrackRecordingService.Binder) mServiceRule.bindService(createStartIntent(context)))
|
||||
.getService();
|
||||
|
||||
HandlerServer handlerServer = service.getHandlerServer();
|
||||
TrackPointCreator handlerServer = service.getHandlerServer();
|
||||
|
||||
handlerServer.setClock(Clock.fixed(Instant.parse("2020-02-02T02:02:02Z"), ZoneId.of("CET")));
|
||||
Track.Id trackId = service.startNewTrack();
|
||||
@@ -405,7 +405,7 @@ public class TrackRecordingServiceTest {
|
||||
TrackRecordingService service = ((TrackRecordingService.Binder) mServiceRule.bindService(createStartIntent(context)))
|
||||
.getService();
|
||||
|
||||
HandlerServer handlerServer = service.getHandlerServer();
|
||||
TrackPointCreator handlerServer = service.getHandlerServer();
|
||||
handlerServer.stopGPS();
|
||||
|
||||
handlerServer.setClock(Clock.fixed(Instant.parse("2020-02-02T02:02:02Z"), ZoneId.of("CET")));
|
||||
|
||||
+5
-5
@@ -1,5 +1,9 @@
|
||||
package de.dennisguse.opentracks.services.handlers;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Location;
|
||||
@@ -22,10 +26,6 @@ import de.dennisguse.opentracks.content.data.Distance;
|
||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LocationHandlerTest {
|
||||
|
||||
@@ -33,7 +33,7 @@ public class LocationHandlerTest {
|
||||
private final SharedPreferences sharedPreferences = PreferencesUtils.getSharedPreferences(context);
|
||||
|
||||
@Mock
|
||||
private HandlerServer handlerServer;
|
||||
private TrackPointCreator handlerServer;
|
||||
|
||||
@InjectMocks
|
||||
private LocationHandler locationHandler;
|
||||
|
||||
+6
-6
@@ -1,5 +1,7 @@
|
||||
package de.dennisguse.opentracks.services.handlers;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
@@ -14,16 +16,14 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import de.dennisguse.opentracks.content.data.Distance;
|
||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class HandlerServerTest {
|
||||
public class TrackPointCreatorTest {
|
||||
|
||||
@Mock
|
||||
private Context context;
|
||||
|
||||
@Mock
|
||||
private HandlerServer.HandlerServerInterface server;
|
||||
private TrackPointCreator.Callback server;
|
||||
|
||||
@Mock
|
||||
private LocationHandler locationHandler;
|
||||
@@ -31,11 +31,11 @@ public class HandlerServerTest {
|
||||
@Mock
|
||||
private SharedPreferences sharedPreferences;
|
||||
|
||||
private HandlerServer subject;
|
||||
private TrackPointCreator subject;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
subject = new HandlerServer(locationHandler, server);
|
||||
subject = new TrackPointCreator(locationHandler, server);
|
||||
subject.start(context);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import de.dennisguse.opentracks.content.data.Track;
|
||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||
import de.dennisguse.opentracks.services.handlers.HandlerServer;
|
||||
import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
|
||||
import de.dennisguse.opentracks.stats.TrackStatistics;
|
||||
import de.dennisguse.opentracks.stats.TrackStatisticsUpdater;
|
||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||
@@ -79,14 +79,14 @@ class TrackRecordingManager {
|
||||
insertTrackPoint(track, segmentStartTrackPoint);
|
||||
}
|
||||
|
||||
void pause(HandlerServer handlerServer) {
|
||||
void pause(TrackPointCreator handlerServer) {
|
||||
if (lastTrackPoint != null) {
|
||||
insertTrackPointIfNewer(track, lastTrackPoint);
|
||||
}
|
||||
insertTrackPoint(track, handlerServer.createSegmentEnd());
|
||||
}
|
||||
|
||||
void end(HandlerServer handlerServer) {
|
||||
void end(TrackPointCreator handlerServer) {
|
||||
if (lastTrackPoint != null) {
|
||||
insertTrackPointIfNewer(track, lastTrackPoint);
|
||||
}
|
||||
@@ -101,7 +101,7 @@ class TrackRecordingManager {
|
||||
isIdle = false;
|
||||
}
|
||||
|
||||
Pair<Track, Pair<TrackPoint, SensorDataSet>> get(HandlerServer handlerServer) {
|
||||
Pair<Track, Pair<TrackPoint, SensorDataSet>> get(TrackPointCreator handlerServer) {
|
||||
if (handlerServer == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||
import de.dennisguse.opentracks.io.file.exporter.ExportServiceResultReceiver;
|
||||
import de.dennisguse.opentracks.services.handlers.EGM2008CorrectionManager;
|
||||
import de.dennisguse.opentracks.services.handlers.GpsStatusValue;
|
||||
import de.dennisguse.opentracks.services.handlers.HandlerServer;
|
||||
import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
|
||||
import de.dennisguse.opentracks.services.tasks.AnnouncementPeriodicTask;
|
||||
import de.dennisguse.opentracks.services.tasks.PeriodicTask;
|
||||
import de.dennisguse.opentracks.services.tasks.PeriodicTaskExecutor;
|
||||
@@ -65,7 +65,7 @@ import de.dennisguse.opentracks.util.SystemUtils;
|
||||
*
|
||||
* @author Leif Hendrik Wilden
|
||||
*/
|
||||
public class TrackRecordingService extends Service implements HandlerServer.HandlerServerInterface, ExportServiceResultReceiver.Receiver {
|
||||
public class TrackRecordingService extends Service implements TrackPointCreator.Callback, ExportServiceResultReceiver.Receiver {
|
||||
|
||||
private static final String TAG = TrackRecordingService.class.getSimpleName();
|
||||
|
||||
@@ -124,7 +124,7 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
|
||||
private final Binder binder = new Binder();
|
||||
|
||||
private HandlerServer handlerServer; //TODO Move to TrackRecordingManager?
|
||||
private TrackPointCreator handlerServer; //TODO Move to TrackRecordingManager?
|
||||
|
||||
private RecordingStatus recordingStatus;
|
||||
private MutableLiveData<RecordingStatus> recordingStatusObservable;
|
||||
@@ -143,7 +143,7 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
recordingDataObservable = new MutableLiveData<>(NOT_RECORDING);
|
||||
|
||||
trackRecordingManager = new TrackRecordingManager(this);
|
||||
handlerServer = new HandlerServer(this);
|
||||
handlerServer = new TrackPointCreator(this);
|
||||
|
||||
voiceExecutor = new PeriodicTaskExecutor(this, new AnnouncementPeriodicTask.Factory());
|
||||
|
||||
@@ -422,7 +422,7 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
|
||||
@Deprecated
|
||||
@VisibleForTesting
|
||||
public HandlerServer getHandlerServer() {
|
||||
public TrackPointCreator getHandlerServer() {
|
||||
return handlerServer;
|
||||
}
|
||||
|
||||
@@ -442,7 +442,7 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
|
||||
// Compute temporary track statistics using sensorData and update time.
|
||||
|
||||
HandlerServer localHandlerServer = this.handlerServer;
|
||||
TrackPointCreator localHandlerServer = this.handlerServer;
|
||||
if (localHandlerServer == null) {
|
||||
// when this happens, no recording is running and we should not send any notifications.
|
||||
//TODO This implementation is not a good idea; rather solve the issue for this properly
|
||||
|
||||
@@ -25,14 +25,14 @@ public class LocationHandler implements LocationListener, GpsStatus.GpsStatusLis
|
||||
private final String TAG = LocationHandler.class.getSimpleName();
|
||||
|
||||
private LocationManager locationManager;
|
||||
private final HandlerServer handlerServer;
|
||||
private final TrackPointCreator handlerServer;
|
||||
private GpsStatus gpsStatus;
|
||||
private LocationListenerPolicy locationListenerPolicy;
|
||||
private Duration currentRecordingInterval;
|
||||
private Distance thresholdHorizontalAccuracy;
|
||||
private TrackPoint lastTrackPoint;
|
||||
|
||||
public LocationHandler(HandlerServer handlerServer) {
|
||||
public LocationHandler(TrackPointCreator handlerServer) {
|
||||
this.handlerServer = handlerServer;
|
||||
}
|
||||
|
||||
|
||||
+9
-6
@@ -19,13 +19,16 @@ import de.dennisguse.opentracks.services.sensors.AltitudeSumManager;
|
||||
import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager;
|
||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||
|
||||
public class HandlerServer {
|
||||
/**
|
||||
* Creates TrackPoints while recording by fusing data from different sensors (e.g., GNSS, barometer, BLE sensors).
|
||||
*/
|
||||
public class TrackPointCreator {
|
||||
|
||||
private static final String TAG = HandlerServer.class.getSimpleName();
|
||||
private static final String TAG = TrackPointCreator.class.getSimpleName();
|
||||
|
||||
private Context context;
|
||||
|
||||
private final HandlerServerInterface service;
|
||||
private final Callback service;
|
||||
// Disabled to simplify testing and implementation of #822
|
||||
// private ExecutorService serviceExecutor;
|
||||
|
||||
@@ -36,13 +39,13 @@ public class HandlerServer {
|
||||
private BluetoothRemoteSensorManager remoteSensorManager;
|
||||
private AltitudeSumManager altitudeSumManager;
|
||||
|
||||
public HandlerServer(HandlerServerInterface service) {
|
||||
public TrackPointCreator(Callback service) {
|
||||
this.service = service;
|
||||
this.locationHandler = new LocationHandler(this);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
HandlerServer(LocationHandler locationHandler, HandlerServerInterface service) {
|
||||
TrackPointCreator(LocationHandler locationHandler, Callback service) {
|
||||
this.service = service;
|
||||
this.locationHandler = locationHandler;
|
||||
}
|
||||
@@ -183,7 +186,7 @@ public class HandlerServer {
|
||||
service.newGpsStatus(gpsStatusValue);
|
||||
}
|
||||
|
||||
public interface HandlerServerInterface {
|
||||
public interface Callback {
|
||||
void newTrackPoint(TrackPoint trackPoint, Distance thresholdHorizontalAccuracy);
|
||||
|
||||
void newGpsStatus(GpsStatusValue gpsStatusValue);
|
||||
Reference in New Issue
Block a user