Skip to content

Commit c76665b

Browse files
pekingmewcshi
authored andcommitted
[ProgressIndicator] Deprecated LINEAR type in ProgressIndicator and ProgressIndicator.
PiperOrigin-RevId: 342069665
1 parent a5890bf commit c76665b

File tree

8 files changed

+103
-1628
lines changed

8 files changed

+103
-1628
lines changed

docs/components/ProgressIndicator.md

Lines changed: 70 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,18 @@
22

33
<!-- TODO(b/169262619) Update API and style for sub-type progress indicator classes. -->
44

5-
Note: Due to an internal change of API, ProgressIndicator will be deprecated in
6-
the near future.
5+
Note: Due to an internal change of API, `ProgressIndicator` has been deprecated.
6+
It will be removed in the near future after the internal migration process.
77

88
com.google.android.material provides an implementation of linear and circular
99
progress indicator, compatible back to API 15 (Ice Cream Sandwich MR1). The
10-
easiest way to make use of these indicators is through `ProgressIndicator` and
11-
`CircularProgressIndicator`.
10+
easiest way to make use of these indicators is through `LinearProgressIndicator`
11+
and `CircularProgressIndicator`.
1212

13-
## ProgressIndicator
14-
15-
Note: `ProgressIndicator` currently only supports linear type. Circular type is
16-
implemented in `CircularProgressIndicator`. In the near future,
17-
`ProgressIndicator` will be completely deprecated and removed. Instead, the
18-
linear type will be implemented in `LinearProgressIndicator`.
13+
## LinearProgressIndicator
1914

20-
`ProgressIndicator` is API-compatible with Android's `ProgressBar` class and can
21-
therefore be used as a drop-in replacement. It can be included in XML layouts,
22-
or constructed programmatically:
15+
`LinearProgressIndicator` is a separate implementation of linear type. It can be
16+
added to the layout via xml or programmatically.
2317

2418
### XML
2519

@@ -31,36 +25,67 @@ or constructed programmatically:
3125
android:layout_height="match_parent">
3226
<!-- ... -->
3327
34-
<com.google.android.material.progressindicator.ProgressIndicator
35-
style="@style/Widget.MaterialComponents.ProgressIndicator.Linear.Indeterminate"
28+
<com.google.android.material.progressindicator.LinearProgressIndicator
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
3631
android:id="@+id/Progress"/>
3732
3833
<!-- ... -->
3934
</FrameLayout>
4035
```
4136

37+
The default material style `Widget.MaterialComponents.LinearProgressIndicator`
38+
will be used as a determinate progress indicator. For the indeterminate mode,
39+
please add `android:indeterminate="true"` as the attribute.
40+
4241
### Java
4342

4443
```java
45-
// An example to create linear indeterminate progress indicator.
46-
import static com.google.android.material.progressindicator.R.style.
47-
Widget_MaterialComponents_ProgressIndicator_Linear_Indeterminate;
44+
// An example to create a linear indeterminate progress indicator.
45+
import com.google.android.material.progressindicator.LinearProgressIndicator;
4846

49-
import com.google.android.material.progressindicator.ProgressIndicator;
50-
51-
ProgressIndicator progressIndicator =
52-
new ProgressIndicator(getContext(), null, 0,
53-
Widget_MaterialComponents_ProgressIndicator_Circular_Indeterminate);
47+
LinearProgressIndicator indicator = new LinearProgressIndicator(getContext());
5448
```
5549

56-
### Showing and hiding with animations
50+
### Default style
51+
52+
The default style `Widget.MaterialComponents.LinearProgressIndicator` will
53+
configure the indicator to draw a linear strip with the track width of 4dp. The
54+
indicator will swipe or grow from `start` to `end` regarding the layout
55+
direction. No animation will be used while showing or hiding.
56+
57+
### Custom styling
58+
59+
`LinearProgressIndicator` can be configured with custom values to have different
60+
appearance.
61+
62+
#### Colors
63+
64+
The indicator color and track color can be configured by setting
65+
`indicatorColor` and `trackColor`. For multiple indicator color use, a color
66+
array can be assigned to `indicatorColor`, too. To set it programmatically, one
67+
can use `setIndicatorColor(int[])`.
68+
69+
Note: `getIndicatorColor()` will always return in the form of an int array
70+
regardless the number of indicator colors used.
71+
72+
#### Size and layout
73+
74+
`LinearProgressIndicator` can configure its height by adjusting `indicatorSize`.
75+
`indicatorSize` sets the width of the track/indicator; in the linear type case,
76+
it's the height of the strip.
77+
78+
Note: The width of strip depends on the view and its layout.
79+
80+
#### Showing and hiding with animations
5781

5882
The progress indicator can be animated in and out by calling `#show()` or
59-
`#hide()` actively on `ProgressIndicator`:
83+
`#hide()` actively on `LinearProgressIndicator`:
6084

6185
```java
6286
// ...
63-
ProgressIndicator progress = (ProgressIndicator) findViewById(R.id.Progress);
87+
LinearProgressIndicator progress =
88+
(LinearProgressIndicator) findViewById(R.id.Progress);
6489
progress.show();
6590
// ... wait until finished
6691
progress.hide();
@@ -71,98 +96,26 @@ The component can also be animated in when it's attached to the current window:
7196
```java
7297
// ...
7398
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
74-
ProgressIndicator progress = new ProgressIndicator(activity, null, 0,
75-
Widget_MaterialComponents_ProgressIndicator_Linear_Indeterminate);
99+
LinearProgressIndicator progress =
100+
new LinearProgressIndicator(getContext());
76101
// ... configures the components.
77-
layout.addView(progress, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
102+
layout.addView(progress, new LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
78103
```
79104

80-
By setting `growMode`, the linear progress indicator can have different
81-
animation effects while showing or hiding.
105+
By setting the `showBehaviorLinear` and `hideBehaviorLinear`, the indicator can
106+
have different animation effects as follows:
82107

83108
<table>
84-
<tr><td>GrowMode</td><td>show()</td><td>hide()</td></tr>
85-
<tr>
86-
<td>GROW_MODE_INCOMING</td>
87-
<td>Expending vertically from the top</td>
88-
<td>Collapsing vertically to the top</td></tr>
89-
<tr>
90-
<td>GROW_MODE_OUTCOMING</td>
91-
<td>Expending vertically from the bottom</td>
92-
<td>Collapsing vertically to the bottom</td></tr>
93-
<tr>
94-
<td>GROW_MODE_BIDIRECTIONAL</td>
95-
<td>Expending from the horizontal central line</td>
96-
<td>Collapsing to the horizontal central line</td></tr>
97-
<tr>
98-
<td>GROW_MODE_NONE</td>
99-
<td>Appear immediately</td>
100-
<td>Disappear immediately</td></tr>
101-
</table>
102-
103-
### Preset styles
104-
105-
There are 2 preset styles available that match the types of indicators shown in
106-
the spec. To use them, simply set your `style` attribute in XML to the desired
107-
name.
108-
109-
<table>
110-
<tr><td>Preset style name</td><td>Style</td></tr>
111-
<tr>
112-
<td>Widget.MaterialComponents.ProgressIndicator.<br>&emsp;Linear.Determinate</td>
113-
<td>4 dp high linear determinate with default max (100)</td>
114-
</tr>
115-
<tr>
116-
<td>Widget.MaterialComponents.ProgressIndicator.<br>&emsp;Linear.Indeterminate</td>
117-
<td>4 dp high linear indeterminate</td>
118-
</tr>
109+
<tr><td colspan=2>showBehaviorLinear<td></tr>
110+
<tr><td>none</td><td>Appear immediately</td></tr>
111+
<tr><td>upward</td><td>Expanding from the bottom edge</td></tr>
112+
<tr><td>downward</td><td>Expanding from the top edge</td></tr>
113+
<tr><td colspan=2>hideBehaviorLinear<td></tr>
114+
<tr><td>none</td><td>Disappear immediately</td></tr>
115+
<tr><td>upward</td><td>Collapsing to the top edge</td></tr>
116+
<tr><td>downward</td><td>Collapsing to the bottom edge</td></tr>
119117
</table>
120118

121-
### Custom styling
122-
123-
`ProgressIndicator` can be styled further by customizing colors, size, grow
124-
mode, etc. These are done through XML attributes, or their corresponding setter
125-
methods.
126-
127-
#### Colors
128-
129-
For single color mode styles (i.e., all determinate types, and some
130-
indeterminate types), the color of indicator (or stroke) can be set in attribute
131-
`indicatorColor` in XML or `setIndicatorColors(int[])` programmatically; the
132-
color of track (the parts of track other than stroke) can be set in attribute
133-
`trackColor` in XML or `setTrackColor(int)` programmatically.
134-
135-
Note: Multiple colors can only take effect in indeterminate mode. If multiple
136-
indicator colors are set in determinate mode, only the first color will be used.
137-
138-
Note: In XML, only one of the attributes `indicatorColor` and `indicatorColors`
139-
can be set. If both are defined, `IllegalArgumentException` will be thrown while
140-
initialization. If neither is defined, the primary color of the current theme
141-
will be used as the indicator color.
142-
143-
#### Size
144-
145-
Use `indicatorSize` to customize the size of the linear type. It can adjust the
146-
height of the progress bar. To add inset for linear types, please use padding of
147-
the layout.
148-
149-
Note: The indicator and track always have the same width.
150-
151-
The size of circular types can be set with a combination of `indicatorSize`,
152-
`circularRadius`, and `circularInset`. `indicatorSize` defines the width of the
153-
ring (circular spinner). `circularRadius` defines the radius of the central line
154-
of the ring. `circularInset` gives extra space between the outer boundary to the
155-
bounds of the component.
156-
157-
Note: If half of the `indicatorSize` is greater than the `circularRadius`,
158-
`IllegalArgumentException` will be thrown during initialization.
159-
160-
### Caveats
161-
162-
Subclassing `ProgressIndicator` is not recommended. If additional features are
163-
needed, please file an issue througth Github with `feature request` tag. Pull
164-
requests directly to `ProgressIndicator` are also welcome.
165-
166119
## CircularProgressIndicator
167120

168121
`CircularProgressIndicator` is a separate implementation of circular type. It
@@ -195,7 +148,7 @@ please add `android:indeterminate="true"` as the attribute.
195148

196149
```java
197150
// An example to create a circular indeterminate progress indicator.
198-
import com.google.android.material.progressindicator.ProgressIndicator;
151+
import com.google.android.material.progressindicator.CircularProgressIndicator;
199152

200153
CircularProgressIndicator indicator = new CircularProgressIndicator(getContext());
201154
```
@@ -216,14 +169,7 @@ different appearance.
216169

217170
#### Colors
218171

219-
Similar as `ProgressIndicator`, the indicator color and track color can be
220-
configured by setting `indicatorColor` and `trackColor`. The difference is that,
221-
for multiple indicator colors, one should set `indicatorColor` with a color
222-
array instead of using `indicatorColors`. To set it programmatically, one can
223-
use `setIndicatorColor(int[])`.
224-
225-
Note: `getIndicatorColor()` will always return in the form of an int array
226-
regardless the number of indicator colors used.
172+
Same as `LinearProgressIndicator`.
227173

228174
#### Size and layout
229175

@@ -275,12 +221,8 @@ can have different animation effects as follows:
275221
<tr><td>outward</td><td>Collapsing to the outer edge</td></tr>
276222
</table>
277223

278-
### Caveats
279-
280-
`CircularProgressIndicator` is final. For more customized appearances, please
281-
consider to implement custom `DrawingDelegate` and
282-
`IndetermianteAnimatorDelegate` and inherit from the `BaseProgressIndicator`.
283-
284-
## LinearProgressIndicator
224+
## Caveats
285225

286-
<!--TODO(b/169262416) Finishes after implementation is done. -->
226+
`CircularProgressIndicator` and `LinearProgressIndicator` are final. For more
227+
customized appearances, please consider to implement custom `DrawingDelegate`
228+
and `IndetermianteAnimatorDelegate` and inherit from the `BaseProgressIndicator`.

0 commit comments

Comments
 (0)