From 95b17a5e62eeeb7b38ef668508df43a1ee9e0880 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Wed, 15 Dec 2010 16:08:57 -0800 Subject: LayoutLib API refactoring Change-Id: I40abba4c4f786755c2a1c0e70df4d7bc08e2bcde --- .../android/ide/common/rendering/api/Bridge.java | 93 ++++++++ .../ide/common/rendering/api/Capability.java | 47 ++++ .../rendering/api/DensityBasedResourceValue.java | 46 ++++ .../common/rendering/api/IAnimationListener.java | 48 ++++ .../ide/common/rendering/api/IImageFactory.java | 42 ++++ .../common/rendering/api/ILayoutPullParser.java | 45 ++++ .../ide/common/rendering/api/IProjectCallback.java | 74 ++++++ .../ide/common/rendering/api/LayoutLog.java | 42 ++++ .../android/ide/common/rendering/api/Params.java | 228 ++++++++++++++++++ .../ide/common/rendering/api/RenderSession.java | 256 ++++++++++++++++++++ .../ide/common/rendering/api/ResourceDensity.java | 59 +++++ .../ide/common/rendering/api/ResourceValue.java | 89 +++++++ .../android/ide/common/rendering/api/Result.java | 187 +++++++++++++++ .../common/rendering/api/StyleResourceValue.java | 80 +++++++ .../android/ide/common/rendering/api/ViewInfo.java | 133 +++++++++++ .../src/com/android/layoutlib/api/Capability.java | 47 ---- .../layoutlib/api/DensityBasedResourceValue.java | 44 ---- .../layoutlib/api/IDensityBasedResourceValue.java | 3 + .../com/android/layoutlib/api/IImageFactory.java | 41 ---- .../com/android/layoutlib/api/ILayoutBridge.java | 14 +- .../src/com/android/layoutlib/api/ILayoutLog.java | 2 + .../com/android/layoutlib/api/ILayoutResult.java | 5 +- .../android/layoutlib/api/IProjectCallback.java | 11 +- .../com/android/layoutlib/api/IResourceValue.java | 2 + .../android/layoutlib/api/IStyleResourceValue.java | 2 + .../com/android/layoutlib/api/IXmlPullParser.java | 13 +- .../com/android/layoutlib/api/LayoutBridge.java | 88 ------- .../src/com/android/layoutlib/api/LayoutLog.java | 38 --- .../src/com/android/layoutlib/api/LayoutScene.java | 263 --------------------- .../com/android/layoutlib/api/ResourceDensity.java | 59 ----- .../com/android/layoutlib/api/ResourceValue.java | 87 ------- .../src/com/android/layoutlib/api/SceneParams.java | 228 ------------------ .../src/com/android/layoutlib/api/SceneResult.java | 187 --------------- .../android/layoutlib/api/StyleResourceValue.java | 77 ------ .../src/com/android/layoutlib/api/ViewInfo.java | 133 ----------- 35 files changed, 1496 insertions(+), 1317 deletions(-) create mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java create mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/Capability.java create mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/DensityBasedResourceValue.java create mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/IAnimationListener.java create mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/IImageFactory.java create mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/ILayoutPullParser.java create mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/IProjectCallback.java create mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/LayoutLog.java create mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/Params.java create mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/RenderSession.java create mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/ResourceDensity.java create mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/ResourceValue.java create mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/Result.java create mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/StyleResourceValue.java create mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/ViewInfo.java delete mode 100644 layoutlib_api/src/com/android/layoutlib/api/Capability.java delete mode 100644 layoutlib_api/src/com/android/layoutlib/api/DensityBasedResourceValue.java delete mode 100644 layoutlib_api/src/com/android/layoutlib/api/IImageFactory.java delete mode 100644 layoutlib_api/src/com/android/layoutlib/api/LayoutBridge.java delete mode 100644 layoutlib_api/src/com/android/layoutlib/api/LayoutLog.java delete mode 100644 layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java delete mode 100644 layoutlib_api/src/com/android/layoutlib/api/ResourceDensity.java delete mode 100644 layoutlib_api/src/com/android/layoutlib/api/ResourceValue.java delete mode 100644 layoutlib_api/src/com/android/layoutlib/api/SceneParams.java delete mode 100644 layoutlib_api/src/com/android/layoutlib/api/SceneResult.java delete mode 100644 layoutlib_api/src/com/android/layoutlib/api/StyleResourceValue.java delete mode 100644 layoutlib_api/src/com/android/layoutlib/api/ViewInfo.java (limited to 'layoutlib_api/src/com/android') 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 new file mode 100644 index 0000000..b2c2109 --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2010 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.io.File; +import java.util.EnumSet; +import java.util.Map; + +/** + * Entry point of the Layout Library. Extensions of this class provide a method to compute + * and render a layout. + */ +public abstract class Bridge { + + public final static int API_CURRENT = 5; + + /** + * Returns the API level of the layout library. + *

+ * While no methods will ever be removed, some may become deprecated, and some new ones + * will appear. + *

All Layout libraries based on {@link Bridge} return at minimum an API level of 5. + */ + public abstract int getApiLevel(); + + /** + * Returns an {@link EnumSet} of the supported {@link Capability}. + * @return an {@link EnumSet} with the supported capabilities. + * + */ + public EnumSet getCapabilities() { + return EnumSet.noneOf(Capability.class); + } + + /** + * Initializes the Bridge object. + * + * @param fontLocation the location of the fonts. + * @param enumValueMap map attrName => { map enumFlagName => Integer value }. + * @return true if success. + */ + public boolean init(File fontLocation, Map> enumValueMap) { + return false; + } + + /** + * Prepares the layoutlib to unloaded. + */ + public boolean dispose() { + return false; + } + + /** + * Starts a layout session by inflating and rendering it. The method returns a + * {@link RenderSession} on which further actions can be taken. + * + * @return a new {@link RenderSession} object that contains the result of the scene creation and + * first rendering. + */ + public RenderSession createSession(Params params) { + return null; + } + + /** + * Clears the resource cache for a specific project. + *

This cache contains bitmaps and nine patches that are loaded from the disk and reused + * until this method is called. + *

The cache is not configuration dependent and should only be cleared when a + * resource changes (at this time only bitmaps and 9 patches go into the cache). + *

+ * The project key provided must be similar to the one passed in {@link Params}. + * + * @param projectKey the key for the project. + */ + public void clearCaches(Object projectKey) { + + } +} 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 new file mode 100644 index 0000000..abbab45 --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/Capability.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2010 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; + +/** + * Enum describing the layout bridge capabilities. + * + */ +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)} */ + TRANSPARENCY, + /** Ability to call {@link LayoutScene#render()} and {@link LayoutScene#render(long)}. */ + RENDER, + /** + * Ability to control embedded layout parsers through {@link IXmlPullParser#getParser(String)} + */ + EMBEDDED_LAYOUT, + /** Ability to call
+ * {@link LayoutScene#insertChild(Object, IXmlPullParser, int, com.android.layoutlib.api.LayoutScene.IAnimationListener)}
+ * {@link LayoutScene#moveChild(Object, Object, int, java.util.Map, com.android.layoutlib.api.LayoutScene.IAnimationListener)}
+ * {@link LayoutScene#removeChild(Object, com.android.layoutlib.api.LayoutScene.IAnimationListener)}
+ * {@link LayoutScene#setProperty(Object, String, String)} + * */ + VIEW_MANIPULATION, + /** Ability to call
+ * {@link LayoutScene#animate(Object, String, boolean, com.android.layoutlib.api.LayoutScene.IAnimationListener)} + *

If the bridge also supports {@link #VIEW_MANIPULATION} then those methods can use + * an {@link com.android.layoutlib.api.LayoutScene.IAnimationListener}, otherwise they won't. */ + ANIMATE; +} 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 new file mode 100644 index 0000000..d190b62 --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/DensityBasedResourceValue.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2008 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.layoutlib.api.IDensityBasedResourceValue; + +@SuppressWarnings("deprecation") +public class DensityBasedResourceValue extends ResourceValue implements IDensityBasedResourceValue { + + private ResourceDensity mDensity; + + public DensityBasedResourceValue(String type, String name, String value, + ResourceDensity density, boolean isFramework) { + super(type, name, value, isFramework); + mDensity = density; + } + + /** + * Returns the density for which this resource is configured. + * @return the density. + */ + public ResourceDensity getResourceDensity() { + return mDensity; + } + + /** Legacy method, do not call + * @deprecated use {@link #getResourceDensity()} instead. + */ + public Density getDensity() { + return Density.getEnum(mDensity.getDpi()); + } +} diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/IAnimationListener.java b/layoutlib_api/src/com/android/ide/common/rendering/api/IAnimationListener.java new file mode 100644 index 0000000..81a2320 --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/IAnimationListener.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2010 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.awt.image.BufferedImage; + +public interface IAnimationListener { + /** + * Called when a new animation frame is available for display. + * + *

The {@link RenderSession} object is provided as a convenience. It should be queried + * for the image through {@link RenderSession#getImage()}. + * + *

If no {@link IImageFactory} is used, then each new animation frame will be rendered + * in its own new {@link BufferedImage} object. However if an image factory is used, and it + * always re-use the same object, then the image is only guaranteed to be valid during + * this method call. As soon as this method return the image content will be overridden + * with new drawing. + * + */ + void onNewFrame(RenderSession scene); + + /** + * Called when the animation is done playing. + */ + void done(Result result); + + /** + * Return true to cancel the animation. + */ + boolean isCanceled(); + +} diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/IImageFactory.java b/layoutlib_api/src/com/android/ide/common/rendering/api/IImageFactory.java new file mode 100644 index 0000000..c05c7c6 --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/IImageFactory.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2010 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.awt.image.BufferedImage; + +/** + * Image Factory Interface. + * + * An Image factory's task is to create the {@link BufferedImage} into which the scene will be + * rendered. The goal is to let the layoutlib caller create an image that's optimized for its use + * case. + * + * If no factory is passed in {@link Params#setImageFactory(IImageFactory)}, then a default + * {@link BufferedImage} of type {@link BufferedImage#TYPE_INT_ARGB} is created. + * + */ +public interface IImageFactory { + + /** + * Creates a buffered image with the given size + * @param width the width of the image + * @param height the height of the image + * @return a new (or reused) BufferedImage of the given size. + */ + BufferedImage getImage(int width, int height); +} 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 new file mode 100644 index 0000000..4b033d9 --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/ILayoutPullParser.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2008 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 org.xmlpull.v1.XmlPullParser; + +/** + * Extended version of {@link XmlPullParser} to use with + * {@link Bridge#createScene(SceneParams)} + */ +public interface ILayoutPullParser extends XmlPullParser { + + /** + * Returns a cookie for the current XML node. + *

This cookie will be passed back in the {@link ViewInfo} objects, allowing association + * of a particular XML node with its result from the layout computation. + * + * @see ViewInfo#getCookie() + */ + Object getViewCookie(); + + /** + * 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. + * + * @since 5 + */ + 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 new file mode 100644 index 0000000..67e082e --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/IProjectCallback.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2008 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; + +/** + * Callback for project information needed by the Layout Library. + * Classes implementing this interface provide methods giving access to some project data, like + * resource resolution, namespace information, and instantiation of custom view. + */ +public interface IProjectCallback { + + /** + * Loads a custom view with the given constructor signature and arguments. + * @param name The fully qualified name of the class. + * @param constructorSignature The signature of the class to use + * @param constructorArgs The arguments to use on the constructor + * @return A newly instantiated android.view.View object. + * @throws ClassNotFoundException + * @throws Exception + */ + @SuppressWarnings("unchecked") + Object loadView(String name, Class[] constructorSignature, Object[] constructorArgs) + throws ClassNotFoundException, Exception; + + /** + * Returns the namespace of the application. + *

This lets the Layout Lib load custom attributes for custom views. + */ + String getNamespace(); + + /** + * Resolves the id of a resource Id. + *

The resource id is the value of a R.<type>.<name>, and + * this method will return both the type and name of the resource. + * @param id the Id to resolve. + * @return an array of 2 strings containing the resource name and type, or null if the id + * does not match any resource. + */ + String[] resolveResourceValue(int id); + + /** + * Resolves the id of a resource Id of type int[] + *

The resource id is the value of a R.styleable.<name>, and this method will + * return the name of the resource. + * @param id the Id to resolve. + * @return the name of the resource or null if not found. + */ + String resolveResourceValue(int[] id); + + /** + * Returns the id of a resource. + *

The provided type and name must match an existing constant defined as + * R.<type>.<name>. + * @param type the type of the resource + * @param name the name of the resource + * @return an Integer containing the resource Id, or null if not found. + */ + Integer getResourceValue(String type, String name); + +} diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/LayoutLog.java b/layoutlib_api/src/com/android/ide/common/rendering/api/LayoutLog.java new file mode 100644 index 0000000..a735f81 --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/LayoutLog.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2010 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; + +public class LayoutLog { + + public void error(String tag, String message) { + } + + public void error(String tag, Throwable t) { + } + + public void warning(String tag, String message) { + } + + /** + * Logs an error message and a {@link Throwable}. + * @param message the message to log. + * @param throwable the {@link Throwable} to log. + */ + public void error(String tag, String message, Throwable throwable) { + + } + + public void fidelityWarning(String tag, String message, Throwable throwable) { + + } +} diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/Params.java b/layoutlib_api/src/com/android/ide/common/rendering/api/Params.java new file mode 100644 index 0000000..59e790e --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/Params.java @@ -0,0 +1,228 @@ +/* + * Copyright (C) 2010 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.Map; + +public class Params { + + public final static long DEFAULT_TIMEOUT = 250; //ms + + public static enum RenderingMode { + NORMAL(false, false), + V_SCROLL(false, true), + H_SCROLL(true, false), + FULL_EXPAND(true, true); + + private final boolean mHorizExpand; + private final boolean mVertExpand; + + private RenderingMode(boolean horizExpand, boolean vertExpand) { + mHorizExpand = horizExpand; + mVertExpand = vertExpand; + } + + public boolean isHorizExpand() { + return mHorizExpand; + } + + public boolean isVertExpand() { + return mVertExpand; + } + } + + private ILayoutPullParser mLayoutDescription; + private Object mProjectKey; + private int mScreenWidth; + private int mScreenHeight; + private RenderingMode mRenderingMode; + private int mDensity; + private float mXdpi; + private float mYdpi; + private String mThemeName; + private boolean mIsProjectTheme; + private Map> mProjectResources; + private Map> mFrameworkResources; + private IProjectCallback mProjectCallback; + private LayoutLog mLog; + + private boolean mCustomBackgroundEnabled; + private int mCustomBackgroundColor; + private long mTimeout; + + private IImageFactory mImageFactory = null; + + /** + * + * @param layoutDescription the {@link ILayoutPullParser} letting the LayoutLib Bridge visit the + * layout file. + * @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 renderingMode The rendering mode. + * @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 log the object responsible for displaying warning/errors to the user. + */ + public Params(ILayoutPullParser layoutDescription, + Object projectKey, + int screenWidth, int screenHeight, RenderingMode renderingMode, + int density, float xdpi, float ydpi, + String themeName, boolean isProjectTheme, + Map> projectResources, + Map> frameworkResources, + IProjectCallback projectCallback, LayoutLog log) { + mLayoutDescription = layoutDescription; + mProjectKey = projectKey; + mScreenWidth = screenWidth; + mScreenHeight = screenHeight; + mRenderingMode = renderingMode; + mDensity = density; + mXdpi = xdpi; + mYdpi = ydpi; + mThemeName = themeName; + mIsProjectTheme = isProjectTheme; + mProjectResources = projectResources; + mFrameworkResources = frameworkResources; + mProjectCallback = projectCallback; + mLog = log; + mCustomBackgroundEnabled = false; + mTimeout = DEFAULT_TIMEOUT; + } + + /** + * Copy constructor. + */ + public Params(Params params) { + mLayoutDescription = params.mLayoutDescription; + mProjectKey = params.mProjectKey; + mScreenWidth = params.mScreenWidth; + mScreenHeight = params.mScreenHeight; + mRenderingMode = params.mRenderingMode; + mDensity = params.mDensity; + mXdpi = params.mXdpi; + mYdpi = params.mYdpi; + mThemeName = params.mThemeName; + mIsProjectTheme = params.mIsProjectTheme; + mProjectResources = params.mProjectResources; + mFrameworkResources = params.mFrameworkResources; + mProjectCallback = params.mProjectCallback; + mLog = params.mLog; + mCustomBackgroundEnabled = params.mCustomBackgroundEnabled; + mCustomBackgroundColor = params.mCustomBackgroundColor; + mTimeout = params.mTimeout; + mImageFactory = params.mImageFactory; + } + + public void setOverrideBgColor(int color) { + mCustomBackgroundEnabled = true; + mCustomBackgroundColor = color; + } + + public void setTimeout(long timeout) { + mTimeout = timeout; + } + + public void setImageFactory(IImageFactory imageFactory) { + mImageFactory = imageFactory; + } + + public ILayoutPullParser getLayoutDescription() { + return mLayoutDescription; + } + + public Object getProjectKey() { + return mProjectKey; + } + + public int getScreenWidth() { + return mScreenWidth; + } + + public int getScreenHeight() { + return mScreenHeight; + } + + public RenderingMode getRenderingMode() { + return mRenderingMode; + } + + public int getDensity() { + return mDensity; + } + + public float getXdpi() { + return mXdpi; + } + + public float getYdpi() { + return mYdpi; + } + + public String getThemeName() { + return mThemeName; + } + + public boolean isProjectTheme() { + return mIsProjectTheme; + } + + public Map> getProjectResources() { + return mProjectResources; + } + + public Map> getFrameworkResources() { + return mFrameworkResources; + } + + public IProjectCallback getProjectCallback() { + return mProjectCallback; + } + + public LayoutLog getLog() { + return mLog; + } + + public boolean isBgColorOverridden() { + return mCustomBackgroundEnabled; + } + + public int getOverrideBgColor() { + return mCustomBackgroundColor; + } + + public long getTimeout() { + return mTimeout; + } + + public IImageFactory getImageFactory() { + return mImageFactory; + } +} 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 new file mode 100644 index 0000000..12a28de --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/RenderSession.java @@ -0,0 +1,256 @@ +/* + * Copyright (C) 2010 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 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; +import java.util.Map; + +/** + * An object allowing interaction with an Android layout. + * + * This is returned by {@link Bridge#createScene(Params)}. + * and can then be used for subsequent actions on the layout. + * + * @since 5 + * + */ +public class RenderSession { + + /** + * Returns the last operation result. + */ + public Result getResult() { + return NOT_IMPLEMENTED.createResult(); + } + + /** + * Returns the {@link ViewInfo} object for the top level view. + *

+ * + * This is reset to a new instance every time {@link #render()} is called and can be + * null if the call failed (and the method returned a {@link Result} with + * {@link Status#ERROR_UNKNOWN} or {@link Status#NOT_IMPLEMENTED}. + *

+ * This can be safely modified by the caller. + */ + public ViewInfo getRootView() { + return null; + } + + /** + * Returns the rendering of the full layout. + *

+ * This is reset to a new instance every time {@link #render()} is called and can be + * null if the call failed (and the method returned a {@link Result} with + * {@link Status#ERROR_UNKNOWN} or {@link Status#NOT_IMPLEMENTED}. + *

+ * This can be safely modified by the caller. + */ + public BufferedImage getImage() { + return null; + } + + + /** + * Returns a map of (XML attribute name, attribute value) containing only default attribute + * values, for the given view Object. + * @param viewObject the view object. + * @return a map of the default property values or null. + */ + public Map getDefaultProperties(Object viewObject) { + return null; + } + + /** + * Re-renders the layout as-is. + * In case of success, this should be followed by calls to {@link #getRootView()} and + * {@link #getImage()} to access the result of the rendering. + * + * This is equivalent to calling render(SceneParams.DEFAULT_TIMEOUT) + * + * @return a {@link Result} indicating the status of the action. + */ + public Result render() { + return render(Params.DEFAULT_TIMEOUT); + } + + /** + * Re-renders the layout as-is, with a given timeout in case other renderings are being done. + * In case of success, this should be followed by calls to {@link #getRootView()} and + * {@link #getImage()} to access the result of the rendering. + * + * The {@link Bridge} is only able to inflate or render one layout at a time. There + * is an internal lock object whenever such an action occurs. The timeout parameter is used + * when attempting to acquire the lock. If the timeout expires, the method will return + * {@link Status#ERROR_TIMEOUT}. + * + * @param timeout timeout for the rendering, in milliseconds. + * + * @return a {@link Result} indicating the status of the action. + */ + public Result render(long timeout) { + return NOT_IMPLEMENTED.createResult(); + } + + /** + * Sets the value of a given property on a given object. + *

+ * This does nothing more than change the property. To render the scene in its new state, a + * call to {@link #render()} is required. + *

+ * Any amount of actions can be taken on the scene before {@link #render()} is called. + * + * @param objectView + * @param propertyName + * @param propertyValue + * + * @return a {@link Result} indicating the status of the action. + * + * @throws IllegalArgumentException if the view object is not an android.view.View + */ + public Result setProperty(Object objectView, String propertyName, String propertyValue) { + return NOT_IMPLEMENTED.createResult(); + } + + /** + * returns the value of a given property on a given object. + *

+ * This returns a {@link Result} object. If the operation of querying the object for its + * property was successful (check {@link Result#isSuccess()}), then the property value + * is set in the result and can be accessed through {@link Result#getData()}. + * + * @param objectView + * @param propertyName + * + * @return a {@link Result} indicating the status of the action. + * + * @throws IllegalArgumentException if the view object is not an android.view.View + */ + public Result getProperty(Object objectView, String propertyName) { + 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 + * position. If the index is -1 then the child is added at the end of the parent. + *

+ * If an animation listener is passed then the rendering is done asynchronously and the + * result is sent to the listener. + * If the listener is null, then the rendering is done synchronously. + *

+ * The child stays in the view hierarchy after the rendering is done. To remove it call + * {@link #removeChild(Object, IAnimationListener)} + *

+ * The returned {@link Result} object will contain the android.view.View object for + * the newly inflated child. It is accessible through {@link Result#getData()}. + * + * @param parentView the parent View object to receive the new child. + * @param childXml an {@link ILayoutPullParser} containing the content of the new child, + * including ViewGroup.LayoutParams attributes. + * @param index the index at which position to add the new child into the parent. -1 means at + * the end. + * @param listener an optional {@link IAnimationListener}. + * + * @return a {@link Result} indicating the status of the action. + */ + public Result insertChild(Object parentView, ILayoutPullParser childXml, int index, + IAnimationListener listener) { + return NOT_IMPLEMENTED.createResult(); + } + + /** + * Move a new child to a different ViewGroup object. + *

+ * The child is first removed from its current parent, and then added to its new parent, at the + * given index position. In case the parentView is the current parent of + * childView then the index must be the value with the childView removed + * from its parent. If the index is -1 then the child is added at the end of + * the parent. + *

+ * If an animation listener is passed then the rendering is done asynchronously and the + * result is sent to the listener. + * If the listener is null, then the rendering is done synchronously. + *

+ * The child stays in the view hierarchy after the rendering is done. To remove it call + * {@link #removeChild(Object, IAnimationListener)} + *

+ * The returned {@link Result} object will contain the android.view.ViewGroup.LayoutParams + * object created from the layoutParams map if it was non null. + * + * @param parentView the parent View object to receive the child. Can be the current parent + * already. + * @param childView the view to move. + * @param index the index at which position to add the new child into the parent. -1 means at + * the end. + * @param layoutParams an optional map of new ViewGroup.LayoutParams attribute. If non null, + * then the current layout params of the view will be removed and a new one will + * be inflated and set with the content of the map. + * @param listener an optional {@link IAnimationListener}. + * + * @return a {@link Result} indicating the status of the action. + */ + public Result moveChild(Object parentView, Object childView, int index, + Map layoutParams, IAnimationListener listener) { + return NOT_IMPLEMENTED.createResult(); + } + + /** + * Removes a child from a ViewGroup object. + *

+ * This does nothing more than change the layout. To render the scene in its new state, a + * call to {@link #render()} is required. + *

+ * Any amount of actions can be taken on the scene before {@link #render()} is called. + * + * @param childView the view object to remove from its parent + * @param listener an optional {@link IAnimationListener}. + * + * @return a {@link Result} indicating the status of the action. + */ + public Result removeChild(Object childView, IAnimationListener listener) { + return NOT_IMPLEMENTED.createResult(); + } + + /** + * Starts playing an given animation on a given object. + *

+ * The animation playback is asynchronous and the rendered frame is sent vi the + * listener. + * + * @param targetObject the view object to animate + * @param animationName the name of the animation (res/anim) to play. + * @param listener the listener callback. + * + * @return a {@link Result} indicating the status of the action. + */ + public Result animate(Object targetObject, String animationName, + boolean isFrameworkAnimation, IAnimationListener listener) { + return NOT_IMPLEMENTED.createResult(); + } + + /** + * Discards the layout. No more actions can be called on this object. + */ + public void dispose() { + } +} diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/ResourceDensity.java b/layoutlib_api/src/com/android/ide/common/rendering/api/ResourceDensity.java new file mode 100644 index 0000000..ca92eae --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/ResourceDensity.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2010 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; + +/** + * Enum representing the density class of Android resources. + */ +public enum ResourceDensity { + XHIGH(320), + HIGH(240), + MEDIUM(160), + LOW(120), + NODPI(0); + + public final static int DEFAULT_DENSITY = 160; + + private final int mDpi; + + ResourceDensity(int dpi) { + mDpi = dpi; + } + + /** + * Returns the dot-per-inch value associated with the density. + * @return the dpi value. + */ + public int getDpi() { + return mDpi; + } + + /** + * Returns the enum matching the given dpi. + * @param dpi The dpi + * @return the enum for the dpi or null if no match was found. + */ + public static ResourceDensity getEnum(int dpi) { + for (ResourceDensity d : values()) { + if (d.mDpi == dpi) { + return d; + } + } + + return null; + } +} 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 new file mode 100644 index 0000000..f59f3c3 --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/ResourceValue.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2008 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.layoutlib.api.IResourceValue; + +/** + * Represents an android resource with a name and a string value. + */ +@SuppressWarnings("deprecation") +public class ResourceValue implements IResourceValue { + private final String mType; + private final String mName; + private String mValue = null; + private final boolean mIsFramwork; + + public ResourceValue(String type, String name, boolean isFramwork) { + mType = type; + mName = name; + mIsFramwork = isFramwork; + } + + public ResourceValue(String type, String name, String value, boolean isFramework) { + mType = type; + mName = name; + mValue = value; + mIsFramwork = isFramework; + } + + /** + * Returns the type of the resource. For instance "drawable", "color", etc... + */ + public String getType() { + return mType; + } + + /** + * 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 null + */ + public final String getValue() { + return mValue; + } + + /** + * Returns whether the resource is a framework resource (true) or a project + * resource (false). + */ + public final boolean isFramework() { + return mIsFramwork; + } + + + /** + * Sets the value of the resource. + * @param value the new value + */ + public void setValue(String value) { + mValue = value; + } + + /** + * Sets the value from another resource. + * @param value the resource value + */ + public void replaceWith(ResourceValue value) { + mValue = value.mValue; + } +} diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/Result.java b/layoutlib_api/src/com/android/ide/common/rendering/api/Result.java new file mode 100644 index 0000000..172a7e7 --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/Result.java @@ -0,0 +1,187 @@ +/* + * Copyright (C) 2010 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; + +/** + * Scene result class. This is an immutable class. + *

+ * This cannot be allocated directly, instead use + * {@link Status#createResult()}, + * {@link Status#createResult(String, Throwable)}, + * {@link Status#createResult(String)} + * {@link Status#createResult(Object)} + */ +public class Result { + + private final Status mStatus; + private final String mErrorMessage; + private final Throwable mThrowable; + private Object mData; + + /** + * Scene Status enum. + *

This indicates the status of all scene actions. + */ + public enum Status { + SUCCESS, + NOT_IMPLEMENTED, + ERROR_TIMEOUT, + ERROR_LOCK_INTERRUPTED, + ERROR_INFLATION, + ERROR_VIEWGROUP_NO_CHILDREN, + ERROR_NOT_INFLATED, + ERROR_RENDER, + ERROR_ANIM_NOT_FOUND, + ERROR_UNKNOWN; + + private Result mResult; + + /** + * Returns a {@link Result} object with this status. + * @return an instance of SceneResult; + */ + public Result createResult() { + // don't want to get generic error that way. + assert this != ERROR_UNKNOWN; + + if (mResult == null) { + mResult = new Result(this); + } + + return mResult; + } + + /** + * Returns a {@link Result} object with this status, and the given data. + * @return an instance of SceneResult; + * + * @see Result#getData() + */ + public Result createResult(Object data) { + Result res = createResult(); + + if (data != null) { + res = res.getCopyWithData(data); + } + + return res; + } + + /** + * Returns a {@link #ERROR_UNKNOWN} result with the given message and throwable + * @param errorMessage the error message + * @param throwable the throwable + * @return an instance of SceneResult. + */ + public Result createResult(String errorMessage, Throwable throwable) { + return new Result(this, errorMessage, throwable); + } + + /** + * Returns a {@link #ERROR_UNKNOWN} result with the given message + * @param errorMessage the error message + * @return an instance of SceneResult. + */ + public Result createResult(String errorMessage) { + return new Result(this, errorMessage, null /*throwable*/); + } + } + + /** + * Creates a {@link Result} object with the given SceneStatus. + * + * @param status the status. Must not be null. + */ + private Result(Status status) { + this(status, null, null); + } + + /** + * Creates a {@link Result} object with the given SceneStatus, and the given message + * and {@link Throwable} + * + * @param status the status. Must not be null. + * @param errorMessage an optional error message. + * @param t an optional exception. + */ + private Result(Status status, String errorMessage, Throwable t) { + assert status != null; + mStatus = status; + mErrorMessage = errorMessage; + mThrowable = t; + } + + private Result(Result result) { + mStatus = result.mStatus; + mErrorMessage = result.mErrorMessage; + mThrowable = result.mThrowable; + } + + /** + * Returns a copy of the current result with the added (or replaced) given data + * @param data the data bundle + * + * @return returns a new SceneResult instance. + */ + public Result getCopyWithData(Object data) { + Result r = new Result(this); + r.mData = data; + return r; + } + + + /** + * Returns whether the status is successful. + *

+ * This is the same as calling getStatus() == SceneStatus.SUCCESS + * @return true if the status is successful. + */ + public boolean isSuccess() { + return mStatus == Status.SUCCESS; + } + + /** + * Returns the status. This is never null. + */ + public Status getStatus() { + return mStatus; + } + + /** + * Returns the error message. This is only non-null when {@link #getStatus()} returns + * {@link Status#ERROR_UNKNOWN} + */ + public String getErrorMessage() { + return mErrorMessage; + } + + /** + * Returns the exception. This is only non-null when {@link #getStatus()} returns + * {@link Status#ERROR_UNKNOWN} + */ + public Throwable getException() { + return mThrowable; + } + + /** + * Returns the optional data bundle stored in the result object. + * @return the data bundle or null if none have been set. + */ + public Object getData() { + return mData; + } +} 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 new file mode 100644 index 0000000..a9f499f --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/StyleResourceValue.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2008 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.layoutlib.api.IResourceValue; +import com.android.layoutlib.api.IStyleResourceValue; + +import java.util.HashMap; + +/** + * Represents an android style resources with a name and a list of children {@link ResourceValue}. + */ +@SuppressWarnings("deprecation") +public final class StyleResourceValue extends ResourceValue implements IStyleResourceValue { + + private String mParentStyle = null; + private HashMap mItems = new HashMap(); + + public StyleResourceValue(String type, String name, boolean isFramework) { + super(type, name, isFramework); + } + + public StyleResourceValue(String type, String name, String parentStyle, boolean isFramework) { + super(type, name, isFramework); + mParentStyle = parentStyle; + } + + /** + * Returns the parent style name or null if unknown. + */ + public String getParentStyle() { + return mParentStyle; + } + + /** + * Finds a value in the list by name + * @param name the name of the resource + */ + public ResourceValue findValue(String name) { + return mItems.get(name); + } + + public void addValue(ResourceValue value) { + mItems.put(value.getName(), value); + } + + @Override + public void replaceWith(ResourceValue value) { + assert value instanceof StyleResourceValue; + super.replaceWith(value); + + if (value instanceof StyleResourceValue) { + mItems.clear(); + mItems.putAll(((StyleResourceValue)value).mItems); + } + } + + /** + * Legacy method. + * @deprecated use {@link #getValue()} + */ + public IResourceValue findItem(String name) { + return mItems.get(name); + } + +} diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/ViewInfo.java b/layoutlib_api/src/com/android/ide/common/rendering/api/ViewInfo.java new file mode 100644 index 0000000..2c0c829 --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/ViewInfo.java @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2010 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.Collections; +import java.util.List; + +/** + * Layout information for a specific view object + */ +public class ViewInfo { + + private final Object mCookie; + private final String mName; + private final int mLeft; + private final int mRight; + private final int mTop; + private final int mBottom; + private List mChildren = Collections.emptyList(); + private final Object mViewObject; + private final Object mLayoutParamsObject; + + public ViewInfo(String name, Object cookie, int left, int top, int right, int bottom) { + this(name, cookie, left, top, right, bottom, null /*viewObject*/, + null /*layoutParamsObject*/); + } + + public ViewInfo(String name, Object cookie, int left, int top, int right, int bottom, + Object viewObject, Object layoutParamsObject) { + mName = name; + mCookie = cookie; + mLeft = left; + mRight = right; + mTop = top; + mBottom = bottom; + mViewObject = viewObject; + mLayoutParamsObject = layoutParamsObject; + } + + /** + * Sets the list of children {@link ViewInfo}. + */ + public void setChildren(List children) { + if (children != null) { + mChildren = Collections.unmodifiableList(children); + } else { + mChildren = Collections.emptyList(); + } + } + + /** + * Returns the list of children views. This is never null, but can be empty. + */ + public List getChildren() { + return mChildren; + } + + /** + * Returns the cookie associated with the XML node. Can be null. + * + * @see ILayoutPullParser#getViewKey() + */ + public Object getCookie() { + return mCookie; + } + + /** + * Returns the class name of the view object. Can be null. + */ + public String getClassName() { + return mName; + } + + /** + * Returns the left of the view bounds, relative to the view parent bounds. + */ + public int getLeft() { + return mLeft; + } + + /** + * Returns the top of the view bounds, relative to the view parent bounds. + */ + public int getTop() { + return mTop; + } + + /** + * Returns the right of the view bounds, relative to the view parent bounds. + */ + public int getRight() { + return mRight; + } + + /** + * Returns the bottom of the view bounds, relative to the view parent bounds. + */ + public int getBottom() { + return mBottom; + } + + /** + * Returns the actual android.view.View (or child class) object. This can be used + * to query the object properties that are not in the XML and not in the map returned + * by {@link #getDefaultPropertyValues()}. + */ + public Object getViewObject() { + return mViewObject; + } + + /** + * Returns the actual android.view.ViewGroup$LayoutParams (or child class) object. + * This can be used to query the object properties that are not in the XML and not in + * the map returned by {@link #getDefaultPropertyValues()}. + */ + public Object getLayoutParamsObject() { + return mLayoutParamsObject; + } +} diff --git a/layoutlib_api/src/com/android/layoutlib/api/Capability.java b/layoutlib_api/src/com/android/layoutlib/api/Capability.java deleted file mode 100644 index 87ceca1..0000000 --- a/layoutlib_api/src/com/android/layoutlib/api/Capability.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2010 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.layoutlib.api; - -/** - * Enum describing the layout bridge capabilities. - * - */ -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)} */ - TRANSPARENCY, - /** Ability to call {@link LayoutScene#render()} and {@link LayoutScene#render(long)}. */ - RENDER, - /** - * Ability to control embedded layout parsers through {@link IXmlPullParser#getParser(String)} - */ - EMBEDDED_LAYOUT, - /** Ability to call
- * {@link LayoutScene#insertChild(Object, IXmlPullParser, int, com.android.layoutlib.api.LayoutScene.IAnimationListener)}
- * {@link LayoutScene#moveChild(Object, Object, int, java.util.Map, com.android.layoutlib.api.LayoutScene.IAnimationListener)}
- * {@link LayoutScene#removeChild(Object, com.android.layoutlib.api.LayoutScene.IAnimationListener)}
- * {@link LayoutScene#setProperty(Object, String, String)} - * */ - VIEW_MANIPULATION, - /** Ability to call
- * {@link LayoutScene#animate(Object, String, boolean, com.android.layoutlib.api.LayoutScene.IAnimationListener)} - *

If the bridge also supports {@link #VIEW_MANIPULATION} then those methods can use - * an {@link com.android.layoutlib.api.LayoutScene.IAnimationListener}, otherwise they won't. */ - ANIMATE; -} diff --git a/layoutlib_api/src/com/android/layoutlib/api/DensityBasedResourceValue.java b/layoutlib_api/src/com/android/layoutlib/api/DensityBasedResourceValue.java deleted file mode 100644 index 78b084c..0000000 --- a/layoutlib_api/src/com/android/layoutlib/api/DensityBasedResourceValue.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2008 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.layoutlib.api; - -@SuppressWarnings("deprecation") -public class DensityBasedResourceValue extends ResourceValue implements IDensityBasedResourceValue { - - private ResourceDensity mDensity; - - public DensityBasedResourceValue(String type, String name, String value, - ResourceDensity density, boolean isFramework) { - super(type, name, value, isFramework); - mDensity = density; - } - - /** - * Returns the density for which this resource is configured. - * @return the density. - */ - public ResourceDensity getResourceDensity() { - return mDensity; - } - - /** Legacy method, do not call - * @deprecated use {@link #getResourceDensity()} instead. - */ - public Density getDensity() { - return Density.getEnum(mDensity.getDpi()); - } -} diff --git a/layoutlib_api/src/com/android/layoutlib/api/IDensityBasedResourceValue.java b/layoutlib_api/src/com/android/layoutlib/api/IDensityBasedResourceValue.java index bc319c2..4e55d54 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/IDensityBasedResourceValue.java +++ b/layoutlib_api/src/com/android/layoutlib/api/IDensityBasedResourceValue.java @@ -16,6 +16,9 @@ package com.android.layoutlib.api; +import com.android.ide.common.rendering.api.DensityBasedResourceValue; +import com.android.ide.common.rendering.api.ResourceDensity; + /** * Represents an Android Resources that has a density info attached to it. * @deprecated use {@link DensityBasedResourceValue}. diff --git a/layoutlib_api/src/com/android/layoutlib/api/IImageFactory.java b/layoutlib_api/src/com/android/layoutlib/api/IImageFactory.java deleted file mode 100644 index 626423e..0000000 --- a/layoutlib_api/src/com/android/layoutlib/api/IImageFactory.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2010 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.layoutlib.api; - -import java.awt.image.BufferedImage; - -/** - * Image Factory Interface. - * - * An Image factory's task is to create the {@link BufferedImage} into which the scene will be - * rendered. The goal is to let the layoutlib caller create an image that's optimized for its use - * case. - * - * If no factory is passed in {@link SceneParams#setImageFactory(IImageFactory)}, then a default - * {@link BufferedImage} of type {@link BufferedImage#TYPE_INT_ARGB} is created. - * - */ -public interface IImageFactory { - - /** - * Creates a buffered image with the given size - * @param width the width of the image - * @param height the height of the image - * @return a new (or reused) BufferedImage of the given size. - */ - BufferedImage getImage(int width, int height); -} diff --git a/layoutlib_api/src/com/android/layoutlib/api/ILayoutBridge.java b/layoutlib_api/src/com/android/layoutlib/api/ILayoutBridge.java index f5d3660..56d2e36 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/ILayoutBridge.java +++ b/layoutlib_api/src/com/android/layoutlib/api/ILayoutBridge.java @@ -16,6 +16,8 @@ package com.android.layoutlib.api; +import com.android.ide.common.rendering.api.Bridge; + import java.util.Map; /** @@ -26,7 +28,7 @@ import java.util.Map; *

* Changes in API level 5: *

* Changes in API level 4: * - * @deprecated Extend {@link LayoutBridge} instead. + * @deprecated Extend {@link Bridge} instead. */ @Deprecated public interface ILayoutBridge { @@ -102,7 +104,7 @@ public interface ILayoutBridge { * the project. * @param logger the object responsible for displaying warning/errors to the user. * @return a new {@link ILayoutResult} object that contains the result of the layout. - * @deprecated use {@link LayoutBridge#createScene(SceneParams)} + * @deprecated use {@link Bridge#createScene(SceneParams)} * @since 4 */ @Deprecated @@ -139,7 +141,7 @@ public interface ILayoutBridge { * the project. * @param logger the object responsible for displaying warning/errors to the user. * @return a new {@link ILayoutResult} object that contains the result of the layout. - * @deprecated use {@link LayoutBridge#createScene(SceneParams)} + * @deprecated use {@link Bridge#createScene(SceneParams)} * @since 3 */ @Deprecated @@ -172,7 +174,7 @@ public interface ILayoutBridge { * the project. * @param logger the object responsible for displaying warning/errors to the user. * @return a new {@link ILayoutResult} object that contains the result of the layout. - * @deprecated use {@link LayoutBridge#createScene(SceneParams)} + * @deprecated use {@link Bridge#createScene(SceneParams)} * @since 2 */ @Deprecated @@ -204,7 +206,7 @@ public interface ILayoutBridge { * the project. * @param logger the object responsible for displaying warning/errors to the user. * @return a new {@link ILayoutResult} object that contains the result of the layout. - * @deprecated use {@link LayoutBridge#createScene(SceneParams)} + * @deprecated use {@link Bridge#createScene(SceneParams)} * @since 1 */ @Deprecated diff --git a/layoutlib_api/src/com/android/layoutlib/api/ILayoutLog.java b/layoutlib_api/src/com/android/layoutlib/api/ILayoutLog.java index 9931f3e..38a22b8 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/ILayoutLog.java +++ b/layoutlib_api/src/com/android/layoutlib/api/ILayoutLog.java @@ -16,6 +16,8 @@ package com.android.layoutlib.api; +import com.android.ide.common.rendering.api.LayoutLog; + /** * Callback interface to display warnings/errors that happened during the computation and * rendering of the layout. diff --git a/layoutlib_api/src/com/android/layoutlib/api/ILayoutResult.java b/layoutlib_api/src/com/android/layoutlib/api/ILayoutResult.java index a4d6da0..46255c4 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/ILayoutResult.java +++ b/layoutlib_api/src/com/android/layoutlib/api/ILayoutResult.java @@ -16,13 +16,16 @@ package com.android.layoutlib.api; +import com.android.ide.common.rendering.api.Bridge; +import com.android.ide.common.rendering.api.RenderSession; + import java.awt.image.BufferedImage; /** * The result of a layout computation through {@link ILayoutBridge}. * * @since 1 - * @deprecated use {@link LayoutScene} as returned by {@link LayoutBridge#createScene(SceneParams)} + * @deprecated use {@link RenderSession} as returned by {@link Bridge#createScene(SceneParams)} */ public interface ILayoutResult { /** diff --git a/layoutlib_api/src/com/android/layoutlib/api/IProjectCallback.java b/layoutlib_api/src/com/android/layoutlib/api/IProjectCallback.java index fbdd918..65e2a87 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/IProjectCallback.java +++ b/layoutlib_api/src/com/android/layoutlib/api/IProjectCallback.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 The Android Open Source Project + * Copyright (C) 2010 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. @@ -17,11 +17,11 @@ package com.android.layoutlib.api; /** - * Callback for project information needed by the Layout Library. - * Classes implementing this interface provide methods giving access to some project data, like - * resource resolution, namespace information, and instantiation of custom view. + * + * @deprecated + * */ -public interface IProjectCallback { +public interface IProjectCallback { /** * Loads a custom view with the given constructor signature and arguments. @@ -70,5 +70,4 @@ public interface IProjectCallback { * @return an Integer containing the resource Id, or null if not found. */ Integer getResourceValue(String type, String name); - } diff --git a/layoutlib_api/src/com/android/layoutlib/api/IResourceValue.java b/layoutlib_api/src/com/android/layoutlib/api/IResourceValue.java index 8a3e754..9a00801 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/IResourceValue.java +++ b/layoutlib_api/src/com/android/layoutlib/api/IResourceValue.java @@ -16,6 +16,8 @@ package com.android.layoutlib.api; +import com.android.ide.common.rendering.api.ResourceValue; + /** * Represents an android resource with a name and a string value. * @deprecated use {@link ResourceValue}. diff --git a/layoutlib_api/src/com/android/layoutlib/api/IStyleResourceValue.java b/layoutlib_api/src/com/android/layoutlib/api/IStyleResourceValue.java index 33133c9..21036ca 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/IStyleResourceValue.java +++ b/layoutlib_api/src/com/android/layoutlib/api/IStyleResourceValue.java @@ -16,6 +16,8 @@ package com.android.layoutlib.api; +import com.android.ide.common.rendering.api.StyleResourceValue; + /** * Represents an android style resources with a name and a list of children {@link IResourceValue}. * @deprecated Use {@link StyleResourceValue}. diff --git a/layoutlib_api/src/com/android/layoutlib/api/IXmlPullParser.java b/layoutlib_api/src/com/android/layoutlib/api/IXmlPullParser.java index c3c738f..b4d10a2 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/IXmlPullParser.java +++ b/layoutlib_api/src/com/android/layoutlib/api/IXmlPullParser.java @@ -19,8 +19,7 @@ package com.android.layoutlib.api; import org.xmlpull.v1.XmlPullParser; /** - * Extended version of {@link XmlPullParser} to use with - * {@link LayoutBridge#createScene(SceneParams)} + * @deprecated */ public interface IXmlPullParser extends XmlPullParser { @@ -30,14 +29,4 @@ public interface IXmlPullParser extends XmlPullParser { * of a particular XML node with its result from the layout computation. */ Object getViewKey(); - - /** - * 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. - * - * @since 5 - */ - IXmlPullParser getParser(String layoutName); } - diff --git a/layoutlib_api/src/com/android/layoutlib/api/LayoutBridge.java b/layoutlib_api/src/com/android/layoutlib/api/LayoutBridge.java deleted file mode 100644 index a3bd921..0000000 --- a/layoutlib_api/src/com/android/layoutlib/api/LayoutBridge.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2010 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.layoutlib.api; - -import java.util.EnumSet; -import java.util.Map; - -/** - * Entry point of the Layout Lib. Extensions of this class provide a method to compute - * and render a layout. - */ -public abstract class LayoutBridge { - - public final static int API_CURRENT = 5; - - /** - * Returns the API level of the layout library. - *

- * While no methods will ever be removed, some may become deprecated, and some new ones - * will appear. - */ - public abstract int getApiLevel(); - - /** - * Returns an {@link EnumSet} of the supported {@link Capability}. - * @return an {@link EnumSet} with the supported capabilities. - * - */ - public EnumSet getCapabilities() { - return EnumSet.noneOf(Capability.class); - } - - /** - * Initializes the Bridge object. - * - * @param fontOsLocation the location of the fonts. - * @param enumValueMap map attrName => { map enumFlagName => Integer value }. - * @return true if success. - */ - public boolean init(String fontOsLocation, Map> enumValueMap) { - return false; - } - - /** - * Prepares the layoutlib to unloaded. - */ - public boolean dispose() { - return false; - } - - /** - * Starts a layout session by inflating and rendering it. The method returns a - * {@link LayoutScene} on which further actions can be taken. - * - * @return a new {@link LayoutScene} object that contains the result of the scene creation and - * first rendering. - */ - public LayoutScene createScene(SceneParams params) { - return null; - } - - /** - * Clears the resource cache for a specific project. - *

This cache contains bitmaps and nine patches that are loaded from the disk and reused - * until this method is called. - *

The cache is not configuration dependent and should only be cleared when a - * resource changes (at this time only bitmaps and 9 patches go into the cache). - * - * @param projectKey the key for the project. - */ - public void clearCaches(Object projectKey) { - - } -} diff --git a/layoutlib_api/src/com/android/layoutlib/api/LayoutLog.java b/layoutlib_api/src/com/android/layoutlib/api/LayoutLog.java deleted file mode 100644 index 052750e..0000000 --- a/layoutlib_api/src/com/android/layoutlib/api/LayoutLog.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2010 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.layoutlib.api; - -public class LayoutLog { - - public void error(String tag, String message) { - } - - public void error(String tag, Throwable t) { - } - - public void warning(String tag, String message) { - } - - /** - * Logs an error message and a {@link Throwable}. - * @param message the message to log. - * @param throwable the {@link Throwable} to log. - */ - public void error(String tag, String message, Throwable throwable) { - - } -} diff --git a/layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java b/layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java deleted file mode 100644 index 8bfa7ed..0000000 --- a/layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright (C) 2010 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.layoutlib.api; - -import static com.android.layoutlib.api.SceneResult.SceneStatus.NOT_IMPLEMENTED; - -import com.android.layoutlib.api.SceneResult.SceneStatus; - -import java.awt.image.BufferedImage; -import java.util.Map; - -/** - * An object allowing interaction with an Android layout. - * - * This is returned by {@link LayoutBridge#createScene(SceneParams)}. - * and can then be used for subsequent actions on the layout. - * - * @since 5 - * - */ -public class LayoutScene { - - public interface IAnimationListener { - /** - * Called when a new animation frame is available for display. - * - *

The {@link LayoutScene} object is provided as a convenience. It should be queried - * for the image through {@link LayoutScene#getImage()}. - * - *

If no {@link IImageFactory} is used, then each new animation frame will be rendered - * in its own new {@link BufferedImage} object. However if an image factory is used, and it - * always re-use the same object, then the image is only guaranteed to be valid during - * this method call. As soon as this method return the image content will be overridden - * with new drawing. - * - */ - void onNewFrame(LayoutScene scene); - - /** - * Called when the animation is done playing. - */ - void done(SceneResult result); - - /** - * Return true to cancel the animation. - */ - boolean isCanceled(); - } - - /** - * Returns the last operation result. - */ - public SceneResult getResult() { - return NOT_IMPLEMENTED.createResult(); - } - - /** - * Returns the {@link ViewInfo} object for the top level view. - *

- * - * This is reset to a new instance every time {@link #render()} is called and can be - * null if the call failed (and the method returned a {@link SceneResult} with - * {@link SceneStatus#ERROR_UNKNOWN} or {@link SceneStatus#NOT_IMPLEMENTED}. - *

- * This can be safely modified by the caller. - */ - public ViewInfo getRootView() { - return null; - } - - /** - * Returns the rendering of the full layout. - *

- * This is reset to a new instance every time {@link #render()} is called and can be - * null if the call failed (and the method returned a {@link SceneResult} with - * {@link SceneStatus#ERROR_UNKNOWN} or {@link SceneStatus#NOT_IMPLEMENTED}. - *

- * This can be safely modified by the caller. - */ - public BufferedImage getImage() { - return null; - } - - - /** - * Returns a map of (XML attribute name, attribute value) containing only default attribute - * values, for the given view Object. - * @param viewObject the view object. - * @return a map of the default property values or null. - */ - public Map getDefaultViewPropertyValues(Object viewObject) { - return null; - } - - /** - * Re-renders the layout as-is. - * In case of success, this should be followed by calls to {@link #getRootView()} and - * {@link #getImage()} to access the result of the rendering. - * - * This is equivalent to calling render(SceneParams.DEFAULT_TIMEOUT) - * - * @return a {@link SceneResult} indicating the status of the action. - */ - public SceneResult render() { - return render(SceneParams.DEFAULT_TIMEOUT); - } - - /** - * Re-renders the layout as-is, with a given timeout in case other renderings are being done. - * In case of success, this should be followed by calls to {@link #getRootView()} and - * {@link #getImage()} to access the result of the rendering. - * - * The {@link LayoutBridge} is only able to inflate or render one layout at a time. There - * is an internal lock object whenever such an action occurs. The timeout parameter is used - * when attempting to acquire the lock. If the timeout expires, the method will return - * {@link SceneStatus#ERROR_TIMEOUT}. - * - * @param timeout timeout for the rendering, in milliseconds. - * - * @return a {@link SceneResult} indicating the status of the action. - */ - public SceneResult render(long timeout) { - return NOT_IMPLEMENTED.createResult(); - } - - /** - * Sets the value of a given property on a given object. - *

- * This does nothing more than change the property. To render the scene in its new state, a - * call to {@link #render()} is required. - *

- * Any amount of actions can be taken on the scene before {@link #render()} is called. - * - * @param objectView - * @param propertyName - * @param propertyValue - * - * @return a {@link SceneResult} indicating the status of the action. - */ - public SceneResult setProperty(Object objectView, String propertyName, String propertyValue) { - 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 - * position. If the index is -1 then the child is added at the end of the parent. - *

- * If an animation listener is passed then the rendering is done asynchronously and the - * result is sent to the listener. - * If the listener is null, then the rendering is done synchronously. - *

- * The child stays in the view hierarchy after the rendering is done. To remove it call - * {@link #removeChild(Object, IAnimationListener)} - *

- * The returned {@link SceneResult} object will contain the android.view.View object for - * the newly inflated child. It is accessible through {@link SceneResult#getData()}. - * - * @param parentView the parent View object to receive the new child. - * @param childXml an {@link IXmlPullParser} containing the content of the new child, including - * ViewGroup.LayoutParams attributes. - * @param index the index at which position to add the new child into the parent. -1 means at - * the end. - * @param listener an optional {@link IAnimationListener}. - * - * @return a {@link SceneResult} indicating the status of the action. - */ - public SceneResult insertChild(Object parentView, IXmlPullParser childXml, int index, - IAnimationListener listener) { - return NOT_IMPLEMENTED.createResult(); - } - - /** - * Move a new child to a different ViewGroup object. - *

- * The child is first removed from its current parent, and then added to its new parent, at the - * given index position. In case the parentView is the current parent of - * childView then the index must be the value with the childView removed - * from its parent. If the index is -1 then the child is added at the end of - * the parent. - *

- * If an animation listener is passed then the rendering is done asynchronously and the - * result is sent to the listener. - * If the listener is null, then the rendering is done synchronously. - *

- * The child stays in the view hierarchy after the rendering is done. To remove it call - * {@link #removeChild(Object, IAnimationListener)} - *

- * The returned {@link SceneResult} object will contain the android.view.ViewGroup.LayoutParams - * object created from the layoutParams map if it was non null. - * - * @param parentView the parent View object to receive the child. Can be the current parent - * already. - * @param childView the view to move. - * @param index the index at which position to add the new child into the parent. -1 means at - * the end. - * @param layoutParams an optional map of new ViewGroup.LayoutParams attribute. If non null, - * then the current layout params of the view will be removed and a new one will - * be inflated and set with the content of the map. - * @param listener an optional {@link IAnimationListener}. - * - * @return a {@link SceneResult} indicating the status of the action. - */ - public SceneResult moveChild(Object parentView, Object childView, int index, - Map layoutParams, IAnimationListener listener) { - return NOT_IMPLEMENTED.createResult(); - } - - /** - * Removes a child from a ViewGroup object. - *

- * This does nothing more than change the layout. To render the scene in its new state, a - * call to {@link #render()} is required. - *

- * Any amount of actions can be taken on the scene before {@link #render()} is called. - * - * @param childView the view object to remove from its parent - * @param listener an optional {@link IAnimationListener}. - * - * @return a {@link SceneResult} indicating the status of the action. - */ - public SceneResult removeChild(Object childView, IAnimationListener listener) { - return NOT_IMPLEMENTED.createResult(); - } - - /** - * Starts playing an given animation on a given object. - *

- * The animation playback is asynchronous and the rendered frame is sent vi the - * listener. - * - * @param targetObject the view object to animate - * @param animationName the name of the animation (res/anim) to play. - * @param listener the listener callback. - * - * @return a {@link SceneResult} indicating the status of the action. - */ - public SceneResult animate(Object targetObject, String animationName, - boolean isFrameworkAnimation, IAnimationListener listener) { - return NOT_IMPLEMENTED.createResult(); - } - - /** - * Discards the layout. No more actions can be called on this object. - */ - public void dispose() { - } -} diff --git a/layoutlib_api/src/com/android/layoutlib/api/ResourceDensity.java b/layoutlib_api/src/com/android/layoutlib/api/ResourceDensity.java deleted file mode 100644 index cebb8df..0000000 --- a/layoutlib_api/src/com/android/layoutlib/api/ResourceDensity.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2010 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.layoutlib.api; - -/** - * Enum representing the density class of Android resources. - */ -public enum ResourceDensity { - XHIGH(320), - HIGH(240), - MEDIUM(160), - LOW(120), - NODPI(0); - - public final static int DEFAULT_DENSITY = 160; - - private final int mDpi; - - ResourceDensity(int dpi) { - mDpi = dpi; - } - - /** - * Returns the dot-per-inch value associated with the density. - * @return the dpi value. - */ - public int getDpi() { - return mDpi; - } - - /** - * Returns the enum matching the given dpi. - * @param dpi The dpi - * @return the enum for the dpi or null if no match was found. - */ - public static ResourceDensity getEnum(int dpi) { - for (ResourceDensity d : values()) { - if (d.mDpi == dpi) { - return d; - } - } - - return null; - } -} diff --git a/layoutlib_api/src/com/android/layoutlib/api/ResourceValue.java b/layoutlib_api/src/com/android/layoutlib/api/ResourceValue.java deleted file mode 100644 index 41f440d..0000000 --- a/layoutlib_api/src/com/android/layoutlib/api/ResourceValue.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2008 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.layoutlib.api; - -/** - * Represents an android resource with a name and a string value. - */ -@SuppressWarnings("deprecation") -public class ResourceValue implements IResourceValue { - private final String mType; - private final String mName; - private String mValue = null; - private final boolean mIsFramwork; - - public ResourceValue(String type, String name, boolean isFramwork) { - mType = type; - mName = name; - mIsFramwork = isFramwork; - } - - public ResourceValue(String type, String name, String value, boolean isFramework) { - mType = type; - mName = name; - mValue = value; - mIsFramwork = isFramework; - } - - /** - * Returns the type of the resource. For instance "drawable", "color", etc... - */ - public String getType() { - return mType; - } - - /** - * 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 null - */ - public final String getValue() { - return mValue; - } - - /** - * Returns whether the resource is a framework resource (true) or a project - * resource (false). - */ - public final boolean isFramework() { - return mIsFramwork; - } - - - /** - * Sets the value of the resource. - * @param value the new value - */ - public void setValue(String value) { - mValue = value; - } - - /** - * Sets the value from another resource. - * @param value the resource value - */ - public void replaceWith(ResourceValue value) { - mValue = value.mValue; - } -} diff --git a/layoutlib_api/src/com/android/layoutlib/api/SceneParams.java b/layoutlib_api/src/com/android/layoutlib/api/SceneParams.java deleted file mode 100644 index 309f9fd..0000000 --- a/layoutlib_api/src/com/android/layoutlib/api/SceneParams.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (C) 2010 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.layoutlib.api; - -import java.util.Map; - -public class SceneParams { - - public final static long DEFAULT_TIMEOUT = 250; //ms - - public static enum RenderingMode { - NORMAL(false, false), - V_SCROLL(false, true), - H_SCROLL(true, false), - FULL_EXPAND(true, true); - - private final boolean mHorizExpand; - private final boolean mVertExpand; - - private RenderingMode(boolean horizExpand, boolean vertExpand) { - mHorizExpand = horizExpand; - mVertExpand = vertExpand; - } - - public boolean isHorizExpand() { - return mHorizExpand; - } - - public boolean isVertExpand() { - return mVertExpand; - } - } - - private IXmlPullParser mLayoutDescription; - private Object mProjectKey; - private int mScreenWidth; - private int mScreenHeight; - private RenderingMode mRenderingMode; - private int mDensity; - private float mXdpi; - private float mYdpi; - private String mThemeName; - private boolean mIsProjectTheme; - private Map> mProjectResources; - private Map> mFrameworkResources; - private IProjectCallback mProjectCallback; - private LayoutLog mLog; - - private boolean mCustomBackgroundEnabled; - private int mCustomBackgroundColor; - private long mTimeout; - - private IImageFactory mImageFactory = null; - - /** - * - * @param layoutDescription the {@link IXmlPullParser} letting the LayoutLib Bridge visit the - * layout file. - * @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 renderingMode The rendering mode. - * @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 IResourceValue}) 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 IResourceValue}) 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 log the object responsible for displaying warning/errors to the user. - */ - public SceneParams(IXmlPullParser layoutDescription, - Object projectKey, - int screenWidth, int screenHeight, RenderingMode renderingMode, - int density, float xdpi, float ydpi, - String themeName, boolean isProjectTheme, - Map> projectResources, - Map> frameworkResources, - IProjectCallback projectCallback, LayoutLog log) { - mLayoutDescription = layoutDescription; - mProjectKey = projectKey; - mScreenWidth = screenWidth; - mScreenHeight = screenHeight; - mRenderingMode = renderingMode; - mDensity = density; - mXdpi = xdpi; - mYdpi = ydpi; - mThemeName = themeName; - mIsProjectTheme = isProjectTheme; - mProjectResources = projectResources; - mFrameworkResources = frameworkResources; - mProjectCallback = projectCallback; - mLog = log; - mCustomBackgroundEnabled = false; - mTimeout = DEFAULT_TIMEOUT; - } - - /** - * Copy constructor. - */ - public SceneParams(SceneParams params) { - mLayoutDescription = params.mLayoutDescription; - mProjectKey = params.mProjectKey; - mScreenWidth = params.mScreenWidth; - mScreenHeight = params.mScreenHeight; - mRenderingMode = params.mRenderingMode; - mDensity = params.mDensity; - mXdpi = params.mXdpi; - mYdpi = params.mYdpi; - mThemeName = params.mThemeName; - mIsProjectTheme = params.mIsProjectTheme; - mProjectResources = params.mProjectResources; - mFrameworkResources = params.mFrameworkResources; - mProjectCallback = params.mProjectCallback; - mLog = params.mLog; - mCustomBackgroundEnabled = params.mCustomBackgroundEnabled; - mCustomBackgroundColor = params.mCustomBackgroundColor; - mTimeout = params.mTimeout; - mImageFactory = params.mImageFactory; - } - - public void setCustomBackgroundColor(int color) { - mCustomBackgroundEnabled = true; - mCustomBackgroundColor = color; - } - - public void setCustomTimeout(long timeout) { - mTimeout = timeout; - } - - public void setImageFactory(IImageFactory imageFactory) { - mImageFactory = imageFactory; - } - - public IXmlPullParser getLayoutDescription() { - return mLayoutDescription; - } - - public Object getProjectKey() { - return mProjectKey; - } - - public int getScreenWidth() { - return mScreenWidth; - } - - public int getScreenHeight() { - return mScreenHeight; - } - - public RenderingMode getRenderingMode() { - return mRenderingMode; - } - - public int getDensity() { - return mDensity; - } - - public float getXdpi() { - return mXdpi; - } - - public float getYdpi() { - return mYdpi; - } - - public String getThemeName() { - return mThemeName; - } - - public boolean getIsProjectTheme() { - return mIsProjectTheme; - } - - public Map> getProjectResources() { - return mProjectResources; - } - - public Map> getFrameworkResources() { - return mFrameworkResources; - } - - public IProjectCallback getProjectCallback() { - return mProjectCallback; - } - - public LayoutLog getLog() { - return mLog; - } - - public boolean isCustomBackgroundEnabled() { - return mCustomBackgroundEnabled; - } - - public int getCustomBackgroundColor() { - return mCustomBackgroundColor; - } - - public long getTimeout() { - return mTimeout; - } - - public IImageFactory getImageFactory() { - return mImageFactory; - } -} diff --git a/layoutlib_api/src/com/android/layoutlib/api/SceneResult.java b/layoutlib_api/src/com/android/layoutlib/api/SceneResult.java deleted file mode 100644 index 2954671..0000000 --- a/layoutlib_api/src/com/android/layoutlib/api/SceneResult.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (C) 2010 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.layoutlib.api; - -/** - * Scene result class. This is an immutable class. - *

- * This cannot be allocated directly, instead use - * {@link SceneStatus#createResult()}, - * {@link SceneStatus#createResult(String, Throwable)}, - * {@link SceneStatus#createResult(String)} - * {@link SceneStatus#createResult(Object)} - */ -public class SceneResult { - - private final SceneStatus mStatus; - private final String mErrorMessage; - private final Throwable mThrowable; - private Object mData; - - /** - * Scene Status enum. - *

This indicates the status of all scene actions. - */ - public enum SceneStatus { - SUCCESS, - NOT_IMPLEMENTED, - ERROR_TIMEOUT, - ERROR_LOCK_INTERRUPTED, - ERROR_INFLATION, - ERROR_VIEWGROUP_NO_CHILDREN, - ERROR_NOT_INFLATED, - ERROR_RENDER, - ERROR_ANIM_NOT_FOUND, - ERROR_UNKNOWN; - - private SceneResult mResult; - - /** - * Returns a {@link SceneResult} object with this status. - * @return an instance of SceneResult; - */ - public SceneResult createResult() { - // don't want to get generic error that way. - assert this != ERROR_UNKNOWN; - - if (mResult == null) { - mResult = new SceneResult(this); - } - - return mResult; - } - - /** - * Returns a {@link SceneResult} object with this status, and the given data. - * @return an instance of SceneResult; - * - * @see SceneResult#getData() - */ - public SceneResult createResult(Object data) { - SceneResult res = createResult(); - - if (data != null) { - res = res.getCopyWithData(data); - } - - return res; - } - - /** - * Returns a {@link #ERROR_UNKNOWN} result with the given message and throwable - * @param errorMessage the error message - * @param throwable the throwable - * @return an instance of SceneResult. - */ - public SceneResult createResult(String errorMessage, Throwable throwable) { - return new SceneResult(this, errorMessage, throwable); - } - - /** - * Returns a {@link #ERROR_UNKNOWN} result with the given message - * @param errorMessage the error message - * @return an instance of SceneResult. - */ - public SceneResult createResult(String errorMessage) { - return new SceneResult(this, errorMessage, null /*throwable*/); - } - } - - /** - * Creates a {@link SceneResult} object with the given SceneStatus. - * - * @param status the status. Must not be null. - */ - private SceneResult(SceneStatus status) { - this(status, null, null); - } - - /** - * Creates a {@link SceneResult} object with the given SceneStatus, and the given message - * and {@link Throwable} - * - * @param status the status. Must not be null. - * @param errorMessage an optional error message. - * @param t an optional exception. - */ - private SceneResult(SceneStatus status, String errorMessage, Throwable t) { - assert status != null; - mStatus = status; - mErrorMessage = errorMessage; - mThrowable = t; - } - - private SceneResult(SceneResult result) { - mStatus = result.mStatus; - mErrorMessage = result.mErrorMessage; - mThrowable = result.mThrowable; - } - - /** - * Returns a copy of the current result with the added (or replaced) given data - * @param data the data bundle - * - * @return returns a new SceneResult instance. - */ - public SceneResult getCopyWithData(Object data) { - SceneResult r = new SceneResult(this); - r.mData = data; - return r; - } - - - /** - * Returns whether the status is successful. - *

- * This is the same as calling getStatus() == SceneStatus.SUCCESS - * @return true if the status is successful. - */ - public boolean isSuccess() { - return mStatus == SceneStatus.SUCCESS; - } - - /** - * Returns the status. This is never null. - */ - public SceneStatus getStatus() { - return mStatus; - } - - /** - * Returns the error message. This is only non-null when {@link #getStatus()} returns - * {@link SceneStatus#ERROR_UNKNOWN} - */ - public String getErrorMessage() { - return mErrorMessage; - } - - /** - * Returns the exception. This is only non-null when {@link #getStatus()} returns - * {@link SceneStatus#ERROR_UNKNOWN} - */ - public Throwable getException() { - return mThrowable; - } - - /** - * Returns the optional data bundle stored in the result object. - * @return the data bundle or null if none have been set. - */ - public Object getData() { - return mData; - } -} diff --git a/layoutlib_api/src/com/android/layoutlib/api/StyleResourceValue.java b/layoutlib_api/src/com/android/layoutlib/api/StyleResourceValue.java deleted file mode 100644 index 8052b4e..0000000 --- a/layoutlib_api/src/com/android/layoutlib/api/StyleResourceValue.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2008 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.layoutlib.api; - -import java.util.HashMap; - -/** - * Represents an android style resources with a name and a list of children {@link ResourceValue}. - */ -@SuppressWarnings("deprecation") -public final class StyleResourceValue extends ResourceValue implements IStyleResourceValue { - - private String mParentStyle = null; - private HashMap mItems = new HashMap(); - - public StyleResourceValue(String type, String name, boolean isFramework) { - super(type, name, isFramework); - } - - public StyleResourceValue(String type, String name, String parentStyle, boolean isFramework) { - super(type, name, isFramework); - mParentStyle = parentStyle; - } - - /** - * Returns the parent style name or null if unknown. - */ - public String getParentStyle() { - return mParentStyle; - } - - /** - * Finds a value in the list by name - * @param name the name of the resource - */ - public ResourceValue findValue(String name) { - return mItems.get(name); - } - - public void addValue(ResourceValue value) { - mItems.put(value.getName(), value); - } - - @Override - public void replaceWith(ResourceValue value) { - assert value instanceof StyleResourceValue; - super.replaceWith(value); - - if (value instanceof StyleResourceValue) { - mItems.clear(); - mItems.putAll(((StyleResourceValue)value).mItems); - } - } - - /** - * Legacy method. - * @deprecated use {@link #getValue()} - */ - public IResourceValue findItem(String name) { - return mItems.get(name); - } - -} diff --git a/layoutlib_api/src/com/android/layoutlib/api/ViewInfo.java b/layoutlib_api/src/com/android/layoutlib/api/ViewInfo.java deleted file mode 100644 index 4a6c93d..0000000 --- a/layoutlib_api/src/com/android/layoutlib/api/ViewInfo.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2010 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.layoutlib.api; - -import java.util.Collections; -import java.util.List; - -/** - * Layout information for a specific view object - */ -public final class ViewInfo { - - private final Object mCookie; - private final String mName; - private final int mLeft; - private final int mRight; - private final int mTop; - private final int mBottom; - private List mChildren = Collections.emptyList(); - private final Object mViewObject; - private final Object mLayoutParamsObject; - - public ViewInfo(String name, Object cookie, int left, int top, int right, int bottom) { - this(name, cookie, left, top, right, bottom, null /*viewObject*/, - null /*layoutParamsObject*/); - } - - public ViewInfo(String name, Object cookie, int left, int top, int right, int bottom, - Object viewObject, Object layoutParamsObject) { - mName = name; - mCookie = cookie; - mLeft = left; - mRight = right; - mTop = top; - mBottom = bottom; - mViewObject = viewObject; - mLayoutParamsObject = layoutParamsObject; - } - - /** - * Sets the list of children {@link ViewInfo}. - */ - public void setChildren(List children) { - if (children != null) { - mChildren = Collections.unmodifiableList(children); - } else { - mChildren = Collections.emptyList(); - } - } - - /** - * Returns the list of children views. This is never null, but can be empty. - */ - public List getChildren() { - return mChildren; - } - - /** - * Returns the cookie associated with the XML node. Can be null. - * - * @see IXmlPullParser#getViewKey() - */ - public Object getCookie() { - return mCookie; - } - - /** - * Returns the class name of the view object. Can be null. - */ - public String getClassName() { - return mName; - } - - /** - * Returns the left of the view bounds, relative to the view parent bounds. - */ - public int getLeft() { - return mLeft; - } - - /** - * Returns the top of the view bounds, relative to the view parent bounds. - */ - public int getTop() { - return mTop; - } - - /** - * Returns the right of the view bounds, relative to the view parent bounds. - */ - public int getRight() { - return mRight; - } - - /** - * Returns the bottom of the view bounds, relative to the view parent bounds. - */ - public int getBottom() { - return mBottom; - } - - /** - * Returns the actual android.view.View (or child class) object. This can be used - * to query the object properties that are not in the XML and not in the map returned - * by {@link #getDefaultPropertyValues()}. - */ - public Object getViewObject() { - return mViewObject; - } - - /** - * Returns the actual android.view.ViewGroup$LayoutParams (or child class) object. - * This can be used to query the object properties that are not in the XML and not in - * the map returned by {@link #getDefaultPropertyValues()}. - */ - public Object getLayoutParamsObject() { - return mLayoutParamsObject; - } -} -- cgit v1.1