Timer
@Document(name = "builtin:Timer")
class Timer : Thing
AppSearch document representing a Timer entity.
Summary
Nested types |
|---|
class Timer.BuilderBuilder for |
Constants |
|
|---|---|
const Int |
STATUS_EXPIRED = 3The |
const Int |
STATUS_MISSED = 4The |
const Int |
STATUS_PAUSED = 2The |
const Int |
STATUS_RESET = 5The |
const Int |
STATUS_STARTED = 1The |
const Int |
STATUS_UNKNOWN = 0The |
Public functions |
|
|---|---|
Long |
calculateBaseTimeMillis(context: Context)Calculates the base time in milliseconds using the |
Long |
Calculates the current remaining time in milliseconds. |
Long |
calculateExpirationTimeMillis(context: Context)Calculates the expire time in milliseconds in 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. |
Long |
Returns the total duration in milliseconds, including additional time added by the user. |
Long |
Returns the original duration in milliseconds when the |
Long |
Returns the amount of time remaining in milliseconds for the |
String? |
Returns the ringtone as a content URI to be played, or |
Long |
Returns the start time in milliseconds using the |
Int |
Returns the current status. |
Boolean |
Returns whether or not to activate the device vibrator when the |
Inherited functions |
||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Constants
STATUS_RESET
const val STATUS_RESET = 5: Int
The Timer is reset to its initial value.
STATUS_UNKNOWN
const val STATUS_UNKNOWN = 0: Int
The Timer is in an unknown error state.
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.
calculateCurrentRemainingDurationMillis
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
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
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
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
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
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
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
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
fun getRingtone(): String?
Returns the ringtone as a content URI to be played, or VALUE_RINGTONE_SILENT if no ringtone will be played.
getStartTimeMillis
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
fun getStatus(): Int
Returns the current status.
Status can be STATUS_UNKNOWN, STATUS_STARTED, STATUS_PAUSED, STATUS_EXPIRED, STATUS_MISSED, or STATUS_RESET.
shouldVibrate
fun shouldVibrate(): Boolean
Returns whether or not to activate the device vibrator when the Timer expires.