com.android.resources.ResourceType Java Examples
The following examples show how to use
com.android.resources.ResourceType.
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: ProjectCallback.java From javaide with GNU General Public License v3.0 | 6 votes |
public Integer getResourceId(ResourceType type, String name) { // since we don't have access to compiled id, generate one on the fly. Map<String, Integer> typeMap = mIdMap.get(type); if (typeMap == null) { typeMap = new HashMap<String, Integer>(); mIdMap.put(type, typeMap); } Integer value = typeMap.get(name); if (value == null) { value = typeMap.size() + 1; typeMap.put(name, value); mReverseIdMap.put(value, Pair.of(type, name)); } return value; }
Example #2
Source File: KotlinResourcePsiElementFinder.java From intellij with Apache License 2.0 | 6 votes |
/** Checks if `expression` matches an expected R.abc.xyz pattern. */ private static boolean isResourceExpression(PsiElement expression) { if (!(expression instanceof KtQualifiedExpression)) { return false; } KtQualifiedExpression qualifiedExpression = (KtQualifiedExpression) expression; // qualifier should be `R.abc` which is also a `KtQualifiedExpression` PsiElement qualifier = qualifiedExpression.getReceiverExpression(); if (!(qualifier instanceof KtQualifiedExpression)) { return false; } KtQualifiedExpression qualifierExpression = (KtQualifiedExpression) qualifier; // rClassExpression should be `R` PsiElement rClassExpression = qualifierExpression.getReceiverExpression(); // rTypeExpression should be `abc` PsiElement rTypeExpression = qualifierExpression.getSelectorExpression(); return rTypeExpression != null && SdkConstants.R_CLASS.equals(rClassExpression.getText()) && ResourceType.fromClassName(rTypeExpression.getText()) != null; }
Example #3
Source File: IdGeneratingResourceFile.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
@Override public ResourceValue getValue(ResourceType type, String name) { // Check to see if they're asking for one of the right types: if (type != mFileType && type != ResourceType.ID) { return null; } // If they're looking for a resource of this type with this name give them the whole file if (type == mFileType && name.equals(mFileName)) { return mFileValue; } else { // Otherwise try to return them an ID // the map will return null if it's not found return mIdResources.get(name); } }
Example #4
Source File: IdGeneratingResourceFile.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** * Add the resources represented by this file to the repository */ private void updateResourceItems(ScanningContext context) { ResourceRepository repository = getRepository(); // remove this file from all existing ResourceItem. repository.removeFile(mResourceTypeList, this); // First add this as a layout file ResourceItem item = repository.getResourceItem(mFileType, mFileName); item.add(this); // Now iterate through our IDs and add for (String idName : mIdResources.keySet()) { item = repository.getResourceItem(ResourceType.ID, idName); // add this file to the list of files generating ID resources. item.add(this); } // Ask the repository for an ID refresh context.requestFullAapt(); }
Example #5
Source File: MultiResourceFile.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
/** * Adds a resource item to the list * @param value The value of the resource. */ @Override public void addResourceValue(ResourceValue value) { ResourceType resType = value.getResourceType(); ResourceValueMap list = mResourceItems.get(resType); // if the list does not exist, create it. if (list == null) { list = ResourceValueMap.create(); mResourceItems.put(resType, list); } else { // look for a possible value already existing. ResourceValue oldValue = list.get(value.getName()); if (oldValue != null) { oldValue.replaceWith(value); return; } } // empty list or no match found? add the given resource list.put(value.getName(), value); }
Example #6
Source File: AbstractResourceRepository.java From javaide with GNU General Public License v3.0 | 6 votes |
@Nullable public ResourceValue getConfiguredValue( @NonNull ResourceType type, @NonNull String name, @NonNull FolderConfiguration referenceConfig) { // get the resource item for the given type ListMultimap<String, ResourceItem> items = getMap(type, false); if (items == null) { return null; } List<ResourceItem> keyItems = items.get(name); if (keyItems == null) { return null; } // look for the best match for the given configuration // the match has to be of type ResourceFile since that's what the input list contains ResourceItem match = (ResourceItem) referenceConfig.findMatchingConfigurable(keyItems); return match != null ? match.getResourceValue(mFramework) : null; }
Example #7
Source File: ResourceFolder.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
/** * Returns the list of {@link ResourceType}s generated by the files inside this folder. */ public Collection<ResourceType> getResourceTypes() { ArrayList<ResourceType> list = new ArrayList<ResourceType>(); if (mFiles != null) { for (ResourceFile file : mFiles) { Collection<ResourceType> types = file.getResourceTypes(); // loop through those and add them to the main list, // if they are not already present for (ResourceType resType : types) { if (list.indexOf(resType) == -1) { list.add(resType); } } } } return list; }
Example #8
Source File: ResourceVisibilityLookup.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * Returns true if the given resource is private in the library * * @param type the type of the resource * @param name the name of the resource * @return true if the given resource is private */ @Override public boolean isPrivate(@NonNull ResourceType type, @NonNull String name) { //noinspection SimplifiableIfStatement if (mPublic == null) { // No public definitions: Everything assumed to be public return false; } //noinspection SimplifiableIfStatement if (!mAll.containsEntry(name, type)) { // Don't respond to resource URLs that are not part of this project // since we won't have private information on them return false; } return !mPublic.containsEntry(name, type); }
Example #9
Source File: ResourceResolver.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
/** * Updates the parent of a given framework style. This method is used to * patch DeviceDefault styles when using a CompatibilityTarget. */ public void patchAutoStyleParent(String childStyleName, String parentName) { // TODO(namespaces): why only framework styles? ResourceValueMap map = getResourceValueMap(ResourceNamespace.RES_AUTO, ResourceType.STYLE); if (map != null) { StyleResourceValue from = (StyleResourceValue) map.get(childStyleName); StyleResourceValue to = (StyleResourceValue) map.get(parentName); if (from != null && to != null) { StyleResourceValue newStyle = new StyleResourceValueImpl( from.asReference(), parentName, from.getLibraryName()); newStyle.replaceWith(from); mStyleInheritanceMap.put(newStyle, to); mReverseStyleInheritanceMap.clear(); } } }
Example #10
Source File: IdGeneratingResourceFile.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
/** * Add the resources represented by this file to the repository */ private void updateResourceItems(ScanningContext context) { ResourceRepository repository = getRepository(); // remove this file from all existing ResourceItem. repository.removeFile(mResourceTypeList, this); // First add this as a layout file ResourceItem item = repository.getResourceItem(mFileType, mFileName); item.add(this); // Now iterate through our IDs and add for (String idName : mIdResources.keySet()) { item = repository.getResourceItem(ResourceType.ID, idName); // add this file to the list of files generating ID resources. item.add(this); } // Ask the repository for an ID refresh context.requestFullAapt(); }
Example #11
Source File: ResourceRepository.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
/** * Returns the resources values matching a given {@link FolderConfiguration} for the current * project. * * @param referenceConfig the configuration that each value must match. * @return a map with guaranteed to contain an entry for each {@link ResourceType} */ @NonNull protected final Map<ResourceType, ResourceValueMap> doGetConfiguredResources( @NonNull FolderConfiguration referenceConfig) { ensureInitialized(); Map<ResourceType, ResourceValueMap> map = new EnumMap<ResourceType, ResourceValueMap>(ResourceType.class); for (ResourceType key : ResourceType.values()) { // get the local results and put them in the map map.put(key, getConfiguredResource(key, referenceConfig)); } return map; }
Example #12
Source File: ResourceName.java From bazel with Apache License 2.0 | 6 votes |
/** * Constructs a ResourceName from the canonical form used throughout Android ({@code * [<pkg>:]<type>/<entry>}). */ // While we use aapt2 to convert XML data to protobuf, we still need to do some parsing: // // https://android.googlesource.com/platform/frameworks/base.git/+/refs/tags/platform-tools-29.0.2/tools/aapt2/Resources.proto#232 static ResourceName parse(String name) { Matcher matcher = FullyQualifiedName.QUALIFIED_REFERENCE.matcher(name); verify( matcher.matches(), "%s is not a valid resource name. Expected %s", name, FullyQualifiedName.QUALIFIED_REFERENCE); return create( Strings.nullToEmpty(matcher.group("package")), ResourceType.getEnum(matcher.group("type")), matcher.group("name")); }
Example #13
Source File: AbstractResourceRepository.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** * Returns the resources values matching a given {@link FolderConfiguration}. * * @param referenceConfig the configuration that each value must match. * @return a map with guaranteed to contain an entry for each {@link ResourceType} */ @NonNull public Map<ResourceType, Map<String, ResourceValue>> getConfiguredResources( @NonNull FolderConfiguration referenceConfig) { Map<ResourceType, Map<String, ResourceValue>> map = Maps.newEnumMap(ResourceType.class); synchronized (ITEM_MAP_LOCK) { Map<ResourceType, ListMultimap<String, ResourceItem>> itemMap = getMap(); for (ResourceType key : ResourceType.values()) { // get the local results and put them in the map map.put(key, getConfiguredResources(itemMap, key, referenceConfig)); } } return map; }
Example #14
Source File: MultiResourceFile.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** * Adds a resource item to the list * @param value The value of the resource. */ @Override public void addResourceValue(ResourceValue value) { ResourceType resType = value.getResourceType(); Map<String, ResourceValue> list = mResourceItems.get(resType); // if the list does not exist, create it. if (list == null) { list = new HashMap<String, ResourceValue>(); mResourceItems.put(resType, list); } else { // look for a possible value already existing. ResourceValue oldValue = list.get(value.getName()); if (oldValue != null) { oldValue.replaceWith(value); return; } } // empty list or no match found? add the given resource list.put(value.getName(), value); }
Example #15
Source File: MultiResourceFile.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
private void updateResourceItems(ScanningContext context) { ResourceRepository repository = getRepository(); // remove this file from all existing ResourceItem. repository.removeFile(mResourceTypeList, this); for (ResourceType type : mResourceTypeList) { Map<String, ResourceValue> list = mResourceItems.get(type); if (list != null) { Collection<ResourceValue> values = list.values(); for (ResourceValue res : values) { ResourceItem item = repository.getResourceItem(type, res.getName()); // add this file to the list of files generating this resource item. item.add(this); } } } // If we need an ID refresh, ask the repository for that now if (mNeedIdRefresh) { context.requestFullAapt(); } }
Example #16
Source File: PublicXmlResourceValue.java From bazel with Apache License 2.0 | 6 votes |
@Override public XmlResourceValue combineWith(XmlResourceValue value) { if (!(value instanceof PublicXmlResourceValue)) { throw new IllegalArgumentException(value + "is not combinable with " + this); } PublicXmlResourceValue other = (PublicXmlResourceValue) value; Map<ResourceType, Optional<Integer>> combined = new EnumMap<>(ResourceType.class); combined.putAll(typeToId); for (Map.Entry<ResourceType, Optional<Integer>> entry : other.typeToId.entrySet()) { Optional<Integer> existing = combined.get(entry.getKey()); if (existing != null && !existing.equals(entry.getValue())) { throw new IllegalArgumentException( String.format( "Public resource of type %s assigned two different id values 0x%x and 0x%x", entry.getKey(), existing.orNull(), entry.getValue().orNull())); } combined.put(entry.getKey(), entry.getValue()); } return of(combined); }
Example #17
Source File: AtlasSymbolIo.java From atlas with Apache License 2.0 | 6 votes |
@Nullable private static AtlasSymbolIo.SymbolData readLine(@NonNull String line, @Nullable AtlasSymbolIo.SymbolFilter filter) throws IOException { // format is "<type> <class> <name> <value>" // don't want to split on space as value could contain spaces. int pos = line.indexOf(' '); String typeName = line.substring(0, pos); SymbolJavaType type = SymbolJavaType.getEnum(typeName); int pos2 = line.indexOf(' ', pos + 1); String className = line.substring(pos + 1, pos2); if (filter != null && !filter.validate(className, typeName)) { return null; } ResourceType resourceType = ResourceType.getEnum(className); if (resourceType == null) { throw new IOException("Invalid resource type " + className); } int pos3 = line.indexOf(' ', pos2 + 1); String name = line.substring(pos2 + 1, pos3); String value = line.substring(pos3 + 1); return new SymbolData(resourceType, name, type, value); }
Example #18
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 #19
Source File: ResourceClassGeneratorConfig.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
public int getOrCreateId(ResourceNamespace namespace, ResourceType resourceType, String name) { Map<ResourceReference, Integer> references = resources.get(resourceType); Map<String, Integer> names = resourceNamesToId.get(resourceType); if (references == null) { references = new HashMap<>(); resources.put(resourceType, references); } if (names == null) { names = new HashMap<>(); resourceNamesToId.put(resourceType, names); } ResourceReference reference = new ResourceReference(namespace, resourceType, name); Integer value = references.get(reference); if (value == null) { value = getCounter(resourceType).incrementAndGet(); references.put(reference, value); names.put(name, value); resourcesReverse.put(value, reference); } return value; }
Example #20
Source File: ResourceResolver.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
/** * Creates a new {@link ResourceResolver} object. * * @param resources all resources. * @param themeReference reference to the theme to be used. * @return a new {@link ResourceResolver} */ public static ResourceResolver create( @NonNull Map<ResourceNamespace, Map<ResourceType, ResourceValueMap>> resources, @Nullable ResourceReference themeReference) { StyleResourceValue theme = null; if (themeReference != null) { assert themeReference.getResourceType() == ResourceType.STYLE; theme = findTheme(themeReference, resources); } ResourceResolver resolver = new ResourceResolver(resources, theme); resolver.preProcessStyles(); return resolver; }
Example #21
Source File: InlineResourceItem.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
@Override public ResourceValue getResourceValue(ResourceType type, FolderConfiguration referenceConfig, boolean isFramework) { assert type == ResourceType.ID; if (mValue == null) { mValue = new ResourceValue(type, getName(), isFramework); } return mValue; }
Example #22
Source File: ValueResourceParser.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
private ResourceType getType(String qName, Attributes attributes) { String typeValue; // if the node is <item>, we get the type from the attribute "type" if (NODE_ITEM.equals(qName)) { typeValue = attributes.getValue(ATTR_TYPE); } else { // the type is the name of the node. typeValue = qName; } ResourceType type = ResourceType.getEnum(typeValue); return type; }
Example #23
Source File: ResourceVisibilityLookup.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Returns a map from name to applicable resource types where the presence of the type+name * combination means that the corresponding resource is explicitly public. * * If the result is null, there is no {@code public.txt} definition for this library, so all * resources should be taken to be public. * * @return a map from name to resource type for public resources in this library */ @Nullable private Multimap<String, ResourceType> computeVisibilityMap() { File publicResources = mLibrary.getPublicResources(); if (!publicResources.exists()) { return null; } try { List<String> lines = Files.readLines(publicResources, Charsets.UTF_8); Multimap<String, ResourceType> result = ArrayListMultimap.create(lines.size(), 2); for (String line : lines) { // These files are written by code in MergedResourceWriter#postWriteAction // Format for each line: <type><space><name>\n // Therefore, we don't expect/allow variations in the format (we don't // worry about extra spaces needing to be trimmed etc) int index = line.indexOf(' '); if (index == -1 || line.isEmpty()) { continue; } String typeString = line.substring(0, index); ResourceType type = ResourceType.getEnum(typeString); if (type == null) { // This could in theory happen if in the future a new ResourceType is // introduced, and a newer version of the Gradle build system writes the // name of this type into the public.txt file, and an older version of // the IDE then attempts to read it. Just skip these symbols. continue; } String name = line.substring(index + 1); result.put(name, type); } return result; } catch (IOException ignore) { } return null; }
Example #24
Source File: ResourceRepository.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Returns whether the repository has resources of a given {@link ResourceType}. * @param type the type of resource to check. * @return true if the repository contains resources of the given type, false otherwise. */ public boolean hasResourcesOfType(@NonNull ResourceType type) { ensureInitialized(); Map<String, ResourceItem> items = mResourceMap.get(type); return (items != null && !items.isEmpty()); }
Example #25
Source File: ValueResourceParser.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
public StyleResourceValueImpl2( @NonNull ResourceNamespace namespace, @NonNull ResourceType type, @NonNull String name, @com.android.annotations.Nullable String parentStyle, @com.android.annotations.Nullable String libraryName) { super(namespace, type, name, parentStyle, libraryName); }
Example #26
Source File: ResourceResolver.java From javaide with GNU General Public License v3.0 | 5 votes |
private ResourceResolver( Map<ResourceType, Map<String, ResourceValue>> projectResources, Map<ResourceType, Map<String, ResourceValue>> frameworkResources, String themeName, boolean isProjectTheme) { mProjectResources = projectResources; mFrameworkResources = frameworkResources; mThemeName = themeName; mIsProjectTheme = isProjectTheme; mThemes = new LinkedList<StyleResourceValue>(); }
Example #27
Source File: MultiResourceFile.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
@Override protected void update(ScanningContext context) { // Reset the ID generation flag mNeedIdRefresh = false; // Copy the previous version of our list of ResourceItems and types Map<ResourceType, ResourceValueMap> oldResourceItems = new EnumMap<ResourceType, ResourceValueMap>(mResourceItems); // reset current content. mResourceItems.clear(); // need to parse the file and find the content. parseFile(); // create new ResourceItems for the new content. mResourceTypeList = Collections.unmodifiableCollection(mResourceItems.keySet()); // Check to see if any names have changed. If so, mark the flag so updateResourceItems // can notify the ResourceRepository that an ID refresh is needed if (oldResourceItems.keySet().equals(mResourceItems.keySet())) { for (ResourceType type : mResourceTypeList) { // We just need to check the names of the items. // If there are new or removed names then we'll have to regenerate IDs if (mResourceItems.get(type).keySet() .equals(oldResourceItems.get(type).keySet()) == false) { mNeedIdRefresh = true; } } } else { // If our type list is different, obviously the names will be different mNeedIdRefresh = true; } // create/update the resource items. updateResourceItems(context); }
Example #28
Source File: BlazeRClass.java From intellij with Apache License 2.0 | 5 votes |
public BlazeRClass(PsiManager psiManager, AndroidFacet androidFacet, String packageName) { super( psiManager, new ResourcesSource() { @Override public String getPackageName() { return packageName; } @Override public LocalResourceRepository getResourceRepository() { return ResourceRepositoryManager.getAppResources(androidFacet); } @Override public ResourceNamespace getResourceNamespace() { return ResourceNamespace.RES_AUTO; } @Override public AndroidLightField.FieldModifier getFieldModifier() { return AndroidLightField.FieldModifier.NON_FINAL; } @Override public boolean isPublic(ResourceType resourceType, String resourceName) { return true; } }); this.androidFacet = androidFacet; setModuleInfo(getModule(), false); VirtualFile virtualFile = myFile.getViewProvider().getVirtualFile(); virtualFile.putUserData( MODULE_POINTER_KEY, ModulePointerManager.getInstance(getProject()).create(getModule())); virtualFile.putUserData(LIGHT_CLASS_KEY, ResourceRepositoryRClass.class); }
Example #29
Source File: SingleResourceFile.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Returns the name of the resources. */ private String getResourceName(ResourceType type) { // get the name from the filename. String name = getFile().getName(); int pos = name.indexOf('.'); if (pos != -1) { name = name.substring(0, pos); } return name; }
Example #30
Source File: ResourceResolver.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
private RecordingResourceResolver( @NonNull List<ResourceValue> lookupChain, @NonNull Map<ResourceNamespace, Map<ResourceType, ResourceValueMap>> resources, @Nullable StyleResourceValue theme) { super(resources, theme); mLookupChain = lookupChain; }