public class RenderResources
extends java.lang.Object
This contains both the project specific resources and the framework resources, and provide convenience methods to resolve resource and theme references.
| Modifier and Type | Class and Description |
|---|---|
static class |
RenderResources.FrameworkResourceIdProvider
Deprecated.
This class will be removed after layoutlib is updated. Use
RenderResources.ResourceIdProvider |
static class |
RenderResources.ResourceIdProvider |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
REFERENCE_EMPTY |
static java.lang.String |
REFERENCE_NULL |
static java.lang.String |
REFERENCE_UNDEFINED |
| Constructor and Description |
|---|
RenderResources() |
| Modifier and Type | Method and Description |
|---|---|
void |
applyStyle(StyleResourceValue theme,
boolean useAsPrimary)
Use this theme to resolve resources.
|
void |
clearStyles()
Clear all the themes applied with
applyStyle(StyleResourceValue, boolean) |
ResourceValue |
dereference(ResourceValue resourceValue)
Searches for a
ResourceValue referenced by the given value. |
ResourceValue |
findItemInStyle(StyleResourceValue style,
java.lang.String attrName)
Deprecated.
Use
findItemInStyle(StyleResourceValue, String, boolean) since this
method doesn't know the item namespace. |
ResourceValue |
findItemInStyle(StyleResourceValue style,
java.lang.String attrName,
boolean isFrameworkAttr)
Returns the
ResourceValue matching a given attribute in a given style. |
ResourceValue |
findItemInTheme(java.lang.String itemName)
Deprecated.
|
ResourceValue |
findItemInTheme(java.lang.String attrName,
boolean isFrameworkAttr)
Returns the
ResourceValue matching a given name in the all themes returned by
getAllThemes(). |
ResourceValue |
findResValue(java.lang.String reference,
boolean forceFrameworkOnly)
Deprecated.
Use
dereference(ResourceValue) instead, to provide context necessary to
handle namespaces correctly, like the "current" namespace or namespace prefix lookup
logic. Alternatively, use getUnresolvedResource(ResourceReference) or getResolvedResource(ResourceReference) if you already know exactly what you're looking
for. |
java.util.List<StyleResourceValue> |
getAllThemes()
Returns a list of
StyleResourceValue containing a list of themes to be used for
resolving resources. |
StyleResourceValue |
getCurrentTheme()
Deprecated.
Use
getDefaultTheme() or getAllThemes() |
StyleResourceValue |
getDefaultTheme()
Returns the
StyleResourceValue representing the default theme. |
ResourceValue |
getFrameworkResource(ResourceType resourceType,
java.lang.String resourceName)
Deprecated.
|
StyleResourceValue |
getParent(StyleResourceValue style)
Returns the parent style of the given style, if any
|
ResourceValue |
getProjectResource(ResourceType resourceType,
java.lang.String resourceName)
Deprecated.
|
ResourceValue |
getResolvedResource(ResourceReference reference)
Returns a resource by namespace, type and name.
|
StyleResourceValue |
getStyle(ResourceReference reference)
Returns the style matching the given reference.
|
StyleResourceValue |
getStyle(java.lang.String styleName,
boolean isFramework)
Deprecated.
|
StyleResourceValue |
getTheme(java.lang.String name,
boolean frameworkTheme)
Deprecated.
|
ResourceValue |
getUnresolvedResource(ResourceReference reference)
Returns a resource by namespace, type and name.
|
ResourceValue |
resolveResValue(ResourceValue value)
Returns the "final"
ResourceValue referenced by the value of value. |
ResourceValue |
resolveValue(ResourceType type,
java.lang.String name,
java.lang.String value,
boolean isFrameworkValue)
Deprecated.
|
void |
setFrameworkResourceIdProvider(RenderResources.FrameworkResourceIdProvider provider)
Deprecated.
This method will be removed after layoutlib is updated. Use
setFrameworkResourceIdProvider(ResourceIdProvider) |
void |
setFrameworkResourceIdProvider(RenderResources.ResourceIdProvider provider) |
void |
setLogger(LayoutLog logger) |
boolean |
themeIsParentOf(StyleResourceValue parentTheme,
StyleResourceValue childTheme)
Returns whether a theme is a parent of a given theme.
|
public static final java.lang.String REFERENCE_NULL
public static final java.lang.String REFERENCE_EMPTY
public static final java.lang.String REFERENCE_UNDEFINED
public void setFrameworkResourceIdProvider(RenderResources.ResourceIdProvider provider)
@Deprecated public void setFrameworkResourceIdProvider(RenderResources.FrameworkResourceIdProvider provider)
setFrameworkResourceIdProvider(ResourceIdProvider)public void setLogger(LayoutLog logger)
@Deprecated public StyleResourceValue getCurrentTheme()
getDefaultTheme() or getAllThemes()StyleResourceValue representing the current theme.public StyleResourceValue getDefaultTheme()
StyleResourceValue representing the default theme.public void applyStyle(StyleResourceValue theme, boolean useAsPrimary)
Remember to call clearStyles() to clear the applied styles, so the default theme
may be restored.
theme - The style to use for resource resolution in addition to the the default theme
and the styles applied earlier. If null, the operation is a no-op.useAsPrimary - If true, the theme is used first to resolve attributes. If
false, the theme is used if the resource cannot be resolved using the default theme and
all the themes that have been applied prior to this call.public void clearStyles()
applyStyle(StyleResourceValue, boolean)public java.util.List<StyleResourceValue> getAllThemes()
StyleResourceValue containing a list of themes to be used for
resolving resources. The order of the themes in the list specifies the order in which they
should be used to resolve resources.@Deprecated public StyleResourceValue getTheme(java.lang.String name, boolean frameworkTheme)
getStyle(ResourceReference)public boolean themeIsParentOf(StyleResourceValue parentTheme, StyleResourceValue childTheme)
parentTheme - the parent themechildTheme - the child theme.@Deprecated public ResourceValue getFrameworkResource(ResourceType resourceType, java.lang.String resourceName)
getResolvedResource(ResourceReference)resourceType - the type of the resourceresourceName - the name of the resource@Deprecated public ResourceValue getProjectResource(ResourceType resourceType, java.lang.String resourceName)
getResolvedResource(ResourceReference)resourceType - the type of the resourceresourceName - the name of the resource@Deprecated public ResourceValue findItemInTheme(java.lang.String itemName)
findItemInTheme(String, boolean)ResourceValue matching a given name in the all themes returned by
getAllThemes(). If the item is not directly available in the a theme, its parent
theme is used before checking the next theme from the list.itemName - the name of the item to search for.ResourceValue object or nullpublic ResourceValue findItemInTheme(java.lang.String attrName, boolean isFrameworkAttr)
ResourceValue matching a given name in the all themes returned by
getAllThemes(). If the item is not directly available in the a theme, its parent
theme is used before checking the next theme from the list.attrName - the name of the attribute to search for.isFrameworkAttr - whether the attribute is a framework attributeResourceValue object or null@Deprecated public ResourceValue findItemInStyle(StyleResourceValue style, java.lang.String attrName)
findItemInStyle(StyleResourceValue, String, boolean) since this
method doesn't know the item namespace.ResourceValue matching a given name in a given style. If the
item is not directly available in the style, the method looks in its parent style.
This version of doesn't support providing the namespace of the attribute so it'll search
in both the project's namespace and then in the android namespace.style - the style to search inattrName - the name of the attribute to search for.ResourceValue object or nullpublic ResourceValue findItemInStyle(StyleResourceValue style, java.lang.String attrName, boolean isFrameworkAttr)
ResourceValue matching a given attribute in a given style. If the
item is not directly available in the style, the method looks in its parent style.style - the style to search inattrName - the name of the attribute to search for.isFrameworkAttr - whether the attribute is a framework attributeResourceValue object or null@Nullable @Deprecated public final ResourceValue findResValue(@Nullable java.lang.String reference, boolean forceFrameworkOnly)
dereference(ResourceValue) instead, to provide context necessary to
handle namespaces correctly, like the "current" namespace or namespace prefix lookup
logic. Alternatively, use getUnresolvedResource(ResourceReference) or getResolvedResource(ResourceReference) if you already know exactly what you're looking
for.@Nullable public ResourceValue dereference(@NonNull ResourceValue resourceValue)
ResourceValue referenced by the given value. This method doesn't
perform recursive resolution, so the returned ResourceValue (if not null) may be just
another reference.
References to theme attributes is supported and resolved against the theme from getDefaultTheme(). For more details see Referencing
style attributes
Unlike resolveResValue(ResourceValue), this method returns null if the input is
not a reference (i.e. doesn't start with '@' or '?').
resourceValue - the value to dereference. Its namespace and namespace lookup logic are
used to handle namespaces when interpreting the textual value. The type is ignored and
will not affect the type of the returned value.resolveResValue(ResourceValue)@Nullable public ResourceValue getUnresolvedResource(ResourceReference reference)
@Nullable public ResourceValue getResolvedResource(ResourceReference reference)
resolveResValue(ResourceValue).resolveResValue(ResourceValue)@Nullable @Deprecated public ResourceValue resolveValue(ResourceType type, java.lang.String name, java.lang.String value, boolean isFrameworkValue)
resolveResValue(ResourceValue)@Nullable public ResourceValue resolveResValue(@Nullable ResourceValue value)
ResourceValue referenced by the value of value.
This method ensures that the returned ResourceValue object is not a valid
reference to another resource. It may be just a leaf value (e.g. "#000000") or a reference
that could not be dereferenced.
If a value that does not need to be resolved is given, the method will return the input value.
value - the value containing the reference to resolve.ResourceValue object or nullpublic StyleResourceValue getParent(StyleResourceValue style)
style - the style to look up@Deprecated public StyleResourceValue getStyle(java.lang.String styleName, boolean isFramework)
getStyle(ResourceReference)styleName - Name of the style. For example, "Widget.ListView.DropDown".@Nullable public StyleResourceValue getStyle(@NonNull ResourceReference reference)