From 658db3c23fabfa686898a0424531d9219d8c3c00 Mon Sep 17 00:00:00 2001 From: George Mount Date: Fri, 20 Dec 2019 07:17:49 -0800 Subject: [PATCH] Add public access to debug layout bounds flag. Jetpack compose UI wants to respond to the developer setting that shows the layout bounds of Views to show layout bounds of it sub-elements. This API gives access to that value. Bug: 146676765 Test: New CTS test Change-Id: I1c45f9e6f0ab1192f231ad34df88e392214fa061 --- api/current.txt | 1 + api/test-current.txt | 1 + core/java/android/view/View.java | 25 +++++++++++++++++++++---- core/java/android/view/ViewGroup.java | 4 ++-- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/api/current.txt b/api/current.txt index 00f06ec3545d1..6f5226a4f5f5a 100644 --- a/api/current.txt +++ b/api/current.txt @@ -51295,6 +51295,7 @@ package android.view { method public boolean isScrollContainer(); method public boolean isScrollbarFadingEnabled(); method @android.view.ViewDebug.ExportedProperty public boolean isSelected(); + method public final boolean isShowingLayoutBounds(); method public boolean isShown(); method @android.view.ViewDebug.ExportedProperty public boolean isSoundEffectsEnabled(); method public final boolean isTemporarilyDetached(); diff --git a/api/test-current.txt b/api/test-current.txt index efb85387a7435..51b87c1ea097f 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -4395,6 +4395,7 @@ package android.view { method public void setAutofilled(boolean); method public final void setFocusedInCluster(); method public void setIsRootNamespace(boolean); + method public final void setShowingLayoutBounds(boolean); } public class ViewConfiguration { diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 9d4f387895bbd..4e12db6c947e3 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -6161,10 +6161,27 @@ public class View implements Drawable.Callback, KeyEvent.Callback, mRenderNode = RenderNode.create(getClass().getName(), new ViewAnimationHostBridge(this)); } - final boolean debugDraw() { + /** + * Returns {@code true} when the View is attached and the system developer setting to show + * the layout bounds is enabled or {@code false} otherwise. + */ + public final boolean isShowingLayoutBounds() { return DEBUG_DRAW || mAttachInfo != null && mAttachInfo.mDebugLayout; } + /** + * Used to test isShowingLayoutBounds(). This sets the local value used + * by that function. This method does nothing if the layout isn't attached. + * + * @hide + */ + @TestApi + public final void setShowingLayoutBounds(boolean debugLayout) { + if (mAttachInfo != null) { + mAttachInfo.mDebugLayout = debugLayout; + } + } + private static SparseArray getAttributeMap() { if (mAttributeMap == null) { mAttributeMap = new SparseArray<>(); @@ -20861,7 +20878,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (mOverlay != null && !mOverlay.isEmpty()) { mOverlay.getOverlayView().draw(canvas); } - if (debugDraw()) { + if (isShowingLayoutBounds()) { debugDrawFocus(canvas); } } else { @@ -22006,7 +22023,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // Step 7, draw the default focus highlight drawDefaultFocusHighlight(canvas); - if (debugDraw()) { + if (isShowingLayoutBounds()) { debugDrawFocus(canvas); } @@ -22181,7 +22198,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // Step 6, draw decorations (foreground, scrollbars) onDrawForeground(canvas); - if (debugDraw()) { + if (isShowingLayoutBounds()) { debugDrawFocus(canvas); } } diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index 853a302269825..0db0814c0593b 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -680,7 +680,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager private void initViewGroup() { // ViewGroup doesn't draw by default - if (!debugDraw()) { + if (!isShowingLayoutBounds()) { setFlags(WILL_NOT_DRAW, DRAW_MASK); } mGroupFlags |= FLAG_CLIP_CHILDREN; @@ -4155,7 +4155,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } if (usingRenderNodeProperties) canvas.insertInorderBarrier(); - if (debugDraw()) { + if (isShowingLayoutBounds()) { onDebugDraw(canvas); }