From 6685d3a8cb5fe1374e36358c1436a70c6bca1659 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Thu, 27 Jan 2011 13:10:25 -0800 Subject: Update the Layoutlib API to contain part of the current config. Right now only the screen size is needed. We can add more to Params as needed. Since we should use the existing enum classes for this, I moved all the current enum from sdklib into a new jar file called resources.jar. ADT, sdklib, layoutlib_api all depend on it. Changes to resources should always be API compatible and the result should be copied into the in-dev platform branch in prebuilt, similar to layoutlib_api. See the README.txt files in layoutlib_api/ and resources/ Change-Id: I877ba3cad555ec497954bb0866639e51e7751020 --- .../rendering/api/DensityBasedResourceValue.java | 8 +-- .../android/ide/common/rendering/api/Params.java | 13 +++++ .../ide/common/rendering/api/RenderSession.java | 10 ++-- .../ide/common/rendering/api/ResourceDensity.java | 59 ---------------------- .../layoutlib/api/IDensityBasedResourceValue.java | 3 +- 5 files changed, 22 insertions(+), 71 deletions(-) delete mode 100644 layoutlib_api/src/com/android/ide/common/rendering/api/ResourceDensity.java (limited to 'layoutlib_api/src') 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 d190b62..4d0d51f 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 @@ -21,10 +21,10 @@ import com.android.layoutlib.api.IDensityBasedResourceValue; @SuppressWarnings("deprecation") public class DensityBasedResourceValue extends ResourceValue implements IDensityBasedResourceValue { - private ResourceDensity mDensity; + private com.android.resources.Density mDensity; public DensityBasedResourceValue(String type, String name, String value, - ResourceDensity density, boolean isFramework) { + com.android.resources.Density density, boolean isFramework) { super(type, name, value, isFramework); mDensity = density; } @@ -33,7 +33,7 @@ public class DensityBasedResourceValue extends ResourceValue implements IDensity * Returns the density for which this resource is configured. * @return the density. */ - public ResourceDensity getResourceDensity() { + public com.android.resources.Density getResourceDensity() { return mDensity; } @@ -41,6 +41,6 @@ public class DensityBasedResourceValue extends ResourceValue implements IDensity * @deprecated use {@link #getResourceDensity()} instead. */ public Density getDensity() { - return Density.getEnum(mDensity.getDpi()); + return Density.getEnum(mDensity.getDpiValue()); } } 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 index 4bb41f1..fb4b423 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/Params.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/Params.java @@ -16,6 +16,8 @@ package com.android.ide.common.rendering.api; +import com.android.resources.ScreenSize; + public class Params { @@ -64,6 +66,8 @@ public class Params { private IImageFactory mImageFactory = null; + private ScreenSize mConfigScreenSize = null; + /** * * @param layoutDescription the {@link ILayoutPullParser} letting the LayoutLib Bridge visit the @@ -137,6 +141,7 @@ public class Params { mCustomBackgroundColor = params.mCustomBackgroundColor; mTimeout = params.mTimeout; mImageFactory = params.mImageFactory; + mConfigScreenSize = params.mConfigScreenSize; } public void setOverrideBgColor(int color) { @@ -152,6 +157,10 @@ public class Params { mImageFactory = imageFactory; } + public void setConfigScreenSize(ScreenSize size) { + mConfigScreenSize = size; + } + public ILayoutPullParser getLayoutDescription() { return mLayoutDescription; } @@ -219,4 +228,8 @@ public class Params { public IImageFactory getImageFactory() { return mImageFactory; } + + public ScreenSize getConfigScreenSize() { + return mConfigScreenSize; + } } 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 5a00ebc..9bdd146 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 @@ -74,13 +74,11 @@ public class RenderSession { } /** - * Returns true if the current session is rendered as a floating window. - *

- * If true this means the alpha channel of {@link #getImage()} should be respected. If false, - * if can be dropped if it's more convenient/faster. - * @return whether the current session is rendered as a floating window. + * Returns true if the current image alpha channel is relevant. + * + * @return whether the image alpha channel is relevant. */ - public boolean isFloatingWindow() { + public boolean isAlphaChannelImage() { return true; } 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 deleted file mode 100644 index ca92eae..0000000 --- a/layoutlib_api/src/com/android/ide/common/rendering/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.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/layoutlib/api/IDensityBasedResourceValue.java b/layoutlib_api/src/com/android/layoutlib/api/IDensityBasedResourceValue.java index 4e55d54..dce907c 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/IDensityBasedResourceValue.java +++ b/layoutlib_api/src/com/android/layoutlib/api/IDensityBasedResourceValue.java @@ -17,7 +17,6 @@ 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. @@ -29,7 +28,7 @@ public interface IDensityBasedResourceValue extends IResourceValue { /** * Density. * - * @deprecated use {@link ResourceDensity}. + * @deprecated use {@link com.android.resources.Density}. */ @Deprecated public static enum Density { -- cgit v1.1