Merge 6103e22c from honeycomb-mr1. do not merge.
LayoutLib: custom styles override the default style instead of replacing it. Intead of reading either the custom or the default style for a widget, we read both and use the values from the custom style if it exists, or from the default style otherwise. Change-Id: Ibcec2e9b1e8a95295ab26ede145c287ff2f30be4
This commit is contained in:
@@ -509,14 +509,13 @@ public final class BridgeContext extends Activity {
|
||||
BridgeTypedArray ta = ((BridgeResources) mSystemResources).newTypeArray(attrs.length,
|
||||
isPlatformFile);
|
||||
|
||||
// resolve the defStyleAttr value into a IStyleResourceValue
|
||||
StyleResourceValue defStyleValues = null;
|
||||
|
||||
// look for a custom style.
|
||||
String customStyle = null;
|
||||
if (set != null) {
|
||||
customStyle = set.getAttributeValue(null /* namespace*/, "style");
|
||||
}
|
||||
|
||||
StyleResourceValue customStyleValues = null;
|
||||
if (customStyle != null) {
|
||||
ResourceValue item = mRenderResources.findResValue(customStyle,
|
||||
false /*forceFrameworkOnly*/);
|
||||
@@ -525,75 +524,76 @@ public final class BridgeContext extends Activity {
|
||||
item = mRenderResources.resolveResValue(item);
|
||||
|
||||
if (item instanceof StyleResourceValue) {
|
||||
defStyleValues = (StyleResourceValue)item;
|
||||
customStyleValues = (StyleResourceValue)item;
|
||||
}
|
||||
}
|
||||
|
||||
if (defStyleValues == null) {
|
||||
if (defStyleAttr != 0) {
|
||||
// get the name from the int.
|
||||
String defStyleName = searchAttr(defStyleAttr);
|
||||
// resolve the defStyleAttr value into a IStyleResourceValue
|
||||
StyleResourceValue defStyleValues = null;
|
||||
|
||||
if (defaultPropMap != null) {
|
||||
defaultPropMap.put("style", defStyleName);
|
||||
if (defStyleAttr != 0) {
|
||||
// get the name from the int.
|
||||
String defStyleName = searchAttr(defStyleAttr);
|
||||
|
||||
if (defaultPropMap != null) {
|
||||
defaultPropMap.put("style", defStyleName);
|
||||
}
|
||||
|
||||
// look for the style in the current theme, and its parent:
|
||||
ResourceValue item = mRenderResources.findItemInTheme(defStyleName);
|
||||
|
||||
if (item != null) {
|
||||
// item is a reference to a style entry. Search for it.
|
||||
item = mRenderResources.findResValue(item.getValue(),
|
||||
false /*forceFrameworkOnly*/);
|
||||
|
||||
if (item instanceof StyleResourceValue) {
|
||||
defStyleValues = (StyleResourceValue)item;
|
||||
}
|
||||
} else {
|
||||
Bridge.getLog().error(null,
|
||||
String.format(
|
||||
"Failed to find style '%s' in current theme", defStyleName),
|
||||
null /*data*/);
|
||||
}
|
||||
} else if (defStyleRes != 0) {
|
||||
Pair<ResourceType, String> value = Bridge.resolveResourceId(defStyleRes);
|
||||
if (value == null) {
|
||||
value = mProjectCallback.resolveResourceId(defStyleRes);
|
||||
}
|
||||
|
||||
// look for the style in the current theme, and its parent:
|
||||
ResourceValue item = mRenderResources.findItemInTheme(defStyleName);
|
||||
|
||||
if (item != null) {
|
||||
// item is a reference to a style entry. Search for it.
|
||||
item = mRenderResources.findResValue(item.getValue(),
|
||||
false /*forceFrameworkOnly*/);
|
||||
|
||||
if (item instanceof StyleResourceValue) {
|
||||
defStyleValues = (StyleResourceValue)item;
|
||||
}
|
||||
} else {
|
||||
Bridge.getLog().error(null,
|
||||
String.format(
|
||||
"Failed to find style '%s' in current theme", defStyleName),
|
||||
null /*data*/);
|
||||
}
|
||||
} else if (defStyleRes != 0) {
|
||||
Pair<ResourceType, String> value = Bridge.resolveResourceId(defStyleRes);
|
||||
if (value == null) {
|
||||
value = mProjectCallback.resolveResourceId(defStyleRes);
|
||||
}
|
||||
|
||||
if (value != null) {
|
||||
if (value.getFirst() == ResourceType.STYLE) {
|
||||
// look for the style in the current theme, and its parent:
|
||||
ResourceValue item = mRenderResources.findItemInTheme(value.getSecond());
|
||||
if (item != null) {
|
||||
if (item instanceof StyleResourceValue) {
|
||||
if (defaultPropMap != null) {
|
||||
defaultPropMap.put("style", item.getName());
|
||||
}
|
||||
|
||||
defStyleValues = (StyleResourceValue)item;
|
||||
if (value != null) {
|
||||
if (value.getFirst() == ResourceType.STYLE) {
|
||||
// look for the style in the current theme, and its parent:
|
||||
ResourceValue item = mRenderResources.findItemInTheme(value.getSecond());
|
||||
if (item != null) {
|
||||
if (item instanceof StyleResourceValue) {
|
||||
if (defaultPropMap != null) {
|
||||
defaultPropMap.put("style", item.getName());
|
||||
}
|
||||
} else {
|
||||
Bridge.getLog().error(null,
|
||||
String.format(
|
||||
"Style with id 0x%x (resolved to '%s') does not exist.",
|
||||
defStyleRes, value.getSecond()),
|
||||
null /*data*/);
|
||||
|
||||
defStyleValues = (StyleResourceValue)item;
|
||||
}
|
||||
} else {
|
||||
Bridge.getLog().error(null,
|
||||
String.format(
|
||||
"Resouce id 0x%x is not of type STYLE (instead %s)",
|
||||
defStyleRes, value.getFirst().toString()),
|
||||
"Style with id 0x%x (resolved to '%s') does not exist.",
|
||||
defStyleRes, value.getSecond()),
|
||||
null /*data*/);
|
||||
}
|
||||
} else {
|
||||
Bridge.getLog().error(null,
|
||||
String.format(
|
||||
"Failed to find style with id 0x%x in current theme",
|
||||
defStyleRes),
|
||||
"Resouce id 0x%x is not of type STYLE (instead %s)",
|
||||
defStyleRes, value.getFirst().toString()),
|
||||
null /*data*/);
|
||||
}
|
||||
} else {
|
||||
Bridge.getLog().error(null,
|
||||
String.format(
|
||||
"Failed to find style with id 0x%x in current theme",
|
||||
defStyleRes),
|
||||
null /*data*/);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,8 +618,13 @@ public final class BridgeContext extends Activity {
|
||||
if (value == null) {
|
||||
ResourceValue resValue = null;
|
||||
|
||||
// look for the value in the defStyle first (and its parent if needed)
|
||||
if (defStyleValues != null) {
|
||||
// look for the value in the custom style first (and its parent if needed)
|
||||
if (customStyleValues != null) {
|
||||
resValue = mRenderResources.findItemInStyle(customStyleValues, name);
|
||||
}
|
||||
|
||||
// then look for the value in the default Style (and its parent if needed)
|
||||
if (resValue == null && defStyleValues != null) {
|
||||
resValue = mRenderResources.findItemInStyle(defStyleValues, name);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user