Java Code Examples for com.android.ide.common.resources.configuration.FolderConfiguration#findMatchingConfigurable()

The following examples show how to use com.android.ide.common.resources.configuration.FolderConfiguration#findMatchingConfigurable() . 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: AbstractResourceRepository.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: ResourceRepository.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the list of source files for a given resource.
 * Optionally, if a {@link FolderConfiguration} is given, then only the best
 * match for this config is returned.
 *
 * @param type the type of the resource.
 * @param name the name of the resource.
 * @param referenceConfig an optional config for which only the best match will be returned.
 *
 * @return a list of files generating this resource or null if it was not found.
 */
@Nullable
public List<ResourceFile> getSourceFiles(@NonNull ResourceType type, @NonNull String name,
        @Nullable FolderConfiguration referenceConfig) {
    ensureInitialized();

    Collection<ResourceItem> items = getResourceItemsOfType(type);

    for (ResourceItem item : items) {
        if (name.equals(item.getName())) {
            if (referenceConfig != null) {
                Configurable match = referenceConfig.findMatchingConfigurable(
                        item.getSourceFileList());

                if (match instanceof ResourceFile) {
                    return Collections.singletonList((ResourceFile) match);
                }

                return null;
            }
            return item.getSourceFileList();
        }
    }

    return null;
}
 
Example 3
Source File: AbstractResourceRepository.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@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 4
Source File: ResourceRepository.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the list of source files for a given resource.
 * Optionally, if a {@link FolderConfiguration} is given, then only the best
 * match for this config is returned.
 *
 * @param type the type of the resource.
 * @param name the name of the resource.
 * @param referenceConfig an optional config for which only the best match will be returned.
 *
 * @return a list of files generating this resource or null if it was not found.
 */
@Nullable
public List<ResourceFile> getSourceFiles(@NonNull ResourceType type, @NonNull String name,
        @Nullable FolderConfiguration referenceConfig) {
    ensureInitialized();

    Collection<ResourceItem> items = getResourceItemsOfType(type);

    for (ResourceItem item : items) {
        if (name.equals(item.getName())) {
            if (referenceConfig != null) {
                Configurable match = referenceConfig.findMatchingConfigurable(
                        item.getSourceFileList());

                if (match instanceof ResourceFile) {
                    return Collections.singletonList((ResourceFile) match);
                }

                return null;
            }
            return item.getSourceFileList();
        }
    }

    return null;
}
 
Example 5
Source File: ResourceRepository.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the list of source files for a given resource.
 * Optionally, if a {@link FolderConfiguration} is given, then only the best
 * match for this config is returned.
 *
 * @param type the type of the resource.
 * @param name the name of the resource.
 * @param referenceConfig an optional config for which only the best match will be returned.
 *
 * @return a list of files generating this resource or null if it was not found.
 */
@Nullable
public List<ResourceFile> getSourceFiles(@NonNull ResourceType type, @NonNull String name,
        @Nullable FolderConfiguration referenceConfig) {
    ensureInitialized();

    Collection<ResourceItem> items = getResourceItemsOfType(type);

    for (ResourceItem item : items) {
        if (name.equals(item.getName())) {
            if (referenceConfig != null) {
                ResourceFile match =
                        referenceConfig.findMatchingConfigurable(item.getSourceFileList());
                if (match != null) {
                    return Collections.singletonList((ResourceFile) match);
                }

                return null;
            }
            return item.getSourceFileList();
        }
    }

    return null;
}
 
Example 6
Source File: AbstractResourceRepository.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@NonNull
public Map<String, ResourceValue> getConfiguredResources(
        @NonNull Map<ResourceType, ListMultimap<String, ResourceItem>> itemMap,
        @NonNull ResourceType type,
        @NonNull FolderConfiguration referenceConfig) {
    // get the resource item for the given type
    ListMultimap<String, ResourceItem> items = itemMap.get(type);
    if (items == null) {
        return Maps.newHashMap();
    }

    Set<String> keys = items.keySet();

    // create the map
    Map<String, ResourceValue> map = Maps.newHashMapWithExpectedSize(keys.size());

    for (String key : keys) {
        List<ResourceItem> keyItems = items.get(key);

        // 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);
        if (match != null) {
            ResourceValue value = match.getResourceValue(mFramework);
            if (value != null) {
                map.put(match.getName(), value);
            }
        }
    }

    return map;
}
 
Example 7
Source File: ResourceItem.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link ResourceValue} for this item based on the given configuration.
 * If the ResourceItem has several source files, one will be selected based on the config.
 * @param type the type of the resource. This is necessary because ResourceItem doesn't embed
 *     its type, but ResourceValue does.
 * @param referenceConfig the config of the resource item.
 * @param isFramework whether the resource is a framework value. Same as the type.
 * @return a ResourceValue or null if none match the config.
 */
public ResourceValue getResourceValue(ResourceType type, FolderConfiguration referenceConfig,
        boolean isFramework) {
    // 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
    ResourceFile match = (ResourceFile) referenceConfig.findMatchingConfigurable(mFiles);

    if (match != null) {
        // get the value of this configured resource.
        return match.getValue(type, mName);
    }

    return null;
}
 
Example 8
Source File: AbstractResourceRepository.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
public Map<String, ResourceValue> getConfiguredResources(
        @NonNull Map<ResourceType, ListMultimap<String, ResourceItem>> itemMap,
        @NonNull ResourceType type,
        @NonNull FolderConfiguration referenceConfig) {
    // get the resource item for the given type
    ListMultimap<String, ResourceItem> items = itemMap.get(type);
    if (items == null) {
        return Maps.newHashMap();
    }

    Set<String> keys = items.keySet();

    // create the map
    Map<String, ResourceValue> map = Maps.newHashMapWithExpectedSize(keys.size());

    for (String key : keys) {
        List<ResourceItem> keyItems = items.get(key);

        // 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);
        if (match != null) {
            ResourceValue value = match.getResourceValue(mFramework);
            if (value != null) {
                map.put(match.getName(), value);
            }
        }
    }

    return map;
}
 
Example 9
Source File: ResourceItem.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a {@link ResourceValue} for this item based on the given configuration.
 * If the ResourceItem has several source files, one will be selected based on the config.
 * @param type the type of the resource. This is necessary because ResourceItem doesn't embed
 *     its type, but ResourceValue does.
 * @param referenceConfig the config of the resource item.
 * @param isFramework whether the resource is a framework value. Same as the type.
 * @return a ResourceValue or null if none match the config.
 */
public ResourceValue getResourceValue(ResourceType type, FolderConfiguration referenceConfig,
        boolean isFramework) {
    // 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
    ResourceFile match = (ResourceFile) referenceConfig.findMatchingConfigurable(mFiles);

    if (match != null) {
        // get the value of this configured resource.
        return match.getValue(type, mName);
    }

    return null;
}
 
Example 10
Source File: ResourceItem.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link ResourceValue} for this item based on the given configuration.
 * If the ResourceItem has several source files, one will be selected based on the config.
 * @param type the type of the resource. This is necessary because ResourceItem doesn't embed
 *     its type, but ResourceValue does.
 * @param referenceConfig the config of the resource item.
 * @param isFramework whether the resource is a framework value. Same as the type.
 * @return a ResourceValue or null if none match the config.
 */
public ResourceValue getResourceValue(ResourceType type, FolderConfiguration referenceConfig,
        boolean isFramework) {
    // 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
    ResourceFile match = (ResourceFile) referenceConfig.findMatchingConfigurable(mFiles);

    if (match != null) {
        // get the value of this configured resource.
        return match.getValue(type, mName);
    }

    return null;
}