Search in sources :

Example 6 with ItemResourceValue

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

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

the class ChooseResourceDialog method selectResourceValue.

private void selectResourceValue(@Nullable ResourceValue resValue) {
    // initial selection
    if (resValue != null) {
        ResourcePanel panel = getSelectedPanel();
        if (panel.select(resValue)) {
            return;
        }
        // Selection not found in the current panel: switch tab to show it
        ResourceType type;
        if (resValue instanceof ItemResourceValue) {
            // type is always null for ItemResourceValue
            type = ResolutionUtils.getAttrType((ItemResourceValue) resValue, myConfiguration);
        } else {
            type = resValue.getResourceType();
        }
        // panel is null if the reference is incorrect, e.g. "@sdfgsdfgs" (user error).
        if (type != null) {
            panel = getPanel(myTabbedPane, type);
            if (panel != null) {
                if (myTabbedPane != null) {
                    myTabbedPane.setSelectedComponent(panel.myComponent.getParent());
                }
                if (!panel.select(resValue) && type == ResourceType.COLOR) {
                    // You might have selected a private framework color; we *can* edit these
                    panel.showPreview(null, true);
                }
            }
        }
    }
}
Also used : CreateXmlResourcePanel(org.jetbrains.android.actions.CreateXmlResourcePanel) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ResourceType(com.android.resources.ResourceType)

Example 8 with ItemResourceValue

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

the class ThemeAttributeResolverTest method testResolveAllVersion.

/**
   * Tests {@link ThemeAttributeResolver#resolveAll(ConfiguredThemeEditorStyle, ThemeResolver)}
   */
public void testResolveAllVersion() {
    VirtualFile myFile = myFixture.copyFileToProject("themeEditor/styles.xml", "res/values/styles.xml");
    VirtualFile resourceDir = myFile.getParent().getParent();
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myFile);
    createNewStyle(resourceDir, "ThemeA", "android:Theme", "red", Lists.newArrayList("values-v13", "values-v16"));
    createNewStyle(resourceDir, "ThemeB", "ThemeA", "blue", Lists.newArrayList("values-v12"));
    createNewStyle(resourceDir, "ThemeB", "ThemeA", null, Lists.newArrayList("values-v15"));
    // ResourceFolderRepository needs to rescan the files to pick up the changes.
    UIUtil.dispatchAllInvocationEvents();
    ThemeResolver themeResolver = new ThemeResolver(configuration);
    ConfiguredThemeEditorStyle style = themeResolver.getTheme("ThemeB");
    assertNotNull(style);
    Set<String> answer = Sets.newHashSet("-v16:red", "-v15:red", "-v14:blue");
    List<EditedStyleItem> items = ThemeAttributeResolver.resolveAll(style, configuration.getConfigurationManager());
    boolean foundColorPrimary = false;
    for (EditedStyleItem item : items) {
        if (item.getName().equals("colorPrimary") && item.getAttrGroup().equals("Other non-theme attributes.")) {
            foundColorPrimary = true;
            assertEquals(answer.size(), item.getAllConfiguredItems().size());
            for (ConfiguredElement<ItemResourceValue> value : item.getAllConfiguredItems()) {
                assertTrue(answer.contains(value.getConfiguration().getUniqueKey() + ":" + value.getElement().getValue()));
            }
        }
    }
    assertTrue(foundColorPrimary);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)

Example 9 with ItemResourceValue

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

the class EditedStyleItemTest method testValueSetters.

public void testValueSetters() {
    // Do a simple instantiation and check that the setters update the right value
    VirtualFile myLayout = myFixture.copyFileToProject("xmlpull/layout.xml", "res/layout/layout1.xml");
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myLayout);
    // We just get a theme that we use as fake source to pass to the ConfiguredItemResourceValue constructor
    ConfiguredThemeEditorStyle fakeTheme = ResolutionUtils.getStyle(configuration, "android:Theme", null);
    assertNotNull(fakeTheme);
    //noinspection ConstantConditions
    List<ConfiguredElement<ItemResourceValue>> items = ImmutableList.of(ConfiguredElement.create(FolderConfiguration.getConfigForFolder("values-v21"), new ItemResourceValue("attribute", false, "otherValue", false, null)));
    EditedStyleItem editedStyleItem = new EditedStyleItem(ConfiguredElement.create(new FolderConfiguration(), new ItemResourceValue("attribute", false, "selectedValue", false, null)), items, fakeTheme);
    assertEquals("selectedValue", editedStyleItem.getValue());
    assertEquals("selectedValue", editedStyleItem.getSelectedValue().getValue());
    assertEquals(1, editedStyleItem.getNonSelectedItemResourceValues().size());
    ConfiguredElement<ItemResourceValue> notSelectedItem = editedStyleItem.getNonSelectedItemResourceValues().iterator().next();
    assertEquals("otherValue", notSelectedItem.myValue.getValue());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration)

Example 10 with ItemResourceValue

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

the class ConfiguredThemeEditorStyleTest method testSetValueMinSdk.

/**
   * Tests setValue method for an attribute having api level below than Minimum Sdk
   * Tests following cases:
   * values, values-v17, values-v19, values-v22
   * setValue("android:colorBackgroundCacheHint", "#000000");
   */
public void testSetValueMinSdk() {
    VirtualFile file = myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_3.xml", "res/values/styles.xml");
    myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_3.xml", "res/values-v17/styles.xml");
    myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_4.xml", "res/values-v19/styles.xml");
    myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_3.xml", "res/values-v22/styles.xml");
    ItemResourceValue item = new ItemResourceValue("colorBackgroundCacheHint", true, "#000000", false, null);
    checkSetValue(file, item, "", "-v17", "-v19", "-v22");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue)

Aggregations

ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)28 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 NotNull (org.jetbrains.annotations.NotNull)8 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)7 Configuration (com.android.tools.idea.configurations.Configuration)7 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)5 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)4 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)4 ResourceItem (com.android.ide.common.res2.ResourceItem)3 ResourceResolver (com.android.ide.common.resources.ResourceResolver)3 ResourceType (com.android.resources.ResourceType)3 ResourceUrl (com.android.ide.common.resources.ResourceUrl)2 ThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ThemeEditorStyle)2 RestrictedConfiguration (com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration)2 Nullable (org.jetbrains.annotations.Nullable)2 Nullable (com.android.annotations.Nullable)1 AbstractResourceRepository (com.android.ide.common.res2.AbstractResourceRepository)1 ResourceFile (com.android.ide.common.resources.ResourceFile)1 Configurable (com.android.ide.common.resources.configuration.Configurable)1