* 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
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;
* @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);
}
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;
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();
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) {
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;
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]);
}
}
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;
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.
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]);
}
}
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;
import java.io.File;
import java.io.FileReader;
+import java.util.Arrays;
import java.util.Map;
/**
// 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.
// 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) {
@Override
public String toString() {
- return mResourceData.toString();
+ return Arrays.toString(mResourceData);
}
}
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;
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();
}
// 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();
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) {
mTtfToFontMap.put(ttf, styleMap);
}
- Font f = styleMap.get(style);
+ Font f = styleMap.get(style[0]);
if (f != null) {
return f;
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;
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);
}
}
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) {
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) {
// --- FrameworkResourceIdProvider methods
@Override
- public Integer getId(String resType, String resName) {
+ public Integer getId(ResourceType resType, String resName) {
return Bridge.getResourceValue(resType, resName);
}
}
*/
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) {