diff options
author | Diego Perez <diegoperez@google.com> | 2016-11-21 15:10:34 +0000 |
---|---|---|
committer | Diego Perez <diegoperez@google.com> | 2016-11-21 15:10:34 +0000 |
commit | 2d657bc344717281e470430b05adaa32fbd0af00 (patch) | |
tree | 12e92c00647a7502dfd3e772b407a71d4dc424e8 | |
parent | b29ce49c6ffbf3215a4ba3b0d97277825d285a5e (diff) | |
download | base-studio-master-dev.tar.gz |
Call layout when doing an only-measure passstudio-3.1.2studio-2.3gradle_3.1.2gradle_2.3.0studio-master-dev
Test: Modified testScrolled to check the only-measure behaviour
Change-Id: Ie86c329e0f7d9135d53274977e24f431f5edc201
-rw-r--r-- | tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java | 20 | ||||
-rw-r--r-- | tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java | 21 |
2 files changed, 33 insertions, 8 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java index c31bc11889a6..6f26d09ff6d2 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java @@ -370,13 +370,10 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { } /** - * Renders the given view hierarchy to the passed canvas and returns the result of the render - * operation. - * @param canvas an optional canvas to render the views to. If null, only the measure and - * layout steps will be executed. + * Runs a layout pass for the given view root */ - private static Result renderAndBuildResult(@NonNull BridgeContext context, @NonNull ViewGroup viewRoot, - @Nullable Canvas canvas, int width, int height) { + private static void doLayout(@NonNull BridgeContext context, @NonNull ViewGroup viewRoot, + int width, int height) { // measure again with the size we need // This must always be done before the call to layout measureView(viewRoot, null /*measuredView*/, @@ -386,7 +383,16 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { // now do the layout. viewRoot.layout(0, 0, width, height); handleScrolling(context, viewRoot); + } + /** + * Renders the given view hierarchy to the passed canvas and returns the result of the render + * operation. + * @param canvas an optional canvas to render the views to. If null, only the measure and + * layout steps will be executed. + */ + private static Result renderAndBuildResult(@NonNull BridgeContext context, @NonNull ViewGroup viewRoot, + @Nullable Canvas canvas, int width, int height) { if (canvas == null) { return SUCCESS.createResult(); } @@ -464,6 +470,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { // delete the canvas and image to reset them on the next full rendering mImage = null; mCanvas = null; + doLayout(getContext(), mViewRoot, mMeasuredScreenWidth, mMeasuredScreenHeight); } else { // draw the views // create the BufferedImage into which the layout will be rendered. @@ -524,6 +531,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { gc.dispose(); } + doLayout(getContext(), mViewRoot, mMeasuredScreenWidth, mMeasuredScreenHeight); if (mElapsedFrameTimeNanos >= 0) { long initialTime = System_Delegate.nanoTime(); if (!mFirstFrameExecuted) { diff --git a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java index 3850b3a253a0..2531eb800377 100644 --- a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java +++ b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java @@ -529,7 +529,7 @@ public class Main { /** Test activity.xml */ @Test - public void testScrolling() throws ClassNotFoundException { + public void testScrollingAndMeasure() throws ClassNotFoundException { // Create the layout pull parser. LayoutPullParser parser = createLayoutPullParser("scrolled.xml"); // Create LayoutLibCallback. @@ -543,7 +543,10 @@ public class Main { params.setForceNoDecor(); params.setExtendedViewInfoMode(true); - RenderResult result = renderAndVerify(params, "scrolled.png"); + // Do an only-measure pass + RenderSession session = sBridge.createSession(params); + session.measure(); + RenderResult result = RenderResult.getFromSession(session); assertNotNull(result); assertNotNull(result.getResult()); assertTrue(result.getResult().isSuccess()); @@ -560,6 +563,20 @@ public class Main { assertEquals(90, rootLayout.getChildren().get(5).getChildren().get(0).getLeft()); assertEquals(-270, rootLayout.getChildren().get(5).getChildren().get(0).getBottom()); assertEquals(690, rootLayout.getChildren().get(5).getChildren().get(0).getRight()); + + // Do a full render pass + parser = createLayoutPullParser("scrolled.xml"); + + params = getSessionParams(parser, ConfigGenerator.NEXUS_5, + layoutLibCallback, "Theme.Material.NoActionBar.Fullscreen", false, + RenderingMode.V_SCROLL, 22); + params.setForceNoDecor(); + params.setExtendedViewInfoMode(true); + + result = renderAndVerify(params, "scrolled.png"); + assertNotNull(result); + assertNotNull(result.getResult()); + assertTrue(result.getResult().isSuccess()); } @Test |