@Immutable
public class ResourceUrl
extends java.lang.Object
implements java.io.Serializable
| Modifier and Type | Class and Description |
|---|---|
static class |
ResourceUrl.UrlType |
| Modifier and Type | Field and Description |
|---|---|
java.lang.String |
name
Name of resource.
|
java.lang.String |
namespace
The namespace, or null if it's in the project namespace.
|
boolean |
privateAccessOverride
The URL requests access to a private resource.
|
ResourceType |
type
Type of resource.
|
ResourceUrl.UrlType |
urlType |
| Modifier and Type | Method and Description |
|---|---|
static ResourceUrl |
create(ResourceType type,
java.lang.String name,
boolean framework)
Deprecated.
This factory method is used where we have no way of knowing the namespace. We
need to migrate every call site to the other factory method that takes a namespace.
|
static ResourceUrl |
create(java.lang.String namespace,
ResourceType type,
java.lang.String name)
Creates a new resource URL, representing "@namespace:type/name".
|
static ResourceUrl |
createAttrReference(java.lang.String namespace,
java.lang.String name)
Creates a new resource URL, representing "namespace:name".
|
static ResourceUrl |
createThemeReference(java.lang.String namespace,
ResourceType type,
java.lang.String name)
Creates a new resource URL, representing "?namespace:type/name".
|
boolean |
equals(java.lang.Object o) |
java.lang.String |
getQualifiedName()
Returns a short string representation, which includes just the namespace (if defined in this
ResourceUrl and name, separated by a colon.
|
int |
hashCode() |
boolean |
hasValidName()
Checks whether this resource has a valid name.
|
boolean |
isCreate()
Whether an id resource is of the form
@+id rather than just @id. |
boolean |
isFramework()
If true, the resource is in the android: framework.
|
static boolean |
isNullOrEmpty(java.lang.String url)
Returns if the resource url is @null, @empty or @undefined.
|
boolean |
isPrivateAccessOverride()
Whether this is a theme resource reference.
|
boolean |
isTheme()
Whether this is a theme resource reference.
|
static boolean |
isValidName(java.lang.String input,
ResourceType type) |
static ResourceUrl |
parse(java.lang.String url)
Returns a ResourceUrl representation of the given string, or null if it's not a
valid resource reference.
|
static ResourceUrl |
parse(java.lang.String url,
boolean defaultToFramework)
Returns a ResourceUrl representation of the given string, or null if it's not a
valid resource reference.
|
static ResourceUrl |
parseAttrReference(java.lang.String input)
Returns a ResourceUrl representation of the given reference to an
attr
resources, most likely the contents of <item name="..." >. |
static ResourceUrl |
parseStyleParentReference(java.lang.String input)
Returns a ResourceUrl representation of the given reference to a style's parent.
|
ResourceReference |
resolve(ResourceNamespace contextNamespace,
ResourceNamespace.Resolver resolver)
Tries to resolve this ResourceUrl into a valid
ResourceReference by
expanding the namespace alias (or lack thereof) based on the context in which this
ResourceUrl was used. |
java.lang.String |
toString() |
@NonNull public final ResourceType type
@NonNull public final java.lang.String name
@Nullable public final java.lang.String namespace
@NonNull public final ResourceUrl.UrlType urlType
public final boolean privateAccessOverride
public boolean isFramework()
public boolean isCreate()
@+id rather than just @id.public boolean isTheme()
public boolean isPrivateAccessOverride()
@Deprecated public static ResourceUrl create(@NonNull ResourceType type, @NonNull java.lang.String name, boolean framework)
type - the resource typename - the nameframework - whether it's a framework resourceparse(String)@NonNull public static ResourceUrl create(@Nullable java.lang.String namespace, @NonNull ResourceType type, @NonNull java.lang.String name)
namespace - the resource namespacetype - the resource typename - the nameparse(String)@NonNull public static ResourceUrl createThemeReference(@Nullable java.lang.String namespace, @NonNull ResourceType type, @NonNull java.lang.String name)
namespace - the resource namespacetype - the resource typename - the nameparse(String)@NonNull public static ResourceUrl createAttrReference(@Nullable java.lang.String namespace, @NonNull java.lang.String name)
namespace - the resource namespacename - the nameparse(String)@Nullable public static ResourceUrl parse(@NonNull java.lang.String url)
ResourceUrl.UrlType.NORMAL,
ResourceUrl.UrlType.CREATE and ResourceUrl.UrlType.THEME, see dedicated methods for parsing
references to style parents and to attr resources in the name XML attribute
of style items.url - the resource url to be parsed@Nullable public static ResourceUrl parse(@NonNull java.lang.String url, boolean defaultToFramework)
ResourceUrl.UrlType.NORMAL,
ResourceUrl.UrlType.CREATE and ResourceUrl.UrlType.THEME, see dedicated methods for parsing
references to style parents and to attr resources in the name XML attribute
of style items.url - the resource url to be parseddefaultToFramework - defaults the returned value to be a framework resource if no
namespace is specified.
TODO(namespaces): remove the defaultToFramework argument.
@Nullable public static ResourceUrl parseAttrReference(@NonNull java.lang.String input)
attr
resources, most likely the contents of <item name="..." >.@Nullable public static ResourceUrl parseStyleParentReference(@NonNull java.lang.String input)
public static boolean isNullOrEmpty(@NonNull
java.lang.String url)
public boolean hasValidName()
public static boolean isValidName(@NonNull
java.lang.String input,
@NonNull
ResourceType type)
@Nullable public ResourceReference resolve(@NonNull ResourceNamespace contextNamespace, @NonNull ResourceNamespace.Resolver resolver)
ResourceReference by
expanding the namespace alias (or lack thereof) based on the context in which this
ResourceUrl was used.contextNamespace - aapt namespace of the module in which this URL was usedresolver - logic for expanding namespaces aliases, most likely by walking up the XML
tree.ResourceNamespace.fromNamespacePrefix(String, ResourceNamespace,
ResourceNamespace.Resolver)public java.lang.String toString()
toString in class java.lang.Object@NonNull public java.lang.String getQualifiedName()
ResourceUrl.parse("@android:style/Theme").getQualifiedName() returns "android:Theme"
and ResourceUrl.parse("?myColor").getQualifiedName() returns "myColor".
This is used when the type is implicit, e.g. when specifying attribute for a style item or a parent for a style.
public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object