-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
167 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
publicresults/src/main/java/app/owlcms/prutils/CountdownTimer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package app.owlcms.prutils; | ||
|
||
import java.util.Timer; | ||
import java.util.TimerTask; | ||
|
||
public class CountdownTimer { | ||
private Timer timer; | ||
private long startTime; | ||
private long duration; | ||
private TimerTask task; | ||
private boolean running; | ||
|
||
public CountdownTimer(long duration) { | ||
this.duration = duration; | ||
this.timer = new Timer(); | ||
this.running = false; | ||
this.task = new TimerTask() { | ||
@Override | ||
public void run() { | ||
// Task to be scheduled | ||
} | ||
}; | ||
} | ||
|
||
public void start() { | ||
this.running = true; | ||
this.startTime = System.currentTimeMillis(); | ||
this.timer.schedule(task, this.duration); | ||
} | ||
|
||
public void set(long duration) { | ||
stop(); | ||
this.duration = duration; | ||
} | ||
|
||
public void stop() { | ||
this.running = false; | ||
this.timer.cancel(); | ||
this.timer.purge(); | ||
} | ||
|
||
public void restart() { | ||
this.timer = new Timer(); | ||
this.task = new TimerTask() { | ||
@Override | ||
public void run() { | ||
// Task to be scheduled | ||
} | ||
}; | ||
start(); | ||
} | ||
|
||
public void restartAtValue(long duration) { | ||
stop(); | ||
this.duration = duration; | ||
restart(); | ||
} | ||
|
||
public long getTimeRemaining() { | ||
if (!running) { | ||
return this.duration; | ||
} | ||
long elapsedTime = System.currentTimeMillis() - this.startTime; | ||
return this.duration - elapsedTime; | ||
} | ||
|
||
public boolean isRunning() { | ||
return running; | ||
} | ||
|
||
public boolean isIndefinite() { | ||
return duration < 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters