diff options
author | Philip Milne <pmilne@google.com> | 2012-04-24 19:27:11 -0700 |
---|---|---|
committer | Philip Milne <pmilne@google.com> | 2012-04-24 19:32:31 -0700 |
commit | 604f440dfd6e5ee857f1e71d12c635d4ee1afcbc (patch) | |
tree | 6177b68a96b25b2e256940f3a53252e866b8fd0f /core | |
parent | b2b15716d8b5b5814e82575a592e76f522f6a4c6 (diff) | |
download | frameworks_base-604f440dfd6e5ee857f1e71d12c635d4ee1afcbc.zip frameworks_base-604f440dfd6e5ee857f1e71d12c635d4ee1afcbc.tar.gz frameworks_base-604f440dfd6e5ee857f1e71d12c635d4ee1afcbc.tar.bz2 |
Fix for layout debug mode.
Change-Id: I0d02aa4cf7e18c2bbb01a3296e573f2f9de60bf1
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/view/ViewGroup.java | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index 6ecd767..c4647f7 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -382,6 +382,16 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager private static final int ARRAY_INITIAL_CAPACITY = 12; private static final int ARRAY_CAPACITY_INCREMENT = 12; + private static Paint DEBUG_PAINT; + + private static Paint getDebugPaint() { + if (DEBUG_PAINT == null) { + DEBUG_PAINT = new Paint(); + DEBUG_PAINT.setStyle(Paint.Style.STROKE); + } + return DEBUG_PAINT; + } + // Used to draw cached views Paint mCachePaint; @@ -2658,7 +2668,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager return b; } - private static void drawRect(Canvas canvas, int x1, int y1, int x2, int y2, Paint paint) { + private static void drawRect(Canvas canvas, int x1, int y1, int x2, int y2, int color) { + Paint paint = getDebugPaint(); + paint.setColor(color); canvas.drawRect(x1, y1, x2 - 1, y2 - 1, paint); } @@ -2668,7 +2680,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager protected void onDebugDrawMargins(Canvas canvas) { for (int i = 0; i < getChildCount(); i++) { View c = getChildAt(i); - c.getLayoutParams().onDebugDraw(this, canvas); + c.getLayoutParams().onDebugDraw(c, canvas); } } @@ -2676,12 +2688,8 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager * @hide */ protected void onDebugDraw(Canvas canvas) { - Paint paint = new Paint(); - paint.setStyle(Paint.Style.STROKE); - // Draw optical bounds if (getLayoutMode() == LAYOUT_BOUNDS) { - paint.setColor(Color.RED); for (int i = 0; i < getChildCount(); i++) { View c = getChildAt(i); Insets insets = c.getLayoutInsets(); @@ -2689,19 +2697,18 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager c.getLeft() + insets.left, c.getTop() + insets.top, c.getRight() - insets.right, - c.getBottom() - insets.bottom, paint); + c.getBottom() - insets.bottom, Color.RED); } } + // Draw margins + onDebugDrawMargins(canvas); + // Draw bounds - paint.setColor(Color.BLUE); for (int i = 0; i < getChildCount(); i++) { View c = getChildAt(i); - drawRect(canvas, c.getLeft(), c.getTop(), c.getRight(), c.getBottom(), paint); + drawRect(canvas, c.getLeft(), c.getTop(), c.getRight(), c.getBottom(), Color.BLUE); } - - // Draw margins - onDebugDrawMargins(canvas); } /** @@ -5793,15 +5800,11 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager */ @Override public void onDebugDraw(View view, Canvas canvas) { - Paint paint = new Paint(); - paint.setStyle(Paint.Style.STROKE); - paint.setColor(Color.MAGENTA); - drawRect(canvas, view.getLeft() - leftMargin, view.getTop() - topMargin, view.getRight() + rightMargin, - view.getBottom() + bottomMargin, paint); + view.getBottom() + bottomMargin, Color.MAGENTA); } } |