Support background color in the debug overlay
package com.facebook.fresco.vito.core.impl.debug;
import android.graphics.Canvas;
+import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
@@ -15,6 +16,7 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.Pair;
import android.view.Gravity;
+import androidx.annotation.ColorInt;
import java.util.HashMap;
import java.util.Map;
@@ -32,6 +34,7 @@ public class DebugOverlayDrawable extends Drawable {
private static final int INITIAL_MAX_LINE_LENGTH = 4;
private static final int MARGIN = TEXT_LINE_SPACING_PX / 2;
+ private @ColorInt int mBackgroundColor = Color.TRANSPARENT;
private int mTextGravity = Gravity.BOTTOM;
// Internal helpers
@@ -86,6 +89,11 @@ public class DebugOverlayDrawable extends Drawable {
mPaint.setColor(OUTLINE_COLOR);
canvas.drawRect(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint);
+ // Draw overlay
+ mPaint.setStyle(Paint.Style.FILL);
+ mPaint.setColor(mBackgroundColor);
+ canvas.drawRect(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint);
+
// Draw text
mPaint.setStyle(Paint.Style.FILL);
mPaint.setStrokeWidth(0);
@@ -107,6 +115,10 @@ public class DebugOverlayDrawable extends Drawable {
@Override
public void setColorFilter(ColorFilter cf) {}
+ public void setBackgroundColor(@ColorInt int color) {
+ mBackgroundColor = color;
+ }
+
@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
