public class Stopwatch extends Object
Created by Yashovardhan99 on 8/12/18 as a part of TimeIt.
Runnable| Modifier and Type | Class and Description |
|---|---|
static interface |
Stopwatch.OnTickListener
Interface to listen for stopwatch tick events every time clock is updated.
|
| Constructor and Description |
|---|
Stopwatch()
The default constructor should be called to create an object to call functions accordingly.
|
| Modifier and Type | Method and Description |
|---|---|
long |
getClockDelay()
Returns the currently set clock delay
|
long |
getElapsedTime()
Gets the current elapsed time the stopwatch has been running for in milliseconds
|
LinkedList<Split> |
getSplits()
Get a list of all splits that have been created.
|
long |
getStart()
Returns the clock time (in milliseconds) when the stopwatch was started
|
boolean |
isPaused()
Returns true if the stopwatch is paused
|
boolean |
isStarted()
Returns true if the stopwatch has started
|
void |
pause()
Pauses the stopwatch.
|
void |
resume()
Used to resume the stopwatch from the current time after being paused.
|
void |
setClockDelay(long clockDelay)
Set a custom clock delay to increase/decrease update frequency.
|
void |
setDebugMode(boolean debugMode)
Set whether to print debug logs or not.
|
void |
setOnTickListener(Stopwatch.OnTickListener onTickListener)
Set an OnTickListener to listen for clock changes.
|
void |
setTextView(TextView textView)
Allows you to set a textView where the stopwatch time is displayed.
|
void |
split()
Creates a new split/lap at the current time.
|
void |
start()
Starts the stopwatch at the current time.
|
void |
stop()
Stops the stopwatch.
|
public Stopwatch()
public boolean isStarted()
public boolean isPaused()
public long getElapsedTime()
public long getStart()
public LinkedList<Split> getSplits()
Splitpublic long getClockDelay()
public void setClockDelay(long clockDelay)
clockDelay - clock delay in milliseconds (default : 100ms)Thread.sleep(long)public void setDebugMode(boolean debugMode)
debugMode - desired debugging statuspublic void setTextView(@Nullable
TextView textView)
textView - the textView where you want to display the stopwatch time. Can be null.public void setOnTickListener(Stopwatch.OnTickListener onTickListener)
onTickListener - a reference to the interface implementation.public void start()
IllegalStateException - if the stopwatch has already been started.stop(),
isStarted()public void stop()
IllegalStateException - if stopwatch has not been started yet.start(),
isStarted()public void pause()
IllegalStateException - if stopwatch is already paused or not started yet.resume(),
isPaused()public void resume()
IllegalStateException - if stopwatch is not paused or not started yet.pause(),
isPaused()public void split()
IllegalStateException - if stopwatch is not started yetgetSplits()