use of com.android.ide.common.resources.IntArrayWrapper in project android_frameworks_base by ResurrectionRemix.
the class LayoutLibTestCallback method initResources.
public void initResources() throws ClassNotFoundException {
Class<?> rClass = mModuleClassLoader.loadClass(PACKAGE_NAME + ".R");
Class<?>[] nestedClasses = rClass.getDeclaredClasses();
for (Class<?> resClass : nestedClasses) {
final ResourceType resType = ResourceType.getEnum(resClass.getSimpleName());
if (resType != null) {
final Map<String, Integer> resName2Id = Maps.newHashMap();
mResources.put(resType, resName2Id);
for (Field field : resClass.getDeclaredFields()) {
final int modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers)) {
// May not be final in library projects
final Class<?> type = field.getType();
try {
if (type.isArray() && type.getComponentType() == int.class) {
mStyleableValueToNameMap.put(new IntArrayWrapper((int[]) field.get(null)), field.getName());
} else if (type == int.class) {
final Integer value = (Integer) field.get(null);
mProjectResources.put(value, Pair.of(resType, field.getName()));
resName2Id.put(field.getName(), value);
} else {
mLog.error(null, "Unknown field type in R class: %1$s", type);
}
} catch (IllegalAccessException ignored) {
mLog.error(ignored, "Malformed R class: %1$s", PACKAGE_NAME + ".R");
}
}
}
}
}
}
use of com.android.ide.common.resources.IntArrayWrapper in project android_frameworks_base by crdroidandroid.
the class LayoutLibTestCallback method initResources.
public void initResources() throws ClassNotFoundException {
Class<?> rClass = mModuleClassLoader.loadClass(PACKAGE_NAME + ".R");
Class<?>[] nestedClasses = rClass.getDeclaredClasses();
for (Class<?> resClass : nestedClasses) {
final ResourceType resType = ResourceType.getEnum(resClass.getSimpleName());
if (resType != null) {
final Map<String, Integer> resName2Id = Maps.newHashMap();
mResources.put(resType, resName2Id);
for (Field field : resClass.getDeclaredFields()) {
final int modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers)) {
// May not be final in library projects
final Class<?> type = field.getType();
try {
if (type.isArray() && type.getComponentType() == int.class) {
mStyleableValueToNameMap.put(new IntArrayWrapper((int[]) field.get(null)), field.getName());
} else if (type == int.class) {
final Integer value = (Integer) field.get(null);
mProjectResources.put(value, Pair.of(resType, field.getName()));
resName2Id.put(field.getName(), value);
} else {
mLog.error(null, "Unknown field type in R class: %1$s", type);
}
} catch (IllegalAccessException ignored) {
mLog.error(ignored, "Malformed R class: %1$s", PACKAGE_NAME + ".R");
}
}
}
}
}
}
Aggregations