diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2014-02-14 22:08:54 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-02-14 22:08:55 +0000 |
commit | 3ce7789f80db952bb80235f893b0e9fd238a317f (patch) | |
tree | 4ce6637e4146f113bf6e044f621ddf073de8b217 /eclipse | |
parent | da06e3d51427f7d7bb9a1258fd50d34b5d6cd927 (diff) | |
parent | 538184c5c32ea086eb3e4248d8b200ae2d3924e1 (diff) | |
download | sdk-3ce7789f80db952bb80235f893b0e9fd238a317f.zip sdk-3ce7789f80db952bb80235f893b0e9fd238a317f.tar.gz sdk-3ce7789f80db952bb80235f893b0e9fd238a317f.tar.bz2 |
Merge "Add activity details to the ManifestInfo" into idea133
Diffstat (limited to 'eclipse')
6 files changed, 198 insertions, 55 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/Configuration.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/Configuration.java index 2260303..44faf71 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/Configuration.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/Configuration.java @@ -39,6 +39,7 @@ import com.android.ide.common.resources.configuration.VersionQualifier; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService; import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo; +import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo.ActivityAttributes; import com.android.ide.eclipse.adt.internal.preferences.AdtPrefs; import com.android.ide.eclipse.adt.internal.resources.ResourceHelper; import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources; @@ -63,7 +64,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.QualifiedName; import java.util.List; -import java.util.Map; /** * A {@linkplain Configuration} is a selection of device, orientation, theme, @@ -707,8 +707,10 @@ public class Configuration { String activity = getActivity(); if (activity != null) { - Map<String, String> activityThemes = manifest.getActivityThemes(); - preferred = activityThemes.get(activity); + ActivityAttributes attributes = manifest.getActivityAttributes(activity); + if (attributes != null) { + preferred = attributes.getTheme(); + } } if (preferred == null) { preferred = defaultTheme; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationChooser.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationChooser.java index ebd1fb9..5b8e70b 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationChooser.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationChooser.java @@ -58,6 +58,7 @@ import com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorP import com.android.ide.eclipse.adt.internal.editors.layout.gle2.IncludeFinder.Reference; import com.android.ide.eclipse.adt.internal.editors.layout.gle2.LayoutCanvas; import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo; +import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo.ActivityAttributes; import com.android.ide.eclipse.adt.internal.resources.ResourceHelper; import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources; import com.android.ide.eclipse.adt.internal.resources.manager.ResourceManager; @@ -1586,8 +1587,11 @@ public class ConfigurationChooser extends Composite // See if there is a default theme assigned to this activity, and if so, use it ManifestInfo manifest = ManifestInfo.get(mEditedFile.getProject()); - Map<String, String> activityThemes = manifest.getActivityThemes(); - String preferred = activityThemes.get(activity); + String preferred = null; + ActivityAttributes attributes = manifest.getActivityAttributes(activity); + if (attributes != null) { + preferred = attributes.getTheme(); + } if (preferred != null && !Objects.equal(preferred, mConfiguration.getTheme())) { // Yes, switch to it selectTheme(preferred); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationDescription.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationDescription.java index 7141f94..cc50398 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationDescription.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ConfigurationDescription.java @@ -32,6 +32,7 @@ import com.android.ide.common.resources.configuration.RegionQualifier; import com.android.ide.common.resources.configuration.ScreenSizeQualifier; import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo; +import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo.ActivityAttributes; import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData; import com.android.ide.eclipse.adt.internal.sdk.Sdk; import com.android.resources.NightMode; @@ -50,7 +51,6 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import java.util.List; -import java.util.Map; /** A description of a configuration, used for persistence */ public class ConfigurationDescription { @@ -349,8 +349,10 @@ public class ConfigurationDescription { // from the outer layout instead if (activity != null) { - Map<String, String> activityThemes = manifest.getActivityThemes(); - preferred = activityThemes.get(activity); + ActivityAttributes attributes = manifest.getActivityAttributes(activity); + if (attributes != null) { + preferred = attributes.getTheme(); + } } if (preferred == null) { preferred = defaultTheme; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ThemeMenuAction.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ThemeMenuAction.java index 0f6c9eb..b1ce21d 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ThemeMenuAction.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/configuration/ThemeMenuAction.java @@ -21,6 +21,7 @@ import static com.android.SdkConstants.ANDROID_STYLE_RESOURCE_PREFIX; import com.android.ide.eclipse.adt.internal.editors.Hyperlinks; import com.android.ide.eclipse.adt.internal.editors.layout.gle2.SubmenuAction; import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo; +import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo.ActivityAttributes; import com.android.ide.eclipse.adt.internal.resources.ResourceHelper; import com.android.sdklib.IAndroidTarget; @@ -41,7 +42,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; /** @@ -180,30 +180,39 @@ class ThemeMenuAction extends SubmenuAction { case MENU_MANIFEST: { IProject project = mConfigChooser.getEditedFile().getProject(); ManifestInfo manifest = ManifestInfo.get(project); - Map<String, String> activityThemes = manifest.getActivityThemes(); Configuration configuration = mConfigChooser.getConfiguration(); String activity = configuration.getActivity(); if (activity != null) { - String theme = activityThemes.get(activity); - if (theme != null) { - addMenuItem(menu, theme, isSelectedTheme(theme)); + ActivityAttributes attributes = manifest.getActivityAttributes(activity); + if (attributes != null) { + String theme = attributes.getTheme(); + if (theme != null) { + addMenuItem(menu, theme, isSelectedTheme(theme)); + } } } String manifestTheme = manifest.getManifestTheme(); - if (activityThemes.size() > 0 || manifestTheme != null) { - Set<String> allThemes = new HashSet<String>(activityThemes.values()); - if (manifestTheme != null) { - allThemes.add(manifestTheme); - } - List<String> sorted = new ArrayList<String>(allThemes); - Collections.sort(sorted); - String current = configuration.getTheme(); - for (String theme : sorted) { - boolean selected = theme.equals(current); - addMenuItem(menu, theme, selected); + boolean found = false; + Set<String> allThemes = new HashSet<String>(); + if (manifestTheme != null) { + found = true; + allThemes.add(manifestTheme); + } + for (ActivityAttributes info : manifest.getActivityAttributesMap().values()) { + if (info.getTheme() != null) { + found = true; + allThemes.add(info.getTheme()); } - } else { + } + List<String> sorted = new ArrayList<String>(allThemes); + Collections.sort(sorted); + String current = configuration.getTheme(); + for (String theme : sorted) { + boolean selected = theme.equals(current); + addMenuItem(menu, theme, selected); + } + if (!found) { addDisabledMessageItem("No themes are registered in the manifest"); } break; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestInfo.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestInfo.java index 9b26057..056132d 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestInfo.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestInfo.java @@ -24,11 +24,16 @@ import static com.android.xml.AndroidManifest.ATTRIBUTE_LABEL; import static com.android.xml.AndroidManifest.ATTRIBUTE_MIN_SDK_VERSION; import static com.android.xml.AndroidManifest.ATTRIBUTE_NAME; import static com.android.xml.AndroidManifest.ATTRIBUTE_PACKAGE; +import static com.android.xml.AndroidManifest.ATTRIBUTE_PARENT_ACTIVITY_NAME; import static com.android.xml.AndroidManifest.ATTRIBUTE_SUPPORTS_RTL; import static com.android.xml.AndroidManifest.ATTRIBUTE_TARGET_SDK_VERSION; import static com.android.xml.AndroidManifest.ATTRIBUTE_THEME; +import static com.android.xml.AndroidManifest.ATTRIBUTE_UI_OPTIONS; +import static com.android.xml.AndroidManifest.ATTRIBUTE_VALUE; import static com.android.xml.AndroidManifest.NODE_ACTIVITY; +import static com.android.xml.AndroidManifest.NODE_METADATA; import static com.android.xml.AndroidManifest.NODE_USES_SDK; +import static com.android.xml.AndroidManifest.VALUE_PARENT_ACTIVITY; import static org.eclipse.jdt.core.search.IJavaSearchConstants.REFERENCES; import com.android.SdkConstants; @@ -99,6 +104,123 @@ import javax.xml.xpath.XPathExpressionException; * @see AndroidManifest */ public class ManifestInfo { + + public static class ActivityAttributes { + @Nullable + private final String mIcon; + @Nullable + private final String mLabel; + @NonNull + private final String mName; + @Nullable + private final String mParentActivity; + @Nullable + private final String mTheme; + @Nullable + private final String mUiOptions; + + public ActivityAttributes(Element activity, String packageName) { + + // Get activity name. + String name = activity.getAttributeNS(NS_RESOURCES, ATTRIBUTE_NAME); + if (name == null || name.length() == 0) { + throw new RuntimeException("Activity name cannot be empty"); + } + int index = name.indexOf('.'); + if (index <= 0 && packageName != null && !packageName.isEmpty()) { + name = packageName + (index == -1 ? "." : "") + name; + } + mName = name; + + // Get activity icon. + String value = activity.getAttributeNS(NS_RESOURCES, ATTRIBUTE_ICON); + if (value != null && value.length() > 0) { + mIcon = value; + } else { + mIcon = null; + } + + // Get activity label. + value = activity.getAttributeNS(NS_RESOURCES, ATTRIBUTE_LABEL); + if (value != null && value.length() > 0) { + mLabel = value; + } else { + mLabel = null; + } + + // Get activity parent. Also search the meta-data for parent info. + value = activity.getAttributeNS(NS_RESOURCES, ATTRIBUTE_PARENT_ACTIVITY_NAME); + if (value == null || value.length() == 0) { + // TODO: Not sure if meta data can be used for API Level > 16 + NodeList metaData = activity.getElementsByTagName(NODE_METADATA); + for (int j = 0, m = metaData.getLength(); j < m; j++) { + Element data = (Element) metaData.item(j); + String metadataName = data.getAttributeNS(NS_RESOURCES, ATTRIBUTE_NAME); + if (VALUE_PARENT_ACTIVITY.equals(metadataName)) { + value = data.getAttributeNS(NS_RESOURCES, ATTRIBUTE_VALUE); + if (value != null) { + index = value.indexOf('.'); + if (index <= 0 && packageName != null && !packageName.isEmpty()) { + value = packageName + (index == -1 ? "." : "") + value; + break; + } + } + } + } + } + if (value != null && value.length() > 0) { + mParentActivity = value; + } else { + mParentActivity = null; + } + + // Get activity theme. + value = activity.getAttributeNS(NS_RESOURCES, ATTRIBUTE_THEME); + if (value != null && value.length() > 0) { + mTheme = value; + } else { + mTheme = null; + } + + // Get UI options. + value = activity.getAttributeNS(NS_RESOURCES, ATTRIBUTE_UI_OPTIONS); + if (value != null && value.length() > 0) { + mUiOptions = value; + } else { + mUiOptions = null; + } + } + + @Nullable + public String getIcon() { + return mIcon; + } + + @Nullable + public String getLabel() { + return mLabel; + } + + public String getName() { + return mName; + } + + @Nullable + public String getParentActivity() { + return mParentActivity; + } + + @Nullable + public String getTheme() { + return mTheme; + } + + @Nullable + public String getUiOptions() { + return mUiOptions; + } + } + /** * The maximum number of milliseconds to search for an activity in the codebase when * attempting to associate layouts with activities in @@ -109,7 +231,7 @@ public class ManifestInfo { private final IProject mProject; private String mPackage; private String mManifestTheme; - private Map<String, String> mActivityThemes; + private Map<String, ActivityAttributes> mActivityAttributes; private IAbstractFile mManifestFile; private long mLastModified; private long mLastChecked; @@ -201,7 +323,7 @@ public class ManifestInfo { } mLastModified = fileModified; - mActivityThemes = new HashMap<String, String>(); + mActivityAttributes = new HashMap<String, ActivityAttributes>(); mManifestTheme = null; mTargetSdk = 1; // Default when not specified mMinSdk = 1; // Default when not specified @@ -226,15 +348,8 @@ public class ManifestInfo { NodeList activities = document.getElementsByTagName(NODE_ACTIVITY); for (int i = 0, n = activities.getLength(); i < n; i++) { Element activity = (Element) activities.item(i); - String theme = activity.getAttributeNS(NS_RESOURCES, ATTRIBUTE_THEME); - if (theme != null && theme.length() > 0) { - String name = activity.getAttributeNS(NS_RESOURCES, ATTRIBUTE_NAME); - int index = name.indexOf('.'); - if (index <= 0 && mPackage != null && !mPackage.isEmpty()) { - name = mPackage + (index == -1 ? "." : "") + name; - } - mActivityThemes.put(name, theme); - } + ActivityAttributes info = new ActivityAttributes(activity, mPackage); + mActivityAttributes.put(info.getName(), info); } NodeList applications = root.getElementsByTagName(AndroidManifest.NODE_APPLICATION); @@ -318,15 +433,22 @@ public class ManifestInfo { } /** - * Returns a map from activity full class names to the corresponding theme style to be - * used + * Returns a map from activity full class names to the corresponding {@link ActivityAttributes}. * - * @return a map from activity fqcn to theme style + * @return a map from activity fqcn to ActivityAttributes */ @NonNull - public Map<String, String> getActivityThemes() { + public Map<String, ActivityAttributes> getActivityAttributesMap() { sync(); - return mActivityThemes; + return mActivityAttributes; + } + + /** + * Returns the attributes of an activity given its full class name. + */ + @Nullable + public ActivityAttributes getActivityAttributes(String activity) { + return getActivityAttributesMap().get(activity); } /** @@ -402,6 +524,7 @@ public class ManifestInfo { sync(); return mApplicationSupportsRtl; } + /** * Returns the target SDK version * diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestInfoTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestInfoTest.java index 57027e9..43f9d68 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestInfoTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestInfoTest.java @@ -19,7 +19,9 @@ import static com.android.resources.ScreenSize.LARGE; import static com.android.resources.ScreenSize.NORMAL; import static com.android.resources.ScreenSize.XLARGE; +import com.android.annotations.NonNull; import com.android.ide.eclipse.adt.internal.editors.layout.refactoring.AdtProjectTest; +import com.android.ide.eclipse.adt.internal.editors.manifest.ManifestInfo.ActivityAttributes; import com.android.ide.eclipse.adt.internal.resources.ResourceHelper; import com.android.sdklib.AndroidVersion; import com.android.sdklib.BuildToolInfo; @@ -50,7 +52,7 @@ public class ManifestInfoTest extends AdtProjectTest { " package='com.android.unittest'>\n" + " <uses-sdk android:minSdkVersion='3' android:targetSdkVersion='4'/>\n" + "</manifest>\n"); - Map<String, String> map = info.getActivityThemes(); + Map<String, ActivityAttributes> map = info.getActivityAttributesMap(); assertEquals(map.toString(), 0, map.size()); assertEquals("com.android.unittest", info.getPackage()); assertEquals("Theme", ResourceHelper.styleToTheme(info.getDefaultTheme(null, NORMAL))); @@ -64,7 +66,7 @@ public class ManifestInfoTest extends AdtProjectTest { " package='com.android.unittest'>\n" + " <uses-sdk android:minSdkVersion='3' android:targetSdkVersion='11'/>\n" + "</manifest>\n"); - Map<String, String> map = info.getActivityThemes(); + Map<String, ActivityAttributes> map = info.getActivityAttributesMap(); assertEquals(map.toString(), 0, map.size()); assertEquals("com.android.unittest", info.getPackage()); assertEquals("Theme.Holo", ResourceHelper.styleToTheme(info.getDefaultTheme(null, @@ -78,7 +80,7 @@ public class ManifestInfoTest extends AdtProjectTest { " package='com.android.unittest'>\n" + " <uses-sdk android:minSdkVersion='11'/>\n" + "</manifest>\n"); - Map<String, String> map = info.getActivityThemes(); + Map<String, ActivityAttributes> map = info.getActivityAttributesMap(); assertEquals(map.toString(), 0, map.size()); assertEquals("com.android.unittest", info.getPackage()); assertEquals("Theme.Holo", ResourceHelper.styleToTheme(info.getDefaultTheme(null, @@ -110,11 +112,11 @@ public class ManifestInfoTest extends AdtProjectTest { assertEquals("com.android.unittest", info.getPackage()); assertEquals("Theme", ResourceHelper.styleToTheme(info.getDefaultTheme(null, XLARGE))); - Map<String, String> map = info.getActivityThemes(); - assertEquals(map.toString(), 1, map.size()); - assertNull(map.get("com.android.unittest.prefs.PrefsActivity")); + Map<String, ActivityAttributes> map = info.getActivityAttributesMap(); + assertEquals(map.toString(), 2, map.size()); + assertNull(map.get("com.android.unittest.prefs.PrefsActivity").getTheme()); assertEquals("@android:style/Theme.Dialog", - map.get("com.android.unittest.app.IntroActivity")); + map.get("com.android.unittest.app.IntroActivity").getTheme()); } public void testGetActivityThemes5() throws Exception { @@ -145,11 +147,11 @@ public class ManifestInfoTest extends AdtProjectTest { assertEquals("NoBackground", ResourceHelper.styleToTheme(info.getDefaultTheme(null, NORMAL))); - Map<String, String> map = info.getActivityThemes(); - assertEquals(map.toString(), 1, map.size()); - assertNull(map.get("com.android.unittest.prefs.PrefsActivity")); + Map<String, ActivityAttributes> map = info.getActivityAttributesMap(); + assertEquals(map.toString(), 2, map.size()); + assertNull(map.get("com.android.unittest.prefs.PrefsActivity").getTheme()); assertEquals("@android:style/Theme.Dialog", - map.get("com.android.unittest.app.IntroActivity")); + map.get("com.android.unittest.app.IntroActivity").getTheme()); } public void testGetActivityThemes6() throws Exception { @@ -160,7 +162,7 @@ public class ManifestInfoTest extends AdtProjectTest { " package='com.android.unittest'>\n" + " <uses-sdk android:minSdkVersion='3' android:targetSdkVersion='11'/>\n" + "</manifest>\n"); - Map<String, String> map = info.getActivityThemes(); + Map<String, ActivityAttributes> map = info.getActivityAttributesMap(); assertEquals(map.toString(), 0, map.size()); assertEquals("com.android.unittest", info.getPackage()); assertEquals("Theme.Holo", ResourceHelper.styleToTheme(info.getDefaultTheme(null, @@ -182,7 +184,7 @@ public class ManifestInfoTest extends AdtProjectTest { " </application>\n" + "" + "</manifest>\n"); - Map<String, String> map = info.getActivityThemes(); + Map<String, ActivityAttributes> map = info.getActivityAttributesMap(); assertEquals(map.toString(), 0, map.size()); assertEquals("com.android.unittest", info.getPackage()); @@ -199,7 +201,7 @@ public class ManifestInfoTest extends AdtProjectTest { " </application>\n" + "" + "</manifest>\n"); - Map<String, String> map = info.getActivityThemes(); + Map<String, ActivityAttributes> map = info.getActivityAttributesMap(); assertEquals(map.toString(), 0, map.size()); assertEquals("com.android.unittest", info.getPackage()); @@ -409,6 +411,7 @@ public class ManifestInfoTest extends AdtProjectTest { } @Override + @NonNull public List<String> getBootClasspath() { return new ArrayList<String>(); } |