summaryrefslogtreecommitdiffstats
path: root/tools/layoutlib
diff options
context:
space:
mode:
authorDeepanshu Gupta <deepanshu@google.com>2015-07-27 11:50:43 -0700
committerDeepanshu Gupta <deepanshu@google.com>2015-07-27 11:54:49 -0700
commite3f9834ebd8a6e4ee155c8e4c9456dfc98e8b832 (patch)
treee8e046f01ffe280eecc2edfb1a8ea0f1de041d2b /tools/layoutlib
parent9c450936aad92920215d2bc52d2c9ce132a55432 (diff)
downloadframeworks_base-e3f9834ebd8a6e4ee155c8e4c9456dfc98e8b832.zip
frameworks_base-e3f9834ebd8a6e4ee155c8e4c9456dfc98e8b832.tar.gz
frameworks_base-e3f9834ebd8a6e4ee155c8e4c9456dfc98e8b832.tar.bz2
LayoutLib: Fix Status/Navigation Bar color.
If the color value for status bar or navigation bar is declared directly in the theme (i.e. doesn't reference a color resource via @color/foo), the ResourceType for the attribute is not assigned by the IDE. LayoutLib used to ignore resources that were not of type color. This change fixes the issue by also checking the resources without a type. Change-Id: I94735ec225415282db06ab9db5c3233ad89c052f
Diffstat (limited to 'tools/layoutlib')
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomBar.java18
1 files changed, 16 insertions, 2 deletions
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 145a03a..b76ec17 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.ide.common.rendering.api.LayoutLog;
import com.android.ide.common.rendering.api.RenderResources;
import com.android.ide.common.rendering.api.ResourceValue;
import com.android.ide.common.rendering.api.StyleResourceValue;
@@ -258,8 +259,21 @@ abstract class CustomBar extends LinearLayout {
ResourceValue resource = renderResources.findItemInTheme(attr, true);
// Form @color/bar to the #AARRGGBB
resource = renderResources.resolveResValue(resource);
- if (resource != null && ResourceType.COLOR.equals(resource.getResourceType())) {
- return ResourceHelper.getColor(resource.getValue());
+ if (resource != null) {
+ ResourceType type = resource.getResourceType();
+ if (type == null || type == ResourceType.COLOR) {
+ // if no type is specified, the value may have been specified directly in the style
+ // file, rather than referencing a color resource value.
+ try {
+ return ResourceHelper.getColor(resource.getValue());
+ } catch (NumberFormatException e) {
+ // Conversion failed.
+ Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT,
+ "Theme attribute @android:" + attr +
+ " does not reference a color, instead is '" +
+ resource.getValue() + "'.", resource);
+ }
+ }
}
return 0;
}