Search in sources :

Example 1 with RenderLogger

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

the class ViewLoaderTest method testMissingClass.

public void testMissingClass() throws Exception {
    RenderLogger logger = RenderService.get(myFacet).createLogger();
    ViewLoader viewLoader = new ViewLoader(myLayoutLib, myFacet, logger, null);
    assertNull(viewLoader.loadClass("broken.brokenclass", true));
    assertTrue(logger.hasErrors());
    assertThat(logger.getMissingClasses(), hasItem("broken.brokenclass"));
    logger = RenderService.get(myFacet).createLogger();
    viewLoader = new ViewLoader(myLayoutLib, myFacet, logger, null);
    try {
        viewLoader.loadView("broken.brokenclass", null, null);
        fail("ClassNotFoundException expected");
    } catch (ClassNotFoundException ignored) {
    }
    logger = RenderService.get(myFacet).createLogger();
    viewLoader = new ViewLoader(myLayoutLib, myFacet, logger, null);
    assertNull(viewLoader.loadClass("broken.brokenclass", false));
    assertFalse(logger.hasErrors());
}
Also used : RenderLogger(com.android.tools.idea.rendering.RenderLogger)

Example 2 with RenderLogger

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

the class ViewLoaderTest method testRClassLoad.

public void testRClassLoad() throws ClassNotFoundException {
    RenderLogger logger = RenderService.get(myFacet).createLogger();
    ViewLoader viewLoader = new ViewLoader(myLayoutLib, myFacet, logger, null);
    // No AppResourceRepository exists prior to calling loadAndParseRClass. It will get created during the call.
    assertNull(AppResourceRepository.getAppResources(myModule, false));
    viewLoader.loadAndParseRClass("org.jetbrains.android.uipreview.ViewLoaderTest$R");
    AppResourceRepository appResources = AppResourceRepository.getAppResources(myModule, false);
    assertNotNull(appResources);
    assertEquals(0x7f0a000e, appResources.getResourceId(ResourceType.STRING, "app_name").intValue());
    // This value wasn't read from the R class since it wasn't final. The value must be a dynamic ID (they start at 0x7fff0000)
    assertEquals(0x7fff0001, appResources.getResourceId(ResourceType.STRING, "not_final").intValue());
}
Also used : RenderLogger(com.android.tools.idea.rendering.RenderLogger) AppResourceRepository(com.android.tools.idea.res.AppResourceRepository)

Example 3 with RenderLogger

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

the class GradleRenderErrorContributor method reportIssues.

@Override
public Collection<RenderErrorModel.Issue> reportIssues() {
    RenderResult result = getResult();
    RenderLogger logger = result.getLogger();
    AndroidFacet facet = AndroidFacet.getInstance(result.getModule());
    reportIssue170841(logger, facet);
    return getIssues();
}
Also used : RenderLogger(com.android.tools.idea.rendering.RenderLogger) RenderResult(com.android.tools.idea.rendering.RenderResult) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 4 with RenderLogger

use of com.android.tools.idea.rendering.RenderLogger 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)

Example 5 with RenderLogger

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

the class ViewEditorImpl method measureChildren.

@Nullable
@Override
public Map<NlComponent, Dimension> measureChildren(@NotNull NlComponent parent, @Nullable RenderTask.AttributeFilter filter) {
    // TODO: Reuse snapshot!
    Map<NlComponent, Dimension> unweightedSizes = Maps.newHashMap();
    XmlTag parentTag = parent.getTag();
    if (parentTag.isValid()) {
        if (parent.getChildCount() == 0) {
            return Collections.emptyMap();
        }
        Map<XmlTag, NlComponent> tagToComponent = Maps.newHashMapWithExpectedSize(parent.getChildCount());
        for (NlComponent child : parent.getChildren()) {
            tagToComponent.put(child.getTag(), child);
        }
        NlModel model = myScreen.getModel();
        XmlFile xmlFile = model.getFile();
        AndroidFacet facet = model.getFacet();
        RenderService renderService = RenderService.get(facet);
        RenderLogger logger = renderService.createLogger();
        final RenderTask task = renderService.createTask(xmlFile, getConfiguration(), logger, null);
        if (task == null) {
            return null;
        }
        // Measure unweighted bounds
        Map<XmlTag, ViewInfo> map = task.measureChildren(parentTag, filter);
        task.dispose();
        if (map != null) {
            for (Map.Entry<XmlTag, ViewInfo> entry : map.entrySet()) {
                ViewInfo viewInfo = entry.getValue();
                viewInfo = RenderService.getSafeBounds(viewInfo);
                Dimension size = new Dimension(viewInfo.getRight() - viewInfo.getLeft(), viewInfo.getBottom() - viewInfo.getTop());
                NlComponent child = tagToComponent.get(entry.getKey());
                if (child != null) {
                    unweightedSizes.put(child, size);
                }
            }
        }
    }
    return unweightedSizes;
}
Also used : RenderLogger(com.android.tools.idea.rendering.RenderLogger) XmlFile(com.intellij.psi.xml.XmlFile) RenderTask(com.android.tools.idea.rendering.RenderTask) NlModel(com.android.tools.idea.uibuilder.model.NlModel) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) ViewInfo(com.android.ide.common.rendering.api.ViewInfo) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) RenderService(com.android.tools.idea.rendering.RenderService) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

RenderLogger (com.android.tools.idea.rendering.RenderLogger)6 ViewInfo (com.android.ide.common.rendering.api.ViewInfo)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 RenderResult (com.android.tools.idea.rendering.RenderResult)2 RenderService (com.android.tools.idea.rendering.RenderService)2 RenderTask (com.android.tools.idea.rendering.RenderTask)2 XmlFile (com.intellij.psi.xml.XmlFile)2 XmlTag (com.intellij.psi.xml.XmlTag)2 Result (com.android.ide.common.rendering.api.Result)1 UsageTracker (com.android.tools.analytics.UsageTracker)1 Configuration (com.android.tools.idea.configurations.Configuration)1 HtmlLinkManager (com.android.tools.idea.rendering.HtmlLinkManager)1 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)1 Insets (com.android.tools.idea.uibuilder.model.Insets)1 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)1 NlModel (com.android.tools.idea.uibuilder.model.NlModel)1 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)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