Skip to content

Commit 1fb57bc

Browse files
committed
[ProgressIndicator] Updated "indicatorSize" in CircularProgressIndicatorSpec to be never less than twice of "trackThickness".
Resolves #2005 PiperOrigin-RevId: 353887395
1 parent 0fcf185 commit 1fb57bc

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import com.google.android.material.R;
2020

21+
import static java.lang.Math.max;
22+
2123
import android.content.Context;
2224
import android.util.AttributeSet;
2325
import androidx.annotation.AttrRes;
@@ -150,10 +152,9 @@ public int getIndicatorSize() {
150152
* @see #getIndicatorSize()
151153
* @attr ref
152154
* com.google.android.material.progressindicator.R.stylable#CircularProgressIndicator_indicatorSize
153-
* @throws IllegalArgumentException if new indicator radius is less than half of the indicator
154-
* size.
155155
*/
156156
public void setIndicatorSize(@Px int indicatorSize) {
157+
indicatorSize = max(indicatorSize, getTrackThickness() * 2);
157158
if (spec.indicatorSize != indicatorSize) {
158159
spec.indicatorSize = indicatorSize;
159160
spec.validateSpec();

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.android.material.R;
2020

2121
import static com.google.android.material.resources.MaterialResources.getDimensionPixelSize;
22+
import static java.lang.Math.max;
2223

2324
import android.content.Context;
2425
import android.content.res.TypedArray;
@@ -82,8 +83,13 @@ public CircularProgressIndicatorSpec(
8283
ThemeEnforcement.obtainStyledAttributes(
8384
context, attrs, R.styleable.CircularProgressIndicator, defStyleAttr, defStyleRes);
8485
indicatorSize =
85-
getDimensionPixelSize(
86-
context, a, R.styleable.CircularProgressIndicator_indicatorSize, defaultIndicatorSize);
86+
max(
87+
getDimensionPixelSize(
88+
context,
89+
a,
90+
R.styleable.CircularProgressIndicator_indicatorSize,
91+
defaultIndicatorSize),
92+
trackThickness * 2);
8793
indicatorInset =
8894
getDimensionPixelSize(
8995
context,
@@ -100,17 +106,5 @@ public CircularProgressIndicatorSpec(
100106
}
101107

102108
@Override
103-
void validateSpec() {
104-
if (indicatorSize < trackThickness * 2) {
105-
// Throws an exception if indicatorSize is less than twice of the trackThickness, which will
106-
// result in a part of the inner side of the indicator overshoots the center, and the visual
107-
// becomes undefined.
108-
throw new IllegalArgumentException(
109-
"The indicatorSize ("
110-
+ indicatorSize
111-
+ " px) cannot be less than twice of the trackThickness ("
112-
+ trackThickness
113-
+ " px).");
114-
}
115-
}
109+
void validateSpec() {}
116110
}

0 commit comments

Comments
 (0)