Skip to content

Commit

Permalink
[MaterialShapeDrawable] Implement getAlpha()
Browse files Browse the repository at this point in the history
Resolves #2479

GIT_ORIGIN_REV_ID=20d18f9732871b06aa9f95af0bd02f23b3e7995a
PiperOrigin-RevId: 412092198
  • Loading branch information
Andre\u0301 Wachter authored and paulfthomas committed Nov 29, 2021
1 parent 3c9b452 commit 5ff917d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Expand Up @@ -455,6 +455,11 @@ public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}

@Override
public int getAlpha() {
return drawableState.alpha;
}

@Override
public void setAlpha(@IntRange(from = 0, to = 255) int alpha) {
if (drawableState.alpha != alpha) {
Expand Down
Expand Up @@ -34,6 +34,7 @@ public class MaterialShapeDrawableTest {
private static final float ELEVATION = 4;
private static final float TRANSLATION_Z = 2;
private static final float Z = ELEVATION + TRANSLATION_Z;
private static final int ALPHA = 127;

private final Context context = ApplicationProvider.getApplicationContext();

Expand Down Expand Up @@ -132,4 +133,11 @@ public void givenElevation_whenSetZ_setsTranslationZToDifferenceBetweenZAndEleva
assertThat(drawable.getFillColor().getDefaultColor()).isEqualTo(colorSurface);
assertThat(drawable.isElevationOverlayInitialized()).isTrue();
}

@Test
public void whenSetAlpha_returnsAlpha() {
materialShapeDrawable.setAlpha(ALPHA);

assertThat(materialShapeDrawable.getAlpha()).isEqualTo(ALPHA);
}
}

0 comments on commit 5ff917d

Please sign in to comment.