Merge "LayoutLib: update with Pair API." into honeycomb
This commit is contained in:
committed by
Android (Google) Code Review
commit
f597f75039
@@ -8,6 +8,6 @@
|
|||||||
<classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/kxml2/kxml2-2.3.0.jar" sourcepath="/ANDROID_PLAT_SRC/dalvik/libcore/xml/src/main/java"/>
|
<classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/kxml2/kxml2-2.3.0.jar" sourcepath="/ANDROID_PLAT_SRC/dalvik/libcore/xml/src/main/java"/>
|
||||||
<classpathentry kind="var" path="ANDROID_PLAT_SRC/out/host/common/obj/JAVA_LIBRARIES/temp_layoutlib_intermediates/javalib.jar" sourcepath="/ANDROID_PLAT_SRC/frameworks/base"/>
|
<classpathentry kind="var" path="ANDROID_PLAT_SRC/out/host/common/obj/JAVA_LIBRARIES/temp_layoutlib_intermediates/javalib.jar" sourcepath="/ANDROID_PLAT_SRC/frameworks/base"/>
|
||||||
<classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/ninepatch/ninepatch-prebuilt.jar"/>
|
<classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/ninepatch/ninepatch-prebuilt.jar"/>
|
||||||
<classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/resources/resources-prebuilt.jar"/>
|
<classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/common/common-prebuilt.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ LOCAL_SRC_FILES := $(call all-java-files-under,src)
|
|||||||
LOCAL_JAVA_LIBRARIES := \
|
LOCAL_JAVA_LIBRARIES := \
|
||||||
kxml2-2.3.0 \
|
kxml2-2.3.0 \
|
||||||
layoutlib_api-prebuilt \
|
layoutlib_api-prebuilt \
|
||||||
resources-prebuilt
|
common-prebuilt
|
||||||
|
|
||||||
LOCAL_STATIC_JAVA_LIBRARIES := \
|
LOCAL_STATIC_JAVA_LIBRARIES := \
|
||||||
temp_layoutlib \
|
temp_layoutlib \
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import com.android.ninepatch.NinePatchChunk;
|
|||||||
import com.android.resources.ResourceType;
|
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;
|
||||||
|
import com.android.util.Pair;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
@@ -42,6 +43,7 @@ import java.lang.ref.SoftReference;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.EnumMap;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -69,9 +71,11 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
private final static ReentrantLock sLock = new ReentrantLock();
|
private final static ReentrantLock sLock = new ReentrantLock();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps from id to resource name/type. This is for android.R only.
|
* Maps from id to resource type/name. This is for android.R only.
|
||||||
*/
|
*/
|
||||||
private final static Map<Integer, String[]> sRMap = new HashMap<Integer, String[]>();
|
private final static Map<Integer, Pair<ResourceType, String>> sRMap =
|
||||||
|
new HashMap<Integer, Pair<ResourceType, String>>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as sRMap except for int[] instead of int resources. This is for android.R only.
|
* Same as sRMap except for int[] instead of int resources. This is for android.R only.
|
||||||
*/
|
*/
|
||||||
@@ -80,8 +84,8 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
* Reverse map compared to sRMap, resource type -> (resource name -> id).
|
* Reverse map compared to sRMap, resource type -> (resource name -> id).
|
||||||
* This is for android.R only.
|
* This is for android.R only.
|
||||||
*/
|
*/
|
||||||
private final static Map<String, Map<String, Integer>> sRFullMap =
|
private final static Map<ResourceType, Map<String, Integer>> sRFullMap =
|
||||||
new HashMap<String, Map<String,Integer>>();
|
new EnumMap<ResourceType, Map<String,Integer>>(ResourceType.class);
|
||||||
|
|
||||||
private final static Map<Object, Map<String, SoftReference<Bitmap>>> sProjectBitmapCache =
|
private final static Map<Object, Map<String, SoftReference<Bitmap>>> sProjectBitmapCache =
|
||||||
new HashMap<Object, Map<String, SoftReference<Bitmap>>>();
|
new HashMap<Object, Map<String, SoftReference<Bitmap>>>();
|
||||||
@@ -131,7 +135,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Instance of IntArrayWrapper to be reused in {@link #resolveResourceValue(int[])}. */
|
/** Instance of IntArrayWrapper to be reused in {@link #resolveResourceId(int[])}. */
|
||||||
private final static IntArray sIntArrayWrapper = new IntArray();
|
private final static IntArray sIntArrayWrapper = new IntArray();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -237,28 +241,30 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
Class<?> r = com.android.internal.R.class;
|
Class<?> r = com.android.internal.R.class;
|
||||||
|
|
||||||
for (Class<?> inner : r.getDeclaredClasses()) {
|
for (Class<?> inner : r.getDeclaredClasses()) {
|
||||||
String resType = inner.getSimpleName();
|
String resTypeName = inner.getSimpleName();
|
||||||
|
ResourceType resType = ResourceType.getEnum(resTypeName);
|
||||||
|
if (resType != null) {
|
||||||
|
Map<String, Integer> fullMap = new HashMap<String, Integer>();
|
||||||
|
sRFullMap.put(resType, fullMap);
|
||||||
|
|
||||||
Map<String, Integer> fullMap = new HashMap<String, Integer>();
|
for (Field f : inner.getDeclaredFields()) {
|
||||||
sRFullMap.put(resType, fullMap);
|
// only process static final fields. Since the final attribute may have
|
||||||
|
// been altered by layoutlib_create, we only check static
|
||||||
for (Field f : inner.getDeclaredFields()) {
|
int modifiers = f.getModifiers();
|
||||||
// only process static final fields. Since the final attribute may have
|
if (Modifier.isStatic(modifiers)) {
|
||||||
// been altered by layoutlib_create, we only check static
|
Class<?> type = f.getType();
|
||||||
int modifiers = f.getModifiers();
|
if (type.isArray() && type.getComponentType() == int.class) {
|
||||||
if (Modifier.isStatic(modifiers)) {
|
// if the object is an int[] we put it in sRArrayMap using an IntArray
|
||||||
Class<?> type = f.getType();
|
// wrapper that properly implements equals and hashcode for the array
|
||||||
if (type.isArray() && type.getComponentType() == int.class) {
|
// objects, as required by the map contract.
|
||||||
// if the object is an int[] we put it in sRArrayMap using an IntArray
|
sRArrayMap.put(new IntArray((int[]) f.get(null)), f.getName());
|
||||||
// wrapper that properly implements equals and hashcode for the array
|
} else if (type == int.class) {
|
||||||
// objects, as required by the map contract.
|
Integer value = (Integer) f.get(null);
|
||||||
sRArrayMap.put(new IntArray((int[]) f.get(null)), f.getName());
|
sRMap.put(value, Pair.of(resType, f.getName()));
|
||||||
} else if (type == int.class) {
|
fullMap.put(f.getName(), value);
|
||||||
Integer value = (Integer) f.get(null);
|
} else {
|
||||||
sRMap.put(value, new String[] { f.getName(), resType });
|
assert false;
|
||||||
fullMap.put(f.getName(), value);
|
}
|
||||||
} else {
|
|
||||||
assert false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -389,10 +395,10 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
/**
|
/**
|
||||||
* Returns details of a framework resource from its integer value.
|
* Returns details of a framework resource from its integer value.
|
||||||
* @param value the integer value
|
* @param value the integer value
|
||||||
* @return an array of 2 strings containing the resource name and type, or null if the id
|
* @return a Pair containing the resource type and name, or null if the id
|
||||||
* does not match any resource.
|
* does not match any resource.
|
||||||
*/
|
*/
|
||||||
public static String[] resolveResourceValue(int value) {
|
public static Pair<ResourceType, String> resolveResourceId(int value) {
|
||||||
return sRMap.get(value);
|
return sRMap.get(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,7 +406,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
* Returns the name of a framework resource whose value is an int array.
|
* Returns the name of a framework resource whose value is an int array.
|
||||||
* @param array
|
* @param array
|
||||||
*/
|
*/
|
||||||
public static String resolveResourceValue(int[] array) {
|
public static String resolveResourceId(int[] array) {
|
||||||
sIntArrayWrapper.set(array);
|
sIntArrayWrapper.set(array);
|
||||||
return sRArrayMap.get(sIntArrayWrapper);
|
return sRArrayMap.get(sIntArrayWrapper);
|
||||||
}
|
}
|
||||||
@@ -411,9 +417,8 @@ 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(ResourceType type, String name) {
|
public static Integer getResourceId(ResourceType type, String name) {
|
||||||
String typeString = type.getName();
|
Map<String, Integer> map = sRFullMap.get(type);
|
||||||
Map<String, Integer> map = sRFullMap.get(typeString);
|
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
return map.get(name);
|
return map.get(name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ 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 com.android.resources.ResourceType;
|
||||||
|
import com.android.util.Pair;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
@@ -518,14 +519,14 @@ public final class BridgeContext extends Activity {
|
|||||||
*/
|
*/
|
||||||
private TreeMap<Integer,String> searchAttrs(int[] attrs, boolean[] outFrameworkFlag) {
|
private TreeMap<Integer,String> searchAttrs(int[] attrs, boolean[] outFrameworkFlag) {
|
||||||
// get the name of the array from the framework resources
|
// get the name of the array from the framework resources
|
||||||
String arrayName = Bridge.resolveResourceValue(attrs);
|
String arrayName = Bridge.resolveResourceId(attrs);
|
||||||
if (arrayName != null) {
|
if (arrayName != null) {
|
||||||
// if we found it, get the name of each of the int in the array.
|
// if we found it, get the name of each of the int in the array.
|
||||||
TreeMap<Integer,String> attributes = new TreeMap<Integer, String>();
|
TreeMap<Integer,String> attributes = new TreeMap<Integer, String>();
|
||||||
for (int i = 0 ; i < attrs.length ; i++) {
|
for (int i = 0 ; i < attrs.length ; i++) {
|
||||||
String[] info = Bridge.resolveResourceValue(attrs[i]);
|
Pair<ResourceType, String> info = Bridge.resolveResourceId(attrs[i]);
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
attributes.put(i, info[0]);
|
attributes.put(i, info.getSecond());
|
||||||
} else {
|
} else {
|
||||||
// FIXME Not sure what we should be doing here...
|
// FIXME Not sure what we should be doing here...
|
||||||
attributes.put(i, null);
|
attributes.put(i, null);
|
||||||
@@ -541,13 +542,13 @@ public final class BridgeContext extends Activity {
|
|||||||
|
|
||||||
// if the name was not found in the framework resources, look in the project
|
// if the name was not found in the framework resources, look in the project
|
||||||
// resources
|
// resources
|
||||||
arrayName = mProjectCallback.resolveResourceValue(attrs);
|
arrayName = mProjectCallback.resolveResourceId(attrs);
|
||||||
if (arrayName != null) {
|
if (arrayName != null) {
|
||||||
TreeMap<Integer,String> attributes = new TreeMap<Integer, String>();
|
TreeMap<Integer,String> attributes = new TreeMap<Integer, String>();
|
||||||
for (int i = 0 ; i < attrs.length ; i++) {
|
for (int i = 0 ; i < attrs.length ; i++) {
|
||||||
String[] info = mProjectCallback.resolveResourceValue(attrs[i]);
|
Pair<ResourceType, String> info = mProjectCallback.resolveResourceId(attrs[i]);
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
attributes.put(i, info[0]);
|
attributes.put(i, info.getSecond());
|
||||||
} else {
|
} else {
|
||||||
// FIXME Not sure what we should be doing here...
|
// FIXME Not sure what we should be doing here...
|
||||||
attributes.put(i, null);
|
attributes.put(i, null);
|
||||||
@@ -572,14 +573,14 @@ public final class BridgeContext extends Activity {
|
|||||||
* if nothing is found.
|
* if nothing is found.
|
||||||
*/
|
*/
|
||||||
public String searchAttr(int attr) {
|
public String searchAttr(int attr) {
|
||||||
String[] info = Bridge.resolveResourceValue(attr);
|
Pair<ResourceType, String> info = Bridge.resolveResourceId(attr);
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
return info[0];
|
return info.getSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
info = mProjectCallback.resolveResourceValue(attr);
|
info = mProjectCallback.resolveResourceId(attr);
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
return info[0];
|
return info.getSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -616,7 +617,7 @@ public final class BridgeContext extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int getFrameworkResourceValue(ResourceType resType, String resName, int defValue) {
|
int getFrameworkResourceValue(ResourceType resType, String resName, int defValue) {
|
||||||
Integer value = Bridge.getResourceValue(resType, resName);
|
Integer value = Bridge.getResourceId(resType, resName);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
return value.intValue();
|
return value.intValue();
|
||||||
}
|
}
|
||||||
@@ -626,7 +627,7 @@ public final class BridgeContext extends Activity {
|
|||||||
|
|
||||||
int getProjectResourceValue(ResourceType 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.getResourceId(resType, resName);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
return value.intValue();
|
return value.intValue();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.android.ide.common.rendering.api.MergeCookie;
|
|||||||
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 com.android.resources.ResourceType;
|
||||||
|
import com.android.util.Pair;
|
||||||
|
|
||||||
import org.kxml2.io.KXmlParser;
|
import org.kxml2.io.KXmlParser;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
@@ -155,16 +156,16 @@ public final class BridgeInflater extends LayoutInflater {
|
|||||||
|
|
||||||
ResourceValue value = null;
|
ResourceValue value = null;
|
||||||
|
|
||||||
String[] layoutInfo = Bridge.resolveResourceValue(resource);
|
Pair<ResourceType, String> layoutInfo = Bridge.resolveResourceId(resource);
|
||||||
if (layoutInfo != null) {
|
if (layoutInfo != null) {
|
||||||
value = bridgeContext.getRenderResources().getFrameworkResource(
|
value = bridgeContext.getRenderResources().getFrameworkResource(
|
||||||
ResourceType.LAYOUT, layoutInfo[0]);
|
ResourceType.LAYOUT, layoutInfo.getSecond());
|
||||||
} else {
|
} else {
|
||||||
layoutInfo = mProjectCallback.resolveResourceValue(resource);
|
layoutInfo = mProjectCallback.resolveResourceId(resource);
|
||||||
|
|
||||||
if (layoutInfo != null) {
|
if (layoutInfo != null) {
|
||||||
value = bridgeContext.getRenderResources().getProjectResource(
|
value = bridgeContext.getRenderResources().getProjectResource(
|
||||||
ResourceType.LAYOUT, layoutInfo[0]);
|
ResourceType.LAYOUT, layoutInfo.getSecond());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ 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 com.android.resources.ResourceType;
|
||||||
|
import com.android.util.Pair;
|
||||||
|
|
||||||
import org.kxml2.io.KXmlParser;
|
import org.kxml2.io.KXmlParser;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
@@ -101,32 +102,22 @@ public final class BridgeResources extends Resources {
|
|||||||
|
|
||||||
private ResourceValue getResourceValue(int id, boolean[] platformResFlag_out) {
|
private ResourceValue getResourceValue(int id, boolean[] platformResFlag_out) {
|
||||||
// first get the String related to this id in the framework
|
// first get the String related to this id in the framework
|
||||||
String[] resourceInfo = Bridge.resolveResourceValue(id);
|
Pair<ResourceType, String> resourceInfo = Bridge.resolveResourceId(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(
|
||||||
resType, resourceInfo[0]);
|
resourceInfo.getFirst(), resourceInfo.getSecond());
|
||||||
}
|
}
|
||||||
|
|
||||||
// didn't find a match in the framework? look in the project.
|
// didn't find a match in the framework? look in the project.
|
||||||
if (mProjectCallback != null) {
|
if (mProjectCallback != null) {
|
||||||
resourceInfo = mProjectCallback.resolveResourceValue(id);
|
resourceInfo = mProjectCallback.resolveResourceId(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(
|
||||||
resType, resourceInfo[0]);
|
resourceInfo.getFirst(), resourceInfo.getSecond());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -625,18 +616,18 @@ public final class BridgeResources extends Resources {
|
|||||||
*/
|
*/
|
||||||
private void throwException(int id) throws NotFoundException {
|
private void throwException(int id) throws NotFoundException {
|
||||||
// first get the String related to this id in the framework
|
// first get the String related to this id in the framework
|
||||||
String[] resourceInfo = Bridge.resolveResourceValue(id);
|
Pair<ResourceType, String> resourceInfo = Bridge.resolveResourceId(id);
|
||||||
|
|
||||||
// if the name is unknown in the framework, get it from the custom view loader.
|
// if the name is unknown in the framework, get it from the custom view loader.
|
||||||
if (resourceInfo == null && mProjectCallback != null) {
|
if (resourceInfo == null && mProjectCallback != null) {
|
||||||
resourceInfo = mProjectCallback.resolveResourceValue(id);
|
resourceInfo = mProjectCallback.resolveResourceId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
String message = null;
|
String message = null;
|
||||||
if (resourceInfo != null) {
|
if (resourceInfo != null) {
|
||||||
message = String.format(
|
message = String.format(
|
||||||
"Could not find %1$s resource matching value 0x%2$X (resolved name: %3$s) in current configuration.",
|
"Could not find %1$s resource matching value 0x%2$X (resolved name: %3$s) in current configuration.",
|
||||||
resourceInfo[1], id, resourceInfo[0]);
|
resourceInfo.getFirst(), id, resourceInfo.getSecond());
|
||||||
} else {
|
} else {
|
||||||
message = String.format(
|
message = String.format(
|
||||||
"Could not resolve resource value: 0x%1$X.", id);
|
"Could not resolve resource value: 0x%1$X.", id);
|
||||||
|
|||||||
@@ -589,7 +589,7 @@ 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.getResourceType() != null && resValue.getType().startsWith("@+") == false) {
|
if (resValue.getResourceType() != null) {
|
||||||
// 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
|
||||||
@@ -647,10 +647,10 @@ public final class BridgeTypedArray extends TypedArray {
|
|||||||
Integer idValue = null;
|
Integer idValue = null;
|
||||||
|
|
||||||
if (resValue.isFramework()) {
|
if (resValue.isFramework()) {
|
||||||
idValue = Bridge.getResourceValue(resValue.getResourceType(),
|
idValue = Bridge.getResourceId(resValue.getResourceType(),
|
||||||
resValue.getName());
|
resValue.getName());
|
||||||
} else {
|
} else {
|
||||||
idValue = mContext.getProjectCallback().getResourceValue(
|
idValue = mContext.getProjectCallback().getResourceId(
|
||||||
resValue.getResourceType(), resValue.getName());
|
resValue.getResourceType(), resValue.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,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(ResourceType.ATTR, name);
|
Integer v = Bridge.getResourceId(ResourceType.ATTR, name);
|
||||||
if (v != null) {
|
if (v != null) {
|
||||||
return v.intValue();
|
return v.intValue();
|
||||||
}
|
}
|
||||||
@@ -70,8 +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(ResourceType.ATTR,
|
Integer v = mContext.getProjectCallback().getResourceId(ResourceType.ATTR, name);
|
||||||
name);
|
|
||||||
if (v != null) {
|
if (v != null) {
|
||||||
return v.intValue();
|
return v.intValue();
|
||||||
}
|
}
|
||||||
@@ -111,9 +110,9 @@ 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.getResourceType(), resource.getName());
|
id = Bridge.getResourceId(resource.getResourceType(), resource.getName());
|
||||||
} else {
|
} else {
|
||||||
id = mContext.getProjectCallback().getResourceValue(
|
id = mContext.getProjectCallback().getResourceId(
|
||||||
resource.getResourceType(), resource.getName());
|
resource.getResourceType(), resource.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ 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.ResourceType;
|
||||||
import com.android.resources.ScreenSize;
|
import com.android.resources.ScreenSize;
|
||||||
|
import com.android.util.Pair;
|
||||||
|
|
||||||
import android.animation.Animator;
|
import android.animation.Animator;
|
||||||
import android.animation.AnimatorInflater;
|
import android.animation.AnimatorInflater;
|
||||||
@@ -569,13 +570,13 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
|
|||||||
animationResource = mContext.getRenderResources().getFrameworkResource(
|
animationResource = mContext.getRenderResources().getFrameworkResource(
|
||||||
ResourceType.ANIMATOR, animationName);
|
ResourceType.ANIMATOR, animationName);
|
||||||
if (animationResource != null) {
|
if (animationResource != null) {
|
||||||
animationId = Bridge.getResourceValue(ResourceType.ANIMATOR, animationName);
|
animationId = Bridge.getResourceId(ResourceType.ANIMATOR, animationName);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
animationResource = mContext.getRenderResources().getProjectResource(
|
animationResource = mContext.getRenderResources().getProjectResource(
|
||||||
ResourceType.ANIMATOR, animationName);
|
ResourceType.ANIMATOR, animationName);
|
||||||
if (animationResource != null) {
|
if (animationResource != null) {
|
||||||
animationId = mContext.getProjectCallback().getResourceValue(
|
animationId = mContext.getProjectCallback().getResourceId(
|
||||||
ResourceType.ANIMATOR, animationName);
|
ResourceType.ANIMATOR, animationName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1227,10 +1228,10 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
|
|||||||
View child = content.getChildAt(i);
|
View child = content.getChildAt(i);
|
||||||
String tabSpec = String.format("tab_spec%d", i+1);
|
String tabSpec = String.format("tab_spec%d", i+1);
|
||||||
int id = child.getId();
|
int id = child.getId();
|
||||||
String[] resource = projectCallback.resolveResourceValue(id);
|
Pair<ResourceType, String> resource = projectCallback.resolveResourceId(id);
|
||||||
String name;
|
String name;
|
||||||
if (resource != null) {
|
if (resource != null) {
|
||||||
name = resource[0]; // 0 is resource name, 1 is resource type.
|
name = resource.getSecond();
|
||||||
} else {
|
} else {
|
||||||
name = String.format("Tab %d", i+1); // default name if id is unresolved.
|
name = String.format("Tab %d", i+1); // default name if id is unresolved.
|
||||||
}
|
}
|
||||||
@@ -1310,6 +1311,6 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getId(ResourceType resType, String resName) {
|
public Integer getId(ResourceType resType, String resName) {
|
||||||
return Bridge.getResourceValue(resType, resName);
|
return Bridge.getResourceId(resType, resName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,7 +197,8 @@ public final class ResourceHelper {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// this is an error and not warning since the file existence is checked before
|
// this is an error and not warning since the file existence is checked before
|
||||||
// attempting to parse it.
|
// attempting to parse it.
|
||||||
Bridge.getLog().error(null, "Failed to parse file " + value, e, null /*data*/);
|
Bridge.getLog().error(null, "Failed to parse file " + stringValue,
|
||||||
|
e, null /*data*/);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Bridge.getLog().error(LayoutLog.TAG_BROKEN,
|
Bridge.getLog().error(LayoutLog.TAG_BROKEN,
|
||||||
|
|||||||
Reference in New Issue
Block a user