diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2015-03-25 00:29:42 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-03-25 00:29:42 +0000 |
commit | cb580742e364f29bdd78ee5532d1c00279419e48 (patch) | |
tree | a0faf522a28433af468cfe7a2fd84546b0635f4b /tools/layoutlib | |
parent | 88c2fdc00c0877c384aae359c0c3c36a3c64bf9e (diff) | |
parent | 659413d6a2ccd8c8ade06bc3420ca90def3e3be6 (diff) | |
download | frameworks_base-cb580742e364f29bdd78ee5532d1c00279419e48.zip frameworks_base-cb580742e364f29bdd78ee5532d1c00279419e48.tar.gz frameworks_base-cb580742e364f29bdd78ee5532d1c00279419e48.tar.bz2 |
am 659413d6: am 5c03cd8a: am 96a67430: am 2b98abde: am 8f9ebc65: am 3bd5cbb1: Merge "Use right colors for status bar and nav bar." into lmp-dev
* commit '659413d6a2ccd8c8ade06bc3420ca90def3e3be6':
Use right colors for status bar and nav bar.
Diffstat (limited to 'tools/layoutlib')
5 files changed, 65 insertions, 20 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/Config.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/Config.java index dde041b..9f9b968 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/Config.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/Config.java @@ -16,6 +16,8 @@ package com.android.layoutlib.bridge.bars; +import android.os.Build.VERSION_CODES; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -40,12 +42,12 @@ public class Config { private static final int BLACK = 0xFF000000; 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) { // 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) { @@ -98,7 +100,7 @@ public class Config { } public static int getTimeColor(int platformVersion) { - if (platformVersion == 0 || platformVersion >= KITKAT || + if (isGreaterOrEqual(platformVersion, KITKAT) || platformVersion > FROYO && platformVersion < HONEYCOMB) { // Gingerbread and KitKat onwards. return WHITE; @@ -117,4 +119,13 @@ public class Config { public static String getWifiIconType(int platformVersion) { 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; + } } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java index 13ddf07..bc1a41d 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java @@ -16,6 +16,7 @@ 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.ResourceValue; 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.resources.Density; import com.android.resources.LayoutDirection; +import com.android.resources.ResourceType; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -47,6 +49,8 @@ import android.widget.TextView; import java.io.IOException; import java.io.InputStream; +import static android.os.Build.VERSION_CODES.LOLLIPOP; + /** * 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 @@ -63,7 +67,7 @@ abstract class CustomBar extends LinearLayout { 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 { super(context); mSimulatedPlatformVersion = simulatedPlatformVersion; @@ -197,7 +201,7 @@ abstract class CustomBar extends LinearLayout { ResourceValue textColor = res.findItemInStyle(textStyle, "textColor", - true /*isFrameworkAttr*/); + true); textColor = res.resolveResValue(textColor); if (textColor != null) { 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) { BridgeContext bridgeContext = (BridgeContext) mContext; RenderResources res = bridgeContext.getRenderResources(); // find the resource - ResourceValue value = res.findResValue(reference, false /*isFramework*/); + ResourceValue value = res.findResValue(reference, false); // resolve it if needed return res.resolveResValue(value); diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/NavigationBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/NavigationBar.java index 283ff57..9450b6c 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/NavigationBar.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/NavigationBar.java @@ -16,22 +16,26 @@ package com.android.layoutlib.bridge.bars; +import com.android.layoutlib.bridge.android.BridgeContext; import com.android.resources.Density; import org.xmlpull.v1.XmlPullParserException; -import android.content.Context; import android.widget.LinearLayout; import android.widget.TextView; 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 { super(context, orientation, "/bars/navigation_bar.xml", "navigation_bar.xml", 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 // created for them. diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/StatusBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/StatusBar.java index c7c62d6..e5f1f68 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/StatusBar.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/StatusBar.java @@ -25,7 +25,6 @@ import com.android.resources.Density; import org.xmlpull.v1.XmlPullParserException; -import android.content.Context; import android.graphics.drawable.Drawable; import android.view.Gravity; import android.view.View; @@ -38,20 +37,21 @@ import java.io.InputStream; public class StatusBar extends CustomBar { - private final Context mContext; 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 { // 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", simulatedPlatformVersion); - mContext = context; mSimulatedPlatformVersion = simulatedPlatformVersion; // FIXME: use FILL_H? 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 // created for them. @@ -82,10 +82,8 @@ public class StatusBar extends CustomBar { try { BridgeXmlBlockParser parser = new BridgeXmlBlockParser( ParserFactory.create(stream, null), (BridgeContext) mContext, true); - Drawable drawable = Drawable.createFromXml(mContext.getResources(), parser); - if (drawable != null) { - imageView.setImageDrawable(drawable); - } + imageView.setImageDrawable( + Drawable.createFromXml(mContext.getResources(), parser)); } catch (XmlPullParserException e) { Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Unable to draw wifi icon", e, null); diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/TitleBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/TitleBar.java index 10f1383..c610601 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/TitleBar.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/TitleBar.java @@ -16,9 +16,10 @@ package com.android.layoutlib.bridge.bars; +import com.android.layoutlib.bridge.android.BridgeContext; + import org.xmlpull.v1.XmlPullParserException; -import android.content.Context; import android.widget.LinearLayout; import android.widget.TextView; @@ -26,7 +27,7 @@ public class TitleBar extends CustomBar { private TextView mTextView; - public TitleBar(Context context, String label, int simulatedPlatformVersion) + public TitleBar(BridgeContext context, String label, int simulatedPlatformVersion) throws XmlPullParserException { super(context, LinearLayout.HORIZONTAL, "/bars/title_bar.xml", "title_bar.xml", simulatedPlatformVersion); |