FileDocCategorySizeDatePackage
SingleResourceFile.javaAPI DocAndroid 1.5 API5297Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.resources.manager

SingleResourceFile

public class SingleResourceFile extends ResourceFile
Represents a resource file describing a single resource.

This is typically an XML file inside res/anim, res/layout, or res/menu or an image file under res/drawable.

Fields Summary
private static final SAXParserFactory
sParserFactory
private static final Pattern
sXmlPattern
private static final Pattern[]
sDrawablePattern
private String
mResourceName
private com.android.ide.eclipse.common.resources.ResourceType
mType
private com.android.layoutlib.api.IResourceValue
mValue
Constructors Summary
public SingleResourceFile(com.android.ide.eclipse.editors.resources.manager.files.IAbstractFile file, ResourceFolder folder)


         
        super(file, folder);
        
        // we need to infer the type of the resource from the folder type.
        // This is easy since this is a single Resource file.
        ResourceType[] types = FolderTypeRelationship.getRelatedResourceTypes(folder.getType());
        mType = types[0];

        // compute the resource name
        mResourceName = getResourceName(mType);
        
        mValue = new ResourceValue(mType.getName(), getResourceName(mType), file.getOsLocation(),
                isFramework());
    
Methods Summary
private java.lang.StringgetResourceName(com.android.ide.eclipse.common.resources.ResourceType type)
Returns the name of the resources.

        // get the name from the filename.
        String name = getFile().getName();
        
        if (type == ResourceType.ANIM || type == ResourceType.LAYOUT || type == ResourceType.MENU ||
                type == ResourceType.COLOR || type == ResourceType.XML) {
            Matcher m = sXmlPattern.matcher(name);
            if (m.matches()) {
                return m.group(1);
            }
        } else if (type == ResourceType.DRAWABLE) {
            for (Pattern p : sDrawablePattern) {
                Matcher m = p.matcher(name);
                if (m.matches()) {
                    return m.group(1);
                }
            }
            
            // also try the Xml pattern for selector/shape based drawable.
            Matcher m = sXmlPattern.matcher(name);
            if (m.matches()) {
                return m.group(1);
            }
        }
        return name;
    
public com.android.ide.eclipse.common.resources.ResourceType[]getResourceTypes()

        return FolderTypeRelationship.getRelatedResourceTypes(getFolder().getType());
    
public java.util.CollectiongetResources(com.android.ide.eclipse.common.resources.ResourceType type, ProjectResources projectResources)

        
        // looking for an existing ResourceItem with this name and type
        ProjectResourceItem item = projectResources.findResourceItem(type, mResourceName);
        
        ArrayList<ProjectResourceItem> items = new ArrayList<ProjectResourceItem>();

        if (item == null) {
            item = new ConfigurableResourceItem(mResourceName);
            items.add(item);
        }
        
        // add this ResourceFile to the ResourceItem
        item.add(this);
        
        return items;
    
public com.android.layoutlib.api.IResourceValuegetValue(com.android.ide.eclipse.common.resources.ResourceType type, java.lang.String name)

        return mValue;
    
public booleanhasResources(com.android.ide.eclipse.common.resources.ResourceType type)

        return FolderTypeRelationship.match(type, getFolder().getType());