Debug overlay: use top gravity instead of bottom for text
@@ -35,7 +35,7 @@ public class DebugOverlayDrawable extends Drawable {
private static final int MARGIN = TEXT_LINE_SPACING_PX / 2;
private @ColorInt int mBackgroundColor = Color.TRANSPARENT;
- private int mTextGravity = Gravity.BOTTOM;
+ private int mTextGravity = Gravity.TOP;
// Internal helpers
private final LinkedHashMap<String, Pair<String, Integer>> mDebugData = new LinkedHashMap<>();
@@ -124,6 +124,10 @@ public class DebugOverlayDrawable extends Drawable {
return PixelFormat.TRANSLUCENT;
}
+ public void setTextGravity(int textGravity) {
+ mTextGravity = textGravity;
+ }
+
private void prepareDebugTextParameters(Rect bounds) {
if (mDebugData.isEmpty() || mMaxLineLength <= 0) {
return;
@@ -133,14 +137,11 @@ public class DebugOverlayDrawable extends Drawable {
mPaint.setTextSize(textSizePx);
mLineIncrementPx = textSizePx + TEXT_LINE_SPACING_PX;
- if (mTextGravity == Gravity.BOTTOM) {
- mLineIncrementPx *= -1;
- }
mStartTextXPx = bounds.left + TEXT_PADDING_PX;
mStartTextYPx =
mTextGravity == Gravity.BOTTOM
? bounds.bottom - TEXT_PADDING_PX
- : bounds.top + TEXT_PADDING_PX + MIN_TEXT_SIZE_PX;
+ : bounds.top + TEXT_PADDING_PX + textSizePx;
}
protected void addDebugText(Canvas canvas, String label, String value, Integer color) {
@@ -153,7 +154,7 @@ public class DebugOverlayDrawable extends Drawable {
mCurrentTextXPx - MARGIN,
mCurrentTextYPx + TEXT_LINE_SPACING_PX,
mCurrentTextXPx + labelColonWidth + valueWidth + MARGIN,
- mCurrentTextYPx + mLineIncrementPx + TEXT_LINE_SPACING_PX,
+ mCurrentTextYPx - mLineIncrementPx + TEXT_LINE_SPACING_PX,
mPaint);
mPaint.setColor(TEXT_COLOR);
@@ -162,8 +163,12 @@ public class DebugOverlayDrawable extends Drawable {
canvas.drawText(
String.valueOf(value), mCurrentTextXPx + labelColonWidth, mCurrentTextYPx, mPaint);
+ if (mTextGravity == Gravity.BOTTOM) {
+ mCurrentTextYPx -= mLineIncrementPx;
+ } else {
mCurrentTextYPx += mLineIncrementPx;
}
+ }
protected void addDebugText(
Canvas canvas, int x, int y, String label, String value, Integer color) {
