use of com.android.tools.idea.rendering.RenderResult in project android by JetBrains.
the class GradleRenderErrorContributorTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
IdeComponents.replaceServiceWithMock(myProject, GradleProjectInfo.class);
when(GradleProjectInfo.getInstance(myProject).isBuildWithGradle()).thenReturn(true);
setUpAndroidFacetWithGradleModelWithIssue();
RenderResult result = createResultWithBrokenClass();
myRenderErrorModel = RenderErrorModelFactory.createErrorModel(result, null);
// For the isApplicable tests.
myProvider = new GradleRenderErrorContributor.GradleProvider();
}
use of com.android.tools.idea.rendering.RenderResult 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.RenderResult 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.RenderResult in project android by JetBrains.
the class GradleRenderErrorContributorTest method createResultWithBrokenClass.
private RenderResult createResultWithBrokenClass() {
PsiFile file = new MockPsiFile(new MockPsiManager(myProject));
file.putUserData(ModuleUtilCore.KEY_MODULE, myModule);
RenderResult result = RenderResult.createBlank(file);
result.getLogger().addBrokenClass("com.google.Class", new Exception());
return result;
}
use of com.android.tools.idea.rendering.RenderResult in project android by JetBrains.
the class ConvertToConstraintLayoutAction method inferConstraints.
private static void inferConstraints(NlModel model) {
RenderResult result = model.getRenderResult();
if (result == null || !result.getRenderResult().isSuccess()) {
return;
}
ApplicationManager.getApplication().invokeLater(() -> {
final ConstraintModel constraintModel = ConstraintModel.getConstraintModel(model);
if (constraintModel != null) {
int dpi = model.getConfiguration().getDensity().getDpiValue();
constraintModel.setDpiValue(dpi);
constraintModel.updateNlModel(null, model.getComponents(), true);
// Infer new constraints
WidgetsScene scene = constraintModel.getScene();
try {
Scout.inferConstraints(scene);
} catch (Throwable t) {
Logger.getInstance(ConvertToConstraintLayoutAction.class).warn(t);
}
WriteCommandAction.runWriteCommandAction(model.getProject(), "Infer Constraints", null, new Runnable() {
@Override
public void run() {
constraintModel.saveToXML(true);
constraintModel.setNeedsAnimateConstraints(ConstraintAnchor.SCOUT_CREATOR);
// Finally remove the conversion x/y/width/height attributes
List<NlComponent> components = model.getComponents();
for (NlComponent root : components) {
removeAbsolutePositionAndSizes(root);
}
}
}, model.getFile());
}
}, ModalityState.any());
}
Aggregations