Skip to content

Commit

Permalink
LayoutLib: Fix true transparency in status bar. [DO NOT MERGE]
Browse files Browse the repository at this point in the history
Change-Id: Ieedf23cde9ab3e36c77501d30cc7e808e66a4782
(cherry picked from commit f9662c006c650c9f61f19a5e1ea4a76640eb85ca)
  • Loading branch information
deepanshu- committed Aug 25, 2015
1 parent da68791 commit b1ad4a1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.xmlpull.v1.XmlPullParserException;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Bitmap_Delegate;
Expand Down Expand Up @@ -227,16 +228,18 @@ public BridgeContext getContext() {
* Find the background color for this bar from the theme attributes. Only relevant to StatusBar
* and NavigationBar.
* <p/>
* Returns 0 if not found.
* Returns null if not found.
*
* @param colorAttrName the attribute name for the background color
* @param translucentAttrName the attribute name for the translucency property of the bar.
*
* @throws NumberFormatException if color resolved to an invalid string.
*/
protected int getBarColor(@NonNull String colorAttrName, @NonNull String translucentAttrName) {
@Nullable
protected Integer getBarColor(@NonNull String colorAttrName,
@NonNull String translucentAttrName) {
if (!Config.isGreaterOrEqual(mSimulatedPlatformVersion, LOLLIPOP)) {
return 0;
return null;
}
RenderResources renderResources = getContext().getRenderResources();
// First check if the bar is translucent.
Expand All @@ -251,10 +254,11 @@ protected int getBarColor(@NonNull String colorAttrName, @NonNull String translu
if (transparent) {
return getColor(renderResources, colorAttrName);
}
return 0;
return null;
}

private static int getColor(RenderResources renderResources, String attr) {
@Nullable
private static Integer getColor(RenderResources renderResources, String attr) {
// From ?attr/foo to @color/bar. This is most likely an ItemResourceValue.
ResourceValue resource = renderResources.findItemInTheme(attr, true);
// Form @color/bar to the #AARRGGBB
Expand All @@ -275,7 +279,7 @@ private static int getColor(RenderResources renderResources, String attr) {
}
}
}
return 0;
return null;
}

private ResourceValue getResourceValue(String reference) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public NavigationBar(BridgeContext context, Density density, int orientation, bo
super(context, orientation, "/bars/navigation_bar.xml", "navigation_bar.xml",
simulatedPlatformVersion);

int color = getBarColor(ATTR_COLOR, ATTR_TRANSLUCENT);
setBackgroundColor(color == 0 ? 0xFF000000 : color);
Integer color = getBarColor(ATTR_COLOR, ATTR_TRANSLUCENT);
setBackgroundColor(color == null ? 0xFF000000 : color);

// Cannot access the inside items through id because no R.id values have been
// created for them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ public StatusBar(BridgeContext context, Density density, boolean isRtl, boolean
// FIXME: use FILL_H?
setGravity(Gravity.START | Gravity.TOP | Gravity.RIGHT);

int color = getBarColor(ATTR_COLOR, ATTR_TRANSLUCENT);
setBackgroundColor(color == 0 ? Config.getStatusBarColor(simulatedPlatformVersion) : color);
Integer color = getBarColor(ATTR_COLOR, ATTR_TRANSLUCENT);
setBackgroundColor(
color == null ? Config.getStatusBarColor(simulatedPlatformVersion) : color);

// Cannot access the inside items through id because no R.id values have been
// created for them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,7 @@ public Result render(boolean freshRender) {
gc.setComposite(AlphaComposite.Src);

gc.setColor(new Color(0x00000000, true));
gc.fillRect(0, 0,
mMeasuredScreenWidth, mMeasuredScreenHeight);
gc.fillRect(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight);

// done
gc.dispose();
Expand Down

0 comments on commit b1ad4a1

Please sign in to comment.