Skip to content

Commit

Permalink
Remove unnecessary ColorMatrixColorFilter shadow
Browse files Browse the repository at this point in the history
It was used to modify the Canvas description when a Bitmap was drawn, but the
description was overkill and did not have a valid testing use case. Just
include in the description that a ColorMatrixColorFilter is present.

PiperOrigin-RevId: 477999531
  • Loading branch information
hoisie authored and Copybara-Service committed Sep 30, 2022
1 parent 92de553 commit 590398b
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 52 deletions.
Expand Up @@ -72,9 +72,7 @@ public void withColorFilterSet_draw_shouldCopyDescriptionToCanvas() {
assertThat(shadowOf(canvas).getDescription())
.isEqualTo(
"Bitmap for"
+ " resource:org.robolectric:drawable/an_image"
+ " with"
+ " ColorMatrixColorFilter<1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0>");
+ " resource:org.robolectric:drawable/an_image with ColorMatrixColorFilter");
}

@Test
Expand Down
Expand Up @@ -231,7 +231,7 @@ public void shouldReceiveDescriptionWhenDrawABitmapToCanvasWithAPaintEffect() {
assertThat(shadowOf(bitmap1).getDescription())
.isEqualTo(
"Bitmap One\n"
+ "Bitmap Two with ColorMatrixColorFilter<1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0>"
+ "Bitmap Two with ColorMatrixColorFilter"
+ " transformed by Matrix[pre=[], set={}, post=[]]");
}

Expand Down
Expand Up @@ -15,8 +15,6 @@
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
Expand All @@ -34,7 +32,6 @@
import org.robolectric.annotation.Resetter;
import org.robolectric.res.android.NativeObjRegistry;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.util.Join;
import org.robolectric.util.ReflectionHelpers;
import org.robolectric.util.reflector.Direct;
import org.robolectric.util.reflector.ForType;
Expand Down Expand Up @@ -301,29 +298,11 @@ private void describeBitmap(Bitmap bitmap, Paint paint) {
if (paint != null) {
ColorFilter colorFilter = paint.getColorFilter();
if (colorFilter != null) {
if (colorFilter instanceof ColorMatrixColorFilter) {
ColorMatrixColorFilter colorMatrixColorFilter = (ColorMatrixColorFilter) colorFilter;
ShadowColorMatrixColorFilter shadowColorMatrixColorFilter =
Shadow.extract(colorMatrixColorFilter);
ColorMatrix colorMatrix = shadowColorMatrixColorFilter.getMatrix();
appendDescription(" with ColorMatrixColorFilter<" + formatColorMatric(colorMatrix) + ">");
} else {
appendDescription(" with " + colorFilter);
}
appendDescription(" with " + colorFilter.getClass().getSimpleName());
}
}
}

private String formatColorMatric(ColorMatrix colorMatrix) {
List<String> floats = new ArrayList<>();
for (float f : colorMatrix.getArray()) {
String format = String.format("%.2f", f);
format = format.replace(".00", "");
floats.add(format);
}
return Join.join(",", floats);
}

private void separateLines() {
if (getDescription().length() != 0) {
appendDescription("\n");
Expand Down

This file was deleted.

0 comments on commit 590398b

Please sign in to comment.