diff options
author | Tor Norbye <tnorbye@google.com> | 2011-03-30 08:42:46 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2011-04-01 13:16:00 -0700 |
commit | 2fa8370664b25f391eb15dc22a3daa2d55d2b883 (patch) | |
tree | 0e1c228a801ccf5a82eedebf77f48fee515c4e02 | |
parent | f979b9484623279babee7efb57231442e3318d98 (diff) | |
download | sdk-2fa8370664b25f391eb15dc22a3daa2d55d2b883.zip sdk-2fa8370664b25f391eb15dc22a3daa2d55d2b883.tar.gz sdk-2fa8370664b25f391eb15dc22a3daa2d55d2b883.tar.bz2 |
Improve view cookie handling
The layout editor is passed a ViewInfo hierarchy by the layout
library. For older versions of the layout library, it can be handed
hierarchies where the view cookies (which point back to XML model
objects corresponding to the rendered views) that are missing or
ambiguous. For that reason, it has various algorithms to try to piece
things back together, and for example handle <merge> scenarios as best
it can.
This isn't necessary with layout lib version 5 and higher, since as of
version 5 these scenarios are handled on the layout lib side and the
layout editor is passed back special cookies like the MergeCookie to
properly handle the various scenarios.
This fix makes the layout editor look up the layoutlib version, and if
dealing with version 5 or higher, it takes a simpler path to build up
the hierarchy.
This is also necessary to deal with the latest version of layoutlib
which passes a new type of view cookie which the older algorithm
couldn't handle.
Change-Id: I98c3ba5d17ad9d639eb118e4709c0b6bbf815b0a
9 files changed, 175 insertions, 44 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java index 2bb8901..2a70dd0 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java @@ -526,19 +526,41 @@ public class CanvasViewInfo implements IPropertySource { * This method will build up a set of {@link CanvasViewInfo} that corresponds to the * actual <b>selectable</b> views (which are also shown in the Outline). * + * @param layoutlib5 if true, the {@link ViewInfo} hierarchy was created by layoutlib + * version 5 or higher, which means this algorithm can make certain assumptions + * (for example that {@code <merge>} siblings will provide {@link MergeCookie} + * references, so we don't have to search for them.) * @param root the root {@link ViewInfo} to build from * @return a {@link CanvasViewInfo} hierarchy */ - public static Pair<CanvasViewInfo,List<Rectangle>> create(ViewInfo root) { - return new Builder().create(root); + public static Pair<CanvasViewInfo,List<Rectangle>> create(ViewInfo root, boolean layoutlib5) { + return new Builder(layoutlib5).create(root); } /** Builder object which walks over a tree of {@link ViewInfo} objects and builds * up a corresponding {@link CanvasViewInfo} hierarchy. */ private static class Builder { - private Map<UiViewElementNode,List<CanvasViewInfo>> mMergeNodeMap; + public Builder(boolean layoutlib5) { + mLayoutLib5 = layoutlib5; + } - public Pair<CanvasViewInfo,List<Rectangle>> create(ViewInfo root) { + /** + * The mapping from nodes that have a {@code <merge>} as a parent in the node + * model to their corresponding views + */ + private Map<UiViewElementNode, List<CanvasViewInfo>> mMergeNodeMap; + + /** + * Whether the ViewInfos are provided by a layout library that is version 5 or + * later, since that will allow us to take several shortcuts + */ + private boolean mLayoutLib5; + + /** + * Creates a hierarchy of {@link CanvasViewInfo} objects and merge bounding + * rectangles from the given {@link ViewInfo} hierarchy + */ + private Pair<CanvasViewInfo,List<Rectangle>> create(ViewInfo root) { Object cookie = root.getCookie(); if (cookie == null) { // Special case: If the root-most view does not have a view cookie, @@ -717,10 +739,24 @@ public class CanvasViewInfo implements IPropertySource { parentX += viewInfo.getLeft(); parentY += viewInfo.getTop(); + List<ViewInfo> children = viewInfo.getChildren(); + + if (mLayoutLib5) { + for (ViewInfo child : children) { + Object cookie = child.getCookie(); + if (cookie instanceof UiViewElementNode || cookie instanceof MergeCookie) { + CanvasViewInfo childView = createSubtree(view, child, + parentX, parentY); + view.addChild(childView); + } // else: null cookies, adapter item references, etc: No child views. + } + + return view; + } + // See if we have any missing keys at this level int missingNodes = 0; int mergeNodes = 0; - List<ViewInfo> children = viewInfo.getChildren(); for (ViewInfo child : children) { // Only use children which have a ViewKey of the correct type. // We can't interact with those when they have a null key or @@ -751,7 +787,9 @@ public class CanvasViewInfo implements IPropertySource { // embedded_layout rendering, or we are including a view with a <merge> // as the root element. - String containerName = view.getUiViewNode().getDescriptor().getXmlLocalName(); + UiViewElementNode uiViewNode = view.getUiViewNode(); + String containerName = uiViewNode != null + ? uiViewNode.getDescriptor().getXmlLocalName() : ""; //$NON-NLS-1$ if (containerName.equals(LayoutDescriptors.VIEW_INCLUDE)) { // This is expected -- we don't WANT to get node keys for the content // of an include since it's in a different file and should be treated @@ -764,9 +802,11 @@ public class CanvasViewInfo implements IPropertySource { // that there are <merge> tags which are doing surprising things // to the view hierarchy LinkedList<UiViewElementNode> unused = new LinkedList<UiViewElementNode>(); - for (UiElementNode child : view.getUiViewNode().getUiChildren()) { - if (child instanceof UiViewElementNode) { - unused.addLast((UiViewElementNode) child); + if (uiViewNode != null) { + for (UiElementNode child : uiViewNode.getUiChildren()) { + if (child instanceof UiViewElementNode) { + unused.addLast((UiViewElementNode) child); + } } } for (ViewInfo child : children) { diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java index ad3292e..0a65865 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java @@ -1053,7 +1053,7 @@ public class GraphicalEditorPart extends EditorPart new StaticRenderSession( Result.Status.SUCCESS.createResult(), null /*rootViewInfo*/, null /*image*/), - null /*explodeNodes*/); + null /*explodeNodes*/, true /* layoutlib5 */); return; } @@ -1339,7 +1339,8 @@ public class GraphicalEditorPart extends EditorPart explodeNodes, null /*custom background*/, false /*no decorations*/, logger, mIncludedWithin, renderingMode); - canvas.setSession(session, explodeNodes); + boolean layoutlib5 = layoutLib.supports(Capability.EMBEDDED_LAYOUT); + canvas.setSession(session, explodeNodes, layoutlib5); // update the UiElementNode with the layout info. if (session != null && session.getResult().isSuccess() == false) { diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java index 321ad01..b54e3d1 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java @@ -553,11 +553,12 @@ public class LayoutCanvas extends Canvas { * {@link #showInvisibleViews(boolean)}) where individual invisible nodes * are padded during certain interactions. */ - /* package */ void setSession(RenderSession session, Set<UiElementNode> explodedNodes) { + /* package */ void setSession(RenderSession session, Set<UiElementNode> explodedNodes, + boolean layoutlib5) { // disable any hover clearHover(); - mViewHierarchy.setSession(session, explodedNodes); + mViewHierarchy.setSession(session, explodedNodes, layoutlib5); if (mViewHierarchy.isValid() && session != null) { Image image = mImageOverlay.setImage(session.getImage(), session.isAlphaChannelImage()); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ViewHierarchy.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ViewHierarchy.java index 8624cd3..10625bb 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ViewHierarchy.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ViewHierarchy.java @@ -136,7 +136,8 @@ public class ViewHierarchy { * {@link LayoutCanvas#showInvisibleViews}) where individual invisible * nodes are padded during certain interactions. */ - /* package */ void setSession(RenderSession session, Set<UiElementNode> explodedNodes) { + /* package */ void setSession(RenderSession session, Set<UiElementNode> explodedNodes, + boolean layoutlib5) { // replace the previous scene, so the previous scene must be disposed. if (mSession != null) { mSession.dispose(); @@ -157,7 +158,7 @@ public class ViewHierarchy { // via drag & drop, etc. if (hasMergeRoot()) { ViewInfo mergeRoot = createMergeInfo(session); - infos = CanvasViewInfo.create(mergeRoot); + infos = CanvasViewInfo.create(mergeRoot, layoutlib5); } else { infos = null; } @@ -165,11 +166,12 @@ public class ViewHierarchy { if (rootList.size() > 1 && hasMergeRoot()) { ViewInfo mergeRoot = createMergeInfo(session); mergeRoot.setChildren(rootList); - infos = CanvasViewInfo.create(mergeRoot); + infos = CanvasViewInfo.create(mergeRoot, layoutlib5); } else { ViewInfo root = rootList.get(0); + if (root != null) { - infos = CanvasViewInfo.create(root); + infos = CanvasViewInfo.create(root, layoutlib5); if (DUMP_INFO) { dump(root, 0); } diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RefactoringTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RefactoringTest.java index 18d56a1..661b553 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RefactoringTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RefactoringTest.java @@ -258,7 +258,7 @@ public class RefactoringTest extends AdtProjectTest { UiViewElementNode model = createModel(null, element); ViewInfo info = createInfos(model, relativePath); - CanvasViewInfo rootView = CanvasViewInfo.create(info).getFirst(); + CanvasViewInfo rootView = CanvasViewInfo.create(info, true /* layoutlib5 */).getFirst(); TestLayoutEditor layoutEditor = new TestLayoutEditor(file, structuredDocument, null); TestContext testInfo = createTestContext(); diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfoTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfoTest.java index 494346a..d336b35 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfoTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfoTest.java @@ -18,7 +18,9 @@ package com.android.ide.eclipse.adt.internal.editors.layout.gle2; import com.android.ide.common.rendering.api.Capability; import com.android.ide.common.rendering.api.MergeCookie; +import com.android.ide.common.rendering.api.SessionParams; import com.android.ide.common.rendering.api.ViewInfo; +import com.android.ide.common.rendering.api.SessionParams.AdapterItemReference; import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor; import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.ViewElementDescriptor; @@ -65,6 +67,15 @@ public class CanvasViewInfoTest extends TestCase { } public void testNormalCreate() throws Exception { + normal(true); + } + + public void testNormalCreateLayoutLib5() throws Exception { + normal(false); + } + + private void normal(boolean layoutlib5) { + // Normal view hierarchy, no null keys anywhere UiViewElementNode rootNode = createNode("android.widget.LinearLayout", true); @@ -75,7 +86,7 @@ public class CanvasViewInfoTest extends TestCase { ViewInfo child2 = new ViewInfo("Button", child2Node, 0, 20, 70, 25); root.setChildren(Arrays.asList(child1, child2)); - CanvasViewInfo rootView = CanvasViewInfo.create(root).getFirst(); + CanvasViewInfo rootView = CanvasViewInfo.create(root, layoutlib5).getFirst(); assertNotNull(rootView); assertEquals("LinearLayout", rootView.getName()); assertEquals(new Rectangle(10, 10, 89, 89), rootView.getAbsRect()); @@ -100,6 +111,15 @@ public class CanvasViewInfoTest extends TestCase { } public void testShowIn() throws Exception { + showIn(false); + } + + public void testShowInLayoutLib5() throws Exception { + showIn(true); + } + + public void showIn(boolean layoutlib5) throws Exception { + // Test rendering of "Show Included In" (included content rendered // within an outer content that has null keys) @@ -112,7 +132,7 @@ public class CanvasViewInfoTest extends TestCase { ViewInfo child21 = new ViewInfo("RadioButton", child21Node, 0, 20, 70, 25); child2.setChildren(Arrays.asList(child21)); - CanvasViewInfo rootView = CanvasViewInfo.create(root).getFirst(); + CanvasViewInfo rootView = CanvasViewInfo.create(root, layoutlib5).getFirst(); assertNotNull(rootView); assertEquals("LinearLayout", rootView.getName()); assertEquals(new Rectangle(10, 10, 89, 89), rootView.getAbsRect()); @@ -137,6 +157,8 @@ public class CanvasViewInfoTest extends TestCase { } public void testIncludeTag() throws Exception { + boolean layoutlib5 = true; + // Test rendering of included views on layoutlib 5+ (e.g. has <include> tag) UiViewElementNode rootNode = createNode("android.widget.LinearLayout", true); @@ -149,7 +171,7 @@ public class CanvasViewInfoTest extends TestCase { ViewInfo child21 = new ViewInfo("RadioButton", null, 0, 20, 70, 25); child2.setChildren(Arrays.asList(child21)); - CanvasViewInfo rootView = CanvasViewInfo.create(root).getFirst(); + CanvasViewInfo rootView = CanvasViewInfo.create(root, layoutlib5).getFirst(); assertNotNull(rootView); assertEquals("LinearLayout", rootView.getName()); assertEquals(new Rectangle(10, 10, 89, 89), rootView.getAbsRect()); @@ -176,9 +198,10 @@ public class CanvasViewInfoTest extends TestCase { } public void testNoIncludeTag() throws Exception { + boolean layoutlib5 = false; + // Test rendering of included views on layoutlib 4- (e.g. no <include> tag cookie - // in - // view info) + // in view info) UiViewElementNode rootNode = createNode("android.widget.LinearLayout", true); ViewInfo root = new ViewInfo("LinearLayout", rootNode, 10, 10, 100, 100); @@ -190,7 +213,7 @@ public class CanvasViewInfoTest extends TestCase { ViewInfo child21 = new ViewInfo("RadioButton", null, 0, 20, 70, 25); child2.setChildren(Arrays.asList(child21)); - CanvasViewInfo rootView = CanvasViewInfo.create(root).getFirst(); + CanvasViewInfo rootView = CanvasViewInfo.create(root, layoutlib5).getFirst(); assertNotNull(rootView); assertEquals("LinearLayout", rootView.getName()); assertEquals(new Rectangle(10, 10, 89, 89), rootView.getAbsRect()); @@ -217,6 +240,8 @@ public class CanvasViewInfoTest extends TestCase { } public void testMergeMatching() throws Exception { + boolean layoutlib5 = false; + // Test rendering of MULTIPLE included views or when there is no simple match // between view info and ui element node children @@ -232,7 +257,7 @@ public class CanvasViewInfoTest extends TestCase { ViewInfo child21 = new ViewInfo("RadioButton", null, 0, 20, 70, 25); child2.setChildren(Arrays.asList(child21)); - CanvasViewInfo rootView = CanvasViewInfo.create(root).getFirst(); + CanvasViewInfo rootView = CanvasViewInfo.create(root, layoutlib5).getFirst(); assertNotNull(rootView); assertEquals("LinearLayout", rootView.getName()); assertEquals(new Rectangle(10, 10, 89, 89), rootView.getAbsRect()); @@ -272,6 +297,8 @@ public class CanvasViewInfoTest extends TestCase { } public void testMerge() throws Exception { + boolean layoutlib5 = false; + // Test rendering of MULTIPLE included views or when there is no simple match // between view info and ui element node children @@ -286,7 +313,7 @@ public class CanvasViewInfoTest extends TestCase { ViewInfo child21 = new ViewInfo("RadioButton", null, 0, 20, 70, 25); child2.setChildren(Arrays.asList(child21)); - CanvasViewInfo rootView = CanvasViewInfo.create(root).getFirst(); + CanvasViewInfo rootView = CanvasViewInfo.create(root, layoutlib5).getFirst(); assertNotNull(rootView); assertEquals("LinearLayout", rootView.getName()); assertEquals(new Rectangle(10, 10, 89, 89), rootView.getAbsRect()); @@ -313,6 +340,8 @@ public class CanvasViewInfoTest extends TestCase { } public void testInsertMerge() throws Exception { + boolean layoutlib5 = false; + // Test rendering of MULTIPLE included views or when there is no simple match // between view info and ui element node children @@ -320,7 +349,7 @@ public class CanvasViewInfoTest extends TestCase { UiViewElementNode rootNode = createNode(mergeNode, "android.widget.Button", false); ViewInfo root = new ViewInfo("Button", rootNode, 10, 10, 100, 100); - CanvasViewInfo rootView = CanvasViewInfo.create(root).getFirst(); + CanvasViewInfo rootView = CanvasViewInfo.create(root, layoutlib5).getFirst(); assertNotNull(rootView); assertEquals("merge", rootView.getName()); assertSame(rootView.getUiViewNode(), mergeNode); @@ -340,6 +369,8 @@ public class CanvasViewInfoTest extends TestCase { } public void testUnmatchedMissing() throws Exception { + boolean layoutlib5 = false; + UiViewElementNode rootNode = createNode("android.widget.LinearLayout", true); ViewInfo root = new ViewInfo("LinearLayout", rootNode, 0, 0, 100, 100); List<ViewInfo> children = new ArrayList<ViewInfo>(); @@ -387,7 +418,7 @@ public class CanvasViewInfoTest extends TestCase { } root.setChildren(children); - CanvasViewInfo rootView = CanvasViewInfo.create(root).getFirst(); + CanvasViewInfo rootView = CanvasViewInfo.create(root, layoutlib5).getFirst(); assertNotNull(rootView); // dump(root, 0); @@ -412,6 +443,8 @@ public class CanvasViewInfoTest extends TestCase { } public void testMergeCookies() throws Exception { + boolean layoutlib5 = true; + UiViewElementNode rootNode = createNode("android.widget.LinearLayout", true); ViewInfo root = new ViewInfo("LinearLayout", rootNode, 0, 0, 100, 100); @@ -431,7 +464,7 @@ public class CanvasViewInfoTest extends TestCase { } root.setChildren(children); - CanvasViewInfo rootView = CanvasViewInfo.create(root).getFirst(); + CanvasViewInfo rootView = CanvasViewInfo.create(root, layoutlib5).getFirst(); assertNotNull(rootView); assertEquals("LinearLayout", rootView.getName()); @@ -446,6 +479,8 @@ public class CanvasViewInfoTest extends TestCase { } public void testMergeCookies2() throws Exception { + boolean layoutlib5 = true; + UiViewElementNode rootNode = createNode("android.widget.LinearLayout", true); ViewInfo root = new ViewInfo("LinearLayout", rootNode, 0, 0, 100, 100); @@ -460,12 +495,13 @@ public class CanvasViewInfoTest extends TestCase { ArrayList<ViewInfo> children = new ArrayList<ViewInfo>(); for (int i = 0; i < 10; i++) { Object cookie = (i % 2) == 0 ? cookie1 : cookie2; - ViewInfo childView = new ViewInfo("childView" + i, cookie, 0, i * 20, 50, (i + 1) * 20); + ViewInfo childView = new ViewInfo("childView" + i, cookie, 0, i * 20, 50, + (i + 1) * 20); children.add(childView); } root.setChildren(children); - Pair<CanvasViewInfo, List<Rectangle>> result = CanvasViewInfo.create(root); + Pair<CanvasViewInfo, List<Rectangle>> result = CanvasViewInfo.create(root, layoutlib5); CanvasViewInfo rootView = result.getFirst(); List<Rectangle> bounds = result.getSecond(); assertNull(bounds); @@ -495,6 +531,8 @@ public class CanvasViewInfoTest extends TestCase { } public void testIncludeBounds() throws Exception { + boolean layoutlib5 = true; + UiViewElementNode rootNode = createNode("android.widget.LinearLayout", true); ViewInfo root = new ViewInfo("included", null, 0, 0, 100, 100); @@ -509,12 +547,13 @@ public class CanvasViewInfoTest extends TestCase { ArrayList<ViewInfo> children = new ArrayList<ViewInfo>(); for (int i = 0; i < 10; i++) { Object cookie = (i % 2) == 0 ? cookie1 : cookie2; - ViewInfo childView = new ViewInfo("childView" + i, cookie, 0, i * 20, 50, (i + 1) * 20); + ViewInfo childView = new ViewInfo("childView" + i, cookie, 0, i * 20, 50, + (i + 1) * 20); children.add(childView); } root.setChildren(children); - Pair<CanvasViewInfo, List<Rectangle>> result = CanvasViewInfo.create(root); + Pair<CanvasViewInfo, List<Rectangle>> result = CanvasViewInfo.create(root, layoutlib5); CanvasViewInfo rootView = result.getFirst(); List<Rectangle> bounds = result.getSecond(); assertNotNull(rootView); @@ -548,21 +587,27 @@ public class CanvasViewInfoTest extends TestCase { } public void testIncludeBounds2() throws Exception { + includeBounds2(false); + } + + public void testIncludeBounds2LayoutLib5() throws Exception { + includeBounds2(true); + } + + public void includeBounds2(boolean layoutlib5) throws Exception { + UiViewElementNode rootNode = createNode("android.widget.LinearLayout", true); ViewInfo root = new ViewInfo("included", null, 0, 0, 100, 100); UiViewElementNode node1 = createNode(rootNode, "childNode1", false); UiViewElementNode node2 = createNode(rootNode, "childNode2", false); - // Sets alternating merge cookies and checks whether the node sibling lists are - // okay and merged correctly - ViewInfo childView1 = new ViewInfo("childView1", node1, 0, 20, 50, 40); ViewInfo childView2 = new ViewInfo("childView2", node2, 0, 40, 50, 60); root.setChildren(Arrays.asList(childView1, childView2)); - Pair<CanvasViewInfo, List<Rectangle>> result = CanvasViewInfo.create(root); + Pair<CanvasViewInfo, List<Rectangle>> result = CanvasViewInfo.create(root, layoutlib5); CanvasViewInfo rootView = result.getFirst(); List<Rectangle> bounds = result.getSecond(); assertNotNull(rootView); @@ -580,6 +625,8 @@ public class CanvasViewInfoTest extends TestCase { } public void testGestureOverlayView() throws Exception { + boolean layoutlib5 = true; + // Test rendering of included views on layoutlib 5+ (e.g. has <include> tag) UiViewElementNode rootNode = createNode("android.gesture.GestureOverlayView", true); @@ -590,7 +637,7 @@ public class CanvasViewInfoTest extends TestCase { root.setChildren(Collections.singletonList(child)); ViewInfo grandChild = new ViewInfo("Button", grandChildNode, 0, 20, 70, 25); child.setChildren(Collections.singletonList(grandChild)); - CanvasViewInfo rootView = CanvasViewInfo.create(root).getFirst(); + CanvasViewInfo rootView = CanvasViewInfo.create(root, layoutlib5).getFirst(); assertNotNull(rootView); assertEquals("GestureOverlayView", rootView.getName()); @@ -611,6 +658,46 @@ public class CanvasViewInfoTest extends TestCase { assertFalse(grandChildView.isRoot()); } + public void testListView() throws Exception { + // For ListViews we get AdapterItemReferences as cookies. Ensure that this + // works properly. + // + // android.widget.FrameLayout [0,50,320,480] <FrameLayout> + // android.widget.ListView [0,0,320,430] <ListView> + // android.widget.LinearLayout [0,0,320,17] SessionParams$AdapterItemReference + // android.widget.TextView [0,0,73,17] + // android.widget.LinearLayout [0,18,320,35] SessionParams$AdapterItemReference + // android.widget.TextView [0,0,73,17] + // android.widget.LinearLayout [0,36,320,53] SessionParams$AdapterItemReference + // android.widget.TextView [0,0,73,17] + // ... + + UiViewElementNode rootNode = createNode("FrameLayout", true); + UiViewElementNode childNode = createNode(rootNode, "ListView", false); + /*UiViewElementNode grandChildNode =*/ createNode(childNode, "LinearLayout", false); + /*UiViewElementNode greatGrandChildNode =*/ createNode(childNode, "TextView", false); + AdapterItemReference adapterItem = new SessionParams.AdapterItemReference("foo"); + + ViewInfo root = new ViewInfo("FrameLayout", rootNode, 0, 50, 320, 480); + ViewInfo child = new ViewInfo("ListView", childNode, 0, 0, 320, 430); + root.setChildren(Collections.singletonList(child)); + ViewInfo grandChild = new ViewInfo("LinearLayout", adapterItem, 0, 0, 320, 17); + child.setChildren(Collections.singletonList(grandChild)); + ViewInfo greatGrandChild = new ViewInfo("Button", null, 0, 0, 73, 17); + grandChild.setChildren(Collections.singletonList(greatGrandChild)); + CanvasViewInfo rootView = CanvasViewInfo.create(root, true /*layoutlib5*/).getFirst(); + assertNotNull(rootView); + + assertEquals("FrameLayout", rootView.getName()); + assertEquals(1, rootView.getChildren().size()); + assertSame(rootNode, rootView.getUiViewNode()); + + CanvasViewInfo childView = rootView.getChildren().get(0); + assertEquals("ListView", childView.getName()); + assertEquals(0, childView.getChildren().size()); + assertSame(childNode, childView.getUiViewNode()); + } + /** * Dumps out the given {@link ViewInfo} hierarchy to standard out. * Useful during development. diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionManagerTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionManagerTest.java index db18762..b29f9f3 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionManagerTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionManagerTest.java @@ -53,7 +53,7 @@ public class SelectionManagerTest extends TestCase { "android.widget.Button", false); ViewInfo child2 = new ViewInfo("Button2", child2Node, 0, 20, 70, 25); root.setChildren(Arrays.asList(child1, child2)); - CanvasViewInfo rootView = CanvasViewInfo.create(root).getFirst(); + CanvasViewInfo rootView = CanvasViewInfo.create(root, true /* layoutlib5 */).getFirst(); assertNotNull(rootView); manager.selectMultiple(Arrays.asList(rootView, rootView.getChildren().get(0), rootView @@ -104,7 +104,7 @@ public class SelectionManagerTest extends TestCase { "android.widget.Button", false); ViewInfo child2 = new ViewInfo("Button2", child2Node, 0, 20, 70, 25); root.setChildren(Arrays.asList(child1, child2)); - CanvasViewInfo rootView = CanvasViewInfo.create(root).getFirst(); + CanvasViewInfo rootView = CanvasViewInfo.create(root, true /* layoutlib5 */).getFirst(); assertNotNull(rootView); manager.selectMultiple(Arrays.asList(rootView.getChildren().get(0))); diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gre/NodeFactoryTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gre/NodeFactoryTest.java index 277089f..9f670cc 100755 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gre/NodeFactoryTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gre/NodeFactoryTest.java @@ -48,7 +48,7 @@ public class NodeFactoryTest extends TestCase { ViewElementDescriptor ved = new ViewElementDescriptor("xml", "com.example.MyJavaClass"); UiViewElementNode uiv = new UiViewElementNode(ved); ViewInfo lvi = new ViewInfo("name", uiv, 10, 12, 110, 120); - CanvasViewInfo cvi = CanvasViewInfo.create(lvi).getFirst(); + CanvasViewInfo cvi = CanvasViewInfo.create(lvi, true /* layoutlib5 */).getFirst(); // Create a NodeProxy. NodeProxy proxy = m.create(cvi); @@ -95,7 +95,7 @@ public class NodeFactoryTest extends TestCase { ViewElementDescriptor ved = new ViewElementDescriptor("xml", "com.example.MyJavaClass"); UiViewElementNode uiv = new UiViewElementNode(ved); ViewInfo lvi = new ViewInfo("name", uiv, 10, 12, 110, 120); - CanvasViewInfo cvi = CanvasViewInfo.create(lvi).getFirst(); + CanvasViewInfo cvi = CanvasViewInfo.create(lvi, true /* layoutlib5 */).getFirst(); // NodeProxies are cached. Creating the same one twice returns the same proxy. NodeProxy proxy1 = m.create(cvi); @@ -107,7 +107,7 @@ public class NodeFactoryTest extends TestCase { ViewElementDescriptor ved = new ViewElementDescriptor("xml", "com.example.MyJavaClass"); UiViewElementNode uiv = new UiViewElementNode(ved); ViewInfo lvi = new ViewInfo("name", uiv, 10, 12, 110, 120); - CanvasViewInfo cvi = CanvasViewInfo.create(lvi).getFirst(); + CanvasViewInfo cvi = CanvasViewInfo.create(lvi, true /* layoutlib5 */).getFirst(); // NodeProxies are cached. Creating the same one twice returns the same proxy. NodeProxy proxy1 = m.create(cvi); diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/Capability.java b/layoutlib_api/src/com/android/ide/common/rendering/api/Capability.java index 2f79038..6620571 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/Capability.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/Capability.java @@ -24,7 +24,7 @@ public enum Capability { /** Ability to render at full size, as required by the layout, and unbound by the screen */ UNBOUND_RENDERING, /** Ability to override the background of the rendering with transparency using - * {@link SessionParams#setCustomBackgroundColor(int)} */ + * {@link SessionParams#setOverrideBgColor(int)} */ CUSTOM_BACKGROUND_COLOR, /** Ability to call {@link RenderSession#render()} and {@link RenderSession#render(long)}. */ RENDER, |