@Document(name = "builtin:Stopwatch")
public class Stopwatch extends 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

public final class Stopwatch.Builder

Builder for Stopwatch.

Constants

static final int

The Stopwatch is paused.

static final int

The Stopwatch is reset.

static final int

The Stopwatch is running.

static final int

The Stopwatch status is unknown

Public methods

long

Calculates the base time in milliseconds using the currentTimeMillis time base.

long

Calculates the current accumulated time in milliseconds.

long

Returns the total duration in milliseconds accumulated by the Stopwatch.

long

Returns the point in time that the Stopwatch counts up from.

long

Returns the point in time that the Stopwatch counts up from.

int

Returns the boot count of the device when this document is last updated.

@NonNull List<StopwatchLap>

Returns all the StopwatchLap instances.

int

Returns the current status.

Inherited methods

From androidx.appsearch.builtintypes.Thing
@NonNull List<String>

Returns an unmodifiable list of aliases, if any, for this item.

long

Returns the creation timestamp, in milliseconds since Unix epoch, of this item.

@Nullable String

Returns a description of this item.

int

Returns the intrinsic score (or importance) of this item.

long

Returns the time-to-live timestamp, in milliseconds since getCreationTimestampMillis, for this item.

@NonNull String

Returns the unique identifier for this item.

@Nullable String

Returns the URL for an image of this item.

@Nullable String

Returns the name of this item.

@NonNull String

Returns the namespace (or logical grouping) for this item.

@NonNull List<PotentialAction>

Returns the actions that can be taken on this object.

@Nullable String

Returns the deeplink URL of this item.

Constants

STATUS_PAUSED

Added in 1.1.0-alpha06
public static final int STATUS_PAUSED = 3

The Stopwatch is paused.

STATUS_RESET

Added in 1.1.0-alpha06
public static final int STATUS_RESET = 1

The Stopwatch is reset.

STATUS_RUNNING

Added in 1.1.0-alpha06
public static final int STATUS_RUNNING = 2

The Stopwatch is running.

STATUS_UNKNOWN

Added in 1.1.0-alpha06
public static final int STATUS_UNKNOWN = 0

The Stopwatch status is unknown

Public methods

calculateBaseTimeMillis

Added in 1.1.0-alpha06
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

Added in 1.1.0-alpha06
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

Added in 1.1.0-alpha06
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

Added in 1.1.0-alpha06
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

Added in 1.1.0-alpha06
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

Added in 1.1.0-alpha06
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

Added in 1.1.0-alpha06
public @NonNull List<StopwatchLapgetLaps()

Returns all the StopwatchLap instances.

getStatus

Added in 1.1.0-alpha06
public int getStatus()

Returns the current status.

Status can be STATUS_UNKNOWN, STATUS_RESET, STATUS_RUNNING, or STATUS_PAUSED.