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 17 package com.android.ide.common.layout; 18 19 import static com.android.SdkConstants.ANDROID_URI; 20 21 import com.android.ide.common.api.INode; 22 import com.android.ide.common.api.Point; 23 import com.android.ide.common.api.Rect; 24 25 /** Test the {@link AbsoluteLayoutRule} */ 26 public class AbsoluteLayoutRuleTest extends LayoutTestBase { 27 // Utility for other tests dragInto(Rect dragBounds, Point dragPoint, int insertIndex, int currentIndex, String... graphicsFragments)28 protected INode dragInto(Rect dragBounds, Point dragPoint, int insertIndex, int currentIndex, 29 String... graphicsFragments) { 30 INode layout = TestNode.create("android.widget.AbsoluteLayout").id("@+id/AbsoluteLayout01") 31 .bounds(new Rect(0, 0, 240, 480)).add( 32 TestNode.create("android.widget.Button").id("@+id/Button01").bounds( 33 new Rect(0, 0, 100, 80)), 34 TestNode.create("android.widget.Button").id("@+id/Button02").bounds( 35 new Rect(0, 100, 100, 80)), 36 TestNode.create("android.widget.Button").id("@+id/Button03").bounds( 37 new Rect(0, 200, 100, 80)), 38 TestNode.create("android.widget.Button").id("@+id/Button04").bounds( 39 new Rect(0, 300, 100, 80))); 40 41 return super.dragInto(new AbsoluteLayoutRule(), layout, dragBounds, dragPoint, null, 42 insertIndex, currentIndex, graphicsFragments); 43 } 44 testDragMiddle()45 public void testDragMiddle() { 46 INode inserted = dragInto( 47 // Bounds of the dragged item 48 new Rect(0, 0, 105, 80), 49 // Drag point 50 new Point(30, -10), 51 // Expected insert location: We just append in absolute layout 52 4, 53 // Not dragging one of the existing children 54 -1, 55 56 57 // Bounds rectangle 58 "useStyle(DROP_RECIPIENT), drawRect(Rect[0,0,240,480])", 59 60 // Drop preview 61 "useStyle(DROP_PREVIEW), drawRect(30,-10,135,70)"); 62 63 assertEquals("30dp", inserted.getStringAttr(ANDROID_URI, "layout_x")); 64 assertEquals("-10dp", inserted.getStringAttr(ANDROID_URI, "layout_y")); 65 66 // Without drag bounds we should just draw guide lines instead 67 inserted = dragInto(new Rect(0, 0, 0, 0), new Point(30, -10), 4, -1, 68 "useStyle(DROP_RECIPIENT), drawRect(Rect[0,0,240,480])", 69 // Guideline 70 "useStyle(GUIDELINE), drawLine(30,0,30,480), drawLine(0,-10,240,-10)", 71 // Drop preview 72 "useStyle(DROP_PREVIEW), drawLine(30,-10,240,-10), drawLine(30,-10,30,480)"); 73 assertEquals("30dp", inserted.getStringAttr(ANDROID_URI, "layout_x")); 74 assertEquals("-10dp", inserted.getStringAttr(ANDROID_URI, "layout_y")); 75 } 76 77 } 78