Merge "LayoutLib: Update with the new resource map APIs." into honeycomb

This commit is contained in:
Xavier Ducrohet
2011-01-28 12:38:40 -08:00
committed by Android (Google) Code Review
10 changed files with 50 additions and 32 deletions

View File

@@ -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 * Pre-computes the colors for the gradient. This must be called once before any call
* to {@link #getGradientColor(float)} * to {@link #getGradientColor(float)}
*/ */
protected synchronized void precomputeGradientColors() { protected void precomputeGradientColors() {
if (mGradient == null) { if (mGradient == null) {
// actually create an array with an extra size, so that we can really go // 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 // from 0 to SIZE (100%), or currentPos in the loop below will never equal 1.0

View File

@@ -28,6 +28,7 @@ import com.android.layoutlib.bridge.android.BridgeAssetManager;
import com.android.layoutlib.bridge.impl.FontLoader; import com.android.layoutlib.bridge.impl.FontLoader;
import com.android.layoutlib.bridge.impl.RenderSessionImpl; import com.android.layoutlib.bridge.impl.RenderSessionImpl;
import com.android.ninepatch.NinePatchChunk; import com.android.ninepatch.NinePatchChunk;
import com.android.resources.ResourceType;
import com.android.tools.layoutlib.create.MethodAdapter; import com.android.tools.layoutlib.create.MethodAdapter;
import com.android.tools.layoutlib.create.OverrideMethod; 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. * @param name the name of the resource.
* @return an {@link Integer} containing the resource id, or null if no resource were found. * @return an {@link Integer} containing the resource id, or null if no resource were found.
*/ */
public static Integer getResourceValue(String type, String name) { public static Integer getResourceValue(ResourceType type, String name) {
Map<String, Integer> map = sRFullMap.get(type); String typeString = type.getName();
Map<String, Integer> map = sRFullMap.get(typeString);
if (map != null) { if (map != null) {
return map.get(name); return map.get(name);
} }

View File

@@ -24,6 +24,7 @@ import com.android.ide.common.rendering.api.StyleResourceValue;
import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.Stack; import com.android.layoutlib.bridge.impl.Stack;
import com.android.resources.ResourceType;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
@@ -614,7 +615,7 @@ public final class BridgeContext extends Activity {
return null; return null;
} }
int getFrameworkResourceValue(String resType, String resName, int defValue) { int getFrameworkResourceValue(ResourceType resType, String resName, int defValue) {
Integer value = Bridge.getResourceValue(resType, resName); Integer value = Bridge.getResourceValue(resType, resName);
if (value != null) { if (value != null) {
return value.intValue(); return value.intValue();
@@ -623,7 +624,7 @@ public final class BridgeContext extends Activity {
return defValue; return defValue;
} }
int getProjectResourceValue(String resType, String resName, int defValue) { int getProjectResourceValue(ResourceType resType, String resName, int defValue) {
if (mProjectCallback != null) { if (mProjectCallback != null) {
Integer value = mProjectCallback.getResourceValue(resType, resName); Integer value = mProjectCallback.getResourceValue(resType, resName);
if (value != null) { if (value != null) {

View File

@@ -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.IProjectCallback;
import com.android.ide.common.rendering.api.LayoutLog; import com.android.ide.common.rendering.api.LayoutLog;
import com.android.ide.common.rendering.api.MergeCookie; 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.ide.common.rendering.api.ResourceValue;
import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.Bridge;
import com.android.resources.ResourceType;
import org.kxml2.io.KXmlParser; import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
@@ -158,13 +158,13 @@ public final class BridgeInflater extends LayoutInflater {
String[] layoutInfo = Bridge.resolveResourceValue(resource); String[] layoutInfo = Bridge.resolveResourceValue(resource);
if (layoutInfo != null) { if (layoutInfo != null) {
value = bridgeContext.getRenderResources().getFrameworkResource( value = bridgeContext.getRenderResources().getFrameworkResource(
RenderResources.RES_LAYOUT, layoutInfo[0]); ResourceType.LAYOUT, layoutInfo[0]);
} else { } else {
layoutInfo = mProjectCallback.resolveResourceValue(resource); layoutInfo = mProjectCallback.resolveResourceValue(resource);
if (layoutInfo != null) { if (layoutInfo != null) {
value = bridgeContext.getRenderResources().getProjectResource( value = bridgeContext.getRenderResources().getProjectResource(
RenderResources.RES_LAYOUT, layoutInfo[0]); ResourceType.LAYOUT, layoutInfo[0]);
} }
} }

View File

@@ -22,6 +22,7 @@ import com.android.ide.common.rendering.api.ResourceValue;
import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.ResourceHelper; import com.android.layoutlib.bridge.impl.ResourceHelper;
import com.android.resources.ResourceType;
import org.kxml2.io.KXmlParser; import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
@@ -103,9 +104,14 @@ public final class BridgeResources extends Resources {
String[] resourceInfo = Bridge.resolveResourceValue(id); String[] resourceInfo = Bridge.resolveResourceValue(id);
if (resourceInfo != null) { if (resourceInfo != null) {
ResourceType resType = ResourceType.getEnum(resourceInfo[1]);
if (resType == null) {
return null;
}
platformResFlag_out[0] = true; platformResFlag_out[0] = true;
return mContext.getRenderResources().getFrameworkResource( return mContext.getRenderResources().getFrameworkResource(
resourceInfo[1], resourceInfo[0]); resType, resourceInfo[0]);
} }
// didn't find a match in the framework? look in the project. // 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); resourceInfo = mProjectCallback.resolveResourceValue(id);
if (resourceInfo != null) { if (resourceInfo != null) {
ResourceType resType = ResourceType.getEnum(resourceInfo[1]);
if (resType == null) {
return null;
}
platformResFlag_out[0] = false; platformResFlag_out[0] = false;
return mContext.getRenderResources().getProjectResource( return mContext.getRenderResources().getProjectResource(
resourceInfo[1], resourceInfo[0]); resType, resourceInfo[0]);
} }
} }

View File

@@ -24,6 +24,7 @@ import com.android.internal.util.XmlUtils;
import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.ResourceHelper; import com.android.layoutlib.bridge.impl.ResourceHelper;
import com.android.resources.ResourceType;
import org.kxml2.io.KXmlParser; import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
@@ -39,6 +40,7 @@ import android.view.ViewGroup.LayoutParams;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.util.Arrays;
import java.util.Map; 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 // then the xml attribute value was "resolved" which leads us to a ResourceValue with a
// valid getType() and getName() returning a resource name. // valid getType() and getName() returning a resource name.
// (and getValue() returning null!). We need to handle this! // (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 this is a framework id
if (mPlatformFile || resValue.isFramework()) { if (mPlatformFile || resValue.isFramework()) {
// look for idName in the android R classes // look for idName in the android R classes
return mContext.getFrameworkResourceValue( return mContext.getFrameworkResourceValue(
resValue.getType(), resValue.getName(), defValue); resValue.getResourceType(), resValue.getName(), defValue);
} }
// look for idName in the project R class. // look for idName in the project R class.
return mContext.getProjectResourceValue( return mContext.getProjectResourceValue(
resValue.getType(), resValue.getName(), defValue); resValue.getResourceType(), resValue.getName(), defValue);
} }
// else, try to get the value, and resolve it somehow. // 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 this is a framework id
if (mPlatformFile || value.startsWith("@android") || value.startsWith("@+android")) { if (mPlatformFile || value.startsWith("@android") || value.startsWith("@+android")) {
// look for idName in the android R classes // 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. // 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 // not a direct id valid reference? resolve it
Integer idValue = null; Integer idValue = null;
if (resValue.isFramework()) { if (resValue.isFramework()) {
idValue = Bridge.getResourceValue(resValue.getType(), resValue.getName()); idValue = Bridge.getResourceValue(resValue.getResourceType(),
resValue.getName());
} else { } else {
idValue = mContext.getProjectCallback().getResourceValue( idValue = mContext.getProjectCallback().getResourceValue(
resValue.getType(), resValue.getName()); resValue.getResourceType(), resValue.getName());
} }
if (idValue != null) { if (idValue != null) {
@@ -796,6 +799,6 @@ public final class BridgeTypedArray extends TypedArray {
@Override @Override
public String toString() { public String toString() {
return mResourceData.toString(); return Arrays.toString(mResourceData);
} }
} }

View File

@@ -20,6 +20,7 @@ import com.android.ide.common.rendering.api.RenderResources;
import com.android.ide.common.rendering.api.ResourceValue; import com.android.ide.common.rendering.api.ResourceValue;
import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.BridgeConstants;
import com.android.resources.ResourceType;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
@@ -58,7 +59,7 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
String ns = mParser.getAttributeNamespace(index); String ns = mParser.getAttributeNamespace(index);
if (BridgeConstants.NS_RESOURCES.equals(ns)) { if (BridgeConstants.NS_RESOURCES.equals(ns)) {
Integer v = Bridge.getResourceValue(RenderResources.RES_ATTR, name); Integer v = Bridge.getResourceValue(ResourceType.ATTR, name);
if (v != null) { if (v != null) {
return v.intValue(); 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 // this is not an attribute in the android namespace, we query the customviewloader, if
// the namespaces match. // the namespaces match.
if (mContext.getProjectCallback().getNamespace().equals(ns)) { if (mContext.getProjectCallback().getNamespace().equals(ns)) {
Integer v = mContext.getProjectCallback().getResourceValue(RenderResources.RES_ATTR, Integer v = mContext.getProjectCallback().getResourceValue(ResourceType.ATTR,
name); name);
if (v != null) { if (v != null) {
return v.intValue(); return v.intValue();
@@ -110,10 +111,10 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
if (resource != null) { if (resource != null) {
Integer id = null; Integer id = null;
if (mPlatformFile || resource.isFramework()) { if (mPlatformFile || resource.isFramework()) {
id = Bridge.getResourceValue(resource.getType(), resource.getName()); id = Bridge.getResourceValue(resource.getResourceType(), resource.getName());
} else { } else {
id = mContext.getProjectCallback().getResourceValue( id = mContext.getProjectCallback().getResourceValue(
resource.getType(), resource.getName()); resource.getResourceType(), resource.getName());
} }
if (id != null) { if (id != null) {

View File

@@ -163,7 +163,7 @@ public final class FontLoader {
mTtfToFontMap.put(ttf, styleMap); mTtfToFontMap.put(ttf, styleMap);
} }
Font f = styleMap.get(style); Font f = styleMap.get(style[0]);
if (f != null) { if (f != null) {
return f; return f;

View File

@@ -48,6 +48,7 @@ import com.android.layoutlib.bridge.android.BridgeWindow;
import com.android.layoutlib.bridge.android.BridgeWindowSession; import com.android.layoutlib.bridge.android.BridgeWindowSession;
import com.android.layoutlib.bridge.android.BridgeXmlBlockParser; import com.android.layoutlib.bridge.android.BridgeXmlBlockParser;
import com.android.resources.Density; import com.android.resources.Density;
import com.android.resources.ResourceType;
import com.android.resources.ScreenSize; import com.android.resources.ScreenSize;
import android.animation.Animator; import android.animation.Animator;
@@ -566,17 +567,16 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
int animationId = 0; int animationId = 0;
if (isFrameworkAnimation) { if (isFrameworkAnimation) {
animationResource = mContext.getRenderResources().getFrameworkResource( animationResource = mContext.getRenderResources().getFrameworkResource(
RenderResources.RES_ANIMATOR, animationName); ResourceType.ANIMATOR, animationName);
if (animationResource != null) { if (animationResource != null) {
animationId = Bridge.getResourceValue(RenderResources.RES_ANIMATOR, animationId = Bridge.getResourceValue(ResourceType.ANIMATOR, animationName);
animationName);
} }
} else { } else {
animationResource = mContext.getRenderResources().getProjectResource( animationResource = mContext.getRenderResources().getProjectResource(
RenderResources.RES_ANIMATOR, animationName); ResourceType.ANIMATOR, animationName);
if (animationResource != null) { if (animationResource != null) {
animationId = mContext.getProjectCallback().getResourceValue( 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; mStatusBarSize = DEFAULT_STATUS_BAR_HEIGHT;
// get the real value // get the real value
ResourceValue value = resources.getFrameworkResource(RenderResources.RES_DIMEN, ResourceValue value = resources.getFrameworkResource(ResourceType.DIMEN,
"status_bar_height"); "status_bar_height");
if (value != null) { if (value != null) {
@@ -1110,7 +1110,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
mSystemBarSize = 56; // ?? mSystemBarSize = 56; // ??
// get the real value // get the real value
ResourceValue value = resources.getFrameworkResource(RenderResources.RES_DIMEN, ResourceValue value = resources.getFrameworkResource(ResourceType.DIMEN,
"status_bar_height"); "status_bar_height");
if (value != null) { if (value != null) {
@@ -1309,7 +1309,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
// --- FrameworkResourceIdProvider methods // --- FrameworkResourceIdProvider methods
@Override @Override
public Integer getId(String resType, String resName) { public Integer getId(ResourceType resType, String resName) {
return Bridge.getResourceValue(resType, resName); return Bridge.getResourceValue(resType, resName);
} }
} }

View File

@@ -298,7 +298,7 @@ public final class ResourceHelper {
*/ */
public static boolean stringToFloat(String s, TypedValue outValue) { public static boolean stringToFloat(String s, TypedValue outValue) {
// remove the space before and after // remove the space before and after
s.trim(); s = s.trim();
int len = s.length(); int len = s.length();
if (len <= 0) { if (len <= 0) {