com.android.resources.FolderTypeRelationship Java Examples
The following examples show how to use
com.android.resources.FolderTypeRelationship.
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 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 #3
Source File: ResourceFolder.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
/** * Returns whether a file in the folder is generating a resource of a specified type. * @param type The {@link ResourceType} being looked up. */ public boolean hasResources(ResourceType type) { // Check if the folder type is able to generate resource of the type that was asked. // this is a first check to avoid going through the files. List<ResourceFolderType> folderTypes = FolderTypeRelationship.getRelatedFolders(type); boolean valid = false; for (ResourceFolderType rft : folderTypes) { if (rft == mType) { valid = true; break; } } if (valid) { if (mFiles != null) { for (ResourceFile f : mFiles) { if (f.hasResources(type)) { return true; } } } } return false; }
Example #4
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 #5
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 #6
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 #7
Source File: ResourceFolder.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * Returns whether a file in the folder is generating a resource of a specified type. * @param type The {@link ResourceType} being looked up. */ public boolean hasResources(ResourceType type) { // Check if the folder type is able to generate resource of the type that was asked. // this is a first check to avoid going through the files. List<ResourceFolderType> folderTypes = FolderTypeRelationship.getRelatedFolders(type); boolean valid = false; for (ResourceFolderType rft : folderTypes) { if (rft == mType) { valid = true; break; } } if (valid) { if (mFiles != null) { for (ResourceFile f : mFiles) { if (f.hasResources(type)) { return true; } } } } return false; }
Example #8
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 #9
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 #10
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 #11
Source File: ResourceFolder.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** * Returns whether a file in the folder is generating a resource of a specified type. * @param type The {@link ResourceType} being looked up. */ public boolean hasResources(ResourceType type) { // Check if the folder type is able to generate resource of the type that was asked. // this is a first check to avoid going through the files. List<ResourceFolderType> folderTypes = FolderTypeRelationship.getRelatedFolders(type); boolean valid = false; for (ResourceFolderType rft : folderTypes) { if (rft == mType) { valid = true; break; } } if (valid) { if (mFiles != null) { for (ResourceFile f : mFiles) { if (f.hasResources(type)) { return true; } } } } return false; }
Example #12
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 #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: ResourceSet.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Returns a FolderData for the given folder. * * @param folder the folder. * @return the FolderData object, or null if we can't determine the {#link ResourceFolderType} * of the folder. */ @Nullable private FolderData getFolderData(File folder) throws MergingException { FolderData fd = new FolderData(); String folderName = folder.getName(); int pos = folderName.indexOf(ResourceConstants.RES_QUALIFIER_SEP); if (pos != -1) { fd.folderType = ResourceFolderType.getTypeByName(folderName.substring(0, pos)); if (fd.folderType == null) { return null; } FolderConfiguration folderConfiguration = FolderConfiguration.getConfigForFolder(folderName); if (folderConfiguration == null) { throw MergingException.withMessage("Invalid resource directory name") .withFile(folder).build(); } if (mNormalizeResources) { // normalize it folderConfiguration.normalize(); } // get the qualifier portion from the folder config. // the returned string starts with "-" so we remove that. fd.qualifiers = folderConfiguration.getUniqueKey().substring(1); } else { fd.folderType = ResourceFolderType.getTypeByName(folderName); } if (fd.folderType != null && fd.folderType != ResourceFolderType.VALUES) { fd.type = FolderTypeRelationship.getRelatedResourceTypes(fd.folderType).get(0); } return fd; }
Example #15
Source File: LintUtils.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Determine if the given type corresponds to a resource that has a unique * file * * @param type the resource type to check * @return true if the given type corresponds to a file-type resource */ public static boolean isFileBasedResourceType(@NonNull ResourceType type) { List<ResourceFolderType> folderTypes = FolderTypeRelationship.getRelatedFolders(type); for (ResourceFolderType folderType : folderTypes) { if (folderType != ResourceFolderType.VALUES) { return type != ResourceType.ID; } } return false; }
Example #16
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 #17
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 #18
Source File: ResourceSet.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
/** * Returns a FolderData for the given folder * @param folder the folder. * @return the FolderData object. */ @Nullable private static FolderData getFolderData(File folder) { FolderData fd = new FolderData(); String folderName = folder.getName(); int pos = folderName.indexOf(ResourceConstants.RES_QUALIFIER_SEP); if (pos != -1) { fd.folderType = ResourceFolderType.getTypeByName(folderName.substring(0, pos)); if (fd.folderType == null) { return null; } FolderConfiguration folderConfiguration = FolderConfiguration.getConfigForFolder(folderName); if (folderConfiguration == null) { return null; } // normalize it folderConfiguration.normalize(); // get the qualifier portion from the folder config. // the returned string starts with "-" so we remove that. fd.qualifiers = folderConfiguration.getUniqueKey().substring(1); } else { fd.folderType = ResourceFolderType.getTypeByName(folderName); } if (fd.folderType != null && fd.folderType != ResourceFolderType.VALUES) { fd.type = FolderTypeRelationship.getRelatedResourceTypes(fd.folderType).get(0); } return fd; }
Example #19
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 #20
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 #21
Source File: SingleResourceFile.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
@Override public boolean hasResources(ResourceType type) { return FolderTypeRelationship.match(type, getFolder().getType()); }
Example #22
Source File: SingleResourceFile.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
@Override public Collection<ResourceType> getResourceTypes() { return FolderTypeRelationship.getRelatedResourceTypes(getFolder().getType()); }
Example #23
Source File: SingleResourceFile.java From javaide with GNU General Public License v3.0 | 4 votes |
@Override public boolean hasResources(ResourceType type) { return FolderTypeRelationship.match(type, getFolder().getType()); }
Example #24
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 #25
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 #26
Source File: SingleResourceFile.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
@Override public boolean hasResources(ResourceType type) { return FolderTypeRelationship.match(type, getFolder().getType()); }