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());
}
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());
}
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();
}
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());
}
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;
}
Aggregations