aboutsummaryrefslogtreecommitdiffstats
path: root/layoutlib_api/src/com/android/ide/common/rendering
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2011-02-04 17:28:43 -0800
committerXavier Ducrohet <xav@android.com>2011-02-04 17:34:40 -0800
commite25af9f721bcc89d73c8e56adc9d02a6bcfac1c6 (patch)
tree5aff7ab5aa59bf8482327a95b09a13652dce9f38 /layoutlib_api/src/com/android/ide/common/rendering
parent1d2909b8ff75a392af9231fe848674378b234bb9 (diff)
downloadsdk-e25af9f721bcc89d73c8e56adc9d02a6bcfac1c6.zip
sdk-e25af9f721bcc89d73c8e56adc9d02a6bcfac1c6.tar.gz
sdk-e25af9f721bcc89d73c8e56adc9d02a6bcfac1c6.tar.bz2
Add to layoutlib the ability to simply render a Drawable.
RenderParams is now a base class. SessionParams extends it (and contains the layout and the rendering mode which are not part of the base class). DrawableParams is used for the new action and adds a reference to a ResourceValue. Change-Id: Ieacf4da91fda95df1d25a32ae0953bd9d8028113
Diffstat (limited to 'layoutlib_api/src/com/android/ide/common/rendering')
-rw-r--r--layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java15
-rw-r--r--layoutlib_api/src/com/android/ide/common/rendering/api/DrawableParams.java78
-rw-r--r--layoutlib_api/src/com/android/ide/common/rendering/api/RenderParams.java52
-rw-r--r--layoutlib_api/src/com/android/ide/common/rendering/api/Result.java1
-rw-r--r--layoutlib_api/src/com/android/ide/common/rendering/api/SessionParams.java115
5 files changed, 216 insertions, 45 deletions
diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java b/layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java
index 755c736..48309cf 100644
--- a/layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java
+++ b/layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java
@@ -17,6 +17,9 @@
package com.android.ide.common.rendering.api;
+import com.android.ide.common.rendering.api.Result.Status;
+
+import java.awt.image.BufferedImage;
import java.io.File;
import java.util.EnumSet;
import java.util.Map;
@@ -78,11 +81,21 @@ public abstract class Bridge {
* @return a new {@link RenderSession} object that contains the result of the scene creation and
* first rendering.
*/
- public RenderSession createSession(RenderParams params) {
+ public RenderSession createSession(SessionParams params) {
return null;
}
/**
+ * Renders a Drawable. If the rendering is successful, the result image is accessible through
+ * {@link Result#getData()}. It is of type {@link BufferedImage}
+ * @param params the rendering parameters.
+ * @return the result of the action.
+ */
+ public Result renderDrawable(DrawableParams params) {
+ return Status.NOT_IMPLEMENTED.createResult();
+ }
+
+ /**
* Clears the resource cache for a specific project.
* <p/>This cache contains bitmaps and nine patches that are loaded from the disk and reused
* until this method is called.
diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/DrawableParams.java b/layoutlib_api/src/com/android/ide/common/rendering/api/DrawableParams.java
new file mode 100644
index 0000000..766b3be
--- /dev/null
+++ b/layoutlib_api/src/com/android/ide/common/rendering/api/DrawableParams.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ide.common.rendering.api;
+
+import com.android.resources.Density;
+
+/**
+ * Rendering parameters for {@link Bridge#renderDrawable(DrawableParams)}
+ *
+ */
+public class DrawableParams extends RenderParams {
+
+ private final ResourceValue mDrawable;
+
+ /**
+ * Builds a param object with all the necessary parameters to render a drawable with
+ * {@link Bridge#renderDrawable(DrawableParams)}
+ *
+ * @param drawable the {@link ResourceValue} identifying the drawable.
+ * @param projectKey An Object identifying the project. This is used for the cache mechanism.
+ * @param screenWidth the screen width
+ * @param screenHeight the screen height
+ * @param density the density factor for the screen.
+ * @param xdpi the screen actual dpi in X
+ * @param ydpi the screen actual dpi in Y
+ * @param themeName The name of the theme to use.
+ * @param isProjectTheme true if the theme is a project theme, false if it is a framework theme.
+ * @param projectResources the resources of the project. The map contains (String, map) pairs
+ * where the string is the type of the resource reference used in the layout file, and the
+ * map contains (String, {@link ResourceValue}) pairs where the key is the resource name,
+ * and the value is the resource value.
+ * @param frameworkResources the framework resources. The map contains (String, map) pairs
+ * where the string is the type of the resource reference used in the layout file, and the map
+ * contains (String, {@link ResourceValue}) pairs where the key is the resource name, and the
+ * value is the resource value.
+ * @param projectCallback The {@link IProjectCallback} object to get information from
+ * the project.
+ * @param minSdkVersion the minSdkVersion of the project
+ * @param targetSdkVersion the targetSdkVersion of the project
+ * @param log the object responsible for displaying warning/errors to the user.
+ */
+ public DrawableParams(
+ ResourceValue drawable,
+ Object projectKey,
+ int screenWidth, int screenHeight,
+ Density density, float xdpi, float ydpi,
+ RenderResources renderResources,
+ IProjectCallback projectCallback,
+ int minSdkVersion, int targetSdkVersion,
+ LayoutLog log) {
+ super(projectKey, screenWidth, screenHeight, density, xdpi, ydpi,
+ renderResources, projectCallback, minSdkVersion, targetSdkVersion, log);
+ mDrawable = drawable;
+ }
+
+ public DrawableParams(DrawableParams params) {
+ super(params);
+ mDrawable = params.mDrawable;
+ }
+
+ public ResourceValue getDrawable() {
+ return mDrawable;
+ }
+}
diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/RenderParams.java b/layoutlib_api/src/com/android/ide/common/rendering/api/RenderParams.java
index 296982c..2cfe770 100644
--- a/layoutlib_api/src/com/android/ide/common/rendering/api/RenderParams.java
+++ b/layoutlib_api/src/com/android/ide/common/rendering/api/RenderParams.java
@@ -19,39 +19,18 @@ package com.android.ide.common.rendering.api;
import com.android.resources.Density;
import com.android.resources.ScreenSize;
-
-public class RenderParams {
+/**
+ * Base class for rendering parameters. This include the generic parameters but not what needs
+ * to be rendered or additional parameters.
+ *
+ */
+public abstract class RenderParams {
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 final ILayoutPullParser mLayoutDescription;
private final Object mProjectKey;
private final int mScreenWidth;
private final int mScreenHeight;
- private final RenderingMode mRenderingMode;
private final Density mDensity;
private final float mXdpi;
private final float mYdpi;
@@ -75,12 +54,9 @@ public class RenderParams {
/**
*
- * @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
@@ -100,19 +76,17 @@ public class RenderParams {
* @param targetSdkVersion the targetSdkVersion of the project
* @param log the object responsible for displaying warning/errors to the user.
*/
- public RenderParams(ILayoutPullParser layoutDescription,
+ public RenderParams(
Object projectKey,
- int screenWidth, int screenHeight, RenderingMode renderingMode,
+ int screenWidth, int screenHeight,
Density density, float xdpi, float ydpi,
RenderResources renderResources,
IProjectCallback projectCallback,
int minSdkVersion, int targetSdkVersion,
LayoutLog log) {
- mLayoutDescription = layoutDescription;
mProjectKey = projectKey;
mScreenWidth = screenWidth;
mScreenHeight = screenHeight;
- mRenderingMode = renderingMode;
mDensity = density;
mXdpi = xdpi;
mYdpi = ydpi;
@@ -129,11 +103,9 @@ public class RenderParams {
* Copy constructor.
*/
public RenderParams(RenderParams 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;
@@ -186,10 +158,6 @@ public class RenderParams {
mForceNoDecor = true;
}
- public ILayoutPullParser getLayoutDescription() {
- return mLayoutDescription;
- }
-
public Object getProjectKey() {
return mProjectKey;
}
@@ -210,10 +178,6 @@ public class RenderParams {
return mScreenHeight;
}
- public RenderingMode getRenderingMode() {
- return mRenderingMode;
- }
-
public Density getDensity() {
return mDensity;
}
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
index 172a7e7..6152a28 100644
--- a/layoutlib_api/src/com/android/ide/common/rendering/api/Result.java
+++ b/layoutlib_api/src/com/android/ide/common/rendering/api/Result.java
@@ -46,6 +46,7 @@ public class Result {
ERROR_NOT_INFLATED,
ERROR_RENDER,
ERROR_ANIM_NOT_FOUND,
+ ERROR_NOT_A_DRAWABLE,
ERROR_UNKNOWN;
private Result mResult;
diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/SessionParams.java b/layoutlib_api/src/com/android/ide/common/rendering/api/SessionParams.java
new file mode 100644
index 0000000..9446ff5
--- /dev/null
+++ b/layoutlib_api/src/com/android/ide/common/rendering/api/SessionParams.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ide.common.rendering.api;
+
+import com.android.resources.Density;
+
+/**
+ * Rendering parameters for a {@link RenderSession}.
+ *
+ */
+public class SessionParams extends RenderParams {
+
+ 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 final ILayoutPullParser mLayoutDescription;
+ private final RenderingMode mRenderingMode;
+
+ /**
+ *
+ * @param layoutDescription the {@link ILayoutPullParser} letting the LayoutLib Bridge visit the
+ * layout file.
+ * @param renderingMode The rendering mode.
+ * @param projectKey An Object identifying the project. This is used for the cache mechanism.
+ * @param screenWidth the screen width
+ * @param screenHeight the screen height
+ * @param density the density factor for the screen.
+ * @param xdpi the screen actual dpi in X
+ * @param ydpi the screen actual dpi in Y
+ * @param themeName The name of the theme to use.
+ * @param isProjectTheme true if the theme is a project theme, false if it is a framework theme.
+ * @param projectResources the resources of the project. The map contains (String, map) pairs
+ * where the string is the type of the resource reference used in the layout file, and the
+ * map contains (String, {@link ResourceValue}) pairs where the key is the resource name,
+ * and the value is the resource value.
+ * @param frameworkResources the framework resources. The map contains (String, map) pairs
+ * where the string is the type of the resource reference used in the layout file, and the map
+ * contains (String, {@link ResourceValue}) pairs where the key is the resource name, and the
+ * value is the resource value.
+ * @param projectCallback The {@link IProjectCallback} object to get information from
+ * the project.
+ * @param minSdkVersion the minSdkVersion of the project
+ * @param targetSdkVersion the targetSdkVersion of the project
+ * @param log the object responsible for displaying warning/errors to the user.
+ */
+ public SessionParams(
+ ILayoutPullParser layoutDescription,
+ RenderingMode renderingMode,
+ Object projectKey,
+ int screenWidth, int screenHeight,
+ Density density, float xdpi, float ydpi,
+ RenderResources renderResources,
+ IProjectCallback projectCallback,
+ int minSdkVersion, int targetSdkVersion,
+ LayoutLog log) {
+ super(projectKey, screenWidth, screenHeight, density, xdpi, ydpi,
+ renderResources, projectCallback, minSdkVersion, targetSdkVersion, log);
+
+ mLayoutDescription = layoutDescription;
+ mRenderingMode = renderingMode;
+
+ }
+
+ public SessionParams(SessionParams params) {
+ super(params);
+ mLayoutDescription = params.mLayoutDescription;
+ mRenderingMode = params.mRenderingMode;
+ }
+
+ public ILayoutPullParser getLayoutDescription() {
+ return mLayoutDescription;
+ }
+
+ public RenderingMode getRenderingMode() {
+ return mRenderingMode;
+ }
+
+
+
+}