aboutsummaryrefslogtreecommitdiffstats
path: root/layoutlib_api/src/com/android/ide
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2011-01-17 12:38:00 -0800
committerXavier Ducrohet <xav@android.com>2011-01-17 13:45:17 -0800
commit72621cf2b17e86fdfa68a2d46f49cb7ce3416e75 (patch)
tree64b7260ab50da12e072ee7ceefcbcf3c5ccebbaa /layoutlib_api/src/com/android/ide
parent5c5e8fc52062bf1ab74e0bbcf528dd24d7aeffdf (diff)
downloadsdk-72621cf2b17e86fdfa68a2d46f49cb7ce3416e75.zip
sdk-72621cf2b17e86fdfa68a2d46f49cb7ce3416e75.tar.gz
sdk-72621cf2b17e86fdfa68a2d46f49cb7ce3416e75.tar.bz2
Move the resource resolution code into ide-common.
Also move the LayoutLib API to use a new class for all resource info instead of 2 maps, one string, and a boolean. The goal is to move resource resolution code into ADT so that we can use it to better display resource information in the UI. Change-Id: Iad1c1719ab0b08d1a7d0987b92d4be1d3a895adf
Diffstat (limited to 'layoutlib_api/src/com/android/ide')
-rw-r--r--layoutlib_api/src/com/android/ide/common/rendering/api/Params.java56
-rw-r--r--layoutlib_api/src/com/android/ide/common/rendering/api/RenderResources.java167
2 files changed, 183 insertions, 40 deletions
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 59e790e..3cede41 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,7 +16,6 @@
package com.android.ide.common.rendering.api;
-import java.util.Map;
public class Params {
@@ -45,20 +44,17 @@ public class Params {
}
}
- 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<String, Map<String, ResourceValue>> mProjectResources;
- private Map<String, Map<String, ResourceValue>> mFrameworkResources;
- private IProjectCallback mProjectCallback;
- private LayoutLog mLog;
+ 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 LayoutLog mLog;
private boolean mCustomBackgroundEnabled;
private int mCustomBackgroundColor;
@@ -95,9 +91,7 @@ public class Params {
Object projectKey,
int screenWidth, int screenHeight, RenderingMode renderingMode,
int density, float xdpi, float ydpi,
- String themeName, boolean isProjectTheme,
- Map<String, Map<String, ResourceValue>> projectResources,
- Map<String, Map<String, ResourceValue>> frameworkResources,
+ RenderResources renderResources,
IProjectCallback projectCallback, LayoutLog log) {
mLayoutDescription = layoutDescription;
mProjectKey = projectKey;
@@ -107,10 +101,7 @@ public class Params {
mDensity = density;
mXdpi = xdpi;
mYdpi = ydpi;
- mThemeName = themeName;
- mIsProjectTheme = isProjectTheme;
- mProjectResources = projectResources;
- mFrameworkResources = frameworkResources;
+ mRenderResources = renderResources;
mProjectCallback = projectCallback;
mLog = log;
mCustomBackgroundEnabled = false;
@@ -129,10 +120,7 @@ public class Params {
mDensity = params.mDensity;
mXdpi = params.mXdpi;
mYdpi = params.mYdpi;
- mThemeName = params.mThemeName;
- mIsProjectTheme = params.mIsProjectTheme;
- mProjectResources = params.mProjectResources;
- mFrameworkResources = params.mFrameworkResources;
+ mRenderResources = params.mRenderResources;
mProjectCallback = params.mProjectCallback;
mLog = params.mLog;
mCustomBackgroundEnabled = params.mCustomBackgroundEnabled;
@@ -186,20 +174,8 @@ public class Params {
return mYdpi;
}
- public String getThemeName() {
- return mThemeName;
- }
-
- public boolean isProjectTheme() {
- return mIsProjectTheme;
- }
-
- public Map<String, Map<String, ResourceValue>> getProjectResources() {
- return mProjectResources;
- }
-
- public Map<String, Map<String, ResourceValue>> getFrameworkResources() {
- return mFrameworkResources;
+ public RenderResources getResources() {
+ return mRenderResources;
}
public IProjectCallback getProjectCallback() {
diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/RenderResources.java b/layoutlib_api/src/com/android/ide/common/rendering/api/RenderResources.java
new file mode 100644
index 0000000..e371d5a
--- /dev/null
+++ b/layoutlib_api/src/com/android/ide/common/rendering/api/RenderResources.java
@@ -0,0 +1,167 @@
+/*
+ * 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;
+
+/**
+ * A class containing all the resources needed to do a rendering.
+ * <p/>
+ * This contains both the project specific resources and the framework resources, and provide
+ * convenience methods to resolve resource and theme references.
+ */
+public class RenderResources {
+
+ public final static String RES_ANIMATOR = "animator";
+ public final static String RES_STYLE = "style";
+ public final static String RES_ATTR = "attr";
+ public final static String RES_DIMEN = "dimen";
+ public final static String RES_DRAWABLE = "drawable";
+ public final static String RES_COLOR = "color";
+ public final static String RES_LAYOUT = "layout";
+ public final static String RES_STRING = "string";
+ public final static String RES_ID = "id";
+
+ public final static String REFERENCE_NULL = "@null";
+
+
+ public static class FrameworkResourceIdProvider {
+ public Integer getId(String resType, String resName) {
+ return null;
+ }
+ }
+
+ public void setFrameworkResourceIdProvider(FrameworkResourceIdProvider provider) {
+ }
+
+ public void setLogger(LayoutLog logger) {
+ }
+
+ /**
+ * Return the {@link StyleResourceValue} representing the current theme.
+ * @return the theme or null if there is no theme.
+ */
+ public StyleResourceValue getTheme() {
+ return null;
+ }
+
+ /**
+ * Returns a framework resource by type and name. The returned resource is resolved.
+ * @param resourceType the type of the resource
+ * @param resourceName the name of the resource
+ */
+ public ResourceValue getFrameworkResource(String resourceType, String resourceName) {
+ return null;
+ }
+
+ /**
+ * Returns a project resource by type and name. The returned resource is resolved.
+ * @param resourceType the type of the resource
+ * @param resourceName the name of the resource
+ */
+ public ResourceValue getProjectResource(String resourceType, String resourceName) {
+ return null;
+ }
+
+ /**
+ * Returns the {@link ResourceValue} matching a given name in the current theme. If the
+ * item is not directly available in the theme, the method looks in its parent theme.
+ *
+ * @param itemName the name of the item to search for.
+ * @return the {@link ResourceValue} object or <code>null</code>
+ */
+ public ResourceValue findItemInTheme(String itemName) {
+ if (getTheme() != null) {
+ return findItemInStyle(getTheme(), itemName);
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the {@link ResourceValue} matching a given name in a given style. If the
+ * item is not directly available in the style, the method looks in its parent style.
+ *
+ * @param style the style to search in
+ * @param itemName the name of the item to search for.
+ * @return the {@link ResourceValue} object or <code>null</code>
+ */
+ public ResourceValue findItemInStyle(StyleResourceValue style, String itemName) {
+ return null;
+ }
+
+ /**
+ * Searches for, and returns a {@link ResourceValue} by its reference.
+ * <p/>
+ * The reference format can be:
+ * <pre>@resType/resName</pre>
+ * <pre>@android:resType/resName</pre>
+ * <pre>@resType/android:resName</pre>
+ * <pre>?resType/resName</pre>
+ * <pre>?android:resType/resName</pre>
+ * <pre>?resType/android:resName</pre>
+ * Any other string format will return <code>null</code>.
+ * <p/>
+ * The actual format of a reference is <pre>@[namespace:]resType/resName</pre> but this method
+ * only support the android namespace.
+ *
+ * @param reference the resource reference to search for.
+ * @param forceFrameworkOnly if true all references are considered to be toward framework
+ * resource even if the reference does not include the android: prefix.
+ * @return a {@link ResourceValue} or <code>null</code>.
+ */
+ public ResourceValue findResValue(String reference, boolean forceFrameworkOnly) {
+ return null;
+ }
+
+ /**
+ * Resolves the value of a resource, if the value references a theme or resource value.
+ * <p/>
+ * This method ensures that it returns a {@link ResourceValue} object that does not
+ * reference another resource.
+ * If the resource cannot be resolved, it returns <code>null</code>.
+ * <p/>
+ * If a value that does not need to be resolved is given, the method will return a new
+ * instance of {@link ResourceValue} that contains the input value.
+ *
+ * @param type the type of the resource
+ * @param name the name of the attribute containing this value.
+ * @param value the resource value, or reference to resolve
+ * @param isFrameworkValue whether the value is a framework value.
+ *
+ * @return the resolved resource value or <code>null</code> if it failed to resolve it.
+ */
+ public ResourceValue resolveValue(String type, String name, String value,
+ boolean isFrameworkValue) {
+ return null;
+ }
+
+ /**
+ * Returns the {@link ResourceValue} referenced by the value of <var>value</var>.
+ * <p/>
+ * This method ensures that it returns a {@link ResourceValue} object that does not
+ * reference another resource.
+ * If the resource cannot be resolved, it returns <code>null</code>.
+ * <p/>
+ * If a value that does not need to be resolved is given, the method will return the input
+ * value.
+ *
+ * @param value the value containing the reference to resolve.
+ * @return a {@link ResourceValue} object or <code>null</code>
+ */
+ public ResourceValue resolveResValue(ResourceValue value) {
+ return null;
+ }
+}