Search in sources :

Example 6 with StyleItem

use of org.jetbrains.android.dom.resources.StyleItem 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

StyleItem (org.jetbrains.android.dom.resources.StyleItem)6 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 HashMap (com.intellij.util.containers.HashMap)2 ResourceElement (org.jetbrains.android.dom.resources.ResourceElement)2 Style (org.jetbrains.android.dom.resources.Style)2 Nullable (org.jetbrains.annotations.Nullable)2 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)1 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)1 UndoConfirmationPolicy (com.intellij.openapi.command.UndoConfirmationPolicy)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlTag (com.intellij.psi.xml.XmlTag)1 Processor (com.intellij.util.Processor)1 HashSet (com.intellij.util.containers.HashSet)1 ConvertContext (com.intellij.util.xml.ConvertContext)1 DomInvocationHandler (com.intellij.util.xml.impl.DomInvocationHandler)1 ArrayList (java.util.ArrayList)1