Fix status and nav bar translucency

Bug: http://b.android.com/204831
Test: Added new UI tests
Change-Id: I992f4ccc391d9a4a0dda941689ec29fb44acf69b
This commit is contained in:
Diego Perez
2016-12-06 18:22:00 +00:00
parent 82ddb5e118
commit 48a285ce1b
6 changed files with 80 additions and 10 deletions

View File

@@ -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() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textSize="40sp"
android:text="Bottom Text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="40sp"
android:text="Top text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:textSize="40sp"
android:text="Start text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textSize="40sp"
android:text="End text" />
</RelativeLayout>

View File

@@ -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();