Loading core/java/android/view/View.java +56 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Insets; import android.graphics.Interpolator; import android.graphics.LinearGradient; Loading Loading @@ -763,6 +764,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, AccessibilityEventSource { private static final boolean DBG = false; /** @hide */ public static boolean DEBUG_DRAW = false; /** * The logging tag used by this class with android.util.Log. */ Loading Loading @@ -1190,6 +1194,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ static final int PARENT_SAVE_DISABLED_MASK = 0x20000000; private static Paint sDebugPaint; /** @hide */ @IntDef(flag = true, value = { Loading Loading @@ -1661,6 +1667,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, | AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED | AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY; static final int DEBUG_CORNERS_COLOR = Color.rgb(63, 127, 255); static final int DEBUG_CORNERS_SIZE_DIP = 8; /** * Temporary Rect currently for use in setBackground(). This will probably * be extended in the future to hold our own class with more than just Loading Loading @@ -4749,6 +4759,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, mRenderNode = RenderNode.create(getClass().getName(), this); } final boolean debugDraw() { return DEBUG_DRAW || mAttachInfo != null && mAttachInfo.mDebugLayout; } private static SparseArray<String> getAttributeMap() { if (mAttributeMap == null) { mAttributeMap = new SparseArray<>(); Loading Loading @@ -16143,6 +16157,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (mOverlay != null && !mOverlay.isEmpty()) { mOverlay.getOverlayView().draw(canvas); } if (debugDraw()) { debugDrawFocus(canvas); } } else { draw(canvas); } Loading Loading @@ -17121,6 +17138,41 @@ public class View implements Drawable.Callback, KeyEvent.Callback, return more; } static Paint getDebugPaint() { if (sDebugPaint == null) { sDebugPaint = new Paint(); sDebugPaint.setAntiAlias(false); } return sDebugPaint; } final int dipsToPixels(int dips) { float scale = getContext().getResources().getDisplayMetrics().density; return (int) (dips * scale + 0.5f); } final private void debugDrawFocus(Canvas canvas) { if (isFocused()) { final int cornerSquareSize = dipsToPixels(DEBUG_CORNERS_SIZE_DIP); final int w = getWidth(); final int h = getHeight(); final Paint paint = getDebugPaint(); paint.setColor(DEBUG_CORNERS_COLOR); // Draw squares in corners. paint.setStyle(Paint.Style.FILL); canvas.drawRect(0, 0, cornerSquareSize, cornerSquareSize, paint); canvas.drawRect(w - cornerSquareSize, 0, w, cornerSquareSize, paint); canvas.drawRect(0, h - cornerSquareSize, cornerSquareSize, h, paint); canvas.drawRect(w - cornerSquareSize, h - cornerSquareSize, w, h, paint); // Draw big X across the view. paint.setStyle(Paint.Style.STROKE); canvas.drawLine(0, 0, getWidth(), getHeight(), paint); canvas.drawLine(0, getHeight(), getWidth(), 0, paint); } } /** * Manually render this view (and all of its children) to the given Canvas. * The view must have already done a full layout before this function is Loading Loading @@ -17175,6 +17227,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // Step 6, draw decorations (foreground, scrollbars) onDrawForeground(canvas); if (debugDraw()) { debugDrawFocus(canvas); } // we're done... return; } core/java/android/view/ViewGroup.java +2 −22 Original line number Diff line number Diff line Loading @@ -116,8 +116,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager private static final String TAG = "ViewGroup"; private static final boolean DBG = false; /** @hide */ public static boolean DEBUG_DRAW = false; /** * Views which have been hidden or removed which need to be animated on Loading Loading @@ -476,7 +474,6 @@ 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 sDebugPaint; private static float[] sDebugLines; // Used to draw cached views Loading Loading @@ -586,10 +583,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager initFromAttributes(context, attrs, defStyleAttr, defStyleRes); } private boolean debugDraw() { return DEBUG_DRAW || mAttachInfo != null && mAttachInfo.mDebugLayout; } private void initViewGroup() { // ViewGroup doesn't draw by default if (!debugDraw()) { Loading Loading @@ -3380,11 +3373,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager fillRect(c, paint, x1, y1, x1 + lw * sign(dx), y1 + dy); } private int dipsToPixels(int dips) { float scale = getContext().getResources().getDisplayMetrics().density; return (int) (dips * scale + 0.5f); } private static void drawRectCorners(Canvas canvas, int x1, int y1, int x2, int y2, Paint paint, int lineLength, int lineWidth) { drawCorner(canvas, paint, x1, y1, lineLength, lineLength, lineWidth); Loading Loading @@ -3453,10 +3441,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager // Draw clip bounds { paint.setColor(Color.rgb(63, 127, 255)); paint.setColor(DEBUG_CORNERS_COLOR); paint.setStyle(Paint.Style.FILL); int lineLength = dipsToPixels(8); int lineLength = dipsToPixels(DEBUG_CORNERS_SIZE_DIP); int lineWidth = dipsToPixels(1); for (int i = 0; i < getChildCount(); i++) { View c = getChildAt(i); Loading Loading @@ -7931,14 +7919,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } } private static Paint getDebugPaint() { if (sDebugPaint == null) { sDebugPaint = new Paint(); sDebugPaint.setAntiAlias(false); } return sDebugPaint; } private static void drawRect(Canvas canvas, Paint paint, int x1, int y1, int x2, int y2) { if (sDebugLines== null) { // TODO: This won't work with multiple UI threads in a single process Loading Loading
core/java/android/view/View.java +56 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Insets; import android.graphics.Interpolator; import android.graphics.LinearGradient; Loading Loading @@ -763,6 +764,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, AccessibilityEventSource { private static final boolean DBG = false; /** @hide */ public static boolean DEBUG_DRAW = false; /** * The logging tag used by this class with android.util.Log. */ Loading Loading @@ -1190,6 +1194,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ static final int PARENT_SAVE_DISABLED_MASK = 0x20000000; private static Paint sDebugPaint; /** @hide */ @IntDef(flag = true, value = { Loading Loading @@ -1661,6 +1667,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, | AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED | AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY; static final int DEBUG_CORNERS_COLOR = Color.rgb(63, 127, 255); static final int DEBUG_CORNERS_SIZE_DIP = 8; /** * Temporary Rect currently for use in setBackground(). This will probably * be extended in the future to hold our own class with more than just Loading Loading @@ -4749,6 +4759,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, mRenderNode = RenderNode.create(getClass().getName(), this); } final boolean debugDraw() { return DEBUG_DRAW || mAttachInfo != null && mAttachInfo.mDebugLayout; } private static SparseArray<String> getAttributeMap() { if (mAttributeMap == null) { mAttributeMap = new SparseArray<>(); Loading Loading @@ -16143,6 +16157,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (mOverlay != null && !mOverlay.isEmpty()) { mOverlay.getOverlayView().draw(canvas); } if (debugDraw()) { debugDrawFocus(canvas); } } else { draw(canvas); } Loading Loading @@ -17121,6 +17138,41 @@ public class View implements Drawable.Callback, KeyEvent.Callback, return more; } static Paint getDebugPaint() { if (sDebugPaint == null) { sDebugPaint = new Paint(); sDebugPaint.setAntiAlias(false); } return sDebugPaint; } final int dipsToPixels(int dips) { float scale = getContext().getResources().getDisplayMetrics().density; return (int) (dips * scale + 0.5f); } final private void debugDrawFocus(Canvas canvas) { if (isFocused()) { final int cornerSquareSize = dipsToPixels(DEBUG_CORNERS_SIZE_DIP); final int w = getWidth(); final int h = getHeight(); final Paint paint = getDebugPaint(); paint.setColor(DEBUG_CORNERS_COLOR); // Draw squares in corners. paint.setStyle(Paint.Style.FILL); canvas.drawRect(0, 0, cornerSquareSize, cornerSquareSize, paint); canvas.drawRect(w - cornerSquareSize, 0, w, cornerSquareSize, paint); canvas.drawRect(0, h - cornerSquareSize, cornerSquareSize, h, paint); canvas.drawRect(w - cornerSquareSize, h - cornerSquareSize, w, h, paint); // Draw big X across the view. paint.setStyle(Paint.Style.STROKE); canvas.drawLine(0, 0, getWidth(), getHeight(), paint); canvas.drawLine(0, getHeight(), getWidth(), 0, paint); } } /** * Manually render this view (and all of its children) to the given Canvas. * The view must have already done a full layout before this function is Loading Loading @@ -17175,6 +17227,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // Step 6, draw decorations (foreground, scrollbars) onDrawForeground(canvas); if (debugDraw()) { debugDrawFocus(canvas); } // we're done... return; }
core/java/android/view/ViewGroup.java +2 −22 Original line number Diff line number Diff line Loading @@ -116,8 +116,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager private static final String TAG = "ViewGroup"; private static final boolean DBG = false; /** @hide */ public static boolean DEBUG_DRAW = false; /** * Views which have been hidden or removed which need to be animated on Loading Loading @@ -476,7 +474,6 @@ 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 sDebugPaint; private static float[] sDebugLines; // Used to draw cached views Loading Loading @@ -586,10 +583,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager initFromAttributes(context, attrs, defStyleAttr, defStyleRes); } private boolean debugDraw() { return DEBUG_DRAW || mAttachInfo != null && mAttachInfo.mDebugLayout; } private void initViewGroup() { // ViewGroup doesn't draw by default if (!debugDraw()) { Loading Loading @@ -3380,11 +3373,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager fillRect(c, paint, x1, y1, x1 + lw * sign(dx), y1 + dy); } private int dipsToPixels(int dips) { float scale = getContext().getResources().getDisplayMetrics().density; return (int) (dips * scale + 0.5f); } private static void drawRectCorners(Canvas canvas, int x1, int y1, int x2, int y2, Paint paint, int lineLength, int lineWidth) { drawCorner(canvas, paint, x1, y1, lineLength, lineLength, lineWidth); Loading Loading @@ -3453,10 +3441,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager // Draw clip bounds { paint.setColor(Color.rgb(63, 127, 255)); paint.setColor(DEBUG_CORNERS_COLOR); paint.setStyle(Paint.Style.FILL); int lineLength = dipsToPixels(8); int lineLength = dipsToPixels(DEBUG_CORNERS_SIZE_DIP); int lineWidth = dipsToPixels(1); for (int i = 0; i < getChildCount(); i++) { View c = getChildAt(i); Loading Loading @@ -7931,14 +7919,6 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } } private static Paint getDebugPaint() { if (sDebugPaint == null) { sDebugPaint = new Paint(); sDebugPaint.setAntiAlias(false); } return sDebugPaint; } private static void drawRect(Canvas canvas, Paint paint, int x1, int y1, int x2, int y2) { if (sDebugLines== null) { // TODO: This won't work with multiple UI threads in a single process Loading