2
* Copyright 2009 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
* use this file except in compliance with the License. You may obtain a copy of
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
* License for the specific language governing permissions and limitations under
17
package org.opensatnav.contribute.services;
19
import org.opensatnav.OpenSatNavConstants;
21
import android.util.Log;
23
import java.util.Date;
24
import java.util.Timer;
25
import java.util.TimerTask;
28
* This class will periodically announce the user's trip statitics.
30
* @author Sandor Dornbush
32
public class PeriodicTaskExecuter {
34
private final TrackRecordingService service;
37
* A timer to schedule the announcements.
39
private Timer timer = new Timer();
41
private final PeriodicTask task;
43
public PeriodicTaskExecuter(PeriodicTask task,
44
TrackRecordingService service) {
46
this.service = service;
50
* Schedules the task at the given interval.
52
* @param interval The interval in milliseconds
54
public void scheduleTask(long interval) {
62
long now = System.currentTimeMillis();
63
long next = service.getTripStatistics().getStartTime();
64
while (next < now) next += interval;
66
Date start = new Date(next);
67
Log.i(OpenSatNavConstants.LOG_TAG,
68
"StatusAnnouncer scheduled to start at " + start + " every "
69
+ interval + " milliseconds.");
70
timer.scheduleAtFixedRate(new PeriodicTimerTask(), start, interval);
74
* Cleans up this object.
76
public void shutdown() {
84
* The timer task to announce the trip status.
86
private class PeriodicTimerTask extends TimerTask {