Search in sources :

Example 21 with ViewInfo

use of com.android.ide.common.rendering.api.ViewInfo in project android_frameworks_base by AOSPA.

the class RenderSessionImpl method visit.

/**
     * Visits a {@link View} and its children and generate a {@link ViewInfo} containing the
     * bounds of all the views.
     *
     * @param view the root View
     * @param offset an offset for the view bounds.
     * @param setExtendedInfo whether to set the extended view info in the {@link ViewInfo} object.
     * @param isContentFrame {@code true} if the {@code ViewInfo} to be created is part of the
     *                       content frame.
     *
     * @return {@code ViewInfo} containing the bounds of the view and it children otherwise.
     */
private ViewInfo visit(View view, int offset, boolean setExtendedInfo, boolean isContentFrame) {
    ViewInfo result = createViewInfo(view, offset, setExtendedInfo, isContentFrame);
    if (view instanceof ViewGroup) {
        ViewGroup group = ((ViewGroup) view);
        result.setChildren(visitAllChildren(group, isContentFrame ? 0 : offset, setExtendedInfo, isContentFrame));
    }
    return result;
}
Also used : ViewGroup(android.view.ViewGroup) ViewInfo(com.android.ide.common.rendering.api.ViewInfo)

Example 22 with ViewInfo

use of com.android.ide.common.rendering.api.ViewInfo 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 23 with ViewInfo

use of com.android.ide.common.rendering.api.ViewInfo in project android by JetBrains.

the class ComponentDescriptor method createViewInfo.

@NotNull
public ViewInfo createViewInfo(@Nullable ComponentDescriptor parent, @NotNull XmlTag tag) {
    int left = myX;
    int top = myY;
    if (parent != null) {
        left -= parent.myX;
        top -= parent.myY;
    }
    int right = left + myWidth;
    int bottom = top + myHeight;
    TagSnapshot snapshot = TagSnapshot.createTagSnapshotWithoutChildren(tag);
    TestViewInfo viewInfo = new TestViewInfo(myTagName, snapshot, left, top, right, bottom, myViewObject, myLayoutParamsObject);
    viewInfo.setExtendedInfo((int) (0.8 * (bottom - top)), 0, 0, 0, 0);
    if (myViewType != null) {
        viewInfo.setViewType(myViewType);
    }
    List<ViewInfo> childList = Lists.newArrayList();
    XmlTag[] subTags = tag.getSubTags();
    assertEquals(subTags.length, myChildren.length);
    for (int i = 0; i < subTags.length; i++) {
        ComponentDescriptor childDescriptor = myChildren[i];
        XmlTag childTag = subTags[i];
        childList.add(childDescriptor.createViewInfo(this, childTag));
    }
    viewInfo.setChildren(childList);
    return viewInfo;
}
Also used : TagSnapshot(com.android.tools.idea.rendering.TagSnapshot) ViewInfo(com.android.ide.common.rendering.api.ViewInfo) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with ViewInfo

use of com.android.ide.common.rendering.api.ViewInfo in project android by JetBrains.

the class SelectionLayer method parentHandlingSelection.

/**
   * Utility function that checks if the component is a child of a view group that
   * handles painting
   *
   * @param component          the component we are looking at
   * @return true if the parent container handles painting
   */
private static boolean parentHandlingSelection(@NotNull NlComponent component) {
    NlComponent parent = component.getParent();
    if (parent == null) {
        return false;
    }
    ViewInfo view = parent.viewInfo;
    if (view == null) {
        return false;
    }
    ViewHandler handler = parent.getViewHandler();
    if (handler != null && handler instanceof ViewGroupHandler) {
        ViewGroupHandler viewGroupHandler = (ViewGroupHandler) handler;
        if (viewGroupHandler.handlesPainting()) {
            return true;
        }
    }
    return false;
}
Also used : ViewHandler(com.android.tools.idea.uibuilder.api.ViewHandler) ViewGroupHandler(com.android.tools.idea.uibuilder.api.ViewGroupHandler) ViewInfo(com.android.ide.common.rendering.api.ViewInfo)

Example 25 with ViewInfo

use of com.android.ide.common.rendering.api.ViewInfo in project android by JetBrains.

the class PreferenceScreenTestFactory method mockEditor.

@NotNull
static ViewEditor mockEditor() {
    ListView listView = Mockito.mock(ListView.class);
    Mockito.when(listView.getDividerHeight()).thenReturn(2);
    ViewInfo view = new ViewInfo(FQCN_LIST_VIEW, null, 0, 0, 0, 0, listView, null);
    ViewEditor editor = Mockito.mock(ViewEditor.class);
    Mockito.when(editor.getRootViews()).thenReturn(Collections.singletonList(view));
    return editor;
}
Also used : ListView(android.widget.ListView) ViewEditor(com.android.tools.idea.uibuilder.api.ViewEditor) ViewInfo(com.android.ide.common.rendering.api.ViewInfo) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ViewInfo (com.android.ide.common.rendering.api.ViewInfo)37 ViewGroup (android.view.ViewGroup)11 LayoutParams (android.view.ViewGroup.LayoutParams)6 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)6 SessionParams (com.android.ide.common.rendering.api.SessionParams)6 XmlTag (com.intellij.psi.xml.XmlTag)6 ViewParent (android.view.ViewParent)5 ActionMenuView (android.widget.ActionMenuView)5 ListMenuItemView (com.android.internal.view.menu.ListMenuItemView)5 LayoutLibTestCallback (com.android.layoutlib.bridge.intensive.setup.LayoutLibTestCallback)5 LayoutPullParser (com.android.layoutlib.bridge.intensive.setup.LayoutPullParser)5 NotNull (org.jetbrains.annotations.NotNull)5 Test (org.junit.Test)5 View (android.view.View)3 RenderLogger (com.android.tools.idea.rendering.RenderLogger)3 XmlFile (com.intellij.psi.xml.XmlFile)3 ListView (android.widget.ListView)2 Configuration (com.android.tools.idea.configurations.Configuration)2 RenderService (com.android.tools.idea.rendering.RenderService)2 RenderTask (com.android.tools.idea.rendering.RenderTask)2