Search in sources :

Example 1 with ThemeEditorStyle

use of com.android.tools.idea.editors.theme.datamodels.ThemeEditorStyle in project android by JetBrains.

the class ThemeAttributeResolver method resolveFromInheritance.

private void resolveFromInheritance(@NotNull ThemeEditorStyle themeEditorStyle, @NotNull FolderConfiguration configuration, @NotNull RestrictedConfiguration restricted, @NotNull Set<String> seenAttributes) {
    RestrictedConfiguration styleRestricted = getRestrictedConfiguration(themeEditorStyle, configuration);
    if (styleRestricted == null) {
        LOG.warn(configuration + " is unreachable");
        return;
    }
    styleRestricted = restricted.intersect(styleRestricted);
    if (styleRestricted == null) {
        return;
    }
    Set<String> newSeenAttributes = new HashSet<String>(seenAttributes);
    for (ItemResourceValue item : themeEditorStyle.getValues(configuration)) {
        String itemName = ResolutionUtils.getQualifiedItemName(item);
        if (!newSeenAttributes.contains(itemName)) {
            myItemValueMap.putValue(itemName, ConfiguredElement.create(styleRestricted.getAny(), item));
            newSeenAttributes.add(itemName);
        }
    }
    String parentName = themeEditorStyle.getParentName(configuration);
    if (parentName == null) {
        // We have reached the top of the theme hierarchy (i.e "android:Theme")
        return;
    }
    ThemeEditorStyle parent = new ThemeEditorStyle(myManager, parentName);
    for (FolderConfiguration folder : parent.getFolders()) {
        resolveFromInheritance(parent, folder, styleRestricted, newSeenAttributes);
    }
}
Also used : ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ThemeEditorStyle) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) RestrictedConfiguration(com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration)

Example 2 with ThemeEditorStyle

use of com.android.tools.idea.editors.theme.datamodels.ThemeEditorStyle in project android by JetBrains.

the class ThemeAttributeResolver method resolveAll.

@NotNull
private List<EditedStyleItem> resolveAll() {
    ThemeEditorStyle theme = new ThemeEditorStyle(myManager, myStyle.getQualifiedName());
    for (FolderConfiguration folder : theme.getFolders()) {
        resolveFromInheritance(myStyle, folder, new RestrictedConfiguration(), new HashSet<String>());
    }
    List<EditedStyleItem> result = Lists.newArrayList();
    FolderConfiguration configuration = myStyle.getConfiguration().getFullConfig();
    for (String key : myItemValueMap.keySet()) {
        Collection<ConfiguredElement<ItemResourceValue>> itemValues = myItemValueMap.get(key);
        final ConfiguredElement<ItemResourceValue> selectedValue = (ConfiguredElement<ItemResourceValue>) configuration.findMatchingConfigurable(Lists.<Configurable>newArrayList(itemValues));
        if (selectedValue == null) {
            // TODO: there is NO value for this attribute in the current config,so instead we need to show "no value for current device"
            result.add(new EditedStyleItem(itemValues.iterator().next(), itemValues, myStyle));
        } else {
            itemValues.remove(selectedValue);
            assert !itemValues.contains(selectedValue);
            result.add(new EditedStyleItem(selectedValue, itemValues, myStyle));
        }
    }
    return result;
}
Also used : ConfiguredElement(com.android.tools.idea.editors.theme.datamodels.ConfiguredElement) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ThemeEditorStyle) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configurable(com.android.ide.common.resources.configuration.Configurable) RestrictedConfiguration(com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)2 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)2 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)2 ThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ThemeEditorStyle)2 RestrictedConfiguration (com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration)2 Configurable (com.android.ide.common.resources.configuration.Configurable)1 ConfiguredElement (com.android.tools.idea.editors.theme.datamodels.ConfiguredElement)1 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)1 NotNull (org.jetbrains.annotations.NotNull)1