Search in sources :

Example 11 with ConfiguredThemeEditorStyle

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

the class ConfiguredThemeEditorStyleTest method checkSetParent.

private void checkSetParent(VirtualFile file, String newParent, String... answerFolders) {
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(file);
    ThemeResolver themeResolver = new ThemeResolver(configuration);
    ConfiguredThemeEditorStyle theme = themeResolver.getTheme("AppTheme");
    assertNotNull(theme);
    theme.setParent(newParent);
    // 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<String> value : theme.getParentNames()) {
        if (newParent.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) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Example 12 with ConfiguredThemeEditorStyle

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

the class ConfiguredThemeEditorStyleTest method testGetParentNames.

public void testGetParentNames() {
    myFixture.copyFileToProject("themeEditor/attributeResolution/styles_base.xml", "res/values/styles.xml");
    myFixture.copyFileToProject("themeEditor/attributeResolution/styles-v17.xml", "res/values-v17/styles.xml");
    myFixture.copyFileToProject("themeEditor/attributeResolution/styles-v19.xml", "res/values-v19/styles.xml");
    VirtualFile file = myFixture.copyFileToProject("themeEditor/attributeResolution/styles-v20.xml", "res/values-v20/styles.xml");
    ConfigurationManager configurationManager = myFacet.getConfigurationManager();
    Configuration configuration = configurationManager.getConfiguration(file);
    ThemeResolver resolver = new ThemeResolver(configuration);
    ConfiguredThemeEditorStyle theme = resolver.getTheme("AppTheme");
    assertNotNull(theme);
    Collection<ConfiguredElement<String>> parents = theme.getParentNames();
    assertSize(2, parents);
    ImmutableList<String> parentNames = ImmutableList.of(Iterables.get(parents, 0).getElement(), Iterables.get(parents, 1).getElement());
    assertContainsElements(parentNames, "Base.V20", "Base.V17");
    // Set API 17 and try the same resolution
    //noinspection ConstantConditions
    configuration.setTarget(new CompatibilityRenderTarget(configurationManager.getHighestApiTarget(), 17, configurationManager.getHighestApiTarget()));
    parents = theme.getParentNames();
    assertSize(2, parents);
    parentNames = ImmutableList.of(Iterables.get(parents, 0).getElement(), Iterables.get(parents, 1).getElement());
    assertContainsElements(parentNames, "Base.V20", "Base.V17");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ConfiguredElement(com.android.tools.idea.editors.theme.datamodels.ConfiguredElement) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) CompatibilityRenderTarget(com.android.tools.idea.rendering.multi.CompatibilityRenderTarget) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Example 13 with ConfiguredThemeEditorStyle

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

the class ConfiguredThemeEditorStyleTest method testGetStyleResourceUrl.

public void testGetStyleResourceUrl() {
    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);
    assertEquals("@style/AppTheme", theme.getStyleResourceUrl());
    theme = themeResolver.getTheme("android:Theme");
    assertNotNull(theme);
    assertEquals("@android:style/Theme", theme.getStyleResourceUrl());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Example 14 with ConfiguredThemeEditorStyle

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

the class ThemeResolverTest method testLocalThemes.

public void testLocalThemes() throws IOException {
    VirtualFile myLayout = myFixture.copyFileToProject("themeEditor/layout.xml", "res/layout/layout.xml");
    VirtualFile myStyleFile = myFixture.copyFileToProject("themeEditor/styles.xml", "res/values/styles.xml");
    ConfigurationManager configurationManager = myFacet.getConfigurationManager();
    Configuration configuration = configurationManager.getConfiguration(myLayout);
    ThemeResolver themeResolver = new ThemeResolver(configuration);
    // We don't have any libraries so this will only include the project theme
    assertEquals(1, themeResolver.getLocalThemes().size());
    // No library themes
    assertEquals(0, themeResolver.getExternalLibraryThemes().size());
    assertNull("The theme is an app theme and shouldn't be returned for the android namespace", themeResolver.getTheme("android:Theme.MyTheme"));
    ConfiguredThemeEditorStyle theme = themeResolver.getTheme("Theme.MyTheme");
    assertEquals("Theme.MyTheme", theme.getName());
    assertEquals("Theme", theme.getParent().getName());
    assertEquals(1, theme.getConfiguredValues().size());
    ConfiguredElement<ItemResourceValue> value = Iterables.get(theme.getConfiguredValues(), 0);
    assertEquals("windowBackground", value.getElement().getName());
    assertEquals("@drawable/pic", value.getElement().getValue());
    // Modify a value.
    theme.setValue("android:windowBackground", "@drawable/other");
    FileDocumentManager.getInstance().saveAllDocuments();
    assertFalse(new String(myStyleFile.contentsToByteArray(), "UTF-8").contains("@drawable/pic"));
    assertTrue(new String(myStyleFile.contentsToByteArray(), "UTF-8").contains("@drawable/other"));
    // Add a value.
    theme.setValue("android:windowBackground2", "@drawable/second_background");
    FileDocumentManager.getInstance().saveAllDocuments();
    assertTrue(new String(myStyleFile.contentsToByteArray(), "UTF-8").contains("@drawable/other"));
    assertTrue(new String(myStyleFile.contentsToByteArray(), "UTF-8").contains("@drawable/second_background"));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Example 15 with ConfiguredThemeEditorStyle

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

the class ConfiguredThemeEditorStyleTest method testGetConfiguredValues.

/**
   * Tests {@link ConfiguredThemeEditorStyle#getConfiguredValues()}
   * Tests values coming from different modules.
   * Dependency used in the test: mainModule -> moduleA, mainModule -> moduleB
   */
public void testGetConfiguredValues() {
    myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_4.xml", "additionalModules/moduleB/res/values-v19/styles.xml");
    VirtualFile virtualFile = myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_3.xml", "additionalModules/moduleA/res/values/styles.xml");
    ConfigurationManager configurationManager = myFacet.getConfigurationManager();
    Configuration configuration = configurationManager.getConfiguration(virtualFile);
    ThemeResolver resolver = new ThemeResolver(configuration);
    ConfiguredThemeEditorStyle theme = resolver.getTheme("AppTheme");
    assertNotNull(theme);
    assertEquals(3, theme.getConfiguredValues().size());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Aggregations

ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)41 Configuration (com.android.tools.idea.configurations.Configuration)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)13 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)9 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)9 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)8 NotNull (org.jetbrains.annotations.NotNull)6 ResourceResolver (com.android.ide.common.resources.ResourceResolver)5 AttributesTableModel (com.android.tools.idea.editors.theme.attributes.AttributesTableModel)4 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)2 ParentThemesListModel (com.android.tools.idea.editors.theme.ParentThemesListModel)2 ConfiguredElement (com.android.tools.idea.editors.theme.datamodels.ConfiguredElement)2 PsiElement (com.intellij.psi.PsiElement)2 TableModel (javax.swing.table.TableModel)2 Nullable (org.jetbrains.annotations.Nullable)2 ResourceType (com.android.resources.ResourceType)1 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 ThemeResolver (com.android.tools.idea.editors.theme.ThemeResolver)1 AttributesModelColorPaletteModel (com.android.tools.idea.editors.theme.attributes.AttributesModelColorPaletteModel)1