From cf52390eee4c9ae792ef63af1528b2e71b33a04f Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Thu, 11 Nov 2010 18:22:45 -0800 Subject: Layoutlib: Fill the default prop value map for View objects. Change-Id: I35426ced17a10eb092fac2153276f1202692876f --- .../layoutlib/bridge/BridgeLayoutScene.java | 6 +++ .../layoutlib/bridge/android/BridgeContext.java | 48 ++++++++++------------ .../layoutlib/bridge/impl/LayoutSceneImpl.java | 7 +++- 3 files changed, 33 insertions(+), 28 deletions(-) (limited to 'tools') diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeLayoutScene.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeLayoutScene.java index 5fcb9ff..8b67166 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeLayoutScene.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeLayoutScene.java @@ -22,6 +22,7 @@ import com.android.layoutlib.api.ViewInfo; import com.android.layoutlib.bridge.impl.LayoutSceneImpl; import java.awt.image.BufferedImage; +import java.util.Map; /** * An implementation of {@link LayoutScene}. @@ -52,6 +53,11 @@ public class BridgeLayoutScene extends LayoutScene { } @Override + public Map getDefaultViewPropertyValues(Object viewObject) { + return mScene.getDefaultViewPropertyValues(viewObject); + } + + @Override public SceneResult render() { synchronized (mBridge) { 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 79aecff..02db2cf 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 @@ -63,6 +63,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; +import java.util.IdentityHashMap; import java.util.Map; import java.util.TreeMap; import java.util.Map.Entry; @@ -82,6 +83,9 @@ public final class BridgeContext extends Activity { private final Map> mFrameworkResources; private final Map mStyleInheritanceMap; + private final Map> mDefaultPropMaps = + new IdentityHashMap>(); + // maps for dynamically generated id representing style objects (IStyleResourceValue) private Map mDynamicIdToStyleMap; private Map mStyleToDynamicIdMap; @@ -180,6 +184,9 @@ public final class BridgeContext extends Activity { return mLogger; } + public Map getDefaultPropMap(Object key) { + return mDefaultPropMaps.get(key); + } // ------------- Activity Methods @@ -285,13 +292,16 @@ public final class BridgeContext extends Activity { return null; } - Object key = null; + Map defaultPropMap = null; if (parser != null) { - key = parser.getViewKey(); - } - if (key != null) { - String attrs_name = Bridge.resolveResourceValue(attrs); - System.out.println("KEY: " + key.toString() + "(" + attrs_name + ")"); + Object key = parser.getViewKey(); + if (key != null) { + defaultPropMap = mDefaultPropMaps.get(key); + if (defaultPropMap == null) { + defaultPropMap = new HashMap(); + mDefaultPropMaps.put(key, defaultPropMap); + } + } } boolean[] frameworkAttributes = new boolean[1]; @@ -309,9 +319,6 @@ public final class BridgeContext extends Activity { customStyle = parser.getAttributeValue(null /* namespace*/, "style"); } if (customStyle != null) { - if (key != null) { - print("style", customStyle, false); - } IResourceValue item = findResValue(customStyle, false /*forceFrameworkOnly*/); if (item instanceof IStyleResourceValue) { @@ -323,8 +330,8 @@ public final class BridgeContext extends Activity { // get the name from the int. String defStyleName = searchAttr(defStyleAttr); - if (key != null) { - print("style", defStyleName, true); + if (defaultPropMap != null) { + defaultPropMap.put("style", defStyleName); } // look for the style in the current theme, and its parent: @@ -385,20 +392,16 @@ public final class BridgeContext extends Activity { // if we found a value, we make sure this doesn't reference another value. // So we resolve it. if (resValue != null) { - if (key != null) { - print(name, resValue.getValue(), true); + // put the first default value, before the resolution. + if (defaultPropMap != null) { + defaultPropMap.put(name, resValue.getValue()); } resValue = resolveResValue(resValue); - } else if (key != null) { - print(name, "", true); } ta.bridgeSetValue(index, name, resValue); } else { - if (key != null) { - print(name, value, false); - } // there is a value in the XML, but we need to resolve it in case it's // referencing another resource or a theme value. ta.bridgeSetValue(index, name, resolveValue(null, name, value)); @@ -411,15 +414,6 @@ public final class BridgeContext extends Activity { return ta; } - private void print(String name, String value, boolean isDefault) { - System.out.print("\t" + name + " : " + value); - if (isDefault) { - System.out.println(" (default)"); - } else { - System.out.println(""); - } - } - @Override public Looper getMainLooper() { return Looper.myLooper(); diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/LayoutSceneImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/LayoutSceneImpl.java index d8a59ce..b0316a3 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/LayoutSceneImpl.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/LayoutSceneImpl.java @@ -665,7 +665,8 @@ public class LayoutSceneImpl { ViewInfo result = new ViewInfo(view.getClass().getName(), context.getViewKey(view), - view.getLeft(), view.getTop(), view.getRight(), view.getBottom()); + view.getLeft(), view.getTop(), view.getRight(), view.getBottom(), + view, view.getLayoutParams()); if (view instanceof ViewGroup) { ViewGroup group = ((ViewGroup) view); @@ -686,4 +687,8 @@ public class LayoutSceneImpl { public ViewInfo getViewInfo() { return mViewInfo; } + + public Map getDefaultViewPropertyValues(Object viewObject) { + return mContext.getDefaultPropMap(viewObject); + } } -- cgit v1.1