Notification.Metric.TimeDifference
public
static
final
class
Notification.Metric.TimeDifference
extends Notification.Metric.MetricValue
| java.lang.Object | ||
| ↳ | android.app.Notification.Metric.MetricValue | |
| ↳ | android.app.Notification.Metric.TimeDifference | |
This represents a timer, a stopwatch, or a countdown to an event.
When representing a running timer (or stopwatch, etc), this value specifies a reference instant for when that timer will hit zero (or the stopwatch was at zero, respectively), called the "zero time". In this case the time displayed is defined as the difference between the "zero time" and the current time, meaning it will show a live-updated timer.
The zero time can be specified as an Instant (in which case it corresponds
to a "real-world" point in time, from InstantSource.system), or as milliseconds
since boot (from SystemClock.elapsedRealtime()). The latter might be suitable
when the timer is tied to an AlarmManager.ELAPSED_REALTIME alarm in
AlarmManager.
When representing a paused timer (or stopwatch, etc), this value specifies the duration as a fixed value.
This value can also specify its formatting, whether as a "chronometer" (e.g. 43:21) or an adaptive time (e.g. 1h 43m).
Summary
Constants | |
|---|---|
int |
FORMAT_ADAPTIVE
Formatting option: adaptive (e.g. 1h 5m; 15m; 1m 30s; 5s). |
int |
FORMAT_CHRONOMETER
Formatting option: chronometer-style, (e.g. two hours = "2:00:00"). |
Public methods | |
|---|---|
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one. |
static
Notification.Metric.TimeDifference
|
forPausedStopwatch(Duration elapsedTime, int format)
Creates a "paused stopwatch" metric, showing the |
static
Notification.Metric.TimeDifference
|
forPausedTimer(Duration remainingTime, int format)
Creates a "paused timer" metric, showing the |
static
Notification.Metric.TimeDifference
|
forStopwatch(long startTime, int format)
Creates a "running stopwatch" metric, which will show the time elapsed since
|
static
Notification.Metric.TimeDifference
|
forStopwatch(Instant startTime, int format)
Creates a "running stopwatch" metric, which will show the time elapsed since
|
static
Notification.Metric.TimeDifference
|
forTimer(long endTime, int format)
Creates a "running timer" metric, which will show a countdown to |
static
Notification.Metric.TimeDifference
|
forTimer(Instant endTime, int format)
Creates a "running timer" metric, which will show a countdown to |
int
|
getFormat()
Formatting option for the timer/stopwatch. |
Duration
|
getPausedDuration()
The fixed time difference, for a paused timer or stopwatch. |
Long
|
getZeroElapsedRealtime()
The elapsed realtime at which the time difference is zero. |
Instant
|
getZeroTime()
The |
int
|
hashCode()
Returns a hash code value for the object. |
boolean
|
isStopwatch()
Whether this |
boolean
|
isTimer()
Whether this |
String
|
toString()
Returns a string representation of the object. |
Inherited methods | |
|---|---|
Constants
FORMAT_ADAPTIVE
public static final int FORMAT_ADAPTIVE
Formatting option: adaptive (e.g. 1h 5m; 15m; 1m 30s; 5s).
Constant Value: 1 (0x00000001)
FORMAT_CHRONOMETER
public static final int FORMAT_CHRONOMETER
Formatting option: chronometer-style, (e.g. two hours = "2:00:00").
Constant Value: 2 (0x00000002)
Public methods
equals
public boolean equals (Object obj)
Indicates whether some other object is "equal to" this one.
The equals method implements an equivalence relation
on non-null object references:
- It is reflexive: for any non-null reference value
x,x.equals(x)should returntrue. - It is symmetric: for any non-null reference values
xandy,x.equals(y)should returntrueif and only ify.equals(x)returnstrue. - It is transitive: for any non-null reference values
x,y, andz, ifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue. - It is consistent: for any non-null reference values
xandy, multiple invocations ofx.equals(y)consistently returntrueor consistently returnfalse, provided no information used inequalscomparisons on the objects is modified. - For any non-null reference value
x,x.equals(null)should returnfalse.
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
| Parameters | |
|---|---|
obj |
Object: the reference object with which to compare. |
| Returns | |
|---|---|
boolean |
true if this object is the same as the obj
argument; false otherwise. |
forPausedStopwatch
public static Notification.Metric.TimeDifference forPausedStopwatch (Duration elapsedTime, int format)
Creates a "paused stopwatch" metric, showing the elapsedTime.
| Parameters | |
|---|---|
elapsedTime |
Duration: This value cannot be null. |
format |
int: Value is one of the following:
|
| Returns | |
|---|---|
Notification.Metric.TimeDifference |
This value cannot be null. |
forPausedTimer
public static Notification.Metric.TimeDifference forPausedTimer (Duration remainingTime, int format)
Creates a "paused timer" metric, showing the remainingTime.
| Parameters | |
|---|---|
remainingTime |
Duration: This value cannot be null. |
format |
int: Value is one of the following:
|
| Returns | |
|---|---|
Notification.Metric.TimeDifference |
This value cannot be null. |
forStopwatch
public static Notification.Metric.TimeDifference forStopwatch (long startTime, int format)
Creates a "running stopwatch" metric, which will show the time elapsed since
startTime, specified in the SystemClock.elapsedRealtime() frame of
reference.
| Parameters | |
|---|---|
startTime |
long: elapsed realtime at which the stopwatch started.
Value is a non-negative timestamp in the SystemClock.elapsedRealtime() time base. |
format |
int: Value is one of the following:
|
| Returns | |
|---|---|
Notification.Metric.TimeDifference |
This value cannot be null. |
forStopwatch
public static Notification.Metric.TimeDifference forStopwatch (Instant startTime, int format)
Creates a "running stopwatch" metric, which will show the time elapsed since
startTime.
| Parameters | |
|---|---|
startTime |
Instant: instant at which the stopwatch started.
This value cannot be null. |
format |
int: Value is one of the following:
|
| Returns | |
|---|---|
Notification.Metric.TimeDifference |
This value cannot be null. |
forTimer
public static Notification.Metric.TimeDifference forTimer (long endTime, int format)
Creates a "running timer" metric, which will show a countdown to endTime,
specified in the SystemClock.elapsedRealtime() frame of reference.
| Parameters | |
|---|---|
endTime |
long: elapsed realtime at which the timer reaches zero.
Value is a non-negative timestamp in the SystemClock.elapsedRealtime() time base. |
format |
int: Value is one of the following:
|
| Returns | |
|---|---|
Notification.Metric.TimeDifference |
This value cannot be null. |
forTimer
public static Notification.Metric.TimeDifference forTimer (Instant endTime, int format)
Creates a "running timer" metric, which will show a countdown to endTime.
| Parameters | |
|---|---|
endTime |
Instant: instant at which the timer reaches zero.
This value cannot be null. |
format |
int: Value is one of the following:
|
| Returns | |
|---|---|
Notification.Metric.TimeDifference |
This value cannot be null. |
getFormat
public int getFormat ()
Formatting option for the timer/stopwatch.
| Returns | |
|---|---|
int |
Value is one of the following: |
getPausedDuration
public Duration getPausedDuration ()
The fixed time difference, for a paused timer or stopwatch.
- For a paused timer this is the
remainingTimesupplied toforPausedTimer(Duration, int). - For a paused stopwatch this is the
elapsedTimesupplied toforPausedStopwatch(Duration, int). - For running timers or stopwatches this is
null.
| Returns | |
|---|---|
Duration |
|
getZeroElapsedRealtime
public Long getZeroElapsedRealtime ()
The elapsed realtime at which the time difference is zero. Only valid for an
SystemClock.elapsedRealtime()-based TimeDifference.
- For a running timer this is the
endTimesupplied toforTimer(long, int). - For a running stopwatch this is the
startTimesupplied toforStopwatch(long, int). - For running timers or stopwatches based on
Instant(as well as paused timers and stopwatches), this isnull.
Value is a non-negative timestamp in the
SystemClock.elapsedRealtime() time base.
| Returns | |
|---|---|
Long |
Value is a non-negative timestamp in the
SystemClock.elapsedRealtime() time base. |
getZeroTime
public Instant getZeroTime ()
The Instant at which the time difference is zero. Only valid for an
Instant-based TimeDifference.
- For a running timer this is the
endTimesupplied toforTimer(Instant,int). - For a running stopwatch this is the
startTimesupplied toforStopwatch(Instant,int). - For running timers or stopwatches based on elapsed realtime (as well as
paused timers and stopwatches), this is
null.
| Returns | |
|---|---|
Instant |
|
hashCode
public int hashCode ()
Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
HashMap.
The general contract of hashCode is:
- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
hashCodemethod must consistently return the same integer, provided no information used inequalscomparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equalsmethod, then calling thehashCodemethod on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal
according to the
equalsmethod, then calling thehashCodemethod on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
| Returns | |
|---|---|
int |
a hash code value for this object. |
isStopwatch
public boolean isStopwatch ()
Whether this TimeDifference value represents a stopwatch -- when running,
it counts up from getZeroTime() (or getZeroElapsedRealtime()).
| Returns | |
|---|---|
boolean |
|
isTimer
public boolean isTimer ()
Whether this TimeDifference value represents a timer -- when running,
it counts down to getZeroTime() (or getZeroElapsedRealtime()).
| Returns | |
|---|---|
boolean |
|