Search in sources :

Example 1 with EditorDesignSurface

use of com.android.tools.idea.ui.designer.EditorDesignSurface in project android by JetBrains.

the class RenderErrorContributor method reportRenderingFidelityProblems.

private void reportRenderingFidelityProblems(@NotNull RenderLogger logger, @NotNull final RenderTask renderTask) {
    List<RenderProblem> fidelityWarnings = logger.getFidelityWarnings();
    if (fidelityWarnings == null || fidelityWarnings.isEmpty()) {
        return;
    }
    HtmlBuilder builder = new HtmlBuilder();
    builder.add("The graphics preview in the layout editor may not be accurate:").newline();
    builder.beginList();
    int count = 0;
    for (final RenderProblem warning : fidelityWarnings) {
        builder.listItem();
        warning.appendHtml(builder.getStringBuilder());
        final Object clientData = warning.getClientData();
        if (clientData != null) {
            builder.addLink(" (Ignore for this session)", myLinkManager.createRunnableLink(() -> {
                RenderLogger.ignoreFidelityWarning(clientData);
                EditorDesignSurface surface = renderTask.getDesignSurface();
                if (surface != null) {
                    surface.requestRender();
                }
            }));
        }
        builder.newline();
        count++;
        // Only display the first 3 render fidelity issues
        if (count == 3) {
            @SuppressWarnings("ConstantConditions") int remaining = fidelityWarnings.size() - count;
            if (remaining > 0) {
                builder.add("(").addHtml(Integer.toString(remaining)).add(" additional render fidelity issues hidden)");
                break;
            }
        }
    }
    builder.endList();
    builder.addLink("Ignore all fidelity warnings for this session", myLinkManager.createRunnableLink(() -> {
        RenderLogger.ignoreAllFidelityWarnings();
        EditorDesignSurface surface = renderTask.getDesignSurface();
        if (surface != null) {
            surface.requestRender();
        }
    }));
    builder.newline();
    addIssue().setSeverity(HighlightSeverity.WARNING).setSummary("Layout fidelity warning").setHtmlContent(builder).build();
}
Also used : EditorDesignSurface(com.android.tools.idea.ui.designer.EditorDesignSurface) HtmlBuilder(com.android.utils.HtmlBuilder)

Example 2 with EditorDesignSurface

use of com.android.tools.idea.ui.designer.EditorDesignSurface in project android by JetBrains.

the class RenderErrorContributor method reportRtlNotEnabled.

private void reportRtlNotEnabled(@NotNull RenderLogger logger, @Nullable RenderTask task) {
    ApplicationManager.getApplication().runReadAction(() -> {
        Project project = logger.getProject();
        if (project == null || project.isDisposed()) {
            return;
        }
        Module module = logger.getModule();
        if (module == null) {
            return;
        }
        AndroidFacet facet = AndroidFacet.getInstance(module);
        Manifest manifest = facet != null ? facet.getManifest() : null;
        Application application = manifest != null ? manifest.getApplication() : null;
        if (application == null) {
            return;
        }
        final XmlTag applicationTag = application.getXmlTag();
        if (applicationTag == null) {
            return;
        }
        HtmlBuilder builder = new HtmlBuilder();
        builder.add("(").addLink("Add android:supportsRtl=\"true\" to the manifest", logger.getLinkManager().createRunnableLink(() -> {
            new SetAttributeFix(project, applicationTag, AndroidManifest.ATTRIBUTE_SUPPORTS_RTL, ANDROID_URI, VALUE_TRUE).execute();
            EditorDesignSurface surface = task != null ? task.getDesignSurface() : null;
            if (surface != null) {
                surface.requestRender(true);
            }
        })).add(")");
        addIssue().setSeverity(HighlightSeverity.ERROR).setSummary("RTL support requires android:supportsRtl=\"true\" in the manifest").setHtmlContent(builder).build();
    });
}
Also used : Project(com.intellij.openapi.project.Project) EditorDesignSurface(com.android.tools.idea.ui.designer.EditorDesignSurface) HtmlBuilder(com.android.utils.HtmlBuilder) Module(com.intellij.openapi.module.Module) AndroidManifest(com.android.xml.AndroidManifest) Manifest(org.jetbrains.android.dom.manifest.Manifest) Application(org.jetbrains.android.dom.manifest.Application) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

EditorDesignSurface (com.android.tools.idea.ui.designer.EditorDesignSurface)2 HtmlBuilder (com.android.utils.HtmlBuilder)2 AndroidManifest (com.android.xml.AndroidManifest)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 XmlTag (com.intellij.psi.xml.XmlTag)1 Application (org.jetbrains.android.dom.manifest.Application)1 Manifest (org.jetbrains.android.dom.manifest.Manifest)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1