Search in sources :

Example 46 with ResourceFolderType

use of com.android.resources.ResourceFolderType in project android by JetBrains.

the class IncludeTagCreator method createNewIncludedLayout.

/**
   * Create a new layout that will be included as a child of the mockup component
   */
private String createNewIncludedLayout() {
    AndroidFacet facet = getMockup().getComponent().getModel().getFacet();
    ResourceFolderType folderType = AndroidResourceUtil.XML_FILE_RESOURCE_TYPES.get(ResourceType.LAYOUT);
    XmlFile newFile = CreateResourceFileAction.createFileResource(facet, folderType, null, null, null, true, null, null, null, false);
    if (newFile == null) {
        return null;
    }
    XmlTag rootTag = newFile.getRootTag();
    if (rootTag == null) {
        return null;
    }
    NlModel nlModel = NlModel.create(getScreenView().getSurface(), newFile.getProject(), facet, newFile);
    ModelListener listener = new ModelListener() {

        @Override
        public void modelChanged(@NotNull NlModel model) {
        }

        @Override
        public void modelRendered(@NotNull NlModel model) {
            model.removeListener(this);
            if (model.getComponents().isEmpty()) {
                return;
            }
            NlComponent component = model.getComponents().get(0);
            final AttributesTransaction transaction = component.startAttributeTransaction();
            addShowInAttribute(transaction);
            addSizeAttributes(transaction, getAndroidBounds());
            addMockupAttributes(transaction, getSelectionBounds());
            WriteCommandAction.runWriteCommandAction(model.getProject(), (Computable) transaction::commit);
        }

        @Override
        public void modelChangedOnLayout(@NotNull NlModel model, boolean animate) {
        // Do nothing
        }
    };
    nlModel.addListener(listener);
    nlModel.requestRender();
    return getResourceName(newFile);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ResourceFolderType(com.android.resources.ResourceFolderType) ModelListener(com.android.tools.idea.uibuilder.model.ModelListener) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

ResourceFolderType (com.android.resources.ResourceFolderType)46 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)10 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 NotNull (org.jetbrains.annotations.NotNull)10 ResourceType (com.android.resources.ResourceType)8 XmlFile (com.intellij.psi.xml.XmlFile)8 File (java.io.File)8 PsiFile (com.intellij.psi.PsiFile)7 Nullable (org.jetbrains.annotations.Nullable)7 PsiDirectory (com.intellij.psi.PsiDirectory)6 Module (com.intellij.openapi.module.Module)5 XmlTag (com.intellij.psi.xml.XmlTag)5 Configuration (com.android.tools.idea.configurations.Configuration)3 PsiElement (com.intellij.psi.PsiElement)3 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)2 VersionQualifier (com.android.ide.common.resources.configuration.VersionQualifier)2 HtmlBuilder (com.android.utils.HtmlBuilder)2 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)2 Project (com.intellij.openapi.project.Project)2