use of com.android.tools.layoutlib.create.MethodAdapter in project android_frameworks_base by ResurrectionRemix.
the class Bridge method init.
@Override
public boolean init(Map<String, String> platformProperties, File fontLocation, Map<String, Map<String, Integer>> enumValueMap, LayoutLog log) {
sPlatformProperties = platformProperties;
sEnumValueMap = enumValueMap;
BridgeAssetManager.initSystem();
// When DEBUG_LAYOUT is set and is not 0 or false, setup a default listener
// on static (native) methods which prints the signature on the console and
// throws an exception.
// This is useful when testing the rendering in ADT to identify static native
// methods that are ignored -- layoutlib_create makes them returns 0/false/null
// which is generally OK yet might be a problem, so this is how you'd find out.
//
// Currently layoutlib_create only overrides static native method.
// Static non-natives are not overridden and thus do not get here.
final String debug = System.getenv("DEBUG_LAYOUT");
if (debug != null && !debug.equals("0") && !debug.equals("false")) {
OverrideMethod.setDefaultListener(new MethodAdapter() {
@Override
public void onInvokeV(String signature, boolean isNative, Object caller) {
sDefaultLog.error(null, "Missing Stub: " + signature + (isNative ? " (native)" : ""), null);
if (debug.equalsIgnoreCase("throw")) {
// throw it only if the environment variable is "throw" or "THROW".
throw new StaticMethodNotImplementedException(signature);
}
}
});
}
// load the fonts.
FontFamily_Delegate.setFontLocation(fontLocation.getAbsolutePath());
MemoryMappedFile_Delegate.setDataDir(fontLocation.getAbsoluteFile().getParentFile());
// the internal version), and put the content in the maps.
try {
Class<?> r = com.android.internal.R.class;
// Parse the styleable class first, since it may contribute to attr values.
parseStyleable();
for (Class<?> inner : r.getDeclaredClasses()) {
if (inner == com.android.internal.R.styleable.class) {
// that are not referenced from styleables.
continue;
}
String resTypeName = inner.getSimpleName();
ResourceType resType = ResourceType.getEnum(resTypeName);
if (resType != null) {
Map<String, Integer> fullMap = null;
switch(resType) {
case ATTR:
fullMap = sRevRMap.get(ResourceType.ATTR);
break;
case STRING:
case STYLE:
// Slightly less than thousand entries in each.
fullMap = new HashMap<String, Integer>(1280);
// no break.
default:
if (fullMap == null) {
fullMap = new HashMap<String, Integer>();
}
sRevRMap.put(resType, fullMap);
}
for (Field f : inner.getDeclaredFields()) {
// been altered by layoutlib_create, we only check static
if (!isValidRField(f)) {
continue;
}
Class<?> type = f.getType();
if (type.isArray()) {
// 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());
} else {
Integer value = (Integer) f.get(null);
sRMap.put(value, Pair.of(resType, f.getName()));
fullMap.put(f.getName(), value);
}
}
}
}
} catch (Exception throwable) {
if (log != null) {
log.error(LayoutLog.TAG_BROKEN, "Failed to load com.android.internal.R from the layout library jar", throwable, null);
}
return false;
}
return true;
}
use of com.android.tools.layoutlib.create.MethodAdapter in project android_frameworks_base by AOSPA.
the class Bridge method init.
@Override
public boolean init(Map<String, String> platformProperties, File fontLocation, Map<String, Map<String, Integer>> enumValueMap, LayoutLog log) {
sPlatformProperties = platformProperties;
sEnumValueMap = enumValueMap;
BridgeAssetManager.initSystem();
// When DEBUG_LAYOUT is set and is not 0 or false, setup a default listener
// on static (native) methods which prints the signature on the console and
// throws an exception.
// This is useful when testing the rendering in ADT to identify static native
// methods that are ignored -- layoutlib_create makes them returns 0/false/null
// which is generally OK yet might be a problem, so this is how you'd find out.
//
// Currently layoutlib_create only overrides static native method.
// Static non-natives are not overridden and thus do not get here.
final String debug = System.getenv("DEBUG_LAYOUT");
if (debug != null && !debug.equals("0") && !debug.equals("false")) {
OverrideMethod.setDefaultListener(new MethodAdapter() {
@Override
public void onInvokeV(String signature, boolean isNative, Object caller) {
sDefaultLog.error(null, "Missing Stub: " + signature + (isNative ? " (native)" : ""), null);
if (debug.equalsIgnoreCase("throw")) {
// throw it only if the environment variable is "throw" or "THROW".
throw new StaticMethodNotImplementedException(signature);
}
}
});
}
// load the fonts.
FontFamily_Delegate.setFontLocation(fontLocation.getAbsolutePath());
MemoryMappedFile_Delegate.setDataDir(fontLocation.getAbsoluteFile().getParentFile());
// the internal version), and put the content in the maps.
try {
Class<?> r = com.android.internal.R.class;
// Parse the styleable class first, since it may contribute to attr values.
parseStyleable();
for (Class<?> inner : r.getDeclaredClasses()) {
if (inner == com.android.internal.R.styleable.class) {
// that are not referenced from styleables.
continue;
}
String resTypeName = inner.getSimpleName();
ResourceType resType = ResourceType.getEnum(resTypeName);
if (resType != null) {
Map<String, Integer> fullMap = null;
switch(resType) {
case ATTR:
fullMap = sRevRMap.get(ResourceType.ATTR);
break;
case STRING:
case STYLE:
// Slightly less than thousand entries in each.
fullMap = new HashMap<String, Integer>(1280);
// no break.
default:
if (fullMap == null) {
fullMap = new HashMap<String, Integer>();
}
sRevRMap.put(resType, fullMap);
}
for (Field f : inner.getDeclaredFields()) {
// been altered by layoutlib_create, we only check static
if (!isValidRField(f)) {
continue;
}
Class<?> type = f.getType();
if (type.isArray()) {
// 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());
} else {
Integer value = (Integer) f.get(null);
sRMap.put(value, Pair.of(resType, f.getName()));
fullMap.put(f.getName(), value);
}
}
}
}
} catch (Exception throwable) {
if (log != null) {
log.error(LayoutLog.TAG_BROKEN, "Failed to load com.android.internal.R from the layout library jar", throwable, null);
}
return false;
}
return true;
}
use of com.android.tools.layoutlib.create.MethodAdapter in project platform_frameworks_base by android.
the class Bridge method init.
@Override
public boolean init(Map<String, String> platformProperties, File fontLocation, Map<String, Map<String, Integer>> enumValueMap, LayoutLog log) {
sPlatformProperties = platformProperties;
sEnumValueMap = enumValueMap;
BridgeAssetManager.initSystem();
// When DEBUG_LAYOUT is set and is not 0 or false, setup a default listener
// on static (native) methods which prints the signature on the console and
// throws an exception.
// This is useful when testing the rendering in ADT to identify static native
// methods that are ignored -- layoutlib_create makes them returns 0/false/null
// which is generally OK yet might be a problem, so this is how you'd find out.
//
// Currently layoutlib_create only overrides static native method.
// Static non-natives are not overridden and thus do not get here.
final String debug = System.getenv("DEBUG_LAYOUT");
if (debug != null && !debug.equals("0") && !debug.equals("false")) {
OverrideMethod.setDefaultListener(new MethodAdapter() {
@Override
public void onInvokeV(String signature, boolean isNative, Object caller) {
sDefaultLog.error(null, "Missing Stub: " + signature + (isNative ? " (native)" : ""), null);
if (debug.equalsIgnoreCase("throw")) {
// throw it only if the environment variable is "throw" or "THROW".
throw new StaticMethodNotImplementedException(signature);
}
}
});
}
// load the fonts.
FontFamily_Delegate.setFontLocation(fontLocation.getAbsolutePath());
MemoryMappedFile_Delegate.setDataDir(fontLocation.getAbsoluteFile().getParentFile());
// the internal version), and put the content in the maps.
try {
Class<?> r = com.android.internal.R.class;
// Parse the styleable class first, since it may contribute to attr values.
parseStyleable();
for (Class<?> inner : r.getDeclaredClasses()) {
if (inner == com.android.internal.R.styleable.class) {
// that are not referenced from styleables.
continue;
}
String resTypeName = inner.getSimpleName();
ResourceType resType = ResourceType.getEnum(resTypeName);
if (resType != null) {
Map<String, Integer> fullMap = null;
switch(resType) {
case ATTR:
fullMap = sRevRMap.get(ResourceType.ATTR);
break;
case STRING:
case STYLE:
// Slightly less than thousand entries in each.
fullMap = new HashMap<String, Integer>(1280);
// no break.
default:
if (fullMap == null) {
fullMap = new HashMap<String, Integer>();
}
sRevRMap.put(resType, fullMap);
}
for (Field f : inner.getDeclaredFields()) {
// been altered by layoutlib_create, we only check static
if (!isValidRField(f)) {
continue;
}
Class<?> type = f.getType();
if (type.isArray()) {
// 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());
} else {
Integer value = (Integer) f.get(null);
sRMap.put(value, Pair.of(resType, f.getName()));
fullMap.put(f.getName(), value);
}
}
}
}
} catch (Exception throwable) {
if (log != null) {
log.error(LayoutLog.TAG_BROKEN, "Failed to load com.android.internal.R from the layout library jar", throwable, null);
}
return false;
}
return true;
}
use of com.android.tools.layoutlib.create.MethodAdapter in project android_frameworks_base by ParanoidAndroid.
the class Bridge method init.
@Override
public boolean init(Map<String, String> platformProperties, File fontLocation, Map<String, Map<String, Integer>> enumValueMap, LayoutLog log) {
sPlatformProperties = platformProperties;
sEnumValueMap = enumValueMap;
// don't use EnumSet.allOf(), because the bridge doesn't come with its specific version
// of layoutlib_api. It is provided by the client which could have a more recent version
// with newer, unsupported capabilities.
mCapabilities = EnumSet.of(Capability.UNBOUND_RENDERING, Capability.CUSTOM_BACKGROUND_COLOR, Capability.RENDER, Capability.LAYOUT_ONLY, Capability.EMBEDDED_LAYOUT, Capability.VIEW_MANIPULATION, Capability.PLAY_ANIMATION, Capability.ANIMATED_VIEW_MANIPULATION, Capability.ADAPTER_BINDING, Capability.EXTENDED_VIEWINFO, Capability.FIXED_SCALABLE_NINE_PATCH);
BridgeAssetManager.initSystem();
// When DEBUG_LAYOUT is set and is not 0 or false, setup a default listener
// on static (native) methods which prints the signature on the console and
// throws an exception.
// This is useful when testing the rendering in ADT to identify static native
// methods that are ignored -- layoutlib_create makes them returns 0/false/null
// which is generally OK yet might be a problem, so this is how you'd find out.
//
// Currently layoutlib_create only overrides static native method.
// Static non-natives are not overridden and thus do not get here.
final String debug = System.getenv("DEBUG_LAYOUT");
if (debug != null && !debug.equals("0") && !debug.equals("false")) {
OverrideMethod.setDefaultListener(new MethodAdapter() {
@Override
public void onInvokeV(String signature, boolean isNative, Object caller) {
sDefaultLog.error(null, "Missing Stub: " + signature + (isNative ? " (native)" : ""), null);
if (debug.equalsIgnoreCase("throw")) {
// throw it only if the environment variable is "throw" or "THROW".
throw new StaticMethodNotImplementedException(signature);
}
}
});
}
// load the fonts.
FontLoader fontLoader = FontLoader.create(fontLocation.getAbsolutePath());
if (fontLoader != null) {
Typeface_Delegate.init(fontLoader);
} else {
log.error(LayoutLog.TAG_BROKEN, "Failed create FontLoader in layout lib.", null);
return false;
}
// the internal version), and put the content in the maps.
try {
Class<?> r = com.android.internal.R.class;
for (Class<?> inner : r.getDeclaredClasses()) {
String resTypeName = inner.getSimpleName();
ResourceType resType = ResourceType.getEnum(resTypeName);
if (resType != null) {
Map<String, Integer> fullMap = new HashMap<String, Integer>();
sRevRMap.put(resType, fullMap);
for (Field f : inner.getDeclaredFields()) {
// only process static final fields. Since the final attribute may have
// been altered by layoutlib_create, we only check static
int modifiers = f.getModifiers();
if (Modifier.isStatic(modifiers)) {
Class<?> type = f.getType();
if (type.isArray() && type.getComponentType() == int.class) {
// 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());
} else if (type == int.class) {
Integer value = (Integer) f.get(null);
sRMap.put(value, Pair.of(resType, f.getName()));
fullMap.put(f.getName(), value);
} else {
assert false;
}
}
}
}
}
} catch (Throwable throwable) {
if (log != null) {
log.error(LayoutLog.TAG_BROKEN, "Failed to load com.android.internal.R from the layout library jar", throwable);
}
return false;
}
return true;
}
use of com.android.tools.layoutlib.create.MethodAdapter in project android_frameworks_base by DirtyUnicorns.
the class Bridge method init.
@Override
public boolean init(Map<String, String> platformProperties, File fontLocation, Map<String, Map<String, Integer>> enumValueMap, LayoutLog log) {
sPlatformProperties = platformProperties;
sEnumValueMap = enumValueMap;
BridgeAssetManager.initSystem();
// When DEBUG_LAYOUT is set and is not 0 or false, setup a default listener
// on static (native) methods which prints the signature on the console and
// throws an exception.
// This is useful when testing the rendering in ADT to identify static native
// methods that are ignored -- layoutlib_create makes them returns 0/false/null
// which is generally OK yet might be a problem, so this is how you'd find out.
//
// Currently layoutlib_create only overrides static native method.
// Static non-natives are not overridden and thus do not get here.
final String debug = System.getenv("DEBUG_LAYOUT");
if (debug != null && !debug.equals("0") && !debug.equals("false")) {
OverrideMethod.setDefaultListener(new MethodAdapter() {
@Override
public void onInvokeV(String signature, boolean isNative, Object caller) {
sDefaultLog.error(null, "Missing Stub: " + signature + (isNative ? " (native)" : ""), null);
if (debug.equalsIgnoreCase("throw")) {
// throw it only if the environment variable is "throw" or "THROW".
throw new StaticMethodNotImplementedException(signature);
}
}
});
}
// load the fonts.
FontFamily_Delegate.setFontLocation(fontLocation.getAbsolutePath());
MemoryMappedFile_Delegate.setDataDir(fontLocation.getAbsoluteFile().getParentFile());
// the internal version), and put the content in the maps.
try {
Class<?> r = com.android.internal.R.class;
// Parse the styleable class first, since it may contribute to attr values.
parseStyleable();
for (Class<?> inner : r.getDeclaredClasses()) {
if (inner == com.android.internal.R.styleable.class) {
// that are not referenced from styleables.
continue;
}
String resTypeName = inner.getSimpleName();
ResourceType resType = ResourceType.getEnum(resTypeName);
if (resType != null) {
Map<String, Integer> fullMap = null;
switch(resType) {
case ATTR:
fullMap = sRevRMap.get(ResourceType.ATTR);
break;
case STRING:
case STYLE:
// Slightly less than thousand entries in each.
fullMap = new HashMap<String, Integer>(1280);
// no break.
default:
if (fullMap == null) {
fullMap = new HashMap<String, Integer>();
}
sRevRMap.put(resType, fullMap);
}
for (Field f : inner.getDeclaredFields()) {
// been altered by layoutlib_create, we only check static
if (!isValidRField(f)) {
continue;
}
Class<?> type = f.getType();
if (type.isArray()) {
// 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());
} else {
Integer value = (Integer) f.get(null);
sRMap.put(value, Pair.of(resType, f.getName()));
fullMap.put(f.getName(), value);
}
}
}
}
} catch (Exception throwable) {
if (log != null) {
log.error(LayoutLog.TAG_BROKEN, "Failed to load com.android.internal.R from the layout library jar", throwable, null);
}
return false;
}
return true;
}
Aggregations