Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java +14 −6 Original line number Diff line number Diff line Loading @@ -385,13 +385,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*/, Loading @@ -401,7 +398,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(); } Loading Loading @@ -479,6 +485,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. Loading Loading @@ -539,6 +546,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { gc.dispose(); } doLayout(getContext(), mViewRoot, mMeasuredScreenWidth, mMeasuredScreenHeight); if (mElapsedFrameTimeNanos >= 0) { long initialTime = System_Delegate.nanoTime(); if (!mFirstFrameExecuted) { Loading tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java +19 −2 Original line number Diff line number Diff line Loading @@ -555,7 +555,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. Loading @@ -569,7 +569,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()); Loading @@ -586,6 +589,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 Loading Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java +14 −6 Original line number Diff line number Diff line Loading @@ -385,13 +385,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*/, Loading @@ -401,7 +398,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(); } Loading Loading @@ -479,6 +485,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. Loading Loading @@ -539,6 +546,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { gc.dispose(); } doLayout(getContext(), mViewRoot, mMeasuredScreenWidth, mMeasuredScreenHeight); if (mElapsedFrameTimeNanos >= 0) { long initialTime = System_Delegate.nanoTime(); if (!mFirstFrameExecuted) { Loading
tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java +19 −2 Original line number Diff line number Diff line Loading @@ -555,7 +555,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. Loading @@ -569,7 +569,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()); Loading @@ -586,6 +589,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 Loading