OSDN Git Service

Move getViewParent/Index from RenderSession to Bridge.
authorXavier Ducrohet <xav@android.com>
Wed, 6 Apr 2011 19:22:00 +0000 (12:22 -0700)
committerXavier Ducrohet <xav@android.com>
Wed, 6 Apr 2011 21:16:08 +0000 (14:16 -0700)
Also update the IProjectCallback to handle expandableListView.

Change-Id: I36ca8733182bbd9d169fee3e709ebc532fef7b1e

eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/ProjectCallback.java
eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java
eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfoTest.java
ide_common/src/com/android/ide/common/rendering/LayoutLibrary.java
layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java
layoutlib_api/src/com/android/ide/common/rendering/api/IProjectCallback.java
layoutlib_api/src/com/android/ide/common/rendering/api/RenderSession.java

index ca6982f..7b88a16 100644 (file)
@@ -340,7 +340,8 @@ public final class ProjectCallback extends LegacyCallback {
     }
 
     public Object getAdapterItemValue(ResourceReference adapterView, Object adapterCookie,
-            ResourceReference itemRef, int fullPosition, int typePosition,
+            ResourceReference itemRef,
+            int fullPosition, int typePosition, int fullChildPosition, int typeChildPosition,
             ResourceReference viewRef, ViewAttribute viewAttribute, Object defaultValue) {
         if (viewAttribute == ViewAttribute.TEXT && ((String) defaultValue).length() == 0) {
             return viewRef.getName() + " " + typePosition;
@@ -349,7 +350,8 @@ public final class ProjectCallback extends LegacyCallback {
         return null;
     }
 
-    public AdapterBinding getAdapterBinding(ResourceReference adapterView, Object adapterCookie) {
+    public AdapterBinding getAdapterBinding(ResourceReference adapterView, Object adapterCookie,
+            Object viewObject) {
         return null;
     }
 }
index 9b8f554..a043e6d 100644 (file)
@@ -131,12 +131,13 @@ public class ApiDemosRenderingTest extends SdkTestCase {
 
         public Object getAdapterItemValue(ResourceReference adapterView, Object adapterCookie,
                 ResourceReference itemRef, int fullPosition, int typePosition,
+                int fullChildPosition, int typeChildPosition,
                 ResourceReference viewRef, ViewAttribute viewAttribute, Object defaultValue) {
             return null;
         }
 
         public AdapterBinding getAdapterBinding(ResourceReference adapterView,
-                Object adapterCookie) {
+                Object adapterCookie, Object viewObject) {
             return null;
         }
     }
index ed0d67b..2df472e 100644 (file)
@@ -17,9 +17,9 @@
 package com.android.ide.eclipse.adt.internal.editors.layout.gle2;
 
 import com.android.ide.common.rendering.api.Capability;
+import com.android.ide.common.rendering.api.DataBindingItem;
 import com.android.ide.common.rendering.api.MergeCookie;
 import com.android.ide.common.rendering.api.ViewInfo;
-import com.android.ide.common.rendering.api.AdapterBinding.AdapterItemReference;
 import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor;
 import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor;
 import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.ViewElementDescriptor;
@@ -675,12 +675,12 @@ public class CanvasViewInfoTest extends TestCase {
         UiViewElementNode childNode = createNode(rootNode, "ListView", false);
         /*UiViewElementNode grandChildNode =*/ createNode(childNode, "LinearLayout", false);
         /*UiViewElementNode greatGrandChildNode =*/ createNode(childNode, "TextView", false);
-        AdapterItemReference adapterItem = new AdapterItemReference("foo");
+        DataBindingItem dataBindingItem = new DataBindingItem("foo");
 
         ViewInfo root = new ViewInfo("FrameLayout", rootNode, 0, 50, 320, 480);
         ViewInfo child = new ViewInfo("ListView", childNode, 0, 0, 320, 430);
         root.setChildren(Collections.singletonList(child));
-        ViewInfo grandChild = new ViewInfo("LinearLayout", adapterItem, 0, 0, 320, 17);
+        ViewInfo grandChild = new ViewInfo("LinearLayout", dataBindingItem, 0, 0, 320, 17);
         child.setChildren(Collections.singletonList(grandChild));
         ViewInfo greatGrandChild = new ViewInfo("Button", null, 0, 0, 73, 17);
         grandChild.setChildren(Collections.singletonList(greatGrandChild));
index d9ffda7..3294cbe 100644 (file)
@@ -16,6 +16,8 @@
 
 package com.android.ide.common.rendering;
 
+import static com.android.ide.common.rendering.api.Result.Status.NOT_IMPLEMENTED;
+
 import com.android.ide.common.log.ILogger;
 import com.android.ide.common.rendering.api.Bridge;
 import com.android.ide.common.rendering.api.Capability;
@@ -321,6 +323,38 @@ public class LayoutLibrary {
         }
     }
 
+    /**
+     * Utility method returning the parent of a given view object.
+     *
+     * @param viewObject the object for which to return the parent.
+     *
+     * @return a {@link Result} indicating the status of the action, and if success, the parent
+     *      object in {@link Result#getData()}
+     */
+    public Result getViewParent(Object viewObject) {
+        if (mBridge != null) {
+            return mBridge.getViewParent(viewObject);
+        }
+
+        return NOT_IMPLEMENTED.createResult();
+    }
+
+    /**
+     * Utility method returning the index of a given view in its parent.
+     * @param viewObject the object for which to return the index.
+     *
+     * @return a {@link Result} indicating the status of the action, and if success, the index in
+     *      the parent in {@link Result#getData()}
+     */
+    public Result getViewIndex(Object viewObject) {
+        if (mBridge != null) {
+            return mBridge.getViewIndex(viewObject);
+        }
+
+        return NOT_IMPLEMENTED.createResult();
+    }
+
+
     // ------ Implementation
 
     private LayoutLibrary(Bridge bridge, ILayoutBridge legacyBridge, ClassLoader classLoader,
@@ -462,7 +496,7 @@ public class LayoutLibrary {
         for (Entry<ResourceType, Map<String, ResourceValue>> entry : map.entrySet()) {
             // ugly case but works.
             result.put(entry.getKey().getName(),
-                    (Map<String, IResourceValue>)(Map) entry.getValue());
+                    (Map) entry.getValue());
         }
 
         return result;
index 48309cf..f04b266 100644 (file)
@@ -17,6 +17,8 @@
 package com.android.ide.common.rendering.api;
 
 
+import static com.android.ide.common.rendering.api.Result.Status.NOT_IMPLEMENTED;
+
 import com.android.ide.common.rendering.api.Result.Status;
 
 import java.awt.image.BufferedImage;
@@ -109,4 +111,27 @@ public abstract class Bridge {
     public void clearCaches(Object projectKey) {
 
     }
+
+    /**
+     * Utility method returning the parent of a given view object.
+     *
+     * @param viewObject the object for which to return the parent.
+     *
+     * @return a {@link Result} indicating the status of the action, and if success, the parent
+     *      object in {@link Result#getData()}
+     */
+    public Result getViewParent(Object viewObject) {
+        return NOT_IMPLEMENTED.createResult();
+    }
+
+    /**
+     * Utility method returning the index of a given view in its parent.
+     * @param viewObject the object for which to return the index.
+     *
+     * @return a {@link Result} indicating the status of the action, and if success, the index in
+     *      the parent in {@link Result#getData()}
+     */
+    public Result getViewIndex(Object viewObject) {
+        return NOT_IMPLEMENTED.createResult();
+    }
 }
index 144d317..99a1267 100644 (file)
@@ -100,7 +100,12 @@ public interface IProjectCallback {
      * @param itemRef the {@link ResourceReference} for the layout used by the adapter item.
      * @param fullPosition the position of the item in the full list.
      * @param typePosition the position of the item if only items of the same type are considered.
-     *     If there is only one type of items, this is the same as <var>position</var>.
+     *     If there is only one type of items, this is the same as <var>fullPosition</var>.
+     * @param fullChildPosition the position of the item in the full children list. This is only
+     *     valid if the adapter view is an ExpandableListView.
+     * @param typeChildPosition the position of the child item if only items of the same type are
+     *     considered. This is only valid if the adapter view is an ExpandableListView.
+     *     If there is only one type of items, this is the same as <var>fullChildPosition</var>.
      * @param viewRef The {@link ResourceReference} for the view we're trying to fill.
      * @param ViewAttribute the attribute being queried.
      * @param defaultValue the default value for this attribute. The object class matches the
@@ -110,7 +115,9 @@ public interface IProjectCallback {
      * @see ViewAttribute#getAttributeClass()
      */
     Object getAdapterItemValue(ResourceReference adapterView, Object adapterCookie,
-            ResourceReference itemRef, int fullPosition, int typePosition,
+            ResourceReference itemRef,
+            int fullPosition, int typePosition,
+            int fullChildPosition, int typeChildPosition,
             ResourceReference viewRef, ViewAttribute viewAttribute, Object defaultValue);
 
     /**
@@ -118,9 +125,11 @@ public interface IProjectCallback {
      * This is only called if {@link SessionParams} does not have an {@link AdapterBinding} for
      * the given {@link ResourceReference} already.
      *
-     * @param adapterView the adapter view to return the adapter binding for.
+     * @param adapterViewRef the reference of adapter view to return the adapter binding for.
      * @param adapterCookie the view cookie for this particular view.
+     * @param viewObject the view object for the adapter.
      * @return an adapter binding for the given view or null if there's no data.
      */
-    AdapterBinding getAdapterBinding(ResourceReference adapterView, Object adapterCookie);
+    AdapterBinding getAdapterBinding(ResourceReference adapterViewRef, Object adapterCookie,
+            Object viewObject);
 }
index a2e087c..188909e 100644 (file)
@@ -162,29 +162,6 @@ public class RenderSession {
     }
 
     /**
-     * Returns the View parent.
-     *
-     * @param viewObject the object for which to return the parent.
-     *
-     * @return a {@link Result} indicating the status of the action, and if success, the parent
-     *      object in {@link Result#getData()}
-     */
-    public Result getViewParent(Object viewObject) {
-        return NOT_IMPLEMENTED.createResult();
-    }
-
-    /**
-     * Returns the index of a given view it its parent.
-     * @param viewObject the object for which to return the index.
-     *
-     * @return a {@link Result} indicating the status of the action, and if success, the index in
-     *      the parent in {@link Result#getData()}
-     */
-    public Result getViewIndex(Object viewObject) {
-        return NOT_IMPLEMENTED.createResult();
-    }
-
-    /**
      * Inserts a new child in a ViewGroup object, and renders the result.
      * <p/>
      * The child is first inflated and then added to its new parent, at the given <var>index<var>