Search in sources :

Example 1 with HtmlLinkManager

use of com.android.tools.idea.rendering.HtmlLinkManager in project android by JetBrains.

the class GradleRenderErrorContributor method reportIssue170841.

private void reportIssue170841(RenderLogger logger, AndroidFacet facet) {
    Map<String, Throwable> brokenClasses = logger.getBrokenClasses();
    if (brokenClasses == null || brokenClasses.isEmpty() || facet == null) {
        return;
    }
    AndroidModuleModel model = AndroidModuleModel.get(facet);
    if (model == null || !model.getFeatures().isLayoutRenderingIssuePresent()) {
        return;
    }
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            FixAndroidGradlePluginVersionHyperlink quickFix = new FixAndroidGradlePluginVersionHyperlink(GradleVersion.parse(GRADLE_PLUGIN_RECOMMENDED_VERSION), null);
            quickFix.executeIfClicked(facet.getModule().getProject(), new HyperlinkEvent(this, HyperlinkEvent.EventType.ACTIVATED, null, quickFix.getUrl()));
        }
    };
    HtmlBuilder builder = new HtmlBuilder();
    HtmlLinkManager linkManager = logger.getLinkManager();
    builder.add("Tip: Either ").addLink("update the Gradle plugin build version to 1.2.3", linkManager.createRunnableLink(runnable)).add(" or later, or downgrade to version 1.1.3, or as a workaround, ");
    builder.beginList().listItem().addLink("", "Build the project", ", then", linkManager.createBuildProjectUrl()).listItem().addLink("", "Gradle Sync the project", ", then", linkManager.createSyncProjectUrl()).listItem().addLink("Manually ", "refresh the layout", " (or restart the IDE)", linkManager.createRefreshRenderUrl()).endList();
    builder.newline();
    GradleVersion modelVersion = model.getModelVersion();
    addIssue().setSeverity(HighlightSeverity.ERROR).setSummary("Using an obsolete version of the Gradle plugin (" + modelVersion + "); " + "this can lead to layouts not rendering correctly.").setHtmlContent(builder).build();
}
Also used : FixAndroidGradlePluginVersionHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HtmlLinkManager(com.android.tools.idea.rendering.HtmlLinkManager) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) HtmlBuilder(com.android.utils.HtmlBuilder) GradleVersion(com.android.ide.common.repository.GradleVersion)

Example 2 with HtmlLinkManager

use of com.android.tools.idea.rendering.HtmlLinkManager in project android by JetBrains.

the class NlUsageTrackerManagerTest method testRenderLogging.

public void testRenderLogging() {
    UsageTracker usageTracker = mock(UsageTracker.class);
    LinkedList<AndroidStudioEvent> logCalls = new LinkedList<>();
    doAnswer(invocation -> {
        logCalls.add(((AndroidStudioEvent.Builder) invocation.getArguments()[0]).build());
        return null;
    }).when(usageTracker).log(any());
    DesignSurface surface = mock(DesignSurface.class);
    when(surface.getLayoutType()).thenReturn(NlLayoutType.LAYOUT);
    when(surface.getScreenMode()).thenReturn(DesignSurface.ScreenMode.BOTH);
    when(surface.getScale()).thenReturn(0.50);
    Configuration configuration = getConfigurationMock();
    when(surface.getConfiguration()).thenReturn(configuration);
    NlUsageTracker tracker = new NlUsageTrackerManager(SYNC_EXECUTOR, surface, usageTracker) {

        @Override
        boolean shouldLog(int percent) {
            // Log everything in tests
            return true;
        }
    };
    Result renderResult = mock(Result.class);
    when(renderResult.getStatus()).thenReturn(Result.Status.SUCCESS);
    HtmlLinkManager linkManager = mock(HtmlLinkManager.class);
    RenderLogger logger = mock(RenderLogger.class);
    when(logger.getLinkManager()).thenReturn(linkManager);
    ImmutableMap<String, Throwable> brokenClasses = ImmutableMap.of("com.test.mock", new Throwable("mock error"));
    when(logger.getBrokenClasses()).thenReturn(brokenClasses);
    RenderResult result = mock(RenderResult.class);
    ViewInfo rootView = new ViewInfo("ConstraintLayout", null, 0, 0, 50, 50);
    rootView.setChildren(ImmutableList.of(new ViewInfo("TextView", null, 0, 0, 30, 20)));
    ;
    when(result.getRootViews()).thenReturn(ImmutableList.of(rootView));
    when(result.getRenderResult()).thenReturn(renderResult);
    when(result.getLogger()).thenReturn(logger);
    when(result.getModule()).thenReturn(new MockModule(getProject(), getTestRootDisposable()));
    tracker.logRenderResult(NlModel.ChangeType.EDIT, result, 230);
    assertEquals(1, logCalls.size());
    AndroidStudioEvent studioEvent = logCalls.getFirst();
    LayoutEditorRenderResult loggedResult = studioEvent.getLayoutEditorEvent().getRenderResult();
    assertEquals(Result.Status.SUCCESS.ordinal(), loggedResult.getResultCode());
    assertEquals(230, loggedResult.getTotalRenderTimeMs());
    assertEquals(2, loggedResult.getComponentCount());
    assertEquals(1, loggedResult.getTotalIssueCount());
    assertEquals(1, loggedResult.getErrorCount());
    assertEquals(0, loggedResult.getFidelityWarningCount());
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) RenderLogger(com.android.tools.idea.rendering.RenderLogger) Configuration(com.android.tools.idea.configurations.Configuration) RenderResult(com.android.tools.idea.rendering.RenderResult) LayoutEditorRenderResult(com.google.wireless.android.sdk.stats.LayoutEditorRenderResult) LinkedList(java.util.LinkedList) RenderResult(com.android.tools.idea.rendering.RenderResult) Result(com.android.ide.common.rendering.api.Result) LayoutEditorRenderResult(com.google.wireless.android.sdk.stats.LayoutEditorRenderResult) ViewInfo(com.android.ide.common.rendering.api.ViewInfo) UsageTracker(com.android.tools.analytics.UsageTracker) HtmlLinkManager(com.android.tools.idea.rendering.HtmlLinkManager) MockModule(com.intellij.mock.MockModule) LayoutEditorRenderResult(com.google.wireless.android.sdk.stats.LayoutEditorRenderResult) AndroidStudioEvent(com.google.wireless.android.sdk.stats.AndroidStudioEvent)

Aggregations

HtmlLinkManager (com.android.tools.idea.rendering.HtmlLinkManager)2 Result (com.android.ide.common.rendering.api.Result)1 ViewInfo (com.android.ide.common.rendering.api.ViewInfo)1 GradleVersion (com.android.ide.common.repository.GradleVersion)1 UsageTracker (com.android.tools.analytics.UsageTracker)1 Configuration (com.android.tools.idea.configurations.Configuration)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 FixAndroidGradlePluginVersionHyperlink (com.android.tools.idea.gradle.project.sync.hyperlink.FixAndroidGradlePluginVersionHyperlink)1 RenderLogger (com.android.tools.idea.rendering.RenderLogger)1 RenderResult (com.android.tools.idea.rendering.RenderResult)1 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)1 HtmlBuilder (com.android.utils.HtmlBuilder)1 AndroidStudioEvent (com.google.wireless.android.sdk.stats.AndroidStudioEvent)1 LayoutEditorRenderResult (com.google.wireless.android.sdk.stats.LayoutEditorRenderResult)1 MockModule (com.intellij.mock.MockModule)1 LinkedList (java.util.LinkedList)1 HyperlinkEvent (javax.swing.event.HyperlinkEvent)1