diff options
Diffstat (limited to 'layoutlib_api/src')
12 files changed, 566 insertions, 123 deletions
diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/AdapterBinding.java b/layoutlib_api/src/com/android/ide/common/rendering/api/AdapterBinding.java new file mode 100644 index 0000000..9481246 --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/AdapterBinding.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ide.common.rendering.api; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * Describe the content of the dynamic android.widget.Adapter used to fill + * android.widget.AdapterView + */ +public class AdapterBinding implements Iterable<DataBindingItem> { + + private final int mRepeatCount; + private final List<ResourceReference> mHeaders = new ArrayList<ResourceReference>(); + private final List<DataBindingItem> mItems = new ArrayList<DataBindingItem>(); + private final List<ResourceReference> mFooters = new ArrayList<ResourceReference>(); + + public AdapterBinding(int repeatCount) { + mRepeatCount = repeatCount; + } + + public int getRepeatCount() { + return mRepeatCount; + } + + public void addHeader(ResourceReference layoutInfo) { + mHeaders.add(layoutInfo); + } + + public int getHeaderCount() { + return mHeaders.size(); + } + + public ResourceReference getHeaderAt(int index) { + return mHeaders.get(index); + } + + public void addItem(DataBindingItem item) { + mItems.add(item); + } + + public int getItemCount() { + return mItems.size(); + } + + public DataBindingItem getItemAt(int index) { + return mItems.get(index); + } + + public void addFooter(ResourceReference layoutInfo) { + mFooters.add(layoutInfo); + } + + public int getFooterCount() { + return mFooters.size(); + } + + public ResourceReference getFooterAt(int index) { + return mFooters.get(index); + } + + public Iterator<DataBindingItem> iterator() { + return mItems.iterator(); + } +} 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 48309cf..c044353 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,40 @@ 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(); + } + + /** + * Utility method returning the baseline value for a given view object. This basically returns + * View.getBaseline(). + * + * @param viewObject the object for which to return the index. + * + * @return the baseline value or -1 if not applicable to the view object or if this layout + * library does not implement this method. + */ + public int getViewBaseline(Object viewObject) { + return -1; + } } diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/Capability.java b/layoutlib_api/src/com/android/ide/common/rendering/api/Capability.java index ff6777b..6620571 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/Capability.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/Capability.java @@ -24,38 +24,41 @@ public enum Capability { /** Ability to render at full size, as required by the layout, and unbound by the screen */ UNBOUND_RENDERING, /** Ability to override the background of the rendering with transparency using - * {@link SceneParams#setCustomBackgroundColor(int)} */ + * {@link SessionParams#setOverrideBgColor(int)} */ CUSTOM_BACKGROUND_COLOR, - /** Ability to call {@link LayoutScene#render()} and {@link LayoutScene#render(long)}. */ + /** Ability to call {@link RenderSession#render()} and {@link RenderSession#render(long)}. */ RENDER, + /** Ability to ask for a layout only with no rendering through + * {@link SessionParams#setLayoutOnly()} + */ + LAYOUT_ONLY, /** - * Ability to control embedded layout parsers through {@link IXmlPullParser#getParser(String)} + * Ability to control embedded layout parsers through {@link ILayoutPullParser#getParser(String)} */ EMBEDDED_LAYOUT, /** Ability to call<br> - * {@link LayoutScene#insertChild(Object, IXmlPullParser, int, com.android.layoutlib.api.LayoutScene.IAnimationListener)}<br> - * {@link LayoutScene#moveChild(Object, Object, int, java.util.Map, com.android.layoutlib.api.LayoutScene.IAnimationListener)}<br> - * {@link LayoutScene#removeChild(Object, com.android.layoutlib.api.LayoutScene.IAnimationListener)}<br> - * {@link LayoutScene#setProperty(Object, String, String)}<br> + * {@link RenderSession#insertChild(Object, ILayoutPullParser, int, IAnimationListener)}<br> + * {@link RenderSession#moveChild(Object, Object, int, java.util.Map, IAnimationListener)}<br> + * {@link RenderSession#setProperty(Object, String, String)}<br> * The method that receives an animation listener can only use it if the * ANIMATED_VIEW_MANIPULATION, or FULL_ANIMATED_VIEW_MANIPULATION is also supported. - * * */ VIEW_MANIPULATION, /** Ability to play animations with<br> - * {@link LayoutScene#animate(Object, String, boolean, com.android.layoutlib.api.LayoutScene.IAnimationListener)} + * {@link RenderSession#animate(Object, String, boolean, IAnimationListener)} */ PLAY_ANIMATION, /** * Ability to manipulate views with animation, as long as the view does not change parent. - * {@link LayoutScene#insertChild(Object, IXmlPullParser, int, com.android.layoutlib.api.LayoutScene.IAnimationListener)}<br> - * {@link LayoutScene#moveChild(Object, Object, int, java.util.Map, com.android.layoutlib.api.LayoutScene.IAnimationListener)}<br> - * {@link LayoutScene#removeChild(Object, com.android.layoutlib.api.LayoutScene.IAnimationListener)}<br> + * {@link RenderSession#insertChild(Object, ILayoutPullParser, int, IAnimationListener)}<br> + * {@link RenderSession#moveChild(Object, Object, int, java.util.Map, IAnimationListener)}<br> + * {@link RenderSession#removeChild(Object, IAnimationListener)}<br> */ ANIMATED_VIEW_MANIPULATION, /** * Ability to move views (even into a different ViewGroup) with animation. - * see {@link LayoutScene#moveChild(Object, Object, int, java.util.Map, com.android.layoutlib.api.LayoutScene.IAnimationListener)} + * see {@link RenderSession#moveChild(Object, Object, int, java.util.Map, IAnimationListener)} */ - FULL_ANIMATED_VIEW_MANIPULATION; + FULL_ANIMATED_VIEW_MANIPULATION, + ADAPTER_BINDING; } diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/DataBindingItem.java b/layoutlib_api/src/com/android/ide/common/rendering/api/DataBindingItem.java new file mode 100644 index 0000000..93569bd --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/DataBindingItem.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ide.common.rendering.api; + +import com.android.resources.ResourceType; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +/** + * A data binding item. It contain a {@link ResourceReference} to the view used to represent it. + * It also contains how many items of this type the AdapterView should display. + * + * It can also contain an optional list of children in case the AdapterView is an + * ExpandableListView. In this case, the count value is used as a repeat count for the children, + * similar to {@link AdapterBinding#getRepeatCount()}. + * + */ +public class DataBindingItem implements Iterable<DataBindingItem> { + private final ResourceReference mReference; + private final int mCount; + private List<DataBindingItem> mChildren; + + public DataBindingItem(ResourceReference reference, int count) { + mReference = reference; + mCount = count; + } + + public DataBindingItem(String name, boolean platformLayout, int count) { + this(new ResourceReference(name, platformLayout), count); + } + + public DataBindingItem(String name, boolean platformLayout) { + this(name, platformLayout, 1); + } + + public DataBindingItem(String name, int count) { + this(name, false /*platformLayout*/, count); + } + + public DataBindingItem(String name) { + this(name, false /*platformLayout*/, 1); + } + + /** + * Returns the {@link ResourceReference} for the view. The {@link ResourceType} for the + * referenced resource is implied to be {@link ResourceType#LAYOUT}. + */ + public ResourceReference getViewReference() { + return mReference; + } + + /** + * The repeat count for this object or the repeat count for the children if there are any. + */ + public int getCount() { + return mCount; + } + + public void addChild(DataBindingItem child) { + if (mChildren == null) { + mChildren = new ArrayList<DataBindingItem>(); + } + + mChildren.add(child); + } + + public List<DataBindingItem> getChildren() { + if (mChildren != null) { + return mChildren; + } + + return Collections.emptyList(); + } + + public Iterator<DataBindingItem> iterator() { + List<DataBindingItem> list = getChildren(); + return list.iterator(); + } +} diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/DensityBasedResourceValue.java b/layoutlib_api/src/com/android/ide/common/rendering/api/DensityBasedResourceValue.java index ca60640..f63f16f 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/DensityBasedResourceValue.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/DensityBasedResourceValue.java @@ -41,6 +41,7 @@ public class DensityBasedResourceValue extends ResourceValue implements IDensity /** Legacy method, do not call * @deprecated use {@link #getResourceDensity()} instead. */ + @Deprecated public Density getDensity() { return Density.getEnum(mDensity.getDpiValue()); } @@ -51,4 +52,35 @@ public class DensityBasedResourceValue extends ResourceValue implements IDensity + getResourceType() + "/" + getName() + " = " + getValue() + " (density:" + mDensity +", framework:" + isFramework() + ")]"; } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((mDensity == null) ? 0 : mDensity.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + DensityBasedResourceValue other = (DensityBasedResourceValue) obj; + if (mDensity == null) { + if (other.mDensity != null) + return false; + } else if (!mDensity.equals(other.mDensity)) + return false; + return true; + } } diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/ILayoutPullParser.java b/layoutlib_api/src/com/android/ide/common/rendering/api/ILayoutPullParser.java index 4b033d9..574f9bb 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/ILayoutPullParser.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/ILayoutPullParser.java @@ -38,8 +38,9 @@ public interface ILayoutPullParser extends XmlPullParser { * @param layoutName the name of the layout. * @return returns a custom parser or null if no custom parsers are needed. * - * @since 5 + * @deprecated use {@link IProjectCallback#getParser(String)} instead */ + @Deprecated ILayoutPullParser getParser(String layoutName); } 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 0ec214f..b91b598 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 @@ -19,6 +19,8 @@ package com.android.ide.common.rendering.api; import com.android.resources.ResourceType; import com.android.util.Pair; +import java.net.URL; + /** * Callback for project information needed by the Layout Library. * Classes implementing this interface provide methods giving access to some project data, like @@ -26,6 +28,23 @@ import com.android.util.Pair; */ public interface IProjectCallback { + public enum ViewAttribute { + TEXT(String.class), + IS_CHECKED(Boolean.class), + SRC(URL.class), + COLOR(Integer.class); + + private final Class<?> mClass; + + private ViewAttribute(Class<?> theClass) { + mClass = theClass; + } + + public Class<?> getAttributeClass() { + return mClass; + } + } + /** * Loads a custom view with the given constructor signature and arguments. * @param name The fully qualified name of the class. @@ -73,4 +92,52 @@ public interface IProjectCallback { * @return an Integer containing the resource Id, or <code>null</code> if not found. */ Integer getResourceId(ResourceType type, String name); + + /** + * Returns a custom parser for the layout of the given name. + * @param layoutName the name of the layout. + * @return returns a custom parser or null if no custom parsers are needed. + */ + ILayoutPullParser getParser(String layoutName); + + /** + * Returns the value of an item used by an adapter. + * @param adapterView The {@link ResourceReference} for the adapter view info. + * @param adapterCookie the view cookie for this particular view. + * @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 positionPerType 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>fullPosition</var>. + * @param fullParentPosition the full position of the item's parent. This is only + * valid if the adapter view is an ExpandableListView. + * @param parentPositionPerType the position of the parent's item, only considering items + * of the same type. 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>fullParentPosition</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 + * class associated with the {@link ViewAttribute}. + * @return the item value or null if there's no value. + * + * @see ViewAttribute#getAttributeClass() + */ + Object getAdapterItemValue(ResourceReference adapterView, Object adapterCookie, + ResourceReference itemRef, + int fullPosition, int positionPerType, + int fullParentPosition, int parentPositionPerType, + ResourceReference viewRef, ViewAttribute viewAttribute, Object defaultValue); + + /** + * Returns an adapter binding for a given adapter view. + * This is only called if {@link SessionParams} does not have an {@link AdapterBinding} for + * the given {@link ResourceReference} already. + * + * @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 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 a2e087c..188909e 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. * <p/> * The child is first inflated and then added to its new parent, at the given <var>index<var> diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/ResourceReference.java b/layoutlib_api/src/com/android/ide/common/rendering/api/ResourceReference.java new file mode 100644 index 0000000..f22f51e --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/ResourceReference.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ide.common.rendering.api; + +/** + * A resource reference. This contains the String ID of the resource and whether this is a framework + * reference. + * This is an immutable class. + * + */ +public class ResourceReference { + private final String mName; + private final boolean mIsFramework; + + /** + * Builds a resource reference. + * @param name the name of the resource + * @param isFramework whether the reference is to a framework resource. + */ + public ResourceReference(String name, boolean isFramework) { + mName = name; + mIsFramework = isFramework; + } + + /** + * Builds a non-framework resource reference. + * @param name the name of the resource + */ + public ResourceReference(String name) { + this(name, false /*platformLayout*/); + } + + /** + * Returns the name of the resource, as defined in the XML. + */ + public final String getName() { + return mName; + } + + /** + * Returns whether the resource is a framework resource (<code>true</code>) or a project + * resource (<code>false</false>). + */ + public final boolean isFramework() { + return mIsFramework; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (mIsFramework ? 1231 : 1237); + result = prime * result + ((mName == null) ? 0 : mName.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ResourceReference other = (ResourceReference) obj; + if (mIsFramework != other.mIsFramework) + return false; + if (mName == null) { + if (other.mName != null) + return false; + } else if (!mName.equals(other.mName)) + return false; + return true; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "ResourceReference [" + mName + " (framework:" + mIsFramework+ ")]"; + } +} diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/ResourceValue.java b/layoutlib_api/src/com/android/ide/common/rendering/api/ResourceValue.java index f15d903..bb7dab4 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/ResourceValue.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/ResourceValue.java @@ -23,23 +23,19 @@ import com.android.resources.ResourceType; * Represents an android resource with a name and a string value. */ @SuppressWarnings("deprecation") -public class ResourceValue implements IResourceValue { +public class ResourceValue extends ResourceReference implements IResourceValue { private final ResourceType mType; - private final String mName; private String mValue = null; - private final boolean mIsFramwork; - public ResourceValue(ResourceType type, String name, boolean isFramwork) { + public ResourceValue(ResourceType type, String name, boolean isFramework) { + super(name, isFramework); mType = type; - mName = name; - mIsFramwork = isFramwork; } public ResourceValue(ResourceType type, String name, String value, boolean isFramework) { + super(name, isFramework); mType = type; - mName = name; mValue = value; - mIsFramwork = isFramework; } public ResourceType getResourceType() { @@ -50,18 +46,12 @@ public class ResourceValue implements IResourceValue { * Returns the type of the resource. For instance "drawable", "color", etc... * @deprecated use {@link #getResourceType()} instead. */ + @Deprecated public String getType() { return mType.getName(); } /** - * Returns the name of the resource, as defined in the XML. - */ - public final String getName() { - return mName; - } - - /** * Returns the value of the resource, as defined in the XML. This can be <code>null</code> */ public final String getValue() { @@ -69,14 +59,6 @@ public class ResourceValue implements IResourceValue { } /** - * Returns whether the resource is a framework resource (<code>true</code>) or a project - * resource (<code>false</false>). - */ - public final boolean isFramework() { - return mIsFramwork; - } - - /** * Sets the value of the resource. * @param value the new value */ @@ -94,9 +76,44 @@ public class ResourceValue implements IResourceValue { @Override public String toString() { - return "ResourceValue [" + mType + "/" + mName + " = " + mValue - + " (framework:" + mIsFramwork + ")]"; + return "ResourceValue [" + mType + "/" + getName() + " = " + mValue //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + " (framework:" + isFramework() + ")]"; //$NON-NLS-1$ //$NON-NLS-2$ } + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((mType == null) ? 0 : mType.hashCode()); + result = prime * result + ((mValue == null) ? 0 : mValue.hashCode()); + return result; + } + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + ResourceValue other = (ResourceValue) obj; + if (mType == null) { + if (other.mType != null) + return false; + } else if (!mType.equals(other.mType)) + return false; + if (mValue == null) { + if (other.mValue != null) + return false; + } else if (!mValue.equals(other.mValue)) + return false; + return true; + } } diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/SessionParams.java b/layoutlib_api/src/com/android/ide/common/rendering/api/SessionParams.java index 9446ff5..f4f6b5c 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/SessionParams.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/SessionParams.java @@ -18,9 +18,12 @@ package com.android.ide.common.rendering.api; import com.android.resources.Density; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + /** * Rendering parameters for a {@link RenderSession}. - * */ public class SessionParams extends RenderParams { @@ -47,69 +50,94 @@ public class SessionParams extends RenderParams { } } - private final ILayoutPullParser mLayoutDescription; private final RenderingMode mRenderingMode; + private boolean mLayoutOnly = false; + private Map<ResourceReference, AdapterBinding> mAdapterBindingMap; /** - * - * @param layoutDescription the {@link ILayoutPullParser} letting the LayoutLib Bridge visit the - * layout file. - * @param renderingMode The rendering mode. - * @param projectKey An Object identifying the project. This is used for the cache mechanism. - * @param screenWidth the screen width - * @param screenHeight the screen height - * @param density the density factor for the screen. - * @param xdpi the screen actual dpi in X - * @param ydpi the screen actual dpi in Y - * @param themeName The name of the theme to use. - * @param isProjectTheme true if the theme is a project theme, false if it is a framework theme. - * @param projectResources the resources of the project. The map contains (String, map) pairs - * where the string is the type of the resource reference used in the layout file, and the - * map contains (String, {@link ResourceValue}) pairs where the key is the resource name, - * and the value is the resource value. - * @param frameworkResources the framework resources. The map contains (String, map) pairs - * where the string is the type of the resource reference used in the layout file, and the map - * contains (String, {@link ResourceValue}) pairs where the key is the resource name, and the - * value is the resource value. - * @param projectCallback The {@link IProjectCallback} object to get information from - * the project. - * @param minSdkVersion the minSdkVersion of the project - * @param targetSdkVersion the targetSdkVersion of the project - * @param log the object responsible for displaying warning/errors to the user. - */ - public SessionParams( - ILayoutPullParser layoutDescription, - RenderingMode renderingMode, - Object projectKey, - int screenWidth, int screenHeight, - Density density, float xdpi, float ydpi, - RenderResources renderResources, - IProjectCallback projectCallback, - int minSdkVersion, int targetSdkVersion, - LayoutLog log) { - super(projectKey, screenWidth, screenHeight, density, xdpi, ydpi, - renderResources, projectCallback, minSdkVersion, targetSdkVersion, log); - - mLayoutDescription = layoutDescription; - mRenderingMode = renderingMode; - - } - - public SessionParams(SessionParams params) { - super(params); - mLayoutDescription = params.mLayoutDescription; - mRenderingMode = params.mRenderingMode; - } - - public ILayoutPullParser getLayoutDescription() { - return mLayoutDescription; - } - - public RenderingMode getRenderingMode() { - return mRenderingMode; - } + * + * @param layoutDescription the {@link ILayoutPullParser} letting the LayoutLib Bridge visit the + * layout file. + * @param renderingMode The rendering mode. + * @param projectKey An Object identifying the project. This is used for the cache mechanism. + * @param screenWidth the screen width + * @param screenHeight the screen height + * @param density the density factor for the screen. + * @param xdpi the screen actual dpi in X + * @param ydpi the screen actual dpi in Y + * @param themeName The name of the theme to use. + * @param isProjectTheme true if the theme is a project theme, false if it is a framework theme. + * @param projectResources the resources of the project. The map contains (String, map) pairs + * where the string is the type of the resource reference used in the layout file, and the + * map contains (String, {@link ResourceValue}) pairs where the key is the resource name, + * and the value is the resource value. + * @param frameworkResources the framework resources. The map contains (String, map) pairs + * where the string is the type of the resource reference used in the layout file, and the map + * contains (String, {@link ResourceValue}) pairs where the key is the resource name, and the + * value is the resource value. + * @param projectCallback The {@link IProjectCallback} object to get information from + * the project. + * @param minSdkVersion the minSdkVersion of the project + * @param targetSdkVersion the targetSdkVersion of the project + * @param log the object responsible for displaying warning/errors to the user. + */ + public SessionParams( + ILayoutPullParser layoutDescription, + RenderingMode renderingMode, + Object projectKey, + int screenWidth, int screenHeight, + Density density, float xdpi, float ydpi, + RenderResources renderResources, + IProjectCallback projectCallback, + int minSdkVersion, int targetSdkVersion, + LayoutLog log) { + super(projectKey, screenWidth, screenHeight, density, xdpi, ydpi, + renderResources, projectCallback, minSdkVersion, targetSdkVersion, log); + + mLayoutDescription = layoutDescription; + mRenderingMode = renderingMode; + } + + public SessionParams(SessionParams params) { + super(params); + mLayoutDescription = params.mLayoutDescription; + mRenderingMode = params.mRenderingMode; + if (params.mAdapterBindingMap != null) { + mAdapterBindingMap = new HashMap<ResourceReference, AdapterBinding>( + params.mAdapterBindingMap); + } + } + + public ILayoutPullParser getLayoutDescription() { + return mLayoutDescription; + } + + public RenderingMode getRenderingMode() { + return mRenderingMode; + } + + public void setLayoutOnly() { + mLayoutOnly = true; + } + + public boolean isLayoutOnly() { + return mLayoutOnly; + } + public void addAdapterBinding(ResourceReference reference, AdapterBinding data) { + if (mAdapterBindingMap == null) { + mAdapterBindingMap = new HashMap<ResourceReference, AdapterBinding>(); + } + mAdapterBindingMap.put(reference, data); + } + public Map<ResourceReference, AdapterBinding> getAdapterBindings() { + if (mAdapterBindingMap == null) { + return Collections.emptyMap(); + } + + return Collections.unmodifiableMap(mAdapterBindingMap); + } } diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/StyleResourceValue.java b/layoutlib_api/src/com/android/ide/common/rendering/api/StyleResourceValue.java index 429bd26..9d1e65d 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/StyleResourceValue.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/StyleResourceValue.java @@ -75,8 +75,8 @@ public final class StyleResourceValue extends ResourceValue implements IStyleRes * Legacy method. * @deprecated use {@link #getValue()} */ + @Deprecated public IResourceValue findItem(String name) { return mItems.get(name); } - } |