PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/common/layout/RelativeLayoutRuleTest.java

https://gitlab.com/Codeaurora/platform_sdk
Java | 166 lines | 31 code | 9 blank | 126 comment | 0 complexity | 39507a3a8176205a8db0385507bf7a03 MD5 | raw file
  1. /*
  2. * Copyright (C) 2010 The Android Open Source Project
  3. *
  4. * Licensed under the Eclipse Public License, Version 1.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.eclipse.org/org/documents/epl-v10.php
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.android.ide.common.layout;
  17. import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI;
  18. import com.android.ide.common.api.INode;
  19. import com.android.ide.common.api.Point;
  20. import com.android.ide.common.api.Rect;
  21. /** Test the {@link RelativeLayoutRule} */
  22. public class RelativeLayoutRuleTest extends LayoutTestBase {
  23. // Utility for other tests
  24. protected INode dragInto(Rect dragBounds, Point dragPoint, Point secondDragPoint,
  25. int insertIndex, int currentIndex, String... graphicsFragments) {
  26. INode layout = TestNode.create("android.widget.RelativeLayout").id("@+id/RelativeLayout01")
  27. .bounds(new Rect(0, 0, 240, 480)).add(
  28. // Add centered button as the anchor
  29. TestNode.create("android.widget.Button").id("@+id/Centered").bounds(
  30. new Rect(70, 200, 100, 80)).set(ANDROID_URI,
  31. "layout_centerInParent", "true"),
  32. // Add a second button anchored to it
  33. TestNode.create("android.widget.Button").id("@+id/Below").bounds(
  34. new Rect(70, 280, 100, 80)).set(ANDROID_URI, "layout_below",
  35. "@+id/Centered").set(ANDROID_URI, "layout_alignLeft",
  36. "@+id/Centered"));
  37. return super.dragInto(new RelativeLayoutRule(), layout, dragBounds, dragPoint,
  38. secondDragPoint, insertIndex, currentIndex, graphicsFragments);
  39. }
  40. protected INode dragInto(Rect dragBounds, Point dragPoint, Point secondDragPoint,
  41. int insertIndex, int currentIndex, String[] extraFragments,
  42. String... graphicsFragments) {
  43. // When we switch to JDK6, use Arrays#copyOf instead
  44. String[] combined = new String[extraFragments.length + graphicsFragments.length];
  45. System.arraycopy(graphicsFragments, 0, combined, 0, graphicsFragments.length);
  46. System.arraycopy(extraFragments, 0, combined, graphicsFragments.length,
  47. extraFragments.length);
  48. return dragInto(dragBounds, dragPoint, secondDragPoint, insertIndex,
  49. currentIndex, combined);
  50. }
  51. /* This needs to be updated for the new interaction
  52. public void testDropTopEdge() {
  53. // If we drag right into the button itself, not a valid drop position
  54. INode inserted = dragInto(
  55. new Rect(0, 0, 105, 80), new Point(30, -10), null, 2, -1,
  56. // Bounds rectangle
  57. "useStyle(DROP_RECIPIENT), drawRect(Rect[0,0,240,480])",
  58. // Preview line + drop zone rectangle along the top
  59. "useStyle(DROP_ZONE), drawRect(Rect[0,-10,240,20])",
  60. "useStyle(DROP_ZONE_ACTIVE), fillRect(Rect[0,-10,240,20])",
  61. "useStyle(DROP_PREVIEW), drawLine(0,0,240,0)",
  62. // Tip
  63. "useStyle(HELP), drawBoxedStrings(5,15,[alignParentTop])",
  64. // Drop preview
  65. "useStyle(DROP_PREVIEW), drawRect(Rect[0,0,105,80])");
  66. assertEquals("true", inserted.getStringAttr(ANDROID_URI,
  67. "layout_alignParentTop"));
  68. }
  69. public void testDropZones() {
  70. List<Pair<Point,String[]>> zones = new ArrayList<Pair<Point,String[]>>();
  71. zones.add(Pair.of(new Point(51+10, 181+10),
  72. new String[] {"above=@+id/Centered", "toLeftOf=@+id/Centered"}));
  73. zones.add(Pair.of(new Point(71+10, 181+10),
  74. new String[] {"above=@+id/Centered", "alignLeft=@+id/Centered"}));
  75. zones.add(Pair.of(new Point(104+10, 181+10),
  76. new String[] {"above=@+id/Centered", "alignRight=@+id/Centered"}));
  77. zones.add(Pair.of(new Point(137+10, 181+10),
  78. new String[] {"above=@+id/Centered", "alignRight=@+id/Centered"}));
  79. zones.add(Pair.of(new Point(170+10, 181+10),
  80. new String[] {"above=@+id/Centered", "toRightOf=@+id/Centered"}));
  81. zones.add(Pair.of(new Point(51+10, 279+10),
  82. new String[] {"below=@+id/Centered", "toLeftOf=@+id/Centered"}));
  83. zones.add(Pair.of(new Point(71+10, 279+10),
  84. new String[] {"below=@+id/Centered", "alignLeft=@+id/Centered"}));
  85. zones.add(Pair.of(new Point(104+10, 279+10),
  86. new String[] {"below=@+id/Centered", "alignLeft=@+id/Centered"}));
  87. zones.add(Pair.of(new Point(137+10, 279+10),
  88. new String[] {"below=@+id/Centered", "alignRight=@+id/Centered"}));
  89. zones.add(Pair.of(new Point(170+10, 279+10),
  90. new String[] {"below=@+id/Centered", "toRightOf=@+id/Centered"}));
  91. zones.add(Pair.of(new Point(51+10, 201+10),
  92. new String[] {"toLeftOf=@+id/Centered", "alignTop=@+id/Centered"}));
  93. zones.add(Pair.of(new Point(51+10, 227+10),
  94. new String[] {"toLeftOf=@+id/Centered", "alignTop=@+id/Centered"}));
  95. zones.add(Pair.of(new Point(170+10, 201+10),
  96. new String[] {"toRightOf=@+id/Centered", "alignTop=@+id/Centered"}));
  97. zones.add(Pair.of(new Point(51+10, 253+10),
  98. new String[] {"toLeftOf=@+id/Centered", "alignBottom=@+id/Centered"}));
  99. zones.add(Pair.of(new Point(170+10, 227+10),
  100. new String[] {"toRightOf=@+id/Centered", "alignTop=@+id/Centered",
  101. "alignBottom=@+id/Centered"}));
  102. zones.add(Pair.of(new Point(170+10, 253+10),
  103. new String[] {"toRightOf=@+id/Centered", "alignBottom=@+id/Centered"}));
  104. for (Pair<Point,String[]> zonePair : zones) {
  105. Point dropPoint = zonePair.getFirst();
  106. String[] attachments = zonePair.getSecond();
  107. // If we drag right into the button itself, not a valid drop position
  108. INode inserted = dragInto(
  109. new Rect(0, 0, 105, 80), new Point(120, 240), dropPoint, 1, -1,
  110. attachments,
  111. // Bounds rectangle
  112. "useStyle(DROP_RECIPIENT), drawRect(Rect[0,0,240,480])",
  113. // Drop zones
  114. "useStyle(DROP_ZONE), "
  115. + "drawRect(Rect[51,181,20,20]), drawRect(Rect[71,181,33,20]), "
  116. + "drawRect(Rect[104,181,33,20]), drawRect(Rect[137,181,33,20]), "
  117. + "drawRect(Rect[170,181,20,20]), drawRect(Rect[51,279,20,20]), "
  118. + "drawRect(Rect[71,279,33,20]), drawRect(Rect[104,279,33,20]), "
  119. + "drawRect(Rect[137,279,33,20]), drawRect(Rect[170,279,20,20]), "
  120. + "drawRect(Rect[51,201,20,26]), drawRect(Rect[51,227,20,26]), "
  121. + "drawRect(Rect[51,253,20,26]), drawRect(Rect[170,201,20,26]), "
  122. + "drawRect(Rect[170,227,20,26]), drawRect(Rect[170,253,20,26])");
  123. for (String attachment : attachments) {
  124. String[] elements = attachment.split("=");
  125. String name = "layout_" + elements[0];
  126. String value = elements[1];
  127. assertEquals(value, inserted.getStringAttr(ANDROID_URI, name));
  128. }
  129. }
  130. }
  131. public void testDragInvalid() {
  132. // If we drag right into the button itself, not a valid drop position
  133. dragInto(new Rect(70, 200, 100, 80), new Point(120, 240), new Point(120, 240), -1, 0,
  134. // Bounds rectangle
  135. "useStyle(DROP_RECIPIENT), drawRect(Rect[0,0,240,480])",
  136. // Invalid marker
  137. "useStyle(INVALID), fillRect(Rect[70,200,100,80]), drawLine(70,200,170,280), "
  138. + "drawLine(70,280,170,200)");
  139. }
  140. // TODO: Test error (dragging on ancestor)
  141. */
  142. }