@Document(name = "builtin:Timer")
public class Timer extends Thing


AppSearch document representing a Timer entity.

Summary

Nested types

public final class Timer.Builder

Builder for Timer.

Constants

static final int

The Timer is expired.

static final int

The Timer is missed.

static final int

The Timer is paused.

static final int

The Timer is reset to its initial value.

static final int

The Timer is started.

static final int

The Timer is in an unknown error state.

Public methods

long

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

long

Calculates the current remaining time in milliseconds.

long

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

long

Returns the point in time that the Timer counts down from, relative to its getRemainingDurationMillis.

long

Returns the point in time that the Timer counts down from, relative to its getRemainingDurationMillis.

int

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

long

Returns the total duration in milliseconds, including additional time added by the user.

long

Returns the original duration in milliseconds when the Timer was first created.

long

Returns the amount of time remaining in milliseconds for the Timer relative to its getBaseTimeMillis.

@Nullable String

Returns the ringtone as a content URI to be played, or VALUE_RINGTONE_SILENT if no ringtone will be played.

long

Returns the start time in milliseconds using the currentTimeMillis time base.

int

Returns the current status.

boolean

Returns whether or not to activate the device vibrator when the Timer expires.

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_EXPIRED

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

The Timer is expired.

STATUS_MISSED

Added in 1.1.0-alpha06
public static final int STATUS_MISSED = 4

The Timer is missed.

STATUS_PAUSED

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

The Timer is paused.

STATUS_RESET

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

The Timer is reset to its initial value.

STATUS_STARTED

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

The Timer is started.

STATUS_UNKNOWN

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

The Timer is in an unknown error state.

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.

calculateCurrentRemainingDurationMillis

Added in 1.1.0-alpha06
public long calculateCurrentRemainingDurationMillis(@NonNull Context context)

Calculates the current remaining time in milliseconds.

A negative value may be returned if the Timer is STATUS_MISSED or STATUS_EXPIRED to indicate it has already fired.

Use this method to calculate the remaining time at runtime. Use getRemainingDurationMillis to get the static remaining time stored in the document.

Parameters
@NonNull Context context

The app context

calculateExpirationTimeMillis

Added in 1.1.0-alpha06
public long calculateExpirationTimeMillis(@NonNull Context context)

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

MAX_VALUE will be returned if the Timer is STATUS_PAUSED or STATUS_RESET.

A negative value may be returned if the Timer is STATUS_MISSED or STATUS_EXPIRED to indicate it expired in the past.

Parameters
@NonNull Context context

The app context

getBaseTimeMillis

Added in 1.1.0-alpha06
public long getBaseTimeMillis()

Returns the point in time that the Timer counts down from, relative to its getRemainingDurationMillis. In milliseconds using the currentTimeMillis time base.

The expire time of the Timer can be calculated using the sum of its base time and remaining time.

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 Timer counts down from, relative to its getRemainingDurationMillis. In milliseconds using the elapsedRealtime time base.

ElapsedRealtime should only be used if the getBootCount matches the bootCount of the current device. It is used to calculate

The expire time of the Timer can be calculated using the sum of its base time and remaining time.

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.

If available, this value is used to calculate calculateExpirationTimeMillis.

getDurationMillis

Added in 1.1.0-alpha06
public long getDurationMillis()

Returns the total duration in milliseconds, including additional time added by the user.

Applications may allow the user to add additional durations. The durationMillis will always return the new updated duration.

getOriginalDurationMillis

Added in 1.1.0-alpha06
public long getOriginalDurationMillis()

Returns the original duration in milliseconds when the Timer was first created.

Applications may allow the user to add additional durations. The originalDurationMillis will always return the original duration before any change has taken place.

getRemainingDurationMillis

Added in 1.1.0-alpha06
public long getRemainingDurationMillis()

Returns the amount of time remaining in milliseconds for the Timer relative to its getBaseTimeMillis.

The expire time of the Timer can be calculated using the sum of its base time and remaining time.

Use this method to get the static remaining time stored in the document. Use calculateCurrentRemainingDurationMillis to calculate the remaining time at runtime.

getRingtone

Added in 1.1.0-alpha06
public @Nullable String getRingtone()

Returns the ringtone as a content URI to be played, or VALUE_RINGTONE_SILENT if no ringtone will be played.

getStartTimeMillis

Added in 1.1.0-alpha06
public long getStartTimeMillis()

Returns the start time in milliseconds using the currentTimeMillis time base.

The start time is the first time that a new Timer, or a Timer that has been reset is started. Pausing and resuming should not change its start time.

getStatus

Added in 1.1.0-alpha06
public int getStatus()

Returns the current status.

Status can be STATUS_UNKNOWN, STATUS_STARTED, STATUS_PAUSED, STATUS_EXPIRED, STATUS_MISSED, or STATUS_RESET.

shouldVibrate

Added in 1.1.0-alpha06
public boolean shouldVibrate()

Returns whether or not to activate the device vibrator when the Timer expires.