summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorPhilip Milne <pmilne@google.com>2012-04-24 11:36:54 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-04-24 11:36:54 -0700
commitb2b15716d8b5b5814e82575a592e76f522f6a4c6 (patch)
tree1d7ae1c64097c1ab4ba6250c17430d6e79e96dcc /core
parent0b7d747e900dd9e6e6f62f10772c2dded9b9d0c6 (diff)
parent10ca24a97cefc14fca1b26f59e627f487b3b108b (diff)
downloadframeworks_base-b2b15716d8b5b5814e82575a592e76f522f6a4c6.zip
frameworks_base-b2b15716d8b5b5814e82575a592e76f522f6a4c6.tar.gz
frameworks_base-b2b15716d8b5b5814e82575a592e76f522f6a4c6.tar.bz2
Merge "Promote layout debugging code from GridLayout to ViewGroup."
Diffstat (limited to 'core')
-rw-r--r--core/java/android/view/View.java6
-rw-r--r--core/java/android/view/ViewGroup.java87
-rw-r--r--core/java/android/widget/GridLayout.java85
3 files changed, 131 insertions, 47 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index a833cbe..0e6af61 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -46,6 +46,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.SystemClock;
+import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.FloatProperty;
@@ -16920,6 +16921,11 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
Drawable mAccessibilityFocusDrawable;
/**
+ * Show where the margins, bounds and layout bounds are for each view.
+ */
+ final boolean mDebugLayout = SystemProperties.getBoolean("debug.layout", false);
+
+ /**
* Creates a new set of attachment information with the specified
* events handler and thread.
*
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index 8c8711c..6ecd767 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -22,6 +22,8 @@ import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Insets;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PointF;
@@ -420,9 +422,15 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
initFromAttributes(context, attrs);
}
+ private boolean debugDraw() {
+ return mAttachInfo != null && mAttachInfo.mDebugLayout;
+ }
+
private void initViewGroup() {
// ViewGroup doesn't draw by default
- setFlags(WILL_NOT_DRAW, DRAW_MASK);
+ if (!debugDraw()) {
+ setFlags(WILL_NOT_DRAW, DRAW_MASK);
+ }
mGroupFlags |= FLAG_CLIP_CHILDREN;
mGroupFlags |= FLAG_CLIP_TO_PADDING;
mGroupFlags |= FLAG_ANIMATION_DONE;
@@ -2650,6 +2658,52 @@ 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) {
+ canvas.drawRect(x1, y1, x2 - 1, y2 - 1, paint);
+ }
+
+ /**
+ * @hide
+ */
+ protected void onDebugDrawMargins(Canvas canvas) {
+ for (int i = 0; i < getChildCount(); i++) {
+ View c = getChildAt(i);
+ c.getLayoutParams().onDebugDraw(this, canvas);
+ }
+ }
+
+ /**
+ * @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();
+ drawRect(canvas,
+ c.getLeft() + insets.left,
+ c.getTop() + insets.top,
+ c.getRight() - insets.right,
+ c.getBottom() - insets.bottom, paint);
+ }
+ }
+
+ // 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);
+ }
+
+ // Draw margins
+ onDebugDrawMargins(canvas);
+ }
+
/**
* {@inheritDoc}
*/
@@ -2741,6 +2795,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
}
}
+ if (debugDraw()) {
+ onDebugDraw(canvas);
+ }
+
if (clipToPadding) {
canvas.restoreToCount(saveCount);
}
@@ -5469,6 +5527,17 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
}
/**
+ * Use {@code canvas} to draw suitable debugging annotations for these LayoutParameters.
+ *
+ * @param view the view that contains these layout parameters
+ * @param canvas the canvas on which to draw
+ *
+ * @hide
+ */
+ public void onDebugDraw(View view, Canvas canvas) {
+ }
+
+ /**
* Converts the specified size to a readable String.
*
* @param size the size to convert
@@ -5718,6 +5787,22 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
break;
}
}
+
+ /**
+ * @hide
+ */
+ @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);
+ }
}
/* Describes a touched view and the ids of the pointers that it has captured.
diff --git a/core/java/android/widget/GridLayout.java b/core/java/android/widget/GridLayout.java
index 1cb676f..e17e048 100644
--- a/core/java/android/widget/GridLayout.java
+++ b/core/java/android/widget/GridLayout.java
@@ -30,8 +30,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
-import com.android.internal.R;
import android.widget.RemoteViews.RemoteView;
+import com.android.internal.R;
import java.lang.reflect.Array;
import java.util.ArrayList;
@@ -209,7 +209,6 @@ public class GridLayout extends ViewGroup {
// Misc constants
static final String TAG = GridLayout.class.getName();
- static final boolean DEBUG = false;
static final int MAX_SIZE = 100000;
static final int DEFAULT_CONTAINER_MARGIN = 0;
static final int UNINITIALIZED_HASH = 0;
@@ -249,9 +248,6 @@ public class GridLayout extends ViewGroup {
*/
public GridLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- if (DEBUG) {
- setWillNotDraw(false);
- }
defaultGap = context.getResources().getDimensionPixelOffset(R.dimen.default_gap);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridLayout);
try {
@@ -772,56 +768,53 @@ public class GridLayout extends ViewGroup {
}
}
- private static void drawRect(Canvas canvas, int x1, int y1, int x2, int y2, Paint paint) {
- canvas.drawRect(x1, y1, x2 - 1, y2 - 1, paint);
+ /**
+ * @hide
+ */
+ @Override
+ protected void onDebugDrawMargins(Canvas canvas) {
+ // Apply defaults, so as to remove UNDEFINED values
+ LayoutParams lp = new LayoutParams();
+ for (int i = 0; i < getChildCount(); i++) {
+ View c = getChildAt(i);
+ lp.setMargins(
+ getMargin1(c, true, true),
+ getMargin1(c, false, true),
+ getMargin1(c, true, false),
+ getMargin1(c, false, false));
+ lp.onDebugDraw(c, canvas);
+ }
}
+ /**
+ * @hide
+ */
@Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
-
- if (DEBUG) {
- int height = getHeight() - getPaddingTop() - getPaddingBottom();
- int width = getWidth() - getPaddingLeft() - getPaddingRight();
-
- Paint paint = new Paint();
- paint.setStyle(Paint.Style.STROKE);
- paint.setColor(Color.argb(50, 255, 255, 255));
-
- int[] xs = horizontalAxis.locations;
- if (xs != null) {
- for (int i = 0, length = xs.length; i < length; i++) {
- int x = xs[i];
- drawLine(canvas, x, 0, x, height - 1, paint);
- }
- }
+ protected void onDebugDraw(Canvas canvas) {
+ int height = getHeight() - getPaddingTop() - getPaddingBottom();
+ int width = getWidth() - getPaddingLeft() - getPaddingRight();
- int[] ys = verticalAxis.locations;
- if (ys != null) {
- for (int i = 0, length = ys.length; i < length; i++) {
- int y = ys[i];
- drawLine(canvas, 0, y, width - 1, y, paint);
- }
- }
+ Paint paint = new Paint();
+ paint.setStyle(Paint.Style.STROKE);
+ paint.setColor(Color.argb(50, 255, 255, 255));
- // 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);
+ int[] xs = horizontalAxis.locations;
+ if (xs != null) {
+ for (int i = 0, length = xs.length; i < length; i++) {
+ int x = xs[i];
+ drawLine(canvas, x, 0, x, height - 1, paint);
}
+ }
- // Draw margins
- paint.setColor(Color.MAGENTA);
- for (int i = 0; i < getChildCount(); i++) {
- View c = getChildAt(i);
- drawRect(canvas,
- c.getLeft() - getMargin1(c, true, true),
- c.getTop() - getMargin1(c, false, true),
- c.getRight() + getMargin1(c, true, false),
- c.getBottom() + getMargin1(c, false, false), paint);
+ int[] ys = verticalAxis.locations;
+ if (ys != null) {
+ for (int i = 0, length = ys.length; i < length; i++) {
+ int y = ys[i];
+ drawLine(canvas, 0, y, width - 1, y, paint);
}
}
+
+ super.onDebugDraw(canvas);
}
// Add/remove