FileDocCategorySizeDatePackage
LayoutLibTestCallback.javaAPI DocAndroid 5.1 API7471Thu Mar 12 22:22:44 GMT 2015com.android.layoutlib.bridge.intensive.setup

LayoutLibTestCallback

public class LayoutLibTestCallback extends ClassLoader implements com.android.ide.common.rendering.api.IProjectCallback

Fields Summary
private static final String
PROJECT_CLASSES_LOCATION
private static final String
PACKAGE_NAME
private final Map
mProjectResources
private final Map
mStyleableValueToNameMap
private final Map
mResources
private final Map
mClasses
private final com.android.utils.ILogger
mLog
private final com.android.ide.common.rendering.api.ActionBarCallback
mActionBarCallback
Constructors Summary
public LayoutLibTestCallback(com.android.utils.ILogger logger)


       
        mLog = logger;
    
Methods Summary
protected java.lang.ClassfindClass(java.lang.String name)

        Class<?> aClass = mClasses.get(name);
        if (aClass != null) {
            return aClass;
        }
        String pathName = PROJECT_CLASSES_LOCATION.concat(name.replace('.", '/")).concat(".class");
        InputStream classInputStream = getClass().getResourceAsStream(pathName);
        if (classInputStream == null) {
            throw new ClassNotFoundException("Unable to find class " + name + " at " + pathName);
        }
        byte[] data;
        try {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            int nRead;
            data = new byte[16384];
            while ((nRead = classInputStream.read(data, 0, data.length)) != -1) {
                buffer.write(data, 0, nRead);
            }
            buffer.flush();
            data = buffer.toByteArray();
        } catch (IOException e) {
            // Wrap the exception with ClassNotFoundException so that caller can deal with it.
            throw new ClassNotFoundException("Unable to load class " + name, e);
        }
        aClass = defineClass(name, data, 0, data.length);
        mClasses.put(name, aClass);
        return aClass;
    
public com.android.ide.common.rendering.api.ActionBarCallbackgetActionBarCallback()

        return mActionBarCallback;
    
public com.android.ide.common.rendering.api.AdapterBindinggetAdapterBinding(com.android.ide.common.rendering.api.ResourceReference adapterViewRef, java.lang.Object adapterCookie, java.lang.Object viewObject)

        return null;
    
public java.lang.ObjectgetAdapterItemValue(com.android.ide.common.rendering.api.ResourceReference adapterView, java.lang.Object adapterCookie, com.android.ide.common.rendering.api.ResourceReference itemRef, int fullPosition, int positionPerType, int fullParentPosition, int parentPositionPerType, com.android.ide.common.rendering.api.ResourceReference viewRef, ViewAttribute viewAttribute, java.lang.Object defaultValue)

        return null;
    
public java.lang.StringgetNamespace()

        return String.format(SdkConstants.NS_CUSTOM_RESOURCES_S,
                PACKAGE_NAME);
    
public com.android.ide.common.rendering.api.ILayoutPullParsergetParser(com.android.ide.common.rendering.api.ResourceValue layoutResource)

        return new LayoutPullParser(new File(layoutResource.getValue()));
    
public com.android.ide.common.rendering.api.ILayoutPullParsergetParser(java.lang.String layoutName)

        org.junit.Assert.fail("This method shouldn't be called by this version of LayoutLib.");
        return null;
    
public java.lang.IntegergetResourceId(com.android.resources.ResourceType type, java.lang.String name)

        return mResources.get(type).get(name);
    
public voidinitResources()

        Class<?> rClass = 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");
                        }
                    }
                }
            }
        }
    
public java.lang.ObjectloadView(java.lang.String name, java.lang.Class[] constructorSignature, java.lang.Object[] constructorArgs)

        Class<?> viewClass = findClass(name);
        Constructor<?> viewConstructor = viewClass.getConstructor(constructorSignature);
        viewConstructor.setAccessible(true);
        return viewConstructor.newInstance(constructorArgs);
    
public com.android.util.PairresolveResourceId(int id)

        return mProjectResources.get(id);
    
public java.lang.StringresolveResourceId(int[] id)

        return mStyleableValueToNameMap.get(new IntArrayWrapper(id));