From 4362443cd9a5df6c5cc012881a0aaf96c927b923 Mon Sep 17 00:00:00 2001 From: Diego Perez Date: Tue, 2 Jun 2015 17:09:45 +0100 Subject: [PATCH] Render to measured size when using expand mode When using RenderingMode.V_SCROLL or RenderingMode.H_SCROLL, if the screen size is smaller than the measured size but as large as the desired size, the layout will render incorrectly and won't expand. This changes that to expand to at least the size of the screen. Added tests for the V_SCROLL and H_SCROLL modes. Bug: http://b.android.com/174928 Change-Id: I22686903560775e2e4f362af1d7b50c9b985467d --- .../bridge/impl/RenderSessionImpl.java | 10 +++ .../test/myapplication/R$layout.class | Bin 519 -> 598 bytes .../golden/expand_horz_layout.png | Bin 0 -> 636 bytes .../golden/expand_vert_layout.png | Bin 0 -> 578 bytes .../main/res/layout/expand_horz_layout.xml | 15 ++++ .../src/main/res/layout/expand_layout.xml | 29 +++++++ .../main/res/layout/expand_vert_layout.xml | 15 ++++ .../layoutlib/bridge/intensive/Main.java | 73 +++++++++++++++--- 8 files changed, 131 insertions(+), 11 deletions(-) create mode 100644 tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/expand_horz_layout.png create mode 100644 tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/expand_vert_layout.png create mode 100644 tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/expand_horz_layout.xml create mode 100644 tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/expand_layout.xml create mode 100644 tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/expand_vert_layout.xml 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 f6e5ef18a3837..5ded389c7ffe1 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 @@ -523,6 +523,11 @@ public class RenderSessionImpl extends RenderAction { if (neededWidth > measuredWidth) { mMeasuredScreenWidth += neededWidth - measuredWidth; } + if (mMeasuredScreenWidth < measuredWidth) { + // If the screen width is less than the exact measured width, + // expand to match. + mMeasuredScreenWidth = measuredWidth; + } } if (renderingMode.isVertExpand()) { @@ -531,6 +536,11 @@ public class RenderSessionImpl extends RenderAction { if (neededHeight > measuredHeight) { mMeasuredScreenHeight += neededHeight - measuredHeight; } + if (mMeasuredScreenHeight < measuredHeight) { + // If the screen height is less than the exact measured height, + // expand to match. + mMeasuredScreenHeight = measuredHeight; + } } } } diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$layout.class b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/build/intermediates/classes/debug/com/android/layoutlib/test/myapplication/R$layout.class index 36e2688c106f6eb05a2f7a06d6e87231dcb38da8..14997511584bd61067f1e2e030c103ed18b4ee8e 100644 GIT binary patch delta 229 zcmZo?xyB-T>ff$?3=9lL4DwtI%nVZO3^MEtvJ*uuta(!_3KH{D;&T!!^Gi#Z>zNst z7#W11f@P^iB}g*Nj0|iDbu1Gj7qSU32(mNCO=7HNWSv~cXjmc1z{9}G08|IGjERAl zL6U(FiO&y|VPpX60g^&M75ZR40|Tqpb_T|cU@gKxk_{-#z~I6l0wj6BY*q$Q263>w U1ela$5ChU&KshD`X`mI70H3`efdBvi delta 151 zcmcb{(#|4!>ff$?3=9lL4ANW-%nV}e3=-@Nk`qNOc-V3hEAvZBnCqDtm?m~CWaDAr zWoM9@tj}1>$UJ#1qhSOi10w@a5J>U?4bTVDj6j-IYdZtuMj(TUfgeb+fdyR{1b}QF chyn&d24S$g2$&RQ5CYO%KshD`aUd-T0ERaaq5uE@ diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/expand_horz_layout.png b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/expand_horz_layout.png new file mode 100644 index 0000000000000000000000000000000000000000..92eb3e10148b3882c11b5dbfbb27e8f490a7e91f GIT binary patch literal 636 zcmeAS@N?(olHy`uVBq!ia0vp^zkpbUgAGV7xS^iJz`*3}>EaktaqI1!y;(|u5)BVO zve!F^XdiUi!{qo@Y>v~0O~vM6W_gNXi`)crj~pv=5ZKnSRe|}S(*}>Zzdv~GJ7f7^ z)5&*Yma|j8pOCIR`GJ*xaXWi@&vm z*nj`X=W}7-B}%sKIPCnv>Rj3O?|<(*+vjdq>Ps$-uW?^fXH&namivjNht9eGIbUDC z-nLx$LL*n3(IY-qnWR={{;(D|&rz#NFTvM<4z9{h&1F zOUfmH)+zkgC1&dfb#fmtU?jo9owW*Qz|R?3&5NGm>Radi?9{k@Cf7VC;E-)y6J?J{RNN2kD&9`O8vPHO9BiCQQlw(%< zD&nlqHLdBVfBl?%@=5ipSIRSeHpM$Ew|`r;K5y18dHtzgR+FngZ~uR^Ub>p4L!gAGV(zxcP0fq{wB)5S5Q;?~>S_E}7hBF8^| z5+QxkhB;rDNV2H&*ms?r>7-Y~QfiLr|#Wsaa<56P9^TQtyjp9y*m~ z=Hv52%U5wbOjyr?)frHST}qOB&s4cr2rWT$oZ_}vaq-0yoR{8zUwZkahuY-MMagSbk4-t9I@53Y#jY2pGGYvWS$k$}oRPL! zv-_x%*V0SRmlhp-;pL+?S-*7c%a})}L)L~JjnaNw7X9hxp3kSwJpX)t@}(CM-_LFT z-t(&T@vD83{m1=gcr8_W{WYp;Z`_otS)y0xMJn;(*}d5tDnm{r-UW|=d<)B literal 0 HcmV?d00001 diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/expand_horz_layout.xml b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/expand_horz_layout.xml new file mode 100644 index 0000000000000..2c66b7fa35966 --- /dev/null +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/expand_horz_layout.xml @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/expand_layout.xml b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/expand_layout.xml new file mode 100644 index 0000000000000..a255da7bcbcfc --- /dev/null +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/expand_layout.xml @@ -0,0 +1,29 @@ + + + + + + + + + diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/expand_vert_layout.xml b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/expand_vert_layout.xml new file mode 100644 index 0000000000000..5319654ed6594 --- /dev/null +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/expand_vert_layout.xml @@ -0,0 +1,15 @@ + + + + + + + + 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 f2a039ebcd6eb..6fcd645c15b02 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 @@ -32,6 +32,8 @@ import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.intensive.setup.ConfigGenerator; import com.android.layoutlib.bridge.intensive.setup.LayoutLibTestCallback; import com.android.layoutlib.bridge.intensive.setup.LayoutPullParser; +import com.android.resources.Density; +import com.android.resources.Navigation; import com.android.utils.ILogger; import org.junit.Before; @@ -288,20 +290,50 @@ public class Main { renderAndVerify("allwidgets.xml", "allwidgets.png"); } + /** Test expand_layout.xml */ + @Test + public void testExpand() throws ClassNotFoundException { + // Create the layout pull parser. + LayoutPullParser parser = new LayoutPullParser(APP_TEST_RES + "/layout/" + + "expand_vert_layout.xml"); + // Create LayoutLibCallback. + LayoutLibTestCallback layoutLibCallback = new LayoutLibTestCallback(getLogger()); + layoutLibCallback.initResources(); + + ConfigGenerator customConfigGenerator = new ConfigGenerator() + .setScreenWidth(300) + .setScreenHeight(20) + .setDensity(Density.XHIGH) + .setNavigation(Navigation.NONAV); + + SessionParams params = getSessionParams(parser, customConfigGenerator, + layoutLibCallback, "Theme.Material.NoActionBar.Fullscreen", RenderingMode.V_SCROLL, + 22); + + renderAndVerify(params, "expand_vert_layout.png"); + + customConfigGenerator = new ConfigGenerator() + .setScreenWidth(20) + .setScreenHeight(300) + .setDensity(Density.XHIGH) + .setNavigation(Navigation.NONAV); + parser = new LayoutPullParser(APP_TEST_RES + "/layout/" + + "expand_horz_layout.xml"); + params = getSessionParams(parser, customConfigGenerator, + layoutLibCallback, "Theme.Material.NoActionBar.Fullscreen", RenderingMode + .H_SCROLL, 22); + + renderAndVerify(params, "expand_horz_layout.png"); + } + /** * Create a new rendering session and test that rendering given layout on nexus 5 * doesn't throw any exceptions and matches the provided image. */ - private void renderAndVerify(String layoutFileName, String goldenFileName) + private void renderAndVerify(SessionParams params, String goldenFileName) throws ClassNotFoundException { - // Create the layout pull parser. - LayoutPullParser parser = new LayoutPullParser(APP_TEST_RES + "/layout/" + layoutFileName); - // Create LayoutLibCallback. - LayoutLibTestCallback layoutLibCallback = new LayoutLibTestCallback(getLogger()); - layoutLibCallback.initResources(); // TODO: Set up action bar handler properly to test menu rendering. // Create session params. - SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_5, layoutLibCallback); RenderSession session = mBridge.createSession(params); if (!session.getResult().isSuccess()) { getLogger().error(session.getResult().getException(), @@ -321,26 +353,45 @@ public class Main { } } + /** + * Create a new rendering session and test that rendering given layout on nexus 5 + * doesn't throw any exceptions and matches the provided image. + */ + private void renderAndVerify(String layoutFileName, String goldenFileName) + throws ClassNotFoundException { + // Create the layout pull parser. + LayoutPullParser parser = new LayoutPullParser(APP_TEST_RES + "/layout/" + layoutFileName); + // Create LayoutLibCallback. + LayoutLibTestCallback layoutLibCallback = new LayoutLibTestCallback(getLogger()); + layoutLibCallback.initResources(); + // TODO: Set up action bar handler properly to test menu rendering. + // Create session params. + SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_5, + layoutLibCallback, "Theme.Material.Light.DarkActionBar", RenderingMode.NORMAL, 22); + renderAndVerify(params, goldenFileName); + } + /** * Uses Theme.Material and Target sdk version as 22. */ private SessionParams getSessionParams(LayoutPullParser layoutParser, - ConfigGenerator configGenerator, LayoutLibTestCallback layoutLibCallback) { + ConfigGenerator configGenerator, LayoutLibTestCallback layoutLibCallback, + String themeName, RenderingMode renderingMode, int targetSdk) { FolderConfiguration config = configGenerator.getFolderConfig(); ResourceResolver resourceResolver = ResourceResolver.create(mProjectResources.getConfiguredResources(config), mFrameworkRepo.getConfiguredResources(config), - "Theme.Material.Light.DarkActionBar", false); + themeName, false); return new SessionParams( layoutParser, - RenderingMode.NORMAL, + renderingMode, null /*used for caching*/, configGenerator.getHardwareConfig(), resourceResolver, layoutLibCallback, 0, - 22, // TODO: Make it more configurable to run tests for various versions. + targetSdk, getLayoutLog()); }