Skip to content

Commit 27b58f1

Browse files
cketchamafohrman
authored andcommitted
Make ShapeAppearanceModel immutable
PiperOrigin-RevId: 266378228
1 parent d697340 commit 27b58f1

File tree

5 files changed

+186
-613
lines changed

5 files changed

+186
-613
lines changed

lib/java/com/google/android/material/shape/CornerTreatment.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class CornerTreatment implements Cloneable {
3636

3737
private static final String TAG = "CornerTreatment";
3838

39-
protected float cornerSize;
39+
protected final float cornerSize;
4040

4141
public CornerTreatment() {
4242
// Default Constructor has no size. Using this treatment for all corners will draw a square
@@ -70,10 +70,6 @@ public float getCornerSize() {
7070
return cornerSize;
7171
}
7272

73-
public void setCornerSize(float cornerSize) {
74-
this.cornerSize = cornerSize;
75-
}
76-
7773
@NonNull
7874
@Override
7975
public CornerTreatment clone() {

lib/java/com/google/android/material/shape/MaterialShapeDrawable.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@
6767
* Base drawable class for Material Shapes that handles shadows, elevation, scale and color for a
6868
* generated path.
6969
*/
70-
public class MaterialShapeDrawable extends Drawable
71-
implements TintAwareDrawable, ShapeAppearanceModel.OnChangedListener, Shapeable {
70+
public class MaterialShapeDrawable extends Drawable implements TintAwareDrawable, Shapeable {
7271

7372
private static final float SHADOW_RADIUS_MULTIPLIER = .75f;
7473

@@ -204,10 +203,6 @@ public void onEdgePathCreated(@NonNull ShapePath edgePath, Matrix transform, int
204203
edgeShadowOperation[count] = edgePath.createShadowCompatOperation(transform);
205204
}
206205
};
207-
208-
// Listens for modifications made in the ShapeAppearanceModel, and requests a redraw if the
209-
// ShapeAppearanceModel has changed.
210-
drawableState.shapeAppearanceModel.addOnChangedListener(this);
211206
}
212207

213208
@Nullable
@@ -237,9 +232,7 @@ private static int modulateAlpha(int paintAlpha, int alpha) {
237232
*/
238233
@Override
239234
public void setShapeAppearanceModel(@NonNull ShapeAppearanceModel shapeAppearanceModel) {
240-
drawableState.shapeAppearanceModel.removeOnChangedListener(this);
241235
drawableState.shapeAppearanceModel = shapeAppearanceModel;
242-
shapeAppearanceModel.addOnChangedListener(this);
243236
invalidateSelf();
244237
}
245238

@@ -828,11 +821,6 @@ public void setScale(float scale) {
828821
}
829822
}
830823

831-
@Override
832-
public void onShapeAppearanceModelChanged() {
833-
invalidateSelf();
834-
}
835-
836824
@Override
837825
public void invalidateSelf() {
838826
pathDirty = true;

0 commit comments

Comments
 (0)