NotificationCompat.ProgressStyle


public class NotificationCompat.ProgressStyle extends 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 methods

@NonNull NotificationCompat.ProgressStyle

Adds another point.

@NonNull NotificationCompat.ProgressStyle

Appends a segment to the end of the progress bar.

@IntRange(from = 0) int

Gets the progress value of the progress bar.

@Nullable 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.

@NonNull List<NotificationCompat.ProgressStyle.Point>

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

@NonNull List<NotificationCompat.ProgressStyle.Segment>

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

@Nullable IconCompat

Gets the progress bar start icon.

@Nullable 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.

@NonNull NotificationCompat.ProgressStyle
setProgress(@IntRange(from = 0) int progress)

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

@NonNull NotificationCompat.ProgressStyle

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

@NonNull NotificationCompat.ProgressStyle
setProgressIndeterminate(boolean indeterminate)

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

@NonNull NotificationCompat.ProgressStyle

Replaces all the progress points.

@NonNull NotificationCompat.ProgressStyle

Sets or replaces the segments of the progress bar.

@NonNull NotificationCompat.ProgressStyle

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

@NonNull NotificationCompat.ProgressStyle

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

@NonNull NotificationCompat.ProgressStyle
setStyledByProgress(boolean enabled)

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

Inherited methods

From androidx.core.app.NotificationCompat.Style
@Nullable Notification

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

void

Link this rich notification style with a notification builder.

Public constructors

ProgressStyle

Added in 1.17.0-alpha01
public ProgressStyle()

Public methods

addProgressPoint

public @NonNull NotificationCompat.ProgressStyle addProgressPoint(@NonNull NotificationCompat.ProgressStyle.Point point)

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

public @NonNull NotificationCompat.ProgressStyle addProgressSegment(
    @NonNull NotificationCompat.ProgressStyle.Segment segment
)

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

public @IntRange(from = 0) int getProgress()

Gets the progress value of the progress bar.

See also
setProgress

getProgressEndIcon

public @Nullable IconCompat getProgressEndIcon()

Gets the progress bar end icon.

getProgressMax

public @IntRange(from = 0) int getProgressMax()

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

public @NonNull List<NotificationCompat.ProgressStyle.PointgetProgressPoints()

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

getProgressSegments

public @NonNull List<NotificationCompat.ProgressStyle.SegmentgetProgressSegments()

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

public @Nullable IconCompat getProgressStartIcon()

Gets the progress bar start icon.

getProgressTrackerIcon

public @Nullable IconCompat getProgressTrackerIcon()

Gets the progress tracker icon for the progress bar.

isProgressIndeterminate

public boolean isProgressIndeterminate()

Get indeterminate value of the progress bar.

isStyledByProgress

public boolean isStyledByProgress()

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

setProgress

public @NonNull NotificationCompat.ProgressStyle setProgress(@IntRange(from = 0) int progress)

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

public @NonNull NotificationCompat.ProgressStyle setProgressEndIcon(@Nullable IconCompat endIcon)

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

public @NonNull NotificationCompat.ProgressStyle setProgressIndeterminate(boolean indeterminate)

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

public @NonNull NotificationCompat.ProgressStyle setProgressPoints(
    @NonNull List<NotificationCompat.ProgressStyle.Point> points
)

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

public @NonNull NotificationCompat.ProgressStyle setProgressSegments(
    @NonNull List<NotificationCompat.ProgressStyle.Segment> progressSegments
)

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

public @NonNull NotificationCompat.ProgressStyle setProgressStartIcon(@Nullable IconCompat startIcon)

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

public @NonNull NotificationCompat.ProgressStyle setProgressTrackerIcon(@Nullable IconCompat trackerIcon)

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

public @NonNull NotificationCompat.ProgressStyle setStyledByProgress(boolean enabled)

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.