Stopwatch
@Document(name = "builtin:Stopwatch")
public class Stopwatch extends Thing
| java.lang.Object | ||
| ↳ | androidx.appsearch.builtintypes.Thing | |
| ↳ | androidx.appsearch.builtintypes.Stopwatch |
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 |
|---|
public final class Stopwatch.BuilderBuilder for |
Constants |
|
|---|---|
static final int |
STATUS_PAUSED = 3The |
static final int |
STATUS_RESET = 1The |
static final int |
STATUS_RUNNING = 2The |
static final int |
STATUS_UNKNOWN = 0The |
Public methods |
|
|---|---|
long |
calculateBaseTimeMillis(@NonNull 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. |
@NonNull List<StopwatchLap> |
getLaps()Returns all the |
int |
Returns the current status. |
Inherited methods |
||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Constants
STATUS_UNKNOWN
public static final int STATUS_UNKNOWN = 0
The Stopwatch status is unknown
Public methods
calculateBaseTimeMillis
public long calculateBaseTimeMillis(@NonNull Context context)
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
public long calculateCurrentAccumulatedDurationMillis(@NonNull Context context)
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
public long getAccumulatedDurationMillis()
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
public long getBaseTimeMillis()
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
public long getBaseTimeMillisInElapsedRealtime()
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
public int getBootCount()
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
public @NonNull List<StopwatchLap> getLaps()
Returns all the StopwatchLap instances.
getStatus
public int getStatus()
Returns the current status.
Status can be STATUS_UNKNOWN, STATUS_RESET, STATUS_RUNNING, or STATUS_PAUSED.