diff options
author | Xavier Ducrohet <xav@android.com> | 2011-02-18 18:14:13 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-02-18 18:14:13 -0800 |
commit | 82314c013fbd94fdbad6a8f9687a6204c7966e12 (patch) | |
tree | 41b0baf2d22b9b46cf7ffd347e7a67923a1c0f10 | |
parent | 250da4bb91b564c049598975921bc7b49e3f3606 (diff) | |
parent | 3e87bfa1911de10c3d0692b34eba27f5965710f7 (diff) | |
download | frameworks_base-82314c013fbd94fdbad6a8f9687a6204c7966e12.zip frameworks_base-82314c013fbd94fdbad6a8f9687a6204c7966e12.tar.gz frameworks_base-82314c013fbd94fdbad6a8f9687a6204c7966e12.tar.bz2 |
Merge "LayoutLib: support defStyleRes in obtainStyledAttributes."
-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; |