private static boolean isInResourceFolder(@Nullable PsiFile psiFile) { if (psiFile instanceof XmlFile && AndroidFacet.getInstance(psiFile) != null) { return RenderService.canRender(psiFile); } return false; }
private void doRender(@NotNull final AndroidFacet facet, @NotNull final PsiFile psiFile) { if (myProject.isDisposed()) { return; } final AndroidLayoutPreviewToolWindowForm toolWindowForm = myToolWindowForm; if (toolWindowForm == null) { return; } final VirtualFile layoutXmlFile = psiFile.getVirtualFile(); if (layoutXmlFile == null) { return; } Module module = facet.getModule(); Configuration configuration = toolWindowForm.getConfiguration(); if (configuration == null) { return; } // Some types of files must be saved to disk first, because layoutlib doesn't // delegate XML parsers for non-layout files (meaning layoutlib will read the // disk contents, so we have to push any edits to disk before rendering) LayoutPullParserFactory.saveFileIfNecessary(psiFile); RenderResult result = null; synchronized (RENDERING_LOCK) { final RenderLogger logger = new RenderLogger(layoutXmlFile.getName(), module); final RenderService service = RenderService.create(facet, module, psiFile, configuration, logger, toolWindowForm); if (service != null) { service.useDesignMode(psiFile); result = service.render(); service.dispose(); } if (result == null) { result = RenderResult.createBlank(psiFile, logger); } } if (!getRenderingQueue().isEmpty()) { return; } final RenderResult renderResult = result; ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { if (!myToolWindowReady || myToolWindowDisposed) { return; } final TextEditor editor = getActiveLayoutXmlEditor(); // Must be run from read thread myToolWindowForm.setRenderResult(renderResult, editor); myToolWindowForm.updatePreviewPanel(); if (RenderPreviewMode.getCurrent() != RenderPreviewMode.NONE) { RenderPreviewManager previewManager = myToolWindowForm.getPreviewPanel().getPreviewManager(myToolWindowForm, true); if (previewManager != null) { previewManager.renderPreviews(); } } } }); }