Search in sources :

Example 6 with RenderResult

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();
}
Also used : RenderResult(com.android.tools.idea.rendering.RenderResult)

Example 7 with RenderResult

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();
}
Also used : RenderLogger(com.android.tools.idea.rendering.RenderLogger) RenderResult(com.android.tools.idea.rendering.RenderResult) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 8 with RenderResult

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());
}
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 9 with RenderResult

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;
}
Also used : MockPsiFile(com.intellij.mock.MockPsiFile) RenderResult(com.android.tools.idea.rendering.RenderResult) MockPsiFile(com.intellij.mock.MockPsiFile) PsiFile(com.intellij.psi.PsiFile) MockPsiManager(com.intellij.mock.MockPsiManager)

Example 10 with RenderResult

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());
}
Also used : WidgetsScene(com.android.tools.sherpa.structure.WidgetsScene) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) RenderResult(com.android.tools.idea.rendering.RenderResult) List(java.util.List) ConstraintModel(com.android.tools.idea.uibuilder.handlers.constraint.ConstraintModel)

Aggregations

RenderResult (com.android.tools.idea.rendering.RenderResult)11 UsageTracker (com.android.tools.analytics.UsageTracker)2 Configuration (com.android.tools.idea.configurations.Configuration)2 RenderLogger (com.android.tools.idea.rendering.RenderLogger)2 RenderErrorModel (com.android.tools.idea.rendering.errors.ui.RenderErrorModel)2 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)2 PsiFile (com.intellij.psi.PsiFile)2 Update (com.intellij.util.ui.update.Update)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 Result (com.android.ide.common.rendering.api.Result)1 ViewInfo (com.android.ide.common.rendering.api.ViewInfo)1 State (com.android.sdklib.devices.State)1 HtmlLinkManager (com.android.tools.idea.rendering.HtmlLinkManager)1 RenderErrorModelFactory (com.android.tools.idea.rendering.RenderErrorModelFactory)1 ConstraintModel (com.android.tools.idea.uibuilder.handlers.constraint.ConstraintModel)1 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)1 NlModel (com.android.tools.idea.uibuilder.model.NlModel)1 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)1 WidgetsScene (com.android.tools.sherpa.structure.WidgetsScene)1 Cache (com.google.common.cache.Cache)1