• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ide.common.resources;
18 
19 import com.android.ide.common.rendering.api.ResourceValue;
20 import com.android.ide.common.resources.configuration.Configurable;
21 import com.android.ide.common.resources.configuration.FolderConfiguration;
22 import com.android.io.IAbstractFile;
23 import com.android.resources.ResourceType;
24 
25 import java.util.Collection;
26 
27 /**
28  * Represents a Resource file (a file under $Project/res/)
29  */
30 public abstract class ResourceFile implements Configurable {
31 
32     private final IAbstractFile mFile;
33     private final ResourceFolder mFolder;
34 
ResourceFile(IAbstractFile file, ResourceFolder folder)35     protected ResourceFile(IAbstractFile file, ResourceFolder folder) {
36         mFile = file;
37         mFolder = folder;
38     }
39 
load(ScanningContext context)40     protected abstract void load(ScanningContext context);
update(ScanningContext context)41     protected abstract void update(ScanningContext context);
dispose(ScanningContext context)42     protected abstract void dispose(ScanningContext context);
43 
getConfiguration()44     public FolderConfiguration getConfiguration() {
45         return mFolder.getConfiguration();
46     }
47 
48     /**
49      * Returns the IFile associated with the ResourceFile.
50      */
getFile()51     public final IAbstractFile getFile() {
52         return mFile;
53     }
54 
55     /**
56      * Returns the parent folder as a {@link ResourceFolder}.
57      */
getFolder()58     public final ResourceFolder getFolder() {
59         return mFolder;
60     }
61 
getRepository()62     public final ResourceRepository getRepository() {
63         return mFolder.getRepository();
64     }
65 
66     /**
67      * Returns whether the resource is a framework resource.
68      */
isFramework()69     public final boolean isFramework() {
70         return mFolder.getRepository().isFrameworkRepository();
71     }
72 
73     /**
74      * Returns the list of {@link ResourceType} generated by the file. This is never null.
75      */
getResourceTypes()76     public abstract Collection<ResourceType> getResourceTypes();
77 
78     /**
79      * Returns whether the file generated a resource of a specific type.
80      * @param type The {@link ResourceType}
81      */
hasResources(ResourceType type)82     public abstract boolean hasResources(ResourceType type);
83 
84     /**
85      * Returns the value of a resource generated by this file by {@link ResourceType} and name.
86      * <p/>If no resource match, <code>null</code> is returned.
87      * @param type the type of the resource.
88      * @param name the name of the resource.
89      */
getValue(ResourceType type, String name)90     public abstract ResourceValue getValue(ResourceType type, String name);
91 
92     @Override
toString()93     public String toString() {
94         return mFile.toString();
95     }
96 }
97 
98