summaryrefslogtreecommitdiffstats
path: root/core/java/android/view
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/view')
-rw-r--r--core/java/android/view/View.java6
-rw-r--r--core/java/android/view/ViewGroup.java87
2 files changed, 92 insertions, 1 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 537c474..393fa65 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -45,6 +45,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;
@@ -16914,6 +16915,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 91e945b..d05d19b 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;
@@ -2584,6 +2592,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}
*/
@@ -2675,6 +2729,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
}
}
+ if (debugDraw()) {
+ onDebugDraw(canvas);
+ }
+
if (clipToPadding) {
canvas.restoreToCount(saveCount);
}
@@ -5393,6 +5451,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
@@ -5642,6 +5711,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.