aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse/plugins
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2011-06-10 13:41:51 -0700
committerTor Norbye <tnorbye@google.com>2011-06-10 13:41:51 -0700
commit8f21dc3e82c298e727b8813e10896e55f82406f9 (patch)
tree07ec8efd97986a62cb7bdaca3eaa5c1d0fde4c97 /eclipse/plugins
parentb051619189b4c0be377ea080a3f1d188d3f8c073 (diff)
downloadsdk-8f21dc3e82c298e727b8813e10896e55f82406f9.zip
sdk-8f21dc3e82c298e727b8813e10896e55f82406f9.tar.gz
sdk-8f21dc3e82c298e727b8813e10896e55f82406f9.tar.bz2
Workaround view info cookie bug
This changeset works around the case where a ViewInfo cookie is identical to its parent. This is for example the case for a ZoomControls widget, where the child views have MergeCookies whole value points to the parent ZoomControl. Change-Id: Ie0eb62750fba6eeaa7241edce68e05f853e08a75
Diffstat (limited to 'eclipse/plugins')
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java16
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfoTest.java28
2 files changed, 41 insertions, 3 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 7471e54..c37ffe8 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
@@ -779,6 +779,12 @@ public class CanvasViewInfo implements IPropertySource {
assert viewInfo.getCookie() != null;
CanvasViewInfo view = createView(parent, viewInfo, parentX, parentY);
+ // Bug workaround: Ensure that we never have a child node identical
+ // to its parent node: this can happen for example when rendering a
+ // ZoomControls view where the merge cookies point to the parent.
+ if (parent != null && view.mUiViewNode == parent.mUiViewNode) {
+ return null;
+ }
// Process children:
parentX += viewInfo.getLeft();
@@ -792,7 +798,9 @@ public class CanvasViewInfo implements IPropertySource {
if (cookie instanceof UiViewElementNode || cookie instanceof MergeCookie) {
CanvasViewInfo childView = createSubtree(view, child,
parentX, parentY);
- view.addChild(childView);
+ if (childView != null) {
+ view.addChild(childView);
+ }
} // else: null cookies, adapter item references, etc: No child views.
}
@@ -930,7 +938,9 @@ public class CanvasViewInfo implements IPropertySource {
ViewInfo child = children.get(index);
if (child.getCookie() != null) {
CanvasViewInfo childView = createSubtree(parentView, child, parentX, parentY);
- parentView.addChild(childView);
+ if (childView != null) {
+ parentView.addChild(childView);
+ }
if (child.getCookie() instanceof UiViewElementNode) {
afterNode = (UiViewElementNode) child.getCookie();
}
@@ -1084,7 +1094,7 @@ public class CanvasViewInfo implements IPropertySource {
// not MergeCookies.
if (viewInfo.getCookie() != null) {
CanvasViewInfo subtree = createSubtree(parent, viewInfo, parentX, parentY);
- if (parent != null) {
+ if (parent != null && subtree != null) {
parent.mChildren.add(subtree);
}
return subtree;
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 2df472e..bca7cae 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
@@ -623,6 +623,34 @@ public class CanvasViewInfoTest extends TestCase {
assertEquals(new Rectangle(0, 40, 49, 19), bounds2);
}
+ public void testCookieWorkaround() throws Exception {
+ UiViewElementNode rootNode = createNode("android.widget.LinearLayout", true);
+ ViewInfo root = new ViewInfo("included", null, 0, 0, 100, 100);
+
+ UiViewElementNode node2 = createNode(rootNode, "childNode2", false);
+ MergeCookie mergeCookie = new MergeCookie(root);
+
+ ViewInfo childView1 = new ViewInfo("childView1", mergeCookie, 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, true);
+ CanvasViewInfo rootView = result.getFirst();
+ List<Rectangle> bounds = result.getSecond();
+ assertNotNull(rootView);
+
+ assertEquals("included", rootView.getName());
+ assertNull(rootView.getParent());
+ assertNull(rootView.getUiViewNode());
+ // childView1 should have been removed since it has the wrong merge cookie
+ assertEquals(1, rootView.getChildren().size());
+ assertEquals(1, rootView.getUniqueChildren().size());
+
+ Rectangle bounds1 = bounds.get(0);
+ assertEquals(new Rectangle(0, 40, 49, 19), bounds1);
+ }
+
public void testGestureOverlayView() throws Exception {
boolean layoutlib5 = true;