Stopwatch
@Document(name = "builtin:Stopwatch")
class Stopwatch : Thing
An AppSearch document representing a Stopwatch entity.
A stopwatch is used to count time up, starting from 0, and can be paused and resumed at will.
Summary
Nested types |
|---|
class Stopwatch.BuilderBuilder for |
Constants |
|
|---|---|
const Int |
STATUS_PAUSED = 3The |
const Int |
STATUS_RESET = 1The |
const Int |
STATUS_RUNNING = 2The |
const Int |
STATUS_UNKNOWN = 0The |
Public functions |
|
|---|---|
Long |
calculateBaseTimeMillis(context: Context)Calculates the base time in milliseconds using the |
Long |
Calculates the current accumulated time in milliseconds. |
Long |
Returns the total duration in milliseconds accumulated by the |
Long |
Returns the point in time that the |
Long |
Returns the point in time that the |
Int |
Returns the boot count of the device when this document is last updated. |
(Mutable)List<StopwatchLap!> |
getLaps()Returns all the |
Int |
Returns the current status. |
Inherited functions |
||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Constants
Public functions
calculateBaseTimeMillis
fun calculateBaseTimeMillis(context: Context): Long
Calculates the base time in milliseconds using the currentTimeMillis time base.
If the boot count retrieved from the context matches getBootCount, then getBaseTimeMillisInElapsedRealtime will be used to calculate the base time in the currentTimeMillis time base. Otherwise return getBaseTimeMillis.
calculateCurrentAccumulatedDurationMillis
fun calculateCurrentAccumulatedDurationMillis(context: Context): Long
Calculates the current accumulated time in milliseconds.
Use this method to calculate the accumulated time in real time. Use getAccumulatedDurationMillis to get the static accumulated time stored in the document.
getAccumulatedDurationMillis
fun getAccumulatedDurationMillis(): Long
Returns the total duration in milliseconds accumulated by the Stopwatch.
Use this method to get the static accumulated time stored in the document. Use calculateCurrentAccumulatedDurationMillis to calculate the accumulated time in real time.
getBaseTimeMillis
fun getBaseTimeMillis(): Long
Returns the point in time that the Stopwatch counts up from. In milliseconds using the currentTimeMillis time base.
Use calculateBaseTimeMillis to get a more accurate base time that accounts for the current boot count of the device.
getBaseTimeMillisInElapsedRealtime
fun getBaseTimeMillisInElapsedRealtime(): Long
Returns the point in time that the Stopwatch counts up from. In milliseconds using the elapsedRealtime time base.
ElapsedRealtime should only be used if the getBootCount matches the bootCount of the current device.
getBootCount
fun getBootCount(): Int
Returns the boot count of the device when this document is last updated.
The boot count of the device can be accessed from Global Settings. See BOOT_COUNT.
On older APIs where boot count is not available, this value should not be used.
getLaps
fun getLaps(): (Mutable)List<StopwatchLap!>
Returns all the StopwatchLap instances.
getStatus
fun getStatus(): Int
Returns the current status.
Status can be STATUS_UNKNOWN, STATUS_RESET, STATUS_RUNNING, or STATUS_PAUSED.