Home | History | Annotate | Download | only in layout
      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 com.android.ide.common.api.INode;
     20 import com.android.ide.common.api.Point;
     21 import com.android.ide.common.api.Rect;
     22 
     23 /** Test the {@link FrameLayoutRule} */
     24 public class FrameLayoutRuleTest extends LayoutTestBase {
     25     // Utility for other tests
     26     protected void dragInto(Rect dragBounds, Point dragPoint, int insertIndex, int currentIndex,
     27             String... graphicsFragments) {
     28         INode layout = TestNode.create("android.widget.FrameLayout").id("@+id/FrameLayout01")
     29                 .bounds(new Rect(0, 0, 240, 480)).add(
     30                         TestNode.create("android.widget.Button").id("@+id/Button01").bounds(
     31                                 new Rect(0, 0, 100, 80)),
     32                         TestNode.create("android.widget.Button").id("@+id/Button02").bounds(
     33                                 new Rect(0, 100, 100, 80)),
     34                         TestNode.create("android.widget.Button").id("@+id/Button03").bounds(
     35                                 new Rect(0, 200, 100, 80)),
     36                         TestNode.create("android.widget.Button").id("@+id/Button04").bounds(
     37                                 new Rect(0, 300, 100, 80)));
     38 
     39         super.dragInto(new FrameLayoutRule(), layout, dragBounds, dragPoint, null,
     40                 insertIndex, currentIndex, graphicsFragments);
     41     }
     42 
     43     public void testDragMiddle() {
     44         dragInto(
     45         // Bounds of the dragged item
     46                 new Rect(0, 0, 105, 80),
     47                 // Drag point
     48                 new Point(30, -10),
     49                 // Expected insert location: We just append in absolute layout
     50                 4,
     51                 // Not dragging one of the existing children
     52                 -1,
     53                 // Bounds rectangle
     54                 "useStyle(DROP_RECIPIENT), drawRect(Rect[0,0,240,480])",
     55 
     56                 // Drop Preview
     57                 "useStyle(DROP_PREVIEW), drawRect(0,0,105,80)");
     58         // Without drag bounds we should just draw guide lines instead
     59         dragInto(new Rect(0, 0, 0, 0), new Point(30, -10), 4, -1,
     60                 "useStyle(DROP_RECIPIENT), drawRect(Rect[0,0,240,480])",
     61                 "useStyle(DROP_PREVIEW), drawLine(1,0,1,480), drawLine(0,1,240,1)");
     62     }
     63 }
     64