public abstract class LayoutlibCallback extends java.lang.Object implements XmlParserFactory
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
LayoutlibCallback.ViewAttribute |
| Constructor and Description |
|---|
LayoutlibCallback() |
| Modifier and Type | Method and Description |
|---|---|
java.lang.Class<?> |
findClass(java.lang.String name)
Finds a custom class in the project.
|
abstract ActionBarCallback |
getActionBarCallback()
Returns a callback for Action Bar information needed by the Layout Library.
|
abstract AdapterBinding |
getAdapterBinding(ResourceReference adapterViewRef,
java.lang.Object adapterCookie,
java.lang.Object viewObject)
Returns an adapter binding for a given adapter view.
|
java.lang.Object |
getAdapterItemValue(ResourceReference adapterView,
java.lang.Object adapterCookie,
ResourceReference itemRef,
int fullPosition,
int positionPerType,
int fullParentPosition,
int parentPositionPerType,
ResourceReference viewRef,
LayoutlibCallback.ViewAttribute viewAttribute,
java.lang.Object defaultValue)
Returns the value of an item used by an adapter.
|
<T> T |
getFlag(SessionParams.Key<T> key)
A callback to query arbitrary data.
|
ResourceNamespace.Resolver |
getImplicitNamespaces()
Returns an optional
ResourceNamespace.Resolver that knows namespace prefixes assumed
to be declared in every resource file. |
abstract java.lang.String |
getNamespace()
Returns the namespace URI of the application.
|
abstract int |
getOrGenerateResourceId(ResourceReference resource)
Returns the numeric id for the given resource, potentially generating a fresh ID.
|
abstract ILayoutPullParser |
getParser(ResourceValue layoutResource)
Returns a custom parser for a value
|
boolean |
hasAndroidXAppCompat()
Returns true if the module depends on androidx.appcompat.
|
boolean |
hasLegacyAppCompat()
Returns true if the module depends on android.support.v7.appcompat.
|
boolean |
isResourceNamespacingRequired()
Returns true if the module uses namespaced resources.
|
java.lang.Object |
loadClass(java.lang.String name,
java.lang.Class[] constructorSignature,
java.lang.Object[] constructorArgs)
Like
loadView(String, Class[], Object[]), but intended for loading classes that may
not be custom views. |
abstract java.lang.Object |
loadView(java.lang.String name,
java.lang.Class[] constructorSignature,
java.lang.Object[] constructorArgs)
Loads a custom class with the given constructor signature and arguments.
|
abstract ResourceReference |
resolveResourceId(int id)
Finds the resource with a given id.
|
abstract boolean |
supports(int ideFeature)
Returns if the IDE supports the requested feature.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreateXmlParser, createXmlParserForFile, createXmlParserForPsiFile@Nullable
public abstract java.lang.Object loadView(@NonNull
java.lang.String name,
@NonNull
java.lang.Class[] constructorSignature,
java.lang.Object[] constructorArgs)
throws java.lang.Exception
Despite the name, the method is used not just for views (android.view.View), but potentially any class in the project's namespace. However, when the method is used for loading non-view classes the error messages reported may not be ideal, since the the IDE may assume those classes to be a view and try to use a different constructor or replace it with a MockView.
This is done so that LayoutLib can continue to work on older versions of the IDE. Newer
versions of LayoutLib should call loadClass(String, Class[],
Object[]) in such a case.
name - the fully qualified name of the class.constructorSignature - the signature of the class to useconstructorArgs - the arguments to use on the constructorjava.lang.Exception@NonNull public abstract java.lang.String getNamespace()
Used by the Layoutlib to load custom attributes for custom views.
@Nullable public abstract ResourceReference resolveResourceId(int id)
public abstract int getOrGenerateResourceId(@NonNull
ResourceReference resource)
Calling this method for equal references will always produce the same result.
@Nullable public abstract ILayoutPullParser getParser(@NonNull ResourceValue layoutResource)
layoutResource - Layout or a value referencing an _aapt attribute.@Nullable public java.lang.Object getAdapterItemValue(ResourceReference adapterView, java.lang.Object adapterCookie, ResourceReference itemRef, int fullPosition, int positionPerType, int fullParentPosition, int parentPositionPerType, ResourceReference viewRef, LayoutlibCallback.ViewAttribute viewAttribute, java.lang.Object defaultValue)
adapterView - the ResourceReference for the adapter view info.adapterCookie - the view cookie for this particular view.itemRef - the ResourceReference for the layout used by the adapter item.fullPosition - the position of the item in the full list.positionPerType - the position of the item if only items of the same type are
considered. If there is only one type of items, this is the same as
fullPosition.fullParentPosition - the full position of the item's parent. This is only valid if the
adapter view is an ExpandableListView.parentPositionPerType - the position of the parent's item, only considering items of the
same type. This is only valid if the adapter view is an ExpandableListView. If there is
only one type of items, this is the same as fullParentPosition.viewRef - the ResourceReference for the view we're trying to fill.viewAttribute - the attribute being queried.defaultValue - the default value for this attribute. The object class matches the class
associated with the LayoutlibCallback.ViewAttribute.LayoutlibCallback.ViewAttribute.getAttributeClass()@Nullable public abstract AdapterBinding getAdapterBinding(ResourceReference adapterViewRef, java.lang.Object adapterCookie, java.lang.Object viewObject)
SessionParams does not have an AdapterBinding for the given ResourceReference already.adapterViewRef - the reference of adapter view to return the adapter binding for.adapterCookie - the view cookie for this particular view.viewObject - the view object for the adapter.public abstract ActionBarCallback getActionBarCallback()
public java.lang.Object loadClass(@NonNull
java.lang.String name,
@Nullable
java.lang.Class[] constructorSignature,
@Nullable
java.lang.Object[] constructorArgs)
throws java.lang.ClassNotFoundException
loadView(String, Class[], Object[]), but intended for loading classes that may
not be custom views.name - className in binary format (see ClassLoader)java.lang.ClassNotFoundException - any exceptions thrown when creating the instance is wrapped in
a ClassNotFoundException.public abstract boolean supports(int ideFeature)
Features@Nullable
public <T> T getFlag(@NonNull
SessionParams.Key<T> key)
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.@NonNull
public java.lang.Class<?> findClass(@NonNull
java.lang.String name)
throws java.lang.ClassNotFoundException
Like loadClass(String, Class[], Object[]), but doesn't instantiate an object and
just returns the class found.
name - className in binary format. (see ClassLoader.java.lang.ClassNotFoundException@NonNull public ResourceNamespace.Resolver getImplicitNamespaces()
ResourceNamespace.Resolver that knows namespace prefixes assumed
to be declared in every resource file.
For backwards compatibility, in non-namespaced projects this contains the "tools" prefix
mapped to ResourceNamespace.TOOLS. Before the IDE understood resource namespaces,
this prefix was used for referring to sample data, even if the user didn't define the "tools"
prefix using xmlns:tools="...".
In namespaced projects this method returns an empty resolver, which means sample data
won't work without an explicit definition of a namespace prefix for the ResourceNamespace.TOOLS URI.
public boolean hasLegacyAppCompat()
public boolean hasAndroidXAppCompat()
public boolean isResourceNamespacingRequired()