Search in sources :

Example 11 with EditedStyleItem

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

the class ThemeAttributeResolver method resolveAll.

@NotNull
private List<EditedStyleItem> resolveAll() {
    ThemeEditorStyle theme = new ThemeEditorStyle(myManager, myStyle.getQualifiedName());
    for (FolderConfiguration folder : theme.getFolders()) {
        resolveFromInheritance(myStyle, folder, new RestrictedConfiguration(), new HashSet<String>());
    }
    List<EditedStyleItem> result = Lists.newArrayList();
    FolderConfiguration configuration = myStyle.getConfiguration().getFullConfig();
    for (String key : myItemValueMap.keySet()) {
        Collection<ConfiguredElement<ItemResourceValue>> itemValues = myItemValueMap.get(key);
        final ConfiguredElement<ItemResourceValue> selectedValue = (ConfiguredElement<ItemResourceValue>) configuration.findMatchingConfigurable(Lists.<Configurable>newArrayList(itemValues));
        if (selectedValue == null) {
            // TODO: there is NO value for this attribute in the current config,so instead we need to show "no value for current device"
            result.add(new EditedStyleItem(itemValues.iterator().next(), itemValues, myStyle));
        } else {
            itemValues.remove(selectedValue);
            assert !itemValues.contains(selectedValue);
            result.add(new EditedStyleItem(selectedValue, itemValues, myStyle));
        }
    }
    return result;
}
Also used : ConfiguredElement(com.android.tools.idea.editors.theme.datamodels.ConfiguredElement) ItemResourceValue(com.android.ide.common.rendering.api.ItemResourceValue) ThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ThemeEditorStyle) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configurable(com.android.ide.common.resources.configuration.Configurable) RestrictedConfiguration(com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with EditedStyleItem

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

the class AttributesGrouper method generateLabelsForType.

@NotNull
private static List<TableLabel> generateLabelsForType(@NotNull final List<EditedStyleItem> source, @NotNull final List<EditedStyleItem> sink) {
    // ArrayListMultimap is used to ensure the elements stay sorted
    final Multimap<Group, EditedStyleItem> classes = ArrayListMultimap.create();
    for (final EditedStyleItem item : source) {
        final String name = item.getName();
        classes.put(Group.getGroupFromName(name), item);
    }
    final List<TableLabel> labels = new ArrayList<TableLabel>();
    int offset = 0;
    for (Group group : Group.values()) {
        Collection<EditedStyleItem> elements = classes.get(group);
        boolean addHeader = !elements.isEmpty();
        if (addHeader && group == Group.OTHER) {
            // Adding "Everything else" label only in case when there are at least one other label,
            // because having "Everything else" as the only label present looks quite silly
            addHeader = offset != 0;
        }
        if (addHeader) {
            labels.add(new TableLabel(group.name, offset));
        }
        sink.addAll(elements);
        offset += elements.size();
    }
    return labels;
}
Also used : EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with EditedStyleItem

use of com.android.tools.idea.editors.theme.datamodels.EditedStyleItem 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 14 with EditedStyleItem

use of com.android.tools.idea.editors.theme.datamodels.EditedStyleItem 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 15 with EditedStyleItem

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

Aggregations

EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)17 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 NotNull (org.jetbrains.annotations.NotNull)6 Configuration (com.android.tools.idea.configurations.Configuration)5 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)4 AttributesTableModel (com.android.tools.idea.editors.theme.attributes.AttributesTableModel)4 ResourceResolver (com.android.ide.common.resources.ResourceResolver)2 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)2 ImmutableList (com.google.common.collect.ImmutableList)2 Project (com.intellij.openapi.project.Project)2 PsiElement (com.intellij.psi.PsiElement)2 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)1 Configurable (com.android.ide.common.resources.configuration.Configurable)1 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 AttributesModelColorPaletteModel (com.android.tools.idea.editors.theme.attributes.AttributesModelColorPaletteModel)1 ConfiguredElement (com.android.tools.idea.editors.theme.datamodels.ConfiguredElement)1 ThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ThemeEditorStyle)1 AndroidThemePreviewPanel (com.android.tools.idea.editors.theme.preview.AndroidThemePreviewPanel)1 RestrictedConfiguration (com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration)1