MetricStyle
class MetricStyle : Notification.Style
| kotlin.Any | ||
| ↳ | android.app.Notification.Style | |
| ↳ | android.app.Notification.MetricStyle | |
A notification style which shows up to 3 metrics when expanded. Metrics usually represent quantities that change over time, such as fitness information collected by a tracker, timers, weather information, etc.
To use this style with your Notification, feed it to Notification.Builder.setStyle(android.app.Notification.Style) like so:
Notification notif = new Notification.Builder(context) .setStyle(new MetricStyle() .addMetric(new Metric(new Metric.FixedInt(1979), "Steps")) .addMetric(new Metric( Metric.TimeDifference.forStopwatch(startTime, FORMAT_CHRONOMETER_AUTOMATIC), "Time elapsed")))
A MetricStyle must contain at least one Metric object to be valid; an invalid style will be rejected when Builder.build() is called.
If a notification with this style is promoted ongoing, then one of its metrics might be displayed in the status bar chip.
Note that this style doesn't display the large icon set via Builder.setLargeIcon(Icon).
Summary
| Constants | |
|---|---|
| static Int |
Special value for |
| Public constructors | |
|---|---|
| Public methods | |
|---|---|
| Notification.MetricStyle |
addMetric(metric: Notification.Metric)Adds a |
| Boolean | |
| Notification.Metric? |
Returns which, if any, of the metrics is considered the "most important", or |
| MutableList<Notification.Metric!> |
Returns an immutable view of the list of |
| Int |
hashCode() |
| Notification.MetricStyle |
setCriticalMetric(index: Int)Indicates which of the metrics is considered the "most important". |
| Notification.MetricStyle |
setMetrics(metrics: MutableList<Notification.Metric!>)Sets the list of |
| String |
toString() |
| Inherited functions | |
|---|---|
| Inherited properties | |
|---|---|
Constants
METRIC_INDEX_NONE
static val METRIC_INDEX_NONE: Int
Special value for setCriticalMetric(int) to indicate that none of the metrics should be considered the "most important" one.
Value: -1Public constructors
MetricStyle
MetricStyle()
Public methods
addMetric
fun addMetric(metric: Notification.Metric): Notification.MetricStyle
Adds a Metric to this MetricStyle.
| Parameters | |
|---|---|
metric |
Notification.Metric: This value cannot be null. |
| Return | |
|---|---|
Notification.MetricStyle |
This value cannot be null. |
getCriticalMetric
fun getCriticalMetric(): Notification.Metric?
Returns which, if any, of the metrics is considered the "most important", or null if none are. This may be used when the notification is displayed in other surfaces (such as a status bar chip).
By default, unless setCriticalMetric(int) has been set, the first metric in the list is considered the critical one.
getMetrics
fun getMetrics(): MutableList<Notification.Metric!>
Returns an immutable view of the list of Metric instances in this MetricStyle.
| Return | |
|---|---|
MutableList<Notification.Metric!> |
This value cannot be null. |
hashCode
fun hashCode(): Int
setCriticalMetric
fun setCriticalMetric(index: Int): Notification.MetricStyle
Indicates which of the metrics is considered the "most important". This may be used when the notification is displayed in other surfaces (such as a status bar chip).
| Parameters | |
|---|---|
index |
Int: either the index (0-based) of an item in getMetrics(), or METRIC_INDEX_NONE to indicate no Metric should be used for this purpose |
| Return | |
|---|---|
Notification.MetricStyle |
This value cannot be null. |
setMetrics
fun setMetrics(metrics: MutableList<Notification.Metric!>): Notification.MetricStyle
Sets the list of Metric instances for this MetricStyle, replacing whatever was added before.
| Parameters | |
|---|---|
metrics |
MutableList<Notification.Metric!>: This value cannot be null. |
| Return | |
|---|---|
Notification.MetricStyle |
This value cannot be null. |
toString
fun toString(): String