diff options
author | Xavier Ducrohet <xav@android.com> | 2011-02-18 17:50:38 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2011-02-18 17:50:38 -0800 |
commit | 3e87bfa1911de10c3d0692b34eba27f5965710f7 (patch) | |
tree | bc2785d949948e55fc0da3b74fe3414f47da1c6a /tools | |
parent | f20999965b94bdcc2b1f2c05b587ff405924bc96 (diff) | |
download | frameworks_base-3e87bfa1911de10c3d0692b34eba27f5965710f7.zip frameworks_base-3e87bfa1911de10c3d0692b34eba27f5965710f7.tar.gz frameworks_base-3e87bfa1911de10c3d0692b34eba27f5965710f7.tar.bz2 |
LayoutLib: support defStyleRes in obtainStyledAttributes.
This fix the Spinner rendering.
Change-Id: I20a71d9e07f6c86652a74fba3fc05a027a057ff8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java | 84 |
1 files changed, 60 insertions, 24 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java index 33dd214..7d794bd 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java @@ -425,36 +425,72 @@ public final class BridgeContext extends Activity { } } - if (defStyleValues == null && defStyleAttr != 0) { - // get the name from the int. - String defStyleName = searchAttr(defStyleAttr); + if (defStyleValues == null) { + if (defStyleAttr != 0) { + // get the name from the int. + String defStyleName = searchAttr(defStyleAttr); - if (defaultPropMap != null) { - defaultPropMap.put("style", defStyleName); - } + if (defaultPropMap != null) { + defaultPropMap.put("style", defStyleName); + } - // look for the style in the current theme, and its parent: - ResourceValue item = mRenderResources.findItemInTheme(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 != 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; + 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); } - } else { - Bridge.getLog().error(null, - String.format( - "Failed to find style '%s' in current theme", defStyleName), - null /*data*/); - } - } - if (defStyleRes != 0) { - // FIXME: See what we need to do with this. - throw new UnsupportedOperationException(); + 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; + } + } else { + Bridge.getLog().error(null, + String.format( + "Style with id 0x%x (resolved to '%s') does not exist.", + defStyleRes, value.getSecond()), + null /*data*/); + } + } else { + Bridge.getLog().error(null, + String.format( + "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*/); + } + } } String namespace = BridgeConstants.NS_RESOURCES; |