com.android.ide.common.rendering.api
Class LayoutlibCallback

java.lang.Object
  extended by com.android.ide.common.rendering.api.LayoutlibCallback
All Implemented Interfaces:
IProjectCallback

public abstract class LayoutlibCallback
extends java.lang.Object
implements IProjectCallback, IProjectCallback

Intermediary class implementing parts of both the old and new ProjectCallback from the LayoutLib API.

Even newer LayoutLibs use this directly instead of the the interface. This allows the flexibility to add newer methods without having to update LayoutLib API version.

Clients should use this instead of IProjectCallback to target both old and new Layout Libraries.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.android.ide.common.rendering.api.IProjectCallback
IProjectCallback.ViewAttribute
 
Constructor Summary
LayoutlibCallback()
           
 
Method Summary
 java.lang.Class<?> findClass(java.lang.String name)
          Find a custom class in the project.
<T> T
getFlag(SessionParams.Key<T> key)
          A callback to query arbitrary data.
 ParserFactory getParserFactory()
          Get a ParserFactory which can be used to create XmlPullParsers.
 java.lang.Integer getResourceValue(java.lang.String type, java.lang.String name)
          Returns the id of a resource.
 org.xmlpull.v1.XmlPullParser getXmlFileParser(java.lang.String fileName)
          Returns an XmlPullParser for the psi version of an xml file
 java.lang.Object loadClass(java.lang.String name, java.lang.Class[] constructorSignature, java.lang.Object[] constructorArgs)
          Like IProjectCallback.loadView(String, Class[], Object[]), but intended for loading classes that may not be custom views.
 java.lang.String[] resolveResourceValue(int id)
          Resolves the id of a resource Id.
 java.lang.String resolveResourceValue(int[] id)
          Resolves the id of a resource Id of type int[]

The resource id is the value of a R.styleable.<name>, and this method will return the name of the resource.

abstract  boolean supports(int ideFeature)
          Returns if the IDE supports the requested feature.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.android.ide.common.rendering.api.IProjectCallback
getActionBarCallback, getAdapterBinding, getAdapterItemValue, getNamespace, getParser, getParser, getResourceId, loadView, resolveResourceId, resolveResourceId
 
Methods inherited from interface com.android.layoutlib.api.IProjectCallback
getNamespace, loadView
 

Constructor Detail

LayoutlibCallback

public LayoutlibCallback()
Method Detail

loadClass

public java.lang.Object loadClass(@NonNull
                                  java.lang.String name,
                                  @Nullable
                                  java.lang.Class[] constructorSignature,
                                  @Nullable
                                  java.lang.Object[] constructorArgs)
                           throws java.lang.ClassNotFoundException
Like IProjectCallback.loadView(String, Class[], Object[]), but intended for loading classes that may not be custom views.

Parameters:
name - className in binary format (see ClassLoader)
Returns:
an new instance created by calling the given constructor.
Throws:
java.lang.ClassNotFoundException - any exceptions thrown when creating the instance is wrapped in ClassNotFoundException.
Since:
API 15

supports

public abstract boolean supports(int ideFeature)
Returns if the IDE supports the requested feature.

Since:
API 15
See Also:
Features

getFlag

@Nullable
public <T> T getFlag(@NonNull
                              SessionParams.Key<T> key)
A callback to query arbitrary data. This is similar to RenderParams.setFlag(SessionParams.Key, Object). The main difference is that when using this, the IDE doesn't have to compute the value in advance and thus may save on some computation.

Since:
API 15

getParserFactory

@NonNull
public ParserFactory getParserFactory()
Get a ParserFactory which can be used to create XmlPullParsers.

Since:
API 15

findClass

@NonNull
public java.lang.Class<?> findClass(@NonNull
                                            java.lang.String name)
                             throws java.lang.ClassNotFoundException
Find a custom class in the project.

Like loadClass(String, Class[], Object[]), but doesn't instantiate an object and just returns the class found.

Parameters:
name - className in binary format. (see ClassLoader.
Throws:
java.lang.ClassNotFoundException
Since:
API 15

getXmlFileParser

@Nullable
public org.xmlpull.v1.XmlPullParser getXmlFileParser(java.lang.String fileName)
Returns an XmlPullParser for the psi version of an xml file

Parameters:
fileName - name of the file to parse

getResourceValue

public final java.lang.Integer getResourceValue(java.lang.String type,
                                                java.lang.String name)
Description copied from interface: IProjectCallback
Returns the id of a resource.

The provided type and name must match an existing constant defined as R.<type>.<name>.

Specified by:
getResourceValue in interface IProjectCallback
Parameters:
type - the type of the resource
name - the name of the resource
Returns:
an Integer containing the resource Id, or null if not found.

resolveResourceValue

public final java.lang.String[] resolveResourceValue(int id)
Description copied from interface: IProjectCallback
Resolves the id of a resource Id.

The resource id is the value of a R.<type>.<name>, and this method will return both the type and name of the resource.

Specified by:
resolveResourceValue in interface IProjectCallback
Parameters:
id - the Id to resolve.
Returns:
an array of 2 strings containing the resource name and type, or null if the id does not match any resource.

resolveResourceValue

public final java.lang.String resolveResourceValue(int[] id)
Description copied from interface: IProjectCallback
Resolves the id of a resource Id of type int[]

The resource id is the value of a R.styleable.<name>, and this method will return the name of the resource.

Specified by:
resolveResourceValue in interface IProjectCallback
Parameters:
id - the Id to resolve.
Returns:
the name of the resource or null if not found.