diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/Layout.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/Layout.java index 97698df0f22ab..726ff223bd8f2 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/Layout.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/Layout.java @@ -166,13 +166,13 @@ class Layout extends RelativeLayout { FrameLayout contentRoot = new FrameLayout(getContext()); LayoutParams params = createLayoutParams(MATCH_PARENT, MATCH_PARENT); int rule = mBuilder.isNavBarVertical() ? START_OF : ABOVE; - if (mBuilder.hasNavBar() && mBuilder.solidBars()) { + if (mBuilder.hasSolidNavBar()) { params.addRule(rule, getId(ID_NAV_BAR)); } int below = -1; if (mBuilder.mActionBarSize <= 0 && mBuilder.mTitleBarSize > 0) { below = getId(ID_TITLE_BAR); - } else if (mBuilder.hasStatusBar() && mBuilder.solidBars()) { + } else if (mBuilder.hasSolidStatusBar()) { below = getId(ID_STATUS_BAR); } if (below != -1) { @@ -241,10 +241,10 @@ class Layout extends RelativeLayout { } LayoutParams layoutParams = createLayoutParams(MATCH_PARENT, MATCH_PARENT); int rule = mBuilder.isNavBarVertical() ? START_OF : ABOVE; - if (mBuilder.hasNavBar() && mBuilder.solidBars()) { + if (mBuilder.hasSolidNavBar()) { layoutParams.addRule(rule, getId(ID_NAV_BAR)); } - if (mBuilder.hasStatusBar() && mBuilder.solidBars()) { + if (mBuilder.hasSolidStatusBar()) { layoutParams.addRule(BELOW, getId(ID_STATUS_BAR)); } actionBar.getRootView().setLayoutParams(layoutParams); @@ -257,10 +257,10 @@ class Layout extends RelativeLayout { int simulatedPlatformVersion) { TitleBar titleBar = new TitleBar(context, title, simulatedPlatformVersion); LayoutParams params = createLayoutParams(MATCH_PARENT, mBuilder.mTitleBarSize); - if (mBuilder.hasStatusBar() && mBuilder.solidBars()) { + if (mBuilder.hasSolidStatusBar()) { params.addRule(BELOW, getId(ID_STATUS_BAR)); } - if (mBuilder.isNavBarVertical() && mBuilder.solidBars()) { + if (mBuilder.isNavBarVertical() && mBuilder.hasSolidNavBar()) { params.addRule(START_OF, getId(ID_NAV_BAR)); } titleBar.setLayoutParams(params); @@ -419,11 +419,17 @@ class Layout extends RelativeLayout { } /** - * Return true if the status bar or nav bar are present, they are not translucent (i.e - * content doesn't overlap with them). + * Return true if the nav bar is present and not translucent */ - private boolean solidBars() { - return !(hasNavBar() && mTranslucentNav) && !(hasStatusBar() && mTranslucentStatus); + private boolean hasSolidNavBar() { + return hasNavBar() && !mTranslucentNav; + } + + /** + * Return true if the status bar is present and not translucent + */ + private boolean hasSolidStatusBar() { + return hasStatusBar() && !mTranslucentStatus; } private boolean hasNavBar() { diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/four_corners.png b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/four_corners.png new file mode 100644 index 0000000000000..868cd51f8bb57 Binary files /dev/null and b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/four_corners.png differ diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/four_corners_translucent.png b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/four_corners_translucent.png new file mode 100644 index 0000000000000..601f711f32d3b Binary files /dev/null and b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/four_corners_translucent.png differ diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/four_corners_translucent_land.png b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/four_corners_translucent_land.png new file mode 100644 index 0000000000000..0b8f1a96791c0 Binary files /dev/null and b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/golden/four_corners_translucent_land.png differ diff --git a/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/four_corners.xml b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/four_corners.xml new file mode 100644 index 0000000000000..c42284a262ae8 --- /dev/null +++ b/tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/four_corners.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + \ No newline at end of file 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 24cbbca02b77a..c813a12923181 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 @@ -39,6 +39,7 @@ import com.android.layoutlib.bridge.intensive.setup.LayoutPullParser; import com.android.resources.Density; import com.android.resources.Navigation; import com.android.resources.ResourceType; +import com.android.resources.ScreenOrientation; import com.android.tools.layoutlib.java.System_Delegate; import com.android.utils.ILogger; @@ -341,6 +342,31 @@ public class Main { renderAndVerify("activity.xml", "activity.png"); } + @Test + public void testTranslucentBars() throws ClassNotFoundException { + LayoutLibTestCallback layoutLibCallback = + new LayoutLibTestCallback(getLogger(), mDefaultClassLoader); + layoutLibCallback.initResources(); + + LayoutPullParser parser = createLayoutPullParser("four_corners.xml"); + SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_5, + layoutLibCallback, "Theme.Material.Light.NoActionBar.TranslucentDecor", false, + RenderingMode.NORMAL, 22); + renderAndVerify(params, "four_corners_translucent.png"); + + parser = createLayoutPullParser("four_corners.xml"); + params = getSessionParams(parser, ConfigGenerator.NEXUS_5_LAND, + layoutLibCallback, "Theme.Material.Light.NoActionBar.TranslucentDecor", false, + RenderingMode.NORMAL, 22); + renderAndVerify(params, "four_corners_translucent_land.png"); + + parser = createLayoutPullParser("four_corners.xml"); + params = getSessionParams(parser, ConfigGenerator.NEXUS_5, + layoutLibCallback, "Theme.Material.Light.NoActionBar", false, + RenderingMode.NORMAL, 22); + renderAndVerify(params, "four_corners.png"); + } + private static void gc() { // See RuntimeUtil#gc in jlibs (http://jlibs.in/) Object obj = new Object();