Search in sources :

Example 1 with ResourceFile

use of com.android.ide.common.resources.ResourceFile in project android by JetBrains.

the class ConfiguredThemeEditorStyle method getConfiguredValues.

/**
   * Returns all the style attributes and its values. For each attribute, multiple {@link ConfiguredElement} can be returned
   * representing the multiple values in different configurations for each item.
   * TODO: needs to be deleted, as we don't use this method except tests
   */
@NotNull
public ImmutableCollection<ConfiguredElement<ItemResourceValue>> getConfiguredValues() {
    // Get a list of all the items indexed by the item name. Each item contains a list of the
    // possible values in this theme in different configurations.
    //
    // If item1 has multiple values in different configurations, there will be an
    // item1 = {folderConfiguration1 -> value1, folderConfiguration2 -> value2}
    final ImmutableList.Builder<ConfiguredElement<ItemResourceValue>> itemResourceValues = ImmutableList.builder();
    if (isFramework()) {
        assert myConfiguration.getFrameworkResources() != null;
        com.android.ide.common.resources.ResourceItem styleItem = myConfiguration.getFrameworkResources().getResourceItem(ResourceType.STYLE, myStyleResourceValue.getName());
        // Go over all the files containing the resource.
        for (ResourceFile file : styleItem.getSourceFileList()) {
            ResourceValue styleResourceValue = file.getValue(ResourceType.STYLE, styleItem.getName());
            FolderConfiguration folderConfiguration = file.getConfiguration();
            if (styleResourceValue instanceof StyleResourceValue) {
                for (final ItemResourceValue value : ((StyleResourceValue) styleResourceValue).getValues()) {
                    itemResourceValues.add(ConfiguredElement.create(folderConfiguration, value));
                }
            }
        }
    } else {
        for (ResourceItem styleDefinition : getStyleResourceItems()) {
            ResourceValue styleResourceValue = styleDefinition.getResourceValue(isFramework());
            FolderConfiguration folderConfiguration = styleDefinition.getConfiguration();
            if (styleResourceValue instanceof StyleResourceValue) {
                for (final ItemResourceValue value : ((StyleResourceValue) styleResourceValue).getValues()) {
                    // We use the qualified name since apps and libraries can use the same attribute name twice with and without "android:"
                    itemResourceValues.add(ConfiguredElement.create(folderConfiguration, value));
                }
            }
        }
    }
    return itemResourceValues.build();
}
Also used : FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) ResourceFile(com.android.ide.common.resources.ResourceFile) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceItem(com.android.ide.common.res2.ResourceItem) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ResourceFile

use of com.android.ide.common.resources.ResourceFile in project android by JetBrains.

the class ThemeEditorStyle method getParentName.

/**
   * @param configuration FolderConfiguration of the style to lookup
   * @return parent this style with a FolderConfiguration configuration
   */
@Nullable
public /*if there is no of this style*/
String getParentName(@NotNull FolderConfiguration configuration) {
    if (isFramework()) {
        IAndroidTarget target = myManager.getHighestApiTarget();
        assert target != null;
        com.android.ide.common.resources.ResourceItem styleItem = myManager.getResolverCache().getFrameworkResources(new FolderConfiguration(), target).getResourceItem(ResourceType.STYLE, getName());
        for (ResourceFile file : styleItem.getSourceFileList()) {
            if (file.getConfiguration().equals(configuration)) {
                StyleResourceValue style = (StyleResourceValue) file.getValue(ResourceType.STYLE, getName());
                return ResolutionUtils.getParentQualifiedName(style);
            }
        }
        throw new IllegalArgumentException("bad folder config " + configuration);
    }
    for (final ResourceItem styleItem : getStyleResourceItems()) {
        if (configuration.equals(styleItem.getConfiguration())) {
            StyleResourceValue style = (StyleResourceValue) styleItem.getResourceValue(false);
            assert style != null;
            return ResolutionUtils.getParentQualifiedName(style);
        }
    }
    throw new IllegalArgumentException("bad folder config " + configuration);
}
Also used : ResourceFile(com.android.ide.common.resources.ResourceFile) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) IAndroidTarget(com.android.sdklib.IAndroidTarget) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) ResourceItem(com.android.ide.common.res2.ResourceItem) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ResourceFile

use of com.android.ide.common.resources.ResourceFile in project android by JetBrains.

the class ThemeEditorStyle method getValues.

/**
   * @param configuration FolderConfiguration of the style to lookup
   * @return all values defined in this style with a FolderConfiguration configuration
   */
@NotNull
public Collection<ItemResourceValue> getValues(@NotNull FolderConfiguration configuration) {
    if (isFramework()) {
        IAndroidTarget target = myManager.getHighestApiTarget();
        assert target != null;
        com.android.ide.common.resources.ResourceItem styleItem = myManager.getResolverCache().getFrameworkResources(new FolderConfiguration(), target).getResourceItem(ResourceType.STYLE, getName());
        for (ResourceFile file : styleItem.getSourceFileList()) {
            if (file.getConfiguration().equals(configuration)) {
                StyleResourceValue style = (StyleResourceValue) file.getValue(ResourceType.STYLE, getName());
                return style.getValues();
            }
        }
        throw new IllegalArgumentException("bad folder config " + configuration);
    }
    for (final ResourceItem styleItem : getStyleResourceItems()) {
        if (configuration.equals(styleItem.getConfiguration())) {
            StyleResourceValue style = (StyleResourceValue) styleItem.getResourceValue(false);
            if (style == null) {
                // style might be null if the value fails to parse
                continue;
            }
            return style.getValues();
        }
    }
    throw new IllegalArgumentException("bad folder config " + configuration);
}
Also used : ResourceFile(com.android.ide.common.resources.ResourceFile) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) IAndroidTarget(com.android.sdklib.IAndroidTarget) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) ResourceItem(com.android.ide.common.res2.ResourceItem) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)3 ResourceItem (com.android.ide.common.res2.ResourceItem)3 ResourceFile (com.android.ide.common.resources.ResourceFile)3 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)3 IAndroidTarget (com.android.sdklib.IAndroidTarget)2 NotNull (org.jetbrains.annotations.NotNull)2 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)1 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)1 Nullable (org.jetbrains.annotations.Nullable)1