Add post resolve property values
Change-Id: Ia86b7dfc479cc5313cce36b6b3066fbb1d00c292
diff --git a/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java b/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java
index fea633e..308488a 100644
--- a/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java
+++ b/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java
@@ -70,23 +70,6 @@
}
@Override
- public Map<String, String> getDefaultProperties(Object viewObject) {
- return mSession.getDefaultProperties(viewObject);
- }
-
- @Override
- public Result getProperty(Object objectView, String propertyName) {
- // pass
- return super.getProperty(objectView, propertyName);
- }
-
- @Override
- public Result setProperty(Object objectView, String propertyName, String propertyValue) {
- // pass
- return super.setProperty(objectView, propertyName, propertyValue);
- }
-
- @Override
public Result render(long timeout, boolean forceMeasure) {
try {
Bridge.prepareThread();
@@ -213,6 +196,10 @@
}
}
+ public RenderSessionImpl getSessionImpl() {
+ return mSession;
+ }
+
/*package*/ BridgeRenderSession(RenderSessionImpl scene, Result lastResult) {
mSession = scene;
if (scene != null) {
diff --git a/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index 89272fa..fd95bd5 100644
--- a/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -27,6 +27,7 @@
import com.android.ide.common.rendering.api.StyleResourceValue;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
+import com.android.layoutlib.bridge.android.PropertiesMap.Property;
import com.android.layoutlib.bridge.android.view.WindowManagerImpl;
import com.android.layoutlib.bridge.impl.ParserFactory;
import com.android.layoutlib.bridge.impl.Stack;
@@ -275,7 +276,7 @@
return mRenderResources;
}
- public Map<String, String> getDefaultPropMap(Object key) {
+ public PropertiesMap getDefaultPropMap(Object key) {
return mDefaultPropMaps.get(key);
}
@@ -731,16 +732,10 @@
Bridge.getLog().error(LayoutLog.TAG_RESOURCES_RESOLVE,
"Failed to find the style corresponding to the id " + defStyleAttr, null);
} else {
- if (defaultPropMap != null) {
- String defStyleName = defStyleAttribute.getFirst();
- if (defStyleAttribute.getSecond()) {
- defStyleName = "android:" + defStyleName;
- }
- defaultPropMap.put("style", defStyleName);
- }
+ String defStyleName = defStyleAttribute.getFirst();
// look for the style in the current theme, and its parent:
- ResourceValue item = mRenderResources.findItemInTheme(defStyleAttribute.getFirst(),
+ ResourceValue item = mRenderResources.findItemInTheme(defStyleName,
defStyleAttribute.getSecond());
if (item != null) {
@@ -750,6 +745,12 @@
if (item instanceof StyleResourceValue) {
defStyleValues = (StyleResourceValue) item;
}
+ if (defaultPropMap != null) {
+ if (defStyleAttribute.getSecond()) {
+ defStyleName = "android:" + defStyleName;
+ }
+ defaultPropMap.put("style", new Property(defStyleName, item.getValue()));
+ }
} else {
Bridge.getLog().error(LayoutLog.TAG_RESOURCES_RESOLVE_THEME_ATTR,
String.format(
@@ -776,7 +777,8 @@
item = mRenderResources.getStyle(value.getSecond(), isFrameworkRes);
if (item != null) {
if (defaultPropMap != null) {
- defaultPropMap.put("style", item.getName());
+ String name = item.getName();
+ defaultPropMap.put("style", new Property(name, name));
}
defStyleValues = item;
@@ -855,13 +857,14 @@
// if we found a value, we make sure this doesn't reference another value.
// So we resolve it.
if (resValue != null) {
- // put the first default value, before the resolution.
- if (defaultPropMap != null) {
- defaultPropMap.put(attrName, resValue.getValue());
- }
-
+ String preResolve = resValue.getValue();
resValue = mRenderResources.resolveResValue(resValue);
+ if (defaultPropMap != null) {
+ defaultPropMap.put(attrName,
+ new Property(preResolve, resValue.getValue()));
+ }
+
// If the value is a reference to another theme attribute that doesn't
// exist, we should log a warning and omit it.
String val = resValue.getValue();
@@ -949,10 +952,11 @@
if (resValue != null) {
// Add it to defaultPropMap before resolving
- defaultPropMap.put(attrName, resValue.getValue());
+ String preResolve = resValue.getValue();
// resolve it to make sure there are no references left.
- ta.bridgeSetValue(i, attrName, attribute.getSecond(),
- mRenderResources.resolveResValue(resValue));
+ resValue = mRenderResources.resolveResValue(resValue);
+ ta.bridgeSetValue(i, attrName, attribute.getSecond(), resValue);
+ defaultPropMap.put(attrName, new Property(preResolve, resValue.getValue()));
}
}
}
@@ -1915,11 +1919,4 @@
}
}
-
- /**
- * An alias used for the value in {@code {@link #mDefaultPropMaps}}
- */
- private static class PropertiesMap extends HashMap<String, String> {
- }
-
}
diff --git a/bridge/src/com/android/layoutlib/bridge/android/PropertiesMap.java b/bridge/src/com/android/layoutlib/bridge/android/PropertiesMap.java
new file mode 100644
index 0000000..a38d579
--- /dev/null
+++ b/bridge/src/com/android/layoutlib/bridge/android/PropertiesMap.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.layoutlib.bridge.android;
+
+import com.android.layoutlib.bridge.android.PropertiesMap.Property;
+
+import java.util.HashMap;
+
+/**
+ * An alias used for the value in {@link BridgeContext#mDefaultPropMaps}
+ */
+public class PropertiesMap extends HashMap<String, Property> {
+
+ public static class Property {
+ public final String resource;
+ public final String value;
+
+ public Property(String resource, String value) {
+ this.resource = resource;
+ this.value = value;
+ }
+ }
+}
diff --git a/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java b/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java
index 0c53753..2d38831 100644
--- a/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java
+++ b/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java
@@ -286,7 +286,7 @@
return mParams;
}
- protected BridgeContext getContext() {
+ public BridgeContext getContext() {
return mContext;
}
diff --git a/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
index 866b248..11fabc6 100644
--- a/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
+++ b/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
@@ -1415,10 +1415,6 @@
return mSystemViewInfoList;
}
- public Map<String, String> getDefaultProperties(Object viewObject) {
- return getContext().getDefaultPropMap(viewObject);
- }
-
public void setScene(RenderSession session) {
mScene = session;
}