History log of /sdk/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/ResourceHelper.java
Revision Date Author Comments
6ecbb8e46bcb264b08aafa8c5c1f4692578170ed 21-Sep-2013 Tor Norbye <tnorbye@google.com> Use the new ResourceUrl API in sdk-common

Change-Id: I50154323e4db659d0d29753076bae805c7fc6c7d
b5b78c0ae5fb49867e9e4458bd95d7a60baf0eca 06-Dec-2012 Tor Norbye <tnorbye@google.com> Support layout aliases properly

Change-Id: I3c1dac7809a225118b69f1557a42051e96011198
d09b8a2d6ce570cc81ec6678b07f40541f4657f4 29-Nov-2012 Xavier Ducrohet <xav@android.com> Add support for layout dir qualifiers.

Change-Id: I6da728d079975fa19f1ae816fa585031a9c6fe75
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
81cefe2a26dd6db8a878e30874d12cdcbff0e83b 11-Aug-2012 Xavier Ducrohet <xav@android.com> More refactoring.

Move stuff out of sdklib into common and ide_common.
Remove androidprefs and move the one class into common.

Change-Id: I71d126a13cf2ba413692e29616f4968a37d7b33a
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
fd31ed423c9f5b739ec3d7bf259adbd0eb0182c0 07-Aug-2012 Tor Norbye <tnorbye@google.com> Catch exceptions during class initialization.

This primarily fixes running various unit tests that are
accessing this class (to test static methods) but fail
because class initialization looking for icons fails
when not running as a plugin test.

Change-Id: I77d62215f34ab8c8ed4c7ee96b9e6669d0468085
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
bc5879056fba2eb616dea06e6191bdc218b594c0 27-Apr-2012 Tor Norbye <tnorbye@google.com> New Configuration Chooser

This changeset replaces the configuration chooser with a new UI.

First, the two lines of comboboxes have been replaced by a toolbar,
which will wrap to two lines if it cannot fit on a single
line. However, it tries hard to avoid this scenario by using icons and
brief labels. For example, the rendering target is displayed as an
Android icon along with just "4.0" instead of "Android
4.0". Similarly, the "Other" locale is just shown as a globe icon, and
for example in the Device list "4.65in 720p (Galaxy Nexus)" is display
as just "Galaxy Nexus".

Second, the "current configuration" label is now a dropdown instead.
The text of the label displays the current configuration as before
(though using the brief name, e.g. "layout-land" instead of "Landscape
Configuration". In addition, it's a dropdown, and opening the menu
will display all other available configurations for this file. Thus,
if you have a special landscape version and a special tablet version
of a particular layout, the menu will contain default, landscape and
tablet (where the menu items display the full configuration names such
as "Landscape Orientation"). In addition, the configuration menu also
contains "Create New...", which is the new location for the Create
button which used to be in the toolbar itself.

Third, there is a new "Activity" dropdown. This displays the current
activity associated with this layout, next to an Eclipse "class" icon.
It is initially populated with our best guess of what the activity
is. The chosen activity determines which theme is initially assigned
to a layout (for example when there is a Manifest registration of a
theme to an activity). In the future we will use this facility to
drive other features as well, such as preview rendering the action bar
(where we need to know the associated activity) or assisting with
creating click handlers. The Activity dropdown menu also contains a
"Open <Activity class>..." action for jumping to the associated Java
code. The chosen activity is persisted as an XML attribute in the
layout so it should be preserved across IDE sessions and shared among
developers.

Fourth, all the dropdown menus are now native SWT menus rather than
dropdown menus, which means we can use icons, proper separators, and
nesting. The locale menu now shows flag icons next to each region (and
when a locale is chosen the corresponding icon is shown in the
configuration toolbar). In the Theme menu we no longer need to use
"-------" ASCII separators, we can use proper native menu separators
instead. And the Theme menu is now nested; rather than a really long
list of options, the menu is grouped into related sections:

* Currently selected theme
* Project Themes >
* Manifest Themes >
* Holo Themes >
* Holo.Light Themes >
* DeviceDefault Themes >
...
* All >
* Open "<current theme>" Declaration...

Fifth, the device configuration combobox has been replaced by three
inline icon radiobuttons, showing portrait, landscape and (if enabled)
square. This makes it easy to switch orientation through a single
click.

Sixth, the UI mode (Normal/Car/Dock) and Night mode (Day/Night) are no
longer directly shown in the configuration chooser since they are not
used frequently enough to warrant persistent space in the always
visible toolbar. Instead, there is an "Edit Configuration" icon on the
left you can click which brings up a full editor dialog where all the
previous combo boxes appear, along with the generic configuration
qualifier selection dialog. Here you can make more specific edits to
the current configuration state.

There are various fixes as well. For example the whole toolbar is
hidden during platform data loading and made visible at the end. When
creating a new configuration file, that new configuration file is
opened after creation. We now track whether the current theme (stored
in the IDE persistent property) is a project theme or a framework theme.

Change-Id: Ic8d9817c7bc4dbcae4535b6b9222393fb49cfde9
bc083393e77f8139a436683644065e396646d671 21-Jan-2012 Raphael <raphael@google.com> ADT: Refactor editors.xml and editors.resources.

This renames:
- xml.XmlEditor to otherxml.OtherXmlEditor,
- resources.ResourcesEditor to values.ValuesEditor

The change to rename Resources to Values matches
the folder name being /res/values.

That's just a trivial refactoring with no logic change.

Change-Id: I68bfa760f254fbbd3f2d5e3801a5092308e92f7f
59bddc5b09c091cfae54577ec36b16925b362b55 25-Aug-2011 Tor Norbye <tnorbye@google.com> Add support for remaining asset types in Asset Studio Wizard

This changeset ports the remaining graphic generators from the HTML5
version (notifications, tabs, action bar), and hooks up wizard support
for them.

It also adds unit tests for the generators which generates images and
compares them to known good versions. I ran these tests comparing them
to the output from the HTML5 version of Asset Studio and all but 3 of
the images varied less than 5% (and I verified the remaining manually
and they're all fine and the difference is due to the images being
aligned slightly differently.)

The icon wizard is now also hooked up to the "New" button in the
Resource Chooser for drawable resources, and this changeset also fixes
a few related issues ("New" didn't work for file-based resources, and
newly created resources weren't showing up in the selection list.)

Change-Id: I48c49f1d5de452aa5b78e491d9b07e7156397fa9
b3ab7ef8a24a64bcd6f347e8e03bc647c12eb24b 29-Aug-2011 Tor Norbye <tnorbye@google.com> A few warnings fixes

Change-Id: Ie230236444a5e1288d98feea208df5ce6508803d
9c24dfb30b09495de92243ee0c79538302c0b23f 17-Aug-2011 Tor Norbye <tnorbye@google.com> Add missing qualifier icons

The Available Width, Available Height and Smallest Width qualifiers
were missing icons (which are shown in for exmaple the Create
Configuration dialog). This changeset adds icons for these (which
also makes ResourceHelper.testGetIcon pass.)

Change-Id: I42c4e357245adc0b80320bac5fe1e173d1d0eaf3
2354e094e81826d650b0a329129ee6f5db2bb652 06-Aug-2011 Tor Norbye <tnorbye@google.com> Fix template creation of ids

We have a quickfix for creating missing resources, such as
@string/foo. This code was not working correctly for @id resources,
because ids use a different declaration syntax (there is no value to
be specified as a text node child of the item tag, and the type
attribute should be specified).

This changeset also fixes ResourceHelper's isFileBasedResourceType().
ResourceHelper.isFileBasedResourceType recently started returning true
for ResourceType.ID. This seems related to a change in the return
values from FolderTypeRelationship.

In any case, ids should not be treated as #isFileBasedResourceType,
because that method is used to determine whether the id is one-to-one
with a filename, which in turn means that the resource name validator
will insist that the filename can only contain -lowercase- characters
(plus digits and underscores).

Incidentally this change was caught by a unit test, yay!

Change-Id: I0c95c20d666d0744fda73e8230846d24ddd437c3
47e918dd86afa699e017f498de3349a296e7a20f 10-Jun-2011 Xavier Ducrohet <xav@android.com> Revert ScreenLayoutSize to ScreenSize.

I hadn't noticed that LayoutLib actually uses ScrenSize
through the tools-common-prebuilt.jar, so this API is (somewhat*)
frozen.

* Somewhat because LayoutLib.jar actually only uses Density and
ScreenSize but not the other enums (yet?) so the rename of DockMode
is not a problem.

Change-Id: Ida3360b0111abd96d2a27c16833b282706774fb6
a613eae6d3c12ea0e519d38993fd471c69f6cb22 10-Jun-2011 Xavier Ducrohet <xav@android.com> Renamed some resource enum/qualifiers to be more consistent with the platform.

Change-Id: I9c5ea5183e115582e0b805ca3ec75aad70e4a65c
bc095ab3017f4127ba3d4cf86499db21a5a19b76 04-Jun-2011 Tor Norbye <tnorbye@google.com> Show previews of resources in the resource & reference choosers

This is a first cut of previews in the Resource Chooser and the
Reference Chooser. When the selected resource is a drawable or a
color, then a tray is shown on the right hand side of the dialog with
a preview of the given drawable or color. If the color is a state
list, then the fallback color is shown.

The previews only work for resource/reference choosers associated
with a layout editor (because it looks up the associated rendering
configuration from that editor). This should be made more generic
such that it can work for example when bringing up the resource
chooser from a manifest form editor.

Change-Id: I9f2896cb7ce1468076a3ca83f820be7e9affcda6
9bd5e125506d94855fa7f8dff917f20e1b4edb0b 17-Mar-2011 Tor Norbye <tnorbye@google.com> Pick layout themes from manifest registrations and target SDK

This changeset changes the way the layout editor picks themes when a
layout is opened. It used to just pick the first available theme in
the theme chooser.

Now it performs the following checks, in order:

* Does this layout have a persisted theme setting from a previous run
of the tool? If yes, use it.
* Can the activity for this layout be determined? If so, look at the
manifest registration for the corresponding activity, and if it
specifies a theme, use it.
* If not, does the manifest specify a default theme for the project?
If so, use it.
* If not, is the target SDK version (or the minimum SDK version, if
the target is not specified) at least API level 11 or higher? If so,
the default theme is "Theme.Holo"
* If not, the default theme is "Theme".
* If the file to be opened is included from some other layout, use
the no-decorations versions of the default layouts, e.g.
Theme.NoTitleBar or Theme.Holo.NoActionBar.
* At the end of this resolution, the computed theme is stored as the
persisted theme setting for this layout, so the above algorithm will
only be computed once. We might want to tweak this such that it
distinguishes between a default computation of a theme and a manual
user choice of a theme.
* If the file is opened as "Show Included In" (e.g. rendered within an
outer file) then the theme chosen is the one for the outer file.

During startup, this information will be asked for each and every
layout being reopened, so there is now a "ManifestInfo" class attached
to the project which keeps manifest information around. It checks the
timestamp of the AndroidManifest.xml file and refreshes its
information lazily if necessary.

All themes mentioned in the manifest are listed in a special section
at the top of the theme chooser (below the entry for the default
computed described above).

The code to look up the associated Activity of a layout is using a
simple heuristic: it looks for usages of the corresponding R.layout
field, and prefers references from methods called onCreate or in
classes whose superclass name ends with Activity. I tried a different
approach where I searched for usages of Activity.setContentView(int)
but this failed to identify a number of cases where the activity was
doing some simple logic and didn't pass the layout id directly as a
parameter in setContentView, so I went back to the basic approach.

Change-Id: Ibd3c0f089fefe38e6e6c607d65524990699c86d3
842b0eb9e2d530c19b9af3981e2d688411c1e554 18-Mar-2011 Tor Norbye <tnorbye@google.com> Add newline inside new root elements, and some move code around

Tweak the "New XML File" creation code to insert a new line inside the
created root element, indent, and place the cursor there. This means
that you end up with:

<LinearLayout>
|
</LinearLayout>

instead of (where | denotes the initial caret position):

|<LinearLayout>
</LinearLayout>

This means you can instantly press Ctrl-Space to complete on the
elements, etc., and is similar to how Eclipse creates new method
bodies from templates, adding newlines such that you can instantly
write code there instead of having to "open them up".

All the diffs for this are in NewXmlFileWizard.java; the other
modifications in this changeset are simple move refactoring
operations as described next:

The second change in this changeset is moving some code around such
that common utility methods live in more natural places rather than
where they were first needed.

In particular:
Hyperlinks.openUrl => AdtPlugin
Hyperlinks.openJavaClass => AdtPlugin
Hyperlinks.openFile => AdtPlugin
AndroidContentAssist.getAndroidXmlEditor => AndroidXmlEditor
ResourceChooser.canCreateResource => ResourceHelper
ResourceChooser.createResource => ResourceHelper
Hyperlinks.parseResource => ResourceHelper
ResourceNameValidator.isValueBasedResourceType => ResourceHelper
ResourceNameValidator.isFileBasedResourceType => ResourceHelper

Change-Id: If7690df9ce59c709c1d909ffd9f74c2684f3dd46
65e36c24654b47f4fc314566d2883582fc2708ba 18-Mar-2011 Xavier Ducrohet <xav@android.com> Fix unit tests from the previous refactor.

Change-Id: I464fe3f94e701e619b474f82aaf84ee04d158e71
026ba97e98e0527d910e15c4e1512893a777a8d2 18-Mar-2011 Xavier Ducrohet <xav@android.com> Move classes to ide-common

ResourceFolder/File and children classes (single/multi file)
ResourceItem and children classes
ResourceRepository (base and framework, project stays in ADT for now)
All the ResourceQualifiers and FolderConfiguration

Change-Id: I5adc9bdc4886a8fa0ab44860763d594cf7af4bd5
6aa6ce67dc85ea1d928a607d292d2c19bc2e2307 18-Mar-2011 Xavier Ducrohet <xav@android.com> Remove references to SWT from classes that are moving to ide-common.

- Move the SWT based getIcon from the resource qualifier and use a static
helper instead.

- Make a new enum ResourceDeltaKind to replace the IResourceDelta
integer constants, and use the same helper class to convert from
one to the other.

- Make ResourceRepository exclusively use the IAbstractFile/Folder

- Use the ILogger in place of AdtPlugin (which implements ILogger)

Change-Id: I0011c01ac2064b07d28c980112c47cfa433ee372
da02c18ad5b54d97a1fcfd5f6633062b0c873c22 01-Mar-2011 Xavier Ducrohet <xav@android.com> Resource management refactoring and clean-up.

- (I)ResourceRepository is now a common class instead of an
interface. This contains most of the code to control
a repository (which was extracted from ProjectResources)
ProjectResources extends it adding minor features such as
library support, and inline ID definition.
FrameworkResources extends it adding support for public
resources (which used to be duplicated and dispersed
in weird places).
Changed the way resources are reloaded on resource change event.
Instead of marking the resources as modified (using
Resource.touch()), the resources are now parsed as the files are
processed during the resource delta visitor. This makes more sense
as there are now other listeners to the resource changes (hyperlinks)
that access the resource list in their listeners, which wouldn't work
previously.
This also makes the code cleaner as the previous method had to query
the repo for items and return a list of new ones, which was kinda
crappy. The new code is much simpler, as is the post update process.

- ResourceItem is now the base class for resource items. It includes
all the small methods that were added by all the child classes or
interfaces.
Project/ConfigurableResourceItem are merged into the based class.
IIdResourceItem and IdResourceItem are gone and replaced by a
simpler InlineResourceItem.
FrameworkResourceItem is a simple override for framework resources.

- Also improved the API of a bit for the resource repository, making
more use of unmodifiable lists and emptyList/Map()

Change-Id: Ie3ac1995213fed66153c7e7ecbdd170ec257be62
3bd45f0b16f5ebfafd8080a0f17f71d85c9840ed 28-Jan-2011 Xavier Ducrohet <xav@android.com> Change APIs using String instead of ResourceType.

Move ResourceType into resources.jar so that it's accessible
to layoutlib.jar

This is cleaner and allows us to us more efficient EnumMap objects.

Change-Id: If11cbc69ae3ca8bd6c96e6d0ef402570a07af16f