Java Code Examples for com.android.resources.FolderTypeRelationship#getRelatedResourceTypes()
The following examples show how to use
com.android.resources.FolderTypeRelationship#getRelatedResourceTypes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceFolder.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
private ResourceFile createResourceFile(IAbstractFile file) { // check if that's a single or multi resource type folder. For now we define this by // the number of possible resource type output by files in the folder. // We have a special case for layout/menu folders which can also generate IDs. // This does // not make the difference between several resource types from a single file or // the ability to have 2 files in the same folder generating 2 different types of // resource. The former is handled by MultiResourceFile properly while we don't // handle the latter. If we were to add this behavior we'd have to change this call. List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(mType); ResourceFile resFile = null; if (types.size() == 1) { resFile = new SingleResourceFile(file, this); } else if (types.contains(ResourceType.LAYOUT)) { resFile = new IdGeneratingResourceFile(file, this, ResourceType.LAYOUT); } else if (types.contains(ResourceType.MENU)) { resFile = new IdGeneratingResourceFile(file, this, ResourceType.MENU); } else { resFile = new MultiResourceFile(file, this); } return resFile; }
Example 2
Source File: ResourceRepository.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** * Returns the {@link ResourceFile} matching the given name, * {@link ResourceFolderType} and configuration. * <p/> * This only works with files generating one resource named after the file * (for instance, layouts, bitmap based drawable, xml, anims). * * @param name the resource name or file name * @param type the folder type search for * @param config the folder configuration to match for * @return the matching file or <code>null</code> if no match was found. */ @Nullable public ResourceFile getMatchingFile( @NonNull String name, @NonNull ResourceFolderType type, @NonNull FolderConfiguration config) { List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(type); for (ResourceType t : types) { if (t == ResourceType.ID) { continue; } ResourceFile match = getMatchingFile(name, t, config); if (match != null) { return match; } } return null; }
Example 3
Source File: SingleResourceFile.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
public SingleResourceFile(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. List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folder.getType()); mType = types.get(0); // compute the resource name mResourceName = getResourceName(mType); // test if there's a density qualifier associated with the resource DensityQualifier qualifier = folder.getConfiguration().getDensityQualifier(); if (qualifier == null) { mValue = new ResourceValue(mType, getResourceName(mType), file.getOsLocation(), isFramework()); } else { mValue = new DensityBasedResourceValue( mType, getResourceName(mType), file.getOsLocation(), qualifier.getValue(), isFramework()); } }
Example 4
Source File: ResourceRepository.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
/** * Returns the {@link ResourceFile} matching the given name, * {@link ResourceFolderType} and configuration. * <p> * This only works with files generating one resource named after the file * (for instance, layouts, bitmap based drawable, xml, anims). * * @param name the resource name or file name * @param type the folder type search for * @param config the folder configuration to match for * @return the matching file or <code>null</code> if no match was found. */ @Nullable public ResourceFile getMatchingFile( @NonNull String name, @NonNull ResourceFolderType type, @NonNull FolderConfiguration config) { List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(type); for (ResourceType t : types) { if (t == ResourceType.ID) { continue; } ResourceFile match = getMatchingFile(name, t, config); if (match != null) { return match; } } return null; }
Example 5
Source File: ResourceFolder.java From javaide with GNU General Public License v3.0 | 6 votes |
private ResourceFile createResourceFile(IAbstractFile file) { // check if that's a single or multi resource type folder. For now we define this by // the number of possible resource type output by files in the folder. // We have a special case for layout/menu folders which can also generate IDs. // This does // not make the difference between several resource types from a single file or // the ability to have 2 files in the same folder generating 2 different types of // resource. The former is handled by MultiResourceFile properly while we don't // handle the latter. If we were to add this behavior we'd have to change this call. List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(mType); ResourceFile resFile = null; if (types.size() == 1) { resFile = new SingleResourceFile(file, this); } else if (types.contains(ResourceType.LAYOUT)) { resFile = new IdGeneratingResourceFile(file, this, ResourceType.LAYOUT); } else if (types.contains(ResourceType.MENU)) { resFile = new IdGeneratingResourceFile(file, this, ResourceType.MENU); } else { resFile = new MultiResourceFile(file, this); } return resFile; }
Example 6
Source File: ResourceFolder.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
private ResourceFile createResourceFile(IAbstractFile file) { // check if that's a single or multi resource type folder. We have a special case // for ID generating resource types (layout/menu, and XML drawables, etc.). // MultiResourceFile handles the case when several resource types come from a single file // (values files). ResourceFile resFile; if (mType != ResourceFolderType.VALUES) { if (FolderTypeRelationship.isIdGeneratingFolderType(mType) && SdkUtils.endsWithIgnoreCase(file.getName(), SdkConstants.DOT_XML)) { List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(mType); ResourceType primaryType = types.get(0); resFile = new IdGeneratingResourceFile(file, this, primaryType); } else { resFile = new SingleResourceFile(file, this); } } else { resFile = new MultiResourceFile(file, this, namespace); } return resFile; }
Example 7
Source File: ResourceRepository.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * Returns the {@link ResourceFile} matching the given name, * {@link ResourceFolderType} and configuration. * <p/> * This only works with files generating one resource named after the file * (for instance, layouts, bitmap based drawable, xml, anims). * * @param name the resource name or file name * @param type the folder type search for * @param config the folder configuration to match for * @return the matching file or <code>null</code> if no match was found. */ @Nullable public ResourceFile getMatchingFile( @NonNull String name, @NonNull ResourceFolderType type, @NonNull FolderConfiguration config) { List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(type); for (ResourceType t : types) { if (t == ResourceType.ID) { continue; } ResourceFile match = getMatchingFile(name, t, config); if (match != null) { return match; } } return null; }
Example 8
Source File: SingleResourceFile.java From javaide with GNU General Public License v3.0 | 6 votes |
public SingleResourceFile(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. List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folder.getType()); mType = types.get(0); // compute the resource name mResourceName = getResourceName(mType); // test if there's a density qualifier associated with the resource DensityQualifier qualifier = folder.getConfiguration().getDensityQualifier(); if (qualifier == null) { mValue = new ResourceValue(mType, getResourceName(mType), file.getOsLocation(), isFramework()); } else { mValue = new DensityBasedResourceValue( mType, getResourceName(mType), file.getOsLocation(), qualifier.getValue(), isFramework()); } }
Example 9
Source File: ResourceRepository.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
@NonNull public List<ResourceType> getAvailableResourceTypes() { ensureInitialized(); List<ResourceType> list = new ArrayList<ResourceType>(); // For each key, we check if there's a single ResourceType match. // If not, we look for the actual content to give us the resource type. for (ResourceFolderType folderType : mFolderMap.keySet()) { List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folderType); if (types.size() == 1) { // before we add it we check if it's not already present, since a ResourceType // could be created from multiple folders, even for the folders that only create // one type of resource (drawable for instance, can be created from drawable/ and // values/) if (list.contains(types.get(0)) == false) { list.add(types.get(0)); } } else { // there isn't a single resource type out of this folder, so we look for all // content. List<ResourceFolder> folders = mFolderMap.get(folderType); if (folders != null) { for (ResourceFolder folder : folders) { Collection<ResourceType> folderContent = folder.getResourceTypes(); // then we add them, but only if they aren't already in the list. for (ResourceType folderResType : folderContent) { if (list.contains(folderResType) == false) { list.add(folderResType); } } } } } } return list; }
Example 10
Source File: SingleResourceFile.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
public SingleResourceFile(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. List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folder.getType()); mType = types.get(0); // compute the resource name mResourceName = getResourceName(mType); // test if there's a density qualifier associated with the resource DensityQualifier qualifier = folder.getConfiguration().getDensityQualifier(); if (!ResourceQualifier.isValid(qualifier)) { mValue = new ResourceValueImpl( new ResourceReference(mType, getResourceName(mType), isFramework()), file.getOsLocation()); } else { mValue = new DensityBasedResourceValueImpl( new ResourceReference(mType, getResourceName(mType), isFramework()), file.getOsLocation(), qualifier.getValue()); } }
Example 11
Source File: ResourceRepository.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
@NonNull public List<ResourceType> getAvailableResourceTypes() { ensureInitialized(); List<ResourceType> list = new ArrayList<ResourceType>(); // For each key, we check if there's a single ResourceType match. // If not, we look for the actual content to give us the resource type. for (ResourceFolderType folderType : mFolderMap.keySet()) { List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folderType); if (types.size() == 1) { // before we add it we check if it's not already present, since a ResourceType // could be created from multiple folders, even for the folders that only create // one type of resource (drawable for instance, can be created from drawable/ and // values/) if (!list.contains(types.get(0))) { list.add(types.get(0)); } } else { // there isn't a single resource type out of this folder, so we look for all // content. List<ResourceFolder> folders = mFolderMap.get(folderType); if (folders != null) { for (ResourceFolder folder : folders) { Collection<ResourceType> folderContent = folder.getResourceTypes(); // then we add them, but only if they aren't already in the list. for (ResourceType folderResType : folderContent) { if (!list.contains(folderResType)) { list.add(folderResType); } } } } } } return list; }
Example 12
Source File: ResourceRepository.java From javaide with GNU General Public License v3.0 | 5 votes |
@NonNull public List<ResourceType> getAvailableResourceTypes() { ensureInitialized(); List<ResourceType> list = new ArrayList<ResourceType>(); // For each key, we check if there's a single ResourceType match. // If not, we look for the actual content to give us the resource type. for (ResourceFolderType folderType : mFolderMap.keySet()) { List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folderType); if (types.size() == 1) { // before we add it we check if it's not already present, since a ResourceType // could be created from multiple folders, even for the folders that only create // one type of resource (drawable for instance, can be created from drawable/ and // values/) if (list.contains(types.get(0)) == false) { list.add(types.get(0)); } } else { // there isn't a single resource type out of this folder, so we look for all // content. List<ResourceFolder> folders = mFolderMap.get(folderType); if (folders != null) { for (ResourceFolder folder : folders) { Collection<ResourceType> folderContent = folder.getResourceTypes(); // then we add them, but only if they aren't already in the list. for (ResourceType folderResType : folderContent) { if (list.contains(folderResType) == false) { list.add(folderResType); } } } } } } return list; }
Example 13
Source File: PrivateResourceDetector.java From javaide with GNU General Public License v3.0 | 5 votes |
@Override public void beforeCheckFile(@NonNull Context context) { File file = context.file; boolean isXmlFile = LintUtils.isXmlFile(file); if (!isXmlFile && !LintUtils.isBitmapFile(file)) { return; } String parentName = file.getParentFile().getName(); int dash = parentName.indexOf('-'); if (dash != -1 || FD_RES_VALUES.equals(parentName)) { return; } ResourceFolderType folderType = ResourceFolderType.getFolderType(parentName); if (folderType == null) { return; } List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folderType); if (types.isEmpty()) { return; } ResourceType type = types.get(0); String resourceName = getResourceFieldName(getBaseName(file.getName())); if (isPrivate(context, type, resourceName)) { String message = createOverrideErrorMessage(context, type, resourceName); Location location = Location.create(file); context.report(ISSUE, location, message); } }
Example 14
Source File: ResourceUsageAnalyzer.java From javaide with GNU General Public License v3.0 | 5 votes |
@Nullable private Resource getResourceByJarPath(String path) { // Jars use forward slash paths, not File.separator if (path.startsWith("res/")) { int folderStart = 4; // "res/".length int folderEnd = path.indexOf('/', folderStart); if (folderEnd != -1) { String folderName = path.substring(folderStart, folderEnd); ResourceFolderType folderType = ResourceFolderType.getFolderType(folderName); if (folderType != null) { int nameStart = folderEnd + 1; int nameEnd = path.indexOf('.', nameStart); if (nameEnd != -1) { String name = path.substring(nameStart, nameEnd); List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folderType); for (ResourceType type : types) { if (type != ResourceType.ID) { Resource resource = getResource(type, name); if (resource != null) { return resource; } } } } } } } return null; }
Example 15
Source File: SingleResourceFile.java From javaide with GNU General Public License v3.0 | 4 votes |
@Override public Collection<ResourceType> getResourceTypes() { return FolderTypeRelationship.getRelatedResourceTypes(getFolder().getType()); }
Example 16
Source File: SingleResourceFile.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
@Override public Collection<ResourceType> getResourceTypes() { return FolderTypeRelationship.getRelatedResourceTypes(getFolder().getType()); }
Example 17
Source File: SingleResourceFile.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
@Override public Collection<ResourceType> getResourceTypes() { return FolderTypeRelationship.getRelatedResourceTypes(getFolder().getType()); }