aboutsummaryrefslogtreecommitdiffstats
path: root/ide_common/src/com/android/ide/common
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2011-03-16 17:37:48 -0700
committerTor Norbye <tnorbye@google.com>2011-04-04 15:31:10 -0700
commit9bd5e125506d94855fa7f8dff917f20e1b4edb0b (patch)
tree806e53e3bb105405bc7512ed50273bd21a959ef7 /ide_common/src/com/android/ide/common
parentc498ac2aa0b99f25d19ee780344cac2b83bb4184 (diff)
downloadsdk-9bd5e125506d94855fa7f8dff917f20e1b4edb0b.zip
sdk-9bd5e125506d94855fa7f8dff917f20e1b4edb0b.tar.gz
sdk-9bd5e125506d94855fa7f8dff917f20e1b4edb0b.tar.bz2
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
Diffstat (limited to 'ide_common/src/com/android/ide/common')
-rw-r--r--ide_common/src/com/android/ide/common/resources/ResourceResolver.java12
1 files changed, 11 insertions, 1 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 216d694..89a4cba 100644
--- a/ide_common/src/com/android/ide/common/resources/ResourceResolver.java
+++ b/ide_common/src/com/android/ide/common/resources/ResourceResolver.java
@@ -28,13 +28,23 @@ import java.util.Map;
public class ResourceResolver extends RenderResources {
+ /** The constant {@code style/} */
public final static String REFERENCE_STYLE = ResourceType.STYLE.getName() + "/";
+ /** The constant {@code @android:} */
public final static String PREFIX_ANDROID_RESOURCE_REF = "@android:";
+ /** The constant {@code @} */
public final static String PREFIX_RESOURCE_REF = "@";
+ /** The constant {@code ?android:} */
public final static String PREFIX_ANDROID_THEME_REF = "?android:";
+ /** The constant {@code ?} */
public final static String PREFIX_THEME_REF = "?";
+ /** The constant {@code android:} */
public final static String PREFIX_ANDROID = "android:";
-
+ /** The constant {@code @style/} */
+ public static final String PREFIX_STYLE = PREFIX_RESOURCE_REF + REFERENCE_STYLE;
+ /** The constant {@code @android:style/} */
+ public static final String PREFIX_ANDROID_STYLE = PREFIX_ANDROID_RESOURCE_REF
+ + REFERENCE_STYLE;
private final Map<ResourceType, Map<String, ResourceValue>> mProjectResources;
private final Map<ResourceType, Map<String, ResourceValue>> mFrameworkResources;