* commit 'c273c178d70eda9858714d59118b05da7ffb5313': Render to measured size when using expand mode
This commit is contained in:
@@ -526,6 +526,11 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
if (neededWidth > measuredWidth) {
|
if (neededWidth > measuredWidth) {
|
||||||
mMeasuredScreenWidth += 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()) {
|
if (renderingMode.isVertExpand()) {
|
||||||
@@ -534,6 +539,11 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
|
|||||||
if (neededHeight > measuredHeight) {
|
if (neededHeight > measuredHeight) {
|
||||||
mMeasuredScreenHeight += neededHeight - measuredHeight;
|
mMeasuredScreenHeight += neededHeight - measuredHeight;
|
||||||
}
|
}
|
||||||
|
if (mMeasuredScreenHeight < measuredHeight) {
|
||||||
|
// If the screen height is less than the exact measured height,
|
||||||
|
// expand to match.
|
||||||
|
mMeasuredScreenHeight = measuredHeight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 636 B |
Binary file not shown.
|
After Width: | Height: | Size: 578 B |
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:background="#AAAAAA"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<include layout="@layout/expand_layout"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="wrap_content" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<TextView
|
||||||
|
android:background="#FF0000"
|
||||||
|
android:textSize="200sp"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="200dp" />
|
||||||
|
<TextView
|
||||||
|
android:background="#00FF00"
|
||||||
|
android:textSize="200sp"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="200dp" />
|
||||||
|
<TextView
|
||||||
|
android:background="#0000FF"
|
||||||
|
android:textSize="200sp"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="200dp" />
|
||||||
|
<TextView
|
||||||
|
android:background="#FF00FF"
|
||||||
|
android:textSize="200sp"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="200dp" />
|
||||||
|
<TextView
|
||||||
|
android:background="#00FFFF"
|
||||||
|
android:textSize="200sp"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="200dp" />
|
||||||
|
</merge>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:background="#AAAAAA"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<include layout="@layout/expand_layout"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="wrap_content" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
@@ -31,6 +31,8 @@ import com.android.layoutlib.bridge.Bridge;
|
|||||||
import com.android.layoutlib.bridge.intensive.setup.ConfigGenerator;
|
import com.android.layoutlib.bridge.intensive.setup.ConfigGenerator;
|
||||||
import com.android.layoutlib.bridge.intensive.setup.LayoutLibTestCallback;
|
import com.android.layoutlib.bridge.intensive.setup.LayoutLibTestCallback;
|
||||||
import com.android.layoutlib.bridge.intensive.setup.LayoutPullParser;
|
import com.android.layoutlib.bridge.intensive.setup.LayoutPullParser;
|
||||||
|
import com.android.resources.Density;
|
||||||
|
import com.android.resources.Navigation;
|
||||||
import com.android.utils.ILogger;
|
import com.android.utils.ILogger;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
@@ -310,21 +312,52 @@ public class Main {
|
|||||||
sBridge = null;
|
sBridge = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 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
|
* Create a new rendering session and test that rendering given layout on nexus 5
|
||||||
* doesn't throw any exceptions and matches the provided image.
|
* 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 {
|
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.
|
// TODO: Set up action bar handler properly to test menu rendering.
|
||||||
// Create session params.
|
// Create session params.
|
||||||
SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_5, layoutLibCallback);
|
|
||||||
RenderSession session = sBridge.createSession(params);
|
RenderSession session = sBridge.createSession(params);
|
||||||
|
|
||||||
if (!session.getResult().isSuccess()) {
|
if (!session.getResult().isSuccess()) {
|
||||||
getLogger().error(session.getResult().getException(),
|
getLogger().error(session.getResult().getException(),
|
||||||
session.getResult().getErrorMessage());
|
session.getResult().getErrorMessage());
|
||||||
@@ -343,26 +376,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.
|
* Uses Theme.Material and Target sdk version as 22.
|
||||||
*/
|
*/
|
||||||
private SessionParams getSessionParams(LayoutPullParser layoutParser,
|
private SessionParams getSessionParams(LayoutPullParser layoutParser,
|
||||||
ConfigGenerator configGenerator, LayoutLibTestCallback layoutLibCallback) {
|
ConfigGenerator configGenerator, LayoutLibTestCallback layoutLibCallback,
|
||||||
|
String themeName, RenderingMode renderingMode, int targetSdk) {
|
||||||
FolderConfiguration config = configGenerator.getFolderConfig();
|
FolderConfiguration config = configGenerator.getFolderConfig();
|
||||||
ResourceResolver resourceResolver =
|
ResourceResolver resourceResolver =
|
||||||
ResourceResolver.create(sProjectResources.getConfiguredResources(config),
|
ResourceResolver.create(sProjectResources.getConfiguredResources(config),
|
||||||
sFrameworkRepo.getConfiguredResources(config),
|
sFrameworkRepo.getConfiguredResources(config),
|
||||||
"AppTheme", true);
|
themeName, true);
|
||||||
|
|
||||||
return new SessionParams(
|
return new SessionParams(
|
||||||
layoutParser,
|
layoutParser,
|
||||||
RenderingMode.NORMAL,
|
renderingMode,
|
||||||
null /*used for caching*/,
|
null /*used for caching*/,
|
||||||
configGenerator.getHardwareConfig(),
|
configGenerator.getHardwareConfig(),
|
||||||
resourceResolver,
|
resourceResolver,
|
||||||
layoutLibCallback,
|
layoutLibCallback,
|
||||||
0,
|
0,
|
||||||
22, // TODO: Make it more configurable to run tests for various versions.
|
targetSdk,
|
||||||
getLayoutLog());
|
getLayoutLog());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user