Cherry-pick 9b53dd9d60 from master
Change-Id: I670872542feb62c47fe693eb183b19e2eef2b20d LayoutLib: use new API with log in init method.
This commit is contained in:
@@ -180,12 +180,9 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
return mCapabilities;
|
return mCapabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see com.android.layoutlib.api.ILayoutLibBridge#init(java.io.File, java.util.Map)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean init(File fontLocation, Map<String, Map<String, Integer>> enumValueMap) {
|
public boolean init(File fontLocation, Map<String, Map<String, Integer>> enumValueMap,
|
||||||
|
LayoutLog log) {
|
||||||
sEnumValueMap = enumValueMap;
|
sEnumValueMap = enumValueMap;
|
||||||
|
|
||||||
// don't use EnumSet.allOf(), because the bridge doesn't come with its specific version
|
// don't use EnumSet.allOf(), because the bridge doesn't come with its specific version
|
||||||
@@ -242,11 +239,6 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
// now parse com.android.internal.R (and only this one as android.R is a subset of
|
// now parse com.android.internal.R (and only this one as android.R is a subset of
|
||||||
// the internal version), and put the content in the maps.
|
// the internal version), and put the content in the maps.
|
||||||
try {
|
try {
|
||||||
// WARNING: this only works because the class is already loaded, and therefore
|
|
||||||
// the objects returned by Field.get() are the same as the ones used by
|
|
||||||
// the code accessing the R class.
|
|
||||||
// int[] does not implement equals/hashCode, and if the parsing used a different class
|
|
||||||
// loader for the R class, this would NOT work.
|
|
||||||
Class<?> r = com.android.internal.R.class;
|
Class<?> r = com.android.internal.R.class;
|
||||||
|
|
||||||
for (Class<?> inner : r.getDeclaredClasses()) {
|
for (Class<?> inner : r.getDeclaredClasses()) {
|
||||||
@@ -262,7 +254,9 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
if (Modifier.isStatic(modifiers)) {
|
if (Modifier.isStatic(modifiers)) {
|
||||||
Class<?> type = f.getType();
|
Class<?> type = f.getType();
|
||||||
if (type.isArray() && type.getComponentType() == int.class) {
|
if (type.isArray() && type.getComponentType() == int.class) {
|
||||||
// if the object is an int[] we put it in sRArrayMap
|
// if the object is an int[] we put it in sRArrayMap using an IntArray
|
||||||
|
// wrapper that properly implements equals and hashcode for the array
|
||||||
|
// objects, as required by the map contract.
|
||||||
sRArrayMap.put(new IntArray((int[]) f.get(null)), f.getName());
|
sRArrayMap.put(new IntArray((int[]) f.get(null)), f.getName());
|
||||||
} else if (type == int.class) {
|
} else if (type == int.class) {
|
||||||
Integer value = (Integer) f.get(null);
|
Integer value = (Integer) f.get(null);
|
||||||
@@ -274,12 +268,12 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (Throwable throwable) {
|
||||||
// FIXME: log/return the error (there's no logger object at this point!)
|
if (log != null) {
|
||||||
e.printStackTrace();
|
log.error(null,
|
||||||
return false;
|
"Failed to load com.android.internal.R from the layout library jar",
|
||||||
} catch (IllegalAccessException e) {
|
throwable);
|
||||||
e.printStackTrace();
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user