diff options
Diffstat (limited to 'layoutlib_api/src')
-rw-r--r-- | layoutlib_api/src/com/android/layoutlib/api/Capability.java (renamed from layoutlib_api/src/com/android/layoutlib/api/Capabilities.java) | 11 | ||||
-rw-r--r-- | layoutlib_api/src/com/android/layoutlib/api/DensityBasedResourceValue.java | 44 | ||||
-rw-r--r-- | layoutlib_api/src/com/android/layoutlib/api/IDensityBasedResourceValue.java | 11 | ||||
-rw-r--r-- | layoutlib_api/src/com/android/layoutlib/api/IResourceValue.java | 6 | ||||
-rw-r--r-- | layoutlib_api/src/com/android/layoutlib/api/IStyleResourceValue.java | 9 | ||||
-rw-r--r-- | layoutlib_api/src/com/android/layoutlib/api/LayoutBridge.java | 6 | ||||
-rw-r--r-- | layoutlib_api/src/com/android/layoutlib/api/ResourceDensity.java | 59 | ||||
-rw-r--r-- | layoutlib_api/src/com/android/layoutlib/api/ResourceValue.java | 87 | ||||
-rw-r--r-- | layoutlib_api/src/com/android/layoutlib/api/SceneParams.java | 12 | ||||
-rw-r--r-- | layoutlib_api/src/com/android/layoutlib/api/StyleResourceValue.java | 77 |
10 files changed, 305 insertions, 17 deletions
diff --git a/layoutlib_api/src/com/android/layoutlib/api/Capabilities.java b/layoutlib_api/src/com/android/layoutlib/api/Capability.java index 0edc764..586642f 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/Capabilities.java +++ b/layoutlib_api/src/com/android/layoutlib/api/Capability.java @@ -22,9 +22,18 @@ import com.android.layoutlib.api.LayoutScene.IAnimationListener; * Enum describing the layout bridge capabilities. * */ -public enum 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<br> * {@link LayoutScene#insertChild(Object, IXmlPullParser, int, com.android.layoutlib.api.LayoutScene.IAnimationListener)}<br> * {@link LayoutScene#moveChild(Object, Object, int, com.android.layoutlib.api.LayoutScene.IAnimationListener)}<br> diff --git a/layoutlib_api/src/com/android/layoutlib/api/DensityBasedResourceValue.java b/layoutlib_api/src/com/android/layoutlib/api/DensityBasedResourceValue.java new file mode 100644 index 0000000..78b084c --- /dev/null +++ b/layoutlib_api/src/com/android/layoutlib/api/DensityBasedResourceValue.java @@ -0,0 +1,44 @@ +/* + * 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 e969034..bc319c2 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/IDensityBasedResourceValue.java +++ b/layoutlib_api/src/com/android/layoutlib/api/IDensityBasedResourceValue.java @@ -18,9 +18,17 @@ package com.android.layoutlib.api; /** * Represents an Android Resources that has a density info attached to it. + * @deprecated use {@link DensityBasedResourceValue}. */ +@Deprecated public interface IDensityBasedResourceValue extends IResourceValue { + /** + * Density. + * + * @deprecated use {@link ResourceDensity}. + */ + @Deprecated public static enum Density { XHIGH(320), HIGH(240), @@ -28,8 +36,6 @@ public interface IDensityBasedResourceValue extends IResourceValue { LOW(120), NODPI(0); - public final static int DEFAULT_DENSITY = 160; - private final int mValue; Density(int value) { @@ -58,6 +64,7 @@ public interface IDensityBasedResourceValue extends IResourceValue { /** * Returns the density associated to the resource. + * @deprecated use {@link DensityBasedResourceValue#getResourceDensity()} */ Density getDensity(); } diff --git a/layoutlib_api/src/com/android/layoutlib/api/IResourceValue.java b/layoutlib_api/src/com/android/layoutlib/api/IResourceValue.java index 1da9508..8a3e754 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/IResourceValue.java +++ b/layoutlib_api/src/com/android/layoutlib/api/IResourceValue.java @@ -18,9 +18,11 @@ package com.android.layoutlib.api; /** * Represents an android resource with a name and a string value. + * @deprecated use {@link ResourceValue}. */ +@Deprecated public interface IResourceValue { - + /** * Returns the type of the resource. For instance "drawable", "color", etc... */ @@ -35,7 +37,7 @@ public interface IResourceValue { * Returns the value of the resource, as defined in the XML. This can be <code>null</code> */ String getValue(); - + /** * Returns whether the resource is a framework resource (<code>true</code>) or a project * resource (<code>false</false>). diff --git a/layoutlib_api/src/com/android/layoutlib/api/IStyleResourceValue.java b/layoutlib_api/src/com/android/layoutlib/api/IStyleResourceValue.java index 2f17e69..33133c9 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/IStyleResourceValue.java +++ b/layoutlib_api/src/com/android/layoutlib/api/IStyleResourceValue.java @@ -16,12 +16,13 @@ package com.android.layoutlib.api; - /** * Represents an android style resources with a name and a list of children {@link IResourceValue}. + * @deprecated Use {@link StyleResourceValue}. */ +@Deprecated public interface IStyleResourceValue extends IResourceValue { - + /** * Returns the parent style name or <code>null</code> if unknown. */ @@ -29,7 +30,9 @@ public interface IStyleResourceValue extends IResourceValue { /** * Find an item in the list by name - * @param name + * @param name the name of the resource + * + * @deprecated use {@link StyleResourceValue#findValue(String)} */ IResourceValue findItem(String name); } diff --git a/layoutlib_api/src/com/android/layoutlib/api/LayoutBridge.java b/layoutlib_api/src/com/android/layoutlib/api/LayoutBridge.java index 62a1d1d..7c66bc4 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/LayoutBridge.java +++ b/layoutlib_api/src/com/android/layoutlib/api/LayoutBridge.java @@ -36,12 +36,12 @@ public abstract class LayoutBridge { public abstract int getApiLevel(); /** - * Returns an {@link EnumSet} of the supported {@link Capabilities}. + * Returns an {@link EnumSet} of the supported {@link Capability}. * @return an {@link EnumSet} with the supported capabilities. * */ - public EnumSet<Capabilities> getCapabilities() { - return EnumSet.noneOf(Capabilities.class); + public EnumSet<Capability> getCapabilities() { + return EnumSet.noneOf(Capability.class); } /** diff --git a/layoutlib_api/src/com/android/layoutlib/api/ResourceDensity.java b/layoutlib_api/src/com/android/layoutlib/api/ResourceDensity.java new file mode 100644 index 0000000..cebb8df --- /dev/null +++ b/layoutlib_api/src/com/android/layoutlib/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.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 new file mode 100644 index 0000000..41f440d --- /dev/null +++ b/layoutlib_api/src/com/android/layoutlib/api/ResourceValue.java @@ -0,0 +1,87 @@ +/* + * 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 <code>null</code> + */ + public final String getValue() { + return mValue; + } + + /** + * Returns whether the resource is a framework resource (<code>true</code>) or a project + * resource (<code>false</false>). + */ + public final boolean isFramework() { + return mIsFramwork; + } + + + /** + * Sets the value of the resource. + * @param value the new value + */ + 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 index 56014f0..309f9fd 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/SceneParams.java +++ b/layoutlib_api/src/com/android/layoutlib/api/SceneParams.java @@ -55,8 +55,8 @@ public class SceneParams { private float mYdpi; private String mThemeName; private boolean mIsProjectTheme; - private Map<String, Map<String, IResourceValue>> mProjectResources; - private Map<String, Map<String, IResourceValue>> mFrameworkResources; + private Map<String, Map<String, ResourceValue>> mProjectResources; + private Map<String, Map<String, ResourceValue>> mFrameworkResources; private IProjectCallback mProjectCallback; private LayoutLog mLog; @@ -96,8 +96,8 @@ public class SceneParams { int screenWidth, int screenHeight, RenderingMode renderingMode, int density, float xdpi, float ydpi, String themeName, boolean isProjectTheme, - Map<String, Map<String, IResourceValue>> projectResources, - Map<String, Map<String, IResourceValue>> frameworkResources, + Map<String, Map<String, ResourceValue>> projectResources, + Map<String, Map<String, ResourceValue>> frameworkResources, IProjectCallback projectCallback, LayoutLog log) { mLayoutDescription = layoutDescription; mProjectKey = projectKey; @@ -194,11 +194,11 @@ public class SceneParams { return mIsProjectTheme; } - public Map<String, Map<String, IResourceValue>> getProjectResources() { + public Map<String, Map<String, ResourceValue>> getProjectResources() { return mProjectResources; } - public Map<String, Map<String, IResourceValue>> getFrameworkResources() { + public Map<String, Map<String, ResourceValue>> getFrameworkResources() { return mFrameworkResources; } diff --git a/layoutlib_api/src/com/android/layoutlib/api/StyleResourceValue.java b/layoutlib_api/src/com/android/layoutlib/api/StyleResourceValue.java new file mode 100644 index 0000000..8052b4e --- /dev/null +++ b/layoutlib_api/src/com/android/layoutlib/api/StyleResourceValue.java @@ -0,0 +1,77 @@ +/* + * 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<String, ResourceValue> mItems = new HashMap<String, ResourceValue>(); + + 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 <code>null</code> 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); + } + +} |