OSDN Git Service

Add parsing of <uses-configuration> in the manifest.
authorXavier Ducrohet <xav@android.com>
Wed, 19 May 2010 00:30:46 +0000 (17:30 -0700)
committerXavier Ducrohet <xav@android.com>
Wed, 19 May 2010 01:11:13 +0000 (18:11 -0700)
Change-Id: Id6f4b58c5a811b0b7e32b40162c8bd6680f2fc67

eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/TextInputMethodQualifierTest.java
sdkmanager/libs/sdklib/src/com/android/sdklib/resources/Keyboard.java
sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java
sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java
sdkmanager/libs/sdklib/src/com/android/sdklib/xml/ManifestData.java
sdkmanager/libs/sdklib/tests/com/android/sdklib/xml/AndroidManifestParserTest.java

index 04eb8da..e51c12d 100644 (file)
@@ -51,7 +51,7 @@ public class TextInputMethodQualifierTest extends TestCase {
     public void test12Key() {
         assertEquals(true, timq.checkAndSet("12key", config)); //$NON-NLS-1$
         assertTrue(config.getTextInputMethodQualifier() != null);
-        assertEquals(Keyboard.TWELVEKEYS, config.getTextInputMethodQualifier().getValue());
+        assertEquals(Keyboard.TWELVEKEY, config.getTextInputMethodQualifier().getValue());
         assertEquals("12key", config.getTextInputMethodQualifier().toString()); //$NON-NLS-1$
     }
 
index 1b910d4..914b205 100644 (file)
@@ -21,15 +21,16 @@ package com.android.sdklib.resources;
  * <p/>This is used in the manifest in the uses-configuration node and in the resource folder names.
  */
 public enum Keyboard {
-    NOKEY("nokeys", "No Keys"), //$NON-NLS-1$
-    QWERTY("qwerty", "Qwerty"), //$NON-NLS-1$
-    TWELVEKEYS("12key", "12 Key"); //$NON-NLS-1$
+    NOKEY("nokeys", null, "No Keys"), //$NON-NLS-1$
+    QWERTY("qwerty", null, "Qwerty"), //$NON-NLS-1$
+    TWELVEKEY("12key", "twelvekey", "12 Key"); //$NON-NLS-1$
 
-    private String mValue;
+    private String mValue, mValue2;
     private String mDisplayValue;
 
-    private Keyboard(String value, String displayValue) {
+    private Keyboard(String value, String value2, String displayValue) {
         mValue = value;
+        mValue2 = value2;
         mDisplayValue = displayValue;
     }
 
@@ -39,9 +40,10 @@ public enum Keyboard {
      * @return the enum for the qualifier value or null if no matching was found.
      */
     public static Keyboard getEnum(String value) {
-        for (Keyboard orient : values()) {
-            if (orient.mValue.equals(value)) {
-                return orient;
+        for (Keyboard kbrd : values()) {
+            if (kbrd.mValue.equals(value) ||
+                    (kbrd.mValue2 != null && kbrd.mValue2.equals(value))) {
+                return kbrd;
             }
         }
 
index 47340eb..f137928 100644 (file)
@@ -46,7 +46,8 @@ public final class AndroidManifest {
     public final static String NODE_USES_SDK = "uses-sdk";
     public final static String NODE_INSTRUMENTATION = "instrumentation";
     public final static String NODE_USES_LIBRARY = "uses-library";
-    public static final String NODE_SUPPORTS_SCREENS = "supports-screens";
+    public final static String NODE_SUPPORTS_SCREENS = "supports-screens";
+    public final static String NODE_USES_CONFIGURATION = "uses-configuration";
 
     public final static String ATTRIBUTE_PACKAGE = "package";
     public final static String ATTRIBUTE_VERSIONCODE = "versionCode";
@@ -56,11 +57,16 @@ public final class AndroidManifest {
     public final static String ATTRIBUTE_MIN_SDK_VERSION = "minSdkVersion";
     public final static String ATTRIBUTE_TARGET_PACKAGE = "targetPackage";
     public final static String ATTRIBUTE_EXPORTED = "exported";
-    public final static String ATTRIBUTE_RESIZABLE = "resizeable";
+    public final static String ATTRIBUTE_RESIZEABLE = "resizeable";
     public final static String ATTRIBUTE_ANYDENSITY = "anyDensity";
     public final static String ATTRIBUTE_SMALLSCREENS = "smallScreens";
     public final static String ATTRIBUTE_NORMALSCREENS = "normalScreens";
     public final static String ATTRIBUTE_LARGESCREENS = "largeScreens";
+    public final static String ATTRIBUTE_REQ_5WAYNAV = "reqFiveWayNav";
+    public final static String ATTRIBUTE_REQ_NAVIGATION = "reqNavigation";
+    public final static String ATTRIBUTE_REQ_HARDKEYBOARD = "reqHardKeyboard";
+    public final static String ATTRIBUTE_REQ_KEYBOARDTYPE = "reqKeyboardType";
+    public final static String ATTRIBUTE_REQ_TOUCHSCREEN = "reqTouchScreen";
 
     /**
      * Returns the package for a given project.
index cd7bca4..e1c6aa4 100644 (file)
@@ -20,9 +20,13 @@ import com.android.sdklib.SdkConstants;
 import com.android.sdklib.io.IAbstractFile;
 import com.android.sdklib.io.IAbstractFolder;
 import com.android.sdklib.io.StreamException;
+import com.android.sdklib.resources.Keyboard;
+import com.android.sdklib.resources.Navigation;
+import com.android.sdklib.resources.TouchScreen;
 import com.android.sdklib.xml.ManifestData.Activity;
 import com.android.sdklib.xml.ManifestData.Instrumentation;
 import com.android.sdklib.xml.ManifestData.SupportsScreens;
+import com.android.sdklib.xml.ManifestData.UsesConfiguration;
 
 import org.xml.sax.Attributes;
 import org.xml.sax.ErrorHandler;
@@ -76,8 +80,8 @@ public class AndroidManifestParser {
     /**
      * XML error & data handler used when parsing the AndroidManifest.xml file.
      * <p/>
-     * This serves both as an {@link XmlErrorHandler} to report errors and as a data repository
-     * to collect data from the manifest.
+     * During parsing this will fill up the {@link ManifestData} object given to the constructor
+     * and call out errors to the given {@link ManifestErrorHandler}.
      */
     private static class ManifestHandler extends DefaultHandler {
 
@@ -90,7 +94,7 @@ public class AndroidManifestParser {
         private Locator mLocator;
 
         /**
-         * Creates a new {@link ManifestHandler}, which is also an {@link XmlErrorHandler}.
+         * Creates a new {@link ManifestHandler}.
          *
          * @param manifestFile The manifest file being parsed. Can be null.
          * @param errorListener An optional error listener.
@@ -173,8 +177,13 @@ public class AndroidManifestParser {
                                         true /* hasNamespace */);
                             } else if (AndroidManifest.NODE_INSTRUMENTATION.equals(localName)) {
                                 processInstrumentationNode(attributes);
+
                             } else if (AndroidManifest.NODE_SUPPORTS_SCREENS.equals(localName)) {
                                 processSupportsScreensNode(attributes);
+
+                            } else if (AndroidManifest.NODE_USES_CONFIGURATION.equals(localName)) {
+                                processUsesConfiguration(attributes);
+
                             }
                             break;
                         case LEVEL_ACTIVITY:
@@ -412,7 +421,7 @@ public class AndroidManifestParser {
 
             mManifestData.mSupportsScreens.mResizeable = Boolean.valueOf(
                     getAttributeValue(attributes,
-                            AndroidManifest.ATTRIBUTE_RESIZABLE, true /*hasNamespace*/));
+                            AndroidManifest.ATTRIBUTE_RESIZEABLE, true /*hasNamespace*/));
             mManifestData.mSupportsScreens.mAnyDensity = Boolean.valueOf(
                     getAttributeValue(attributes,
                             AndroidManifest.ATTRIBUTE_ANYDENSITY, true /*hasNamespace*/));
@@ -428,6 +437,30 @@ public class AndroidManifestParser {
         }
 
         /**
+         * Processes the supports-screens node.
+         * @param attributes the attributes for the supports-screens node.
+         */
+        private void processUsesConfiguration(Attributes attributes) {
+            mManifestData.mUsesConfiguration = new UsesConfiguration();
+
+            mManifestData.mUsesConfiguration.mReqFiveWayNav = Boolean.valueOf(
+                    getAttributeValue(attributes,
+                            AndroidManifest.ATTRIBUTE_REQ_5WAYNAV, true /*hasNamespace*/));
+            mManifestData.mUsesConfiguration.mReqNavigation = Navigation.getEnum(
+                    getAttributeValue(attributes,
+                            AndroidManifest.ATTRIBUTE_REQ_NAVIGATION, true /*hasNamespace*/));
+            mManifestData.mUsesConfiguration.mReqHardKeyboard = Boolean.valueOf(
+                    getAttributeValue(attributes,
+                            AndroidManifest.ATTRIBUTE_REQ_HARDKEYBOARD, true /*hasNamespace*/));
+            mManifestData.mUsesConfiguration.mReqKeyboardType = Keyboard.getEnum(
+                    getAttributeValue(attributes,
+                            AndroidManifest.ATTRIBUTE_REQ_KEYBOARDTYPE, true /*hasNamespace*/));
+            mManifestData.mUsesConfiguration.mReqTouchScreen = TouchScreen.getEnum(
+                    getAttributeValue(attributes,
+                            AndroidManifest.ATTRIBUTE_REQ_TOUCHSCREEN, true /*hasNamespace*/));
+        }
+
+        /**
          * Searches through the attributes list for a particular one and returns its value.
          * @param attributes the attribute list to search through
          * @param attributeName the name of the attribute to look for.
index 5101736..390a1ea 100644 (file)
 
 package com.android.sdklib.xml;
 
+import com.android.sdklib.resources.Keyboard;
+import com.android.sdklib.resources.Navigation;
+import com.android.sdklib.resources.TouchScreen;
+
 import java.util.ArrayList;
 import java.util.Set;
 import java.util.TreeSet;
@@ -45,6 +49,7 @@ public final class ManifestData {
     final ArrayList<String> mLibraries = new ArrayList<String>();
 
     SupportsScreens mSupportsScreens;
+    UsesConfiguration mUsesConfiguration;
 
     /**
      * Instrumentation info obtained from manifest
@@ -127,6 +132,9 @@ public final class ManifestData {
         }
     }
 
+    /**
+     * Class representing the <code>supports-screens</code> node in the manifest.
+     */
     public final static class SupportsScreens {
         Boolean mResizeable;
         Boolean mAnyDensity;
@@ -134,30 +142,86 @@ public final class ManifestData {
         Boolean mLargeScreens;
         Boolean mNormalScreens;
 
+        /**
+         * returns the value of the <code>resizeable</code> attribute or null if not present.
+         */
         public Boolean getResizeable() {
             return mResizeable;
         }
 
+        /**
+         * returns the value of the <code>anyDensity</code> attribute or null if not present.
+         */
         public Boolean getAnyDensity() {
             return mAnyDensity;
         }
 
+        /**
+         * returns the value of the <code>smallScreens</code> attribute or null if not present.
+         */
         public Boolean getSmallScreens() {
             return mSmallScreens;
         }
 
+        /**
+         * returns the value of the <code>normalScreens</code> attribute or null if not present.
+         */
         public Boolean getNormalScreens() {
             return mNormalScreens;
         }
 
+        /**
+         * returns the value of the <code>largeScreens</code> attribute or null if not present.
+         */
         public Boolean getLargeScreens() {
             return mLargeScreens;
         }
     }
 
+    /**
+     * Class representing the <code>uses-configuration</code> node in the manifest.
+     */
     public final static class UsesConfiguration {
         Boolean mReqFiveWayNav;
         Boolean mReqHardKeyboard;
+        Keyboard mReqKeyboardType;
+        TouchScreen mReqTouchScreen;
+        Navigation mReqNavigation;
+
+        /**
+         * returns the value of the <code>reqFiveWayNav</code> attribute or null if not present.
+         */
+        public Boolean getReqFiveWayNav() {
+            return mReqFiveWayNav;
+        }
+
+        /**
+         * returns the value of the <code>reqNavigation</code> attribute or null if not present.
+         */
+        public Navigation getReqNavigation() {
+            return mReqNavigation;
+        }
+
+        /**
+         * returns the value of the <code>reqHardKeyboard</code> attribute or null if not present.
+         */
+        public Boolean getReqHardKeyboard() {
+            return mReqHardKeyboard;
+        }
+
+        /**
+         * returns the value of the <code>reqKeyboardType</code> attribute or null if not present.
+         */
+        public Keyboard getReqKeyboardType() {
+            return mReqKeyboardType;
+        }
+
+        /**
+         * returns the value of the <code>reqTouchScreen</code> attribute or null if not present.
+         */
+        public TouchScreen getReqTouchScreen() {
+            return mReqTouchScreen;
+        }
     }
 
     /**
@@ -235,10 +299,22 @@ public final class ManifestData {
         return mLibraries.toArray(new String[mLibraries.size()]);
     }
 
+    /**
+     * Returns the {@link SupportsScreens} object representing the <code>supports-screens</code>
+     * node, or null if the node doesn't exist at all.
+     */
     public SupportsScreens getSupportsScreens() {
         return mSupportsScreens;
     }
 
+    /**
+     * Returns the {@link UsesConfiguration} object representing the <code>uses-configuration</code>
+     * node, or null if the node doesn't exist at all.
+     */
+    public UsesConfiguration getUsesConfiguration() {
+        return mUsesConfiguration;
+    }
+
     void addProcessName(String processName) {
         if (mProcesses == null) {
             mProcesses = new TreeSet<String>();
index 647aa74..8c69a9c 100644 (file)
 
 package com.android.sdklib.xml;
 
+import com.android.sdklib.resources.Keyboard;
+import com.android.sdklib.resources.Navigation;
+import com.android.sdklib.resources.TouchScreen;
+
 import java.io.InputStream;
 
 import junit.framework.TestCase;
@@ -95,6 +99,7 @@ public class AndroidManifestParserTest extends TestCase {
     public void testSupportsScreen() {
         ManifestData.SupportsScreens supportsScreens = mManifestTestApp.getSupportsScreens();
 
+        assertNotNull(supportsScreens);
         assertEquals(Boolean.TRUE, supportsScreens.getAnyDensity());
         assertEquals(Boolean.TRUE, supportsScreens.getResizeable());
         assertEquals(Boolean.TRUE, supportsScreens.getSmallScreens());
@@ -102,6 +107,17 @@ public class AndroidManifestParserTest extends TestCase {
         assertEquals(Boolean.TRUE, supportsScreens.getLargeScreens());
     }
 
+    public void testUsesConfiguration() {
+        ManifestData.UsesConfiguration usesConfig = mManifestTestApp.getUsesConfiguration();
+
+        assertNotNull(usesConfig);
+        assertEquals(Boolean.TRUE, usesConfig.getReqFiveWayNav());
+        assertEquals(Navigation.NONAV, usesConfig.getReqNavigation());
+        assertEquals(Boolean.TRUE, usesConfig.getReqHardKeyboard());
+        assertEquals(Keyboard.TWELVEKEY, usesConfig.getReqKeyboardType());
+        assertEquals(TouchScreen.FINGER, usesConfig.getReqTouchScreen());
+    }
+
     private void assertEquals(ManifestData.Activity lhs, ManifestData.Activity rhs) {
         assertTrue(lhs == rhs || (lhs != null && rhs != null));
         if (lhs != null && rhs != null) {