Search in sources :

Example 26 with StyleResourceValue

use of com.android.ide.common.rendering.api.StyleResourceValue 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 27 with StyleResourceValue

use of com.android.ide.common.rendering.api.StyleResourceValue in project android by JetBrains.

the class ConfiguredThemeEditorStyle method getParentNames.

/**
   * Returns the names of all the parents of this style. Parents might differ depending on the folder configuration, this returns all the
   * variants for this style.
   */
public Collection<ConfiguredElement<String>> getParentNames() {
    if (isFramework()) {
        // Framework themes do not have multiple parents so we just get the only one.
        ConfiguredThemeEditorStyle parent = getParent();
        if (parent != null) {
            return ImmutableList.of(ConfiguredElement.create(new FolderConfiguration(), parent.getQualifiedName()));
        }
        // The theme has no parent (probably the main "Theme" style)
        return Collections.emptyList();
    }
    ImmutableList.Builder<ConfiguredElement<String>> parents = ImmutableList.builder();
    for (final ResourceItem styleItem : getStyleResourceItems()) {
        StyleResourceValue style = (StyleResourceValue) styleItem.getResourceValue(false);
        assert style != null;
        String parentName = ResolutionUtils.getParentQualifiedName(style);
        if (parentName != null) {
            parents.add(ConfiguredElement.create(styleItem.getConfiguration(), parentName));
        }
    }
    return parents.build();
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) ResourceItem(com.android.ide.common.res2.ResourceItem)

Example 28 with StyleResourceValue

use of com.android.ide.common.rendering.api.StyleResourceValue 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 29 with StyleResourceValue

use of com.android.ide.common.rendering.api.StyleResourceValue 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)

Example 30 with StyleResourceValue

use of com.android.ide.common.rendering.api.StyleResourceValue in project android by JetBrains.

the class ConfiguredThemeEditorStyle method getParent.

/**
   * @param themeResolver theme resolver that would be used to look up parent theme by name
   *                      Pass null if you don't care about resulting ThemeEditorStyle source module (which would be null in that case)
   * @return the style parent
   */
@Nullable
public /*if this is a root style*/
ConfiguredThemeEditorStyle getParent(@Nullable ThemeResolver themeResolver) {
    ResourceResolver resolver = myConfiguration.getResourceResolver();
    assert resolver != null;
    StyleResourceValue parent = resolver.getParent(getStyleResourceValue());
    if (parent == null) {
        return null;
    }
    if (themeResolver == null) {
        return ResolutionUtils.getStyle(myConfiguration, ResolutionUtils.getQualifiedStyleName(parent), null);
    } else {
        return themeResolver.getTheme(ResolutionUtils.getQualifiedStyleName(parent));
    }
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceResolver(com.android.ide.common.resources.ResourceResolver) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)69 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)41 BridgeTypedArray (android.content.res.BridgeTypedArray)18 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)15 PropertiesMap (com.android.util.PropertiesMap)15 Pair (com.android.util.Pair)12 RenderResources (com.android.ide.common.rendering.api.RenderResources)11 Property (com.android.util.PropertiesMap.Property)10 ResourceReference (com.android.ide.common.rendering.api.ResourceReference)9 ResourceItem (com.android.ide.common.res2.ResourceItem)7 ColorStateList (android.content.res.ColorStateList)6 BitmapDrawable (android.graphics.drawable.BitmapDrawable)6 Drawable (android.graphics.drawable.Drawable)6 TypedValue (android.util.TypedValue)6 TextView (android.widget.TextView)6 ResourceType (com.android.resources.ResourceType)6 FileNotFoundException (java.io.FileNotFoundException)6 NotNull (org.jetbrains.annotations.NotNull)6 Context (android.content.Context)5 ContextThemeWrapper (android.view.ContextThemeWrapper)5