diff options
author | Xavier Ducrohet <xav@android.com> | 2011-02-28 16:49:37 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2011-03-08 17:50:49 -0800 |
commit | da02c18ad5b54d97a1fcfd5f6633062b0c873c22 (patch) | |
tree | 2c64e7089fa60df984aa883c6f131031ad614279 /ide_common | |
parent | 1d0a2869f34ff2c12e57bac5dcd85da8b5ce8e10 (diff) | |
download | sdk-da02c18ad5b54d97a1fcfd5f6633062b0c873c22.zip sdk-da02c18ad5b54d97a1fcfd5f6633062b0c873c22.tar.gz sdk-da02c18ad5b54d97a1fcfd5f6633062b0c873c22.tar.bz2 |
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
Diffstat (limited to 'ide_common')
-rw-r--r-- | ide_common/src/com/android/ide/common/resources/ResourceResolver.java | 84 |
1 files changed, 37 insertions, 47 deletions
diff --git a/ide_common/src/com/android/ide/common/resources/ResourceResolver.java b/ide_common/src/com/android/ide/common/resources/ResourceResolver.java index 2a06373..9493c35 100644 --- a/ide_common/src/com/android/ide/common/resources/ResourceResolver.java +++ b/ide_common/src/com/android/ide/common/resources/ResourceResolver.java @@ -121,14 +121,10 @@ public class ResourceResolver extends RenderResources { if (frameworkTheme) { Map<String, ResourceValue> frameworkStyleMap = mFrameworkResources.get( ResourceType.STYLE); - if (frameworkStyleMap != null) { - theme = frameworkStyleMap.get(name); - } + theme = frameworkStyleMap.get(name); } else { Map<String, ResourceValue> projectStyleMap = mProjectResources.get(ResourceType.STYLE); - if (projectStyleMap != null) { - theme = projectStyleMap.get(name); - } + theme = projectStyleMap.get(name); } if (theme instanceof StyleResourceValue) { @@ -334,29 +330,25 @@ public class ResourceResolver extends RenderResources { // if allowed, search in the project resources first. if (frameworkOnly == false) { typeMap = mProjectResources.get(resType); - if (typeMap != null) { - ResourceValue item = typeMap.get(resName); - if (item != null) { - return item; - } + ResourceValue item = typeMap.get(resName); + if (item != null) { + return item; } } // now search in the framework resources. typeMap = mFrameworkResources.get(resType); - if (typeMap != null) { - ResourceValue item = typeMap.get(resName); - if (item != null) { - return item; - } + ResourceValue item = typeMap.get(resName); + if (item != null) { + return item; + } - // if it was not found and the type is an id, it is possible that the ID was - // generated dynamically when compiling the framework resources. - // Look for it in the R map. - if (mFrameworkProvider != null && resType == ResourceType.ID) { - if (mFrameworkProvider.getId(resType, resName) != null) { - return new ResourceValue(resType, resName, true); - } + // if it was not found and the type is an id, it is possible that the ID was + // generated dynamically when compiling the framework resources. + // Look for it in the R map. + if (mFrameworkProvider != null && resType == ResourceType.ID) { + if (mFrameworkProvider.getId(resType, resName) != null) { + return new ResourceValue(resType, resName, true); } } @@ -397,32 +389,30 @@ public class ResourceResolver extends RenderResources { Map<String, ResourceValue> projectStyleMap = mProjectResources.get(ResourceType.STYLE); Map<String, ResourceValue> frameworkStyleMap = mFrameworkResources.get(ResourceType.STYLE); - if (projectStyleMap != null && frameworkStyleMap != null) { - // first, get the theme - ResourceValue theme = null; - - // project theme names have been prepended with a * - if (isProjectTheme) { - theme = projectStyleMap.get(themeName); - } else { - theme = frameworkStyleMap.get(themeName); - } - - if (theme instanceof StyleResourceValue) { - // compute the inheritance map for both the project and framework styles - computeStyleInheritance(projectStyleMap.values(), projectStyleMap, - frameworkStyleMap); + // first, get the theme + ResourceValue theme = null; - // Compute the style inheritance for the framework styles/themes. - // Since, for those, the style parent values do not contain 'android:' - // we want to force looking in the framework style only to avoid using - // similarly named styles from the project. - // To do this, we pass null in lieu of the project style map. - computeStyleInheritance(frameworkStyleMap.values(), null /*inProjectStyleMap */, - frameworkStyleMap); + // project theme names have been prepended with a * + if (isProjectTheme) { + theme = projectStyleMap.get(themeName); + } else { + theme = frameworkStyleMap.get(themeName); + } - mTheme = (StyleResourceValue) theme; - } + if (theme instanceof StyleResourceValue) { + // compute the inheritance map for both the project and framework styles + computeStyleInheritance(projectStyleMap.values(), projectStyleMap, + frameworkStyleMap); + + // Compute the style inheritance for the framework styles/themes. + // Since, for those, the style parent values do not contain 'android:' + // we want to force looking in the framework style only to avoid using + // similarly named styles from the project. + // To do this, we pass null in lieu of the project style map. + computeStyleInheritance(frameworkStyleMap.values(), null /*inProjectStyleMap */, + frameworkStyleMap); + + mTheme = (StyleResourceValue) theme; } } |