Search in sources :

Example 26 with ItemResourceValue

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

the class ConfiguredThemeEditorStyleTest method testSetValueCopy.

/**
   * Tests setValue method for copying from right FolderConfiguration
   * Tests following cases:
   * values, values-v17, values-v19, values-v22
   * setValue("android:colorAccent", "#000000");
   * Should create values-v21 based on values-v19, and modify values-v22
   */
public void testSetValueCopy() {
    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("colorAccent", true, "#000000", false, null);
    checkSetValue(file, item, "-v21", "-v22");
    myFixture.checkResultByFile("res/values-v21/styles.xml", "themeEditor/themeEditorStyle/styles_4_modified.xml", true);
    myFixture.checkResultByFile("res/values-v22/styles.xml", "themeEditor/themeEditorStyle/styles_3_modified.xml", true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue)

Example 27 with ItemResourceValue

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

the class ConfiguredThemeEditorStyleTest method checkSetValue.

private void checkSetValue(VirtualFile file, ItemResourceValue item, String... answerFolders) {
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(file);
    ThemeResolver themeResolver = new ThemeResolver(configuration);
    ConfiguredThemeEditorStyle style = themeResolver.getTheme("AppTheme");
    assertNotNull(style);
    style.setValue(ResolutionUtils.getQualifiedItemName(item), item.getValue());
    // ResourceFolderRepository needs to rescan the files to pick up the changes.
    UIUtil.dispatchAllInvocationEvents();
    HashSet<String> modifiedFolders = new HashSet<>(Arrays.asList(answerFolders));
    int valuesFound = 0;
    for (ConfiguredElement<ItemResourceValue> value : style.getConfiguredValues()) {
        if (item.equals(value.getElement())) {
            valuesFound++;
            assertTrue(modifiedFolders.contains(value.getConfiguration().getUniqueKey()));
        }
    }
    assertEquals(modifiedFolders.size(), valuesFound);
}
Also used : FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Example 28 with ItemResourceValue

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

the class ConfiguredThemeEditorStyleTest method testSetValueAndroidAttribute.

/**
   * Tests setValue method for following cases:
   * values, values-v21, values-night, value-port, values-port-v21
   * setValue("android:colorAccent", "#000000"), android:colorAccent is defined in API 21
   */
public void testSetValueAndroidAttribute() {
    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, "#000000", 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)

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