Merge "LayoutLib: Update with the new resource map APIs." into honeycomb
This commit is contained in:
committed by
Android (Google) Code Review
commit
361d614822
@@ -95,7 +95,7 @@ public abstract class Gradient_Delegate extends Shader_Delegate {
|
||||
* Pre-computes the colors for the gradient. This must be called once before any call
|
||||
* to {@link #getGradientColor(float)}
|
||||
*/
|
||||
protected synchronized void precomputeGradientColors() {
|
||||
protected void precomputeGradientColors() {
|
||||
if (mGradient == null) {
|
||||
// actually create an array with an extra size, so that we can really go
|
||||
// from 0 to SIZE (100%), or currentPos in the loop below will never equal 1.0
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.android.layoutlib.bridge.android.BridgeAssetManager;
|
||||
import com.android.layoutlib.bridge.impl.FontLoader;
|
||||
import com.android.layoutlib.bridge.impl.RenderSessionImpl;
|
||||
import com.android.ninepatch.NinePatchChunk;
|
||||
import com.android.resources.ResourceType;
|
||||
import com.android.tools.layoutlib.create.MethodAdapter;
|
||||
import com.android.tools.layoutlib.create.OverrideMethod;
|
||||
|
||||
@@ -410,8 +411,9 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
||||
* @param name the name of the resource.
|
||||
* @return an {@link Integer} containing the resource id, or null if no resource were found.
|
||||
*/
|
||||
public static Integer getResourceValue(String type, String name) {
|
||||
Map<String, Integer> map = sRFullMap.get(type);
|
||||
public static Integer getResourceValue(ResourceType type, String name) {
|
||||
String typeString = type.getName();
|
||||
Map<String, Integer> map = sRFullMap.get(typeString);
|
||||
if (map != null) {
|
||||
return map.get(name);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,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.impl.Stack;
|
||||
import com.android.resources.ResourceType;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
@@ -614,7 +615,7 @@ public final class BridgeContext extends Activity {
|
||||
return null;
|
||||
}
|
||||
|
||||
int getFrameworkResourceValue(String resType, String resName, int defValue) {
|
||||
int getFrameworkResourceValue(ResourceType resType, String resName, int defValue) {
|
||||
Integer value = Bridge.getResourceValue(resType, resName);
|
||||
if (value != null) {
|
||||
return value.intValue();
|
||||
@@ -623,7 +624,7 @@ public final class BridgeContext extends Activity {
|
||||
return defValue;
|
||||
}
|
||||
|
||||
int getProjectResourceValue(String resType, String resName, int defValue) {
|
||||
int getProjectResourceValue(ResourceType resType, String resName, int defValue) {
|
||||
if (mProjectCallback != null) {
|
||||
Integer value = mProjectCallback.getResourceValue(resType, resName);
|
||||
if (value != null) {
|
||||
|
||||
@@ -19,9 +19,9 @@ package com.android.layoutlib.bridge.android;
|
||||
import com.android.ide.common.rendering.api.IProjectCallback;
|
||||
import com.android.ide.common.rendering.api.LayoutLog;
|
||||
import com.android.ide.common.rendering.api.MergeCookie;
|
||||
import com.android.ide.common.rendering.api.RenderResources;
|
||||
import com.android.ide.common.rendering.api.ResourceValue;
|
||||
import com.android.layoutlib.bridge.Bridge;
|
||||
import com.android.resources.ResourceType;
|
||||
|
||||
import org.kxml2.io.KXmlParser;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
@@ -158,13 +158,13 @@ public final class BridgeInflater extends LayoutInflater {
|
||||
String[] layoutInfo = Bridge.resolveResourceValue(resource);
|
||||
if (layoutInfo != null) {
|
||||
value = bridgeContext.getRenderResources().getFrameworkResource(
|
||||
RenderResources.RES_LAYOUT, layoutInfo[0]);
|
||||
ResourceType.LAYOUT, layoutInfo[0]);
|
||||
} else {
|
||||
layoutInfo = mProjectCallback.resolveResourceValue(resource);
|
||||
|
||||
if (layoutInfo != null) {
|
||||
value = bridgeContext.getRenderResources().getProjectResource(
|
||||
RenderResources.RES_LAYOUT, layoutInfo[0]);
|
||||
ResourceType.LAYOUT, layoutInfo[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.android.ide.common.rendering.api.ResourceValue;
|
||||
import com.android.layoutlib.bridge.Bridge;
|
||||
import com.android.layoutlib.bridge.BridgeConstants;
|
||||
import com.android.layoutlib.bridge.impl.ResourceHelper;
|
||||
import com.android.resources.ResourceType;
|
||||
|
||||
import org.kxml2.io.KXmlParser;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
@@ -103,9 +104,14 @@ public final class BridgeResources extends Resources {
|
||||
String[] resourceInfo = Bridge.resolveResourceValue(id);
|
||||
|
||||
if (resourceInfo != null) {
|
||||
ResourceType resType = ResourceType.getEnum(resourceInfo[1]);
|
||||
if (resType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
platformResFlag_out[0] = true;
|
||||
return mContext.getRenderResources().getFrameworkResource(
|
||||
resourceInfo[1], resourceInfo[0]);
|
||||
resType, resourceInfo[0]);
|
||||
}
|
||||
|
||||
// didn't find a match in the framework? look in the project.
|
||||
@@ -113,9 +119,14 @@ public final class BridgeResources extends Resources {
|
||||
resourceInfo = mProjectCallback.resolveResourceValue(id);
|
||||
|
||||
if (resourceInfo != null) {
|
||||
ResourceType resType = ResourceType.getEnum(resourceInfo[1]);
|
||||
if (resType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
platformResFlag_out[0] = false;
|
||||
return mContext.getRenderResources().getProjectResource(
|
||||
resourceInfo[1], resourceInfo[0]);
|
||||
resType, resourceInfo[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.android.internal.util.XmlUtils;
|
||||
import com.android.layoutlib.bridge.Bridge;
|
||||
import com.android.layoutlib.bridge.BridgeConstants;
|
||||
import com.android.layoutlib.bridge.impl.ResourceHelper;
|
||||
import com.android.resources.ResourceType;
|
||||
|
||||
import org.kxml2.io.KXmlParser;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
@@ -39,6 +40,7 @@ import android.view.ViewGroup.LayoutParams;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -587,17 +589,17 @@ public final class BridgeTypedArray extends TypedArray {
|
||||
// then the xml attribute value was "resolved" which leads us to a ResourceValue with a
|
||||
// valid getType() and getName() returning a resource name.
|
||||
// (and getValue() returning null!). We need to handle this!
|
||||
if (resValue.getType() != null && resValue.getType().startsWith("@+") == false) {
|
||||
if (resValue.getResourceType() != null && resValue.getType().startsWith("@+") == false) {
|
||||
// if this is a framework id
|
||||
if (mPlatformFile || resValue.isFramework()) {
|
||||
// look for idName in the android R classes
|
||||
return mContext.getFrameworkResourceValue(
|
||||
resValue.getType(), resValue.getName(), defValue);
|
||||
resValue.getResourceType(), resValue.getName(), defValue);
|
||||
}
|
||||
|
||||
// look for idName in the project R class.
|
||||
return mContext.getProjectResourceValue(
|
||||
resValue.getType(), resValue.getName(), defValue);
|
||||
resValue.getResourceType(), resValue.getName(), defValue);
|
||||
}
|
||||
|
||||
// else, try to get the value, and resolve it somehow.
|
||||
@@ -634,21 +636,22 @@ public final class BridgeTypedArray extends TypedArray {
|
||||
// if this is a framework id
|
||||
if (mPlatformFile || value.startsWith("@android") || value.startsWith("@+android")) {
|
||||
// look for idName in the android R classes
|
||||
return mContext.getFrameworkResourceValue(RenderResources.RES_ID, idName, defValue);
|
||||
return mContext.getFrameworkResourceValue(ResourceType.ID, idName, defValue);
|
||||
}
|
||||
|
||||
// look for idName in the project R class.
|
||||
return mContext.getProjectResourceValue(RenderResources.RES_ID, idName, defValue);
|
||||
return mContext.getProjectResourceValue(ResourceType.ID, idName, defValue);
|
||||
}
|
||||
|
||||
// not a direct id valid reference? resolve it
|
||||
Integer idValue = null;
|
||||
|
||||
if (resValue.isFramework()) {
|
||||
idValue = Bridge.getResourceValue(resValue.getType(), resValue.getName());
|
||||
idValue = Bridge.getResourceValue(resValue.getResourceType(),
|
||||
resValue.getName());
|
||||
} else {
|
||||
idValue = mContext.getProjectCallback().getResourceValue(
|
||||
resValue.getType(), resValue.getName());
|
||||
resValue.getResourceType(), resValue.getName());
|
||||
}
|
||||
|
||||
if (idValue != null) {
|
||||
@@ -796,6 +799,6 @@ public final class BridgeTypedArray extends TypedArray {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mResourceData.toString();
|
||||
return Arrays.toString(mResourceData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.android.ide.common.rendering.api.RenderResources;
|
||||
import com.android.ide.common.rendering.api.ResourceValue;
|
||||
import com.android.layoutlib.bridge.Bridge;
|
||||
import com.android.layoutlib.bridge.BridgeConstants;
|
||||
import com.android.resources.ResourceType;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
@@ -58,7 +59,7 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
|
||||
String ns = mParser.getAttributeNamespace(index);
|
||||
|
||||
if (BridgeConstants.NS_RESOURCES.equals(ns)) {
|
||||
Integer v = Bridge.getResourceValue(RenderResources.RES_ATTR, name);
|
||||
Integer v = Bridge.getResourceValue(ResourceType.ATTR, name);
|
||||
if (v != null) {
|
||||
return v.intValue();
|
||||
}
|
||||
@@ -69,7 +70,7 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
|
||||
// this is not an attribute in the android namespace, we query the customviewloader, if
|
||||
// the namespaces match.
|
||||
if (mContext.getProjectCallback().getNamespace().equals(ns)) {
|
||||
Integer v = mContext.getProjectCallback().getResourceValue(RenderResources.RES_ATTR,
|
||||
Integer v = mContext.getProjectCallback().getResourceValue(ResourceType.ATTR,
|
||||
name);
|
||||
if (v != null) {
|
||||
return v.intValue();
|
||||
@@ -110,10 +111,10 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
|
||||
if (resource != null) {
|
||||
Integer id = null;
|
||||
if (mPlatformFile || resource.isFramework()) {
|
||||
id = Bridge.getResourceValue(resource.getType(), resource.getName());
|
||||
id = Bridge.getResourceValue(resource.getResourceType(), resource.getName());
|
||||
} else {
|
||||
id = mContext.getProjectCallback().getResourceValue(
|
||||
resource.getType(), resource.getName());
|
||||
resource.getResourceType(), resource.getName());
|
||||
}
|
||||
|
||||
if (id != null) {
|
||||
|
||||
@@ -163,7 +163,7 @@ public final class FontLoader {
|
||||
mTtfToFontMap.put(ttf, styleMap);
|
||||
}
|
||||
|
||||
Font f = styleMap.get(style);
|
||||
Font f = styleMap.get(style[0]);
|
||||
|
||||
if (f != null) {
|
||||
return f;
|
||||
|
||||
@@ -48,6 +48,7 @@ import com.android.layoutlib.bridge.android.BridgeWindow;
|
||||
import com.android.layoutlib.bridge.android.BridgeWindowSession;
|
||||
import com.android.layoutlib.bridge.android.BridgeXmlBlockParser;
|
||||
import com.android.resources.Density;
|
||||
import com.android.resources.ResourceType;
|
||||
import com.android.resources.ScreenSize;
|
||||
|
||||
import android.animation.Animator;
|
||||
@@ -566,17 +567,16 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
|
||||
int animationId = 0;
|
||||
if (isFrameworkAnimation) {
|
||||
animationResource = mContext.getRenderResources().getFrameworkResource(
|
||||
RenderResources.RES_ANIMATOR, animationName);
|
||||
ResourceType.ANIMATOR, animationName);
|
||||
if (animationResource != null) {
|
||||
animationId = Bridge.getResourceValue(RenderResources.RES_ANIMATOR,
|
||||
animationName);
|
||||
animationId = Bridge.getResourceValue(ResourceType.ANIMATOR, animationName);
|
||||
}
|
||||
} else {
|
||||
animationResource = mContext.getRenderResources().getProjectResource(
|
||||
RenderResources.RES_ANIMATOR, animationName);
|
||||
ResourceType.ANIMATOR, animationName);
|
||||
if (animationResource != null) {
|
||||
animationId = mContext.getProjectCallback().getResourceValue(
|
||||
RenderResources.RES_ANIMATOR, animationName);
|
||||
ResourceType.ANIMATOR, animationName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1022,7 +1022,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
|
||||
mStatusBarSize = DEFAULT_STATUS_BAR_HEIGHT;
|
||||
|
||||
// get the real value
|
||||
ResourceValue value = resources.getFrameworkResource(RenderResources.RES_DIMEN,
|
||||
ResourceValue value = resources.getFrameworkResource(ResourceType.DIMEN,
|
||||
"status_bar_height");
|
||||
|
||||
if (value != null) {
|
||||
@@ -1110,7 +1110,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
|
||||
mSystemBarSize = 56; // ??
|
||||
|
||||
// get the real value
|
||||
ResourceValue value = resources.getFrameworkResource(RenderResources.RES_DIMEN,
|
||||
ResourceValue value = resources.getFrameworkResource(ResourceType.DIMEN,
|
||||
"status_bar_height");
|
||||
|
||||
if (value != null) {
|
||||
@@ -1309,7 +1309,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
|
||||
// --- FrameworkResourceIdProvider methods
|
||||
|
||||
@Override
|
||||
public Integer getId(String resType, String resName) {
|
||||
public Integer getId(ResourceType resType, String resName) {
|
||||
return Bridge.getResourceValue(resType, resName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ public final class ResourceHelper {
|
||||
*/
|
||||
public static boolean stringToFloat(String s, TypedValue outValue) {
|
||||
// remove the space before and after
|
||||
s.trim();
|
||||
s = s.trim();
|
||||
int len = s.length();
|
||||
|
||||
if (len <= 0) {
|
||||
|
||||
Reference in New Issue
Block a user