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 setCriticalMetric(int) to indicate that none of the metrics should be considered the "most important" one.

Public constructors

Public methods
Notification.MetricStyle

Adds a Metric to this MetricStyle.

Boolean
equals(other: Any?)

Notification.Metric?

Returns which, if any, of the metrics is considered the "most important", or null if none are.

MutableList<Notification.Metric!>

Returns an immutable view of the list of Metric instances in this MetricStyle.

Int

Notification.MetricStyle

Indicates which of the metrics is considered the "most important".

Notification.MetricStyle

Sets the list of Metric instances for this MetricStyle, replacing whatever was added before.

String

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: -1

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

equals

fun equals(other: Any?): Boolean

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