diff options
author | Tor Norbye <tnorbye@google.com> | 2011-09-07 11:28:54 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2011-09-28 16:15:25 -0700 |
commit | 4cd282c7b21dc06c2d2d02748278f07c94282fc1 (patch) | |
tree | 02096910dedd4f271e87426d63548cb0b588415b /eclipse/plugins/com.android.ide.eclipse.tests | |
parent | fc0cd95e9802d56b35331cb337c04e6dc29d4eff (diff) | |
download | sdk-4cd282c7b21dc06c2d2d02748278f07c94282fc1.zip sdk-4cd282c7b21dc06c2d2d02748278f07c94282fc1.tar.gz sdk-4cd282c7b21dc06c2d2d02748278f07c94282fc1.tar.bz2 |
Grid Layout and Convert to Grid Layout improvements
First, some improvements to Grid Layout handling:
(1) When dropping a new widget, look up the sizing metadata and use it
to determine what fill gravity to set. For example, a button will
use gravity left, and a text field will use gravity
fill_horizontal.
(2) Don't warn about reflection problems when failing to find
GridLayout layout data; this probably means the layout is being
attempted opened in an unsupporting SDK. There's a fallback case
to compute the data instead already.
Second, improvements to the conversion to GridLayout handling:
(1) It now looks at the layout_gravity values to see whether each row
and column is flexible, and if there's no flexible column in each
of the horizontal and vertical dimensions, it will insert a
special <Space> element to absorb any available extra space. This
avoids constraints warnings from GridLayout.
(2) It treats layout_width or layout_height attributes of match_parent
or fill_parent as the same as a fill gravity (and removes it) and
uses this in the flexibility computation above.
(3) It removes unsupported layout params for all children (earlier
this would only remove unsupported layout params on the direct
children of the layout, which isn't enough when a hierarchy is
being flattened.)
(4) It's smarter about computing implicit rows and columns, so it
avoids writing out redundant layout_row and layout_column
attributes in some cases.
(5) It avoids throwing refactoring errors in cases where an attribute
is removed twice
(6) Fixes a bug where the root layout was included when computing the
set of used x and y coordinates, which means you'd often end up
with a blank row and column 0.
(7) Various refactoring to make the code cleaner.
(8) More unit tests and updates to existing unit tests to reflect the
new behavior such as an absorbing spacer and removal of redundant
attributes.
Change-Id: Iee44c3ca749eefc107b83545669cc9d7f84615b1
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.tests')
8 files changed, 204 insertions, 11 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 5236dc2..bcbf461 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 @@ -98,6 +98,10 @@ public class ChangeLayoutRefactoringTest extends RefactoringTest { checkRefactoring(FQCN_LINEAR_LAYOUT, "sample10.xml", true, "android:orientation=vertical"); } + public void testInsertSpacer() throws Exception { + checkRefactoring(FQCN_GRID_LAYOUT, "sample11.xml", true); + } + private void checkRefactoring(String newLayoutType, String basename, boolean flatten) throws Exception { checkRefactoring(newLayoutType, basename, flatten, null); diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample11-expected-insertSpacer.xml b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample11-expected-insertSpacer.xml new file mode 100644 index 0000000..d10626a --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample11-expected-insertSpacer.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright 2010 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/home_root" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:columnCount="3" + android:orientation="horizontal" > + + <Button + android:layout_gravity="fill_horizontal" + android:layout_weight="1" /> + + <Button + android:layout_gravity="fill_horizontal" + android:layout_weight="1" /> + + <Button + android:layout_column="0" + android:layout_gravity="fill_horizontal" + android:layout_weight="1" + android:gravity="center_horizontal" /> + + <Button + android:layout_gravity="fill_horizontal" + android:layout_weight="1" + android:gravity="center_horizontal" /> + + <Button + android:layout_column="0" + android:layout_gravity="fill_horizontal" + android:layout_weight="1" + android:gravity="center_horizontal" /> + + <Button + android:layout_gravity="fill_horizontal" + android:layout_weight="1" + android:gravity="center_horizontal" /> + + <Space + android:layout_column="2" + android:layout_gravity="fill_vertical" + android:layout_row="3" /> + +</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/sample11.info b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample11.info new file mode 100644 index 0000000..560e8a8 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample11.info @@ -0,0 +1,11 @@ +android.widget.LinearLayout [0,50,480,320] <LinearLayout> + android.widget.LinearLayout [0,0,480,270] <LinearLayout> + android.widget.LinearLayout [6,6,474,92] <LinearLayout> + android.widget.Button [0,19,234,67] <Button> + android.widget.Button [234,19,468,67] <Button> + android.widget.LinearLayout [6,92,474,178] <LinearLayout> + android.widget.Button [0,19,234,67] <Button> + android.widget.Button [234,19,468,67] <Button> + android.widget.LinearLayout [6,178,474,264] <LinearLayout> + android.widget.Button [0,19,234,67] <Button> + android.widget.Button [234,19,468,67] <Button> diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample11.xml b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample11.xml new file mode 100644 index 0000000..4df91a1 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/sample11.xml @@ -0,0 +1,92 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright 2010 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/home_root" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:orientation="vertical" > + + <LinearLayout + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_weight="1" + android:orientation="vertical" + android:padding="6dip" > + + <LinearLayout + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_weight="1" + android:orientation="horizontal" > + + <Button + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:layout_weight="1" /> + + <Button + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:layout_weight="1" /> + </LinearLayout> + + <LinearLayout + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_weight="1" + android:orientation="horizontal" > + + <Button + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:layout_weight="1" + android:gravity="center_horizontal" /> + + <Button + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:layout_weight="1" + android:gravity="center_horizontal" /> + </LinearLayout> + + <LinearLayout + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_weight="1" + android:orientation="horizontal" > + + <Button + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:layout_weight="1" + android:gravity="center_horizontal" /> + + <Button + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:layout_weight="1" + android:gravity="center_horizontal" /> + </LinearLayout> + </LinearLayout> + +</LinearLayout> 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 a5cbc35..72fe214 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 @@ -3,40 +3,45 @@ android:id="@+id/GridLayout1" android:layout_width="match_parent" android:layout_height="match_parent" - android:columnCount="3" + android:columnCount="4" android:orientation="horizontal" > <Button android:id="@+id/button1" + android:layout_gravity="left" android:text="FirstButton" > </Button> <Button android:id="@+id/button2" android:layout_column="0" - android:layout_row="1" + android:layout_gravity="left" android:text="SecondButton" > </Button> <Button android:id="@+id/button3" + android:layout_gravity="left" android:text="ThirdButton" > </Button> <CheckBox android:id="@+id/checkBox1" + android:layout_gravity="left" android:text="CheckBox" > </CheckBox> <Button android:id="@+id/button4" - android:layout_width="match_parent" + android:layout_column="0" android:layout_columnSpan="3" + android:layout_gravity="fill_horizontal" android:text="FourthButton" > </Button> <Button android:id="@+id/button5" + android:layout_column="0" android:layout_gravity="right" android:text="FifthButton" > </Button> @@ -44,8 +49,13 @@ <Button android:id="@+id/button6" android:layout_column="0" - android:layout_row="4" + android:layout_gravity="left" android:text="Button" > </Button> + <Space + android:layout_column="3" + android:layout_gravity="fill_vertical" + android:layout_row="5" /> + </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/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 40031a6..8b90562 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 @@ -3,12 +3,13 @@ android:id="@+id/GridLayout1" android:layout_width="match_parent" android:layout_height="match_parent" - android:columnCount="5" + android:columnCount="6" android:orientation="horizontal" > <Button android:id="@+id/button1" android:layout_columnSpan="2" + android:layout_gravity="left" android:text="Button" > </Button> @@ -17,13 +18,14 @@ android:layout_alignParentLeft="true" android:layout_column="0" android:layout_columnSpan="2" - android:layout_row="1" + android:layout_gravity="left" android:text="Button" > </Button> <Button android:id="@+id/button3" android:layout_below="@+id/button2" + android:layout_gravity="left" android:layout_row="2" android:layout_toRightOf="@+id/button2" android:text="Button" > @@ -32,6 +34,7 @@ <Button android:id="@+id/button4" android:layout_below="@+id/button3" + android:layout_gravity="left" android:layout_row="3" android:layout_toRightOf="@+id/button3" android:text="Button" > @@ -42,7 +45,7 @@ android:layout_below="@+id/button4" android:layout_column="1" android:layout_columnSpan="2" - android:layout_row="4" + android:layout_gravity="left" android:layout_toLeftOf="@+id/button4" android:text="CheckBox" > </CheckBox> @@ -51,8 +54,14 @@ android:id="@+id/button5" android:layout_alignParentRight="true" android:layout_column="4" + android:layout_gravity="left" android:layout_row="1" android:text="Button" > </Button> + <Space + android:layout_column="5" + android:layout_gravity="fill_vertical" + android:layout_row="5" /> + </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/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 09f8d36..dd9f18c 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,7 +8,6 @@ <Button android:id="@+id/button1" - android:layout_column="2" android:layout_columnSpan="2" android:layout_gravity="center_horizontal" android:text="Button" > @@ -16,9 +15,9 @@ <Button android:id="@+id/button2" - android:layout_column="2" android:layout_columnSpan="2" android:layout_gravity="center" + android:layout_row="1" 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 index 15f1c3b..03ffac7 100644 --- 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 @@ -3,26 +3,35 @@ android:id="@+id/GridLayout1" android:layout_width="match_parent" android:layout_height="match_parent" - android:columnCount="2" + android:columnCount="3" android:orientation="horizontal" > <Button android:id="@+id/button1" + android:layout_gravity="left" android:text="Button" /> <RadioButton android:id="@+id/radioButton1" android:layout_width="150dp" android:layout_column="0" - android:layout_row="1" + android:layout_gravity="left" android:text="RadioButton" /> <RadioButton android:id="@+id/radioButton2" + android:layout_gravity="left" android:text="RadioButton" /> <CheckBox android:id="@+id/checkBox1" + android:layout_column="0" + android:layout_gravity="left" android:text="CheckBox" /> + <Space + android:layout_column="2" + android:layout_gravity="fill_vertical" + android:layout_row="3" /> + </GridLayout>
\ No newline at end of file |