diff options
author | Tor Norbye <tnorbye@google.com> | 2011-09-07 07:46:54 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2011-09-07 07:52:27 -0700 |
commit | 78d3947aeebf2d8c0d17fe35d0fd94e53013b60e (patch) | |
tree | 721b7ecbb9291fd88b4f97e30f8b5b82e4040a1e /eclipse/plugins/com.android.ide.eclipse.tests | |
parent | 007841f608852cc428bd4d1fe07c92275bf86b7d (diff) | |
download | sdk-78d3947aeebf2d8c0d17fe35d0fd94e53013b60e.zip sdk-78d3947aeebf2d8c0d17fe35d0fd94e53013b60e.tar.gz sdk-78d3947aeebf2d8c0d17fe35d0fd94e53013b60e.tar.bz2 |
Add/Remove wrap_content when converting GridLayouts
In GridLayout, the layout_width and layout_height attributes use
wrap_content by default. We already avoid setting these on the
elements themselves when dragging into the layout, but this changeset
makes the Change Layout refactoring remove wrap_content attributes
when converting to GridLayout, and adding them when converting from a
GridLayout.
When changing layouts, any layout params that are supported on the old
parent layout, but not the new layout, are removed. However, this was
not done for the non-layout attributes on the parent layout. This
changeset also fixes that bug, so for example after converting a
horizontal LinearLayout to a RelativeLayout, the "orientation"
attribute is removed.
Change-Id: Id25b80b567578bd5882c527bbe23115577ff7d61
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.tests')
10 files changed, 148 insertions, 37 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeLayoutRefactoringTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeLayoutRefactoringTest.java index ff2f78a..8b825ad 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeLayoutRefactoringTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/ChangeLayoutRefactoringTest.java @@ -16,6 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout.refactoring; import static com.android.ide.common.layout.LayoutConstants.FQCN_GRID_LAYOUT; +import static com.android.ide.common.layout.LayoutConstants.FQCN_LINEAR_LAYOUT; import static com.android.ide.common.layout.LayoutConstants.FQCN_RELATIVE_LAYOUT; import com.android.ide.eclipse.adt.internal.editors.layout.gle2.CanvasViewInfo; @@ -28,6 +29,7 @@ import org.w3c.dom.Element; import java.util.Collections; import java.util.List; +@SuppressWarnings("javadoc") public class ChangeLayoutRefactoringTest extends RefactoringTest { public void testChangeLayout1a() throws Exception { @@ -80,6 +82,14 @@ public class ChangeLayoutRefactoringTest extends RefactoringTest { checkRefactoring(FQCN_GRID_LAYOUT, "sample5.xml", true); } + public void testConvertToGrid() throws Exception { + checkRefactoring(FQCN_GRID_LAYOUT, "sample9.xml", true); + } + + public void testConvertFromGrid() throws Exception { + checkRefactoring(FQCN_LINEAR_LAYOUT, "sample10.xml", true); + } + private void checkRefactoring(String basename, boolean flatten) throws Exception { checkRefactoring(FQCN_RELATIVE_LAYOUT, basename, flatten); } diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample10-expected-convertFromGrid.xml b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample10-expected-convertFromGrid.xml new file mode 100644 index 0000000..faa95d7 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample10-expected-convertFromGrid.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/LinearLayout1" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="horizontal" > + + <Button + android:id="@+id/button1" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Button" /> + + <RadioButton + android:id="@+id/radioButton1" + android:layout_width="150dp" + android:layout_height="wrap_content" + android:text="RadioButton" /> + + <RadioButton + android:id="@+id/radioButton2" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="RadioButton" /> + + <CheckBox + android:id="@+id/checkBox1" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="CheckBox" /> + +</LinearLayout>
\ No newline at end of file diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample10.info b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample10.info new file mode 100644 index 0000000..c964b0e --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample10.info @@ -0,0 +1,5 @@ +android.widget.GridLayout [0,73,320,480] <GridLayout> + android.widget.Button [0,0,79,48] <Button> + android.widget.RadioButton [0,48,150,86] <RadioButton> + android.widget.RadioButton [150,48,273,86] <RadioButton> + android.widget.CheckBox [0,86,107,124] <CheckBox> diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample10.xml b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample10.xml new file mode 100644 index 0000000..1fcaab5 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample10.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/GridLayout1" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:columnCount="2" + android:orientation="horizontal" > + + <Button + android:id="@+id/button1" + android:text="Button" /> + + <RadioButton + android:id="@+id/radioButton1" + android:layout_width="150dp" + android:layout_column="0" + android:layout_row="1" + android:text="RadioButton" /> + + <RadioButton + android:id="@+id/radioButton2" + android:text="RadioButton" /> + + <CheckBox + android:id="@+id/checkBox1" + android:text="CheckBox" /> + +</GridLayout> diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample1a-expected-gridLayout1.xml b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample1a-expected-gridLayout1.xml index 89932a5..a5cbc35 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample1a-expected-gridLayout1.xml +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample1a-expected-gridLayout1.xml @@ -8,15 +8,11 @@ <Button android:id="@+id/button1" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:text="FirstButton" > </Button> <Button android:id="@+id/button2" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:layout_column="0" android:layout_row="1" android:text="SecondButton" > @@ -24,38 +20,29 @@ <Button android:id="@+id/button3" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:text="ThirdButton" > </Button> <CheckBox android:id="@+id/checkBox1" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:text="CheckBox" > </CheckBox> <Button android:id="@+id/button4" android:layout_width="match_parent" - android:layout_height="wrap_content" android:layout_columnSpan="3" android:text="FourthButton" > </Button> <Button android:id="@+id/button5" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:layout_gravity="right" android:text="FifthButton" > </Button> <Button android:id="@+id/button6" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:layout_column="0" android:layout_row="4" android:text="Button" > diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample2-expected-gridLayout2.xml b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample2-expected-gridLayout2.xml index bfd130a..40031a6 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample2-expected-gridLayout2.xml +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample2-expected-gridLayout2.xml @@ -8,16 +8,12 @@ <Button android:id="@+id/button1" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:layout_columnSpan="2" android:text="Button" > </Button> <Button android:id="@+id/button2" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_column="0" android:layout_columnSpan="2" @@ -27,8 +23,6 @@ <Button android:id="@+id/button3" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:layout_below="@+id/button2" android:layout_row="2" android:layout_toRightOf="@+id/button2" @@ -37,8 +31,6 @@ <Button android:id="@+id/button4" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:layout_below="@+id/button3" android:layout_row="3" android:layout_toRightOf="@+id/button3" @@ -47,8 +39,6 @@ <CheckBox android:id="@+id/checkBox1" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:layout_below="@+id/button4" android:layout_column="1" android:layout_columnSpan="2" @@ -59,8 +49,6 @@ <Button android:id="@+id/button5" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_column="4" android:layout_row="1" diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample5-expected-gridLayout5.xml b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample5-expected-gridLayout5.xml index 6625529..09f8d36 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample5-expected-gridLayout5.xml +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample5-expected-gridLayout5.xml @@ -8,8 +8,6 @@ <Button android:id="@+id/button1" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:layout_column="2" android:layout_columnSpan="2" android:layout_gravity="center_horizontal" @@ -18,8 +16,6 @@ <Button android:id="@+id/button2" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:layout_column="2" android:layout_columnSpan="2" android:layout_gravity="center" @@ -28,8 +24,6 @@ <Button android:id="@+id/button3" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:layout_column="2" android:layout_columnSpan="2" android:layout_gravity="right" @@ -38,16 +32,12 @@ <Button android:id="@+id/button4" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:layout_gravity="center" android:text="Button" > </Button> <Button android:id="@+id/button5" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:layout_columnSpan="2" android:layout_gravity="center_vertical" android:text="Button" > @@ -55,8 +45,6 @@ <Button android:id="@+id/button6" - android:layout_width="wrap_content" - android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="Button" > </Button> diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample9-expected-convertToGrid.xml b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample9-expected-convertToGrid.xml new file mode 100644 index 0000000..15f1c3b --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample9-expected-convertToGrid.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/GridLayout1" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:columnCount="2" + android:orientation="horizontal" > + + <Button + android:id="@+id/button1" + android:text="Button" /> + + <RadioButton + android:id="@+id/radioButton1" + android:layout_width="150dp" + android:layout_column="0" + android:layout_row="1" + android:text="RadioButton" /> + + <RadioButton + android:id="@+id/radioButton2" + android:text="RadioButton" /> + + <CheckBox + android:id="@+id/checkBox1" + android:text="CheckBox" /> + +</GridLayout>
\ No newline at end of file diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample9.info b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample9.info new file mode 100644 index 0000000..3085ff0 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample9.info @@ -0,0 +1,6 @@ +android.widget.LinearLayout [0,73,320,480] <LinearLayout> + android.widget.Button [0,0,79,48] <Button> + android.widget.LinearLayout [0,48,320,86] <LinearLayout> + android.widget.RadioButton [0,0,150,38] <RadioButton> + android.widget.RadioButton [150,0,273,38] <RadioButton> + android.widget.CheckBox [0,86,107,124] <CheckBox> diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample9.xml b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample9.xml new file mode 100644 index 0000000..13068e7 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample9.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/LinearLayout1" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" > + + <Button + android:id="@+id/button1" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Button" /> + + <LinearLayout + android:id="@+id/linearLayout2" + android:layout_width="match_parent" + android:layout_height="wrap_content" > + + <RadioButton + android:id="@+id/radioButton1" + android:layout_width="150dp" + android:layout_height="wrap_content" + android:text="RadioButton" /> + + <RadioButton + android:id="@+id/radioButton2" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="RadioButton" /> + + </LinearLayout> + + <CheckBox + android:id="@+id/checkBox1" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="CheckBox" /> + +</LinearLayout> |