aboutsummaryrefslogtreecommitdiffstats
path: root/ide_common/src/com/android/ide/common/resources/ResourceResolver.java
Commit message (Collapse)AuthorAgeFilesLines
* Rename ide_common to sdk_commonSiva Velusamy2012-09-181-560/+0
| | | | Change-Id: I1b39ee439a532f3f6758be35b569948e2e906665
* Constants refactoring.Tor Norbye2012-09-131-23/+11
| | | | | | | | | | | | | | | | 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
* Improve search of items into style for legacy layoutlibs.Xavier Ducrohet2012-05-161-9/+7
| | | | | | | | | | | | | Legacy versions uses the old API that doesn't specify the namespace of the attribute being queried. The implementation used the namespace of the style as the namespace of the attribute but this make little sense. At better implementation searches in the project's namespace and, if the attribute is not found, then searches in the framework namespace. Change-Id: Ief43ecd45f108162de2b1512027d4eedf2c132db
* Properly support attr ns when used in styles.Xavier Ducrohet2012-03-161-8/+30
| | | | | | | | | | | | | Previously we just stripped the namespace prefix when reading attribute names in styles and declare-styleables. This was bad if one created a declare-styleable mixing platform and app attributes that were named the same. This change is Eclipse side only and prevents ADT crashed (due to stack overflows) but the rendering won't be correct. An updated version of layoutlib using API 8 is necessary. Change-Id: I3029f3e06cdd96cd46af511bb029bc5274b935ad
* Add proper styleable support.Xavier Ducrohet2011-06-071-9/+10
| | | | Change-Id: I2dc79e71521f93d798fd4a9b33aa59979bef379d
* Detect and add special warning for wrong themesTor Norbye2011-05-231-5/+14
| | | | | | | | | | | | | | | | | | | If you open a layout designed for a particular theme in another theme, you can get many confusing error messages. Instead of "attribute missing" it may tell you that it failed to convert a resource to a color or drawable, and so on. To help guide users to the root problem (wrong theme chosen) this changeset detects the scenario where theme attributes can't be resolved, and when these are found the top of the error log will start with a bold message stating that theme resources were not found and to check whether the correct theme is chosen. To do this, the resource resolver emits a new sub-type of the resource missing tag into the error log, which is used in the IDE to prefix the errors with the special error message. Change-Id: Ic29c9af37da4b5cc2c9fb1ca5670c8b8f79bf852
* Pick layout themes from manifest registrations and target SDKTor Norbye2011-04-041-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Extract Style RefactoringTor Norbye2011-03-311-1/+1
| | | | | | | | | | | | | | | Adds a new refactoring, "Extract Style", which will show the user the attributes for the current selected elements (or if invoked from an editor context, the attributes overlapping the current caret or editor selection). The user can select which attributes to extract, and these are then added as a new style in the styles.xml file in the project (which is created if necessary). The user can optionally replace the attributes that were extracted, and the user can also optionally set the style attribute on the elements to the new style. (Both are on by default.) This is integrated with the refactoring quick assistant as well. Change-Id: I0504e86a824b00730482607150a879ff28233618
* Add go to declaration support for styles and embedded textTor Norbye2011-03-211-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changeset adds support to the Go To Declaration code for styles. Style strings are a bit different from resource URLs - they can have an @android: prefix, but they don't specify a resource type. For example, go to declaration can now jump to the value in the parent attribute: <style name="BrowserTheme" parent="@android:Theme.Black"> This will show the Theme.Black style definition in the SDK's styles.xml document. In addition, the hyperlink resolver can now also link to fragments of an attribute value. In particular, in the above, if you point anywhere to the left of the ".", only the @android:Theme range will be selected. This lets you go to parents, since styles inherit from other styles by adding to them with dots. Third, the hyperlink resolver can now link to resource urls that is in the content part of XML documents (e.g. a text node, not an element name or attribute value). As an example, you can now jump to the color defined inside this style element: <style name="CustomTheme" parent="android:Theme.Light"> <item name="android:bg">@color/custom_theme_color</item> </style> Finally, this changeset adds unit/plugin tests for the hyperlink resolver, which asserts the expected list of matches, and the expected editor context when the default link is opened. Change-Id: I73757ec78405f7c711e13387d0bb046f698799f1
* Resource management refactoring and clean-up.Xavier Ducrohet2011-03-081-47/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - (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
* Remove some non needed asserts.Xavier Ducrohet2011-02-221-1/+0
| | | | Change-Id: Ib12b25d7c7a6630075cfe4f5e757a10673305220
* Change APIs using String instead of ResourceType.Xavier Ducrohet2011-01-281-27/+33
| | | | | | | | | 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
* Add more theme query APIs to RenderResourcesXavier Ducrohet2011-01-261-1/+36
| | | | Change-Id: Iebde7536a0007898387dc7bb5d943e3767140a3c
* Move the resource resolution code into ide-common.Xavier Ducrohet2011-01-171-0/+502
Also move the LayoutLib API to use a new class for all resource info instead of 2 maps, one string, and a boolean. The goal is to move resource resolution code into ADT so that we can use it to better display resource information in the UI. Change-Id: Iad1c1719ab0b08d1a7d0987b92d4be1d3a895adf