History log of /sdk/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/RelativeLayoutConversionHelper.java
Revision Date Author Comments
12d4581faa6438941e65a9dc83213be34c6ca970 13-Sep-2012 Tor Norbye <tnorbye@google.com> Constants refactoring.

This changeset moves most constants into the SdkConstants
class, and gets rid of AndroidConstants and LintConstants.
It also migrates all non-ADT specific constants from
AdtConstants into SdkConstants. It furthermore moves various
other constants (such as those in XmlUtils and ValuesDescriptors)
into the constants class. It also fixes the modifier order
to be the canonical modifier order (JLS 8.x).

Finally, it removes redundancy and combines various constant
aliases such that we don't have both NAME_ATTR and ATTR_NAME
pointing to "name", etc.

Change-Id: Ifd1755016f62ce2dd80e5c76130d6de4b0e32161
85e4a1a9dd133abb879ec211ce8dd385004edf22 08-Aug-2012 Xavier Ducrohet <xav@android.com> Refactor common.jar

Move resources and com.android.util.Pair into layoutlib_api
where they belong since layoutlib depends on them and we need
to control the API.

Made a copy of Pair to stay in common.jar but moved it to
com.android.utils.Pair (the one in com.android.util.Pair is
marked as deprecated to prevent usage where applicable).

Also moved XmlUtil and PositionXmlParser to com.android.utils
to match Pair.

Change-Id: I21d7057d3f2ce604f86a3bb1fa3c130948c93b89
a881b0b34678ad76c9f5eba62fac7a00a22ac606 20-May-2012 Tor Norbye <tnorbye@google.com> Move XML code to the common library

The ManifestMerger library needs to look up the prefix to use for the
Android namespace, and the Document.lookupPrefix method is not
implemented by the Eclipse DOM implementation (which throws an
exception). However, we have an implementation of this in the ADT
plugin.

This changeset creates a new XmlUtils class in the common/ library
(which is accessible by both ADT and the manifest merger, and the
anttasks where the manifest merger is used), and moves the namespace
prefix lookup code in there. It also moves the XML escape methods
into that class. It also adds a new method to the ManifestMerger for
merging directly from documents (rather than files), and makes sure
that all the merging code goes via the prefix utility method rather
than calling the document.lookupPrefix method.

Finally, it moves the various string constants associated with XML
namespaces into the single XmlUtils class, since these were spread
across several different classes before (and many of them are needed
in the XmlUtils class).

The vast majority of the diffs in this changeset are related to simple
import statement changes to reflect the new locations of these
constants.

Change-Id: Ib8f3d0e5c89e47e61ea509a23925af7b6580abee
ab36f4e7488358dea4ab6b54ee2b7bef3da0232b 21-Dec-2011 Tor Norbye <tnorbye@google.com> Update SDK codebase to JDK 6

This changeset makes the SDK codebase compile with source=1.6 (which
means it also requires JDK 6). This means that methods implementing an
interface requires @Override's. It also means we can start using APIs
like the ArrayDeque class and methods like String#isEmpty().

This changeset looks big but the change is trivial: it's basically
adding @Override in all the places that need it, along with some other
automatic Eclipse cleanup in certain files (such as reordering imports
where they were incorrectly ordered (because older versions of Eclipse
didn't always handle inner classes right)), as well as cleaning up
trailing whitespace and removing some $NON-NLS-1$ markers on lines
where there aren't any string literals anymore.

This changeset also sets the source and target JDK level to 6 in the
Eclipse compiler .settings file, and synchronizes this file to all the
other Eclipse SDK projects.

Change-Id: I6a9585aa44c3dee9a5c00739ab22fbdbcb9f8275
fadd53c9ef6d046a60919e89eed1380696b67b7a 21-Oct-2011 Tor Norbye <tnorbye@google.com> Misc GridLayout handling fixes

This changeset fixes some miscellaneous in the GridLayout support.

The gravity handling code (which creates a bitmask for gravity from
XML attribute values) was pulled out of the change layout refactoring
such that it can also be used by the GridLayout. This is done to
figure out where cells are not bound to the top or left corners, in
which case they should not be considered when computing a suitable
right or bottom edge for splitting a cell.

There's also fixes for a problem where certain negative constraints
would be offered, there were tooltips when only one of the two
dimensions produced suggestions (and you can only drop when both are
valid).

When removing children back to a blank layout, reset the columCount
to 2.

And finally there were some problems where the columnCount was larger
than the number of actual used columns in the table, where dragging
near top/left corner would use some of the later columns rather than
the first available one.

Change-Id: Ice22754fb14659812b54019452aeca6daaeede10
8a06163380b3df70071df08a17f2f8c2aa77513c 07-Sep-2011 Tor Norbye <tnorbye@google.com> Cherrypick 4cd282 from master. do not merge.

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: Ifaca43458a4961fa032dfe22dc033b6def3c38d3
4cd282c7b21dc06c2d2d02748278f07c94282fc1 07-Sep-2011 Tor Norbye <tnorbye@google.com> 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
78d3947aeebf2d8c0d17fe35d0fd94e53013b60e 07-Sep-2011 Tor Norbye <tnorbye@google.com> 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
b3ab7ef8a24a64bcd6f347e8e03bc647c12eb24b 29-Aug-2011 Tor Norbye <tnorbye@google.com> A few warnings fixes

Change-Id: Ie230236444a5e1288d98feea208df5ce6508803d
f5256a38ef2e429b5efd4482808bc902bf7634e3 23-Aug-2011 Tor Norbye <tnorbye@google.com> Misc refactoring and test fixes

This changeset turns on automatic formatting of the affected regions
in extract include, change layout, wrap in and style refactorings.

It also fixes a couple of minor bugs - one handling empty tags in the
change widget type refactoring, and one handling selection offsets.

It also turns on automatic formatting of GUI editor changes (there was
a previous changeset which prepared for this but forgot to actually
switch the default option.)

This changeset also makes various test infrastructure fixes: code
completion tests recently stopped working for a number of files
(something about the initialization order of editor types when running
as tests). I also tweaked the goldenfile format of the diffs to avoid
trailing diffs on lines with just a ">" or "<" since gerrit makes thee
light up in red.

Change-Id: I78b858f0b21e5b2f25a9566ad495bad09c66a18f
fb49439a6128d6812558d5089f9a4767cd4e3cc0 18-Aug-2011 Tor Norbye <tnorbye@google.com> Add Unwrap Refactoring

This changeset adds a new visual refactoring: "Remove Container". This
is basically the reverse of the "Wrap In" refactoring (which surrounds
the selected views with a new parent layout). Instead it takes a
parent and removes it, in the process transferring the namespace
declaration (if a root element) and any layout params to the children.

Change-Id: Id535b88fcf39a8b7a83fd6feb981fff000140e8a
42b2f34604a3f8e8ac191831d8f01a0498760d38 09-Jun-2011 Tor Norbye <tnorbye@google.com> Fix various warnings

I ran the latest version of findbugs on our codebase and fixed some
(not all!) of the warnings.

I also ran with Eclipse 3.7 RC3 and updated our compiler warning
settings for the new warnings that are available.

I also fixed some DOS line endings in some files (formatted with CRLF
instead of LF).

Change-Id: I9a9d34a9b60f2cb609245793815d96a4587007b0
bfe50d0630041bbc3e3b2b5182d18e139f2879bf 15-Mar-2011 Tor Norbye <tnorbye@google.com> XML code completion improvements

This changeset contains a number of improvements to the code
completion in XML files.

(1) Add suffix completion in attribute values. For dimensional
attributes, this will add in (or complete prefixes of) units like
"dp", "sp", etc. For fractional attributes, the % and %p suffixes
are completed. (In both cases, there is also a tooltip message
provided shown in the completion documentation popup). In
addition, for flag values, when completing at the end of a flag,
then the separator character (|) along with the other flag values
(except those already set) are offered.

(2) Handle completion when the caret is not at the end. For example,
if you have the following source:

layout_w^idth="wrap_content" (^ = caret position)

then if you invoke code completion you will also be offered the
attribute layout_weight, and selecting it will -replace- the
layout_width attribute with layout_height, it will not insert
layout_weight in the middle of layout_width. This handling is done
not just for attribute names as shown here but for attribute
values and element tag names as well.

(3) Improve @resource/ completion sorting. When completing resources,
consider which attribute is being completed, and use that
information to sort the resources. For example, if completing a
"text" attribute then @string/, and @android:string/ resources
will be listed first. For attributes like margins @dimen will be
first, for include layout the @layout attributes will be listed
first, and so on. Also, the resources are sorted alphabetically
as the second sort key.

(4) Hide some builtin Eclipse code completion items. In particular,
the default code completion provider for Eclipse will always add
the current attribute value as a completion. This is extremely
confusing since if you have a typo, code completion will tell you
that what you have is okay. I personally witnessed this confusing
a user who had typed something from memory and code completion
seemed to him to "confirm" that he had it right.

To fix this, the code which installs completion providers, will
identify the builting WST completion provider, and when found,
replace it with a "filtering" wrapper. This completion provider
delegates all its calls to the WST completion provider, but it
recognizes a few patterns, in particular the above attribute value
completion proposal as well as some namespace and schema ones, and
removes these.

(The reason we only filter out these items instead of removing it
completely is that the completion provider also appears to be
responsible for inserting code templates defined by the user, and
we don't want to neuter those if defined by the user.)

(5) Fix a bunch of corner cases - flags could only have a single
separator (|), resource attribute completion items were missing
icons, and completion in some positions was not working.

(6) Unit tests. There are now comprehensive unit tests for code
completion. Each unit test points to a particular source file
and a particular position within the source file, and code completion
is invoked for that position. A set of unit tests dump out the
allowed completion items for each such position, and these are
compared against golden files. A second set of unit tests then
specify a particular code completion item among the choices to
be applied, and then applies that completion item to the document.
This, along with the caret position (indicated as ^) is written
into a golden file and used for comparisons. To make it easy
to see what these tests do, the golden file is actually recorded
as a diff, so in the test you will see something like this:

Code completion in completion1.xml for android:gravity="left|b^ottom"
selecting bottom:
< android:gravity="left|bottom"
---
> android:gravity="left|bottom^"

(6) There are some other misc changes. We had some code which used
"dip" for device indepdendent pixels (such as the AbsoluteLayout
handler). Since "dp" seems to be preferred, the code will now
use that instead.

Change-Id: I8bd5c8336d8747dac1f10a9269ea4197f304cb70
9e6db060854d0e890190919a27a1846f50f69d1a 07-Mar-2011 Tor Norbye <tnorbye@google.com> Extract as Include support for configuration variations

First, add support for the "Extract as Include" refactoring to update
all identical code fragments in configuration variations of the same
file. For example, if you have a particular subtree of XML elements
in a file that you have then duplicated into say a landscape mode,
then applying the Extract as Include refactoring will locate the same
code fragment in both files, and replace *both* code fragments with an
include (and this is optional with a checkbox in the wizard
dialog). This only happens when the extracted code fragment is
"identical" in both files. The code fragments can vary in terms of XML
formatting and attribute order (and namespace prefix choice), but the
element hierarchy order, names, attributes defined and attribute
values must be identical.

Second, make fixes to the Change Layout and Change Widget Type
refactorings such that when the id of the converted element is
changed, then references to that id are updated as well.

Third, ensure that the refactorings are enabled even when there is no
text selection; in that case the refactoring will apply to the element
containing the caret.

Some test infrastructure improvements.

Change-Id: Idb4ba40f4217dba2b13881b3d06e269c80ba4b97
0757ce4af2764e4dd564acc0b1a013e910abc8da 18-Feb-2011 Tor Norbye <tnorbye@google.com> More refactoring work: Convert hierarchy, and change type

A lot of work on the "Change Layout" refactoring to improve conversion
to a Relative Layout. First, add a "Flatten Hierarchy" option which
can take an entire hierarchy of layout widgets and flatten it down to
a single top level RelativeLayout where the constraints attempt to
reflect the original layout. (This isn't always possible, since some
layout managers offer features not possible to express in
RelativeLayout, such as a LinearLayout with multiple different
weights) but it often works or is at least a good start. (This work
is ongoing, but since my changeset is getting large I want to check in
this snapshot since the functionality is better than what is in the
trunk.)

This changeset also adds a new refactoring: Change Widget Type. This
can be applied to a selection of elements, and it will convert the
widget type to the new target widget type. It will also remove any
attributes that are not valid for the new layout.

It also improves the wizards which display the possible target types.
For Change Widget Type, it will first offer "related" widgets, so for
an AnalogClock it will first offer Digital Clock, for a checkbox it
will offer a checked text view and a radio button, etc.

In addition, it will list Views and Layouts that it finds in any
library jars (except for the builtin Android ones), and any custom
view classes in the project.

There is also now some preliminary support for refactoring unit
tests. These tests must be run as Eclipse plugin tests, since they
utilize the XML model (and the XML model cannot be mocked). The test
infrastructure reads source XML files, applies the refactoring change
list to them, and diffs the output with the known expected output
(also stored as result XML files in the test project).

Finally, there are a number of fixes and improvements to the shared
refactoring code.

Change-Id: I0974653e530dfb4feb625e0eef8257c29d50614b