NotificationCompat.ProgressStyle


class NotificationCompat.ProgressStyle : NotificationCompat.Style


Helper class for generating large-format notifications that display progress to the user with a highly customizable progress bar with segments, points, a custom tracker icon, and custom icons at the start and end of the progress bar. If the platform does not provide large-format notifications, this method has no effect. The user will always see the normal notification view. This class is a "rebuilder": It attaches to a Builder object and modifies its behavior, like so:

new NotificationCompat.Builder(context)
  .setSmallIcon(R.drawable.ic_notification)
  .setColor(Color.GREEN)
  .setColorized(true)
  .setContentTitle("Arrive 10:08 AM").
  .setContentText("Dominique Ansel Bakery Soho")
  .addAction(new NotificationCompat.Action("Exit navigation",...))
  .setStyle(new NotificationCompat.ProgressStyle()
      .setStyledByProgress(false)
      .setProgress(456)
      .setProgressTrackerIcon(IconCompat.createWithResource(R.drawable.ic_driving_tracker))
      .addProgressSegment(new Segment(41).setColor(Color.BLACK))
      .addProgressSegment(new Segment(552).setColor(Color.YELLOW))
      .addProgressSegment(new Segment(253).setColor(Color.YELLOW))
      .addProgressSegment(new Segment(94).setColor(Color.BLUE))
      .addProgressPoint(new Point(60).setColor(Color.RED))
      .addProgressPoint(new Point(560).setColor(Color.YELLOW))
  )

NOTE: ProgressStyle Notifications are supported on Android 36 and above. If the SDK version is below 36, the ProgressStyle will fall back to the default notification style.

Summary

Nested types

A point within the progress bar, defining its position and color.

A segment of the progress bar, which defines its length and color.

Public constructors

Public functions

NotificationCompat.ProgressStyle

Adds another point.

NotificationCompat.ProgressStyle

Appends a segment to the end of the progress bar.

@IntRange(from = 0) Int

Gets the progress value of the progress bar.

IconCompat?

Gets the progress bar end icon.

@IntRange(from = 0) Int

Gets the sum of the lengths of all Segments in the style, which defines the maximum progress.

(Mutable)List<NotificationCompat.ProgressStyle.Point!>

Gets the points that are displayed on the progress bar. .

(Mutable)List<NotificationCompat.ProgressStyle.Segment!>

Gets the segments that define the background layer of the progress bar.

IconCompat?

Gets the progress bar start icon.

IconCompat?

Gets the progress tracker icon for the progress bar.

Boolean

Get indeterminate value of the progress bar.

Boolean

Gets whether the progress bar's style is based on its progress.

NotificationCompat.ProgressStyle
setProgress(progress: @IntRange(from = 0) Int)

Specifies the progress (in the same units as getLength) of the tracker along the length of the bar.

NotificationCompat.ProgressStyle

An optional square icon that appears at the end of the progress bar.

NotificationCompat.ProgressStyle

Used to indicate an initialization state without a known progress amount.

NotificationCompat.ProgressStyle

Replaces all the progress points.

NotificationCompat.ProgressStyle

Sets or replaces the segments of the progress bar.

NotificationCompat.ProgressStyle

An optional square icon that appears at the start of the progress bar.

NotificationCompat.ProgressStyle

An optional icon that can appear as an overlay on the bar at the point of current progress.

NotificationCompat.ProgressStyle

Indicates whether the segments and points will be styled differently based on whether they are behind or ahead of the current progress.

Inherited functions

From androidx.core.app.NotificationCompat.Style
Notification?

If this Style object has been set on a notification builder, this method will build that notification and return it.

Unit

Link this rich notification style with a notification builder.

Public constructors

ProgressStyle

Added in 1.17.0-alpha01
ProgressStyle()

Public functions

addProgressPoint

fun addProgressPoint(point: NotificationCompat.ProgressStyle.Point): NotificationCompat.ProgressStyle

Adds another point. Points within a progress bar are used to visualize distinct stages or milestones. For example, you might use points to mark stops in a multi-stop navigation journey, where each point represents a destination. Points can be added in any order, as their position within the progress bar is determined by their individual getPosition.

addProgressSegment

fun addProgressSegment(segment: NotificationCompat.ProgressStyle.Segment): NotificationCompat.ProgressStyle

Appends a segment to the end of the progress bar. Segments allow for creating progress bars with multiple colors or sections to represent different stages or categories of progress. For example, Traffic conditions along a navigation journey.

getProgress

fun getProgress(): @IntRange(from = 0) Int

Gets the progress value of the progress bar.

See also
setProgress

getProgressEndIcon

fun getProgressEndIcon(): IconCompat?

Gets the progress bar end icon.

getProgressMax

fun getProgressMax(): @IntRange(from = 0) Int

Gets the sum of the lengths of all Segments in the style, which defines the maximum progress. Defaults to 100 when segments are omitted.

getProgressPoints

fun getProgressPoints(): (Mutable)List<NotificationCompat.ProgressStyle.Point!>

Gets the points that are displayed on the progress bar. .

getProgressSegments

fun getProgressSegments(): (Mutable)List<NotificationCompat.ProgressStyle.Segment!>

Gets the segments that define the background layer of the progress bar. If no segments are provided, the progress bar will be rendered with a single segment with length 100 and default color.

getProgressStartIcon

fun getProgressStartIcon(): IconCompat?

Gets the progress bar start icon.

getProgressTrackerIcon

fun getProgressTrackerIcon(): IconCompat?

Gets the progress tracker icon for the progress bar.

isProgressIndeterminate

fun isProgressIndeterminate(): Boolean

Get indeterminate value of the progress bar.

isStyledByProgress

fun isStyledByProgress(): Boolean

Gets whether the progress bar's style is based on its progress.

setProgress

fun setProgress(progress: @IntRange(from = 0) Int): NotificationCompat.ProgressStyle

Specifies the progress (in the same units as getLength) of the tracker along the length of the bar. The max progress value is the sum of all Segment lengths. The default value is 0.

setProgressEndIcon

fun setProgressEndIcon(endIcon: IconCompat?): NotificationCompat.ProgressStyle

An optional square icon that appears at the end of the progress bar. This icon will be cropped to its central square. This icon will NOT be mirrored in RTL layouts.

setProgressIndeterminate

fun setProgressIndeterminate(indeterminate: Boolean): NotificationCompat.ProgressStyle

Used to indicate an initialization state without a known progress amount. When specified, the following fields are ignored:

See also
setProgress
setProgressSegments
setProgressPoints
setProgressTrackerIcon
setStyledByProgress

If the app provides exactly one Segment, that segment's color will be used to style the indeterminate bar.

setProgressPoints

fun setProgressPoints(
    points: (Mutable)List<NotificationCompat.ProgressStyle.Point!>
): NotificationCompat.ProgressStyle

Replaces all the progress points. Points within a progress bar are used to visualize distinct stages or milestones. For example, you might use points to mark stops in a multi-stop navigation journey, where each point represents a destination.

setProgressSegments

fun setProgressSegments(
    progressSegments: (Mutable)List<NotificationCompat.ProgressStyle.Segment!>
): NotificationCompat.ProgressStyle

Sets or replaces the segments of the progress bar. Segments allow for creating progress bars with multiple colors or sections to represent different stages or categories of progress. For example, Traffic conditions along a navigation journey.

setProgressStartIcon

fun setProgressStartIcon(startIcon: IconCompat?): NotificationCompat.ProgressStyle

An optional square icon that appears at the start of the progress bar. This icon will be cropped to its central square. This icon will NOT be mirrored in RTL layouts.

setProgressTrackerIcon

fun setProgressTrackerIcon(trackerIcon: IconCompat?): NotificationCompat.ProgressStyle

An optional icon that can appear as an overlay on the bar at the point of current progress. Aspect ratio may be anywhere from 2:1 to 1:2; content outside that aspect ratio range will be cropped. This icon will be mirrored in RTL.

setStyledByProgress

fun setStyledByProgress(enabled: Boolean): NotificationCompat.ProgressStyle

Indicates whether the segments and points will be styled differently based on whether they are behind or ahead of the current progress. When true, segments appearing ahead of the current progress will be given a slightly different appearance to indicate that it is part of the progress bar that is not "filled". When false, all segments will be given the filled appearance, and it will be the app's responsibility to use #setProgressTrackerIcon or segment colors to make the current progress clear to the user. the default value is true.