FolderTypeRelationshippublic final class FolderTypeRelationship extends Object This class gives access to the bi directional relationship between {@link ResourceType} and
{@link ResourceFolderType}. |
Fields Summary |
---|
private static final HashMap | mTypeToFolderMap | private static final HashMap | mFolderToTypeMap |
Methods Summary |
---|
private static void | add(com.android.ide.eclipse.common.resources.ResourceType type, ResourceFolderType folder, java.util.HashMap typeToFolderMap, java.util.HashMap folderToTypeMap)Adds a {@link ResourceType} - {@link ResourceFolderType} relationship. this indicates that
a file in the folder can generate a resource of the specified type.
// first we add the folder to the list associated with the type.
List<ResourceFolderType> folderList = typeToFolderMap.get(type);
if (folderList == null) {
folderList = new ArrayList<ResourceFolderType>();
typeToFolderMap.put(type, folderList);
}
if (folderList.indexOf(folder) == -1) {
folderList.add(folder);
}
// now we add the type to the list associated with the folder.
List<ResourceType> typeList = folderToTypeMap.get(folder);
if (typeList == null) {
typeList = new ArrayList<ResourceType>();
folderToTypeMap.put(folder, typeList);
}
if (typeList.indexOf(type) == -1) {
typeList.add(type);
}
| public static ResourceFolderType[] | getRelatedFolders(com.android.ide.eclipse.common.resources.ResourceType resType)Returns a list of {@link ResourceFolderType} that can contain files generating resources
of the specified type.
ResourceFolderType[] array = mTypeToFolderMap.get(resType);
if (array != null) {
return array;
}
return new ResourceFolderType[0];
| public static com.android.ide.eclipse.common.resources.ResourceType[] | getRelatedResourceTypes(ResourceFolderType folderType)Returns a list of {@link ResourceType}s that can be generated from files inside a folder
of the specified type.
// generate the relationships.
HashMap<ResourceType, List<ResourceFolderType>> typeToFolderMap =
new HashMap<ResourceType, List<ResourceFolderType>>();
HashMap<ResourceFolderType, List<ResourceType>> folderToTypeMap =
new HashMap<ResourceFolderType, List<ResourceType>>();
add(ResourceType.ANIM, ResourceFolderType.ANIM, typeToFolderMap, folderToTypeMap);
add(ResourceType.ARRAY, ResourceFolderType.VALUES, typeToFolderMap, folderToTypeMap);
add(ResourceType.COLOR, ResourceFolderType.VALUES, typeToFolderMap, folderToTypeMap);
add(ResourceType.COLOR, ResourceFolderType.COLOR, typeToFolderMap, folderToTypeMap);
add(ResourceType.DIMEN, ResourceFolderType.VALUES, typeToFolderMap, folderToTypeMap);
add(ResourceType.DRAWABLE, ResourceFolderType.VALUES, typeToFolderMap, folderToTypeMap);
add(ResourceType.DRAWABLE, ResourceFolderType.DRAWABLE, typeToFolderMap, folderToTypeMap);
add(ResourceType.ID, ResourceFolderType.VALUES, typeToFolderMap, folderToTypeMap);
add(ResourceType.LAYOUT, ResourceFolderType.LAYOUT, typeToFolderMap, folderToTypeMap);
add(ResourceType.MENU, ResourceFolderType.MENU, typeToFolderMap, folderToTypeMap);
add(ResourceType.RAW, ResourceFolderType.RAW, typeToFolderMap, folderToTypeMap);
add(ResourceType.STRING, ResourceFolderType.VALUES, typeToFolderMap, folderToTypeMap);
add(ResourceType.STYLE, ResourceFolderType.VALUES, typeToFolderMap, folderToTypeMap);
add(ResourceType.XML, ResourceFolderType.XML, typeToFolderMap, folderToTypeMap);
optimize(typeToFolderMap, folderToTypeMap);
ResourceType[] array = mFolderToTypeMap.get(folderType);
if (array != null) {
return array;
}
return new ResourceType[0];
| public static boolean | match(com.android.ide.eclipse.common.resources.ResourceType resType, ResourceFolderType folderType)Returns true if the {@link ResourceType} and the {@link ResourceFolderType} values match.
ResourceFolderType[] array = mTypeToFolderMap.get(resType);
if (array != null && array.length > 0) {
for (ResourceFolderType fType : array) {
if (fType == folderType) {
return true;
}
}
}
return false;
| private static void | optimize(java.util.HashMap typeToFolderMap, java.util.HashMap folderToTypeMap)Optimize the map to contains array instead of lists (since the api returns arrays)
Set<ResourceType> types = typeToFolderMap.keySet();
for (ResourceType type : types) {
List<ResourceFolderType> list = typeToFolderMap.get(type);
mTypeToFolderMap.put(type, list.toArray(new ResourceFolderType[list.size()]));
}
Set<ResourceFolderType> folders = folderToTypeMap.keySet();
for (ResourceFolderType folder : folders) {
List<ResourceType> list = folderToTypeMap.get(folder);
mFolderToTypeMap.put(folder, list.toArray(new ResourceType[list.size()]));
}
|
|