Merge "Use right colors for status bar and nav bar." into lmp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
3bd5cbb1f3
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.layoutlib.bridge.bars;
|
package com.android.layoutlib.bridge.bars;
|
||||||
|
|
||||||
|
import android.os.Build.VERSION_CODES;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -40,12 +42,12 @@ public class Config {
|
|||||||
private static final int BLACK = 0xFF000000;
|
private static final int BLACK = 0xFF000000;
|
||||||
|
|
||||||
public static boolean showOnScreenNavBar(int platformVersion) {
|
public static boolean showOnScreenNavBar(int platformVersion) {
|
||||||
return platformVersion == 0 || platformVersion >= ICE_CREAM_SANDWICH;
|
return isGreaterOrEqual(platformVersion, ICE_CREAM_SANDWICH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getStatusBarColor(int platformVersion) {
|
public static int getStatusBarColor(int platformVersion) {
|
||||||
// return white for froyo and earlier; black otherwise.
|
// return white for froyo and earlier; black otherwise.
|
||||||
return platformVersion == 0 || platformVersion >= GINGERBREAD ? BLACK : WHITE;
|
return isGreaterOrEqual(platformVersion, GINGERBREAD) ? BLACK : WHITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getResourceDirs(int platformVersion) {
|
public static List<String> getResourceDirs(int platformVersion) {
|
||||||
@@ -95,7 +97,7 @@ public class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getTimeColor(int platformVersion) {
|
public static int getTimeColor(int platformVersion) {
|
||||||
if (platformVersion == 0 || platformVersion >= KITKAT ||
|
if (isGreaterOrEqual(platformVersion, KITKAT) ||
|
||||||
platformVersion > FROYO && platformVersion < HONEYCOMB) {
|
platformVersion > FROYO && platformVersion < HONEYCOMB) {
|
||||||
// Gingerbread and KitKat onwards.
|
// Gingerbread and KitKat onwards.
|
||||||
return WHITE;
|
return WHITE;
|
||||||
@@ -114,4 +116,13 @@ public class Config {
|
|||||||
public static String getWifiIconType(int platformVersion) {
|
public static String getWifiIconType(int platformVersion) {
|
||||||
return platformVersion == 0 ? "xml" : "png";
|
return platformVersion == 0 ? "xml" : "png";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare simulated platform version and code from {@link VERSION_CODES} to check if
|
||||||
|
* the simulated platform is greater than or equal to the version code.
|
||||||
|
*/
|
||||||
|
public static boolean isGreaterOrEqual(int platformVersion, int code) {
|
||||||
|
// simulated platform version = 0 means that we use the latest.
|
||||||
|
return platformVersion == 0 || platformVersion >= code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.layoutlib.bridge.bars;
|
package com.android.layoutlib.bridge.bars;
|
||||||
|
|
||||||
|
import com.android.annotations.NonNull;
|
||||||
import com.android.ide.common.rendering.api.RenderResources;
|
import com.android.ide.common.rendering.api.RenderResources;
|
||||||
import com.android.ide.common.rendering.api.ResourceValue;
|
import com.android.ide.common.rendering.api.ResourceValue;
|
||||||
import com.android.ide.common.rendering.api.StyleResourceValue;
|
import com.android.ide.common.rendering.api.StyleResourceValue;
|
||||||
@@ -26,6 +27,7 @@ import com.android.layoutlib.bridge.impl.ParserFactory;
|
|||||||
import com.android.layoutlib.bridge.impl.ResourceHelper;
|
import com.android.layoutlib.bridge.impl.ResourceHelper;
|
||||||
import com.android.resources.Density;
|
import com.android.resources.Density;
|
||||||
import com.android.resources.LayoutDirection;
|
import com.android.resources.LayoutDirection;
|
||||||
|
import com.android.resources.ResourceType;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
@@ -47,6 +49,8 @@ import android.widget.TextView;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import static android.os.Build.VERSION_CODES.LOLLIPOP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base "bar" class for the window decor around the the edited layout.
|
* Base "bar" class for the window decor around the the edited layout.
|
||||||
* This is basically an horizontal layout that loads a given layout on creation (it is read
|
* This is basically an horizontal layout that loads a given layout on creation (it is read
|
||||||
@@ -63,7 +67,7 @@ abstract class CustomBar extends LinearLayout {
|
|||||||
|
|
||||||
protected abstract TextView getStyleableTextView();
|
protected abstract TextView getStyleableTextView();
|
||||||
|
|
||||||
protected CustomBar(Context context, int orientation, String layoutPath,
|
protected CustomBar(BridgeContext context, int orientation, String layoutPath,
|
||||||
String name, int simulatedPlatformVersion) throws XmlPullParserException {
|
String name, int simulatedPlatformVersion) throws XmlPullParserException {
|
||||||
super(context);
|
super(context);
|
||||||
mSimulatedPlatformVersion = simulatedPlatformVersion;
|
mSimulatedPlatformVersion = simulatedPlatformVersion;
|
||||||
@@ -197,7 +201,7 @@ abstract class CustomBar extends LinearLayout {
|
|||||||
|
|
||||||
|
|
||||||
ResourceValue textColor = res.findItemInStyle(textStyle, "textColor",
|
ResourceValue textColor = res.findItemInStyle(textStyle, "textColor",
|
||||||
true /*isFrameworkAttr*/);
|
true);
|
||||||
textColor = res.resolveResValue(textColor);
|
textColor = res.resolveResValue(textColor);
|
||||||
if (textColor != null) {
|
if (textColor != null) {
|
||||||
ColorStateList stateList = ResourceHelper.getColorStateList(
|
ColorStateList stateList = ResourceHelper.getColorStateList(
|
||||||
@@ -210,12 +214,39 @@ abstract class CustomBar extends LinearLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a theme attribute name, get the color referenced by it. The theme attribute may be
|
||||||
|
* used in a layout like "?attr/foo".
|
||||||
|
* <p/>
|
||||||
|
* Returns 0 if not found.
|
||||||
|
*
|
||||||
|
* @throws NumberFormatException if color resolved to an invalid string.
|
||||||
|
*/
|
||||||
|
protected int getThemeAttrColor(@NonNull String attrName, boolean isFramework) {
|
||||||
|
if (!Config.isGreaterOrEqual(mSimulatedPlatformVersion, LOLLIPOP)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
assert mContext instanceof BridgeContext;
|
||||||
|
BridgeContext context = ((BridgeContext) mContext);
|
||||||
|
RenderResources renderResources = context.getRenderResources();
|
||||||
|
// From ?attr/foo to @color/bar. This is most likely an ItemResourceValue.
|
||||||
|
ResourceValue resource = renderResources.findItemInTheme(attrName, isFramework);
|
||||||
|
if (resource != null) {
|
||||||
|
// Form @color/bar to the #AARRGGBB
|
||||||
|
resource = renderResources.resolveResValue(resource);
|
||||||
|
}
|
||||||
|
if (resource != null && ResourceType.COLOR.equals(resource.getResourceType())) {
|
||||||
|
return ResourceHelper.getColor(resource.getValue());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
private ResourceValue getResourceValue(String reference) {
|
private ResourceValue getResourceValue(String reference) {
|
||||||
BridgeContext bridgeContext = (BridgeContext) mContext;
|
BridgeContext bridgeContext = (BridgeContext) mContext;
|
||||||
RenderResources res = bridgeContext.getRenderResources();
|
RenderResources res = bridgeContext.getRenderResources();
|
||||||
|
|
||||||
// find the resource
|
// find the resource
|
||||||
ResourceValue value = res.findResValue(reference, false /*isFramework*/);
|
ResourceValue value = res.findResValue(reference, false);
|
||||||
|
|
||||||
// resolve it if needed
|
// resolve it if needed
|
||||||
return res.resolveResValue(value);
|
return res.resolveResValue(value);
|
||||||
|
|||||||
@@ -16,22 +16,26 @@
|
|||||||
|
|
||||||
package com.android.layoutlib.bridge.bars;
|
package com.android.layoutlib.bridge.bars;
|
||||||
|
|
||||||
|
import com.android.layoutlib.bridge.android.BridgeContext;
|
||||||
import com.android.resources.Density;
|
import com.android.resources.Density;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class NavigationBar extends CustomBar {
|
public class NavigationBar extends CustomBar {
|
||||||
|
|
||||||
public NavigationBar(Context context, Density density, int orientation, boolean isRtl,
|
/** Navigation bar background color attribute name. */
|
||||||
|
private static final String ATTR_COLOR = "navigationBarColor";
|
||||||
|
|
||||||
|
public NavigationBar(BridgeContext context, Density density, int orientation, boolean isRtl,
|
||||||
boolean rtlEnabled, int simulatedPlatformVersion) throws XmlPullParserException {
|
boolean rtlEnabled, int simulatedPlatformVersion) throws XmlPullParserException {
|
||||||
super(context, orientation, "/bars/navigation_bar.xml", "navigation_bar.xml",
|
super(context, orientation, "/bars/navigation_bar.xml", "navigation_bar.xml",
|
||||||
simulatedPlatformVersion);
|
simulatedPlatformVersion);
|
||||||
|
|
||||||
setBackgroundColor(0xFF000000);
|
int color = getThemeAttrColor(ATTR_COLOR, true);
|
||||||
|
setBackgroundColor(color == 0 ? 0xFF000000 : color);
|
||||||
|
|
||||||
// Cannot access the inside items through id because no R.id values have been
|
// Cannot access the inside items through id because no R.id values have been
|
||||||
// created for them.
|
// created for them.
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import com.android.resources.Density;
|
|||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -38,20 +37,21 @@ import java.io.InputStream;
|
|||||||
|
|
||||||
public class StatusBar extends CustomBar {
|
public class StatusBar extends CustomBar {
|
||||||
|
|
||||||
private final Context mContext;
|
|
||||||
private final int mSimulatedPlatformVersion;
|
private final int mSimulatedPlatformVersion;
|
||||||
|
/** Status bar background color attribute name. */
|
||||||
|
private static final String ATTR_COLOR = "colorPrimaryDark";
|
||||||
|
|
||||||
public StatusBar(Context context, Density density, int direction, boolean RtlEnabled,
|
public StatusBar(BridgeContext context, Density density, int direction, boolean RtlEnabled,
|
||||||
int simulatedPlatformVersion) throws XmlPullParserException {
|
int simulatedPlatformVersion) throws XmlPullParserException {
|
||||||
// FIXME: if direction is RTL but it's not enabled in application manifest, mirror this bar.
|
// FIXME: if direction is RTL but it's not enabled in application manifest, mirror this bar.
|
||||||
super(context, LinearLayout.HORIZONTAL, "/bars/status_bar.xml", "status_bar.xml",
|
super(context, LinearLayout.HORIZONTAL, "/bars/status_bar.xml", "status_bar.xml",
|
||||||
simulatedPlatformVersion);
|
simulatedPlatformVersion);
|
||||||
mContext = context;
|
|
||||||
mSimulatedPlatformVersion = simulatedPlatformVersion;
|
mSimulatedPlatformVersion = simulatedPlatformVersion;
|
||||||
|
|
||||||
// FIXME: use FILL_H?
|
// FIXME: use FILL_H?
|
||||||
setGravity(Gravity.START | Gravity.TOP | Gravity.RIGHT);
|
setGravity(Gravity.START | Gravity.TOP | Gravity.RIGHT);
|
||||||
setBackgroundColor(Config.getStatusBarColor(simulatedPlatformVersion));
|
int color = getThemeAttrColor(ATTR_COLOR, true);
|
||||||
|
setBackgroundColor(color == 0 ? Config.getStatusBarColor(simulatedPlatformVersion) : color);
|
||||||
|
|
||||||
// Cannot access the inside items through id because no R.id values have been
|
// Cannot access the inside items through id because no R.id values have been
|
||||||
// created for them.
|
// created for them.
|
||||||
@@ -82,10 +82,8 @@ public class StatusBar extends CustomBar {
|
|||||||
try {
|
try {
|
||||||
BridgeXmlBlockParser parser = new BridgeXmlBlockParser(
|
BridgeXmlBlockParser parser = new BridgeXmlBlockParser(
|
||||||
ParserFactory.create(stream, null), (BridgeContext) mContext, true);
|
ParserFactory.create(stream, null), (BridgeContext) mContext, true);
|
||||||
Drawable drawable = Drawable.createFromXml(mContext.getResources(), parser);
|
imageView.setImageDrawable(
|
||||||
if (drawable != null) {
|
Drawable.createFromXml(mContext.getResources(), parser));
|
||||||
imageView.setImageDrawable(drawable);
|
|
||||||
}
|
|
||||||
} catch (XmlPullParserException e) {
|
} catch (XmlPullParserException e) {
|
||||||
Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Unable to draw wifi icon", e,
|
Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Unable to draw wifi icon", e,
|
||||||
null);
|
null);
|
||||||
|
|||||||
@@ -16,9 +16,10 @@
|
|||||||
|
|
||||||
package com.android.layoutlib.bridge.bars;
|
package com.android.layoutlib.bridge.bars;
|
||||||
|
|
||||||
|
import com.android.layoutlib.bridge.android.BridgeContext;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ public class TitleBar extends CustomBar {
|
|||||||
|
|
||||||
private TextView mTextView;
|
private TextView mTextView;
|
||||||
|
|
||||||
public TitleBar(Context context, String label, int simulatedPlatformVersion)
|
public TitleBar(BridgeContext context, String label, int simulatedPlatformVersion)
|
||||||
throws XmlPullParserException {
|
throws XmlPullParserException {
|
||||||
super(context, LinearLayout.HORIZONTAL, "/bars/title_bar.xml", "title_bar.xml",
|
super(context, LinearLayout.HORIZONTAL, "/bars/title_bar.xml", "title_bar.xml",
|
||||||
simulatedPlatformVersion);
|
simulatedPlatformVersion);
|
||||||
|
|||||||
Reference in New Issue
Block a user