diff options
author | Xavier Ducrohet <xav@android.com> | 2011-02-04 11:42:19 -0800 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2011-02-04 11:42:19 -0800 |
commit | 1d2909b8ff75a392af9231fe848674378b234bb9 (patch) | |
tree | a7428e957db1898bd666be80fb50ee00ab278600 /sdkmanager | |
parent | 5605ef77b4ae4e2d7c5a203b242a0923a295b928 (diff) | |
parent | f538a020eec631ca19ce493877de2ebca3b8d6f3 (diff) | |
download | sdk-1d2909b8ff75a392af9231fe848674378b234bb9.zip sdk-1d2909b8ff75a392af9231fe848674378b234bb9.tar.gz sdk-1d2909b8ff75a392af9231fe848674378b234bb9.tar.bz2 |
Merge "Add app name/icon and current render locale to the LayoutLib API."
Diffstat (limited to 'sdkmanager')
-rw-r--r-- | sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java | 66 | ||||
-rw-r--r-- | sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java | 18 |
2 files changed, 64 insertions, 20 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java index 6ed6e49..2cb6ace 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java @@ -58,6 +58,8 @@ public final class AndroidManifest { public final static String ATTRIBUTE_GLESVERSION = "glEsVersion"; public final static String ATTRIBUTE_PROCESS = "process"; public final static String ATTRIBUTE_DEBUGGABLE = "debuggable"; + public final static String ATTRIBUTE_LABEL = "label"; + public final static String ATTRIBUTE_ICON = "icon"; public final static String ATTRIBUTE_MIN_SDK_VERSION = "minSdkVersion"; public final static String ATTRIBUTE_TARGET_SDK_VERSION = "targetSdkVersion"; public final static String ATTRIBUTE_TARGET_PACKAGE = "targetPackage"; @@ -76,6 +78,22 @@ public final class AndroidManifest { public final static String ATTRIBUTE_REQ_TOUCHSCREEN = "reqTouchScreen"; /** + * Returns an {@link IAbstractFile} object representing the manifest for the given project. + * + * @param project The project containing the manifest file. + * @return An IAbstractFile object pointing to the manifest or null if the manifest + * is missing. + */ + public static IAbstractFile getManifest(IAbstractFolder projectFolder) { + IAbstractFile file = projectFolder.getFile(SdkConstants.FN_ANDROID_MANIFEST_XML); + if (file.exists()) { + return file; + } + + return null; + } + + /** * Returns the package for a given project. * @param projectFolder the folder of the project. * @return the package info or null (or empty) if not found. @@ -84,8 +102,12 @@ public final class AndroidManifest { */ public static String getPackage(IAbstractFolder projectFolder) throws XPathExpressionException, StreamException { - IAbstractFile file = projectFolder.getFile(SdkConstants.FN_ANDROID_MANIFEST_XML); - return getPackage(file); + IAbstractFile file = getManifest(projectFolder); + if (file != null) { + return getPackage(file); + } + + return null; } /** @@ -123,7 +145,8 @@ public final class AndroidManifest { String value = xPath.evaluate( "/" + NODE_MANIFEST + "/" + NODE_APPLICATION + - "/@" + ATTRIBUTE_DEBUGGABLE, + "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX + + ":" + ATTRIBUTE_DEBUGGABLE, new InputSource(manifestFile.getContents())); // default is not debuggable, which is the same behavior as parseBoolean @@ -240,6 +263,43 @@ public final class AndroidManifest { } } + /** + * Returns the application icon for a given manifest. + * @param manifestFile the manifest to parse. + * @return the icon or null (or empty) if not found. + * @throws XPathExpressionException + * @throws StreamException If any error happens when reading the manifest. + */ + public static String getApplicationIcon(IAbstractFile manifestFile) + throws XPathExpressionException, StreamException { + XPath xPath = AndroidXPathFactory.newXPath(); + + return xPath.evaluate( + "/" + NODE_MANIFEST + + "/" + NODE_APPLICATION + + "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX + + ":" + ATTRIBUTE_ICON, + new InputSource(manifestFile.getContents())); + } + + /** + * Returns the application label for a given manifest. + * @param manifestFile the manifest to parse. + * @return the label or null (or empty) if not found. + * @throws XPathExpressionException + * @throws StreamException If any error happens when reading the manifest. + */ + public static String getApplicationLabel(IAbstractFile manifestFile) + throws XPathExpressionException, StreamException { + XPath xPath = AndroidXPathFactory.newXPath(); + + return xPath.evaluate( + "/" + NODE_MANIFEST + + "/" + NODE_APPLICATION + + "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX + + ":" + ATTRIBUTE_LABEL, + new InputSource(manifestFile.getContents())); + } /** * Combines a java package, with a class value from the manifest to make a fully qualified diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java index 9a67735..09e81f7 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java @@ -632,7 +632,7 @@ public class AndroidManifestParser { public static ManifestData parse(IAbstractFolder projectFolder) throws SAXException, IOException, StreamException, ParserConfigurationException { - IAbstractFile manifestFile = getManifest(projectFolder); + IAbstractFile manifestFile = AndroidManifest.getManifest(projectFolder); if (manifestFile == null) { throw new FileNotFoundException(); } @@ -666,20 +666,4 @@ public class AndroidManifestParser { return null; } - - /** - * Returns an {@link IAbstractFile} object representing the manifest for the given project. - * - * @param project The project containing the manifest file. - * @return An IAbstractFile object pointing to the manifest or null if the manifest - * is missing. - */ - public static IAbstractFile getManifest(IAbstractFolder projectFolder) { - IAbstractFile file = projectFolder.getFile(SdkConstants.FN_ANDROID_MANIFEST_XML); - if (file.exists()) { - return file; - } - - return null; - } } |