Search in sources :

Example 16 with ResourceElement

use of org.jetbrains.android.dom.resources.ResourceElement in project android by JetBrains.

the class ThemeAttributeResolverTest method createNewStyle.

public boolean createNewStyle(@NotNull final VirtualFile resourceDir, @NotNull final String newStyleName, @NotNull final String parentStyleName, @Nullable final String colorPrimaryValue, @NotNull final List<String> folders) {
    return new WriteCommandAction<Boolean>(getProject(), "Create new style " + newStyleName) {

        @Override
        protected void run(@NotNull Result<Boolean> result) {
            result.setResult(AndroidResourceUtil.createValueResource(getProject(), resourceDir, newStyleName, null, ResourceType.STYLE, "styles.xml", folders, new Processor<ResourceElement>() {

                @Override
                public boolean process(ResourceElement element) {
                    assert element instanceof Style;
                    final Style style = (Style) element;
                    style.getParentStyle().setStringValue(parentStyleName);
                    if (colorPrimaryValue != null) {
                        StyleItem styleItem = style.addItem();
                        styleItem.getName().setStringValue("colorPrimary");
                        styleItem.setStringValue(colorPrimaryValue);
                    }
                    return true;
                }
            }));
        }
    }.execute().getResultObject();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) ResourceElement(org.jetbrains.android.dom.resources.ResourceElement) Processor(com.intellij.util.Processor) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) StyleItem(org.jetbrains.android.dom.resources.StyleItem) Style(org.jetbrains.android.dom.resources.Style) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Aggregations

ResourceElement (org.jetbrains.android.dom.resources.ResourceElement)16 XmlTag (com.intellij.psi.xml.XmlTag)7 NotNull (org.jetbrains.annotations.NotNull)7 Result (com.intellij.openapi.application.Result)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)6 DomElement (com.intellij.util.xml.DomElement)6 Nullable (org.jetbrains.annotations.Nullable)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Resources (org.jetbrains.android.dom.resources.Resources)4 Style (org.jetbrains.android.dom.resources.Style)4 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)3 ResourceType (com.android.resources.ResourceType)2 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)2 Project (com.intellij.openapi.project.Project)2 PsiFile (com.intellij.psi.PsiFile)2 XmlAttribute (com.intellij.psi.xml.XmlAttribute)2 Processor (com.intellij.util.Processor)2 Item (org.jetbrains.android.dom.resources.Item)2 StyleItem (org.jetbrains.android.dom.resources.StyleItem)2 LocalResourceManager (org.jetbrains.android.resourceManagers.LocalResourceManager)2