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


AppSearch document representing a Timer entity.

Summary

Nested types

Builder for Timer.

Constants

const Int

The Timer is expired.

const Int

The Timer is missed.

const Int

The Timer is paused.

const Int

The Timer is reset to its initial value.

const Int

The Timer is started.

const Int

The Timer is in an unknown error state.

Public functions

Long
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
calculateBaseTimeMillis(context: Context)

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

Long
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
calculateCurrentRemainingDurationMillis(context: Context)

Calculates the current remaining time in milliseconds.

Long
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
calculateExpirationTimeMillis(context: Context)

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.

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 functions

From androidx.appsearch.builtintypes.Thing
(Mutable)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.

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.

String

Returns the unique identifier for this item.

String?

Returns the URL for an image of this item.

String?

Returns the name of this item.

String

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

(Mutable)List<PotentialAction!>

Returns the actions that can be taken on this object.

String?

Returns the deeplink URL of this item.

Constants

STATUS_EXPIRED

Added in 1.1.0-alpha04
const val STATUS_EXPIRED = 3: Int

The Timer is expired.

STATUS_MISSED

Added in 1.1.0-alpha04
const val STATUS_MISSED = 4: Int

The Timer is missed.

STATUS_PAUSED

Added in 1.1.0-alpha04
const val STATUS_PAUSED = 2: Int

The Timer is paused.

STATUS_RESET

Added in 1.1.0-alpha04
const val STATUS_RESET = 5: Int

The Timer is reset to its initial value.

STATUS_STARTED

Added in 1.1.0-alpha04
const val STATUS_STARTED = 1: Int

The Timer is started.

STATUS_UNKNOWN

Added in 1.1.0-alpha04
const val STATUS_UNKNOWN = 0: Int

The Timer is in an unknown error state.

Public functions

calculateBaseTimeMillis

Added in 1.1.0-alpha04
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
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.

calculateCurrentRemainingDurationMillis

Added in 1.1.0-alpha04
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
fun calculateCurrentRemainingDurationMillis(context: Context): Long

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
context: Context

The app context

calculateExpirationTimeMillis

Added in 1.1.0-alpha04
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
fun calculateExpirationTimeMillis(context: Context): Long

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
context: Context

The app context

getBaseTimeMillis

Added in 1.1.0-alpha04
fun getBaseTimeMillis(): Long

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-alpha04
fun getBaseTimeMillisInElapsedRealtime(): Long

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-alpha04
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.

If available, this value is used to calculate calculateExpirationTimeMillis.

getDurationMillis

Added in 1.1.0-alpha04
fun getDurationMillis(): Long

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-alpha04
fun getOriginalDurationMillis(): Long

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-alpha04
fun getRemainingDurationMillis(): Long

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-alpha04
fun getRingtone(): String?

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-alpha04
fun getStartTimeMillis(): Long

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-alpha04
fun getStatus(): Int

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-alpha04
fun shouldVibrate(): Boolean

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