ProgressBar
1. Feature Description
RemoteProgressBar is a horizontal progress bar component for showing task progress, corresponding to ViewType.PROGRESS_BAR. It supports setting the current progress, the maximum value, and the bar color. It fits linear progress for uploading / downloading / loading, etc.
Create it via RemoteViewHelper.createProgressBar():
val progressBar = helper.createProgressBar()
2. Common Properties
The following properties are set via the corresponding setXxx() methods. Unless noted otherwise, if the component is already mounted, call syncToRemote() after changing a property to make it take effect on Pilot.
Size & Layout (inherited from RemoteViewProvider)
| Method | Params | Description |
|---|---|---|
setWidth | Int | Width (dp); special values RemoteView.MATCH_PARENT(-1) / WRAP_CONTENT(-2) |
setHeight | Int | Height (dp), i.e. the bar thickness; same special values |
setMinSize | minWidth: Int, minHeight: Int | Minimum size (dp) |
setPadding | left, top, right, bottom: Int | Padding (dp) |
setVisibility | VisibilityType | Visibility: VISIBLE / INVISIBLE / GONE |
setAlpha | Float | Opacity, 0.0 – 1.0 |
setEnabled | Boolean | Whether enabled |
Background & Shape (inherited from RemoteViewProvider)
| Method | Params | Description |
|---|---|---|
setBackground | Int | Solid background color (ARGB Int) |
setBackgroundShape | ShapeDescriptor | Background shape: fill / stroke / corner radius |
Progress Bar Properties
| Method | Params | Description |
|---|---|---|
setProgress | Int | Current progress value; must not exceed the maximum set by setMax |
setMax | Int | Maximum progress value, defaults to 100 |
setProgressColor | Int | Progress fill color (ARGB Int) |
3. Tips
- Colors must be ARGB Int.
setProgressColor/setBackgroundaccept an Int color value (e.g.0xFF1A8BFF.toInt()orColor.RED). Do not pass"#RRGGBB","0xAARRGGBB", orR.color.xxx. - Call
syncToRemote()after changing a mounted component's properties.setXxxonly updates the local cache;syncToRemote()batch-syncs to Pilot. If you configure properties before mounting, no extra call is needed. - Progress percentage =
progress / max. If you use a custom maximum other than 100, set it viasetMaxand make sure the value passed tosetProgressdoes not exceed that maximum. - The bar thickness is controlled by
setHeight. For a horizontal progress bar, the height is the bar thickness; set the width toMATCH_PARENTto fill the container.
4. Sample Code
In each group below, the code sample is on the left and the corresponding Pilot-side rendered preview is on the right.
01 Progress & Style (value / thickness / color)
// Different progress values: 33% / 66% / 100%
val p33 = helper.createProgressBar().apply {
setWidth(RemoteView.MATCH_PARENT); setHeight(12)
setMax(100); setProgress(33); setProgressColor(0xFF1A8BFF.toInt())
}
val p66 = helper.createProgressBar().apply {
setWidth(RemoteView.MATCH_PARENT); setHeight(12)
setMax(100); setProgress(66); setProgressColor(0xFF1A8BFF.toInt())
}
val p100 = helper.createProgressBar().apply {
setWidth(RemoteView.MATCH_PARENT); setHeight(12)
setMax(100); setProgress(100); setProgressColor(0xFF1A8BFF.toInt())
}
// Different thickness (via setHeight): 4dp / 8dp / 12dp
val thin = helper.createProgressBar().apply {
setWidth(RemoteView.MATCH_PARENT); setHeight(4)
setProgress(33); setProgressColor(0xFF1A8BFF.toInt())
}
val medium = helper.createProgressBar().apply {
setWidth(RemoteView.MATCH_PARENT); setHeight(8)
setProgress(66); setProgressColor(0xFF1A8BFF.toInt())
}
val thick = helper.createProgressBar().apply {
setWidth(RemoteView.MATCH_PARENT); setHeight(12)
setProgress(100); setProgressColor(0xFF1A8BFF.toInt())
}
// Different colors: blue / orange / red
val blue = helper.createProgressBar().apply {
setWidth(RemoteView.MATCH_PARENT); setHeight(12)
setProgress(33); setProgressColor(0xFF1A8BFF.toInt())
}
val orange = helper.createProgressBar().apply {
setWidth(RemoteView.MATCH_PARENT); setHeight(12)
setProgress(66); setProgressColor(0xFFFF8100.toInt())
}
val red = helper.createProgressBar().apply {
setWidth(RemoteView.MATCH_PARENT); setHeight(12)
setProgress(88); setProgressColor(0xFFE41F29.toInt())
}
For a full runnable example, see drawing/ProgressBarDrawer.kt in the official Sample
open-pilot-plugin-sample.