Search in sources :

Example 36 with ConfiguredThemeEditorStyle

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

the class ConfiguredThemeEditorStyleTest method testSettingInHighApiTheme.

/**
   * Test setting a low-api attributes and parent in a theme defined only in higher api files
   */
public void testSettingInHighApiTheme() {
    VirtualFile virtualFile = myFixture.copyFileToProject("themeEditor/apiTestBefore/stylesApi.xml", "res/values/styles.xml");
    myFixture.copyFileToProject("themeEditor/apiTestBefore/stylesApi-v14.xml", "res/values-v14/styles.xml");
    myFixture.copyFileToProject("themeEditor/apiTestBefore/stylesApi-v19.xml", "res/values-v19/styles.xml");
    myFixture.copyFileToProject("themeEditor/apiTestBefore/stylesApi-v21.xml", "res/values-v21/styles.xml");
    ConfigurationManager configurationManager = myFacet.getConfigurationManager();
    Configuration configuration = configurationManager.getConfiguration(virtualFile);
    ThemeResolver themeResolver = new ThemeResolver(configuration);
    ConfiguredThemeEditorStyle theme = themeResolver.getTheme("Theme.MyOtherTheme");
    assertNotNull(theme);
    theme.setValue("android:windowIsFloating", "holo_purple");
    theme.setValue("android:actionBarDivider", "myValue");
    theme.setParent("android:Theme.Holo.Light.DarkActionBar");
    myFixture.checkResultByFile("res/values/styles.xml", "themeEditor/apiTestAfter8/stylesApi.xml", true);
    myFixture.checkResultByFile("res/values-v14/styles.xml", "themeEditor/apiTestAfter8/stylesApi-v14.xml", true);
    myFixture.checkResultByFile("res/values-v19/styles.xml", "themeEditor/apiTestAfter8/stylesApi-v19.xml", true);
    myFixture.checkResultByFile("res/values-v21/styles.xml", "themeEditor/apiTestAfter8/stylesApi-v21.xml", true);
}
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 37 with ConfiguredThemeEditorStyle

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

the class ThemeEditorUtilsTest method testGetDisplayHtml.

public void testGetDisplayHtml() {
    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);
    Collection<EditedStyleItem> values = ThemeEditorTestUtils.getStyleLocalValues(theme);
    assertEquals(7, values.size());
    for (EditedStyleItem item : values) {
        String displayHtml = ThemeEditorUtils.getDisplayHtml(item);
        if ("myDeprecated".equals(item.getName())) {
            assertEquals("<html><body><strike>myDeprecated</strike></body></html>", displayHtml);
        } else {
            assertEquals(item.getName(), displayHtml);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)

Example 38 with ConfiguredThemeEditorStyle

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

the class ThemeEditorUtilsTest method testGenerateToolTipText.

public void testGenerateToolTipText() throws IOException {
    if (SystemInfo.isWindows) {
        // Do not run tests on Windows (see http://b.android.com/222904)
        return;
    }
    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);
    IAndroidTarget androidTarget = configuration.getTarget();
    assertNotNull(androidTarget);
    sdkPlatformPath = androidTarget.getLocation();
    if (LayoutLibraryLoader.USE_SDK_LAYOUTLIB) {
        if (!sdkPlatformPath.endsWith("/"))
            sdkPlatformPath += "/";
        sdkPlatformPath += "platforms/android-" + androidTarget.getVersion().getApiString();
    }
    sdkPlatformPath = Files.simplifyPath(sdkPlatformPath);
    ThemeResolver themeResolver = new ThemeResolver(configuration);
    ConfiguredThemeEditorStyle theme = themeResolver.getTheme("AppTheme");
    assertNotNull(theme);
    Collection<EditedStyleItem> values = ThemeEditorTestUtils.getStyleLocalValues(theme);
    assertEquals(7, values.size());
    configuration.setTheme("AppTheme");
    for (EditedStyleItem item : values) {
        String doc = ThemeEditorUtils.generateToolTipText(item.getSelectedValue(), myModule, configuration);
        compareWithGoldenFile(doc, myFixture.getTestDataPath() + "/themeEditor/tooltipDocAns/" + item.getName() + ".ans");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) IAndroidTarget(com.android.sdklib.IAndroidTarget) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)

Example 39 with ConfiguredThemeEditorStyle

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

the class ThemeResolverTest method testFrameworkThemeRead.

/*
   * The test SDK only includes some resources. It only includes a few incomplete styles.
   */
public void testFrameworkThemeRead() {
    VirtualFile myLayout = myFixture.copyFileToProject("xmlpull/layout.xml", "res/layout/layout1.xml");
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myLayout);
    ThemeResolver themeResolver = new ThemeResolver(configuration);
    // It's system theme and we're not specifying namespace so it will fail.
    assertNull(themeResolver.getTheme("Theme.Holo.Light"));
    ConfiguredThemeEditorStyle theme = themeResolver.getTheme("android:Theme.Holo.Light");
    assertEquals("Theme.Holo.Light", theme.getName());
    // Only framework themes.
    assertEquals(themeResolver.getThemesCount(), themeResolver.getFrameworkThemes().size());
    assertEmpty(themeResolver.getLocalThemes());
    assertNull("Theme resolver shouldn't resolve styles", themeResolver.getTheme("android:TextAppearance"));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Example 40 with ConfiguredThemeEditorStyle

use of com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle 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)

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