Skip to content

Commit 112d8a3

Browse files
diegoplAndroid Git Automerger
authored andcommitted
am d6f2a9e: am 7720eb1: Merge "Render to measured size when using expand mode" into lmp-mr1-dev
* commit 'd6f2a9efbb0e0525f6cf970fd9c9b9b7082b19f9': Render to measured size when using expand mode
2 parents 8691749 + d6f2a9e commit 112d8a3

8 files changed

Lines changed: 131 additions & 11 deletions

File tree

tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@ public Result render(boolean freshRender) {
523523
if (neededWidth > measuredWidth) {
524524
mMeasuredScreenWidth += neededWidth - measuredWidth;
525525
}
526+
if (mMeasuredScreenWidth < measuredWidth) {
527+
// If the screen width is less than the exact measured width,
528+
// expand to match.
529+
mMeasuredScreenWidth = measuredWidth;
530+
}
526531
}
527532

528533
if (renderingMode.isVertExpand()) {
@@ -531,6 +536,11 @@ public Result render(boolean freshRender) {
531536
if (neededHeight > measuredHeight) {
532537
mMeasuredScreenHeight += neededHeight - measuredHeight;
533538
}
539+
if (mMeasuredScreenHeight < measuredHeight) {
540+
// If the screen height is less than the exact measured height,
541+
// expand to match.
542+
mMeasuredScreenHeight = measuredHeight;
543+
}
534544
}
535545
}
536546
}
636 Bytes
Loading
578 Bytes
Loading
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:padding="16dp"
5+
android:orientation="horizontal"
6+
android:background="#AAAAAA"
7+
android:layout_width="wrap_content"
8+
android:layout_height="wrap_content">
9+
10+
<include layout="@layout/expand_layout"
11+
android:layout_height="wrap_content"
12+
android:layout_width="wrap_content" />
13+
14+
</LinearLayout>
15+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<merge xmlns:android="http://schemas.android.com/apk/res/android">
4+
<TextView
5+
android:background="#FF0000"
6+
android:textSize="200sp"
7+
android:layout_width="200dp"
8+
android:layout_height="200dp" />
9+
<TextView
10+
android:background="#00FF00"
11+
android:textSize="200sp"
12+
android:layout_width="200dp"
13+
android:layout_height="200dp" />
14+
<TextView
15+
android:background="#0000FF"
16+
android:textSize="200sp"
17+
android:layout_width="200dp"
18+
android:layout_height="200dp" />
19+
<TextView
20+
android:background="#FF00FF"
21+
android:textSize="200sp"
22+
android:layout_width="200dp"
23+
android:layout_height="200dp" />
24+
<TextView
25+
android:background="#00FFFF"
26+
android:textSize="200sp"
27+
android:layout_width="200dp"
28+
android:layout_height="200dp" />
29+
</merge>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:padding="16dp"
5+
android:orientation="vertical"
6+
android:background="#AAAAAA"
7+
android:layout_width="wrap_content"
8+
android:layout_height="wrap_content">
9+
10+
<include layout="@layout/expand_layout"
11+
android:layout_height="wrap_content"
12+
android:layout_width="wrap_content" />
13+
14+
</LinearLayout>
15+

tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import com.android.layoutlib.bridge.intensive.setup.ConfigGenerator;
3333
import com.android.layoutlib.bridge.intensive.setup.LayoutLibTestCallback;
3434
import com.android.layoutlib.bridge.intensive.setup.LayoutPullParser;
35+
import com.android.resources.Density;
36+
import com.android.resources.Navigation;
3537
import com.android.utils.ILogger;
3638

3739
import org.junit.Before;
@@ -288,20 +290,50 @@ public void testAllWidgets() throws ClassNotFoundException {
288290
renderAndVerify("allwidgets.xml", "allwidgets.png");
289291
}
290292

293+
/** Test expand_layout.xml */
294+
@Test
295+
public void testExpand() throws ClassNotFoundException {
296+
// Create the layout pull parser.
297+
LayoutPullParser parser = new LayoutPullParser(APP_TEST_RES + "/layout/" +
298+
"expand_vert_layout.xml");
299+
// Create LayoutLibCallback.
300+
LayoutLibTestCallback layoutLibCallback = new LayoutLibTestCallback(getLogger());
301+
layoutLibCallback.initResources();
302+
303+
ConfigGenerator customConfigGenerator = new ConfigGenerator()
304+
.setScreenWidth(300)
305+
.setScreenHeight(20)
306+
.setDensity(Density.XHIGH)
307+
.setNavigation(Navigation.NONAV);
308+
309+
SessionParams params = getSessionParams(parser, customConfigGenerator,
310+
layoutLibCallback, "Theme.Material.NoActionBar.Fullscreen", RenderingMode.V_SCROLL,
311+
22);
312+
313+
renderAndVerify(params, "expand_vert_layout.png");
314+
315+
customConfigGenerator = new ConfigGenerator()
316+
.setScreenWidth(20)
317+
.setScreenHeight(300)
318+
.setDensity(Density.XHIGH)
319+
.setNavigation(Navigation.NONAV);
320+
parser = new LayoutPullParser(APP_TEST_RES + "/layout/" +
321+
"expand_horz_layout.xml");
322+
params = getSessionParams(parser, customConfigGenerator,
323+
layoutLibCallback, "Theme.Material.NoActionBar.Fullscreen", RenderingMode
324+
.H_SCROLL, 22);
325+
326+
renderAndVerify(params, "expand_horz_layout.png");
327+
}
328+
291329
/**
292330
* Create a new rendering session and test that rendering given layout on nexus 5
293331
* doesn't throw any exceptions and matches the provided image.
294332
*/
295-
private void renderAndVerify(String layoutFileName, String goldenFileName)
333+
private void renderAndVerify(SessionParams params, String goldenFileName)
296334
throws ClassNotFoundException {
297-
// Create the layout pull parser.
298-
LayoutPullParser parser = new LayoutPullParser(APP_TEST_RES + "/layout/" + layoutFileName);
299-
// Create LayoutLibCallback.
300-
LayoutLibTestCallback layoutLibCallback = new LayoutLibTestCallback(getLogger());
301-
layoutLibCallback.initResources();
302335
// TODO: Set up action bar handler properly to test menu rendering.
303336
// Create session params.
304-
SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_5, layoutLibCallback);
305337
RenderSession session = mBridge.createSession(params);
306338
if (!session.getResult().isSuccess()) {
307339
getLogger().error(session.getResult().getException(),
@@ -321,26 +353,45 @@ private void renderAndVerify(String layoutFileName, String goldenFileName)
321353
}
322354
}
323355

356+
/**
357+
* Create a new rendering session and test that rendering given layout on nexus 5
358+
* doesn't throw any exceptions and matches the provided image.
359+
*/
360+
private void renderAndVerify(String layoutFileName, String goldenFileName)
361+
throws ClassNotFoundException {
362+
// Create the layout pull parser.
363+
LayoutPullParser parser = new LayoutPullParser(APP_TEST_RES + "/layout/" + layoutFileName);
364+
// Create LayoutLibCallback.
365+
LayoutLibTestCallback layoutLibCallback = new LayoutLibTestCallback(getLogger());
366+
layoutLibCallback.initResources();
367+
// TODO: Set up action bar handler properly to test menu rendering.
368+
// Create session params.
369+
SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_5,
370+
layoutLibCallback, "Theme.Material.Light.DarkActionBar", RenderingMode.NORMAL, 22);
371+
renderAndVerify(params, goldenFileName);
372+
}
373+
324374
/**
325375
* Uses Theme.Material and Target sdk version as 22.
326376
*/
327377
private SessionParams getSessionParams(LayoutPullParser layoutParser,
328-
ConfigGenerator configGenerator, LayoutLibTestCallback layoutLibCallback) {
378+
ConfigGenerator configGenerator, LayoutLibTestCallback layoutLibCallback,
379+
String themeName, RenderingMode renderingMode, int targetSdk) {
329380
FolderConfiguration config = configGenerator.getFolderConfig();
330381
ResourceResolver resourceResolver =
331382
ResourceResolver.create(mProjectResources.getConfiguredResources(config),
332383
mFrameworkRepo.getConfiguredResources(config),
333-
"Theme.Material.Light.DarkActionBar", false);
384+
themeName, false);
334385

335386
return new SessionParams(
336387
layoutParser,
337-
RenderingMode.NORMAL,
388+
renderingMode,
338389
null /*used for caching*/,
339390
configGenerator.getHardwareConfig(),
340391
resourceResolver,
341392
layoutLibCallback,
342393
0,
343-
22, // TODO: Make it more configurable to run tests for various versions.
394+
targetSdk,
344395
getLayoutLog());
345396
}
346397

0 commit comments

Comments
 (0)