From 79c8c93587295a899fa89da8b31fbfb008b59ee6 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Wed, 6 Apr 2011 12:22:00 -0700 Subject: [PATCH] Move getViewParent/Index from RenderSession to Bridge. Also update the IProjectCallback to handle expandableListView. Change-Id: I36ca8733182bbd9d169fee3e709ebc532fef7b1e --- .../internal/editors/layout/ProjectCallback.java | 6 ++-- .../layoutRendering/ApiDemosRenderingTest.java | 3 +- .../editors/layout/gle2/CanvasViewInfoTest.java | 6 ++-- .../ide/common/rendering/LayoutLibrary.java | 36 +++++++++++++++++++++- .../android/ide/common/rendering/api/Bridge.java | 25 +++++++++++++++ .../ide/common/rendering/api/IProjectCallback.java | 17 +++++++--- .../ide/common/rendering/api/RenderSession.java | 23 -------------- 7 files changed, 82 insertions(+), 34 deletions(-) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/ProjectCallback.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/ProjectCallback.java index ca6982ffc..7b88a16ac 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/ProjectCallback.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/ProjectCallback.java @@ -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; } } diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java index 9b8f55422..a043e6d6e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java @@ -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; } } diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfoTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfoTest.java index ed0d67bd5..2df472ee2 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfoTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfoTest.java @@ -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)); diff --git a/ide_common/src/com/android/ide/common/rendering/LayoutLibrary.java b/ide_common/src/com/android/ide/common/rendering/LayoutLibrary.java index d9ffda718..3294cbe26 100644 --- a/ide_common/src/com/android/ide/common/rendering/LayoutLibrary.java +++ b/ide_common/src/com/android/ide/common/rendering/LayoutLibrary.java @@ -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> entry : map.entrySet()) { // ugly case but works. result.put(entry.getKey().getName(), - (Map)(Map) entry.getValue()); + (Map) entry.getValue()); } return result; diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java b/layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java index 48309cfc8..f04b2660d 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java @@ -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(); + } } diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/IProjectCallback.java b/layoutlib_api/src/com/android/ide/common/rendering/api/IProjectCallback.java index 144d31773..99a126709 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/IProjectCallback.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/IProjectCallback.java @@ -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 position. + * If there is only one type of items, this is the same as fullPosition. + * @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 fullChildPosition. * @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); } diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/RenderSession.java b/layoutlib_api/src/com/android/ide/common/rendering/api/RenderSession.java index a2e087c03..188909e90 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/RenderSession.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/RenderSession.java @@ -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. *

* The child is first inflated and then added to its new parent, at the given index -- 2.11.0