Notification.ProgressStyle


public static class Notification.ProgressStyle
extends Notification.Style

java.lang.Object
   ↳ android.app.Notification.Style
     ↳ android.app.Notification.ProgressStyle


A Notification Style used to define a notification whose expanded state includes a highly customizable progress bar with segments, points, a custom tracker icon, and custom icons at the start and end of the progress bar. This style is suggested for use cases where the app is showing a tracker to the user of a thing they are interested in: the location of a car on its way to pick them up, food being delivered, or their own progress in a navigation journey. To use this style with your Notification, feed it to Notification.Builder.setStyle(android.app.Notification.Style) like so:

 new Notification.Builder(context)
   .setSmallIcon(R.drawable.ic_notification)
   .setColor(Color.GREEN)
   .setColorized(true)
   .setContentTitle("Arrive 10:08 AM").
   .setContentText("Dominique Ansel Bakery Soho")
   .addAction(new Notification.Action("Exit navigation",...))
   .setStyle(new Notification.ProgressStyle()
       .setStyledByProgress(false)
       .setProgress(456)
       .setProgressTrackerIcon(Icon.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: The progress bar layout will be mirrored for RTL layout. NOTE: The extras set by Notification.Builder.setProgress will be overridden by the values set on this style object when the notification is built.

Summary

Nested classes

class Notification.ProgressStyle.Point

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

class Notification.ProgressStyle.Segment

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

Inherited fields

Public constructors

ProgressStyle()

Public methods

Notification.ProgressStyle addProgressPoint(Notification.ProgressStyle.Point point)

Adds another point.

Notification.ProgressStyle addProgressSegment(Notification.ProgressStyle.Segment segment)

Appends a segment to the end of the progress bar.

int getProgress()

Gets the progress value of the progress bar.

Icon getProgressEndIcon()

Gets the progress bar end icon.

int getProgressMax()

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

List<Notification.ProgressStyle.Point> getProgressPoints()

Gets the points that are displayed on the progress bar.

List<Notification.ProgressStyle.Segment> getProgressSegments()

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

Icon getProgressStartIcon()

Gets the progress bar start icon.

Icon getProgressTrackerIcon()

Gets the progress tracker icon for the progress bar.

boolean isProgressIndeterminate()

Get indeterminate value of the progress bar.

boolean isStyledByProgress()

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

Notification.ProgressStyle setProgress(int progress)

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

Notification.ProgressStyle setProgressEndIcon(Icon endIcon)

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

Notification.ProgressStyle setProgressIndeterminate(boolean indeterminate)

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

Notification.ProgressStyle setProgressPoints(List<Notification.ProgressStyle.Point> points)

Replaces all the progress points.

Notification.ProgressStyle setProgressSegments(List<Notification.ProgressStyle.Segment> progressSegments)

Sets or replaces the segments of the progress bar.

Notification.ProgressStyle setProgressStartIcon(Icon startIcon)

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

Notification.ProgressStyle setProgressTrackerIcon(Icon trackerIcon)

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

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

Public constructors

ProgressStyle

public ProgressStyle ()

Public methods

addProgressPoint

public Notification.ProgressStyle addProgressPoint (Notification.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 Point.getPosition().

Parameters
point Notification.ProgressStyle.Point: This value cannot be null.

Returns
Notification.ProgressStyle This value cannot be null.

addProgressSegment

public Notification.ProgressStyle addProgressSegment (Notification.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.

Parameters
segment Notification.ProgressStyle.Segment: This value cannot be null.

Returns
Notification.ProgressStyle This value cannot be null.

getProgress

public int getProgress ()

Gets the progress value of the progress bar.

Returns
int

See also:

getProgressEndIcon

public Icon getProgressEndIcon ()

Gets the progress bar end icon.

Returns
Icon This value may be null.

getProgressMax

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

Returns
int

getProgressPoints

public List<Notification.ProgressStyle.Point> getProgressPoints ()

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

Returns
List<Notification.ProgressStyle.Point> This value cannot be null.

getProgressSegments

public List<Notification.ProgressStyle.Segment> getProgressSegments ()

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.

Returns
List<Notification.ProgressStyle.Segment> This value cannot be null.

getProgressStartIcon

public Icon getProgressStartIcon ()

Gets the progress bar start icon.

Returns
Icon This value may be null.

getProgressTrackerIcon

public Icon getProgressTrackerIcon ()

Gets the progress tracker icon for the progress bar.

Returns
Icon This value may be null.

isProgressIndeterminate

public boolean isProgressIndeterminate ()

Get indeterminate value of the progress bar.

Returns
boolean

isStyledByProgress

public boolean isStyledByProgress ()

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

Returns
boolean

setProgress

public Notification.ProgressStyle setProgress (int progress)

Specifies the progress (in the same units as Segment.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.

Parameters
progress int

Returns
Notification.ProgressStyle This value cannot be null.

setProgressEndIcon

public Notification.ProgressStyle setProgressEndIcon (Icon 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.

Parameters
endIcon Icon: This value may be null.

Returns
Notification.ProgressStyle This value cannot be null.

setProgressIndeterminate

public Notification.ProgressStyle setProgressIndeterminate (boolean indeterminate)

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

Parameters
indeterminate boolean

Returns
Notification.ProgressStyle This value cannot be null.

setProgressPoints

public Notification.ProgressStyle setProgressPoints (List<Notification.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.

Parameters
points List: This value cannot be null.

Returns
Notification.ProgressStyle This value cannot be null.

setProgressSegments

public Notification.ProgressStyle setProgressSegments (List<Notification.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.

Parameters
progressSegments List: This value cannot be null.

Returns
Notification.ProgressStyle This value cannot be null.

setProgressStartIcon

public Notification.ProgressStyle setProgressStartIcon (Icon 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.

Parameters
startIcon Icon: This value may be null.

Returns
Notification.ProgressStyle This value cannot be null.

setProgressTrackerIcon

public Notification.ProgressStyle setProgressTrackerIcon (Icon 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.

Parameters
trackerIcon Icon: This value may be null.

Returns
Notification.ProgressStyle This value cannot be null.

setStyledByProgress

public Notification.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.

Parameters
enabled boolean

Returns
Notification.ProgressStyle This value cannot be null.