Search in sources :

Example 21 with ItemResourceValue

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

the class ChooseResourceDialog method initializeThemeAttributes.

private static MultiMap<ResourceType, String> initializeThemeAttributes(@NotNull Configuration configuration, @NotNull ResourceResolver resolver) {
    MultiMap<ResourceType, String> attrs = new MultiMap<>();
    String themeName = configuration.getTheme();
    assert themeName != null;
    for (ItemResourceValue item : ResolutionUtils.getThemeAttributes(resolver, themeName)) {
        ResourceType type = ResolutionUtils.getAttrType(item, configuration);
        if (type != null) {
            attrs.putValue(type, ResolutionUtils.getQualifiedItemName(item));
        }
    }
    return attrs;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ResourceType(com.android.resources.ResourceType)

Example 22 with ItemResourceValue

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

the class ThemeAttributeResolverTest method testResolveAllEnum.

/**
   * Tests {@link ThemeAttributeResolver#resolveAll(ConfiguredThemeEditorStyle, ThemeResolver)}
   */
public void testResolveAllEnum() {
    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-port", "values-square", "values-land"));
    createNewStyle(resourceDir, "ThemeB", "ThemeA", null, Lists.newArrayList("values", "values-port"));
    // 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("-port:red", "-land:red", "-square:red");
    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 23 with ItemResourceValue

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

the class ConfiguredThemeEditorStyleTest method testSetValueAndroidAttributeValue.

/**
   * Tests setValue method for following cases:
   * values, values-v21, values-night, value-port, values-port-v21
   * setValue("android:colorFocusedHighlight", "?android:attr/colorAccent"), colorAccent - v21, colorFocusedHighlight - v14
   */
public void testSetValueAndroidAttributeValue() {
    VirtualFile file = myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values/styles.xml");
    myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_3.xml", "res/values-v21/styles.xml");
    myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values-night/styles.xml");
    myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values-port/styles.xml");
    myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values-port-v21/styles.xml");
    ItemResourceValue item = new ItemResourceValue("colorAccent", true, "?android:attr/colorAccent", false, null);
    checkSetValue(file, item, "-night-v21", "-v21", "-port-v21");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue)

Example 24 with ItemResourceValue

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

the class ConfiguredThemeEditorStyleTest method testHasItem.

public void testHasItem() {
    VirtualFile myFile = myFixture.copyFileToProject("themeEditor/styles_1.xml", "res/values/styles.xml");
    myFixture.copyFileToProject("themeEditor/attrs.xml", "res/values/attrs.xml");
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myFile);
    ThemeResolver themeResolver = new ThemeResolver(configuration);
    ConfiguredThemeEditorStyle theme = themeResolver.getTheme("AppTheme");
    assertNotNull(theme);
    ConfiguredThemeEditorStyle parent = theme.getParent();
    assertNotNull(parent);
    FolderConfiguration defaultConfig = new FolderConfiguration();
    ConfiguredElement<ItemResourceValue> hasItem = ConfiguredElement.create(defaultConfig, new ItemResourceValue("myColor", false, "?android:attr/colorBackground", false, null));
    ConfiguredElement<ItemResourceValue> hasNotItem = ConfiguredElement.create(defaultConfig, new ItemResourceValue("myHasNot", false, "?android:attr/colorBackground", false, null));
    ConfiguredElement<ItemResourceValue> hasInParent = ConfiguredElement.create(defaultConfig, new ItemResourceValue("editTextStyle", true, "?android:attr/colorBackground", true, null));
    assertTrue(theme.hasItem(new EditedStyleItem(hasItem, theme)));
    assertFalse(theme.hasItem(new EditedStyleItem(hasNotItem, theme)));
    assertTrue(theme.getParent().hasItem(new EditedStyleItem(hasInParent, parent)));
    assertFalse(theme.hasItem(new EditedStyleItem(hasInParent, parent)));
}
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) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)

Example 25 with ItemResourceValue

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

the class ConfiguredThemeEditorStyleTest method testSetValue.

/**
   * Tests setValue method for following cases:
   * values, values-v21, values-night, value-port, values-port-v21
   * setValue("colorAccent", "#000000")
   */
public void testSetValue() {
    VirtualFile file = myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values/styles.xml");
    myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values-v21/styles.xml");
    myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values-night/styles.xml");
    myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values-port/styles.xml");
    myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_2.xml", "res/values-port-v21/styles.xml");
    ItemResourceValue item = new ItemResourceValue("colorAccent", false, "#000000", false, null);
    checkSetValue(file, item, "", "-v21", "-night", "-port", "-port-v21");
}
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