aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2011-02-03 11:43:14 -0800
committerXavier Ducrohet <xav@android.com>2011-02-04 09:41:54 -0800
commitf538a020eec631ca19ce493877de2ebca3b8d6f3 (patch)
treecf101d31c6a9fdc69001e6c5c53ae27c4b6a3325 /sdkmanager
parent8818812b7d824bcd52bb730c6bf659227fb86177 (diff)
downloadsdk-f538a020eec631ca19ce493877de2ebca3b8d6f3.zip
sdk-f538a020eec631ca19ce493877de2ebca3b8d6f3.tar.gz
sdk-f538a020eec631ca19ce493877de2ebca3b8d6f3.tar.bz2
Add app name/icon and current render locale to the LayoutLib API.
This allows the layoutlib to render system/title/action bars as a window decor like it would look on the device. This can be disabled with RenderParams.setForceNoDecor(). (BTW, Params was renamed RenderParams too) Also minor update to the API by replacing an int with Density since the enum is now accessible to the API and layoutlib. Change-Id: Ic37770a9276d12af90c60199a84b04cb64e7c3a1
Diffstat (limited to 'sdkmanager')
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java66
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java18
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;
- }
}