OSDN Git Service

Fix ADT to build with the new layoutlib API.
authorXavier Ducrohet <xav@android.com>
Wed, 10 Nov 2010 00:18:26 +0000 (16:18 -0800)
committerXavier Ducrohet <xav@android.com>
Wed, 10 Nov 2010 00:18:26 +0000 (16:18 -0800)
Also make the custom cleaning of the layoutlib looper
only done through API 4. Newer bridge can do their own clean up.

Change-Id: I1ee128e09912df53e110094d8909f81bc6a788e3

eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/UiElementPullParser.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/WidgetPullParser.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/sdk/AndroidTargetData.java

index f18bc6f..5f93387 100644 (file)
@@ -154,6 +154,14 @@ public final class UiElementPullParser extends BasePullParser {
         return getCurrentNode();
     }
 
+    /**
+     * This implementation does nothing for now as all the embedded XML will use a normal KXML
+     * parser.
+     */
+    public IXmlPullParser getParser(String layoutName) {
+        return null;
+    }
+
     // ------------- XmlPullParser --------
 
     public String getPositionDescription() {
index 4343ce7..2d8a2b2 100644 (file)
@@ -53,6 +53,11 @@ public class WidgetPullParser extends BasePullParser {
         return mDescriptor;
     }
 
+    public IXmlPullParser getParser(String layoutName) {
+        // there's no embedded layout for a single widget.
+        return null;
+    }
+
     public int getAttributeCount() {
         return mAttributes.length; // text attribute
     }
index c388545..a9dc43e 100644 (file)
@@ -63,19 +63,21 @@ public class AndroidTargetData {
          * versions of the layoutlib.
          */
         public void cleanUp() {
-            try {
-                Class<?> looperClass = classLoader.loadClass("android.os.Looper"); //$NON-NLS-1$
-                Field threadLocalField = looperClass.getField("sThreadLocal"); //$NON-NLS-1$
-                if (threadLocalField != null) {
-                    threadLocalField.setAccessible(true);
-                    // get object. Field is static so no need to pass an object
-                    ThreadLocal<?> threadLocal = (ThreadLocal<?>) threadLocalField.get(null);
-                    if (threadLocal != null) {
-                        threadLocal.remove();
+            if (apiLevel <= 4) {
+                try {
+                    Class<?> looperClass = classLoader.loadClass("android.os.Looper"); //$NON-NLS-1$
+                    Field threadLocalField = looperClass.getField("sThreadLocal"); //$NON-NLS-1$
+                    if (threadLocalField != null) {
+                        threadLocalField.setAccessible(true);
+                        // get object. Field is static so no need to pass an object
+                        ThreadLocal<?> threadLocal = (ThreadLocal<?>) threadLocalField.get(null);
+                        if (threadLocal != null) {
+                            threadLocal.remove();
+                        }
                     }
+                } catch (Exception e) {
+                    AdtPlugin.log(e, "Failed to clean up bridge for API level %d", apiLevel);
                 }
-            } catch (Exception e) {
-                AdtPlugin.log(e, "Failed to clean up bridge for API level %d", apiLevel);
             }
         }
     }