com.android.ide.common.resources
Class ResourceItem

java.lang.Object
  extended by com.android.ide.common.resources.ResourceItem
All Implemented Interfaces:
java.lang.Comparable<ResourceItem>
Direct Known Subclasses:
InlineResourceItem

public class ResourceItem
extends java.lang.Object
implements java.lang.Comparable<ResourceItem>

An android resource. This is a representation of the resource, not of its value(s). It gives access to all the source files that generate this particular resource which then can be used to access the actual value(s).


Constructor Summary
ResourceItem(java.lang.String name)
          Constructs a new ResourceItem.
 
Method Summary
protected  void add(ResourceFile file)
          Adds a new source file.
 int compareTo(ResourceItem other)
          Compares the ResourceItem to another.
 int getAlternateCount()
          Returns the number of alternate versions for this resource.
 java.lang.String getName()
          Returns the name of the resource.
 com.android.ide.common.rendering.api.ResourceValue getResourceValue(com.android.resources.ResourceType type, FolderConfiguration referenceConfig, boolean isFramework)
          Returns a ResourceValue for this item based on the given configuration.
 ResourceFile[] getSourceFileArray()
          Returns the sorted list of ResourceItem objects for this resource item.
 java.util.List<ResourceFile> getSourceFileList()
          Returns the list of source file for this resource.
 java.lang.String getXmlString(com.android.resources.ResourceType type, boolean system)
          Returns a formatted string usable in an XML to use for the ResourceItem.
 boolean hasAlternates()
          Returns if the resource has at least one non-default version.
 boolean hasDefault()
          Returns whether the resource has a default version, with no qualifier.
protected  boolean hasNoSourceFile()
          Returns true if the item has no source file.
 boolean isDeclaredInline()
          Returns whether the ID resource has been declared inline inside another resource XML file.
 boolean isEditableDirectly()
          Returns whether the resource is editable directly.
protected  void removeFile(ResourceFile file)
          Removes a file from the list of source files.
protected  void reset()
          Reset the item by emptying its source file list.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResourceItem

public ResourceItem(java.lang.String name)
Constructs a new ResourceItem.

Parameters:
name - the name of the resource as it appears in the XML and R.java files.
Method Detail

getName

public final java.lang.String getName()
Returns the name of the resource.


compareTo

public int compareTo(ResourceItem other)
Compares the ResourceItem to another.

Specified by:
compareTo in interface java.lang.Comparable<ResourceItem>
Parameters:
other - the ResourceItem to be compared to.

isEditableDirectly

public boolean isEditableDirectly()
Returns whether the resource is editable directly.

This is typically the case for resources that don't have alternate versions, or resources of type ResourceType.ID that aren't declared inline.


isDeclaredInline

public boolean isDeclaredInline()
Returns whether the ID resource has been declared inline inside another resource XML file. If the resource type is not ResourceType.ID, this will always return false.


getResourceValue

public com.android.ide.common.rendering.api.ResourceValue getResourceValue(com.android.resources.ResourceType type,
                                                                           FolderConfiguration referenceConfig,
                                                                           boolean isFramework)
Returns a ResourceValue for this item based on the given configuration. If the ResourceItem has several source files, one will be selected based on the config.

Parameters:
type - the type of the resource. This is necessary because ResourceItem doesn't embed its type, but ResourceValue does.
referenceConfig - the config of the resource item.
isFramework - whether the resource is a framework value. Same as the type.
Returns:
a ResourceValue or null if none match the config.

add

protected void add(ResourceFile file)
Adds a new source file.

Parameters:
file - the source file.

removeFile

protected void removeFile(ResourceFile file)
Removes a file from the list of source files.

Parameters:
file - the file to remove

hasNoSourceFile

protected boolean hasNoSourceFile()
Returns true if the item has no source file.

Returns:
true if the item has no source file.

reset

protected void reset()
Reset the item by emptying its source file list.


getSourceFileArray

public ResourceFile[] getSourceFileArray()
Returns the sorted list of ResourceItem objects for this resource item.


getSourceFileList

public java.util.List<ResourceFile> getSourceFileList()
Returns the list of source file for this resource.


hasAlternates

public boolean hasAlternates()
Returns if the resource has at least one non-default version.

See Also:
ResourceFile.getConfiguration(), FolderConfiguration.isDefault()

hasDefault

public boolean hasDefault()
Returns whether the resource has a default version, with no qualifier.

See Also:
ResourceFile.getConfiguration(), FolderConfiguration.isDefault()

getAlternateCount

public int getAlternateCount()
Returns the number of alternate versions for this resource.

See Also:
ResourceFile.getConfiguration(), FolderConfiguration.isDefault()

getXmlString

public java.lang.String getXmlString(com.android.resources.ResourceType type,
                                     boolean system)
Returns a formatted string usable in an XML to use for the ResourceItem.

Parameters:
system - Whether this is a system resource or a project resource.
Returns:
a string in the format @[type]/[name]

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object