Skip to content

Commit be6ed3d

Browse files
pekingmewcshi
authored andcommitted
[ProgressIndicator] Updated class visibility.
PiperOrigin-RevId: 342664697
1 parent fd36390 commit be6ed3d

14 files changed

+151
-122
lines changed

catalog/java/io/material/catalog/progressindicator/ProgressIndicatorStandaloneDemoFragment.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import androidx.annotation.Nullable;
2626
import com.google.android.material.chip.Chip;
2727
import com.google.android.material.internal.ViewUtils;
28-
import com.google.android.material.progressindicator.CircularDrawingDelegate;
29-
import com.google.android.material.progressindicator.CircularIndeterminateAnimatorDelegate;
3028
import com.google.android.material.progressindicator.CircularProgressIndicatorSpec;
3129
import com.google.android.material.progressindicator.IndeterminateDrawable;
3230
import com.google.android.material.switchmaterial.SwitchMaterial;
@@ -55,11 +53,7 @@ public View onCreateDemoView(
5553
spec.indicatorInset = 0; // No inset.
5654
spec.indicatorRadius = (int) ViewUtils.dpToPx(getContext(), 10); // Circular radius is 10 dp.
5755
IndeterminateDrawable progressIndicatorDrawable =
58-
new IndeterminateDrawable(
59-
getContext(),
60-
/*animatedVisibilityChangeBehavior=*/ spec,
61-
new CircularDrawingDelegate(spec),
62-
new CircularIndeterminateAnimatorDelegate(spec));
56+
IndeterminateDrawable.createCircularDrawable(getContext(), spec);
6357

6458
Chip chip = view.findViewById(R.id.cat_progress_indicator_chip);
6559
chip.setChipIcon(progressIndicatorDrawable);

lib/java/com/google/android/material/progressindicator/AnimatedVisibilityChangeBehavior.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package com.google.android.material.progressindicator;
1717

1818
/** An interface to show whether show/hide behaviors are needed for a progress indicator. */
19-
public interface AnimatedVisibilityChangeBehavior {
19+
interface AnimatedVisibilityChangeBehavior {
2020

2121
/** Returns whether the visibility change should be animated while showing. */
2222
boolean isShowAnimationEnabled();

lib/java/com/google/android/material/progressindicator/BaseProgressIndicator.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@ public class BaseProgressIndicator extends ProgressBar {
7575
public static final int HIDE_OUTWARD = 1;
7676
public static final int HIDE_INWARD = 2;
7777

78-
protected static final int DEF_STYLE_RES = R.style.Widget_MaterialComponents_ProgressIndicator;
78+
static final int DEF_STYLE_RES = R.style.Widget_MaterialComponents_ProgressIndicator;
7979

80-
protected static final float DEFAULT_OPACITY = 0.2f;
81-
protected static final int MAX_ALPHA = 255;
80+
static final float DEFAULT_OPACITY = 0.2f;
81+
static final int MAX_ALPHA = 255;
8282
/**
8383
* The maximum time, in milliseconds, that the requested hide action is allowed to wait once
8484
* {@link #show()} is called.
8585
*/
8686
private static final int MAX_HIDE_DELAY = 1000;
8787

8888
/** A place to hold all the attributes. */
89-
protected final BaseProgressIndicatorSpec baseSpec;
89+
final BaseProgressIndicatorSpec baseSpec;
9090

9191
/** A temp place to hold new progress while switching from indeterminate to determinate mode. */
9292
private int storedProgress;
@@ -251,8 +251,8 @@ public void hide() {
251251
* @see #hide()
252252
*/
253253
private void internalHide() {
254-
getCurrentDrawable()
255-
.setVisible(/*visible=*/ false, /*restart=*/ false, /*animationDesired=*/ true);
254+
((DrawableWithAnimatedVisibilityChange) getCurrentDrawable())
255+
.setVisible(/*visible=*/ false, /*restart=*/ false, /*animate=*/ true);
256256

257257
if (isNoLongerNeedToBeVisible()) {
258258
setVisibility(INVISIBLE);
@@ -262,27 +262,28 @@ private void internalHide() {
262262
@Override
263263
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
264264
super.onVisibilityChanged(changedView, visibility);
265-
applyNewVisibility(/*animationDesired=*/ visibility == VISIBLE);
265+
applyNewVisibility(/*animate=*/ visibility == VISIBLE);
266266
}
267267

268268
@Override
269269
protected void onWindowVisibilityChanged(int visibility) {
270270
super.onWindowVisibilityChanged(visibility);
271-
applyNewVisibility(/*animationDesired=*/ false);
271+
applyNewVisibility(/*animate=*/ false);
272272
}
273273

274274
/**
275275
* If it changes to visible, the start animation will be started if {@code showAnimationBehavior}
276276
* indicates any. If it changes to invisible, hides the drawable immediately.
277277
*
278-
* @param animationDesired Whether to change the visibility with animation.
278+
* @param animate Whether to change the visibility with animation.
279279
*/
280-
protected void applyNewVisibility(boolean animationDesired) {
280+
protected void applyNewVisibility(boolean animate) {
281281
if (!isParentDoneInitializing) {
282282
return;
283283
}
284284

285-
getCurrentDrawable().setVisible(visibleToUser(), /*restart=*/ false, animationDesired);
285+
((DrawableWithAnimatedVisibilityChange) getCurrentDrawable())
286+
.setVisible(visibleToUser(), /*restart=*/ false, animate);
286287
}
287288

288289
@Override
@@ -300,7 +301,7 @@ protected void onDetachedFromWindow() {
300301
// Removes the delayedHide and delayedShow runnables from the queue if it has been scheduled.
301302
removeCallbacks(delayedHide);
302303
removeCallbacks(delayedShow);
303-
getCurrentDrawable().hideNow();
304+
((DrawableWithAnimatedVisibilityChange) getCurrentDrawable()).hideNow();
304305
unregisterAnimationCallbacks();
305306
super.onDetachedFromWindow();
306307
}
@@ -329,6 +330,9 @@ protected synchronized void onDraw(@NonNull Canvas canvas) {
329330
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
330331
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
331332
DrawingDelegate drawingDelegate = getCurrentDrawingDelegate();
333+
if (drawingDelegate == null) {
334+
return;
335+
}
332336
int drawableMeasuredWidth = drawingDelegate.getPreferredWidth();
333337
int drawableMeasuredHeight = drawingDelegate.getPreferredHeight();
334338
setMeasuredDimension(
@@ -353,13 +357,13 @@ public void invalidate() {
353357
/** Returns the corresponding drawable based on current indeterminate state. */
354358
@Override
355359
@Nullable
356-
public DrawableWithAnimatedVisibilityChange getCurrentDrawable() {
360+
public Drawable getCurrentDrawable() {
357361
return isIndeterminate() ? getIndeterminateDrawable() : getProgressDrawable();
358362
}
359363

360364
/** Returns the drawing delegate associated with the current drawable. */
361365
@Nullable
362-
public DrawingDelegate getCurrentDrawingDelegate() {
366+
private DrawingDelegate getCurrentDrawingDelegate() {
363367
if (isIndeterminate()) {
364368
return getIndeterminateDrawable() == null
365369
? null
@@ -431,7 +435,7 @@ public IndeterminateDrawable getIndeterminateDrawable() {
431435
* Returns whether or not this view is currently displayed in window, based on whether it is
432436
* attached to a window and whether it and its ancestors are visible.
433437
*/
434-
protected boolean visibleToUser() {
438+
boolean visibleToUser() {
435439
return ViewCompat.isAttachedToWindow(this)
436440
&& getWindowVisibility() == View.VISIBLE
437441
&& isEffectivelyVisible();
@@ -460,7 +464,7 @@ && getWindowVisibility() == View.VISIBLE
460464
* conclusively prove otherwise (but may result in some false positives, if this view ends up
461465
* being attached to a non-visible hierarchy after being detached in a visible state).
462466
*/
463-
protected boolean isEffectivelyVisible() {
467+
boolean isEffectivelyVisible() {
464468
View current = this;
465469
do {
466470
if (current.getVisibility() != VISIBLE) {
@@ -508,14 +512,16 @@ public synchronized void setIndeterminate(boolean indeterminate) {
508512

509513
// Needs to explicitly set visibility of two drawables. ProgressBar.setIndeterminate doesn't
510514
// handle it properly for pre-lollipop.
511-
DrawableWithAnimatedVisibilityChange oldDrawable = getCurrentDrawable();
515+
DrawableWithAnimatedVisibilityChange oldDrawable =
516+
(DrawableWithAnimatedVisibilityChange) getCurrentDrawable();
512517
if (oldDrawable != null) {
513518
oldDrawable.hideNow();
514519
}
515520
super.setIndeterminate(indeterminate);
516-
DrawableWithAnimatedVisibilityChange newDrawable = getCurrentDrawable();
521+
DrawableWithAnimatedVisibilityChange newDrawable =
522+
(DrawableWithAnimatedVisibilityChange) getCurrentDrawable();
517523
if (newDrawable != null) {
518-
newDrawable.setVisible(visibleToUser(), /*restart=*/ false, /*animationDesired=*/ false);
524+
newDrawable.setVisible(visibleToUser(), /*restart=*/ false, /*animate=*/ false);
519525
}
520526

521527
// Indeterminate mode change finished.
@@ -691,7 +697,7 @@ public void setHideAnimationBehavior(@HideAnimationBehavior int hideAnimationBeh
691697
*
692698
* @param progress The new progress value.
693699
* @see ProgressBar#setProgress(int)
694-
* @see #setProgress(int, boolean)
700+
* @see #setProgressCompat(int, boolean)
695701
*/
696702
@Override
697703
public synchronized void setProgress(int progress) {

lib/java/com/google/android/material/progressindicator/CircularDrawingDelegate.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import com.google.android.material.color.MaterialColors;
2727

2828
/** A delegate class to help draw the graphics for {@link CircularProgressIndicator}. */
29-
public final class CircularDrawingDelegate extends DrawingDelegate {
29+
final class CircularDrawingDelegate extends DrawingDelegate {
3030

3131
private final CircularProgressIndicatorSpec spec;
3232
private final BaseProgressIndicatorSpec baseSpec;
@@ -68,6 +68,8 @@ public int getPreferredHeight() {
6868
public void adjustCanvas(
6969
@NonNull Canvas canvas,
7070
@FloatRange(from = 0.0, to = 1.0) float indicatorSizeFraction) {
71+
spec.validateSpec();
72+
7173
int outerRadiusWithInset =
7274
spec.indicatorRadius + baseSpec.indicatorSize / 2 + spec.indicatorInset;
7375
canvas.translate(outerRadiusWithInset, outerRadiusWithInset);

lib/java/com/google/android/material/progressindicator/CircularIndeterminateAnimatorDelegate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* This is the implementation class for drawing progress indicator in the circular indeterminate
3333
* mode.
3434
*/
35-
public final class CircularIndeterminateAnimatorDelegate
35+
final class CircularIndeterminateAnimatorDelegate
3636
extends IndeterminateAnimatorDelegate<AnimatorSet> {
3737

3838
// Constants for animation values.

lib/java/com/google/android/material/progressindicator/CircularProgressIndicator.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@
4848
* <li>{@code indicatorDirectionCircular}: the rotation direction of the spinner or indicator.
4949
* </ul>
5050
*/
51-
public class CircularProgressIndicator extends BaseProgressIndicator {
51+
public final class CircularProgressIndicator extends BaseProgressIndicator {
5252
public static final int DEF_STYLE_RES =
5353
R.style.Widget_MaterialComponents_CircularProgressIndicator;
5454

5555
public static final int INDICATOR_DIRECTION_CLOCKWISE = 0;
5656
public static final int INDICATOR_DIRECTION_COUNTERCLOCKWISE = 1;
5757

58-
protected final CircularProgressIndicatorSpec spec;
58+
final CircularProgressIndicatorSpec spec;
5959

6060
// **************** Constructors ****************
6161

@@ -83,16 +83,8 @@ public CircularProgressIndicator(
8383
// ******************** Initialization **********************
8484

8585
private void initializeDrawables() {
86-
AnimatedVisibilityChangeBehavior behavior = spec;
87-
setIndeterminateDrawable(
88-
new IndeterminateDrawable(
89-
getContext(),
90-
behavior,
91-
new CircularDrawingDelegate(spec),
92-
new CircularIndeterminateAnimatorDelegate(spec)));
93-
setProgressDrawable(
94-
new DeterminateDrawable(
95-
getContext(), baseSpec, behavior, new CircularDrawingDelegate(spec)));
86+
setIndeterminateDrawable(IndeterminateDrawable.createCircularDrawable(getContext(), spec));
87+
setProgressDrawable(DeterminateDrawable.createCircularDrawable(getContext(), spec));
9688
}
9789

9890
// **************** Getters and setters ****************
@@ -145,15 +137,15 @@ public void setIndicatorInset(@Px int indicatorInset) {
145137
* com.google.android.material.progressindicator.R.stylable#CircularProgressIndicator_indicatorRadius
146138
*/
147139
@Px
148-
public int getIndicatorrRadius() {
140+
public int getIndicatorRadius() {
149141
return spec.indicatorRadius;
150142
}
151143

152144
/**
153145
* Sets the radius of this progress indicator.
154146
*
155147
* @param indicatorRadius The new radius in pixels.
156-
* @see #getIndicatorrRadius()
148+
* @see #getIndicatorRadius()
157149
* @attr ref
158150
* com.google.android.material.progressindicator.R.stylable#CircularProgressIndicator_indicatorRadius
159151
* @throws IllegalArgumentException if new indicator radius is less than half of the indicator

lib/java/com/google/android/material/progressindicator/CircularProgressIndicatorSpec.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131

3232
/**
3333
* This class contains the parameters for drawing a circular type progress indicator. The parameters
34-
* reflect the attributes defined in {@link R.styleable.BaseProgressIndicator} and {@link
35-
* R.styleable.CircularProgressIndicator}.
34+
* reflect the attributes defined in {@link R.styleable#BaseProgressIndicator} and {@link
35+
* R.styleable#CircularProgressIndicator}.
3636
*/
37-
public class CircularProgressIndicatorSpec implements AnimatedVisibilityChangeBehavior {
37+
public final class CircularProgressIndicatorSpec implements AnimatedVisibilityChangeBehavior {
3838

3939
private final BaseProgressIndicatorSpec baseSpec;
4040

@@ -111,7 +111,7 @@ private void loadAttributes(@NonNull Context context, @Nullable AttributeSet att
111111
a.recycle();
112112
}
113113

114-
protected void validateSpec() {
114+
void validateSpec() {
115115
if (indicatorRadius < baseSpec.indicatorSize / 2) {
116116
// Throws an exception if circularRadius is less than half of the indicatorSize, which will
117117
// result in a part of the inner side of the indicator overshoots the center, and the visual

0 commit comments

Comments
 (0)