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