From f538a020eec631ca19ce493877de2ebca3b8d6f3 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Thu, 3 Feb 2011 11:43:14 -0800 Subject: Add app name/icon and current render locale to the LayoutLib API. This allows the layoutlib to render system/title/action bars as a window decor like it would look on the device. This can be disabled with RenderParams.setForceNoDecor(). (BTW, Params was renamed RenderParams too) Also minor update to the API by replacing an int with Density since the enum is now accessible to the API and layoutlib. Change-Id: Ic37770a9276d12af90c60199a84b04cb64e7c3a1 --- .../android/ide/common/rendering/api/Bridge.java | 4 +- .../rendering/api/DensityBasedResourceValue.java | 7 + .../ide/common/rendering/api/IImageFactory.java | 2 +- .../android/ide/common/rendering/api/Params.java | 235 ------------------ .../ide/common/rendering/api/RenderParams.java | 276 +++++++++++++++++++++ .../ide/common/rendering/api/RenderSession.java | 4 +- .../ide/common/rendering/api/ResourceValue.java | 8 + 7 files changed, 296 insertions(+), 240 deletions(-) delete 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/RenderParams.java (limited to 'layoutlib_api/src/com/android/ide/common/rendering/api') 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 d014b6c..755c736 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 @@ -78,7 +78,7 @@ public abstract class Bridge { * @return a new {@link RenderSession} object that contains the result of the scene creation and * first rendering. */ - public RenderSession createSession(Params params) { + public RenderSession createSession(RenderParams params) { return null; } @@ -89,7 +89,7 @@ public abstract class Bridge { *

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}. + * The project key provided must be similar to the one passed in {@link RenderParams}. * * @param projectKey the key for the project. */ diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/DensityBasedResourceValue.java b/layoutlib_api/src/com/android/ide/common/rendering/api/DensityBasedResourceValue.java index 12bd57c..ca60640 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/DensityBasedResourceValue.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/DensityBasedResourceValue.java @@ -44,4 +44,11 @@ public class DensityBasedResourceValue extends ResourceValue implements IDensity public Density getDensity() { return Density.getEnum(mDensity.getDpiValue()); } + + @Override + public String toString() { + return "DensityBasedResourceValue [" + + getResourceType() + "/" + getName() + " = " + getValue() + + " (density:" + mDensity +", framework:" + isFramework() + ")]"; + } } 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 index c05c7c6..7681243 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/IImageFactory.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/IImageFactory.java @@ -26,7 +26,7 @@ import java.awt.image.BufferedImage; * 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 + * If no factory is passed in {@link RenderParams#setImageFactory(IImageFactory)}, then a default * {@link BufferedImage} of type {@link BufferedImage#TYPE_INT_ARGB} is created. * */ 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 deleted file mode 100644 index fb4b423..0000000 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/Params.java +++ /dev/null @@ -1,235 +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.ide.common.rendering.api; - -import com.android.resources.ScreenSize; - - -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 final ILayoutPullParser mLayoutDescription; - private final Object mProjectKey; - private final int mScreenWidth; - private final int mScreenHeight; - private final RenderingMode mRenderingMode; - private final int mDensity; - private final float mXdpi; - private final float mYdpi; - private final RenderResources mRenderResources; - private final IProjectCallback mProjectCallback; - private final int mMinSdkVersion; - private final int mTargetSdkVersion; - private final LayoutLog mLog; - - private boolean mCustomBackgroundEnabled; - private int mCustomBackgroundColor; - private long mTimeout; - - private IImageFactory mImageFactory = null; - - private ScreenSize mConfigScreenSize = 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 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 Params(ILayoutPullParser layoutDescription, - Object projectKey, - int screenWidth, int screenHeight, RenderingMode renderingMode, - int 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; - mRenderResources = renderResources; - mProjectCallback = projectCallback; - mMinSdkVersion = minSdkVersion; - mTargetSdkVersion = targetSdkVersion; - 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; - mRenderResources = params.mRenderResources; - mProjectCallback = params.mProjectCallback; - mMinSdkVersion = params.mMinSdkVersion; - mTargetSdkVersion = params.mTargetSdkVersion; - mLog = params.mLog; - mCustomBackgroundEnabled = params.mCustomBackgroundEnabled; - mCustomBackgroundColor = params.mCustomBackgroundColor; - mTimeout = params.mTimeout; - mImageFactory = params.mImageFactory; - mConfigScreenSize = params.mConfigScreenSize; - } - - public void setOverrideBgColor(int color) { - mCustomBackgroundEnabled = true; - mCustomBackgroundColor = color; - } - - public void setTimeout(long timeout) { - mTimeout = timeout; - } - - public void setImageFactory(IImageFactory imageFactory) { - mImageFactory = imageFactory; - } - - public void setConfigScreenSize(ScreenSize size) { - mConfigScreenSize = size; - } - - public ILayoutPullParser getLayoutDescription() { - return mLayoutDescription; - } - - public Object getProjectKey() { - return mProjectKey; - } - - public int getMinSdkVersion() { - return mMinSdkVersion; - } - - public int getTargetSdkVersion() { - return mTargetSdkVersion; - } - - 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 RenderResources getResources() { - return mRenderResources; - } - - 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; - } - - public ScreenSize getConfigScreenSize() { - return mConfigScreenSize; - } -} 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 new file mode 100644 index 0000000..296982c --- /dev/null +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/RenderParams.java @@ -0,0 +1,276 @@ +/* + * 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 com.android.resources.Density; +import com.android.resources.ScreenSize; + + +public 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; + private final RenderResources mRenderResources; + private final IProjectCallback mProjectCallback; + private final int mMinSdkVersion; + private final int mTargetSdkVersion; + private final LayoutLog mLog; + + private boolean mCustomBackgroundEnabled; + private int mCustomBackgroundColor; + private long mTimeout; + + private IImageFactory mImageFactory = null; + + private ScreenSize mConfigScreenSize = null; + private String mAppIcon = null; + private String mAppLabel = null; + private String mLocale = null; + private boolean mForceNoDecor; + + /** + * + * @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 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 RenderParams(ILayoutPullParser layoutDescription, + Object projectKey, + int screenWidth, int screenHeight, RenderingMode renderingMode, + 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; + mRenderResources = renderResources; + mProjectCallback = projectCallback; + mMinSdkVersion = minSdkVersion; + mTargetSdkVersion = targetSdkVersion; + mLog = log; + mCustomBackgroundEnabled = false; + mTimeout = DEFAULT_TIMEOUT; + } + + /** + * 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; + mRenderResources = params.mRenderResources; + mProjectCallback = params.mProjectCallback; + mMinSdkVersion = params.mMinSdkVersion; + mTargetSdkVersion = params.mTargetSdkVersion; + mLog = params.mLog; + mCustomBackgroundEnabled = params.mCustomBackgroundEnabled; + mCustomBackgroundColor = params.mCustomBackgroundColor; + mTimeout = params.mTimeout; + mImageFactory = params.mImageFactory; + mConfigScreenSize = params.mConfigScreenSize; + mAppIcon = params.mAppIcon; + mAppLabel = params.mAppLabel; + mLocale = params.mLocale; + mForceNoDecor = params.mForceNoDecor; + } + + public void setOverrideBgColor(int color) { + mCustomBackgroundEnabled = true; + mCustomBackgroundColor = color; + } + + public void setTimeout(long timeout) { + mTimeout = timeout; + } + + public void setImageFactory(IImageFactory imageFactory) { + mImageFactory = imageFactory; + } + + public void setConfigScreenSize(ScreenSize size) { + mConfigScreenSize = size; + } + + public void setAppIcon(String appIcon) { + mAppIcon = appIcon; + } + + public void setAppLabel(String appLabel) { + mAppLabel = appLabel; + } + + public void setLocale(String locale) { + mLocale = locale; + } + + public void setForceNoDecor() { + mForceNoDecor = true; + } + + public ILayoutPullParser getLayoutDescription() { + return mLayoutDescription; + } + + public Object getProjectKey() { + return mProjectKey; + } + + public int getMinSdkVersion() { + return mMinSdkVersion; + } + + public int getTargetSdkVersion() { + return mTargetSdkVersion; + } + + public int getScreenWidth() { + return mScreenWidth; + } + + public int getScreenHeight() { + return mScreenHeight; + } + + public RenderingMode getRenderingMode() { + return mRenderingMode; + } + + public Density getDensity() { + return mDensity; + } + + public float getXdpi() { + return mXdpi; + } + + public float getYdpi() { + return mYdpi; + } + + public RenderResources getResources() { + return mRenderResources; + } + + 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; + } + + public ScreenSize getConfigScreenSize() { + return mConfigScreenSize; + } + + public String getAppIcon() { + return mAppIcon; + } + + public String getAppLabel() { + return mAppLabel; + } + + public String getLocale() { + return mLocale; + } + + public boolean isForceNoDecor() { + return mForceNoDecor; + } +} diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/RenderSession.java b/layoutlib_api/src/com/android/ide/common/rendering/api/RenderSession.java index 9bdd146..a2e087c 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/RenderSession.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/RenderSession.java @@ -27,7 +27,7 @@ import java.util.Map; /** * An object allowing interaction with an Android layout. * - * This is returned by {@link Bridge#createScene(Params)}. + * This is returned by {@link Bridge#createScene(RenderParams)}. * and can then be used for subsequent actions on the layout. * * @since 5 @@ -102,7 +102,7 @@ public class RenderSession { * @return a {@link Result} indicating the status of the action. */ public Result render() { - return render(Params.DEFAULT_TIMEOUT); + return render(RenderParams.DEFAULT_TIMEOUT); } /** diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/ResourceValue.java b/layoutlib_api/src/com/android/ide/common/rendering/api/ResourceValue.java index 76561c8..f15d903 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/ResourceValue.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/ResourceValue.java @@ -91,4 +91,12 @@ public class ResourceValue implements IResourceValue { public void replaceWith(ResourceValue value) { mValue = value.mValue; } + + @Override + public String toString() { + return "ResourceValue [" + mType + "/" + mName + " = " + mValue + + " (framework:" + mIsFramwork + ")]"; + } + + } -- cgit v1.1