diff options
5 files changed, 63 insertions, 46 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java index fea633e7036d..308488a39ec7 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java @@ -70,23 +70,6 @@ public class BridgeRenderSession extends RenderSession { } @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 class BridgeRenderSession extends RenderSession { } } + public RenderSessionImpl getSessionImpl() { + return mSession; + } + /*package*/ BridgeRenderSession(RenderSessionImpl scene, Result lastResult) { mSession = scene; if (scene != null) { 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 89272fa916c1..fd95bd5a0204 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 @@ -27,6 +27,7 @@ import com.android.ide.common.rendering.api.ResourceValue; 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 @@ public final class BridgeContext extends Context { return mRenderResources; } - public Map<String, String> getDefaultPropMap(Object key) { + public PropertiesMap getDefaultPropMap(Object key) { return mDefaultPropMaps.get(key); } @@ -731,16 +732,10 @@ public final class BridgeContext extends Context { 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 @@ public final class BridgeContext extends Context { 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 @@ public final class BridgeContext extends Context { 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 @@ public final class BridgeContext extends Context { // 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. + String preResolve = resValue.getValue(); + resValue = mRenderResources.resolveResValue(resValue); + if (defaultPropMap != null) { - defaultPropMap.put(attrName, resValue.getValue()); + defaultPropMap.put(attrName, + new Property(preResolve, resValue.getValue())); } - resValue = mRenderResources.resolveResValue(resValue); - // 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 @@ public final class BridgeContext extends Context { 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 @@ public final class BridgeContext extends Context { } } - - /** - * An alias used for the value in {@code {@link #mDefaultPropMaps}} - */ - private static class PropertiesMap extends HashMap<String, String> { - } - } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/PropertiesMap.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/PropertiesMap.java new file mode 100644 index 000000000000..a38d579d2b4b --- /dev/null +++ b/tools/layoutlib/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/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java index 0c537533479e..2d388312330b 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java @@ -286,7 +286,7 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso return mParams; } - protected BridgeContext getContext() { + public BridgeContext getContext() { return mContext; } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java index 866b2480b828..11fabc6a59a9 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java @@ -1415,10 +1415,6 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { return mSystemViewInfoList; } - public Map<String, String> getDefaultProperties(Object viewObject) { - return getContext().getDefaultPropMap(viewObject); - } - public void setScene(RenderSession session) { mScene = session; } |