Search in sources :

Example 11 with ViewInfo

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

the class NlComponentFixture method requireActualText.

public void requireActualText(@NotNull String expectedText) {
    ViewInfo viewInfo = myComponent.viewInfo;
    Object viewObject = viewInfo.getViewObject();
    try {
        Method getText = viewObject.getClass().getMethod("getText");
        String actualText = (String) getText.invoke(viewObject);
        assertEquals(expectedText, actualText);
    } catch (NoSuchMethodException e) {
        fail("No getText() method on " + viewObject.getClass().getName());
    } catch (InvocationTargetException e) {
        fail("Can't invoke getText() method on " + viewObject.getClass().getName());
    } catch (IllegalAccessException e) {
        fail("Can't access getText() method on " + viewObject.getClass().getName());
    }
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) ViewInfo(com.android.ide.common.rendering.api.ViewInfo)

Example 12 with ViewInfo

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

the class RenderServiceTest method testGetSafeBounds.

public void testGetSafeBounds() {
    ViewInfo valid;
    ViewInfo invalid;
    valid = new ViewInfo("", "", 0, 0, 0, 0);
    assertSame(valid, RenderService.getSafeBounds(valid));
    valid = new ViewInfo("", "", 0, 0, 1024, 768);
    assertSame(valid, RenderService.getSafeBounds(valid));
    valid = new ViewInfo("", "", -200, -200, 8000, 8000);
    assertSame(valid, RenderService.getSafeBounds(valid));
    invalid = new ViewInfo("", "", -(1 << 27), 0, 0, 0);
    assertNotSame(invalid, RenderService.getSafeBounds(invalid));
    assertEquals(0, RenderService.getSafeBounds(invalid).getLeft());
    invalid = new ViewInfo("", "", +(1 << 27), 0, 0, 0);
    assertNotSame(invalid, RenderService.getSafeBounds(invalid));
    invalid = new ViewInfo("", "", 0, -(1 << 27), 0, 0);
    assertNotSame(invalid, RenderService.getSafeBounds(invalid));
    invalid = new ViewInfo("", "", 0, +(1 << 27), 0, 0);
    assertNotSame(invalid, RenderService.getSafeBounds(invalid));
    invalid = new ViewInfo("", "", 0, 0, -(1 << 27), 0);
    assertNotSame(invalid, RenderService.getSafeBounds(invalid));
    invalid = new ViewInfo("", "", 0, 0, +(1 << 27), 0);
    assertNotSame(invalid, RenderService.getSafeBounds(invalid));
    invalid = new ViewInfo("", "", 0, 0, 0, -(1 << 27));
    assertNotSame(invalid, RenderService.getSafeBounds(invalid));
    invalid = new ViewInfo("", "", 0, 0, 0, +(1 << 27));
    assertNotSame(invalid, RenderService.getSafeBounds(invalid));
}
Also used : ViewInfo(com.android.ide.common.rendering.api.ViewInfo)

Example 13 with ViewInfo

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

the class GenerateLayoutTestSkeletonAction method getBounds.

@NotNull
private static Rectangle getBounds(@NotNull NlComponent component) {
    NlComponent parent = component.getParent();
    Rectangle parentBounds = parent != null ? getBounds(parent) : new Rectangle(0, 0, 1000, 1000);
    ViewInfo viewInfo = component.viewInfo;
    if (viewInfo == null) {
        return new Rectangle(parentBounds.x, parentBounds.y, 100, 100);
    }
    return new Rectangle(viewInfo.getLeft() + parentBounds.x, viewInfo.getTop() + parentBounds.y, viewInfo.getRight() - viewInfo.getLeft(), viewInfo.getBottom() - viewInfo.getTop());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ViewInfo(com.android.ide.common.rendering.api.ViewInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with ViewInfo

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

the class MenuTestFactory method mockViewInfo.

@NotNull
static ViewInfo mockViewInfo(@NotNull ViewType viewType) {
    ViewInfo view = Mockito.mock(ViewInfo.class);
    Mockito.when(view.getViewType()).thenReturn(viewType);
    return view;
}
Also used : ViewInfo(com.android.ide.common.rendering.api.ViewInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with ViewInfo

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

the class PreferenceScreenDragHandlerLayoutTest method mockEditor.

@NotNull
private static ViewEditor mockEditor(@NotNull NlModel model) {
    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.getModel()).thenReturn(model);
    Mockito.when(editor.getRootViews()).thenReturn(Collections.singletonList(view));
    return editor;
}
Also used : ListView(android.widget.ListView) 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