forked from upstream-mirrors/OpenTracks
PeriodTaskFactory: refactor interfaces.
This commit is contained in:
@@ -50,8 +50,8 @@ import de.dennisguse.opentracks.services.handlers.EGM2008CorrectionManager;
|
|||||||
import de.dennisguse.opentracks.services.handlers.GpsStatusValue;
|
import de.dennisguse.opentracks.services.handlers.GpsStatusValue;
|
||||||
import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
|
import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
|
||||||
import de.dennisguse.opentracks.services.tasks.AnnouncementPeriodicTask;
|
import de.dennisguse.opentracks.services.tasks.AnnouncementPeriodicTask;
|
||||||
import de.dennisguse.opentracks.services.tasks.PeriodicTask;
|
|
||||||
import de.dennisguse.opentracks.services.tasks.PeriodicTaskExecutor;
|
import de.dennisguse.opentracks.services.tasks.PeriodicTaskExecutor;
|
||||||
|
import de.dennisguse.opentracks.services.tasks.PeriodicTaskFactory;
|
||||||
import de.dennisguse.opentracks.settings.SettingsActivity;
|
import de.dennisguse.opentracks.settings.SettingsActivity;
|
||||||
import de.dennisguse.opentracks.stats.TrackStatistics;
|
import de.dennisguse.opentracks.stats.TrackStatistics;
|
||||||
import de.dennisguse.opentracks.util.ExportUtils;
|
import de.dennisguse.opentracks.util.ExportUtils;
|
||||||
@@ -209,7 +209,7 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
|||||||
return trackRecordingManager.insertMarker(name, category, description, photoUrl);
|
return trackRecordingManager.insertMarker(name, category, description, photoUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(@NonNull PeriodicTask periodicTask) {
|
public void run(@NonNull PeriodicTaskFactory.Task periodicTask) {
|
||||||
periodicTask.run(recordingStatus.getTrackId(), trackRecordingManager.getTrackStatistics());
|
periodicTask.run(recordingStatus.getTrackId(), trackRecordingManager.getTrackStatistics());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ public class TrackPointCreator {
|
|||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
private final Callback service;
|
private final Callback service;
|
||||||
// Disabled to simplify testing and implementation of #822
|
|
||||||
// private ExecutorService serviceExecutor;
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private Clock clock = Clock.systemUTC();
|
private Clock clock = Clock.systemUTC();
|
||||||
@@ -52,7 +50,6 @@ public class TrackPointCreator {
|
|||||||
|
|
||||||
public void start(@NonNull Context context) {
|
public void start(@NonNull Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
// serviceExecutor = Executors.newSingleThreadExecutor();
|
|
||||||
|
|
||||||
SharedPreferences sharedPreferences = PreferencesUtils.getSharedPreferences(context);
|
SharedPreferences sharedPreferences = PreferencesUtils.getSharedPreferences(context);
|
||||||
locationHandler.onStart(context, sharedPreferences);
|
locationHandler.onStart(context, sharedPreferences);
|
||||||
@@ -100,11 +97,6 @@ public class TrackPointCreator {
|
|||||||
public void stop() {
|
public void stop() {
|
||||||
locationHandler.onStop();
|
locationHandler.onStop();
|
||||||
|
|
||||||
// if (serviceExecutor != null) {
|
|
||||||
// serviceExecutor.shutdownNow();
|
|
||||||
// }
|
|
||||||
// serviceExecutor = null;
|
|
||||||
|
|
||||||
if (remoteSensorManager != null) {
|
if (remoteSensorManager != null) {
|
||||||
remoteSensorManager.stop();
|
remoteSensorManager.stop();
|
||||||
remoteSensorManager = null;
|
remoteSensorManager = null;
|
||||||
@@ -128,13 +120,8 @@ public class TrackPointCreator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onNewTrackPoint(TrackPoint trackPoint, Distance thresholdHorizontalAccuracy) {
|
public void onNewTrackPoint(TrackPoint trackPoint, Distance thresholdHorizontalAccuracy) {
|
||||||
// if (serviceExecutor == null || serviceExecutor.isTerminated() || serviceExecutor.isShutdown()) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
fillAndReset(trackPoint);
|
fillAndReset(trackPoint);
|
||||||
|
|
||||||
// serviceExecutor.execute(() -> service.newTrackPoint(trackPoint, thresholdHorizontalAccuracy));
|
|
||||||
service.newTrackPoint(trackPoint, thresholdHorizontalAccuracy);
|
service.newTrackPoint(trackPoint, thresholdHorizontalAccuracy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ import de.dennisguse.opentracks.viewmodels.IntervalStatistics;
|
|||||||
*
|
*
|
||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
*/
|
*/
|
||||||
public class AnnouncementPeriodicTask implements PeriodicTask {
|
public class AnnouncementPeriodicTask implements PeriodicTaskFactory.Task {
|
||||||
|
|
||||||
private static final String TAG = AnnouncementPeriodicTask.class.getSimpleName();
|
private static final String TAG = AnnouncementPeriodicTask.class.getSimpleName();
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ public class AnnouncementPeriodicTask implements PeriodicTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public PeriodicTask create(Context context) {
|
public Task create(Context context) {
|
||||||
return new AnnouncementPeriodicTask(context);
|
return new AnnouncementPeriodicTask(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2009 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.dennisguse.opentracks.services.tasks;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.data.Track;
|
|
||||||
import de.dennisguse.opentracks.stats.TrackStatistics;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is interface for a task that will be executed on some schedule.
|
|
||||||
*
|
|
||||||
* @author Sandor Dornbush
|
|
||||||
*/
|
|
||||||
public interface PeriodicTask {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets up this task for subsequent calls to the run method.
|
|
||||||
*/
|
|
||||||
void start();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method will be called periodically.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
void run(@NonNull Track.Id trackId, @NonNull TrackStatistics trackStatistics);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shuts down this task and clean up resources.
|
|
||||||
*/
|
|
||||||
void shutdown();
|
|
||||||
}
|
|
||||||
@@ -49,7 +49,7 @@ public class PeriodicTaskExecutor {
|
|||||||
*/
|
*/
|
||||||
private int taskFrequency;
|
private int taskFrequency;
|
||||||
|
|
||||||
private PeriodicTask periodicTask;
|
private PeriodicTaskFactory.Task periodicTask;
|
||||||
|
|
||||||
// Time periodic task executor
|
// Time periodic task executor
|
||||||
private TimerTaskExecutor timerTaskExecutor = null;
|
private TimerTaskExecutor timerTaskExecutor = null;
|
||||||
|
|||||||
@@ -20,18 +20,40 @@ import android.content.Context;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
|
import de.dennisguse.opentracks.stats.TrackStatistics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for classes that can create {@link PeriodicTask}.
|
* An interface for classes that can create {@link Task}.
|
||||||
*
|
*
|
||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
*/
|
*/
|
||||||
interface PeriodicTaskFactory {
|
public interface PeriodicTaskFactory {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
Task create(Context context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link PeriodicTask}.
|
* This is interface for a task that will be executed on some schedule.
|
||||||
*
|
*
|
||||||
* @return the task, or null if the task is not supported
|
* @author Sandor Dornbush
|
||||||
*/
|
*/
|
||||||
@NonNull
|
interface Task {
|
||||||
PeriodicTask create(Context context);
|
|
||||||
|
/**
|
||||||
|
* Sets up this task for subsequent calls to the run method.
|
||||||
|
*/
|
||||||
|
void start();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will be called periodically.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
void run(@NonNull Track.Id trackId, @NonNull TrackStatistics trackStatistics);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuts down this task and clean up resources.
|
||||||
|
*/
|
||||||
|
void shutdown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -30,13 +30,13 @@ import de.dennisguse.opentracks.services.TrackRecordingService;
|
|||||||
*/
|
*/
|
||||||
class TimerTaskExecutor {
|
class TimerTaskExecutor {
|
||||||
|
|
||||||
private final PeriodicTask periodicTask;
|
private final PeriodicTaskFactory.Task periodicTask;
|
||||||
private final TrackRecordingService trackRecordingService;
|
private final TrackRecordingService trackRecordingService;
|
||||||
|
|
||||||
private TimerTask timerTask;
|
private TimerTask timerTask;
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
|
|
||||||
public TimerTaskExecutor(PeriodicTask periodicTask, TrackRecordingService trackRecordingService) {
|
public TimerTaskExecutor(PeriodicTaskFactory.Task periodicTask, TrackRecordingService trackRecordingService) {
|
||||||
this.periodicTask = periodicTask;
|
this.periodicTask = periodicTask;
|
||||||
this.trackRecordingService = trackRecordingService;
|
this.trackRecordingService = trackRecordingService;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user