Search in sources :

Example 16 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class MultipleModulesTest method testThemeResolver.

public void testThemeResolver() {
    final VirtualFile appThemes = myFixture.copyFileToProject("themeEditor/multimodulesProject/app_themes.xml", "res/values/themes.xml");
    myFixture.copyFileToProject("themeEditor/multimodulesProject/unusedlibrary_themes.xml", getAdditionalModulePath(UNUSEDLIBRARY) + "/res/values/themes.xml");
    myFixture.copyFileToProject("themeEditor/multimodulesProject/usedlibrary_themes.xml", getAdditionalModulePath(USEDLIBRARY) + "/res/values/themes.xml");
    // Main theme module
    final Configuration configuration1 = myFacet.getConfigurationManager().getConfiguration(appThemes);
    final ThemeResolver resolver1 = new ThemeResolver(configuration1);
    // Available themes should contain from used library, but, more importantly, shouldn't contain themes from unused library (not a dependency)
    assertContainsElements(themeNames(resolver1.getLocalThemes()), "AppTheme", "LibraryDependentTheme", "UsedLibraryTheme");
    // Used library module
    final Configuration configuration2 = AndroidFacet.getInstance(myAdditionalModules.get(0)).getConfigurationManager().getConfiguration(appThemes);
    final ThemeResolver resolver2 = new ThemeResolver(configuration2);
    assertContainsElements(themeNames(resolver2.getLocalThemes()), "UsedLibraryTheme");
    // Unused library module
    final Configuration configuration3 = AndroidFacet.getInstance(myAdditionalModules.get(1)).getConfigurationManager().getConfiguration(appThemes);
    final ThemeResolver resolver3 = new ThemeResolver(configuration3);
    assertContainsElements(themeNames(resolver3.getLocalThemes()), "UnusedLibraryTheme");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration)

Example 17 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class ResolutionUtilsTest method testGetParentQualifiedName.

/**
   * Tests {@link ResolutionUtils#getParentQualifiedName(StyleResourceValue)}
   */
public void testGetParentQualifiedName() {
    VirtualFile file = myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles.xml", "res/values/styles.xml");
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(file);
    ResourceResolver resolver = configuration.getResourceResolver();
    assertNotNull(resolver);
    StyleResourceValue style;
    style = resolver.getStyle("Theme", true);
    assertNotNull(style);
    assertEquals(null, ResolutionUtils.getParentQualifiedName(style));
    style = resolver.getStyle("Theme.Holo.Light", true);
    assertNotNull(style);
    assertEquals("android:Theme.Light", ResolutionUtils.getParentQualifiedName(style));
    style = resolver.getStyle("ATheme", false);
    assertNotNull(style);
    assertEquals("android:Theme", ResolutionUtils.getParentQualifiedName(style));
    style = resolver.getStyle("AppTheme", false);
    assertNotNull(style);
    assertEquals("ATheme", ResolutionUtils.getParentQualifiedName(style));
    style = resolver.getStyle("ATheme.Red", false);
    assertNotNull(style);
    assertEquals("ATheme", ResolutionUtils.getParentQualifiedName(style));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) Configuration(com.android.tools.idea.configurations.Configuration) ResourceResolver(com.android.ide.common.resources.ResourceResolver)

Example 18 with Configuration

use of com.android.tools.idea.configurations.Configuration 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 19 with Configuration

use of com.android.tools.idea.configurations.Configuration 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)

Example 20 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class OverrideResourceAction method forkResourceFile.

/**
   * Create a variation (copy) of a given resource file
   *
   * @param surface   the design surface for the resource file to fork
   * @param newFolder the resource folder to create, or null to ask the user
   * @param open      if true, open the file after creating it
   */
public static void forkResourceFile(@NotNull EditorDesignSurface surface, @Nullable String newFolder, boolean open) {
    Configuration configuration = surface.getConfiguration();
    if (configuration == null) {
        assert false;
        // Should not happen
        return;
    }
    final VirtualFile file = configuration.getFile();
    if (file == null) {
        assert false;
        // Should not happen
        return;
    }
    Module module = configuration.getModule();
    if (module == null) {
        assert false;
        // Should not happen
        return;
    }
    XmlFile xmlFile = (XmlFile) configuration.getPsiFile();
    ResourceFolderType folderType = ResourceHelper.getFolderType(xmlFile);
    if (folderType == null) {
        folderType = ResourceFolderType.LAYOUT;
    }
    forkResourceFile(module.getProject(), folderType, file, xmlFile, newFolder, configuration, open);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) XmlFile(com.intellij.psi.xml.XmlFile) ResourceFolderType(com.android.resources.ResourceFolderType) Module(com.intellij.openapi.module.Module)

Aggregations

Configuration (com.android.tools.idea.configurations.Configuration)95 VirtualFile (com.intellij.openapi.vfs.VirtualFile)38 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)23 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)21 ResourceResolver (com.android.ide.common.resources.ResourceResolver)16 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)14 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 Module (com.intellij.openapi.module.Module)9 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)8 IAndroidTarget (com.android.sdklib.IAndroidTarget)7 Device (com.android.sdklib.devices.Device)7 State (com.android.sdklib.devices.State)7 NotNull (org.jetbrains.annotations.NotNull)7 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)6 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)5 CompatibilityRenderTarget (com.android.tools.idea.rendering.multi.CompatibilityRenderTarget)5 NlModel (com.android.tools.idea.uibuilder.model.NlModel)4 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)4 PsiFile (com.intellij.psi.PsiFile)4 ResourceFolderType (com.android.resources.ResourceFolderType)3