Add post resolve property values

Change-Id: Ia86b7dfc479cc5313cce36b6b3066fbb1d00c292
This commit is contained in:
Deepanshu Gupta
2016-04-12 12:07:40 -07:00
parent 8af20ef6a8
commit 79c59fe4a8
5 changed files with 64 additions and 47 deletions

View File

@@ -69,23 +69,6 @@ public class BridgeRenderSession extends RenderSession {
return mSession.getSystemViewInfos();
}
@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 {
@@ -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) {

View File

@@ -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.
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 @@ 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> {
}
}

View File

@@ -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;
}
}
}

View File

@@ -286,7 +286,7 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso
return mParams;
}
protected BridgeContext getContext() {
public BridgeContext getContext() {
return mContext;
}

View File

@@ -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;
}