com.android.ide.common.res2
Class ResourceItem

java.lang.Object
  extended by com.android.ide.common.res2.ResourceItem
All Implemented Interfaces:
Configurable, java.lang.Comparable<ResourceItem>
Direct Known Subclasses:
GeneratedResourceItem

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

A resource. This includes the name, type, source file as a ResourceFile and an optional Node in case of a resource coming from a value file.


Field Summary
protected  com.android.ide.common.rendering.api.ResourceValue mResourceValue
           
 
Constructor Summary
ResourceItem(java.lang.String name, com.android.resources.ResourceType type, org.w3c.dom.Node value)
          Constructs the object with a name, type and optional value.
 
Method Summary
 int compareTo(ResourceItem resourceItem)
           
 boolean compareValueWith(ResourceItem resource)
          Compares the ResourceItem getValue() together and returns true if they are the same.
 boolean equals(java.lang.Object o)
           
 FolderConfiguration getConfiguration()
          Returns the FolderConfiguration for this object.
 java.io.File getFile()
          For non-values resources, this is the original source file.
 boolean getIgnoredFromDiskMerge()
           
 java.lang.String getKey()
          Returns a key for this resource.
 java.lang.String getName()
          Returns the name of the item.
 java.lang.String getQualifiers()
          Returns the resource item qualifiers.
 com.android.ide.common.rendering.api.ResourceValue getResourceValue(boolean isFrameworks)
           
 F getSource()
          Returns the DataFile the item is coming from.
 com.android.ide.common.res2.DataFile.FileType getSourceType()
           
protected  int getStatus()
          Obtains the full status of the data item; should not generally be used except for debug purposes.
 com.android.resources.ResourceType getType()
          Returns the type of the resource.
 org.w3c.dom.Node getValue()
          Returns the optional value of the resource.
 java.lang.String getValueText()
          Returns the optional string value of the 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.
 int hashCode()
           
 void setIgnoredFromDiskMerge(boolean ignored)
           
 void setSource(F sourceFile)
          Sets the DataFile.
 java.lang.String toString()
           
protected  void wasTouched()
          Hook invoked when the data item has been touched.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

mResourceValue

@Nullable
protected com.android.ide.common.rendering.api.ResourceValue mResourceValue
Constructor Detail

ResourceItem

public ResourceItem(@NonNull
                    java.lang.String name,
                    @NonNull
                    com.android.resources.ResourceType type,
                    @Nullable
                    org.w3c.dom.Node value)
Constructs the object with a name, type and optional value. Note that the object is not fully usable as-is. It must be added to a ResourceFile first.

Parameters:
name - the name of the resource
type - the type of the resource
value - an optional Node that represents the resource value.
Method Detail

getType

@NonNull
public com.android.resources.ResourceType getType()
Returns the type of the resource.

Returns:
the type.

getValue

@Nullable
public org.w3c.dom.Node getValue()
Returns the optional value of the resource. Can be null

Returns:
the value or null.

getValueText

@Nullable
public java.lang.String getValueText()
Returns the optional string value of the resource. Can be null

Returns:
the value or null.

getQualifiers

@NonNull
public java.lang.String getQualifiers()
Returns the resource item qualifiers.

Returns:
the qualifiers

getSourceType

@NonNull
public com.android.ide.common.res2.DataFile.FileType getSourceType()

getConfiguration

public FolderConfiguration getConfiguration()
Description copied from interface: Configurable
Returns the FolderConfiguration for this object.

Specified by:
getConfiguration in interface Configurable

getKey

public java.lang.String getKey()
Returns a key for this resource. They key uniquely identifies this resource by combining resource type, qualifiers, and name. If the resource has not been added to a ResourceFile, this will throw an IllegalStateException.

Returns:
the key for this resource.
Throws:
java.lang.IllegalStateException - if the resource is not added to a ResourceFile

wasTouched

protected void wasTouched()
Hook invoked when the data item has been touched. The default implementation does nothing.


getResourceValue

@Nullable
public com.android.ide.common.rendering.api.ResourceValue getResourceValue(boolean isFrameworks)

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]

compareValueWith

public boolean compareValueWith(ResourceItem resource)
Compares the ResourceItem getValue() together and returns true if they are the same.

Parameters:
resource - The ResourceItem object to compare to.
Returns:
true if equal

toString

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

equals

public boolean equals(java.lang.Object o)

hashCode

public int hashCode()

compareTo

public int compareTo(@NonNull
                     ResourceItem resourceItem)
Specified by:
compareTo in interface java.lang.Comparable<ResourceItem>

setIgnoredFromDiskMerge

public void setIgnoredFromDiskMerge(boolean ignored)

getIgnoredFromDiskMerge

public boolean getIgnoredFromDiskMerge()

getName

@NonNull
public java.lang.String getName()
Returns the name of the item.


getSource

@Nullable
public F getSource()
Returns the DataFile the item is coming from.


setSource

public void setSource(@NonNull
                      F sourceFile)
Sets the DataFile. The item must not belong to a data file.

Parameters:
sourceFile - the data file, if null then the item is marked as being removed from the data file

getStatus

protected int getStatus()
Obtains the full status of the data item; should not generally be used except for debug purposes.

Returns:
the internal representation

getFile

public java.io.File getFile()
For non-values resources, this is the original source file. This method is here as GeneratedResourceItem overrides it.